PageRenderTime 103ms CodeModel.GetById 61ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/Rendering/Models/Model.cs

#
C# | 137 lines | 22 code | 4 blank | 111 comment | 1 complexity | c6a41e38616d08b71d235dfae09f6d35 MD5 | raw file
  1namespace Delta.Rendering.Models
  2{
  3	/// <summary>
  4	/// Sorry, this class is not yet implemented and needs to be merged first!
  5	/// </summary>
  6	internal class Model
  7	{
  8
  9
 10		#region IsAnimated (Public)
 11		/// <summary>
 12		/// "True" if the mesh is animated and contains animation data
 13		/// animation.
 14		/// </summary>
 15		public bool IsAnimated
 16		{
 17			get
 18			{
 19				return Animation != null;
 20			}
 21		}
 22		#endregion
 23
 24		#region Animation (Public)
 25		/// <summary>
 26		/// Animation
 27		/// </summary>
 28		/// <returns>Animation</returns>
 29		public Animation Animation
 30		{
 31			get;
 32			private set;
 33		}
 34		#endregion
 35
 36		/*TODO
 37    			if (setAnimationData != null)
 38    			{
 39    				Animation = new Animation(this, setAnimationData);
 40    				// Update once to get an initial pose (else you can't see the mesh)
 41    				UpdateAnimation();
 42    			}
 43		#region UpdateAnimation
 44		/// <summary>
 45		/// Updates the animation.
 46		/// </summary>
 47		public void UpdateAnimation()
 48		{
 49			//Animation.Update();
 50			//Matrix[] finalPoseMatrices = Geometry.FinalBoneMatrices;
 51			//for (int index = 0; index < finalPoseMatrices.Length; index++)
 52			//{
 53			//  BoneData bone = Geometry.Data.Bones[index];
 54			//  finalPoseMatrices[index] = bone.CombinedBoneSkinMatrix *
 55			//    bone.FinalAnimationMatrix;
 56			//} // for
 57
 58			// Update the bone data for skinned meshes
 59
 60			//Geometry.UpdateAnimation(ref Matrix.Identity);
 61			//Geometry.UpdateFinalBoneMatrices(ref Matrix.Identity);
 62			if (Animation != null)
 63			{
 64				//Animation.Update(Geometry.Data.Bones);
 65				Animation.Update();//obs: null);
 66			}
 67		} // UpdateAnimation(drawTransformation)
 68		#endregion
 69
 70		#region DebugShowSkeleton
 71		/// <summary>
 72		/// Debug show skeleton
 73		/// </summary>
 74		/// <param name="drawTransformation">Draw transformation</param>
 75		public void DebugShowSkeleton(ref Matrix drawTransformation)
 76		{
 77			int boneNum = 0;
 78			BoneData[] bones = Geometry.Data.Bones;
 79
 80			// Draw a line from the parent to (all of) his children
 81			Matrix[] boneRenderMatrices = Geometry.FinalBoneMatrices;
 82			foreach (BoneData bone in bones)
 83			{
 84				//foreach (BoneData childBone in bone.Children)
 85				foreach (int childBoneId in bone.ChildrenIds)
 86				{
 87					//Line.Draw(
 88					//  (boneAnimationMatrices[bone.Id] * drawTransformation).Translation,
 89					//  (boneAnimationMatrices[childBoneId] * drawTransformation).Translation,
 90					//  BoneColors[boneNum % BoneColors.Length]);
 91
 92					// The bone matrices are baked with
 93					// "bone.InverseBoneMatrix * bone.AnimationTransformMatrix".
 94					// For visualizing the (animated / transformed) skeleton we only need
 95					// the bone position in the (current) animation frame. The needed
 96					// data is located in the 'Translation' part of the
 97					// 'bone.AnimationTransformMatrix' which we get back if we "remove"
 98					// the 'bone.InverseBoneMatrix' part of the baked matrix again.
 99					// 
100					// Bone.RenderTransform = Bone.InverseTransfrom * Bone.AnimTransform
101					// Bone.AnimTransform = Bone.SpaceTransfrom * Bone.RenderTransform
102
103					//Line.Draw(
104					//  (bone.InverseBoneSkinMatrix.Inverse *
105					//    boneRenderMatrices[bone.Id]).Translation,
106					//  (bones[childBoneId].InverseBoneSkinMatrix.Inverse *
107					//    boneRenderMatrices[childBoneId]).Translation,
108					//  BoneColors[boneNum % BoneColors.Length]);
109
110					// Init with the "ParentBone.SpaceTransform" because we need to init
111					// the "AnimationTransform" matrix, so we just share it instead to
112					// to declare 2 matrices
113					Matrix parentBoneAnimTransform = bone.InverseTransformMatrix.Inverse;
114					Matrix.Multiply(ref parentBoneAnimTransform,
115						ref boneRenderMatrices[bone.Id], ref parentBoneAnimTransform);
116
117					// Init with the "ChildBone.SpaceTransform" because we need to init
118					// the "AnimationTransform" matrix, so we just share it instead to
119					// to declare 2 matrices
120					Matrix childBoneAnimTransform =
121						bones[childBoneId].InverseTransformMatrix.Inverse;
122					Matrix.Multiply(ref childBoneAnimTransform,
123					ref boneRenderMatrices[childBoneId], ref childBoneAnimTransform);
124
125					Line.Draw(parentBoneAnimTransform.Translation,
126						childBoneAnimTransform.Translation,
127						BoneColors[boneNum % BoneColors.Length]);
128
129					boneNum++;
130				} // foreach
131			} // foreach
132		} // DebugShowSkeleton(drawTransformation)
133		#endregion
134
135		 */
136	}
137}