public ConvexShapeDesc CreateConvexHull(StaticMeshData meshData) { // create descriptor for convex hull ConvexShapeDesc convexMeshShapeDesc = null; ConvexMeshDesc convexMeshDesc = new ConvexMeshDesc(); convexMeshDesc.PinPoints <float>(meshData.Points, 0, sizeof(float) * 3); convexMeshDesc.PinTriangles <uint>(meshData.Indices, 0, sizeof(uint) * 3); convexMeshDesc.VertexCount = (uint)meshData.Vertices.Length; convexMeshDesc.TriangleCount = (uint)meshData.TriangleCount; convexMeshDesc.Flags = ConvexFlags.ComputeConvex; MemoryStream stream = new MemoryStream(1024); CookingInterface.InitCooking(); if (CookingInterface.CookConvexMesh(convexMeshDesc, stream)) { stream.Seek(0, SeekOrigin.Begin); ConvexMesh convexMesh = physics.CreateConvexMesh(stream); convexMeshShapeDesc = new ConvexShapeDesc(convexMesh); CookingInterface.CloseCooking(); } convexMeshDesc.UnpinAll(); return(convexMeshShapeDesc); }
public TriangleMeshShapeDesc CreateTriangleMesh(StaticMeshData meshData) { // create descriptor for triangle mesh TriangleMeshShapeDesc triangleMeshShapeDesc = null; TriangleMeshDesc triangleMeshDesc = new TriangleMeshDesc(); triangleMeshDesc.PinPoints <float>(meshData.Points, 0, sizeof(float) * 3); triangleMeshDesc.PinTriangles <uint>(meshData.Indices, 0, sizeof(uint) * 3); triangleMeshDesc.VertexCount = (uint)meshData.Vertices.Length; triangleMeshDesc.TriangleCount = (uint)meshData.TriangleCount; MemoryStream stream = new MemoryStream(1024); CookingInterface.InitCooking(); if (CookingInterface.CookTriangleMesh(triangleMeshDesc, stream)) { stream.Seek(0, SeekOrigin.Begin); TriangleMesh triangleMesh = physics.CreateTriangleMesh(stream); triangleMeshShapeDesc = new TriangleMeshShapeDesc(triangleMesh); CookingInterface.CloseCooking(); } triangleMeshDesc.UnpinAll(); return(triangleMeshShapeDesc); }
public ActorDesc CreateActorDesc(EntityWorldEntity entityNode, Entity entity, Vector3 position, Quaternion orientation, Vector3 scale) { ActorDesc actorDesc = new ActorDesc(); actorDesc.GlobalPosition = position; actorDesc.GlobalOrientation = orientation.ToRotationMatrix(); if (entityNode.CollisionMode == CollisionMode.ConvexHull || entityNode.CollisionMode == CollisionMode.TriangleMesh) { StaticMeshData meshData = new StaticMeshData(entity.GetMesh(), scale); if (entityNode.CollisionMode == CollisionMode.TriangleMesh) { actorDesc.Shapes.Add(Engine.Physics.CreateTriangleMesh(meshData)); } else { actorDesc.Shapes.Add(Engine.Physics.CreateConvexHull(meshData)); } } else { switch (entityNode.CollisionMode) { case CollisionMode.BoundingBox: actorDesc.Shapes.Add(new BoxShapeDesc(entity.BoundingBox.HalfSize * scale, entity.BoundingBox.Center * scale)); break; case CollisionMode.BoundingSphere: actorDesc.Shapes.Add(new SphereShapeDesc(Engine.MaxAxis(entity.BoundingBox.HalfSize), entity.BoundingBox.Center * scale)); break; case CollisionMode.Shapes: foreach (ShapeDesc shapeDesc in entityNode.Shapes) { actorDesc.Shapes.Add(shapeDesc); } break; default: throw new Exception(entityNode.CollisionMode.ToString() + " not implemented"); } } return(actorDesc); }
public ActorDesc CreateActorDesc(EntityWorldEntity entityNode, Entity entity, Vector3 position, Quaternion orientation, Vector3 scale) { ActorDesc actorDesc = new ActorDesc(); actorDesc.GlobalPosition = position; actorDesc.GlobalOrientation = orientation.ToRotationMatrix(); if (entityNode.CollisionMode == CollisionMode.ConvexHull || entityNode.CollisionMode == CollisionMode.TriangleMesh) { StaticMeshData meshData = new StaticMeshData(entity.GetMesh(), scale); if (entityNode.CollisionMode == CollisionMode.TriangleMesh) actorDesc.Shapes.Add(Engine.Physics.CreateTriangleMesh(meshData)); else actorDesc.Shapes.Add(Engine.Physics.CreateConvexHull(meshData)); } else { switch (entityNode.CollisionMode) { case CollisionMode.BoundingBox: actorDesc.Shapes.Add(new BoxShapeDesc(entity.BoundingBox.HalfSize * scale, entity.BoundingBox.Center * scale)); break; case CollisionMode.BoundingSphere: actorDesc.Shapes.Add(new SphereShapeDesc(Engine.MaxAxis(entity.BoundingBox.HalfSize), entity.BoundingBox.Center * scale)); break; case CollisionMode.Shapes: foreach (ShapeDesc shapeDesc in entityNode.Shapes) actorDesc.Shapes.Add(shapeDesc); break; default: throw new Exception(entityNode.CollisionMode.ToString() + " not implemented"); } } return actorDesc; }
public ConvexShapeDesc CreateConvexHull(StaticMeshData meshData) { // create descriptor for convex hull ConvexShapeDesc convexMeshShapeDesc = null; ConvexMeshDesc convexMeshDesc = new ConvexMeshDesc(); convexMeshDesc.PinPoints<float>(meshData.Points, 0, sizeof(float) * 3); convexMeshDesc.PinTriangles<uint>(meshData.Indices, 0, sizeof(uint) * 3); convexMeshDesc.VertexCount = (uint)meshData.Vertices.Length; convexMeshDesc.TriangleCount = (uint)meshData.TriangleCount; convexMeshDesc.Flags = ConvexFlags.ComputeConvex; MemoryStream stream = new MemoryStream(1024); CookingInterface.InitCooking(); if (CookingInterface.CookConvexMesh(convexMeshDesc, stream)) { stream.Seek(0, SeekOrigin.Begin); ConvexMesh convexMesh = physics.CreateConvexMesh(stream); convexMeshShapeDesc = new ConvexShapeDesc(convexMesh); CookingInterface.CloseCooking(); } convexMeshDesc.UnpinAll(); return convexMeshShapeDesc; }
public TriangleMeshShapeDesc CreateTriangleMesh(StaticMeshData meshData) { // create descriptor for triangle mesh TriangleMeshShapeDesc triangleMeshShapeDesc = null; TriangleMeshDesc triangleMeshDesc = new TriangleMeshDesc(); triangleMeshDesc.PinPoints<float>(meshData.Points, 0, sizeof(float) * 3); triangleMeshDesc.PinTriangles<uint>(meshData.Indices, 0, sizeof(uint) * 3); triangleMeshDesc.VertexCount = (uint)meshData.Vertices.Length; triangleMeshDesc.TriangleCount = (uint)meshData.TriangleCount; MemoryStream stream = new MemoryStream(1024); CookingInterface.InitCooking(); if (CookingInterface.CookTriangleMesh(triangleMeshDesc, stream)) { stream.Seek(0, SeekOrigin.Begin); TriangleMesh triangleMesh = physics.CreateTriangleMesh(stream); triangleMeshShapeDesc = new TriangleMeshShapeDesc(triangleMesh); CookingInterface.CloseCooking(); } triangleMeshDesc.UnpinAll(); return triangleMeshShapeDesc; }