Пример #1
0
		private void AddChildBones(string parentName, OOGL.Animation.Bone parentBone, OOGL.Animation.Bone[] bones)
		{
			for(int j = 0; j < this.joints.Length; j++)
			{
				if(this.joints[j].parentName == parentName)
				{						
					Matrix4 localRotationMatrix
						= Matrix4.RotateX(this.joints[j].rotation.X)
						* Matrix4.RotateY(this.joints[j].rotation.Y)
						* Matrix4.RotateZ(this.joints[j].rotation.Z);
																														
					Matrix4 localTranslationMatrix = Matrix4.CreateTranslation(this.joints[j].position);
					// TODO delete
					//Matrix4 localTranslationMatrix = Matrix4.Translation(this.joints[j].position);
					
					Dictionary<float,OOGL.Animation.KeyFrame> keyFrameDict =new Dictionary<float,OOGL.Animation.KeyFrame>();
					
					for(int r = 0; r < this.joints[j].keyFrameRotations.Length; r++)
					{
						float time = this.joints[j].keyFrameRotations[r].time;
						Vector3 rotVec = this.joints[j].keyFrameRotations[r].rotation;
									
						Quaternion rotation
							= Quaternion.FromAxisAngle(Vector3.UnitZ, rotVec.Z)
							* Quaternion.FromAxisAngle(Vector3.UnitY, rotVec.Y)
							* Quaternion.FromAxisAngle(Vector3.UnitX, rotVec.X);
																		
						keyFrameDict[time] = new OOGL.Animation.KeyFrame(time, rotation, Vector3.Zero);
					}
					
					for(int t = 0; t < this.joints[j].keyFramePositions.Length; t++)
					{	
						float time = this.joints[j].keyFramePositions[t].time;
						Vector3 translation	= this.joints[j].keyFramePositions[t].position;
						
						if(keyFrameDict.ContainsKey(time))
						{							
							keyFrameDict[time] = new OOGL.Animation.KeyFrame(time, keyFrameDict[time].rotation, translation);
						}
						else
						{
							keyFrameDict[time] = new OOGL.Animation.KeyFrame(time, Quaternion.Identity, translation);
						}						
					}
						
					List<OOGL.Animation.KeyFrame> keyFrames = new List<OOGL.Animation.KeyFrame>(keyFrameDict.Values);
					keyFrames.Sort();
					
					bones[j] = new OOGL.Animation.Bone(this.joints[j].name, parentBone, localRotationMatrix, localTranslationMatrix , keyFrames.ToArray());
					
					AddChildBones(bones[j].name, bones[j], bones);					
				}
			}
		}
Пример #2
0
		public OOGL.Animation.Model ToModel(ShaderProgram shader, OOGL.Animation.Sample[] tracks)
		{
			OOGL.Animation.Group[] groups = new OOGL.Animation.Group[this.groups.Length];
			for(int i = 0; i < this.groups.Length; i++)
			{
				ushort[] indices;
				OOGL.Animation.VertexStruct[] vertices = GetVertices(i, out indices);
			
				groups[i] = new OOGL.Animation.Group
				(
					this.groups[i].name,
					this.materials[this.groups[i].materialIndex].GetOOGLMaterial(this.fileName),
					vertices,
					indices
				);
			}

			OOGL.Animation.Bone[] bones = new OOGL.Animation.Bone[this.joints.Length];
			AddChildBones("", null, bones);

            OOGL.Animation.Model model = new OOGL.Animation.Model(shader, groups, bones, tracks);
			
			return model;
		}