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

Public Member Functions

 CHR0Node ()
 
CHR0EntryNode CreateEntry ()
 
CHR0EntryNode CreateEntry (string name)
 
void InsertKeyframe (int index)
 
void DeleteKeyframe (int index)
 
override bool OnInitialize ()
 
override void OnPopulate ()
 
override int OnCalculateSize (bool force)
 
override void Export (string outPath)
 
override void Replace (string fileName)
 
override void OnRebuild (VoidPtr address, int length, bool force)
 
void Resize ()
 Stretches or compresses all frames of the animation to fit a new frame count specified by the user. More...
 
void Resize (int newFrameCount)
 Stretches or compresses all frames of the animation to fit a new frame count. More...
 
void MergeWith ()
 
void MergeWith (CHR0Node external)
 
void Append ()
 Adds an animation opened by the user to the end of this one More...
 
void Append (CHR0Node external)
 Adds an animation to the end of this one More...
 
void Append (CHR0Node external, int timesToAppend)
 
CHR0Node Reverse (bool appendReverse)
 
void Port (MDL0Node baseModel)
 
void Port (MDL0Node _targetModel, MDL0Node _extModel)
 
void AverageKeys ()
 
void AverageKeys (string boneName)
 
- 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 ()
 

Static Public Member Functions

static CHR0Node FromFile (string path)
 
- 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

int num
 
- Public Attributes inherited from BrawlLib.SSBB.ResourceNodes.NW4RAnimationNode
int _numFrames = 1
 
bool _loop
 
- 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
 

Protected Member Functions

override void UpdateChildFrameLimits ()
 
virtual void UpdateChildFrameLimits ()
 
- Protected Member Functions inherited from BrawlLib.SSBB.ResourceNodes.BRESEntryNode
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 Type[] AllowedChildTypes [get]
 
override int[] SupportedVersions [get]
 
override string Tag [get]
 
override int FrameCount [get, set]
 
override bool Loop [get, set]
 
- Properties inherited from BrawlLib.SSBB.ResourceNodes.NW4RAnimationNode
virtual int FrameCount [get, set]
 
virtual bool Loop [get, set]
 
- 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]
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ CHR0Node()

BrawlLib.SSBB.ResourceNodes.CHR0Node.CHR0Node ( )
inline
26 {
27 _version = 4;
28 }
int _version
Definition: BRRESNode.cs:1045

Member Function Documentation

◆ Append() [1/3]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.Append ( )
inline

Adds an animation opened by the user to the end of this one

543 {
544 CHR0Node external = null;
545 OpenFileDialog o = new OpenFileDialog
546 {
547 Filter = "CHR0 Animation (*.chr0)|*.chr0",
548 Title = "Please select an animation to append."
549 };
550 if (o.ShowDialog() == DialogResult.OK)
551 {
552 if ((external = (CHR0Node) NodeFactory.FromFile(null, o.FileName)) != null)
553 {
554 Append(external);
555 }
556 }
557 }
CHR0Node()
Definition: CHR0Node.cs:25
void Append()
Adds an animation opened by the user to the end of this one
Definition: CHR0Node.cs:542

◆ Append() [2/3]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.Append ( CHR0Node  external)
inline

Adds an animation to the end of this one

563 {
564 Append(external, 1);
565 }

◆ Append() [3/3]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.Append ( CHR0Node  external,
int  timesToAppend 
)
inline
568 {
569 int extCount = external.FrameCount;
570
571 for (int appendCount = 0; appendCount < timesToAppend; appendCount++)
572 {
573 int origIntCount = FrameCount;
574 FrameCount += extCount;
575
576 foreach (CHR0EntryNode extEntry in external.Children)
577 {
578 CHR0EntryNode intEntry = null;
579 KeyframeEntry kfe;
580 if ((intEntry = (CHR0EntryNode) FindChild(extEntry.Name, false)) == null)
581 {
582 CHR0EntryNode newIntEntry = new CHR0EntryNode {Name = extEntry.Name};
583 newIntEntry.SetSize(extEntry.FrameCount + origIntCount, Loop);
584 for (int x = 0; x < extEntry.FrameCount; x++)
585 {
586 for (int i = 0; i < 9; i++)
587 {
588 if ((kfe = extEntry.GetKeyframe(i, x)) != null)
589 {
590 newIntEntry.Keyframes.SetFrameValue(i, x + origIntCount, kfe._value)._tangent =
591 kfe._tangent;
592 }
593 }
594 }
595
596 AddChild(newIntEntry);
597 }
598 else
599 {
600 for (int x = 0; x < extEntry.FrameCount; x++)
601 {
602 for (int i = 0; i < 9; i++)
603 {
604 if ((kfe = extEntry.GetKeyframe(i, x)) != null)
605 {
606 intEntry.Keyframes.SetFrameValue(i, x + origIntCount, kfe._value)._tangent =
607 kfe._tangent;
608 }
609 }
610 }
611 }
612 }
613 }
614 }
override bool Loop
Definition: CHR0Node.cs:41
override int FrameCount
Definition: CHR0Node.cs:34
virtual string Name
Definition: ResourceNode.cs:223
virtual void AddChild(ResourceNode child)
Definition: ResourceNode.cs:757
ResourceNode FindChild(string path)
Definition: ResourceNode.cs:1342
Definition: KeyframeCollection.cs:193
float _value
Definition: KeyframeCollection.cs:197
float _tangent
Definition: KeyframeCollection.cs:198

◆ AverageKeys() [1/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.AverageKeys ( )
inline
849 {
850 foreach (CHR0EntryNode w in Children)
851 {
852 for (int i = 0; i < 9; i++)
853 {
854 if (w.Keyframes._keyArrays[i]._keyCount > 1)
855 {
856 KeyframeEntry root = w.Keyframes._keyArrays[i]._keyRoot;
857 if (root._next != root && root._prev != root && root._prev != root._next)
858 {
859 float tan = (root._next._tangent + root._prev._tangent) / 2.0f;
860 float val = (root._next._value + root._prev._value) / 2.0f;
861
862 root._next._tangent = tan;
863 root._prev._tangent = tan;
864
865 root._next._value = val;
866 root._prev._value = val;
867 }
868 }
869 }
870 }
871
873 }
virtual void SignalPropertyChange()
Definition: ResourceNode.cs:313
List< ResourceNode > Children
Definition: ResourceNode.cs:262
KeyframeEntry _prev
Definition: KeyframeCollection.cs:195
KeyframeEntry _next
Definition: KeyframeCollection.cs:195

◆ AverageKeys() [2/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.AverageKeys ( string  boneName)
inline
876 {
877 CHR0EntryNode w = FindChild(boneName, false) as CHR0EntryNode;
878 if (w == null)
879 {
880 return;
881 }
882
883 for (int i = 0; i < 9; i++)
884 {
885 if (w.Keyframes._keyArrays[i]._keyCount > 1)
886 {
887 KeyframeEntry root = w.Keyframes._keyArrays[i]._keyRoot;
888 if (root._next != root && root._prev != root && root._prev != root._next)
889 {
890 float tan = (root._next._tangent + root._prev._tangent) / 2.0f;
891 float val = (root._next._value + root._prev._value) / 2.0f;
892
893 root._next._tangent = tan;
894 root._prev._tangent = tan;
895
896 root._next._value = val;
897 root._prev._value = val;
898 }
899 }
900 }
901
903 }

◆ CreateEntry() [1/2]

CHR0EntryNode BrawlLib.SSBB.ResourceNodes.CHR0Node.CreateEntry ( )
inline
59 {
60 return CreateEntry(null);
61 }
CHR0EntryNode CreateEntry()
Definition: CHR0Node.cs:58

◆ CreateEntry() [2/2]

CHR0EntryNode BrawlLib.SSBB.ResourceNodes.CHR0Node.CreateEntry ( string  name)
inline
64 {
65 CHR0EntryNode n = new CHR0EntryNode
66 {
67 _name = FindName(name)
68 };
69 AddChild(n);
70 n.SetSize(_numFrames, Loop);
71 return n;
72 }
int _numFrames
Definition: BRRESNode.cs:994
unsafe string FindName(string name)
Definition: ResourceNode.cs:1578
string _name
Definition: ResourceNode.cs:139

◆ DeleteKeyframe()

void BrawlLib.SSBB.ResourceNodes.CHR0Node.DeleteKeyframe ( int  index)
inline
84 {
85 foreach (CHR0EntryNode c in Children)
86 {
87 c.Keyframes.Delete(index, 0, 1, 2, 3, 4, 5, 6, 7, 8);
88 }
89
90 FrameCount--;
91 }

◆ Export()

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

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

197 {
198 if (outPath.EndsWith(".dae", StringComparison.OrdinalIgnoreCase))
199 {
200 Collada.Serialize(new CHR0Node[] {this}, 60.0f, false, outPath);
201 }
202 else if (outPath.EndsWith(".anim", StringComparison.OrdinalIgnoreCase))
203 {
204 AnimFormat.Serialize(this, outPath);
205 }
206 else
207 {
208 base.Export(outPath);
209 }
210 }
Definition: ColladaAssetDecoder.cs:10
static void Serialize(MDL0Node model, string outFile)
Definition: ColladaExporter.cs:20
Definition: AnimFormat.cs:11
static void Serialize(CHR0Node node, string output)
Definition: AnimFormat.cs:15

◆ FromFile()

static CHR0Node BrawlLib.SSBB.ResourceNodes.CHR0Node.FromFile ( string  path)
inlinestatic
213 {
214 try
215 {
216 if (path.EndsWith(".anim", StringComparison.OrdinalIgnoreCase))
217 {
218 return AnimFormat.Read(path);
219 }
220
221 if (path.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
222 {
223 return CHR0TextImporter.Convert(path);
224 }
225
226 if (path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
227 {
228 return CHR0JsonImporter.Convert(path);
229 }
230
231 //if (path.EndsWith(".bvh", StringComparison.OrdinalIgnoreCase))
232 // return BVH.Import(path);
233 //if (path.EndsWith(".vmd", StringComparison.OrdinalIgnoreCase))
234 // return PMDModel.ImportVMD(path);
235
236 return NodeFactory.FromFile(null, path, typeof(CHR0Node)) as CHR0Node;
237 }
238 catch (System.Runtime.Serialization.SerializationException e)
239 {
240 MessageBox.Show("There was a problem importing the model animation.\n\nError:\n" + e.Message);
241 }
242
243
244 throw new NotSupportedException("The file extension specified is not of a supported animation type.");
245 }
static CHR0Node Read(string input)
Definition: AnimFormat.cs:100

◆ InsertKeyframe()

void BrawlLib.SSBB.ResourceNodes.CHR0Node.InsertKeyframe ( int  index)
inline
75 {
76 FrameCount++;
77 foreach (CHR0EntryNode c in Children)
78 {
79 c.Keyframes.Insert(index, 0, 1, 2, 3, 4, 5, 6, 7, 8);
80 }
81 }

◆ MergeWith() [1/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.MergeWith ( )
inline
402 {
403 OpenFileDialog o = new OpenFileDialog
404 {
405 Filter = "CHR0 Animation (*.chr0)|*.chr0",
406 Title = "Please select an animation to merge with."
407 };
408 if (o.ShowDialog() == DialogResult.OK)
409 {
410 CHR0Node external;
411 if ((external = FromFile(o.FileName)) != null)
412 {
413 MergeWith(external);
414 }
415 }
416 }
static CHR0Node FromFile(string path)
Definition: CHR0Node.cs:212
void MergeWith()
Definition: CHR0Node.cs:401

◆ MergeWith() [2/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.MergeWith ( CHR0Node  external)
inline
419 {
420 if (external.FrameCount != FrameCount && MessageBox.Show(null,
421 "Frame counts are not equal; the shorter animation will end early. Do you still wish to continue?",
422 "Merge Animations", MessageBoxButtons.YesNo) == DialogResult.No)
423 {
424 return;
425 }
426
427 if (external.FrameCount > FrameCount)
428 {
429 FrameCount = external.FrameCount;
430 }
431
432 foreach (CHR0EntryNode _extTarget in external.Children)
433 {
434 CHR0EntryNode node = null;
435 KeyframeEntry kfe = null;
436
437 CHR0EntryNode entry = new CHR0EntryNode {Name = _extTarget.Name};
438 entry.SetSize(_extTarget.FrameCount, Loop);
439
440 //Apply all external keyframes to current entry.
441 for (int x = 0; x < _extTarget.FrameCount; x++)
442 {
443 for (int i = 0; i < 9; i++)
444 {
445 if ((kfe = _extTarget.GetKeyframe(i, x)) != null)
446 {
447 entry.Keyframes.SetFrameValue(i, x, kfe._value)._tangent = kfe._tangent;
448 }
449 }
450 }
451
452 if ((node = FindChild(_extTarget.Name, false) as CHR0EntryNode) == null)
453 {
454 AddChild(entry, true);
455 }
456 else
457 {
458 DialogResult result = MessageBox.Show(null,
459 "A bone entry with the name " + _extTarget.Name +
460 " already exists.\nDo you want to rename this entry?\nOtherwise, you will have the option to merge the keyframes.",
461 "Rename Entry?", MessageBoxButtons.YesNoCancel);
462 if (result == DialogResult.Yes)
463 {
464 Top:
465 RenameDialog d = new RenameDialog();
466 if (d.ShowDialog(null, entry) == DialogResult.OK)
467 {
468 if (entry.Name != _extTarget.Name)
469 {
470 AddChild(entry, true);
471 }
472 else
473 {
474 MessageBox.Show("The name wasn't changed!");
475 goto Top;
476 }
477 }
478 }
479 else if (result == DialogResult.No)
480 {
481 result = MessageBox.Show(null, "Do you want to merge the keyframes of the entries?",
482 "Merge Keyframes?", MessageBoxButtons.YesNoCancel);
483 if (result == DialogResult.Yes)
484 {
485 KeyframeEntry kfe2 = null;
486
487 if (_extTarget.FrameCount > node.FrameCount)
488 {
489 node.SetSize(_extTarget.FrameCount, Loop);
490 }
491
492 //Merge all external keyframes with the current entry.
493 for (int x = 0; x < _extTarget.FrameCount; x++)
494 {
495 for (int i = 0; i < 9; i++)
496 {
497 if ((kfe = _extTarget.GetKeyframe(i, x)) != null)
498 {
499 if ((kfe2 = node.GetKeyframe(i, x)) == null)
500 {
501 node.SetKeyframe(i, x, kfe._value);
502 }
503 else
504 {
505 result = MessageBox.Show(null,
506 "A keyframe at frame " + x + " already exists.\nOld value: " +
507 kfe2._value + "\nNew value:" + kfe._value +
508 "\nReplace the old value with the new one?", "Replace Keyframe?",
509 MessageBoxButtons.YesNoCancel);
510 if (result == DialogResult.Yes)
511 {
512 node.SetKeyframe(i, x, kfe._value);
513 }
514 else if (result == DialogResult.Cancel)
515 {
516 Restore();
517 return;
518 }
519 }
520 }
521 }
522 }
523 }
524 else if (result == DialogResult.Cancel)
525 {
526 Restore();
527 return;
528 }
529 }
530 else if (result == DialogResult.Cancel)
531 {
532 Restore();
533 return;
534 }
535 }
536 }
537 }
DialogResult ShowDialog(IWin32Window owner, ResourceNode node)
Definition: RenameDialog.cs:16
virtual void Restore()
Definition: ResourceNode.cs:706

◆ OnCalculateSize()

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

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

181 {
182 int size = (_version == 5 ? CHR0v5.Size : CHR0v4_3.Size) + 0x18 + Children.Count * 0x10;
183 foreach (CHR0EntryNode n in Children)
184 {
185 size += n.CalculateSize(true);
186 }
187
188 if (_version == 5)
189 {
190 size += _userEntries.GetSize();
191 }
192
193 return size;
194 }
const int Size
Definition: CHR0.cs:10

◆ OnInitialize()

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

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

96 {
97 base.OnInitialize();
98 if (_version == 5)
99 {
100 CHR0v5* header = Header5;
101 _numFrames = header->_numFrames;
102 _loop = header->_loop != 0;
103
104 if (_name == null)
105 {
106 if (header->ResourceString != null)
107 {
108 _name = header->ResourceString;
109 }
110 else
111 {
112 _name = "anim" + Index;
113 }
114 }
115
116 if (header->_origPathOffset > 0)
117 {
118 _originalPath = header->OrigPath;
119 }
120
121 (_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);
122
123 return header->Group->_numEntries > 0;
124 }
125 else
126 {
127 CHR0v4_3* header = Header4_3;
128 _numFrames = header->_numFrames;
129 _loop = header->_loop != 0;
130
131 if (_name == null)
132 {
133 if (header->ResourceString != null)
134 {
135 _name = header->ResourceString;
136 }
137 else
138 {
139 _name = "anim" + Index;
140 }
141 }
142
143 if (header->_origPathOffset > 0)
144 {
145 _originalPath = header->OrigPath;
146 }
147
148 return header->Group->_numEntries > 0;
149 }
150 }
string _originalPath
Definition: BRRESNode.cs:1046
bool _loop
Definition: BRRESNode.cs:995
int Index
Definition: ResourceNode.cs:301
DataSource WorkingUncompressed
Definition: ResourceNode.cs:183
bint _loop
Definition: CHR0.cs:19
ResourceGroup * Group
Definition: CHR0.cs:33
string ResourceString
Definition: CHR0.cs:43
bushort _numFrames
Definition: CHR0.cs:17
bint _origPathOffset
Definition: CHR0.cs:16
string OrigPath
Definition: CHR0.cs:35
ResourceGroup * Group
Definition: CHR0.cs:94
VoidPtr UserData
Definition: CHR0.cs:97
bushort _numFrames
Definition: CHR0.cs:78
string ResourceString
Definition: CHR0.cs:110
bint _origPathOffset
Definition: CHR0.cs:77
bint _loop
Definition: CHR0.cs:80
string OrigPath
Definition: CHR0.cs:102
bint _numEntries
Definition: Common.cs:384

◆ OnPopulate()

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

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

153 {
154 ResourceGroup* group = Header4_3->Group;
155 for (int i = 0; i < group->_numEntries; i++)
156 {
157 new CHR0EntryNode().Initialize(this, new DataSource(group->First[i].DataAddress, 0));
158 }
159 }
VoidPtr DataAddress
Definition: Common.cs:524
Definition: Common.cs:380
ResourceEntry * First
Definition: Common.cs:405

◆ OnRebuild()

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

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

262 {
263 ResourceGroup* group;
264 if (_version == 5)
265 {
266 CHR0v5* header = (CHR0v5*) address;
267 *header = new CHR0v5(_version, length, _numFrames, Children.Count, _loop);
268 group = header->Group;
269 }
270 else
271 {
272 CHR0v4_3* header = (CHR0v4_3*) address;
273 *header = new CHR0v4_3(_version, length, _numFrames, Children.Count, _loop);
274 group = header->Group;
275 }
276
277 *group = new ResourceGroup(Children.Count);
278
279 VoidPtr entryAddress = group->EndAddress;
280 VoidPtr dataAddress = entryAddress;
281
282 foreach (CHR0EntryNode n in Children)
283 {
284 dataAddress += n._entryLen;
285 }
286
287 ResourceEntry* rEntry = group->First;
288 foreach (CHR0EntryNode n in Children)
289 {
290 (rEntry++)->_dataOffset = (int) entryAddress - (int) group;
291
292 n._dataAddr = dataAddress;
293 n.Rebuild(entryAddress, n._entryLen, true);
294 entryAddress += n._entryLen;
295 dataAddress += n._dataLen;
296 }
297
298 if (_userEntries.Count > 0 && _version == 5)
299 {
300 CHR0v5* header = (CHR0v5*) address;
301 header->UserData = dataAddress;
302 _userEntries.Write(dataAddress);
303 }
304 }
Definition: VoidPtr.cs:9
Definition: Common.cs:472
VoidPtr EndAddress
Definition: Common.cs:406

◆ Port() [1/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.Port ( MDL0Node  _targetModel,
MDL0Node  _extModel 
)
inline
675 {
676 MDL0BoneNode extBone;
677 MDL0BoneNode bone;
678 KeyframeEntry kfe;
679 foreach (CHR0EntryNode _target in Children)
680 {
681 extBone = (MDL0BoneNode) _extModel.FindChild(_target.Name, true); //Get external model bone
682 bone = (MDL0BoneNode) _targetModel.FindChild(_target.Name, true); //Get target model bone
683
684 for (int x = 0; x < _target.FrameCount; x++)
685 {
686 for (int i = 3; i < 9; i++)
687 {
688 if ((kfe = _target.GetKeyframe(i, x)) != null) //Check for a keyframe
689 {
690 if (bone != null && extBone != null)
691 {
692 switch (i)
693 {
694 //Translations
695 case 6: //Trans X
696 if (Math.Round(kfe._value, 4) == Math.Round(extBone._bindState.Translate._x, 4))
697 {
698 kfe._value = bone._bindState.Translate._x;
699 }
700 else if (bone._bindState.Translate._x < extBone._bindState.Translate._x)
701 {
702 kfe._value -=
703 extBone._bindState.Translate._x - bone._bindState.Translate._x;
704 }
705 else if (bone._bindState.Translate._x > extBone._bindState.Translate._x)
706 {
707 kfe._value +=
708 bone._bindState.Translate._x - extBone._bindState.Translate._x;
709 }
710
711 break;
712 case 7: //Trans Y
713 if (Math.Round(kfe._value, 4) == Math.Round(extBone._bindState.Translate._y, 4))
714 {
715 kfe._value = bone._bindState.Translate._y;
716 }
717 else if (bone._bindState.Translate._y < extBone._bindState.Translate._y)
718 {
719 kfe._value -=
720 extBone._bindState.Translate._y - bone._bindState.Translate._y;
721 }
722 else if (bone._bindState.Translate._y > extBone._bindState.Translate._y)
723 {
724 kfe._value +=
725 bone._bindState.Translate._y - extBone._bindState.Translate._y;
726 }
727
728 break;
729 case 8: //Trans Z
730 if (Math.Round(kfe._value, 4) == Math.Round(extBone._bindState.Translate._z, 4))
731 {
732 kfe._value = bone._bindState.Translate._z;
733 }
734 else if (bone._bindState.Translate._z < extBone._bindState.Translate._z)
735 {
736 kfe._value -=
737 extBone._bindState.Translate._z - bone._bindState.Translate._z;
738 }
739 else if (bone._bindState.Translate._z > extBone._bindState.Translate._z)
740 {
741 kfe._value +=
742 bone._bindState.Translate._z - extBone._bindState.Translate._z;
743 }
744
745 break;
746
747 //Rotations
748 //case 3: //Rot X
749 // difference = bone._bindState.Rotate._x - extBone._bindState.Rotate._x;
750 // kfe._value += difference;
751 // //if (difference != 0)
752 // // FixChildren(bone, 0);
753 // break;
754 //case 4: //Rot Y
755 // difference = bone._bindState.Rotate._y - extBone._bindState.Rotate._y;
756 // kfe._value += difference;
757 // //if (difference != 0)
758 // // FixChildren(bone, 1);
759 // break;
760 //case 5: //Rot Z
761 // difference = bone._bindState.Rotate._z - extBone._bindState.Rotate._z;
762 // kfe._value += difference;
763 // //if (difference != 0)
764 // // FixChildren(bone, 2);
765 // break;
766 }
767 }
768
769 if (kfe._value == float.NaN || kfe._value == float.PositiveInfinity ||
770 kfe._value == float.NegativeInfinity)
771 {
772 kfe.Remove();
773 _target.Keyframes._keyArrays[i]._keyCount--;
774 }
775 }
776 }
777 }
778 }
779
780 _changed = true;
781 }
void Remove()
Definition: KeyframeCollection.cs:253

◆ Port() [2/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.Port ( MDL0Node  baseModel)
inline
656 {
657 MDL0Node model;
658
659 OpenFileDialog dlgOpen = new OpenFileDialog
660 {
661 Filter = "MDL0 Model (*.mdl0)|*.mdl0",
662 Title = "Select the model this animation is for..."
663 };
664
665 if (dlgOpen.ShowDialog() == DialogResult.OK)
666 {
667 if ((model = (MDL0Node) NodeFactory.FromFile(null, dlgOpen.FileName)) != null)
668 {
669 Port(baseModel, model);
670 }
671 }
672 }
void Port(MDL0Node baseModel)
Definition: CHR0Node.cs:655

◆ Replace()

override void BrawlLib.SSBB.ResourceNodes.CHR0Node.Replace ( string  fileName)
inlinevirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.ResourceNode.

248 {
249 if (fileName.EndsWith(".chr0", StringComparison.OrdinalIgnoreCase))
250 {
251 base.Replace(fileName);
252 return;
253 }
254
255 CHR0Node n = FromFile(fileName);
256 n.Name = Name;
257 Parent?.InsertChild(n, true, Index + 1);
258 Remove();
259 }
virtual void Remove()
Definition: ResourceNode.cs:741
virtual void InsertChild(ResourceNode child, int index)
Definition: ResourceNode.cs:774
ResourceNode Parent
Definition: ResourceNode.cs:245

◆ Resize() [1/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.Resize ( )
inline

Stretches or compresses all frames of the animation to fit a new frame count specified by the user.

363 {
365 if (f.ShowDialog(FrameCount) == DialogResult.OK)
366 {
367 Resize(f.NewValue);
368 }
369 }
Definition: FrameCountChanger.cs:7
DialogResult ShowDialog(int frameCount)
Definition: FrameCountChanger.cs:15
int NewValue
Definition: FrameCountChanger.cs:13
void Resize()
Stretches or compresses all frames of the animation to fit a new frame count specified by the user.
Definition: CHR0Node.cs:362

◆ Resize() [2/2]

void BrawlLib.SSBB.ResourceNodes.CHR0Node.Resize ( int  newFrameCount)
inline

Stretches or compresses all frames of the animation to fit a new frame count.

375 {
376 KeyframeEntry kfe = null;
377 float ratio = newFrameCount / (float) FrameCount;
378 foreach (CHR0EntryNode e in Children)
379 {
380 KeyframeCollection newCollection = new KeyframeCollection(9, newFrameCount + (Loop ? 1 : 0), 1, 1, 1);
381 for (int x = 0; x < FrameCount; x++)
382 {
383 int newFrame = (int) (x * ratio + 0.5f);
384 float frameRatio = newFrame == 0 ? 0 : x / (float) newFrame;
385 for (int i = 0; i < 9; i++)
386 {
387 if ((kfe = e.GetKeyframe(i, x)) != null)
388 {
389 newCollection.SetFrameValue(i, newFrame, kfe._value)._tangent =
390 kfe._tangent * (float.IsNaN(frameRatio) ? 1 : frameRatio);
391 }
392 }
393 }
394
395 e._keyframes = newCollection;
396 }
397
398 FrameCount = newFrameCount;
399 }
Definition: KeyframeCollection.cs:17
KeyframeEntry SetFrameValue(int arrayIndex, int frameIndex, float value, bool parsing=false)
Definition: KeyframeCollection.cs:74

◆ Reverse()

CHR0Node BrawlLib.SSBB.ResourceNodes.CHR0Node.Reverse ( bool  appendReverse)
inline
617 {
618 using (CHR0Node tempReversedCHR0 = new CHR0Node
620 {
621 KeyframeEntry kfe;
622 foreach (CHR0EntryNode tempEntry in Children)
623 {
624 CHR0EntryNode newIntEntry = new CHR0EntryNode {Name = tempEntry.Name};
625 newIntEntry.SetSize(tempEntry.FrameCount, Loop);
626 for (int x = 0; x < tempEntry.FrameCount; x++)
627 {
628 for (int i = 0; i < 9; i++)
629 {
630 if ((kfe = tempEntry.GetKeyframe(i, x)) != null)
631 {
632 newIntEntry.Keyframes.SetFrameValue(i, FrameCount - (x + (Loop ? 0 : 1)), kfe._value)
633 ._tangent =
634 kfe._tangent;
635 }
636 }
637 }
638
639 tempReversedCHR0.AddChild(newIntEntry);
640 }
641
642 if (appendReverse)
643 {
644 Append(tempReversedCHR0);
645 return this;
646 }
647 else
648 {
649 Replace(tempReversedCHR0);
650 return tempReversedCHR0;
651 }
652 }
653 }
override void Replace(string fileName)
Definition: CHR0Node.cs:247

◆ UpdateChildFrameLimits()

override void BrawlLib.SSBB.ResourceNodes.CHR0Node.UpdateChildFrameLimits ( )
inlineprotectedvirtual

Reimplemented from BrawlLib.SSBB.ResourceNodes.NW4RAnimationNode.

51 {
52 foreach (CHR0EntryNode n in Children)
53 {
54 n.SetSize(_numFrames, Loop);
55 }
56 }

Member Data Documentation

◆ num

int BrawlLib.SSBB.ResourceNodes.CHR0Node.num

Property Documentation

◆ AllowedChildTypes

override Type [] BrawlLib.SSBB.ResourceNodes.CHR0Node.AllowedChildTypes
get

◆ FrameCount

override int BrawlLib.SSBB.ResourceNodes.CHR0Node.FrameCount
getset
34 {
35 get => base.FrameCount;
36 set => base.FrameCount = value;
37 }

◆ Loop

override bool BrawlLib.SSBB.ResourceNodes.CHR0Node.Loop
getset
41 {
42 get => base.Loop;
43 set
44 {
45 base.Loop = value;
47 }
48 }
override void UpdateChildFrameLimits()
Definition: CHR0Node.cs:50

◆ ResourceFileType

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

◆ SupportedVersions

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

◆ Tag

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

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