BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Properties | Events | List of all members
BrawlLib.SSBB.ResourceNodes.MDL0Node Class Reference
Inheritance diagram for BrawlLib.SSBB.ResourceNodes.MDL0Node:
BrawlLib.SSBB.ResourceNodes.BRESEntryNode BrawlLib.Modeling.IModel BrawlLib.SSBB.ResourceNodes.ResourceNode BrawlLib.OpenGL.IRenderedObject

Public Member Functions

 MDL0Node ()
 
Box GetBox ()
 Call ApplyCHR0 before calling this More...
 
void CalculateBoundingBoxes ()
 
void CheckTextures ()
 
List< ResourceNodeGetUsedShaders ()
 
void GenerateMetalMaterials ()
 
void GenerateMetalMaterials (string metalTextureName)
 
void CleanTextures ()
 
MDL0TextureNode FindOrCreateTexture (string name)
 
MDL0TextureNode FindOrCreatePalette (string name)
 
MDL0BoneNode FindBone (string name)
 
MDL0BoneNode FindBoneByIndex (int givenIndex)
 
MDL0MaterialNode FindOrCreateOpaMaterial (string name)
 
MDL0MaterialNode FindOrCreateXluMaterial (string name)
 
override void AddChild (ResourceNode child, bool change)
 
override void RemoveChild (ResourceNode child)
 
void ReplaceOrAddMesh (MDL0ObjectNode replacement, bool doSearch, bool replaceIfFound, bool addIfNotFound)
 
void ReplaceMeshes (MDL0Node replacement, bool doSearch, bool replaceIfFound, bool addIfNotFound)
 
void ConvertToShadowModel ()
 
void ConvertToSpyModel ()
 
void ConvertToSpyModelMultiType ()
 
void StripModel ()
 
void LinkGroup (MDL0GroupNode group)
 
void UnlinkGroup (MDL0GroupNode group)
 
override bool OnInitialize ()
 
override void OnPopulate ()
 
void BeginImport ()
 
void FinishImport (Collada form=null)
 
override void Replace (string fileName, FileMapProtect prot, FileOptions options)
 
override void Export (string outPath)
 
override int OnCalculateSize (bool force)
 
override void OnRebuild (VoidPtr address, int length, bool force)
 
void Attach ()
 
void RegenerateVIS0Indices ()
 This only needs to be called when the model is currently attached to a model renderer and the amount of objects change or an object's visibility bone changes. More...
 
void Detach ()
 
void Refresh ()
 
void PreRender (ModelPanelViewport v)
 
void RenderVertices (bool depthPass, IBoneNode weightTarget, GLCamera camera)
 
void RenderNormals ()
 
void RenderBoxes (bool model, bool obj, bool bone, bool bindState)
 
void RenderBones (ModelPanelViewport v)
 
void ResetToBindState ()
 
void DrawBox (bool bindState)
 
void ApplyCHR (CHR0Node node, float index)
 
void WeightMeshes (ModelPanelViewport v=null)
 
void ApplySRT (SRT0Node node, float index)
 
void ApplyCLR (CLR0Node node, float index)
 
void ApplyPAT (PAT0Node node, float index)
 
void ApplyVIS (VIS0Node node, float index)
 
void ApplySCN (SCN0Node node, float index)
 
void ApplySHP (SHP0Node node, float index)
 
void OnDrawCallsChanged ()
 
- Public Member Functions inherited from BrawlLib.SSBB.ResourceNodes.BRESEntryNode
override bool OnInitialize ()
 
override void Export (string outPath)
 
override byte[] MD5 ()
 Find the MD5 checksum of this node's data. Before calculating the checksum, the data will be copied to a temporary area in memory and PostProcess will be run just as in Export(). More...
 
- Public Member Functions inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
void OnRenamed ()
 
List< ResourceNodeGetChildrenRecursive ()
 Used primarily to get bone lists. Kept for all resource nodes for utility. More...
 
virtual void SignalPropertyChange ()
 
virtual void Dispose ()
 
void SelectChildAtIndex (int index)
 
void UpdateProperties ()
 
void UpdateCurrentControl ()
 
virtual bool MoveUp ()
 
virtual bool MoveDown ()
 
virtual void OnMoved ()
 
virtual void DoMoveDown ()
 
virtual void DoMoveDown (bool select)
 
virtual void DoMoveUp ()
 
virtual void DoMoveUp (bool select)
 
virtual bool AddUp ()
 
virtual bool AddDown ()
 
virtual bool ToParent ()
 
void Populate (int levels=-1)
 
virtual void OnPopulate ()
 
void Initialize (ResourceNode parent, FileMap source)
 
void Initialize (ResourceNode parent, VoidPtr address, int length)
 
void Initialize (ResourceNode parent, DataSource origSource)
 
virtual void Initialize (ResourceNode parent, DataSource origSource, DataSource uncompSource)
 
virtual bool OnInitialize ()
 
virtual void Restore ()
 
virtual void Remove ()
 
virtual void RemoveChild (ResourceNode child)
 
virtual void AddChild (ResourceNode child)
 
virtual void AddChild (ResourceNode child, bool change)
 
virtual void InsertChild (ResourceNode child, int index)
 
virtual void InsertChild (ResourceNode child, bool change, int index)
 
void SetSizeInternal (int size)
 
virtual void Replace (string fileName)
 
virtual void Replace (ResourceNode node)
 
virtual void Replace (string fileName, FileMapProtect prot, FileOptions options)
 
virtual void ReplaceRaw (VoidPtr address, int length)
 
virtual void ReplaceRaw (FileMap map)
 
virtual void Export (string outPath)
 
void Export (FileStream outStream)
 
virtual void ExportUncompressed (string outPath)
 
void ExportUncompressed (FileStream outStream)
 
virtual void Rebuild ()
 
virtual void Rebuild (bool force)
 
virtual void Rebuild (VoidPtr address, int length, bool force)
 
virtual void OnRebuild (VoidPtr address, int length, bool force)
 
virtual int CalculateSize (bool force)
 
virtual int OnCalculateSize (bool force)
 
void Merge ()
 
void Merge (bool forceBuild)
 
ResourceNode FindChildByType (string path, bool searchChildren, params ResourceType[] types)
 
ResourceNode FindChildByType (string path, bool searchChildren, StringComparison compare, params ResourceType[] types)
 
ResourceNode FindChild (string path)
 
ResourceNode FindChild (string path, bool searchChildren)
 
ResourceNode FindChild (string path, StringComparison compare)
 
ResourceNode FindChild (string path, bool searchChildren, StringComparison compare)
 
ResourceNode[] FindChildrenByClassType (string path, Type type)
 
ResourceNode[] FindChildrenByType (string path, ResourceType type)
 
ResourceNode[] FindChildrenByTypeInGroup (string path, ResourceType type, byte group)
 
ResourceNode[] FindChildrenByName (string name)
 
unsafe string FindName (string name)
 
ResourceNode FindEmbeddedIndex (int index)
 
virtual unsafe byte[] MD5 ()
 Find the MD5 checksum of this node's data. If this node doesn't have any data (BRESGroupNode, for example), this method will return null. More...
 
string MD5Str ()
 Get the result of the MD5() function as a string of hexadecimal digits. If MD5() returns null, this method will return an empty string. More...
 
ResourceNode PrevSibling ()
 
ResourceNode NextSibling ()
 
override string ToString ()
 
virtual void SortChildren ()
 
void ResetToBindState ()
 
void ApplyCHR (CHR0Node node, float index)
 
void ApplySRT (SRT0Node node, float index)
 
void ApplySHP (SHP0Node node, float index)
 
void ApplyPAT (PAT0Node node, float index)
 
void ApplyVIS (VIS0Node node, float index)
 
void ApplyCLR (CLR0Node node, float index)
 
void ApplySCN (SCN0Node node, float index)
 
void RenderVertices (bool depthPass, IBoneNode weightTarget, GLCamera camera)
 
void RenderNormals ()
 
void RenderBoxes (bool model, bool obj, bool bone, bool bindState)
 
void RenderBones (ModelPanelViewport v)
 
void Attach ()
 
void Detach ()
 
void Refresh ()
 
void PreRender (ModelPanelViewport v)
 
Box GetBox ()
 

Static Public Member Functions

static MDL0Node FromFile (string path, FileOptions options=FileOptions.RandomAccess)
 
- Static Public Member Functions inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
static ResourceNode[] FindAllSubNodes (ResourceNode root)
 
static ResourceNode FindNode (ResourceNode root, string path, bool searchChildren, StringComparison compare)
 

Public Attributes

byte _envMtxMode
 
bool _needsNrmMtxArray
 
bool _needsTexMtxArray
 
bool _enableExtents
 
int _numFacepoints
 
int _numTriangles
 
int _numNodes
 
Box _extents
 
ModelLinker _linker
 
AssetStorage _assets
 
bool _hasTree
 
bool _hasMix
 
bool _hasOpa
 
bool _hasXlu
 
bool _isImport
 
bool _autoMetal
 
List< MDL0BoneNode_billboardBones = new List<MDL0BoneNode>()
 
InfluenceManager _influences = new InfluenceManager()
 
List< string > _errors = new List<string>()
 
string _metalMat
 
MDL0GroupNode _boneGroup
 
MDL0GroupNode _matGroup
 
MDL0GroupNode _shadGroup
 
MDL0GroupNode _objGroup
 
MDL0GroupNode _texGroup
 
MDL0GroupNode _pltGroup
 
MDL0GroupNode _vertGroup
 
MDL0GroupNode _normGroup
 
MDL0GroupNode _uvGroup
 
MDL0GroupNode _defGroup
 
MDL0GroupNode _colorGroup
 
MDL0GroupNode _furPosGroup
 
MDL0GroupNode _furVecGroup
 
List< ResourceNode_boneList
 
List< ResourceNode_matList
 
List< ResourceNode_shadList
 
List< ResourceNode_objList
 
List< ResourceNode_texList
 
List< ResourceNode_pltList
 
List< ResourceNode_vertList
 
List< ResourceNode_normList
 
List< ResourceNode_uvList
 
List< ResourceNode_defList
 
List< ResourceNode_colorList
 
List< ResourceNode_furPosList
 
List< ResourceNode_furVecList
 
ModelRenderAttributes _renderAttribs = new ModelRenderAttributes()
 
bool _ignoreModelViewerAttribs = false
 
int _selectedObjectIndex = -1
 
Dictionary< string, Dictionary< int, List< int > > > VIS0Indices
 
Matrix_matrixOffset = null
 
bool _dontUpdateMesh = false
 
- Public Attributes inherited from BrawlLib.SSBB.ResourceNodes.BRESEntryNode
int _version
 
string _originalPath
 
- Public Attributes inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
Form _mainForm
 
string _name
 
string _origPath
 
ResourceNode _parent
 
List< ResourceNode_children = new List<ResourceNode>()
 
int _calcSize
 
EventHandler UpdateControl
 
MoveEventHandler MovedDown
 
ResourceEventHandler Renamed
 
ResourceEventHandler PropertyChanged
 
ResourceEventHandler Replaced
 
ResourceEventHandler Restored
 
ResourceChildEventHandler ChildRemoved
 
bool _isPopulating
 
bool _replaced
 

Static Public Attributes

static bool MultiTypeWorks = false
 

Protected Member Functions

override void OnVersionChanged (int previousVersion)
 
virtual void OnVersionChanged (int previousVersion)
 
- Protected Member Functions inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
void ForceReplacedEvent ()
 
virtual void MergeInternal ()
 

Properties

override ResourceType ResourceFileType [get]
 
override int DataAlign [get]
 
override int[] SupportedVersions [get]
 
override string Tag [get]
 
InfluenceManager Influences [get]
 
bool AutoMetalMaterials [get, set]
 
string MetalTexture [get, set]
 
MDLScalingRule ScalingRule [get, set]
 
TexMatrixMode TextureMatrixMode [get, set]
 
int NumFacepoints [get]
 
int NumVertices [get]
 
int NumTriangles [get]
 
int NumNodes [get]
 
bool NeedsNormalMtxArray [get]
 
bool NeedsTextureMtxArray [get]
 
Vector3 BoxMin [get, set]
 
Vector3 BoxMax [get, set]
 
bool EnableBoundingBox [get, set]
 
MDLEnvelopeMatrixMode EnvelopeMatrixMode [get, set]
 
bool IsStagePosition [get]
 
ResourceNode DefinitionsGroup [get]
 
ResourceNode BoneGroup [get]
 
ResourceNode MaterialGroup [get]
 
ResourceNode ShaderGroup [get]
 
ResourceNode VertexGroup [get]
 
ResourceNode NormalGroup [get]
 
ResourceNode UVGroup [get]
 
ResourceNode ColorGroup [get]
 
ResourceNode PolygonGroup [get]
 
ResourceNode TextureGroup [get]
 
ResourceNode PaletteGroup [get]
 
ResourceNode FurVecGroup [get]
 
ResourceNode FurPosGroup [get]
 
List< ResourceNodeDefinitionsList [get]
 
List< ResourceNodeBoneList [get]
 
List< MDL0BoneNodeAllBones [get]
 
List< ResourceNodeMaterialList [get]
 
List< ResourceNodeShaderList [get]
 
List< ResourceNodeVertexList [get]
 
List< ResourceNodeNormalList [get]
 
List< ResourceNodeUVList [get]
 
List< ResourceNodeColorList [get]
 
List< ResourceNodePolygonList [get]
 
List< ResourceNodeTextureList [get]
 
List< ResourceNodePaletteList [get]
 
List< ResourceNodeFurVecList [get]
 
List< ResourceNodeFurPosList [get]
 
IBoneNode[] BoneCache [get]
 
IBoneNode[] RootBones [get]
 
bool IsRendering [get, set]
 
bool IsTargetModel [get, set]
 
bool Attached [get]
 
int SelectedObjectIndex [get, set]
 
IObject[] Objects [get]
 
List< DrawCallBaseDrawCalls [get]
 
- Properties inherited from BrawlLib.SSBB.ResourceNodes.BRESEntryNode
virtual int DataAlign [get]
 
BRRESNode BRESNode [get]
 
virtual int[] SupportedVersions [get]
 
virtual string Tag [get]
 
int Version [get, set]
 
string OriginalPath [get, set]
 
UserDataCollection UserEntries [get, set]
 
- Properties inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
string FilePath [get]
 
string FileName [get]
 
string DirectoryName [get]
 
ResourceNode RootNode [get]
 
DataSource OriginalSource [get]
 
DataSource UncompressedSource [get]
 
DataSource WorkingSource [get]
 
DataSource WorkingUncompressed [get]
 
virtual bool HasChildren [get]
 
virtual ResourceType ResourceFileType [get]
 
string NodeType [get]
 
virtual string TreePathAbsolute [get]
 
virtual string TreePath [get]
 
virtual int Level [get]
 
virtual int MaxNameLength [get]
 
virtual bool AllowDuplicateNames [get]
 
virtual bool AllowNullNames [get]
 
virtual string Name [get, set]
 
ResourceNode Parent [get, set]
 
List< ResourceNodeChildren [get]
 
int Index [get]
 
int HexIndex [get]
 
bool IsCompressed [get]
 
bool HasChanged [get, set]
 
bool IsBranch [get]
 
bool HasMerged [get]
 
virtual bool AllowSaving [get, set]
 
virtual bool IsDirty [get, set]
 
virtual uint UncompressedSize [get]
 
virtual Type[] AllowedChildTypes [get]
 
virtual string Compression [get, set]
 
virtual bool RetainChildrenOnReplace [get]
 
virtual bool supportsCompression [get]
 
static MD5CryptoServiceProvider MD5Provider [get]
 
- Properties inherited from BrawlLib.Modeling.IModel
InfluenceManager Influences [get]
 
IBoneNode[] BoneCache [get]
 
IBoneNode[] RootBones [get]
 
IObject[] Objects [get]
 
int SelectedObjectIndex [get, set]
 
bool IsTargetModel [get, set]
 
- Properties inherited from BrawlLib.OpenGL.IRenderedObject
List< DrawCallBaseDrawCalls [get]
 
bool IsRendering [get, set]
 
bool Attached [get]
 

Events

EventHandler DrawCallsChanged
 
- Events inherited from BrawlLib.SSBB.ResourceNodes.ResourceNode
SelectEventHandler SelectChild
 
EventHandler UpdateProps
 
MoveEventHandler MovedUp
 
ResourceEventHandler Disposing
 
ResourceChildEventHandler ChildAdded
 
ResourceChildInsertEventHandler ChildInserted
 
- Events inherited from BrawlLib.OpenGL.IRenderedObject
EventHandler DrawCallsChanged
 

Constructor & Destructor Documentation

◆ MDL0Node()

BrawlLib.SSBB.ResourceNodes.MDL0Node.MDL0Node ( )
inline
32 {
33 _version = 9;
35 }
int _version
Definition: BRRESNode.cs:1045
ModelLinker _linker
Definition: MDL0Node.cs:45
Definition: ModelLinker.cs:33
static ModelLinker Prepare(MDL0Node model)
Definition: ModelLinker.cs:212

Member Function Documentation

◆ AddChild()

override void BrawlLib.SSBB.ResourceNodes.MDL0Node.AddChild ( ResourceNode  child,
bool  change 
)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

822 {
823 if (child is MDL0GroupNode)
824 {
825 LinkGroup(child as MDL0GroupNode);
826 }
827
828 base.AddChild(child, change);
829 }
void LinkGroup(MDL0GroupNode group)
Definition: MDL0Node.cs:2088

◆ ApplyCHR()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ApplyCHR ( CHR0Node  node,
float  index 
)
inline

Implements BrawlLib.Modeling.IModel.

3216 {
3217 _bindFrame = node == null || index == 0;
3218
3219 //Transform bones
3220 if (_boneList != null)
3221 {
3222 foreach (MDL0BoneNode b in _boneList)
3223 {
3224 b.ApplyCHR0(node, index);
3225 }
3226 }
3227
3228 WeightMeshes();
3229 }
List< ResourceNode > _boneList
Definition: MDL0Node.cs:303
void WeightMeshes(ModelPanelViewport v=null)
Definition: MDL0Node.cs:3231

◆ ApplyCLR()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ApplyCLR ( CLR0Node  node,
float  index 
)
inline

Implements BrawlLib.Modeling.IModel.

3270 {
3271 //Apply color changes
3272 if (_matList != null)
3273 {
3274 foreach (MDL0MaterialNode m in _matList)
3275 {
3276 m.ApplyCLR0(node, index);
3277 }
3278 }
3279 }
List< ResourceNode > _matList
Definition: MDL0Node.cs:304

◆ ApplyPAT()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ApplyPAT ( PAT0Node  node,
float  index 
)
inline

Implements BrawlLib.Modeling.IModel.

3282 {
3283 //Change textures
3284 if (_matList != null)
3285 {
3286 foreach (MDL0MaterialNode m in _matList)
3287 {
3288 m.ApplyPAT0(node, index);
3289 }
3290 }
3291 }

◆ ApplySCN()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ApplySCN ( SCN0Node  node,
float  index 
)
inline

Implements BrawlLib.Modeling.IModel.

3336 {
3337 _scn0 = node;
3338 _scn0Frame = index;
3339
3340 if (node != null)
3341 {
3342 _scn0Frame = _scn0Frame.Clamp(1, node.FrameCount);
3343 }
3344
3345 if (_matList != null)
3346 {
3347 foreach (MDL0MaterialNode mat in _matList)
3348 {
3349 mat.ApplySCN(node, _scn0Frame);
3350 }
3351 }
3352 }

◆ ApplySHP()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ApplySHP ( SHP0Node  node,
float  index 
)
inline

Implements BrawlLib.Modeling.IModel.

3358 {
3359 _currentSHP = node;
3360 _currentSHPIndex = index;
3361
3362 //Max amount of morphs allowed is technically 32
3363
3364 SHP0EntryNode entry;
3365
3366 if (_objList != null)
3367 {
3368 foreach (MDL0ObjectNode poly in _objList)
3369 {
3370 PrimitiveManager p = poly._manager;
3371 if (p?._vertices == null || p._faceData == null)
3372 {
3373 continue;
3374 }
3375
3376 //Reset this object's normal buffer to default
3377 //Vertices are already weighted in WeightMeshes
3378 //and colors aren't influenced by matrices,
3379 //so they can be retrieved directly from the external array later on
3380 for (int i = 0; i < p._vertices.Count; i++)
3381 {
3382 Vertex3 v = p._vertices[i];
3383 if (v.FaceDataIndices != null)
3384 {
3385 for (int m = 0; m < v.FaceDataIndices.Count; m++)
3386 {
3387 int fIndex = v.FaceDataIndices[m];
3388 if (fIndex < p._pointCount && fIndex >= 0)
3389 {
3390 if (p._faceData[1] != null && poly._normalNode != null)
3391 {
3392 int normalIndex = v.Facepoints[m]._normalIndex;
3393 if (normalIndex >= 0 && normalIndex < poly._normalNode.Normals.Length)
3394 {
3395 ((Vector3*) p._faceData[1].Address)[fIndex] =
3396 poly._normalNode.Normals[normalIndex];
3397 }
3398 }
3399
3400 if ((node == null || index == 0) && poly._colorSet != null)
3401 {
3402 for (int c = 0; c < 2; c++)
3403 {
3404 if (p._faceData[c + 2] != null && poly._colorSet[c] != null)
3405 {
3406 int colorIndex = v.Facepoints[m]._colorIndices[c];
3407 if (colorIndex >= 0 && colorIndex < poly._colorSet[c].Colors.Length)
3408 {
3409 ((RGBAPixel*) p._faceData[c + 2].Address)[fIndex] =
3410 poly._colorSet[c].Colors[colorIndex];
3411 }
3412 }
3413 }
3414 }
3415 }
3416 }
3417 }
3418 }
3419
3420 if (node == null || index == 0)
3421 {
3422 continue;
3423 }
3424
3425 if ((entry = node.FindChild(poly.VertexNode, true) as SHP0EntryNode) != null &&
3426 entry.Enabled && entry.UpdateVertices)
3427 {
3428 float[] weights = new float[entry.Children.Count];
3429 foreach (SHP0VertexSetNode shpSet in entry.Children)
3430 {
3431 weights[shpSet.Index] = shpSet.Keyframes.GetFrameValue(index - 1);
3432 }
3433
3434 float totalWeight = 0;
3435 foreach (float f in weights)
3436 {
3437 totalWeight += f;
3438 }
3439
3440 float baseWeight = 1.0f - totalWeight;
3441 float total = totalWeight + baseWeight;
3442
3443 MDL0VertexNode[] nodes = new MDL0VertexNode[entry.Children.Count];
3444 foreach (SHP0VertexSetNode shpSet in entry.Children)
3445 {
3446 nodes[shpSet.Index] = _vertList.Find(x => x.Name == shpSet.Name) as MDL0VertexNode;
3447 }
3448
3449 //Calculate barycenter per vertex and set as weighted pos
3450 if (p._vertices != null)
3451 {
3452 for (int i = 0; i < p._vertices.Count; i++)
3453 {
3454 int x = 0;
3455 Vertex3 v3 = p._vertices[i];
3456 v3._weightedPosition *= baseWeight;
3457
3458 foreach (MDL0VertexNode vNode in nodes)
3459 {
3460 if (vNode != null && v3.Facepoints[0]._vertexIndex < vNode.Vertices.Length)
3461 {
3462 v3._weightedPosition +=
3463 v3.GetMatrix() * vNode.Vertices[v3.Facepoints[0]._vertexIndex] *
3464 weights[x];
3465 }
3466
3467 x++;
3468 }
3469
3470 v3._weightedPosition /= total;
3471
3472 v3._weights = weights;
3473 v3._nodes = nodes;
3474 v3._baseWeight = baseWeight;
3475 v3._bCenter = v3._weightedPosition;
3476 }
3477 }
3478 }
3479
3480 if ((entry = node.FindChild(poly.NormalNode, true) as SHP0EntryNode) != null &&
3481 entry.Enabled && entry.UpdateNormals)
3482 {
3483 float[] weights = new float[entry.Children.Count];
3484 foreach (SHP0VertexSetNode shpSet in entry.Children)
3485 {
3486 weights[shpSet.Index] = shpSet.Keyframes.GetFrameValue(index - 1);
3487 }
3488
3489 float totalWeight = 0;
3490 foreach (float f in weights)
3491 {
3492 totalWeight += f;
3493 }
3494
3495 float baseWeight = 1.0f - totalWeight;
3496 float total = totalWeight + baseWeight;
3497
3498 MDL0NormalNode[] nodes = new MDL0NormalNode[entry.Children.Count];
3499 foreach (SHP0VertexSetNode shpSet in entry.Children)
3500 {
3501 nodes[shpSet.Index] = _normList.Find(x => x.Name == shpSet.Name) as MDL0NormalNode;
3502 }
3503
3504 UnsafeBuffer buf = p._faceData[1];
3505 if (buf != null)
3506 {
3507 Vector3* pData = (Vector3*) buf.Address;
3508
3509 if (p._vertices != null)
3510 {
3511 for (int i = 0; i < p._vertices.Count; i++)
3512 {
3513 Vertex3 v3 = p._vertices[i];
3514 int m = 0;
3515 foreach (Facepoint r in v3.Facepoints)
3516 {
3517 int nIndex = v3.FaceDataIndices[m++];
3518
3519 Vector3 weightedNormal =
3520 v3.GetMatrix().GetRotationMatrix() * pData[nIndex] * baseWeight;
3521
3522 int x = 0;
3523 foreach (MDL0NormalNode n in nodes)
3524 {
3525 if (n != null && r._normalIndex < n.Normals.Length)
3526 {
3527 weightedNormal +=
3529 n.Normals[r._normalIndex] *
3530 weights[x];
3531 }
3532
3533 x++;
3534 }
3535
3536 pData[nIndex] = v3.GetInvMatrix().GetRotationMatrix() *
3537 (weightedNormal / total).Normalize();
3538 }
3539 }
3540 }
3541 }
3542
3543 p._dirty[1] = true;
3544 }
3545
3546 for (int x = 0; x < 2; x++)
3547 {
3548 if (poly._colorSet[x] != null &&
3549 (entry = node.FindChild(poly._colorSet[x].Name, true) as SHP0EntryNode) != null &&
3550 entry.Enabled && entry.UpdateColors)
3551 {
3552 float[] weights = new float[entry.Children.Count];
3553 foreach (SHP0VertexSetNode shpSet in entry.Children)
3554 {
3555 weights[shpSet.Index] = shpSet.Keyframes.GetFrameValue(index - 1);
3556 }
3557
3558 float totalWeight = 0;
3559 foreach (float f in weights)
3560 {
3561 totalWeight += f;
3562 }
3563
3564 float baseWeight = 1.0f - totalWeight;
3565 float total = totalWeight + baseWeight;
3566
3567 MDL0ColorNode[] nodes = new MDL0ColorNode[entry.Children.Count];
3568 foreach (SHP0VertexSetNode shpSet in entry.Children)
3569 {
3570 nodes[shpSet.Index] = _colorList.Find(b => b.Name == shpSet.Name) as MDL0ColorNode;
3571 }
3572
3573 UnsafeBuffer buf = p._faceData[x + 2];
3574 if (buf != null)
3575 {
3576 RGBAPixel* pData = (RGBAPixel*) buf.Address;
3577
3578 if (p._vertices != null)
3579 {
3580 for (int i = 0; i < p._vertices.Count; i++)
3581 {
3582 Vertex3 v3 = p._vertices[i];
3583 int m = 0;
3584 foreach (Facepoint r in v3.Facepoints)
3585 {
3586 int cIndex = v3.FaceDataIndices[m++];
3587 if (cIndex < p._pointCount)
3588 {
3589 Vector4 color =
3590 (Vector4) poly._colorSet[x].Colors[r._colorIndices[x]] * baseWeight;
3591
3592 int w = 0;
3593 foreach (MDL0ColorNode n in nodes)
3594 {
3595 if (n != null && r._colorIndices[x] < n.Colors.Length)
3596 {
3597 color += (Vector4) n.Colors[r._colorIndices[x]] * weights[w];
3598 }
3599
3600 w++;
3601 }
3602
3603 pData[cIndex] = color / total;
3604 }
3605 }
3606 }
3607 }
3608 }
3609
3610 p._dirty[x + 2] = true;
3611 }
3612 }
3613 }
3614 }
3615 }
Definition: UnsafeBuffer.cs:7
VoidPtr Address
Definition: UnsafeBuffer.cs:9
Definition: Face.cs:10
int[] _colorIndices
Definition: Face.cs:31
int _normalIndex
Definition: Face.cs:30
Definition: PrimitiveManager.cs:20
int _pointCount
Definition: PrimitiveManager.cs:51
bool[] _dirty
Definition: PrimitiveManager.cs:60
List< Vertex3 > _vertices
Definition: PrimitiveManager.cs:48
UnsafeBuffer[] _faceData
Definition: PrimitiveManager.cs:59
Definition: Vertex.cs:13
Matrix GetMatrix()
Definition: Vertex.cs:47
List< Facepoint > Facepoints
Definition: Vertex.cs:35
List< int > FaceDataIndices
Definition: Vertex.cs:31
Vector3 _weightedPosition
Definition: Vertex.cs:15
Matrix GetInvMatrix()
Definition: Vertex.cs:58
List< ResourceNode > _colorList
Definition: MDL0Node.cs:313
List< ResourceNode > _vertList
Definition: MDL0Node.cs:309
List< ResourceNode > _objList
Definition: MDL0Node.cs:306
List< ResourceNode > _normList
Definition: MDL0Node.cs:310
Definition: PixelTypes.cs:327
Matrix GetRotationMatrix()
Definition: Matrix.cs:825
Definition: Vector3.cs:40
Definition: Vector4.cs:12

◆ ApplySRT()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ApplySRT ( SRT0Node  node,
float  index 
)
inline

Implements BrawlLib.Modeling.IModel.

3258 {
3259 //Transform textures
3260 if (_matList != null)
3261 {
3262 foreach (MDL0MaterialNode m in _matList)
3263 {
3264 m.ApplySRT0(node, index);
3265 }
3266 }
3267 }

◆ ApplyVIS()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ApplyVIS ( VIS0Node  node,
float  index 
)
inline

Implements BrawlLib.Modeling.IModel.

3294 {
3295 if (node == null || index < 1)
3296 {
3297 //if (_objList != null)
3298 // foreach (MDL0ObjectNode o in _objList)
3299 // if (o._visBoneNode != null)
3300 // o._render = o._visBoneNode._boneFlags.HasFlag(BoneFlags.Visible);
3301 return;
3302 }
3303
3304 if (VIS0Indices == null)
3305 {
3307 }
3308
3309 foreach (string boneName in VIS0Indices.Keys)
3310 {
3311 VIS0EntryNode entry = null;
3312 Dictionary<int, List<int>> objects = VIS0Indices[boneName];
3313 foreach (KeyValuePair<int, List<int>> objDrawCalls in objects)
3314 {
3315 MDL0ObjectNode obj = (MDL0ObjectNode) _objList[objDrawCalls.Key];
3316 for (int x = 0; x < objDrawCalls.Value.Count; x++)
3317 {
3318 DrawCall c = obj._drawCalls[objDrawCalls.Value[x]];
3319 if ((entry = (VIS0EntryNode) node.FindChild(c._visBoneNode.Name, true)) != null)
3320 {
3321 if (entry._entryCount != 0 && index > 0)
3322 {
3323 c._render = entry.GetEntry((int) index - 1);
3324 }
3325 else
3326 {
3327 c._render = entry._flags.HasFlag(VIS0Flags.Enabled);
3328 }
3329 }
3330 }
3331 }
3332 }
3333 }
void RegenerateVIS0Indices()
This only needs to be called when the model is currently attached to a model renderer and the amount ...
Definition: MDL0Node.cs:2982
Dictionary< string, Dictionary< int, List< int > > > VIS0Indices
Definition: MDL0Node.cs:2964
VIS0Flags
Definition: VIS0.cs:9

◆ Attach()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.Attach ( )
inline

Implements BrawlLib.OpenGL.IRenderedObject.

2967 {
2968 _attached = true;
2969 foreach (MDL0GroupNode g in Children)
2970 {
2971 g.Bind();
2972 }
2973
2975 }
List< ResourceNode > Children
Definition: ResourceNode.cs:262

◆ BeginImport()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.BeginImport ( )
inline
2600 {
2601 _isImport = true;
2602 InitGroups();
2603 }
bool _isImport
Definition: MDL0Node.cs:47

◆ CalculateBoundingBoxes()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.CalculateBoundingBoxes ( )
inline
399 {
400 ApplyCHR(null, 0);
401 _extents = GetBox();
402 if (_boneList != null)
403 {
404 foreach (MDL0BoneNode b in _boneList)
405 {
406 b.SetBox();
407 }
408 }
409
412 }
Box GetBox()
Call ApplyCHR0 before calling this
Definition: MDL0Node.cs:376
void ApplyCHR(CHR0Node node, float index)
Definition: MDL0Node.cs:3215
Box _extents
Definition: MDL0Node.cs:43
virtual void SignalPropertyChange()
Definition: ResourceNode.cs:313
void UpdateProperties()
Definition: ResourceNode.cs:477

◆ CheckTextures()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.CheckTextures ( )
inline
415 {
416 if (_texList != null)
417 {
418 for (int i = 0; i < _texList.Count; i++)
419 {
420 MDL0TextureNode t = (MDL0TextureNode) _texList[i];
421 for (int x = 0; x < t._references.Count; x++)
422 {
423 if (t._references[x].Parent == null)
424 {
425 t._references.RemoveAt(x--);
426 }
427 }
428
429 if (t._references.Count == 0)
430 {
431 _texList.RemoveAt(i--);
432 }
433 }
434 }
435 }
List< ResourceNode > _texList
Definition: MDL0Node.cs:307

◆ CleanTextures()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.CleanTextures ( )
inline
648 {
649 if (_texList != null)
650 {
651 int i = 0;
652 while (i < _texList.Count)
653 {
654 MDL0TextureNode texture = (MDL0TextureNode) _texList[i];
655
656 at1:
657 foreach (MDL0MaterialRefNode r in texture._references)
658 {
659 if (_matList.IndexOf(r.Parent) == -1)
660 {
661 texture._references.Remove(r);
662 goto at1;
663 }
664 }
665
666 if (texture._references.Count == 0)
667 {
668 _texList.RemoveAt(i);
669 }
670 else
671 {
672 i++;
673 }
674 }
675 }
676
677 if (_pltList != null)
678 {
679 int i = 0;
680 while (i < _pltList.Count)
681 {
682 MDL0TextureNode palette = (MDL0TextureNode) _pltList[i];
683
684 bt1:
685 foreach (MDL0MaterialRefNode r in palette._references)
686 {
687 if (_matList.IndexOf(r.Parent) == -1)
688 {
689 palette._references.Remove(r);
690 goto bt1;
691 }
692 }
693
694 if (palette._references.Count == 0)
695 {
696 _pltList.RemoveAt(i);
697 }
698 else
699 {
700 i++;
701 }
702 }
703 }
704 }
List< ResourceNode > _pltList
Definition: MDL0Node.cs:308

◆ ConvertToShadowModel()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ConvertToShadowModel ( )
inline
1454 {
1455 if (_matGroup == null)
1456 {
1457 Populate();
1458 if (_matGroup == null || _boneGroup == null || _objGroup == null)
1459 {
1460 return;
1461 }
1462 }
1463
1464 // Implementation with support for multiple culling types
1465 MDL0MaterialNode mat1 = new MDL0MaterialNode();
1466 _matGroup.AddChild(mat1);
1467 mat1.GenerateShadowMaterial();
1468 //mat1.Name += "_CullNone";
1469 mat1.CullMode = CullMode.Cull_None;
1470
1471 MDL0MaterialNode mat2 = new MDL0MaterialNode();
1472 _matGroup.AddChild(mat2);
1473 mat2.GenerateShadowMaterial();
1474 //mat2.Name += "_CullInside";
1475 mat2.CullMode = CullMode.Cull_Inside;
1476
1477 MDL0MaterialNode mat3 = new MDL0MaterialNode();
1478 _matGroup.AddChild(mat3);
1479 mat3.GenerateShadowMaterial();
1480 //mat3.Name += "_CullOutside";
1481 mat3.CullMode = CullMode.Cull_Outside;
1482
1483 MDL0MaterialNode mat4 = new MDL0MaterialNode();
1484 _matGroup.AddChild(mat4);
1485 mat4.GenerateShadowMaterial();
1486 //mat4.Name += "_CullAll";
1487 mat4.CullMode = CullMode.Cull_All;
1488
1489 // Properly remove all shaders
1490 if (ShaderList != null)
1491 {
1492 int shaderNum = ShaderGroup.Children.Count;
1493 for (int i = 0; i < shaderNum; i++)
1494 {
1495 ResourceNode s = ShaderGroup.Children[0];
1497 }
1498
1499 //Children.Remove(ShaderGroup);
1500 }
1501
1502 // Add a new shader
1503 if (_shadGroup == null)
1504 {
1505 MDL0GroupNode g = _shadGroup;
1506 if (g == null)
1507 {
1508 AddChild(g = new MDL0GroupNode(MDLResourceType.Shaders), true);
1509 _shadGroup = g;
1510 _shadList = g.Children;
1511 }
1512 }
1513
1514 if (_shadList.Count == 0)
1515 {
1516 if (_shadList != null && _matList != null && _shadList.Count < _matList.Count)
1517 {
1518 MDL0ShaderNode shader = new MDL0ShaderNode();
1519 _shadGroup.AddChild(shader);
1520 shader.DefaultAsShadow();
1521 shader.Rebuild(true);
1522 }
1523 }
1524
1525 mat1.ShaderNode = (MDL0ShaderNode) _shadList[0];
1526 mat2.ShaderNode = (MDL0ShaderNode) _shadList[0];
1527 mat3.ShaderNode = (MDL0ShaderNode) _shadList[0];
1528 mat4.ShaderNode = (MDL0ShaderNode) _shadList[0];
1529 mat1.Rebuild(true);
1530 mat2.Rebuild(true);
1531 mat3.Rebuild(true);
1532 mat4.Rebuild(true);
1533
1534 if (_objGroup == null)
1535 {
1536 return;
1537 }
1538
1539 bool usesCullOutside = false;
1540 bool usesCullInside = false;
1541 bool usesCullNone = false;
1542 bool usesCullAll = false;
1543 foreach (MDL0ObjectNode m in _objGroup.Children)
1544 {
1545 m.TextureMatrix0Enabled = false;
1546 m.TextureMatrix1Enabled = false;
1547 m.TextureMatrix2Enabled = false;
1548 m.TextureMatrix3Enabled = false;
1549 m.TextureMatrix4Enabled = false;
1550 m.TextureMatrix5Enabled = false;
1551 m.TextureMatrix6Enabled = false;
1552 m.TextureMatrix7Enabled = false;
1553
1554 m.TextureMatrix0Identity = false;
1555 m.TextureMatrix1Identity = false;
1556 m.TextureMatrix2Identity = false;
1557 m.TextureMatrix3Identity = false;
1558 m.TextureMatrix4Identity = false;
1559 m.TextureMatrix5Identity = false;
1560 m.TextureMatrix6Identity = false;
1561 m.TextureMatrix7Identity = false;
1562
1563 foreach (DrawCall c in m.DrawCalls)
1564 {
1565 CullMode cullToUse = c.MaterialNode.CullMode;
1566
1567 switch (cullToUse)
1568 {
1569 case CullMode.Cull_None:
1570 c.MaterialNode = mat1;
1571 usesCullNone = true;
1572 break;
1573 case CullMode.Cull_Inside:
1574 c.MaterialNode = mat2;
1575 usesCullInside = true;
1576 break;
1577 case CullMode.Cull_Outside:
1578 c.MaterialNode = mat3;
1579 usesCullOutside = true;
1580 break;
1581 case CullMode.Cull_All:
1582 c.MaterialNode = mat4;
1583 usesCullAll = true;
1584 break;
1585 default: break;
1586 }
1587
1588 c.DrawPass = DrawCall.DrawPassType.Transparent;
1589 }
1590 }
1591
1592 // Delete unused materials
1593 while (MaterialGroup.Children.Count > 4)
1594 {
1596 }
1597
1598 if (!usesCullAll)
1599 {
1601 }
1602
1603 if (!usesCullOutside)
1604 {
1606 }
1607
1608 if (!usesCullInside)
1609 {
1611 }
1612
1613 if (!usesCullNone)
1614 {
1616 }
1617
1618 if (MaterialGroup.Children.Count == 1 && MaterialGroup.Children[0].Name.IndexOf("_") > 0)
1619 {
1621 .Substring(0,
1622 MaterialGroup.Children[0].Name.IndexOf("_"));
1623 }
1624
1625 if (BoneGroup == null)
1626 {
1627 Populate();
1628 }
1629
1630 MDL0BoneNode b = (MDL0BoneNode) BoneGroup.Children[0];
1631 b.Name = b.Name + "_NShadow";
1632 b.Scale = new Vector3(b.Scale._x * 1.01f, b.Scale._y * 1.01f, b.Scale._z * 1.01f);
1633
1634 if (Name.Length > 4)
1635 {
1636 if (Name.Substring(Name.Length - 4) == " (2)")
1637 {
1638 Name = Name.Substring(0, Name.Length - 4);
1639 }
1640 }
1641
1642 Name = Name + "_Shadow";
1643 }
ResourceNode ShaderGroup
Definition: MDL0Node.cs:320
ResourceNode BoneGroup
Definition: MDL0Node.cs:318
MDL0GroupNode _matGroup
Definition: MDL0Node.cs:290
MDL0GroupNode _shadGroup
Definition: MDL0Node.cs:291
override void AddChild(ResourceNode child, bool change)
Definition: MDL0Node.cs:821
MDL0GroupNode _boneGroup
Definition: MDL0Node.cs:289
MDL0GroupNode _objGroup
Definition: MDL0Node.cs:292
List< ResourceNode > ShaderList
Definition: MDL0Node.cs:358
List< ResourceNode > _shadList
Definition: MDL0Node.cs:305
ResourceNode MaterialGroup
Definition: MDL0Node.cs:319
virtual string Name
Definition: ResourceNode.cs:223
virtual void AddChild(ResourceNode child)
Definition: ResourceNode.cs:757
void Populate(int levels=-1)
Definition: ResourceNode.cs:613
virtual void RemoveChild(ResourceNode child)
Definition: ResourceNode.cs:746
CullMode
Definition: MDL0.cs:958
MDLResourceType
Definition: ModelLinker.cs:15

◆ ConvertToSpyModel()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ConvertToSpyModel ( )
inline
1648 {
1649 if (_matGroup == null)
1650 {
1651 return;
1652 }
1653
1654 Name = Name + "Spy";
1655
1656 if (MultiTypeWorks)
1657 {
1659 return;
1660 }
1661
1662 // Material only works properly with the name SpyCloak, so it needs to select the correct culling type
1663 MDL0MaterialNode mat1 = new MDL0MaterialNode();
1664 _matGroup.AddChild(mat1);
1665 mat1.GenerateSpyMaterial();
1666 mat1.CullMode = CullMode.Cull_None;
1667
1668 MDL0MaterialNode matCulled = new MDL0MaterialNode();
1669 _matGroup.AddChild(matCulled);
1670 matCulled.GenerateSpyMaterial();
1671 matCulled.Name += "_CullAll";
1672 matCulled.CullMode = CullMode.Cull_All;
1673
1674 // Properly remove all shaders
1675 if (ShaderList != null)
1676 {
1677 int shaderNum = ShaderGroup.Children.Count;
1678 for (int i = 0; i < shaderNum; i++)
1679 {
1680 ResourceNode s = ShaderGroup.Children[0];
1682 }
1683
1684 //Children.Remove(ShaderGroup);
1685 }
1686
1687 // Add a new shader
1688 if (_shadGroup == null)
1689 {
1690 MDL0GroupNode g = _shadGroup;
1691 if (g == null)
1692 {
1693 AddChild(g = new MDL0GroupNode(MDLResourceType.Shaders), true);
1694 _shadGroup = g;
1695 _shadList = g.Children;
1696 }
1697 }
1698
1699 if (_shadList.Count == 0)
1700 {
1701 if (_shadList != null && _matList != null && _shadList.Count < _matList.Count)
1702 {
1703 MDL0ShaderNode shader = new MDL0ShaderNode();
1704 _shadGroup.AddChild(shader);
1705 shader.DefaultAsSpy();
1706 shader.Rebuild(true);
1707 }
1708 }
1709
1710 // Add the color
1711 MDL0GroupNode colorG = _colorGroup;
1712 if (colorG == null)
1713 {
1714 AddChild(colorG = new MDL0GroupNode(MDLResourceType.Colors), true);
1715 _colorGroup = colorG;
1716 _colorList = colorG.Children;
1717 }
1718
1719 MDL0ColorNode colorNode = new MDL0ColorNode
1720 {
1721 Name = Name + "_BodyM__" + Name + "_Spycloak",
1722 Colors = new RGBAPixel[] {new RGBAPixel {A = 255, R = 132, G = 130, B = 132}}
1723 };
1724 colorG.AddChild(colorNode, true);
1725
1726 mat1.ShaderNode = (MDL0ShaderNode) _shadList[0];
1727 mat1.Rebuild(true);
1728
1729 if (_objGroup == null)
1730 {
1731 return;
1732 }
1733
1734 bool usesCullOutside = false;
1735 bool usesCullInside = false;
1736 bool usesCullNone = false;
1737 bool usesCullAll = false;
1738 foreach (MDL0ObjectNode m in _objGroup.Children)
1739 {
1740 foreach (DrawCall c in m.DrawCalls)
1741 {
1742 CullMode cullToUse = c.MaterialNode.CullMode;
1743 c.MaterialNode = mat1;
1744 switch (cullToUse)
1745 {
1746 case CullMode.Cull_None:
1747 usesCullNone = true;
1748 break;
1749 case CullMode.Cull_Inside:
1750 usesCullInside = true;
1751 break;
1752 case CullMode.Cull_Outside:
1753 usesCullOutside = true;
1754 break;
1755 case CullMode.Cull_All:
1756 c.MaterialNode = matCulled;
1757 usesCullAll = true;
1758 break;
1759 default: break;
1760 }
1761
1762 c.DrawPass = DrawCall.DrawPassType.Opaque;
1763 }
1764
1765 for (int i = 0; i < 8; i++)
1766 {
1767 m.SetUVs(i, null, true);
1768 }
1769
1770 m.SetColors(0, colorNode.Name, true);
1771 m.SetColors(1, null, true);
1772
1773 m.TextureMatrix0Enabled = true;
1774 m.TextureMatrix1Enabled = true;
1775 m.TextureMatrix2Enabled = false;
1776 m.TextureMatrix3Enabled = false;
1777 m.TextureMatrix4Enabled = false;
1778 m.TextureMatrix5Enabled = false;
1779 m.TextureMatrix6Enabled = false;
1780 m.TextureMatrix7Enabled = false;
1781
1782 m.TextureMatrix0Identity = true;
1783 m.TextureMatrix1Identity = false;
1784 m.TextureMatrix2Identity = false;
1785 m.TextureMatrix3Identity = false;
1786 m.TextureMatrix4Identity = false;
1787 m.TextureMatrix5Identity = false;
1788 m.TextureMatrix6Identity = false;
1789 m.TextureMatrix7Identity = false;
1790 }
1791
1792 // Delete Unused Colors
1793 while (ColorGroup.Children.Count > 1)
1794 {
1796 }
1797
1798
1799 // Delete unused materials
1800 while (MaterialGroup.Children.Count > 2)
1801 {
1803 }
1804
1805 // Choose proper culling based on best usage
1806 if (usesCullNone || usesCullInside && usesCullOutside)
1807 {
1808 mat1.CullMode = CullMode.Cull_None;
1809 }
1810 else if (usesCullInside)
1811 {
1812 mat1.CullMode = CullMode.Cull_Inside;
1813 }
1814 else if (usesCullOutside)
1815 {
1816 mat1.CullMode = CullMode.Cull_Outside;
1817 }
1818
1819 if (!usesCullAll)
1820 {
1821 MaterialGroup.RemoveChild(matCulled);
1822 }
1823
1824 foreach (MDL0MaterialNode mat in _matGroup.Children)
1825 {
1826 foreach (MDL0MaterialRefNode matref in mat.Children)
1827 {
1828 matref.HasTextureMatrix = true;
1829 }
1830 }
1831 }
MDL0GroupNode _colorGroup
Definition: MDL0Node.cs:299
static bool MultiTypeWorks
Definition: MDL0Node.cs:1645
ResourceNode ColorGroup
Definition: MDL0Node.cs:324
void ConvertToSpyModelMultiType()
Definition: MDL0Node.cs:1833

◆ ConvertToSpyModelMultiType()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ConvertToSpyModelMultiType ( )
inline
1834 {
1835 if (_matGroup == null)
1836 {
1837 return;
1838 }
1839
1840 // Implementation with support for multiple culling types
1841 // Will all be named the same as the material appears to need to be named "Spycloak"
1842 MDL0MaterialNode mat1 = new MDL0MaterialNode();
1843 _matGroup.AddChild(mat1);
1844 mat1.GenerateSpyMaterial();
1845 //mat1.Name += "_CullNone";
1846 mat1.CullMode = CullMode.Cull_None;
1847
1848 MDL0MaterialNode mat2 = new MDL0MaterialNode();
1849 _matGroup.AddChild(mat2);
1850 mat2.GenerateSpyMaterial();
1851 //mat2.Name += "_CullInside";
1852 mat2.CullMode = CullMode.Cull_Inside;
1853
1854 MDL0MaterialNode mat3 = new MDL0MaterialNode();
1855 _matGroup.AddChild(mat3);
1856 mat3.GenerateSpyMaterial();
1857 //mat3.Name += "_CullOutside";
1858 mat3.CullMode = CullMode.Cull_Outside;
1859
1860 MDL0MaterialNode mat4 = new MDL0MaterialNode();
1861 _matGroup.AddChild(mat4);
1862 mat4.GenerateSpyMaterial();
1863 //mat4.Name += "_CullAll";
1864 mat4.CullMode = CullMode.Cull_All;
1865
1866 // Properly remove all shaders
1867 if (ShaderList != null)
1868 {
1869 int shaderNum = ShaderGroup.Children.Count;
1870 for (int i = 0; i < shaderNum; i++)
1871 {
1872 ResourceNode s = ShaderGroup.Children[0];
1874 }
1875
1876 //Children.Remove(ShaderGroup);
1877 }
1878
1879 // Add a new shader
1880 if (_shadGroup == null)
1881 {
1882 MDL0GroupNode g = _shadGroup;
1883 if (g == null)
1884 {
1885 AddChild(g = new MDL0GroupNode(MDLResourceType.Shaders), true);
1886 _shadGroup = g;
1887 _shadList = g.Children;
1888 }
1889 }
1890
1891 if (_shadList.Count == 0)
1892 {
1893 if (_shadList != null && _matList != null && _shadList.Count < _matList.Count)
1894 {
1895 MDL0ShaderNode shader = new MDL0ShaderNode();
1896 _shadGroup.AddChild(shader);
1897 shader.DefaultAsSpy();
1898 shader.Rebuild(true);
1899 }
1900 }
1901
1902 // Add the color
1903 MDL0GroupNode colorG = _colorGroup;
1904 if (colorG == null)
1905 {
1906 AddChild(colorG = new MDL0GroupNode(MDLResourceType.Colors), true);
1907 _colorGroup = colorG;
1908 _colorList = colorG.Children;
1909 }
1910
1911 MDL0ColorNode colorNode = new MDL0ColorNode
1912 {
1913 Name = Name + "_BodyM__" + Name + "_Spycloak",
1914 Colors = new RGBAPixel[] {new RGBAPixel {A = 255, R = 132, G = 130, B = 132}}
1915 };
1916 colorG.AddChild(colorNode, true);
1917
1918 mat1.ShaderNode = (MDL0ShaderNode) _shadList[0];
1919 mat2.ShaderNode = (MDL0ShaderNode) _shadList[0];
1920 mat3.ShaderNode = (MDL0ShaderNode) _shadList[0];
1921 mat4.ShaderNode = (MDL0ShaderNode) _shadList[0];
1922 mat1.Rebuild(true);
1923 mat2.Rebuild(true);
1924 mat3.Rebuild(true);
1925 mat4.Rebuild(true);
1926
1927 if (_objGroup == null)
1928 {
1929 return;
1930 }
1931
1932 bool usesCullOutside = false;
1933 bool usesCullInside = false;
1934 bool usesCullNone = false;
1935 bool usesCullAll = false;
1936 foreach (MDL0ObjectNode m in _objGroup.Children)
1937 {
1938 foreach (DrawCall c in m.DrawCalls)
1939 {
1940 CullMode cullToUse = c.MaterialNode.CullMode;
1941 switch (cullToUse)
1942 {
1943 case CullMode.Cull_None:
1944 c.MaterialNode = mat1;
1945 usesCullNone = true;
1946 break;
1947 case CullMode.Cull_Inside:
1948 c.MaterialNode = mat2;
1949 usesCullInside = true;
1950 break;
1951 case CullMode.Cull_Outside:
1952 c.MaterialNode = mat3;
1953 usesCullOutside = true;
1954 break;
1955 case CullMode.Cull_All:
1956 c.MaterialNode = mat4;
1957 usesCullAll = true;
1958 break;
1959 default: break;
1960 }
1961
1962 c.DrawPass = DrawCall.DrawPassType.Opaque;
1963 }
1964
1965 for (int i = 0; i < 8; i++)
1966 {
1967 m.SetUVs(i, null, true);
1968 }
1969
1970 m.SetColors(0, colorNode.Name, true);
1971 m.SetColors(1, null, true);
1972
1973 m.TextureMatrix0Enabled = true;
1974 m.TextureMatrix1Enabled = true;
1975 m.TextureMatrix2Enabled = false;
1976 m.TextureMatrix3Enabled = false;
1977 m.TextureMatrix4Enabled = false;
1978 m.TextureMatrix5Enabled = false;
1979 m.TextureMatrix6Enabled = false;
1980 m.TextureMatrix7Enabled = false;
1981
1982 m.TextureMatrix0Identity = true;
1983 m.TextureMatrix1Identity = false;
1984 m.TextureMatrix2Identity = false;
1985 m.TextureMatrix3Identity = false;
1986 m.TextureMatrix4Identity = false;
1987 m.TextureMatrix5Identity = false;
1988 m.TextureMatrix6Identity = false;
1989 m.TextureMatrix7Identity = false;
1990 }
1991
1992 // Delete Unused Colors
1993 while (ColorGroup.Children.Count > 1)
1994 {
1996 }
1997
1998 // Delete unused materials
1999 while (MaterialGroup.Children.Count > 4)
2000 {
2002 }
2003
2004 if (!usesCullAll)
2005 {
2007 }
2008
2009 if (!usesCullOutside)
2010 {
2012 }
2013
2014 if (!usesCullInside)
2015 {
2017 }
2018
2019 if (!usesCullNone)
2020 {
2022 }
2023
2024 if (MaterialGroup.Children.Count == 1 && MaterialGroup.Children[0].Name.IndexOf("_") > 0)
2025 {
2027 .Substring(0,
2028 MaterialGroup.Children[0].Name.IndexOf("_"));
2029 }
2030
2031 foreach (MDL0MaterialNode mat in _matGroup.Children)
2032 {
2033 foreach (MDL0MaterialRefNode matref in mat.Children)
2034 {
2035 matref.HasTextureMatrix = true;
2036 }
2037 }
2038 }

◆ Detach()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.Detach ( )
inline

Implements BrawlLib.OpenGL.IRenderedObject.

3019 {
3020 _attached = false;
3021 foreach (MDL0GroupNode g in Children)
3022 {
3023 g.Unbind();
3024 }
3025 }

◆ DrawBox()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.DrawBox ( bool  bindState)
inline
3206 {
3207 Box box = bindState ? _extents : GetBox();
3208 //if (box.IsValid)
3210 }
Definition: TKContext.cs:15
static void DrawWireframeBox(Box value)
Definition: TKContext.cs:230
Definition: Box.cs:6

◆ Export()

override void BrawlLib.SSBB.ResourceNodes.MDL0Node.Export ( string  outPath)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.BRESEntryNode.

2785 {
2786 if (outPath.ToUpper().EndsWith(".DAE"))
2787 {
2788 Collada.Serialize(this, outPath);
2789 }
2790 //else if (outPath.ToUpper().EndsWith(".PMD"))
2791 // PMDModel.Export(this, outPath);
2792 //else if (outPath.ToUpper().EndsWith(".RMDL"))
2793 // XMLExporter.ExportRMDL(this, outPath);
2794 else
2795 {
2796 base.Export(outPath);
2797 }
2798 }
Definition: ColladaAssetDecoder.cs:10
static void Serialize(MDL0Node model, string outFile)
Definition: ColladaExporter.cs:20

◆ FindBone()

MDL0BoneNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FindBone ( string  name)
inline
753 {
754 foreach (MDL0BoneNode b in _linker.BoneCache)
755 {
756 if (b.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
757 {
758 return b;
759 }
760 }
761
762 return null;
763 }
MDL0BoneNode[] BoneCache
Definition: ModelLinker.cs:141

◆ FindBoneByIndex()

MDL0BoneNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FindBoneByIndex ( int  givenIndex)
inline
766 {
767 // Generate bones if the model hasn't been seen yet
768 if (_boneGroup == null)
769 {
770 Populate();
772 }
773
774 foreach (MDL0BoneNode b in BoneCache)
775 {
776 if (b.BoneIndex == givenIndex)
777 {
778 return b;
779 }
780 }
781
782 return null;
783 }
IBoneNode[] BoneCache
Definition: MDL0Node.cs:2916
void RegenerateBoneCache(bool remake=false)
Definition: ModelLinker.cs:185

◆ FindOrCreateOpaMaterial()

MDL0MaterialNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FindOrCreateOpaMaterial ( string  name)
inline
786 {
787 foreach (MDL0MaterialNode m in _matList)
788 {
789 if (m.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
790 {
791 return m;
792 }
793 }
794
795 MDL0MaterialNode node = new MDL0MaterialNode {_name = _matGroup.FindName(name)};
796 _matGroup.AddChild(node, false);
797
799
800 return node;
801 }
unsafe string FindName(string name)
Definition: ResourceNode.cs:1578
string _name
Definition: ResourceNode.cs:139

◆ FindOrCreatePalette()

MDL0TextureNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FindOrCreatePalette ( string  name)
inline
730 {
731 if (_pltGroup == null)
732 {
733 AddChild(_pltGroup = new MDL0GroupNode(MDLResourceType.Palettes), false);
734 }
735 else
736 {
737 foreach (MDL0TextureNode n in _pltGroup.Children)
738 {
739 if (n._name == name)
740 {
741 return n;
742 }
743 }
744 }
745
746 MDL0TextureNode node = new MDL0TextureNode(name);
747 _pltGroup.AddChild(node, false);
748
749 return node;
750 }
MDL0GroupNode _pltGroup
Definition: MDL0Node.cs:294

◆ FindOrCreateTexture()

MDL0TextureNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FindOrCreateTexture ( string  name)
inline
707 {
708 if (_texGroup == null)
709 {
710 AddChild(_texGroup = new MDL0GroupNode(MDLResourceType.Textures), false);
711 }
712 else
713 {
714 foreach (MDL0TextureNode n in _texGroup.Children)
715 {
716 if (n._name == name)
717 {
718 return n;
719 }
720 }
721 }
722
723 MDL0TextureNode node = new MDL0TextureNode(name);
724 _texGroup.AddChild(node, false);
725
726 return node;
727 }
MDL0GroupNode _texGroup
Definition: MDL0Node.cs:293

◆ FindOrCreateXluMaterial()

MDL0MaterialNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FindOrCreateXluMaterial ( string  name)
inline
804 {
805 foreach (MDL0MaterialNode m in _matList)
806 {
807 if (m.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
808 {
809 return m;
810 }
811 }
812
813 MDL0MaterialNode node = new MDL0MaterialNode {_name = _matGroup.FindName(name), XLUMaterial = true};
814 _matGroup.AddChild(node, false);
815
817
818 return node;
819 }

◆ FinishImport()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.FinishImport ( Collada  form = null)
inline
2606 {
2607 //Prepare for rebuild
2608 CleanTextures();
2609 CleanGroups();
2611 _influences.Sort();
2612 _linker = ModelLinker.Prepare(this);
2613
2614 //Calculate size and get strings
2615 int size = (_calcSize = ModelEncoder.CalcSize(form, _linker)).Align(4);
2616 StringTable table = new StringTable();
2617 GetStrings(table);
2618
2619 //Create temp file and write model and string table, then post process strings, etc
2620 FileMap uncompMap = FileMap.FromTempFile(size + table.GetTotalSize());
2621 ModelEncoder.Build(form, _linker, (MDL0Header*) uncompMap.Address, _calcSize, true);
2622 table.WriteTable(uncompMap.Address + size);
2623 PostProcess(null, uncompMap.Address, _calcSize, table);
2624
2625 table.Clear();
2626 _isImport = false;
2627
2628 _origSource = _uncompSource = new DataSource(uncompMap);
2629
2630 if (_children != null)
2631 {
2632 foreach (ResourceNode node in _children)
2633 {
2634 node.Dispose();
2635 }
2636
2637 _children.Clear();
2638 _children = null;
2639 }
2640
2641 if (!OnInitialize())
2642 {
2643 _children = new List<ResourceNode>();
2644 }
2645
2646 IsDirty = false;
2647 }
Definition: FileMap.cs:10
static FileMap FromTempFile(int length)
Definition: FileMap.cs:96
VoidPtr Address
Definition: FileMap.cs:16
void CleanTextures()
Definition: MDL0Node.cs:647
InfluenceManager _influences
Definition: MDL0Node.cs:50
override bool OnInitialize()
Definition: MDL0Node.cs:2440
virtual bool IsDirty
Definition: ResourceNode.cs:344
int _calcSize
Definition: ResourceNode.cs:145
List< ResourceNode > _children
Definition: ResourceNode.cs:143
void Sort()
Definition: InfluenceManager.cs:89
void Clean()
Definition: InfluenceManager.cs:72
Definition: ModelEncoder.cs:15
static int CalcSize(ModelLinker linker)
Definition: ModelEncoder.cs:66
Definition: MDL0.cs:15

◆ FromFile()

static MDL0Node BrawlLib.SSBB.ResourceNodes.MDL0Node.FromFile ( string  path,
FileOptions  options = FileOptions.RandomAccess 
)
inlinestatic
2650 {
2651 if (path.EndsWith(".dae", StringComparison.OrdinalIgnoreCase))
2652 {
2653 return new Collada {Text = $"Import Settings - {Path.GetFileName(path)}"}.ShowDialog(path,
2654 Collada.ImportType.MDL0) as MDL0Node;
2655 }
2656
2657 if (path.EndsWith(".pmd", StringComparison.OrdinalIgnoreCase))
2658 {
2659 return PMDModel.ImportModel(path);
2660 }
2661
2662 return NodeFactory.FromFile(null, path, options) as MDL0Node;
2663 }
IModel ShowDialog(string filePath, ImportType type)
Definition: ColladaImportDialog.cs:61
ImportType
Definition: ColladaImporter.cs:25
Definition: PMDModel.cs:19
static MDL0Node ImportModel(string filepath)
Definition: PMDModel.cs:22
MDL0Node()
Definition: MDL0Node.cs:31

◆ GenerateMetalMaterials() [1/2]

void BrawlLib.SSBB.ResourceNodes.MDL0Node.GenerateMetalMaterials ( )
inline
455 {
456 GenerateMetalMaterials(string.IsNullOrEmpty(_metalMat) ? "metal00" : _metalMat);
457 }
string _metalMat
Definition: MDL0Node.cs:102
void GenerateMetalMaterials()
Definition: MDL0Node.cs:454

◆ GenerateMetalMaterials() [2/2]

void BrawlLib.SSBB.ResourceNodes.MDL0Node.GenerateMetalMaterials ( string  metalTextureName)
inline
460 {
461 if (_children == null)
462 {
463 Populate();
464 }
465
466 if (_matList == null)
467 {
468 return;
469 }
470
471 List<MDL0MaterialNode> metalMats = new List<MDL0MaterialNode>();
472 foreach (MDL0MaterialNode m in _matList)
473 {
474 if (m.IsMetal)
475 {
476 metalMats.Add(m);
477 }
478 }
479
480 foreach (MDL0MaterialNode m in metalMats)
481 {
482 m.Remove(true);
483 }
484
485 for (int x = 0; x < _matList.Count; x++)
486 {
487 MDL0MaterialNode n = (MDL0MaterialNode) _matList[x];
488 if (!n.IsMetal && n.MetalMaterial == null)
489 {
490 MDL0MaterialNode node = new MDL0MaterialNode
491 {
492 _updating = true,
493 Name = n.Name + "_ExtMtl",
494 _activeStages = 4
495 };
496
497 _matGroup.AddChild(node);
498 for (int i = 0; i <= n.Children.Count; i++)
499 {
500 if (i != n.Children.Count &&
501 ((MDL0MaterialRefNode) n.Children[i]).MapMode == MappingMethod.EnvCamera)
502 {
503 continue;
504 }
505
506 MDL0MaterialRefNode mr = new MDL0MaterialRefNode();
507 node.AddChild(mr);
508 mr.Texture = metalTextureName;
509
510 mr._uWrap = 0;
511 mr._vWrap = 0;
512 mr._minFltr = 0;
513 mr._magFltr = 0;
514 mr._texMtxFlags.SourceRow = TexSourceRow.TexCoord0;
515 mr.EmbossSource = 5;
516
517 if (i == n.Children.Count || ((MDL0MaterialRefNode) n.Children[i]).HasTextureMatrix)
518 {
519 mr._minFltr = 5;
520 mr._magFltr = 1;
521 mr._lodBias = -2;
522
523 mr.HasTextureMatrix = true;
524 node.Rebuild(true);
525
526 mr._texMtxFlags = new XFTexMtxInfo
527 {
528 Projection = TexProjection.STQ,
529 InputForm = TexInputForm.ABC1,
530 TexGenType = TexTexgenType.Regular,
531 SourceRow = TexSourceRow.Normals,
532 EmbossSource = 5,
533 EmbossLight = 0
534 };
535
536 mr._dualTexFlags._normalEnable = 1;
537 mr._texMatrixEffect.MapMode = MappingMethod.EnvCamera;
538
539 break;
540 }
541 }
542
543 node._chan1 = new LightChannel(63, new RGBAPixel(128, 128, 128, 255),
544 new RGBAPixel(255, 255, 255, 255), 0, 0, node);
545 node.C1ColorEnabled = true;
546 node.C1ColorDiffuseFunction = GXDiffuseFn.Clamped;
547 node.C1ColorAttenuation = GXAttnFn.Spotlight;
548 node.C1AlphaEnabled = true;
549 node.C1AlphaDiffuseFunction = GXDiffuseFn.Clamped;
550 node.C1AlphaAttenuation = GXAttnFn.Spotlight;
551
552 node._chan2 = new LightChannel(63, new RGBAPixel(255, 255, 255, 255), new RGBAPixel(), 0, 0, node);
553 node.C2ColorEnabled = true;
554 node.C2ColorDiffuseFunction = GXDiffuseFn.Disabled;
555 node.C2ColorAttenuation = GXAttnFn.Specular;
556 node.C2AlphaDiffuseFunction = GXDiffuseFn.Disabled;
557 node.C2AlphaAttenuation = GXAttnFn.Specular;
558
559 node._lightSetIndex = n._lightSetIndex;
560 node._fogIndex = n._fogIndex;
561
562 node._cull = n._cull;
563 node.CompareBeforeTexture = true;
564 node._normMapRefLight1 =
565 node._normMapRefLight2 =
566 node._normMapRefLight3 =
567 node._normMapRefLight4 = -1;
568 }
569 }
570
571 foreach (MDL0MaterialNode node in _matList)
572 {
573 if (!node.IsMetal)
574 {
575 continue;
576 }
577
578 if (node.ShaderNode != null)
579 {
580 if (node.ShaderNode._autoMetal && node.ShaderNode._texCount == node.Children.Count)
581 {
582 node._updating = false;
583 continue;
584 }
585
586 if (node.ShaderNode.Stages == 4)
587 {
588 foreach (MDL0MaterialNode y in node.ShaderNode._materials)
589 {
590 if (!y.IsMetal || y.Children.Count != node.Children.Count)
591 {
592 goto Next;
593 }
594 }
595
596 node.ShaderNode.DefaultAsMetal(node.Children.Count);
597 continue;
598 }
599 }
600
601 Next:
602 bool found = false;
603 foreach (MDL0ShaderNode s in _shadGroup.Children)
604 {
605 if (s._autoMetal && s._texCount == node.Children.Count)
606 {
607 node.ShaderNode = s;
608 found = true;
609 }
610 else
611 {
612 if (s.Stages == 4)
613 {
614 foreach (MDL0MaterialNode y in s._materials)
615 {
616 if (!y.IsMetal || y.Children.Count != node.Children.Count)
617 {
618 goto NotFound;
619 }
620 }
621
622 node.ShaderNode = s;
623 found = true;
624 goto End;
625 NotFound:
626 continue;
627 }
628 }
629 }
630
631 End:
632 if (!found)
633 {
634 MDL0ShaderNode shader = new MDL0ShaderNode();
635 _shadGroup.AddChild(shader);
636 shader.DefaultAsMetal(node.Children.Count);
637 node.ShaderNode = shader;
638 }
639 }
640
641 foreach (MDL0MaterialNode m in _matList)
642 {
643 m._updating = false;
644 }
645 }
GXDiffuseFn
Definition: MDL0MaterialNode.cs:2902
GXAttnFn
Definition: MDL0MaterialNode.cs:2909
MappingMethod
Definition: MDL0MaterialRefNode.cs:1024
TexInputForm
Definition: Enum.cs:560
TexSourceRow
Definition: Enum.cs:574
TexProjection
Definition: Enum.cs:554
TexTexgenType
Definition: Enum.cs:566

◆ GetBox()

Box BrawlLib.SSBB.ResourceNodes.MDL0Node.GetBox ( )
inline

Call ApplyCHR0 before calling this

Implements BrawlLib.OpenGL.IRenderedObject.

377 {
378 if (_objList == null)
379 {
380 return new Box();
381 }
382
384 foreach (MDL0ObjectNode o in _objList)
385 {
386 if (o._manager?._vertices != null)
387 {
388 foreach (Vertex3 vertex in o._manager._vertices)
389 {
390 box.ExpandVolume(vertex.WeightedPosition);
391 }
392 }
393 }
394
395 return box;
396 }
Vector3 WeightedPosition
Definition: Vertex.cs:222
static readonly Box ExpandableVolume
Definition: Box.cs:7
void ExpandVolume(Vector3 value)
Definition: Box.cs:29

◆ GetUsedShaders()

List< ResourceNode > BrawlLib.SSBB.ResourceNodes.MDL0Node.GetUsedShaders ( )
inline
438 {
439 List<ResourceNode> shaders = new List<ResourceNode>();
440 if (_shadList != null)
441 {
442 foreach (MDL0ShaderNode s in _shadList)
443 {
444 if (s._materials.Count > 0)
445 {
446 shaders.Add(s);
447 }
448 }
449 }
450
451 return shaders;
452 }

◆ LinkGroup()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.LinkGroup ( MDL0GroupNode  group)
inline
2089 {
2090 switch (group._type)
2091 {
2092 case MDLResourceType.Definitions:
2093 {
2094 _defGroup = group;
2095 _defList = group._children;
2096 break;
2097 }
2098
2099 case MDLResourceType.Bones:
2100 {
2101 _boneGroup = group;
2102 _boneList = group._children;
2103 break;
2104 }
2105
2106 case MDLResourceType.Materials:
2107 {
2108 _matGroup = group;
2109 _matList = group._children;
2110 break;
2111 }
2112
2113 case MDLResourceType.Shaders:
2114 {
2115 _shadGroup = group;
2116 _shadList = group._children;
2117 break;
2118 }
2119
2120 case MDLResourceType.Vertices:
2121 {
2122 _vertGroup = group;
2123 _vertList = group._children;
2124 break;
2125 }
2126
2127 case MDLResourceType.Normals:
2128 {
2129 _normGroup = group;
2130 _normList = group._children;
2131 break;
2132 }
2133
2134 case MDLResourceType.UVs:
2135 {
2136 _uvGroup = group;
2137 _uvList = group._children;
2138 break;
2139 }
2140
2141 case MDLResourceType.Colors:
2142 {
2143 _colorGroup = group;
2144 _colorList = group._children;
2145 break;
2146 }
2147
2148 case MDLResourceType.Objects:
2149 {
2150 _objGroup = group;
2151 _objList = group._children;
2152 break;
2153 }
2154
2155 case MDLResourceType.Textures:
2156 {
2157 _texGroup = group;
2158 _texList = group._children;
2159 break;
2160 }
2161
2162 case MDLResourceType.Palettes:
2163 {
2164 _pltGroup = group;
2165 _pltList = group._children;
2166 break;
2167 }
2168
2169 case MDLResourceType.FurLayerCoords:
2170 {
2171 _furPosGroup = group;
2172 _furPosList = group._children;
2173 break;
2174 }
2175
2176 case MDLResourceType.FurVectors:
2177 {
2178 _furVecGroup = group;
2179 _furVecList = group._children;
2180 break;
2181 }
2182 }
2183 }
MDL0GroupNode _vertGroup
Definition: MDL0Node.cs:295
MDL0GroupNode _uvGroup
Definition: MDL0Node.cs:297
List< ResourceNode > _furVecList
Definition: MDL0Node.cs:315
List< ResourceNode > _furPosList
Definition: MDL0Node.cs:314
MDL0GroupNode _defGroup
Definition: MDL0Node.cs:298
List< ResourceNode > _defList
Definition: MDL0Node.cs:312
MDL0GroupNode _furPosGroup
Definition: MDL0Node.cs:300
MDL0GroupNode _normGroup
Definition: MDL0Node.cs:296
MDL0GroupNode _furVecGroup
Definition: MDL0Node.cs:301
List< ResourceNode > _uvList
Definition: MDL0Node.cs:311

◆ OnCalculateSize()

override int BrawlLib.SSBB.ResourceNodes.MDL0Node.OnCalculateSize ( bool  force)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

2801 {
2802 //Clean and sort influence list
2804 //_influences.Sort();
2805
2806 //Clean texture list
2807 CleanTextures();
2808
2809 _linker = ModelLinker.Prepare(this);
2811 }

◆ OnDrawCallsChanged()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.OnDrawCallsChanged ( )
inline
3625 {
3626 DrawCallsChanged?.Invoke(this, null);
3627 }
EventHandler DrawCallsChanged
Definition: MDL0Node.cs:3629

◆ OnInitialize()

override bool BrawlLib.SSBB.ResourceNodes.MDL0Node.OnInitialize ( )
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.BRESEntryNode.

2441 {
2442 base.OnInitialize();
2443
2444 _billboardBones = new List<MDL0BoneNode>();
2445 _errors = new List<string>();
2447
2448 MDL0Header* header = Header;
2449
2450 if (_name == null && header->StringOffset != 0)
2451 {
2452 _name = header->ResourceString;
2453 }
2454
2455 MDL0Props* props = header->Properties;
2456
2457 if (props != null)
2458 {
2459 _scalingRule = props->_scalingRule;
2460 _texMtxMode = props->_texMatrixMode;
2463 _numNodes = props->_numNodes;
2464 _needsNrmMtxArray = props->_needNrmMtxArray != 0;
2465 _needsTexMtxArray = props->_needTexMtxArray != 0;
2466 _extents = props->_extents;
2467 _enableExtents = props->_enableExtents != 0;
2468 _envMtxMode = props->_envMtxMode;
2469
2470 if (props->_origPathOffset > 0 && props->_origPathOffset < WorkingUncompressed.Length)
2471 {
2472 _originalPath = props->OrigPath;
2473 }
2474 else if (props->_origPathOffset > 0)
2475 {
2476 _errors.Add("Original path was found to be out of range");
2477 }
2478 }
2479
2480 (_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);
2481
2482 return true;
2483 }
string _originalPath
Definition: BRRESNode.cs:1046
byte _envMtxMode
Definition: MDL0Node.cs:40
bool _needsTexMtxArray
Definition: MDL0Node.cs:41
int _numTriangles
Definition: MDL0Node.cs:42
bool _enableExtents
Definition: MDL0Node.cs:41
List< MDL0BoneNode > _billboardBones
Definition: MDL0Node.cs:49
bool _needsNrmMtxArray
Definition: MDL0Node.cs:41
int _numNodes
Definition: MDL0Node.cs:42
List< string > _errors
Definition: MDL0Node.cs:51
int _numFacepoints
Definition: MDL0Node.cs:42
DataSource WorkingUncompressed
Definition: ResourceNode.cs:183
Managed collection of influences. Only influences with references should be used. It is up to the imp...
Definition: InfluenceManager.cs:16
int Length
Definition: ResourceNode.cs:32
VoidPtr UserData
Definition: MDL0.cs:61
MDL0Props * Properties
Definition: MDL0.cs:132
int StringOffset
Definition: MDL0.cs:98
string ResourceString
Definition: MDL0.cs:42
Definition: MDL0.cs:221
byte _envMtxMode
Definition: MDL0.cs:235
byte _needNrmMtxArray
Definition: MDL0.cs:232
bint _numTriangles
Definition: MDL0.cs:229
bint _scalingRule
Definition: MDL0.cs:226
bint _texMatrixMode
Definition: MDL0.cs:227
string OrigPath
Definition: MDL0.cs:280
byte _enableExtents
Definition: MDL0.cs:234
bint _origPathOffset
Definition: MDL0.cs:230
bint _numVertices
Definition: MDL0.cs:228
bint _numNodes
Definition: MDL0.cs:231
byte _needTexMtxArray
Definition: MDL0.cs:233
BBox _extents
Definition: MDL0.cs:237

◆ OnPopulate()

override void BrawlLib.SSBB.ResourceNodes.MDL0Node.OnPopulate ( )
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

2486 {
2487 try
2488 {
2489 InitGroups();
2490 _linker = new ModelLinker(Header) {Model = this};
2492
2493 //Set def flags
2494 _hasMix = _hasOpa = _hasTree = _hasXlu = false;
2495 if (_linker.Defs != null)
2496 {
2497 foreach (ResourcePair p in *_linker.Defs)
2498 {
2499 if (p.Name == "NodeTree")
2500 {
2501 _hasTree = true;
2502 }
2503 else if (p.Name == "NodeMix")
2504 {
2505 _hasMix = true;
2506 }
2507 else if (p.Name == "DrawOpa")
2508 {
2509 _hasOpa = true;
2510 }
2511 else if (p.Name == "DrawXlu")
2512 {
2513 _hasXlu = true;
2514 }
2515 }
2516 }
2517
2518 //These cause some complications if not parsed...
2519 _texGroup.Parse(this);
2520 _pltGroup.Parse(this);
2521
2522 _defGroup.Parse(this);
2523 _boneGroup.Parse(this);
2524 _matGroup.Parse(this);
2525 _shadGroup.Parse(this);
2526 _vertGroup.Parse(this);
2527 _normGroup.Parse(this);
2528 _uvGroup.Parse(this);
2529 _colorGroup.Parse(this);
2530
2531 if (Version >= 10)
2532 {
2533 _furVecGroup.Parse(this);
2534 _furPosGroup.Parse(this);
2535 }
2536
2537 _objGroup.Parse(this); //Parse objects last!
2538
2539 _texList.Sort();
2540 _pltList.Sort();
2541
2542 if (_matGroup != null)
2543 {
2544 foreach (MDL0MaterialNode m in _matGroup.Children)
2545 {
2546 if (m.IsMetal && m.Children != null && m.Children.Count > 0)
2547 {
2548 _metalMat = m.Children[m.Children.Count - 1].Name;
2549 break;
2550 }
2551 }
2552 }
2553 }
2554 catch (Exception ex)
2555 {
2556 _errors.Add("Something went wrong parsing the model: " + ex);
2557 }
2558 finally //Clean up!
2559 {
2560 //We'll use the linker to access the bone cache
2561 //_linker = null;
2562
2563 //Don't dispose assets, in case an object is replaced
2564 //_assets.Dispose();
2565 //_assets = null;
2566
2567 CleanGroups();
2568
2569 //Check for model errors
2570 if (_errors.Count > 0)
2571 {
2572 if (!SupportedVersions.Contains(_version))
2573 {
2574 MessageBox.Show("The model " + _name + " has a version of " + _version +
2575 " which is not supported. The model may be corrupt and data maybe be lost if you save the model.");
2576 }
2577 else
2578 {
2579 string message = _errors.Count + (_errors.Count > 1 ? " errors have" : " error has") +
2580 " been found in the model " + _name + ".\n" +
2581 (_errors.Count > 1 ? "These errors" : "This error") +
2582 " will be fixed when you save:";
2583 foreach (string s in _errors)
2584 {
2585 message += "\n - " + s;
2586 }
2587
2588 if (!Properties.Settings.Default.HideMDL0Errors)
2589 {
2590 MessageBox.Show(message);
2591 }
2592
2594 }
2595 }
2596 }
2597 }
int Version
Definition: BRRESNode.cs:1052
override int[] SupportedVersions
Definition: MDL0Node.cs:28
bool _hasXlu
Definition: MDL0Node.cs:47
bool _hasMix
Definition: MDL0Node.cs:47
bool _hasOpa
Definition: MDL0Node.cs:47
AssetStorage _assets
Definition: MDL0Node.cs:46
bool _hasTree
Definition: MDL0Node.cs:47
Definition: AssetStorage.cs:8
ResourceGroup * Defs
Definition: ModelLinker.cs:121
Definition: Common.cs:421
PString Name
Definition: Common.cs:422

◆ OnRebuild()

override void BrawlLib.SSBB.ResourceNodes.MDL0Node.OnRebuild ( VoidPtr  address,
int  length,
bool  force 
)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

2814 {
2815 ModelEncoder.Build(_linker, (MDL0Header*) address, length, force);
2816 }

◆ OnVersionChanged()

override void BrawlLib.SSBB.ResourceNodes.MDL0Node.OnVersionChanged ( int  previousVersion)
inlineprotectedvirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.BRESEntryNode.

197 {
198 bool
199 convertingDown = previousVersion > 9 && _version <= 9,
200 convertingUp = previousVersion <= 9 && _version > 9;
201
202 if (convertingDown)
203 {
204 //TODO: alert user to information that will be lost after converting down to v8 or v9, saving and closing.
205 //No need to allow cancelling the version change here, as the user can simply change the version back before saving and closing.
206 }
207
208 //Be sure the model is populated so that the object list is filled
209 if (_children == null)
210 {
211 Populate(0);
212 }
213
214 //Version 10 and 11 objects are slighly different from 8 and 9
215 if (_objList != null && (convertingDown || convertingUp))
216 {
217 foreach (MDL0ObjectNode o in _objList)
218 {
219 o._forceRebuild = true;
220 }
221 }
222 }

◆ PreRender()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.PreRender ( ModelPanelViewport  v)
inline

Implements BrawlLib.OpenGL.IRenderedObject.

3042 {
3043 if (_billboardBones.Count > 0)
3044 {
3045 WeightMeshes(v);
3046 ApplySHP(_currentSHP, _currentSHPIndex);
3047 }
3048
3049 if (_matList != null)
3050 {
3051 foreach (MDL0MaterialNode m in _matList)
3052 {
3053 foreach (MDL0MaterialRefNode mr in m.Children)
3054 {
3055 mr.SetEffectMatrix(_scn0, v, _scn0Frame);
3056 }
3057 }
3058 }
3059 }
void ApplySHP(SHP0Node node, float index)
Definition: MDL0Node.cs:3357

◆ Refresh()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.Refresh ( )
inline

Implements BrawlLib.OpenGL.IRenderedObject.

3028 {
3029 if (_texList != null)
3030 {
3031 foreach (MDL0TextureNode t in _texList)
3032 {
3033 t.Reload(this, t.Parent?.Name.EndsWith("_ExtMtl") ?? false);
3034 }
3035 }
3036 }

◆ RegenerateVIS0Indices()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.RegenerateVIS0Indices ( )
inline

This only needs to be called when the model is currently attached to a model renderer and the amount of objects change or an object's visibility bone changes.

2983 {
2984 int i = 0;
2985 VIS0Indices = new Dictionary<string, Dictionary<int, List<int>>>();
2986 if (_objList != null)
2987 {
2988 foreach (MDL0ObjectNode p in _objList)
2989 {
2990 int x = 0;
2991 foreach (DrawCall c in p._drawCalls)
2992 {
2993 if (c._visBoneNode != null && c._visBoneNode.BoneIndex != 0)
2994 {
2995 if (!VIS0Indices.ContainsKey(c._visBoneNode.Name))
2996 {
2997 VIS0Indices.Add(c._visBoneNode.Name,
2998 new Dictionary<int, List<int>> {{i, new List<int> {x}}});
2999 }
3000 else if (!VIS0Indices[c._visBoneNode.Name].ContainsKey(i))
3001 {
3002 VIS0Indices[c._visBoneNode.Name].Add(i, new List<int> {x});
3003 }
3004 else if (!VIS0Indices[c._visBoneNode.Name][i].Contains(x))
3005 {
3006 VIS0Indices[c._visBoneNode.Name][i].Add(x);
3007 }
3008 }
3009
3010 x++;
3011 }
3012
3013 i++;
3014 }
3015 }
3016 }

◆ RemoveChild()

override void BrawlLib.SSBB.ResourceNodes.MDL0Node.RemoveChild ( ResourceNode  child)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

832 {
833 if (child is MDL0GroupNode)
834 {
835 UnlinkGroup(child as MDL0GroupNode);
836 }
837
838 base.RemoveChild(child);
839 }
void UnlinkGroup(MDL0GroupNode group)
Definition: MDL0Node.cs:2185

◆ RenderBones()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.RenderBones ( ModelPanelViewport  v)
inline

Implements BrawlLib.Modeling.IModel.

3164 {
3165 GL.PushAttrib(AttribMask.AllAttribBits);
3166
3167 GL.Enable(EnableCap.Blend);
3168 GL.Disable(EnableCap.Lighting);
3169 GL.Disable(EnableCap.DepthTest);
3170
3171 GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
3172 GL.LineWidth(1.5f);
3173
3174 if (_boneList != null)
3175 {
3176 foreach (MDL0BoneNode bone in _boneList)
3177 {
3178 bone.Render(_isTargetModel, v);
3179 }
3180 }
3181
3182 GL.PopAttrib();
3183 }

◆ RenderBoxes()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.RenderBoxes ( bool  model,
bool  obj,
bool  bone,
bool  bindState 
)
inline

Implements BrawlLib.Modeling.IModel.

3115 {
3116 if (model || obj || bone)
3117 {
3118 GL.PushAttrib(AttribMask.AllAttribBits);
3119
3120 GL.Disable(EnableCap.Lighting);
3121 GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
3122
3123 bindState = _bindFrame && bindState;
3124
3125 if (model)
3126 {
3127 GL.Color4(Color.Gray);
3128 DrawBox(bindState);
3129 }
3130
3131 if (obj && _objList != null)
3132 {
3133 GL.Color4(Color.Purple);
3134 if (_selectedObjectIndex != -1 && ((MDL0ObjectNode) _objList[_selectedObjectIndex]).IsRendering)
3135 {
3136 ((MDL0ObjectNode) _objList[_selectedObjectIndex]).DrawBox();
3137 }
3138 else
3139 {
3140 foreach (MDL0ObjectNode p in _objList)
3141 {
3142 if (p.IsRendering)
3143 {
3144 p.DrawBox();
3145 }
3146 }
3147 }
3148 }
3149
3150 if (bone)
3151 {
3152 GL.Color4(Color.Orange);
3153 foreach (MDL0BoneNode b in _boneList)
3154 {
3155 b.DrawBox(true, bindState);
3156 }
3157 }
3158
3159 GL.PopAttrib();
3160 }
3161 }
int _selectedObjectIndex
Definition: MDL0Node.cs:2957
bool IsRendering
Definition: MDL0Node.cs:2934
void DrawBox(bool bindState)
Definition: MDL0Node.cs:3205

◆ RenderNormals()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.RenderNormals ( )
inline

Implements BrawlLib.Modeling.IModel.

3090 {
3091 if (_objList != null)
3092 {
3093 if (_selectedObjectIndex != -1)
3094 {
3095 MDL0ObjectNode o = (MDL0ObjectNode) _objList[_selectedObjectIndex];
3096 if (o.IsRendering)
3097 {
3098 o._manager.RenderNormals();
3099 }
3100 }
3101 else
3102 {
3103 foreach (MDL0ObjectNode p in _objList)
3104 {
3105 if (p.IsRendering)
3106 {
3107 p._manager.RenderNormals();
3108 }
3109 }
3110 }
3111 }
3112 }

◆ RenderVertices()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.RenderVertices ( bool  depthPass,
IBoneNode  weightTarget,
GLCamera  camera 
)
inline

Implements BrawlLib.Modeling.IModel.

3064 {
3065 if (_objList != null)
3066 {
3067 if (_selectedObjectIndex != -1)
3068 {
3069 MDL0ObjectNode o = (MDL0ObjectNode) _objList[_selectedObjectIndex];
3070 if (o.IsRendering && o._manager != null)
3071 {
3072 o._manager.RenderVertices(o._matrixNode, weightTarget, depthPass, camera);
3073 return;
3074 }
3075 }
3076 else
3077 {
3078 foreach (MDL0ObjectNode p in _objList)
3079 {
3080 if (p.IsRendering)
3081 {
3082 p._manager?.RenderVertices(p._matrixNode, weightTarget, depthPass, camera);
3083 }
3084 }
3085 }
3086 }
3087 }

◆ Replace()

override void BrawlLib.SSBB.ResourceNodes.MDL0Node.Replace ( string  fileName,
FileMapProtect  prot,
FileOptions  options 
)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

2766 {
2767 MDL0Node node = FromFile(fileName, FileOptions.SequentialScan);
2768 if (node == null)
2769 {
2770 return;
2771 }
2772
2773 //Get the original data source from the newly created model
2774 //and clear the reference to it so it's not disposed of
2775 //when the model is disposed
2776 DataSource m = node._uncompSource;
2777 node._uncompSource = DataSource.Empty;
2778 node._origSource = DataSource.Empty;
2779
2780 node.Dispose();
2781 ReplaceRaw(m.Map);
2782 }
static MDL0Node FromFile(string path, FileOptions options=FileOptions.RandomAccess)
Definition: MDL0Node.cs:2649
virtual void ReplaceRaw(VoidPtr address, int length)
Definition: ResourceNode.cs:847

◆ ReplaceMeshes()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ReplaceMeshes ( MDL0Node  replacement,
bool  doSearch,
bool  replaceIfFound,
bool  addIfNotFound 
)
inline
1294 {
1295 if (replacement == null)
1296 {
1297 return;
1298 }
1299
1300 replacement.Populate();
1301 replacement.ResetToBindState();
1302
1303 // Save texture matrix settings
1304 Dictionary<string, bool[]> texMatrixSettings = new Dictionary<string, bool[]>();
1305 if (_matGroup != null && _matGroup.Children.Count > 0)
1306 {
1307 foreach (MDL0MaterialNode m in _matGroup.Children.Where(m => m.HasChildren))
1308 {
1309 bool[] texRefSettings = new bool[m.Children.Count];
1310 foreach (MDL0MaterialRefNode r in m.Children)
1311 {
1312 texRefSettings[r.Index] = r.HasTextureMatrix;
1313 }
1314
1315 if (!texMatrixSettings.ContainsKey(m.Name))
1316 {
1317 texMatrixSettings.Add(m.Name, texRefSettings);
1318 }
1319 }
1320 }
1321
1322 bool[] addGroup = new bool[8];
1323 while (replacement._objList != null && replacement._objList.Count > 0)
1324 {
1325 ReplaceOrAddMeshInternal(
1326 replacement._objList[0] as MDL0ObjectNode,
1327 ref addGroup,
1328 doSearch,
1329 replaceIfFound,
1330 addIfNotFound);
1331 }
1332
1333 FinishReplace(addGroup);
1334
1335 // Copy texture matrix settings from before
1336 if (_matGroup != null && _matGroup.Children.Count > 0)
1337 {
1338 foreach (MDL0MaterialNode m in _matGroup.Children.Where(m => m.HasChildren && texMatrixSettings.ContainsKey(m.Name)))
1339 {
1340 if (texMatrixSettings[m.Name].Length == m.Children.Count)
1341 {
1342 foreach (MDL0MaterialRefNode r in m.Children)
1343 {
1344 r.HasTextureMatrix = texMatrixSettings[m.Name][r.Index];
1345 }
1346 }
1347 }
1348 }
1349 }

◆ ReplaceOrAddMesh()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ReplaceOrAddMesh ( MDL0ObjectNode  replacement,
bool  doSearch,
bool  replaceIfFound,
bool  addIfNotFound 
)
inline
1265 {
1266 if (replacement == null)
1267 {
1268 return;
1269 }
1270
1271 MDL0Node model = replacement.Model;
1272 if (model != null)
1273 {
1274 model.Populate();
1275 model.ResetToBindState();
1276 }
1277
1278 bool[] addGroup = new bool[8];
1279 ReplaceOrAddMeshInternal(
1280 replacement,
1281 ref addGroup,
1282 doSearch,
1283 replaceIfFound,
1284 addIfNotFound);
1285
1286 FinishReplace(addGroup);
1287 }

◆ ResetToBindState()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.ResetToBindState ( )
inline

Implements BrawlLib.Modeling.IModel.

3196 {
3197 ApplyCHR(null, 0);
3198 ApplySRT(null, 0);
3199 ApplyVIS(null, 0);
3200 ApplyPAT(null, 0);
3201 ApplyCLR(null, 0);
3202 ApplySCN(null, 0);
3203 }
void ApplySCN(SCN0Node node, float index)
Definition: MDL0Node.cs:3335
void ApplyVIS(VIS0Node node, float index)
Definition: MDL0Node.cs:3293
void ApplyCLR(CLR0Node node, float index)
Definition: MDL0Node.cs:3269
void ApplySRT(SRT0Node node, float index)
Definition: MDL0Node.cs:3257
void ApplyPAT(PAT0Node node, float index)
Definition: MDL0Node.cs:3281

◆ StripModel()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.StripModel ( )
inline
2041 {
2042 Populate();
2043 while (_objGroup != null && _objGroup.HasChildren)
2044 {
2045 ((MDL0ObjectNode) _objGroup.Children[0]).Remove(true);
2046 }
2047
2048 while (_matGroup != null && _matGroup.HasChildren)
2049 {
2050 ((MDL0MaterialNode) _matGroup.Children[0]).Remove(true);
2051 }
2052
2053 while (_shadGroup != null && _shadGroup.HasChildren)
2054 {
2055 _shadGroup.Children[0].Remove();
2056 }
2057
2058 while (_uvGroup != null && _uvGroup.HasChildren)
2059 {
2060 _uvGroup.Children[0].Remove();
2061 }
2062
2063 while (_normGroup != null && _normGroup.HasChildren)
2064 {
2065 _normGroup.Children[0].Remove();
2066 }
2067
2068 while (_vertGroup != null && _vertGroup.HasChildren)
2069 {
2070 _vertGroup.Children[0].Remove();
2071 }
2072
2073 while (_colorGroup != null && _colorGroup.HasChildren)
2074 {
2075 _colorGroup.Children[0].Remove();
2076 }
2077
2078 while (_pltGroup != null && _pltGroup.HasChildren)
2079 {
2080 _pltGroup.Children[0].Remove();
2081 }
2082 }
virtual bool HasChildren
Definition: ResourceNode.cs:185

◆ UnlinkGroup()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.UnlinkGroup ( MDL0GroupNode  group)
inline
2186 {
2187 if (group != null)
2188 {
2189 switch (group._type)
2190 {
2191 case MDLResourceType.Definitions:
2192 {
2193 _defGroup = null;
2194 _defList = null;
2195 break;
2196 }
2197
2198 case MDLResourceType.Bones:
2199 {
2200 _boneGroup = null;
2201 _boneList = null;
2202 break;
2203 }
2204
2205 case MDLResourceType.Materials:
2206 {
2207 _matGroup = null;
2208 _matList = null;
2209 break;
2210 }
2211
2212 case MDLResourceType.Shaders:
2213 {
2214 _shadGroup = null;
2215 _shadList = null;
2216 break;
2217 }
2218
2219 case MDLResourceType.Vertices:
2220 {
2221 _vertGroup = null;
2222 _vertList = null;
2223 break;
2224 }
2225
2226 case MDLResourceType.Normals:
2227 {
2228 _normGroup = null;
2229 _normList = null;
2230 break;
2231 }
2232
2233 case MDLResourceType.UVs:
2234 {
2235 _uvGroup = null;
2236 _uvList = null;
2237 break;
2238 }
2239
2240 case MDLResourceType.Colors:
2241 {
2242 _colorGroup = null;
2243 _colorList = null;
2244 break;
2245 }
2246
2247 case MDLResourceType.Objects:
2248 {
2249 _objGroup = null;
2250 _objList = null;
2251 break;
2252 }
2253
2254 case MDLResourceType.Textures:
2255 {
2256 _texGroup = null;
2257 _texList = null;
2258 break;
2259 }
2260
2261 case MDLResourceType.Palettes:
2262 {
2263 _pltGroup = null;
2264 _pltList = null;
2265 break;
2266 }
2267
2268 case MDLResourceType.FurLayerCoords:
2269 {
2270 _furPosGroup = null;
2271 _furPosList = null;
2272 break;
2273 }
2274
2275 case MDLResourceType.FurVectors:
2276 {
2277 _furVecGroup = null;
2278 _furVecList = null;
2279 break;
2280 }
2281 }
2282 }
2283 }

◆ WeightMeshes()

void BrawlLib.SSBB.ResourceNodes.MDL0Node.WeightMeshes ( ModelPanelViewport  v = null)
inline
3232 {
3233 //Multiply matrices
3234 if (_boneList != null)
3235 {
3236 foreach (MDL0BoneNode b in _boneList)
3237 {
3238 b.RecalcFrameState(v);
3239 }
3240 }
3241
3242 foreach (Influence inf in _influences._influences)
3243 {
3244 inf.CalcMatrix();
3245 }
3246
3247 //Weight vertices and normals
3248 if (!_dontUpdateMesh && _objList != null)
3249 {
3250 foreach (MDL0ObjectNode poly in _objList)
3251 {
3252 poly.Weight();
3253 }
3254 }
3255 }
bool _dontUpdateMesh
Definition: MDL0Node.cs:3212
Definition: InfluenceManager.cs:96
void CalcMatrix()
Definition: InfluenceManager.cs:271

Member Data Documentation

◆ _assets

AssetStorage BrawlLib.SSBB.ResourceNodes.MDL0Node._assets

◆ _autoMetal

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._autoMetal

◆ _billboardBones

List<MDL0BoneNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._billboardBones = new List<MDL0BoneNode>()

◆ _boneGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._boneGroup

◆ _boneList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._boneList

◆ _colorGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._colorGroup

◆ _colorList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._colorList

◆ _defGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._defGroup

◆ _defList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._defList

◆ _dontUpdateMesh

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._dontUpdateMesh = false

◆ _enableExtents

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._enableExtents

◆ _envMtxMode

byte BrawlLib.SSBB.ResourceNodes.MDL0Node._envMtxMode

◆ _errors

List<string> BrawlLib.SSBB.ResourceNodes.MDL0Node._errors = new List<string>()

◆ _extents

Box BrawlLib.SSBB.ResourceNodes.MDL0Node._extents

◆ _furPosGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._furPosGroup

◆ _furPosList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._furPosList

◆ _furVecGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._furVecGroup

◆ _furVecList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._furVecList

◆ _hasMix

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._hasMix

◆ _hasOpa

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._hasOpa

◆ _hasTree

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._hasTree

◆ _hasXlu

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._hasXlu

◆ _ignoreModelViewerAttribs

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._ignoreModelViewerAttribs = false

◆ _influences

InfluenceManager BrawlLib.SSBB.ResourceNodes.MDL0Node._influences = new InfluenceManager()

◆ _isImport

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._isImport

◆ _linker

ModelLinker BrawlLib.SSBB.ResourceNodes.MDL0Node._linker

◆ _matGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._matGroup

◆ _matList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._matList

◆ _matrixOffset

Matrix? BrawlLib.SSBB.ResourceNodes.MDL0Node._matrixOffset = null

◆ _metalMat

string BrawlLib.SSBB.ResourceNodes.MDL0Node._metalMat

◆ _needsNrmMtxArray

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._needsNrmMtxArray

◆ _needsTexMtxArray

bool BrawlLib.SSBB.ResourceNodes.MDL0Node._needsTexMtxArray

◆ _normGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._normGroup

◆ _normList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._normList

◆ _numFacepoints

int BrawlLib.SSBB.ResourceNodes.MDL0Node._numFacepoints

◆ _numNodes

int BrawlLib.SSBB.ResourceNodes.MDL0Node._numNodes

◆ _numTriangles

int BrawlLib.SSBB.ResourceNodes.MDL0Node._numTriangles

◆ _objGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._objGroup

◆ _objList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._objList

◆ _pltGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._pltGroup

◆ _pltList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._pltList

◆ _renderAttribs

ModelRenderAttributes BrawlLib.SSBB.ResourceNodes.MDL0Node._renderAttribs = new ModelRenderAttributes()

◆ _selectedObjectIndex

int BrawlLib.SSBB.ResourceNodes.MDL0Node._selectedObjectIndex = -1

◆ _shadGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._shadGroup

◆ _shadList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._shadList

◆ _texGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._texGroup

◆ _texList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._texList

◆ _uvGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._uvGroup

◆ _uvList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._uvList

◆ _vertGroup

MDL0GroupNode BrawlLib.SSBB.ResourceNodes.MDL0Node._vertGroup

◆ _vertList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node._vertList

◆ MultiTypeWorks

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.MultiTypeWorks = false
static

◆ VIS0Indices

Dictionary<string, Dictionary<int, List<int> > > BrawlLib.SSBB.ResourceNodes.MDL0Node.VIS0Indices

Property Documentation

◆ AllBones

List<MDL0BoneNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.AllBones
get
336 {
337 get
338 {
339 List<MDL0BoneNode> bones = new List<MDL0BoneNode>();
340 if (BoneGroup != null)
341 {
342 foreach (ResourceNode r in BoneGroup.GetChildrenRecursive())
343 {
344 if (r is MDL0BoneNode b)
345 {
346 bones.Add(b);
347 }
348 }
349
350 bones = bones.OrderBy(o => o.BoneIndex).ToList();
351 }
352
353 return bones;
354 }
355 }
List< ResourceNode > GetChildrenRecursive()
Used primarily to get bone lists. Kept for all resource nodes for utility.
Definition: ResourceNode.cs:281

◆ Attached

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.Attached
get

◆ AutoMetalMaterials

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.AutoMetalMaterials
getset
63 {
64 get => _autoMetal;
65 set
66 {
67 _autoMetal = value;
69 }
70 }
bool _autoMetal
Definition: MDL0Node.cs:47

◆ BoneCache

IBoneNode [] BrawlLib.SSBB.ResourceNodes.MDL0Node.BoneCache
get

Implements BrawlLib.Modeling.IModel.

2916 {
2917 get
2918 {
2919 if (_linker?.BoneCache != null)
2920 {
2921 return _linker.BoneCache.Select(x => x as IBoneNode).ToArray();
2922 }
2923
2924 return new IBoneNode[0];
2925 }
2926 }
Definition: IBoneNode.cs:10

◆ BoneGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.BoneGroup
get

◆ BoneList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.BoneList
get

◆ BoxMax

Vector3 BrawlLib.SSBB.ResourceNodes.MDL0Node.BoxMax
getset
249 {
250 get => _extents.Max;
251 set
252 {
253 _extents.Max = value;
255 }
256 }
Vector3 Max
Definition: Box.cs:18

◆ BoxMin

Vector3 BrawlLib.SSBB.ResourceNodes.MDL0Node.BoxMin
getset
237 {
238 get => _extents.Min;
239 set
240 {
241 _extents.Min = value;
243 }
244 }
Vector3 Min
Definition: Box.cs:12

◆ ColorGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.ColorGroup
get

◆ ColorList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.ColorList
get

◆ DataAlign

override int BrawlLib.SSBB.ResourceNodes.MDL0Node.DataAlign
get

◆ DefinitionsGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.DefinitionsGroup
get

◆ DefinitionsList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.DefinitionsList
get

◆ DrawCalls

List<DrawCallBase> BrawlLib.SSBB.ResourceNodes.MDL0Node.DrawCalls
get

Implements BrawlLib.OpenGL.IRenderedObject.

3633 {
3634 get
3635 {
3636 Populate();
3637 return _objList == null
3638 ? new List<DrawCallBase>()
3639 : _objList.SelectMany(x => ((MDL0ObjectNode) x).DrawCalls).ToList();
3640 }
3641 }
List< DrawCallBase > DrawCalls
Definition: MDL0Node.cs:3633

◆ EnableBoundingBox

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.EnableBoundingBox
getset
260 {
261 get => _enableExtents;
262 set
263 {
264 _enableExtents = value;
266 }
267 }

◆ EnvelopeMatrixMode

MDLEnvelopeMatrixMode BrawlLib.SSBB.ResourceNodes.MDL0Node.EnvelopeMatrixMode
getset
271 {
273 set
274 {
275 _envMtxMode = (byte) value;
277 }
278 }
MDLEnvelopeMatrixMode
Definition: MDL0.cs:212

◆ FurPosGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FurPosGroup
get

◆ FurPosList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.FurPosList
get

◆ FurVecGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.FurVecGroup
get

◆ FurVecList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.FurVecList
get

◆ Influences

InfluenceManager BrawlLib.SSBB.ResourceNodes.MDL0Node.Influences
get

◆ IsRendering

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.IsRendering
getset

Implements BrawlLib.OpenGL.IRenderedObject.

2934 {
2935 get => DrawCalls.Where(x => x._render).Count() > 0;
2936 set
2937 {
2938 foreach (DrawCallBase b in DrawCalls)
2939 {
2940 b._render = value;
2941 }
2942 }
2943 }
Definition: IRenderedObject.cs:11

◆ IsStagePosition

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.IsStagePosition
get

◆ IsTargetModel

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.IsTargetModel
getset

Implements BrawlLib.Modeling.IModel.

2947 {
2948 get => _isTargetModel;
2949 set => _isTargetModel = value;
2950 }

◆ MaterialGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.MaterialGroup
get

◆ MaterialList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.MaterialList
get

◆ MetalTexture

string BrawlLib.SSBB.ResourceNodes.MDL0Node.MetalTexture
getset
77 {
78 get => _metalMat;
79 set
80 {
81 if (_matList != null)
82 {
83 foreach (MDL0MaterialNode m in _matList)
84 {
85 if (m.IsMetal)
86 {
87 foreach (MDL0MaterialRefNode mr in m.Children)
88 {
89 if (mr.Name == _metalMat)
90 {
91 mr.Name = value;
92 }
93 }
94 }
95 }
96 }
97
98 _metalMat = value;
99 }
100 }

◆ NeedsNormalMtxArray

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.NeedsNormalMtxArray
get

◆ NeedsTextureMtxArray

bool BrawlLib.SSBB.ResourceNodes.MDL0Node.NeedsTextureMtxArray
get

◆ NormalGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.NormalGroup
get

◆ NormalList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.NormalList
get

◆ NumFacepoints

int BrawlLib.SSBB.ResourceNodes.MDL0Node.NumFacepoints
get
131 {
132 get
133 {
134 if (_objList == null)
135 {
136 return 0;
137 }
138
139 int i = 0;
140 foreach (MDL0ObjectNode n in _objList)
141 {
142 i += n._numFacepoints;
143 }
144
145 return i;
146 }
147 }

◆ NumNodes

int BrawlLib.SSBB.ResourceNodes.MDL0Node.NumNodes
get

◆ NumTriangles

int BrawlLib.SSBB.ResourceNodes.MDL0Node.NumTriangles
get
174 {
175 get
176 {
177 if (_objList == null)
178 {
179 return 0;
180 }
181
182 int i = 0;
183 foreach (MDL0ObjectNode n in _objList)
184 {
185 i += n._numFaces;
186 }
187
188 return i;
189 }
190 }

◆ NumVertices

int BrawlLib.SSBB.ResourceNodes.MDL0Node.NumVertices
get
153 {
154 get
155 {
156 if (_objList == null)
157 {
158 return 0;
159 }
160
161 int i = 0;
162 foreach (MDL0ObjectNode n in _objList)
163 {
164 i += n.VertexCount;
165 }
166
167 return i;
168 }
169 }

◆ Objects

IObject [] BrawlLib.SSBB.ResourceNodes.MDL0Node.Objects
get

◆ PaletteGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.PaletteGroup
get

◆ PaletteList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.PaletteList
get

◆ PolygonGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.PolygonGroup
get

◆ PolygonList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.PolygonList
get

◆ ResourceFileType

override ResourceType BrawlLib.SSBB.ResourceNodes.MDL0Node.ResourceFileType
get

◆ RootBones

IBoneNode [] BrawlLib.SSBB.ResourceNodes.MDL0Node.RootBones
get

◆ ScalingRule

MDLScalingRule BrawlLib.SSBB.ResourceNodes.MDL0Node.ScalingRule
getset
106 {
107 get => (MDLScalingRule) _scalingRule;
108 set
109 {
110 _scalingRule = (int) value;
112 }
113 }
MDLScalingRule
Definition: MDL0.cs:197

◆ SelectedObjectIndex

int BrawlLib.SSBB.ResourceNodes.MDL0Node.SelectedObjectIndex
getset

Implements BrawlLib.Modeling.IModel.

3187 {
3188 get => _selectedObjectIndex;
3189 set => _selectedObjectIndex = value;
3190 }

◆ ShaderGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.ShaderGroup
get

◆ ShaderList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.ShaderList
get

◆ SupportedVersions

override int [] BrawlLib.SSBB.ResourceNodes.MDL0Node.SupportedVersions
get

◆ Tag

override string BrawlLib.SSBB.ResourceNodes.MDL0Node.Tag
get

◆ TextureGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.TextureGroup
get

◆ TextureList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.TextureList
get

◆ TextureMatrixMode

TexMatrixMode BrawlLib.SSBB.ResourceNodes.MDL0Node.TextureMatrixMode
getset
118 {
119 get => (TexMatrixMode) _texMtxMode;
120 set
121 {
122 _texMtxMode = (int) value;
124 }
125 }
TexMatrixMode
Definition: MDL0.cs:204

◆ UVGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.UVGroup
get

◆ UVList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.UVList
get

◆ VertexGroup

ResourceNode BrawlLib.SSBB.ResourceNodes.MDL0Node.VertexGroup
get

◆ VertexList

List<ResourceNode> BrawlLib.SSBB.ResourceNodes.MDL0Node.VertexList
get

Event Documentation

◆ DrawCallsChanged

EventHandler BrawlLib.SSBB.ResourceNodes.MDL0Node.DrawCallsChanged

The documentation for this class was generated from the following file: