/// <summary> /// Gets an array of vertices and indices from the provided model. /// </summary> /// <param name="collisionModel">Model to use for the collision shape.</param> /// <param name="vertices">Compiled set of vertices from the model.</param> /// <param name="indices">Compiled set of indices from the model.</param> public static void GetVerticesAndIndicesFromModel(Model collisionModel, out Vector3[] vertices, out int[] indices) { var verticesList = new List <Vector3>(); var indicesList = new List <int>(); var transforms = new Matrix[collisionModel.Bones.Count]; collisionModel.CopyAbsoluteBoneTransformsTo(transforms); Matrix transform; foreach (ModelMesh mesh in collisionModel.Meshes) { if (mesh.ParentBone != null) { transform = transforms[mesh.ParentBone.Index]; } else { transform = Matrix.Identity; } AddMesh(mesh, transform, verticesList, indicesList); } vertices = verticesList.ToArray(); indices = indicesList.ToArray(); }
public override void LoadContent() { if (!string.IsNullOrEmpty(_asset)) { Model = GameUtilities.Content.Load <Model>("Models\\" + _asset); BoneTransforms = new Matrix[Model.Bones.Count]; Model.CopyAbsoluteBoneTransformsTo(BoneTransforms); if (Model != null) { Vector3[] vertices; int[] indices; ModelDataExtractor.GetVerticesAndIndicesFromModel(Model, out vertices, out indices); AABB = BoundingBox.CreateFromPoints(vertices); TransformBoundingBox(World); } } base.LoadContent(); }