public void AverageKeys(string boneName) { CHR0EntryNode w = FindChild(boneName, false) as CHR0EntryNode; if (w == null) { return; } for (int i = 0; i < 9; i++) { if (w.Keyframes._keyArrays[i]._keyCount > 1) { KeyframeEntry root = w.Keyframes._keyArrays[i]._keyRoot; if (root._next != root && root._prev != root && root._prev != root._next) { float tan = (root._next._tangent + root._prev._tangent) / 2.0f; float val = (root._next._value + root._prev._value) / 2.0f; root._next._tangent = tan; root._prev._tangent = tan; root._next._value = val; root._prev._value = val; } } } SignalPropertyChange(); }
public CHR0EntryNode CreateEntry() { CHR0EntryNode n = new CHR0EntryNode(); n._numFrames = _numFrames; n._name = this.FindName(null); AddChild(n); return(n); }
public CHR0EntryNode CreateEntry(string name) { CHR0EntryNode n = new CHR0EntryNode(); n._name = this.FindName(name); AddChild(n); n.SetSize(_numFrames, Loop); return(n); }
public void Reverse(bool appendReverse) { CHR0Node tempReversedCHR0 = new CHR0Node(); tempReversedCHR0.Name = this.Name + "_Reversed"; tempReversedCHR0.Loop = this.Loop; tempReversedCHR0.FrameCount = FrameCount; // Fixes non-looped animations being off by a frame int loopfix = 0; if (!Loop) { loopfix = 1; } KeyframeEntry kfe; foreach (CHR0EntryNode tempEntry in Children) { CHR0EntryNode newIntEntry = new CHR0EntryNode() { Name = tempEntry.Name }; newIntEntry.SetSize(tempEntry.FrameCount, Loop); for (int x = 0; x < tempEntry.FrameCount; x++) { for (int i = 0; i < 9; i++) { if ((kfe = tempEntry.GetKeyframe(i, x)) != null) { newIntEntry.Keyframes.SetFrameValue(i, FrameCount - (x + loopfix), kfe._value)._tangent = kfe._tangent; } } } tempReversedCHR0.AddChild(newIntEntry); } if (appendReverse) { Append(tempReversedCHR0, 1); } else { // Remove old keyframes while (HasChildren) { RemoveChild(Children[0]); } // Add reversed keyframes foreach (CHR0EntryNode entryToAdd in tempReversedCHR0.Children) { entryToAdd.SignalPropertyChange(); AddChild(entryToAdd); } } }
/// <summary> /// Adds an animation to the end of this one /// </summary> public void Append(CHR0Node external, int timesToAppend) { KeyframeEntry kfe; int extCount = external.FrameCount; for (int appendCount = 0; appendCount < timesToAppend; ++appendCount) { int origIntCount = FrameCount; FrameCount += extCount; foreach (CHR0EntryNode extEntry in external.Children) { CHR0EntryNode intEntry = null; if ((intEntry = (CHR0EntryNode)FindChild(extEntry.Name, false)) == null) { CHR0EntryNode newIntEntry = new CHR0EntryNode() { Name = extEntry.Name }; newIntEntry.SetSize(extEntry.FrameCount + origIntCount, Loop); for (int x = 0; x < extEntry.FrameCount; x++) { for (int i = 0; i < 9; i++) { if ((kfe = extEntry.GetKeyframe(i, x)) != null) { newIntEntry.Keyframes.SetFrameValue(i, x + origIntCount, kfe._value)._tangent = kfe._tangent; } } } AddChild(newIntEntry); } else { for (int x = 0; x < extEntry.FrameCount; x++) { for (int i = 0; i < 9; i++) { if ((kfe = extEntry.GetKeyframe(i, x)) != null) { intEntry.Keyframes.SetFrameValue(i, x + origIntCount, kfe._value)._tangent = kfe._tangent; } } } } } } }
public void Append(CHR0Node external) { KeyframeEntry kfe; int oldCount = FrameCount; FrameCount += external.FrameCount; foreach (CHR0EntryNode _target in external.Children) { CHR0EntryNode node = null; if ((node = (CHR0EntryNode)FindChild(_target.Name, false)) == null) { CHR0EntryNode newNode = new CHR0EntryNode() { Name = _target.Name }; newNode._numFrames = _target.FrameCount + oldCount; for (int x = 0; x < _target.FrameCount; x++) { for (int i = 0x10; i < 0x19; i++) { if ((kfe = _target.GetKeyframe((KeyFrameMode)i, x)) != null) { newNode.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent; } } } AddChild(newNode); } else { node._numFrames += oldCount; for (int x = 0; x < _target.FrameCount; x++) { for (int i = 0x10; i < 0x19; i++) { if ((kfe = _target.GetKeyframe((KeyFrameMode)i, x)) != null) { node.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent; } } } } } }
/// <summary> /// Adds an animation to the end of this one /// </summary> public void Append(CHR0Node external) { KeyframeEntry kfe; int origIntCount = FrameCount; int extCount = external.FrameCount; FrameCount += extCount; foreach (CHR0EntryNode _extEntry in external.Children) { CHR0EntryNode _intEntry = null; if ((_intEntry = (CHR0EntryNode)FindChild(_extEntry.Name, false)) == null) { CHR0EntryNode newIntEntry = new CHR0EntryNode() { Name = _extEntry.Name }; newIntEntry._numFrames = _extEntry.FrameCount + origIntCount; for (int x = 0; x < _extEntry.FrameCount; x++) { for (int i = 0x10; i < 0x19; i++) { if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null) { newIntEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent; } } } AddChild(newIntEntry); } else { for (int x = 0; x < _extEntry.FrameCount; x++) { for (int i = 0x10; i < 0x19; i++) { if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null) { _intEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent; } } } } } }
public CHR0EntryNode CreateEntryFromBone(MDL0BoneNode b, int framesToGenerate, bool generateOrigin) { CHR0EntryNode n = new CHR0EntryNode(); if (!generateOrigin) { if (b.isOriginRot() && b.isOriginScale() && b.isOriginTrans()) { //Console.WriteLine(" " + b + " has all values equal to origin. Not generating keyframes."); return(null); } } n._name = this.FindName(b.Name); AddChild(n); n.SetSize(_numFrames, Loop); //Console.WriteLine(_numFrames); for (int i = 0; i < framesToGenerate; ++i) { n.generateKeyframeFromBone(b, i, true, generateOrigin); } SignalPropertyChange(); return(n); }
public void MergeWith(CHR0Node external) { if (external.FrameCount != FrameCount && MessageBox.Show(null, "Frame counts are not equal; the shorter animation will end early. Do you still wish to continue?", "", MessageBoxButtons.YesNo) == DialogResult.No) return; if (external.FrameCount > FrameCount) FrameCount = external.FrameCount; foreach (CHR0EntryNode _extTarget in external.Children) { CHR0EntryNode node = null; KeyframeEntry kfe = null; CHR0EntryNode entry = new CHR0EntryNode() { Name = _extTarget.Name }; entry._numFrames = _extTarget.FrameCount; //Apply all external keyframes to current entry. for (int x = 0; x < _extTarget.FrameCount; x++) for (int i = 0x10; i < 0x19; i++) if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null) entry.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent; if ((node = FindChild(_extTarget.Name, false) as CHR0EntryNode) == null) AddChild(entry, true); else { DialogResult result = MessageBox.Show(null, "A bone entry with the name " + _extTarget.Name + " already exists.\nDo you want to rename this entry?\nOtherwise, you will have the option to merge the keyframes.", "Rename Entry?", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { Top: RenameDialog d = new RenameDialog(); if (d.ShowDialog(null, entry) == DialogResult.OK) { if (entry.Name != _extTarget.Name) AddChild(entry, true); else { MessageBox.Show("The name wasn't changed!"); goto Top; } } } else if (result == DialogResult.No) { result = MessageBox.Show(null, "Do you want to merge the keyframes of the entries?", "Merge Keyframes?", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { KeyframeEntry kfe2 = null; if (_extTarget.FrameCount > node.FrameCount) node._numFrames = _extTarget.FrameCount; //Merge all external keyframes with the current entry. for (int x = 0; x < _extTarget.FrameCount; x++) for (int i = 0x10; i < 0x19; i++) if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null) if ((kfe2 = node.GetKeyframe((KeyFrameMode)i, x)) == null) node.SetKeyframe((KeyFrameMode)i, x, kfe._value); else { result = MessageBox.Show(null, "A keyframe at frame " + x + " already exists.\nOld value: " + kfe2._value + "\nNew value:" + kfe._value + "\nReplace the old value with the new one?", "Replace Keyframe?", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) node.SetKeyframe((KeyFrameMode)i, x, kfe._value); else if (result == DialogResult.Cancel) { Restore(); return; } } } else if (result == DialogResult.Cancel) { Restore(); return; } } else if (result == DialogResult.Cancel) { Restore(); return; } } } }
public CHR0EntryNode CreateEntry(string name) { CHR0EntryNode n = new CHR0EntryNode(); n._numFrames = _numFrames; n._name = this.FindName(name); AddChild(n); return n; }
/// <summary> /// Adds an animation to the end of this one /// </summary> public void Append(CHR0Node external) { KeyframeEntry kfe; int origIntCount = FrameCount; int extCount = external.FrameCount; FrameCount += extCount; foreach (CHR0EntryNode _extEntry in external.Children) { CHR0EntryNode _intEntry = null; if ((_intEntry = (CHR0EntryNode)FindChild(_extEntry.Name, false)) == null) { CHR0EntryNode newIntEntry = new CHR0EntryNode() { Name = _extEntry.Name }; newIntEntry._numFrames = _extEntry.FrameCount + origIntCount; for (int x = 0; x < _extEntry.FrameCount; x++) for (int i = 0x10; i < 0x19; i++) if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null) newIntEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent; AddChild(newIntEntry); } else for (int x = 0; x < _extEntry.FrameCount; x++) for (int i = 0x10; i < 0x19; i++) if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null) _intEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent; } }
public void Apply(ResourceNode node) { string _name = name.Text; KeyframeEntry kfe = null; MDL0Node model = null; MDL0Node _targetModel = null; if (Port.Checked) { MessageBox.Show("Please open the model you want to port the animations to.\nThen open the model the animations work normally for."); OpenFileDialog dlgOpen = new OpenFileDialog(); OpenFileDialog dlgOpen2 = new OpenFileDialog(); dlgOpen.Filter = dlgOpen2.Filter = "MDL0 Model (*.mdl0)|*.mdl0"; dlgOpen.Title = "Select the model to port the animations to..."; dlgOpen2.Title = "Select the model the animations are for..."; if (dlgOpen.ShowDialog() == DialogResult.OK) { _targetModel = (MDL0Node)NodeFactory.FromFile(null, dlgOpen.FileName); if (dlgOpen2.ShowDialog() == DialogResult.OK) model = (MDL0Node)NodeFactory.FromFile(null, dlgOpen2.FileName); } } Vector3 scale = new Vector3(ScaleX.Value, ScaleY.Value, ScaleZ.Value); Vector3 rot = new Vector3(RotateX.Value, RotateY.Value, RotateZ.Value); Vector3 trans = new Vector3(TranslateX.Value, TranslateY.Value, TranslateZ.Value); ResourceNode[] CHR0 = node.FindChildrenByType(null, ResourceType.CHR0); foreach (CHR0Node n in CHR0) { if (NameContains.Checked && !n.Name.Contains(targetName.Text)) continue; if (editLoop.Checked) n.Loop = enableLoop.Checked; if (Rename.Checked) n.Name = newName.Text; if (ChangeVersion.Checked) n.Version = Version.SelectedIndex + 4; if (Port.Checked && _targetModel != null && model != null) n.Port(_targetModel, model); if (copyKeyframes.Checked) { CHR0EntryNode _copyNode = n.FindChild(keyframeCopy.Text, false) as CHR0EntryNode; if (n.FindChild(_name, false) == null) { if (!String.IsNullOrEmpty(_name)) { CHR0EntryNode c = new CHR0EntryNode(); c._numFrames = n.FrameCount; c.Name = _name; if (_copyNode != null) for (int x = 0; x < _copyNode._numFrames; x++) for (int i = 0x10; i < 0x19; i++) if ((kfe = _copyNode.GetKeyframe((KeyFrameMode)i, x)) != null) c.SetKeyframe((KeyFrameMode)i, x, kfe._value); n.AddChild(c); } } } CHR0EntryNode entry = n.FindChild(_name, false) as CHR0EntryNode; if (entry == null) { entry = new CHR0EntryNode() { _name = _name }; n.AddChild(entry); } AnimationFrame anim; bool hasKeyframe = false; int numFrames = entry.FrameCount; int low = 0x10, high = 0x13; if (ScaleReplace.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if (entry.GetKeyframe((KeyFrameMode)i, x) != null) entry.RemoveKeyframe((KeyFrameMode)i, x); entry.SetKeyframeOnlyScale(0, scale); } else if (ScaleClear.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if (entry.GetKeyframe((KeyFrameMode)i, x) != null) entry.RemoveKeyframe((KeyFrameMode)i, x); } else if (ScaleAdd.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value += scale._x; else if (i == low + 1) kfe._value += scale._y; else if (i == high - 1) kfe._value += scale._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newScale = anim.Scale; scale._x += newScale._x; scale._y += newScale._y; scale._z += newScale._z; entry.SetKeyframeOnlyScale(0, scale); } } else if (ScaleSubtract.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value -= scale._x; else if (i == low + 1) kfe._value -= scale._y; else if (i == high - 1) kfe._value -= scale._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newScale = anim.Scale; scale._x = newScale._x - scale._x; scale._y = newScale._y - scale._y; scale._z = newScale._z - scale._z; entry.SetKeyframeOnlyScale(0, scale); } } else if (ScaleMultiply.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value *= scale._x; else if (i == low + 1) kfe._value *= scale._y; else if (i == high - 1) kfe._value *= scale._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newScale = anim.Scale; scale._x *= newScale._x; scale._y *= newScale._y; scale._z *= newScale._z; entry.SetKeyframeOnlyScale(0, scale); } } else if (ScaleDivide.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low && scale._x != 0) kfe._value /= scale._x; else if (i == low + 1 && scale._y != 0) kfe._value /= scale._y; else if (i == high - 1 && scale._z != 0) kfe._value /= scale._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newScale = anim.Scale; if (scale._x != 0) scale._x = newScale._x / scale._x; if (scale._y != 0) scale._y = newScale._y / scale._y; if (scale._z != 0) scale._z = newScale._z / scale._z; entry.SetKeyframeOnlyScale(0, scale); } } low = 0x13; high = 0x16; if (RotateReplace.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if (entry.GetKeyframe((KeyFrameMode)i, x) != null) entry.RemoveKeyframe((KeyFrameMode)i, x); entry.SetKeyframeOnlyRot(0, rot); } else if (RotateClear.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if (entry.GetKeyframe((KeyFrameMode)i, x) != null) entry.RemoveKeyframe((KeyFrameMode)i, x); } else if (RotateAdd.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value += rot._x; else if (i == low + 1) kfe._value += rot._y; else if (i == high - 1) kfe._value += rot._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newRotate = anim.Rotation; rot._x += newRotate._x; rot._y += newRotate._y; rot._z += newRotate._z; entry.SetKeyframeOnlyRot(0, rot); } } else if (RotateSubtract.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value -= rot._x; else if (i == low + 1) kfe._value -= rot._y; else if (i == high - 1) kfe._value -= rot._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newRotate = anim.Rotation; rot._x = newRotate._x - rot._x; rot._y = newRotate._y - rot._y; rot._z = newRotate._z - rot._z; entry.SetKeyframeOnlyRot(0, rot); } } else if (RotateMultiply.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value *= rot._x; else if (i == low + 1) kfe._value *= rot._y; else if (i == high - 1) kfe._value *= rot._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newRotate = anim.Rotation; rot._x *= newRotate._x; rot._y *= newRotate._y; rot._z *= newRotate._z; entry.SetKeyframeOnlyRot(0, rot); } } else if (RotateDivide.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low && rot._x != 0) kfe._value /= rot._x; else if (i == low + 1 && rot._y != 0) kfe._value /= rot._y; else if (i == high - 1 && rot._z != 0) kfe._value /= rot._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newRotate = anim.Rotation; if (rot._x != 0) rot._x = newRotate._x / rot._x; if (rot._y != 0) rot._y = newRotate._y / rot._y; if (rot._z != 0) rot._z = newRotate._z / rot._z; entry.SetKeyframeOnlyRot(0, rot); } } low = 0x16; high = 0x19; if (TranslateReplace.Checked) { for (int x = 0; x < numFrames; x++) for (int i = 0x10; i < high; i++) if (entry.GetKeyframe((KeyFrameMode)i, x) != null) entry.RemoveKeyframe((KeyFrameMode)i, x); entry.SetKeyframeOnlyTrans(0, trans); } else if (TranslateClear.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if (entry.GetKeyframe((KeyFrameMode)i, x) != null) entry.RemoveKeyframe((KeyFrameMode)i, x); } else if (TranslateAdd.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value += trans._x; else if (i == low + 1) kfe._value += trans._y; else if (i == high - 1) kfe._value += trans._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newTranslate = anim.Translation; trans._x += newTranslate._x; trans._y += newTranslate._y; trans._z += newTranslate._z; entry.SetKeyframeOnlyTrans(0, trans); } } else if (TranslateSubtract.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value -= trans._x; else if (i == low + 1) kfe._value -= trans._y; else if (i == high - 1) kfe._value -= trans._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newTranslate = anim.Translation; trans._x = newTranslate._x - trans._x; trans._y = newTranslate._y - trans._y; trans._z = newTranslate._z - trans._z; entry.SetKeyframeOnlyTrans(0, trans); } } else if (TranslateMultiply.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low) kfe._value *= trans._x; else if (i == low + 1) kfe._value *= trans._y; else if (i == high - 1) kfe._value *= trans._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newTranslate = anim.Translation; trans._x *= newTranslate._x; trans._y *= newTranslate._y; trans._z *= newTranslate._z; entry.SetKeyframeOnlyTrans(0, trans); } } else if (TranslateDivide.Checked) { for (int x = 0; x < numFrames; x++) for (int i = low; i < high; i++) if ((kfe = entry.GetKeyframe((KeyFrameMode)i, x)) != null) { if (i == low && trans._x != 0) kfe._value /= trans._x; else if (i == low + 1 && trans._y != 0) kfe._value /= trans._y; else if (i == high - 1 && trans._z != 0) kfe._value /= trans._z; hasKeyframe = true; } if (!hasKeyframe) { anim = entry.GetAnimFrame(0); Vector3 newTranslate = anim.Translation; if (trans._x != 0) trans._x = newTranslate._x / trans._x; if (trans._y != 0) trans._y = newTranslate._y / trans._y; if (trans._z != 0) trans._z = newTranslate._z / trans._z; entry.SetKeyframeOnlyTrans(0, trans); } } } }
private void FixChildren(MDL0BoneNode node, int axis) { KeyframeEntry kfe; foreach (MDL0BoneNode b in node.Children) { CHR0EntryNode _target = (CHR0EntryNode)FindChild(b.Name, true); if (_target != null) { switch (axis) { case 0: //X, correct Y and Z for (int l = 0; l < _target.FrameCount; l++) { for (int g = 0x13; g < 0x16; g++) { if (g != 0x13) { if ((kfe = _target.GetKeyframe((KeyFrameMode)g, l)) != null) { kfe._value *= -1; } } } } break; case 1: //Y, correct X and Z for (int l = 0; l < _target.FrameCount; l++) { for (int g = 0x13; g < 0x16; g++) { if (g != 0x14) { if ((kfe = _target.GetKeyframe((KeyFrameMode)g, l)) != null) { kfe._value *= -1; } } } } break; case 2: //Z, correct X and Y for (int l = 0; l < _target.FrameCount; l++) { for (int g = 0x13; g < 0x16; g++) { if (g != 0x15) { if ((kfe = _target.GetKeyframe((KeyFrameMode)g, l)) != null) { kfe._value *= -1; } } } } break; } } FixChildren(b, axis); } }
public void MergeWith(CHR0Node external) { if (external.FrameCount != FrameCount && MessageBox.Show(null, "Frame counts are not equal; the shorter animation will end early. Do you still wish to continue?", "", MessageBoxButtons.YesNo) == DialogResult.No) { return; } if (external.FrameCount > FrameCount) { FrameCount = external.FrameCount; } foreach (CHR0EntryNode _extTarget in external.Children) { CHR0EntryNode node = null; KeyframeEntry kfe = null; CHR0EntryNode entry = new CHR0EntryNode() { Name = _extTarget.Name }; entry._numFrames = _extTarget.FrameCount; //Apply all external keyframes to current entry. for (int x = 0; x < _extTarget.FrameCount; x++) { for (int i = 0x10; i < 0x19; i++) { if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null) { entry.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent; } } } if ((node = FindChild(_extTarget.Name, false) as CHR0EntryNode) == null) { AddChild(entry, true); } else { DialogResult result = MessageBox.Show(null, "A bone entry with the name " + _extTarget.Name + " already exists.\nDo you want to rename this entry?\nOtherwise, you will have the option to merge the keyframes.", "Rename Entry?", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { Top: RenameDialog d = new RenameDialog(); if (d.ShowDialog(null, entry) == DialogResult.OK) { if (entry.Name != _extTarget.Name) { AddChild(entry, true); } else { MessageBox.Show("The name wasn't changed!"); goto Top; } } } else if (result == DialogResult.No) { result = MessageBox.Show(null, "Do you want to merge the keyframes of the entries?", "Merge Keyframes?", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { KeyframeEntry kfe2 = null; if (_extTarget.FrameCount > node.FrameCount) { node._numFrames = _extTarget.FrameCount; } //Merge all external keyframes with the current entry. for (int x = 0; x < _extTarget.FrameCount; x++) { for (int i = 0x10; i < 0x19; i++) { if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null) { if ((kfe2 = node.GetKeyframe((KeyFrameMode)i, x)) == null) { node.SetKeyframe((KeyFrameMode)i, x, kfe._value); } else { result = MessageBox.Show(null, "A keyframe at frame " + x + " already exists.\nOld value: " + kfe2._value + "\nNew value:" + kfe._value + "\nReplace the old value with the new one?", "Replace Keyframe?", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { node.SetKeyframe((KeyFrameMode)i, x, kfe._value); } else if (result == DialogResult.Cancel) { Restore(); return; } } } } } } else if (result == DialogResult.Cancel) { Restore(); return; } } else if (result == DialogResult.Cancel) { Restore(); return; } } } }
public static CHR0Node Convert(string input) { try { CHR0Node chr0 = new CHR0Node(); chr0.Name = Path.GetFileNameWithoutExtension(input); chr0.Loop = false; chr0.Version = 4; for (TextReader reader = new StreamReader(input); reader.Peek() != -1; ) { string line = reader.ReadLine(); if (line.CompareTo("Animation Keyframe Data Frames") == 0) { line = reader.ReadLine(); //Remove any non-digit characters string justNumbers = new String(line.Where(Char.IsDigit).ToArray()); int keyFrameCount = int.Parse(justNumbers); chr0.FrameCount = keyFrameCount; for (line = reader.ReadLine(); line != null && line.CompareTo("End Of Animation Data") != 0; line = reader.ReadLine()) { if (line.CompareTo("Keyframe Data") == 0) { CHR0EntryNode node = new CHR0EntryNode(); node.Name = reader.ReadLine(); node._numFrames = keyFrameCount; Coords translation = new Coords(); Coords rotation = new Coords(); Coords scale = new Coords(); for (line = reader.ReadLine(); line != null && line.CompareTo("End of Keyframe Data") != 0; line = reader.ReadLine()) { //Use goto to retry the loop without advancing the reader, when it returns from getCoords it will have the next line we need from it. retry: if (line.CompareTo("Translation") == 0) { reader.ReadLine(); //Skip first blank line translation = getCoords(reader, out line); goto retry; } else if (line.CompareTo("Rotation") == 0) { reader.ReadLine(); //Skip first blank line rotation = getCoords(reader, out line); goto retry; } else if (line.CompareTo("Scale") == 0) { reader.ReadLine(); //Skip first blank line scale = getCoords(reader, out line); goto retry; } else if (line.CompareTo("End of Keyframe Data") == 0) //If line equals this now it's time to break break; } //Add frames to node for (int frameCount = 0; translation.highestCount > frameCount || rotation.highestCount > frameCount || scale.highestCount > frameCount; frameCount++) { if (translation.highestCount > frameCount) { if (translation.x.Count != 0 && frameCount < translation.x.Count) node.SetKeyframe(KeyFrameMode.TransX, frameCount, translation.x[frameCount]); if (translation.y.Count != 0 && frameCount < translation.y.Count) node.SetKeyframe(KeyFrameMode.TransY, frameCount, translation.y[frameCount]); if (translation.z.Count != 0 && frameCount < translation.z.Count) node.SetKeyframe(KeyFrameMode.TransZ, frameCount, translation.z[frameCount]); } if (rotation.highestCount > frameCount) { if (rotation.x.Count != 0 && frameCount < rotation.x.Count) node.SetKeyframe(KeyFrameMode.RotX, frameCount, rotation.x[frameCount]); if (rotation.y.Count != 0 && frameCount < rotation.y.Count) node.SetKeyframe(KeyFrameMode.RotY, frameCount, rotation.y[frameCount]); if (rotation.z.Count != 0 && frameCount < rotation.z.Count) node.SetKeyframe(KeyFrameMode.RotZ, frameCount, rotation.z[frameCount]); } if (scale.highestCount > frameCount) { if (scale.x.Count != 0 && frameCount < scale.x.Count) node.SetKeyframe(KeyFrameMode.ScaleX, frameCount, scale.x[frameCount]); if (scale.y.Count != 0 && frameCount < scale.y.Count) node.SetKeyframe(KeyFrameMode.ScaleY, frameCount, scale.y[frameCount]); if (scale.z.Count != 0 && frameCount < scale.z.Count) node.SetKeyframe(KeyFrameMode.ScaleZ, frameCount, scale.z[frameCount]); } } chr0.AddChild(node); } } } else { MessageBox.Show("Not a valid CHR0 text file."); return null; } } return chr0; } catch (Exception e) { MessageBox.Show("There was a problem importing keyframes.\n\nError:\n" + e.ToString()); return null; } }