Пример #1
0
        public TriangleMesh Build(IList <Vector3> vertexList, IList <Triangle> triangleList, IList <ushort> materialsList)
        {
            Init(vertexList, triangleList, materialsList);
            TriangleCooking cooked = new TriangleCooking();

            return(cooked.Cook(this));
        }
Пример #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);
            }
        }