Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MeshSkinningUpdater.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using SiliconStudio.Core.Mathematics;
5 using SiliconStudio.Paradox.Effects.Modules;
6 
7 namespace SiliconStudio.Paradox.Effects
8 {
9  /// <summary>
10  /// Performs blend matrix skinning.
11  /// </summary>
12  public static class MeshSkinningUpdater
13  {
14  [ThreadStatic]
15  private static Matrix[] staticBoneMatrices;
16 
17  public static void Update(ModelViewHierarchyUpdater hierarchy, RenderModel renderModel)
18  {
19  var boneMatrices = staticBoneMatrices;
20 
21  foreach (var meshes in renderModel.RenderMeshes)
22  {
23  if (meshes == null)
24  continue;
25 
26  foreach (var renderMesh in meshes)
27  {
28  var mesh = renderMesh.Mesh;
29  var skinning = mesh.Skinning;
30  if (skinning == null)
31  continue;
32 
33  var bones = skinning.Bones;
34 
35  // Make sure there is enough spaces in boneMatrices
36  if (boneMatrices == null || bones.Length > boneMatrices.Length)
37  staticBoneMatrices = boneMatrices = new Matrix[bones.Length];
38 
39  for (int index = 0; index < bones.Length; index++)
40  {
41  var nodeIndex = bones[index].NodeIndex;
42 
43  // Compute bone matrix
44  Matrix.Multiply(ref bones[index].LinkToMeshMatrix, ref hierarchy.NodeTransformations[nodeIndex].WorldMatrix, out boneMatrices[index]);
45  }
46 
47  // Upload bones
48  renderMesh.Mesh.Parameters.Set(TransformationSkinningKeys.BlendMatrixArray, boneMatrices, 0, bones.Length);
49  }
50  }
51  }
52  }
53 }
static void Update(ModelViewHierarchyUpdater hierarchy, RenderModel renderModel)
Instantiation of a Model through a RenderPipeline.
Definition: RenderModel.cs:11
Performs hierarchical updates for a given Model.
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47