AnimationsProcessor.cs 24 KB

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