public Md5JointValue GetBaseJointValue(int joint, Md5Frame baseframe, Md5Frame thisframe) { Md5JointValue v; int parentjoint = anim.Hierarchy[joint].ParentIndex; if (parentjoint < 0) { v = baseframe.Values[joint]; } else { if (parentjoint >= joint) { throw new Exception(""); } Md5JointValue parent = thisframe.Values[parentjoint]; //Vector3 p = Matrix4Extensions.FromQuaternion(parent.Orientation) * baseframe.Values[joint].Position; Vector3 p = Vector3.Transform(baseframe.Values[joint].Position, parent.Orientation); p += parent.Position; Quaternion q = baseframe.Values[joint].Orientation * parent.Orientation; q.Normalize(); v.Orientation = q; v.Position = p; } return(v); }
public Md5JointValue GetBaseFrameJointValue(int joint, float[] values) { Md5JointValue v = new Md5JointValue(); v.Position.X = values[joint * 6 + 0]; if (Flip) { v.Position.Y = values[joint * 6 + 2]; v.Position.Z = values[joint * 6 + 1]; } else { v.Position.Y = values[joint * 6 + 1]; v.Position.Z = values[joint * 6 + 2]; } v.Orientation.X = values[joint * 6 + 3]; if (Flip) { v.Orientation.Y = values[joint * 6 + 5]; v.Orientation.Z = values[joint * 6 + 4]; } else { v.Orientation.Y = values[joint * 6 + 4]; v.Orientation.Z = values[joint * 6 + 5]; } v.Orientation.W = (float)Math.Sqrt(1.0f - ((v.Orientation.X * v.Orientation.X) + (v.Orientation.Y * v.Orientation.Y) + (v.Orientation.Z * v.Orientation.Z))); return(v); }
public Vector3 CalcVertexPosition(Md5Vertex v, Md5Anim a, int frame) { Vector3 pos = Vector3.Zero; for (int i = v.WeightIndex; i < v.WeightIndex + v.WeightCount; ++i) { Md5Weight w = Weights[i]; Md5JointValue j = a.Frames[frame].Values[w.JointIndex]; Matrix4 m = Matrix4Extensions.FromTranslation(j.Position) * Matrix4Extensions.FromQuaternion(j.Orientation); pos += w.Value * Vector3.Transform(w.Position, m); } return(pos); }
/* * public float[] GetJointValues(float[] values, int joint) * { * float[] r = new float[6]; * int i = 0; * int c = 1; * for (int k = 0; k < 6; ++k) * { * //if ((Hierarchy[joint].Components & c) != 0) * if (false) * { * //component is animated * r[k] = values[anim.Hierarchy[joint].FrameIndex + i]; * i++; * } * else * { * //not animated, get from baseframe * //r[k] = values[joint*6+k]; * } * c *= 2; * } * return r; * } */ public Md5JointValue GetJointValue(float[] values, int joint, Md5Frame thisframe, Md5Frame baseframe) { Md5JointValue v = baseframe.Values[joint]; int i = anim.Hierarchy[joint].FrameIndex; int c = anim.Hierarchy[joint].Components; if (Flip) { if ((c & Md5JointAnim.Tx) != 0) { v.Position.X = values[i++]; } if ((c & Md5JointAnim.Ty) != 0) { v.Position.Z = values[i++]; } if ((c & Md5JointAnim.Tz) != 0) { v.Position.Y = values[i++]; } if ((c & Md5JointAnim.Qx) != 0) { v.Orientation.X = values[i++]; } if ((c & Md5JointAnim.Qy) != 0) { v.Orientation.Z = values[i++]; } if ((c & Md5JointAnim.Qz) != 0) { v.Orientation.Y = values[i++]; } } else { if ((c & Md5JointAnim.Tx) != 0) { v.Position.X = values[i++]; } if ((c & Md5JointAnim.Ty) != 0) { v.Position.Y = values[i++]; } if ((c & Md5JointAnim.Tz) != 0) { v.Position.Z = values[i++]; } if ((c & Md5JointAnim.Qx) != 0) { v.Orientation.X = values[i++]; } if ((c & Md5JointAnim.Qy) != 0) { v.Orientation.Y = values[i++]; } if ((c & Md5JointAnim.Qz) != 0) { v.Orientation.Z = values[i++]; } } float term = 1.0f - ((v.Orientation.X * v.Orientation.X) + (v.Orientation.Y * v.Orientation.Y) + (v.Orientation.Z * v.Orientation.Z)); if (term < 0.0f) { v.Orientation.W = 0.0f; } else { v.Orientation.W = (float)Math.Sqrt(term); } //v.Orientation.W = (float)Math.Sqrt(1.0f - ); int parentjoint = anim.Hierarchy[joint].ParentIndex; if (parentjoint < 0) { } else { if (parentjoint >= joint) { throw new Exception(""); } Md5JointValue parent = thisframe.Values[parentjoint]; //Vector3 p = Matrix4Extensions.FromQuaternion(parent.Orientation) * v.Position; Vector3 p = Vector3.Transform(v.Position, parent.Orientation); p += parent.Position; Quaternion q = v.Orientation * parent.Orientation; q.Normalize(); v.Orientation = q; v.Position = p; } return(v); }
public Md5JointValue GetBaseFrameJointValue(int joint, float[] values) { Md5JointValue v = new Md5JointValue(); v.Position.X = values[joint * 6 + 0]; if (Flip) { v.Position.Y = values[joint * 6 + 2]; v.Position.Z = values[joint * 6 + 1]; } else { v.Position.Y = values[joint * 6 + 1]; v.Position.Z = values[joint * 6 + 2]; } v.Orientation.X = values[joint * 6 + 3]; if (Flip) { v.Orientation.Y = values[joint * 6 + 5]; v.Orientation.Z = values[joint * 6 + 4]; } else { v.Orientation.Y = values[joint * 6 + 4]; v.Orientation.Z = values[joint * 6 + 5]; } v.Orientation.W = (float)Math.Sqrt(1.0f - ((v.Orientation.X * v.Orientation.X) + (v.Orientation.Y * v.Orientation.Y) + (v.Orientation.Z * v.Orientation.Z))); return v; }