Source Trianglemesh

This function will create a Physics TriMesh object. This function assumes that m_Physics system is your JigLib physics system that has previously been setup in your class.

In order to pass the Model correctly into this function you will first need to compile and add the custom JigLib VertexProcesser.dll into your Content/References folder and then make sure your .X model uses that VertexProcessor in its Content Processor dropdown.

static Body CreatePhysicsTriMesh(Vector3 _Position, Model _Model)

            Body body;
            CollisionSkin collision;
            TriangleMesh triangleMesh;

            body = new Body();
            collision = new CollisionSkin(null);

            triangleMesh = new TriangleMesh();

            Dictionary<string, object> tagData = _Model.Tag as Dictionary<string, object>;

            Vector3[] vertices = tagData["Vertices"] as Vector3[];
            int[] indices = tagData["Indices"] as int[];

            List<Vector3> vertexList = new List<Vector3>();
            List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>();

            for (int i = 0; i < indices.Length / 3; i++)
                indexList.Add(new TriangleVertexIndices(indices[i * 3 + 2], indices[i * 3 + 1], indices[i * 3 + 0]));

            for (int i = 0; i < vertices.Length; i++)

            triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f);
            collision.AddPrimitive(triangleMesh, 1, new MaterialProperties(0.8f, 0.7f, 0.6f));

            body.CollisionSkin = collision;
            body.Position = _Position;


            return body;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License