private void loadData() { for (int j = 0; j < NodeCount; j++) { TkAnimNodeData node = NodeData[j]; //Init dictionary entries anim_rotations[node.Node] = new OpenTK.Quaternion[FrameCount]; anim_positions[node.Node] = new Vector3[FrameCount]; anim_scales[node.Node] = new Vector3[FrameCount]; for (int i = 0; i < FrameCount; i++) { NMSUtils.fetchRotQuaternion(node, this, i, ref anim_rotations[node.Node][i]); //use Ref NMSUtils.fetchTransVector(node, this, i, ref anim_positions[node.Node][i]); //use Ref NMSUtils.fetchScaleVector(node, this, i, ref anim_scales[node.Node][i]); //use Ref } } }
//TODO: It would be nice if I didn't have to do make the method public, but it needs a lot of work on the //AnimPoseComponent class to temporarily store the selected pose frames, while also in the model.update method //Locator Animation Stuff public Dictionary <string, Matrix4> loadPose() { if (animPoseComponentID < 0) { return(new Dictionary <string, Matrix4>()); } AnimPoseComponent apc = _components[animPoseComponentID] as AnimPoseComponent; Dictionary <string, Matrix4> posematrices = new Dictionary <string, Matrix4>(); foreach (TkAnimNodeData node in apc._poseFrameData.NodeData) { List <OpenTK.Quaternion> quats = new List <OpenTK.Quaternion>(); List <Vector3> translations = new List <Vector3>(); List <Vector3> scales = new List <Vector3>(); //We should interpolate frame shit over all the selected Pose Data //Gather all the transformation data for all the pose factors for (int i = 0; i < apc._poseData.Count; i++) //for (int i = 0; i < 1; i++) { //Get Pose Frame int poseFrameIndex = apc._poseData[i].PActivePoseFrame; Vector3 v_t, v_s; OpenTK.Quaternion lq; //Fetch Rotation Quaternion lq = NMSUtils.fetchRotQuaternion(node, apc._poseFrameData, poseFrameIndex); v_t = NMSUtils.fetchTransVector(node, apc._poseFrameData, poseFrameIndex); v_s = NMSUtils.fetchScaleVector(node, apc._poseFrameData, poseFrameIndex); quats.Add(lq); translations.Add(v_t); scales.Add(v_s); } float fact = 1.0f / quats.Count; Quaternion fq = new Quaternion(); Vector3 f_vt = new Vector3(); Vector3 f_vs = new Vector3(); fq = quats[0]; f_vt = translations[0]; f_vs = scales[0]; //Interpolate all data for (int i = 1; i < quats.Count; i++) { //Method A: Interpolate //Quaternion.Slerp(fq, quats[i], 0.5f); //Vector3.Lerp(f_vt, translations[i], 0.5f); //Vector3.Lerp(f_vs, scales[i], 0.5f); //Addup f_vs *= scales[i]; } //Generate Transformation Matrix //Matrix4 poseMat = Matrix4.CreateScale(f_vs) * Matrix4.CreateFromQuaternion(fq) * Matrix4.CreateTranslation(f_vt); //Matrix4 poseMat = Matrix4.CreateScale(f_vs) * Matrix4.CreateFromQuaternion(fq); Matrix4 poseMat = Matrix4.CreateScale(f_vs); posematrices[node.Node] = poseMat; } return(posematrices); }