Exemple #1
0
        private ConvexMesh loadConvexMesh(MeshCollisionData.Convex convexData, StillDesign.PhysX.Scene scene)
        {
            // Allocate memory for the points and triangles
            var convexMeshDesc = new ConvexMeshDescription()
            {
                PointCount = convexData.Positions.Count
            };

            convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
            convexMeshDesc.AllocatePoints <Vector3>(convexData.Positions.Count);

            // Write in the points and triangles
            // We only want the Position component of the vertex. Also scale down the mesh
            for (int i = 0; i < convexData.Positions.Count; i++)
            {
                convexMeshDesc.PointsStream.Write(convexData.Positions[i]);
            }

            // Cook to memory or to a file
            MemoryStream stream = new MemoryStream();

            //FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

            Cooking.InitializeCooking(new ConsoleOutputStream());
            Cooking.CookConvexMesh(convexMeshDesc, stream);
            Cooking.CloseCooking();

            stream.Position = 0;

            return(scene.Core.CreateConvexMesh(stream));
        }
Exemple #2
0
        public ConvexMesh CreateConvexMesh(StillDesign.PhysX.Scene scene, MeshCollisionData.Convex convex)
        {
            ConvexMesh ret;

            if (convexMeshEntries.TryGetValue(convex, out ret))
            {
                return(ret);
            }

            ret = loadConvexMesh(convex, scene);
            convexMeshEntries[convex] = ret;

            return(ret);
        }