Example #1
0
            /// <summary>Create a new mesh container</summary>
            public override MeshContainer CreateMeshContainer(string name,
                                                              MeshData meshData, ExtendedMaterial[] materials,
                                                              EffectInstance[] effectInstances, GraphicsStream adjacency,
                                                              SkinInformation skinInfo)
            {
                // We only handle meshes here
                if (meshData.Mesh == null)
                {
                    throw new ArgumentException();
                }

                // We must have a vertex format mesh
                if (meshData.Mesh.VertexFormat == VertexFormats.None)
                {
                    throw new ArgumentException();
                }

                AnimationMeshContainer mesh = new AnimationMeshContainer();

                mesh.adjency = adjacency;
                mesh.Name    = name;
                int    numFaces = meshData.Mesh.NumberFaces;
                Device dev      = meshData.Mesh.Device;


                // Store the materials
                mesh.SetMaterials(materials);
                mesh.SetAdjacency(adjacency);

                Texture[] meshTextures = new Texture[materials.Length];
                mesh.MeshData = meshData;

                // If there is skinning info, save any required data
                if (skinInfo != null)
                {
                    mesh.SkinInformation = skinInfo;
                    int      numBones       = skinInfo.NumberBones;
                    Matrix[] offsetMatrices = new Matrix[numBones];

                    for (int i = 0; i < numBones; i++)
                    {
                        offsetMatrices[i] = skinInfo.GetBoneOffsetMatrix(i);
                    }

                    mesh.SetOffsetMatrices(offsetMatrices);

                    GenerateSkinnedMesh(mesh, adjacency);
                }

                return(mesh);
            }