예제 #1
0
        public TriangleMesh Cook(TriangleMesh mesh)
        {
            using (BinaryWriter writer = new BinaryWriter(File.Open("Mesh.bin", FileMode.Create)))
            {
                WriteRawFormatToFile(writer, mesh);
            }

            PhysXHelper.CookTriangleCollision("Mesh.bin", "Cook.bin");

            TriangleMesh cookedTriangleMesh = new TriangleMesh();

            using (BinaryReader reader = new BinaryReader(File.Open("Cook.bin", FileMode.Open)))
            {
                cookedTriangleMesh.Load(reader);
            }

            if (File.Exists("Mesh.bin"))
            {
                File.Delete("Mesh.bin");
            }

            if (File.Exists("Cook.bin"))
            {
                File.Delete("Cook.bin");
            }

            cookedTriangleMesh.Force32BitIndices();
            return(cookedTriangleMesh);
        }
예제 #2
0
        public void WriteToFile()
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new Exception("Name is null or empty");
            }

            //force cook collisions
            if (Utils.Settings.ToolkitSettings.CookCollisions)
            {
                using (BinaryWriter writer = new BinaryWriter(File.Open("MeshBundle.bin", FileMode.Create)))
                {
                    writer.Write(Models.Count);

                    TriangleCooking cooker = new TriangleCooking();

                    foreach (var collisionModel in Models)
                    {
                        cooker.WriteRawFormatToFile(writer, collisionModel.Value.Mesh);
                    }
                }

                PhysXHelper.MultiCookTriangleCollision("MeshBundle.bin", "CookedBundle.bin");

                using (BinaryReader reader = new BinaryReader(File.Open("CookedBundle.bin", FileMode.Open)))
                {
                    uint NumModels = reader.ReadUInt32();
                    for (int i = 0; i < NumModels; i++)
                    {
                        TriangleMesh CookedMesh = new TriangleMesh();
                        CookedMesh.Load(reader);
                        CookedMesh.Force32BitIndices();
                        Models.ElementAt(i).Value.Mesh = CookedMesh;
                    }
                }

                if (File.Exists("MeshBundle.bin"))
                {
                    File.Delete("MeshBundle.bin");
                }

                if (File.Exists("CookedBundle.bin"))
                {
                    File.Delete("CookedBundle.bin");
                }
            }


            using (BinaryWriter writer = new BinaryWriter(File.Open(Name, FileMode.Create)))
            {
                WriteToFile(writer);
            }
        }