Ejemplo n.º 1
0
        private static void GetVerticesAndIndicesFromModel(Microsoft.Xna.Framework.Graphics.Model collisionModel, string collisionMesh, out Vector3[] vertices, out int[] indices)
        {
            if (string.IsNullOrEmpty(collisionMesh) || !collisionModel.Meshes.Any(mesh => mesh.Name == collisionMesh))
            {
                TriangleMesh.GetVerticesAndIndicesFromModel(collisionModel, out vertices, out indices);
                return;
            }

            var verticesList = new List <Vector3>();
            var indicesList  = new List <int>();
            var transforms   = new Matrix[collisionModel.Bones.Count];

            collisionModel.CopyAbsoluteBoneTransformsTo(transforms);

            Matrix transform;

            foreach (Microsoft.Xna.Framework.Graphics.ModelMesh mesh in collisionModel.Meshes)
            {
                if (mesh.Name == collisionMesh)
                {
                    if (mesh.ParentBone != null)
                    {
                        transform = transforms[mesh.ParentBone.Index];
                    }
                    else
                    {
                        transform = Matrix.Identity;
                    }
                    TriangleMesh.AddMesh(mesh, transform, verticesList, indicesList);
                }
            }

            vertices = verticesList.ToArray();
            indices  = indicesList.ToArray();
        }