internal void ApplyCHR0(CHR0Node node, float index) { CHR0EntryNode e; _frameState = _bindState; if (node != null && index >= 1 && (e = node.FindChild(Name, false) as CHR0EntryNode) != null) //Set to anim pose fixed(FrameState *v = &_frameState) { float *f = (float *)v; for (int i = 0; i < 9; i++) { if (e.Keyframes[i]._keyCount > 0) { f[i] = e.GetFrameValue(i, index - 1); } } _frameState.CalcTransforms(); } foreach (MDL0BoneNode b in Children) { b.ApplyCHR0(node, index); } }
internal void ApplyCHR0(CHR0Node node, int index, bool linear) { CHR0EntryNode e; _frameState = _bindState; if (node != null && index > 0 && (e = node.FindChild(Name, false) as CHR0EntryNode) != null) //Set to anim pose fixed(FrameState *v = &_frameState) { float *f = (float *)v; for (int i = 0; i < 9; i++) { if (e.Keyframes[(KeyFrameMode)(i + 0x10)] > 0) { f[i] = e.GetFrameValue((KeyFrameMode)(i + 0x10), index - 1, linear, node.Loop); } } _frameState.CalcTransforms(); } foreach (MDL0BoneNode b in Children) { b.ApplyCHR0(node, index, linear); } }
public FrameState Derive() { FrameState state = new FrameState(); fixed(float *p = _values) { //Translation is easy! state._translate = *(Vector3 *)&p[12]; //Scale, use sqrt of rotation columns state._scale._x = (float)Math.Round(Math.Sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2]), 4); state._scale._y = (float)Math.Round(Math.Sqrt(p[4] * p[4] + p[5] * p[5] + p[6] * p[6]), 4); state._scale._z = (float)Math.Round(Math.Sqrt(p[8] * p[8] + p[9] * p[9] + p[10] * p[10]), 4); state._rotate = GetAngles(); } state.CalcTransforms(); return(state); }
internal unsafe void BoxChanged(object sender, EventArgs e) { if (_transformObject == null) { return; } NumericInputBox box = sender as NumericInputBox; int index = (int)box.Tag; if (_transformObject is MDL0BoneNode) { MDL0BoneNode bone = _transformObject as MDL0BoneNode; if ((_selectedAnim != null) && (_animFrame > 0)) { //Find bone anim and change transform CHR0EntryNode entry = _selectedAnim.FindChild(bone.Name, false) as CHR0EntryNode; if (entry == null) //Create new bone animation { if (!float.IsNaN(box.Value)) { entry = _selectedAnim.CreateEntry(); entry._name = bone.Name; //Set initial values FrameState state = bone._bindState; float * p = (float *)&state; for (int i = 0; i < 3; i++) { if (p[i] != 1.0f) { entry.SetKeyframe(KeyFrameMode.ScaleX + i, 0, p[i]); } } for (int i = 3; i < 9; i++) { if (p[i] != 0.0f) { entry.SetKeyframe(KeyFrameMode.ScaleX + i, 0, p[i]); } } entry.SetKeyframe(KeyFrameMode.ScaleX + index, _animFrame - 1, box.Value); } } else //Set existing { if (float.IsNaN(box.Value)) { entry.RemoveKeyframe(KeyFrameMode.ScaleX + index, _animFrame - 1); } else { entry.SetKeyframe(KeyFrameMode.ScaleX + index, _animFrame - 1, box.Value); } } } else { //Change base transform FrameState state = bone._bindState; float * p = (float *)&state; p[index] = float.IsNaN(box.Value) ? (index > 2 ? 0.0f : 1.0f) : box.Value; state.CalcTransforms(); bone._bindState = state; bone.RecalcBindState(); bone.SignalPropertyChange(); } _targetModel.ApplyCHR(_selectedAnim, _animFrame); ResetBox(index); if (RenderStateChanged != null) { RenderStateChanged(this, null); } } }