AnimationsProcessor.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. #region License
  2. // Copyright 2011-2016 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using Microsoft.Xna.Framework;
  20. using Microsoft.Xna.Framework.Content.Pipeline;
  21. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  22. using Microsoft.Xna.Framework.Graphics;
  23. using nkast.Aether.Content.Pipeline.Animation;
  24. namespace nkast.Aether.Content.Pipeline.Processors
  25. {
  26. [ContentProcessor(DisplayName = "Animation - Aether")]
  27. class AnimationsProcessor : ContentProcessor<NodeContent, AnimationsContent>
  28. {
  29. private int _maxBones = SkinnedEffect.MaxBones;
  30. private int _generateKeyframesFrequency = 0;
  31. private bool _fixRealBoneRoot = false;
  32. [DisplayName("MaxBones")]
  33. [DefaultValue(SkinnedEffect.MaxBones)]
  34. public virtual int MaxBones
  35. {
  36. get { return _maxBones; }
  37. set { _maxBones = value; }
  38. }
  39. [DisplayName("Generate Keyframes Frequency")]
  40. [DefaultValue(0)] // (0=no, 30=30fps, 60=60fps)
  41. public virtual int GenerateKeyframesFrequency
  42. {
  43. get { return _generateKeyframesFrequency; }
  44. set { _generateKeyframesFrequency = value; }
  45. }
  46. [DisplayName("Fix BoneRoot from MG importer")]
  47. [DefaultValue(false)]
  48. public virtual bool FixRealBoneRoot
  49. {
  50. get { return _fixRealBoneRoot; }
  51. set { _fixRealBoneRoot = value; }
  52. }
  53. public override AnimationsContent Process(NodeContent input, ContentProcessorContext context)
  54. {
  55. if(_fixRealBoneRoot)
  56. MGFixRealBoneRoot(input, context);
  57. ValidateMesh(input, context, null);
  58. // Find the skeleton.
  59. BoneContent skeleton = MeshHelper.FindSkeleton(input);
  60. if (skeleton == null)
  61. throw new InvalidContentException("Input skeleton not found.");
  62. // We don't want to have to worry about different parts of the model being
  63. // in different local coordinate systems, so let's just bake everything.
  64. FlattenTransforms(input, skeleton);
  65. // Read the bind pose and skeleton hierarchy data.
  66. IList<BoneContent> bones = MeshHelper.FlattenSkeleton(skeleton);
  67. if (bones.Count > MaxBones)
  68. {
  69. throw new InvalidContentException(string.Format("Skeleton has {0} bones, but the maximum supported is {1}.", bones.Count, MaxBones));
  70. }
  71. List<Matrix> bindPose = new List<Matrix>();
  72. List<Matrix> invBindPose = new List<Matrix>();
  73. List<int> skeletonHierarchy = new List<int>();
  74. List<string> boneNames = new List<string>();
  75. foreach(BoneContent bone in bones)
  76. {
  77. bindPose.Add(bone.Transform);
  78. invBindPose.Add(Matrix.Invert(bone.AbsoluteTransform));
  79. skeletonHierarchy.Add(bones.IndexOf(bone.Parent as BoneContent));
  80. boneNames.Add(bone.Name);
  81. }
  82. // Convert animation data to our runtime format.
  83. Dictionary<string, ClipContent> clips;
  84. clips = ProcessAnimations(input, context, skeleton.Animations, bones, GenerateKeyframesFrequency);
  85. return new AnimationsContent(bindPose, invBindPose, skeletonHierarchy, boneNames, clips);
  86. }
  87. /// <summary>
  88. /// MonoGame converts some NodeContent into BoneContent.
  89. /// Here we revert that to get the original Skeleton and
  90. /// add the real boneRoot to the root node.
  91. /// </summary>
  92. private void MGFixRealBoneRoot(NodeContent input, ContentProcessorContext context)
  93. {
  94. for (int i = input.Children.Count - 1; i >= 0; i--)
  95. {
  96. NodeContent node = input.Children[i];
  97. if (node is BoneContent
  98. && node.AbsoluteTransform == Matrix.Identity
  99. && node.Children.Count == 1
  100. && node.Children[0] is BoneContent
  101. && node.Children[0].AbsoluteTransform == Matrix.Identity
  102. )
  103. {
  104. //dettach real boneRoot
  105. NodeContent realBoneRoot = node.Children[0];
  106. node.Children.RemoveAt(0);
  107. //copy animation from node to boneRoot
  108. foreach (var animation in node.Animations)
  109. realBoneRoot.Animations.Add(animation.Key, animation.Value);
  110. // convert fake BoneContent back to NodeContent
  111. NodeContent realNode = new NodeContent();
  112. realNode.Name = node.Name;
  113. realNode.Identity = node.Identity;
  114. realNode.Transform = node.Transform;
  115. input.Children[i] = realNode;
  116. foreach (var animation in node.Animations)
  117. input.Children[i].Animations.Add(animation.Key, animation.Value);
  118. foreach (var opaqueData in node.OpaqueData)
  119. input.Children[i].OpaqueData.Add(opaqueData.Key, opaqueData.Value);
  120. //attach real boneRoot to the root node
  121. input.Children.Add(realBoneRoot);
  122. break;
  123. }
  124. }
  125. }
  126. /// <summary>
  127. /// Makes sure this mesh contains the kind of data we know how to animate.
  128. /// </summary>
  129. void ValidateMesh(NodeContent node, ContentProcessorContext context, string parentBoneName)
  130. {
  131. MeshContent mesh = node as MeshContent;
  132. if (mesh != null)
  133. {
  134. // Validate the mesh.
  135. if (parentBoneName != null)
  136. {
  137. context.Logger.LogWarning(null, null,
  138. "Mesh {0} is a child of bone {1}. AnimatedModelProcessor " +
  139. "does not correctly handle meshes that are children of bones.",
  140. mesh.Name, parentBoneName);
  141. }
  142. if (!MeshHasSkinning(mesh))
  143. {
  144. context.Logger.LogWarning(null, null,
  145. "Mesh {0} has no skinning information, so it has been deleted.",
  146. mesh.Name);
  147. mesh.Parent.Children.Remove(mesh);
  148. return;
  149. }
  150. }
  151. else if (node is BoneContent)
  152. {
  153. // If this is a bone, remember that we are now looking inside it.
  154. parentBoneName = node.Name;
  155. }
  156. // Recurse (iterating over a copy of the child collection,
  157. // because validating children may delete some of them).
  158. foreach (NodeContent child in new List<NodeContent>(node.Children))
  159. ValidateMesh(child, context, parentBoneName);
  160. }
  161. /// <summary>
  162. /// Checks whether a mesh contains skininng information.
  163. /// </summary>
  164. bool MeshHasSkinning(MeshContent mesh)
  165. {
  166. foreach (GeometryContent geometry in mesh.Geometry)
  167. {
  168. if (!geometry.Vertices.Channels.Contains(VertexChannelNames.Weights()) &&
  169. !geometry.Vertices.Channels.Contains("BlendWeight0"))
  170. return false;
  171. }
  172. return true;
  173. }
  174. /// <summary>
  175. /// Bakes unwanted transforms into the model geometry,
  176. /// so everything ends up in the same coordinate system.
  177. /// </summary>
  178. void FlattenTransforms(NodeContent node, BoneContent skeleton)
  179. {
  180. foreach (NodeContent child in node.Children)
  181. {
  182. // Don't process the skeleton, because that is special.
  183. if (child == skeleton)
  184. continue;
  185. // Bake the local transform into the actual geometry.
  186. MeshHelper.TransformScene(child, child.Transform);
  187. // Having baked it, we can now set the local
  188. // coordinate system back to identity.
  189. child.Transform = Matrix.Identity;
  190. // Recurse.
  191. FlattenTransforms(child, skeleton);
  192. }
  193. }
  194. /// <summary>
  195. /// Converts an intermediate format content pipeline AnimationContentDictionary
  196. /// object to our runtime AnimationClip format.
  197. /// </summary>
  198. Dictionary<string, ClipContent> ProcessAnimations(NodeContent input, ContentProcessorContext context, AnimationContentDictionary animations, IList<BoneContent> bones, int generateKeyframesFrequency)
  199. {
  200. // Build up a table mapping bone names to indices.
  201. Dictionary<string, int> boneMap = new Dictionary<string, int>();
  202. for (int i = 0; i < bones.Count; i++)
  203. {
  204. string boneName = bones[i].Name;
  205. if (!string.IsNullOrEmpty(boneName))
  206. boneMap.Add(boneName, i);
  207. }
  208. // Convert each animation in turn.
  209. Dictionary<string, ClipContent> animationClips;
  210. animationClips = new Dictionary<string, ClipContent>();
  211. foreach (KeyValuePair<string, AnimationContent> animation in animations)
  212. {
  213. ClipContent clip = ProcessAnimation(input, context, animation.Value, boneMap, generateKeyframesFrequency);
  214. animationClips.Add(animation.Key, clip);
  215. }
  216. if (animationClips.Count == 0)
  217. {
  218. //throw new InvalidContentException("Input file does not contain any animations.");
  219. context.Logger.LogWarning(null, null, "Input file does not contain any animations.");
  220. }
  221. return animationClips;
  222. }
  223. /// <summary>
  224. /// Converts an intermediate format content pipeline AnimationContent
  225. /// object to our runtime AnimationClip format.
  226. /// </summary>
  227. ClipContent ProcessAnimation(NodeContent input, ContentProcessorContext context, AnimationContent animation, Dictionary<string, int> boneMap, int generateKeyframesFrequency)
  228. {
  229. List<KeyframeContent> keyframes = new List<KeyframeContent>();
  230. // For each input animation channel.
  231. foreach (KeyValuePair<string, AnimationChannel> channel in
  232. animation.Channels)
  233. {
  234. // Look up what bone this channel is controlling.
  235. int boneIndex;
  236. if (!boneMap.TryGetValue(channel.Key, out boneIndex))
  237. {
  238. //throw new InvalidContentException(string.Format("Found animation for bone '{0}', which is not part of the skeleton.", channel.Key));
  239. context.Logger.LogWarning(null, null, "Found animation for bone '{0}', which is not part of the skeleton.", channel.Key);
  240. continue;
  241. }
  242. foreach (AnimationKeyframe keyframe in channel.Value)
  243. keyframes.Add(new KeyframeContent(boneIndex, keyframe.Time, keyframe.Transform));
  244. }
  245. // Sort the merged keyframes by time.
  246. keyframes.Sort(CompareKeyframeTimes);
  247. //System.Diagnostics.Debugger.Launch();
  248. if (generateKeyframesFrequency > 0)
  249. keyframes = InterpolateKeyframes(animation.Duration, keyframes, generateKeyframesFrequency);
  250. keyframes = EnsureFirstKeyframeExists(animation.Duration, keyframes);
  251. if (keyframes.Count == 0)
  252. throw new InvalidContentException("Animation has no keyframes.");
  253. if (animation.Duration <= TimeSpan.Zero)
  254. throw new InvalidContentException("Animation has a zero duration.");
  255. return new ClipContent(animation.Duration, keyframes.ToArray());
  256. }
  257. static int CompareKeyframeTimes(KeyframeContent a, KeyframeContent b)
  258. {
  259. int cmpTime = a.Time.CompareTo(b.Time);
  260. if (cmpTime == 0)
  261. return a.Bone.CompareTo(b.Bone);
  262. return cmpTime;
  263. }
  264. private List<KeyframeContent> InterpolateKeyframes(TimeSpan duration, List<KeyframeContent> keyframes, int generateKeyframesFrequency)
  265. {
  266. if (generateKeyframesFrequency <= 0)
  267. return keyframes;
  268. int keyframeCount = keyframes.Count;
  269. //
  270. System.Diagnostics.Debug.WriteLine("Duration: " + duration);
  271. System.Diagnostics.Debug.WriteLine("keyframeCount: " + keyframeCount);
  272. // find bones
  273. HashSet<int> bonesSet = new HashSet<int>();
  274. int maxBone = 0;
  275. double maxTime = 0;
  276. for (int i = 0; i < keyframeCount; i++)
  277. {
  278. int bone = keyframes[i].Bone;
  279. maxBone = Math.Max(maxBone, bone);
  280. maxTime = Math.Max(maxTime, keyframes[i].Time.TotalSeconds);
  281. bonesSet.Add(bone);
  282. }
  283. int boneCount = bonesSet.Count;
  284. // check if keyframes are allready fully interpolated
  285. int frames = keyframeCount / boneCount;
  286. TimeSpan checkDuration = TimeSpan.FromSeconds((frames - 1) / generateKeyframesFrequency);
  287. if (duration == checkDuration)
  288. return keyframes;
  289. // split bones
  290. List<KeyframeContent>[] boneFrames = new List<KeyframeContent>[maxBone + 1];
  291. for (int i = 0; i < keyframeCount; i++)
  292. {
  293. int bone = keyframes[i].Bone;
  294. if (boneFrames[bone] == null) boneFrames[bone] = new List<KeyframeContent>();
  295. boneFrames[bone].Add(keyframes[i]);
  296. }
  297. // Interpolate Frames for each bone
  298. for (int b = 0; b < boneFrames.Length; b++)
  299. {
  300. boneFrames[b] = InterpolateFramesBone(b, boneFrames[b], duration, generateKeyframesFrequency);
  301. }
  302. // copy keyframes from boneFrames back to a flat list and order them by time
  303. List<KeyframeContent> newKeyframes = new List<KeyframeContent>();
  304. for (int b = 0; b < boneFrames.Length; b++)
  305. {
  306. if (boneFrames[b] != null)
  307. {
  308. for (int k = 0; k < boneFrames[b].Count; ++k)
  309. {
  310. newKeyframes.Add(boneFrames[b][k]);
  311. }
  312. }
  313. }
  314. newKeyframes.Sort(CompareKeyframeTimes);
  315. return newKeyframes;
  316. }
  317. // the player currently requires all bones to have a keyframe at time zero
  318. private List<KeyframeContent> EnsureFirstKeyframeExists(TimeSpan duration, List<KeyframeContent> keyframes)
  319. {
  320. int keyframeCount = keyframes.Count;
  321. // find bones
  322. HashSet<int> bonesSet = new HashSet<int>();
  323. int maxBone = 0;
  324. for (int i = 0; i < keyframeCount; i++)
  325. {
  326. int bone = keyframes[i].Bone;
  327. maxBone = Math.Max(maxBone, bone);
  328. bonesSet.Add(bone);
  329. }
  330. int boneCount = bonesSet.Count;
  331. // split bones
  332. List<KeyframeContent>[] boneFrames = new List<KeyframeContent>[maxBone + 1];
  333. for (int i = 0; i < keyframeCount; i++)
  334. {
  335. int bone = keyframes[i].Bone;
  336. if (boneFrames[bone] == null) boneFrames[bone] = new List<KeyframeContent>();
  337. boneFrames[bone].Add(keyframes[i]);
  338. }
  339. //
  340. System.Diagnostics.Debug.WriteLine("Duration: " + duration);
  341. System.Diagnostics.Debug.WriteLine("keyframeCount: " + keyframeCount);
  342. for (int b = 0; b < boneFrames.Length; b++)
  343. {
  344. if (boneFrames[b] == null)
  345. continue;
  346. if (boneFrames[b][0].Time != TimeSpan.Zero)
  347. {
  348. KeyframeContent keyframe0 = new KeyframeContent(boneFrames[b][0].Bone, TimeSpan.Zero, boneFrames[b][0].Transform);
  349. boneFrames[b].Insert(0, keyframe0);
  350. }
  351. }
  352. List<KeyframeContent> newKeyframes = new List<KeyframeContent>();
  353. for (int b = 0; b < boneFrames.Length; b++)
  354. {
  355. if (boneFrames[b] != null)
  356. {
  357. for (int k = 0; k < boneFrames[b].Count; ++k)
  358. {
  359. newKeyframes.Add(boneFrames[b][k]);
  360. }
  361. }
  362. }
  363. newKeyframes.Sort(CompareKeyframeTimes);
  364. return newKeyframes;
  365. }
  366. private static List<KeyframeContent> InterpolateFramesBone(int bone, List<KeyframeContent> frames, TimeSpan duration, int generateKeyframesFrequency)
  367. {
  368. System.Diagnostics.Debug.WriteLine("");
  369. System.Diagnostics.Debug.WriteLine("Bone: " + bone);
  370. if (frames == null)
  371. {
  372. System.Diagnostics.Debug.WriteLine("Frames: " + "null");
  373. return frames;
  374. }
  375. System.Diagnostics.Debug.WriteLine("Frames: " + frames.Count);
  376. System.Diagnostics.Debug.WriteLine("MinTime: " + frames[0].Time);
  377. System.Diagnostics.Debug.WriteLine("MaxTime: " + frames[frames.Count - 1].Time);
  378. List<KeyframeContent> newFrames = new List<KeyframeContent>();
  379. if (frames.Count == 1)
  380. {
  381. TimeSpan time = TimeSpan.Zero;
  382. int frame = 0;
  383. for (; time < duration; frame++)
  384. {
  385. long timeTicks = (frame * TimeSpan.TicksPerSecond) / generateKeyframesFrequency;
  386. time = TimeSpan.FromTicks(timeTicks);
  387. newFrames.Add(new KeyframeContent(bone, time, frames[0].Transform));
  388. }
  389. }
  390. else
  391. {
  392. generateKeyframesFrequency = 60;
  393. int lastKeyFrame = (frames.Count - 1);
  394. int keyFrameA = lastKeyFrame;
  395. int keyFrameB = 0;
  396. TimeSpan timeA = frames[keyFrameA].Time - duration; // timeA is initially lower than TimeSpan.Zero
  397. TimeSpan timeB = frames[keyFrameB].Time;
  398. TimeSpan diffAB = timeB - timeA;
  399. Matrix mA = frames[keyFrameA].Transform;
  400. Matrix mB = frames[keyFrameB].Transform;
  401. Matrix mBlend = Matrix.Identity;
  402. TimeSpan time = TimeSpan.Zero;
  403. int frame = 0;
  404. for (; time < duration; frame++)
  405. {
  406. long timeTicks = (frame * TimeSpan.TicksPerSecond) / generateKeyframesFrequency;
  407. time = TimeSpan.FromTicks(timeTicks);
  408. while (time > timeB)
  409. {
  410. keyFrameA = keyFrameB;
  411. timeA = timeB;
  412. mA = mB;
  413. keyFrameB = (keyFrameB + 1) % frames.Count;
  414. timeB = frames[keyFrameB].Time;
  415. if (timeB < timeA)
  416. timeB += duration; // timeB is now greater than duration
  417. mB = frames[keyFrameB].Transform;
  418. diffAB = timeB - timeA;
  419. }
  420. // if the first keyFrame is at time zero, we skip interpolation with the prev/last keyframe.
  421. if (keyFrameB == 0 && timeB == TimeSpan.Zero)
  422. {
  423. mBlend = mB;
  424. }
  425. else
  426. {
  427. TimeSpan diffB = timeB - time;
  428. float amount = 1f - (float)((double)diffB.Ticks / (double)diffAB.Ticks);
  429. MatrixLerpDecomposition(ref mA, ref mB, amount, ref mBlend);
  430. }
  431. newFrames.Add(new KeyframeContent(bone, time, mBlend));
  432. System.Diagnostics.Debug.WriteLine("{Time:" + time);
  433. }
  434. }
  435. //newFrames.AddRange(frames);
  436. newFrames.Sort(CompareKeyframeTimes);
  437. //TimeSpan keySpan = TimeSpan.FromTicks((long)((1f / generateKeyframesFrequency) * TimeSpan.TicksPerSecond));
  438. //for (int i = 0; i < frames.Count - 1; ++i)
  439. //{
  440. // InterpolateFrames(bone, frames, keySpan, i);
  441. //}
  442. return newFrames;
  443. }
  444. private static void InterpolateFrames(int bone, List<KeyframeContent> frames, TimeSpan keySpan, int i)
  445. {
  446. int a = i;
  447. int b = i + 1;
  448. TimeSpan diff = frames[b].Time - frames[a].Time;
  449. Matrix mBlend = Matrix.Identity;
  450. if (diff > keySpan)
  451. {
  452. TimeSpan newTime = frames[a].Time + keySpan;
  453. float amount = (float)(keySpan.TotalSeconds / diff.TotalSeconds);
  454. Matrix m1 = frames[a].Transform;
  455. Matrix m2 = frames[b].Transform;
  456. MatrixLerpDecomposition(ref m1, ref m2, amount, ref mBlend);
  457. frames.Insert(b, new KeyframeContent(bone, newTime, mBlend));
  458. }
  459. return;
  460. }
  461. private static void MatrixLerpPrecise(ref Matrix m1, ref Matrix m2, float amount, ref Matrix result)
  462. {
  463. float w1 = 1f - amount;
  464. float w2 = amount;
  465. result.M11 = (m1.M11 * w1) + (m2.M11 * w2);
  466. result.M12 = (m1.M12 * w1) + (m2.M12 * w2);
  467. result.M13 = (m1.M13 * w1) + (m2.M13 * w2);
  468. result.M21 = (m1.M21 * w1) + (m2.M21 * w2);
  469. result.M22 = (m1.M22 * w1) + (m2.M22 * w2);
  470. result.M23 = (m1.M23 * w1) + (m2.M23 * w2);
  471. result.M31 = (m1.M31 * w1) + (m2.M31 * w2);
  472. result.M32 = (m1.M32 * w1) + (m2.M32 * w2);
  473. result.M33 = (m1.M33 * w1) + (m2.M33 * w2);
  474. result.M41 = (m1.M41 * w1) + (m2.M41 * w2);
  475. result.M42 = (m1.M42 * w1) + (m2.M42 * w2);
  476. result.M43 = (m1.M43 * w1) + (m2.M43 * w2);
  477. }
  478. private static void MatrixLerpDecomposition(ref Matrix m1, ref Matrix m2, float amount, ref Matrix mBlend)
  479. {
  480. Vector3 pScale; Quaternion pRotation; Vector3 pTranslation;
  481. m1.Decompose(out pScale, out pRotation, out pTranslation);
  482. Vector3 iScale; Quaternion iRotation; Vector3 iTranslation;
  483. m2.Decompose(out iScale, out iRotation, out iTranslation);
  484. Vector3 Scale; Quaternion Rotation; Vector3 Translation;
  485. //lerp
  486. Vector3.Lerp(ref pScale, ref iScale, amount, out Scale);
  487. Quaternion.Slerp(ref pRotation, ref iRotation, amount, out Rotation);
  488. Vector3.Lerp(ref pTranslation, ref iTranslation, amount, out Translation);
  489. Matrix rotation;
  490. Matrix.CreateFromQuaternion(ref Rotation, out rotation);
  491. mBlend.M11 = Scale.X * rotation.M11;
  492. mBlend.M12 = Scale.X * rotation.M12;
  493. mBlend.M13 = Scale.X * rotation.M13;
  494. mBlend.M21 = Scale.Y * rotation.M21;
  495. mBlend.M22 = Scale.Y * rotation.M22;
  496. mBlend.M23 = Scale.Y * rotation.M23;
  497. mBlend.M31 = Scale.Z * rotation.M31;
  498. mBlend.M32 = Scale.Z * rotation.M32;
  499. mBlend.M33 = Scale.Z * rotation.M33;
  500. mBlend.M41 = Translation.X;
  501. mBlend.M42 = Translation.Y;
  502. mBlend.M43 = Translation.Z;
  503. }
  504. }
  505. }