PageRenderTime 49ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/Rendering/Models/Model.cs

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