public TriangleMeshObject(Game game, Model model, Matrix orientation, Vector3 position) : base(game, model) { body = new Body(); collision = new CollisionSkin(null); triangleMesh = new TriangleMesh(); List<Vector3> vertexList = new List<Vector3>(); List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>(); ExtractData(vertexList, indexList, model); triangleMesh.CreateMesh(vertexList,indexList, 4, 1.0f); collision.AddPrimitive(triangleMesh,new MaterialProperties(0.8f,0.7f,0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision); }
// Sets the model being simulated, extracts vertices, etc. public void SetModel(string ModelName) { Model Model = Engine.Content.Load<Model>(ModelName); this.modelName = ModelName; CollisionSkin.RemoveAllPrimitives(); triangleMesh = new TriangleMesh(); List<Vector3> vertexList = new List<Vector3>(); List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>(); ExtractData(vertexList, indexList, Model); triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f); CollisionSkin.AddPrimitive(triangleMesh, new MaterialProperties(0.8f, 0.7f, 0.6f)); Mass = Mass; }
public TriangleMeshObject(Game game, Model model, Matrix orientation, Vector3 position) : base(game, model) { body = new Body(); collision = new CollisionSkin(null); triangleMesh = new TriangleMesh(); List<Vector3> vertexList = new List<Vector3>(); List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>(); ExtractData(vertexList, indexList, model); triangleMesh.CreateMesh(vertexList,indexList, 4, 1.0f); collision.AddPrimitive(triangleMesh,new MaterialProperties(0.8f,0.7f,0.6f)); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision); // Transform collision.ApplyLocalTransform(new JigLibX.Math.Transform(position, orientation)); // we also need to move this dummy, so the object is *rendered* at the correct positiob body.MoveTo(position, orientation); }
private TriangleMesh GetTriangleMesh(Model model, Transform3D transform) { TriangleMesh triangleMesh = new TriangleMesh(); List<Vector3> vertexList = new List<Vector3>(); List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>(); ExtractData(vertexList, indexList, model); for (int i = 0; i < vertexList.Count; i++) { vertexList[i] = Vector3.Transform(vertexList[i], transform.World); } // create the collision mesh triangleMesh.CreateMesh(vertexList, indexList, 1, 1.0f); return triangleMesh; }
void GenerateCollisionMesh() { List<Vector3> vertColl = new List<Vector3>(); for (int i = 0; i < geometry.verts.Length; i++) { vertColl.Add(Vector3.Transform(new Vector3(geometry.verts[i].Position.X, geometry.verts[i].Position.Y, geometry.verts[i].Position.Z), transformation.GetTransform())); //vertColl[i] = Vector3.Transform(new Vector3(geometry.verts[i].Position.X, geometry.verts[i].Position.Y, geometry.verts[i].Position.Z), transformation.GetTransform()); } int triCount = 0; TriangleVertexIndices triIdx = new TriangleVertexIndices(0, 0, 0); List<TriangleVertexIndices> triColl = new List<TriangleVertexIndices>(); for (int i = 0; i < geometry.ib.Length; i++) { //int index = geometry.ib[i]; //vertColl.Add(Vector3.Transform(new Vector3(geometry.verts[index].Position.X, geometry.verts[index].Position.Y, geometry.verts[index].Position.Z), transformation.GetTransform())); switch (triCount) { case 0: triIdx.I2 = geometry.ib[i]; break; case 1: triIdx.I1 = geometry.ib[i]; break; case 2: triIdx.I0 = geometry.ib[i]; triCount = -1; triColl.Add(triIdx); triIdx = new TriangleVertexIndices(0, 0, 0); break; } triCount++; } CollisionMesh = new TriangleMesh(); CollisionMesh.CreateMesh(vertColl.ToArray(), triColl.ToArray(), 1500, 0.01f); Collision = new CollisionSkin(null); Collision.AddPrimitive(CollisionMesh, (int)MaterialTable.MaterialID.NotBouncyRough); PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(Collision); }