Exemplo n.º 1
0
        public static void Run()
        {
            // Initialize scene object
            Scene scene = new Scene();

            // Initialize Node class object
            Node cubeNode = new Node("box");

            //ExStart:ConvertBoxMeshtoTriangleMeshCustomMemoryLayout
            // get mesh of the Box
            Mesh box = (new Box()).ToMesh();
            //create a customized vertex layout
            VertexDeclaration vd       = new VertexDeclaration();
            VertexField       position = vd.AddField(VertexFieldDataType.FVector4, VertexFieldSemantic.Position);

            vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Normal);
            // get a triangle mesh
            TriMesh triMesh = TriMesh.FromMesh(box);

            //ExEnd:ConvertBoxMeshtoTriangleMeshCustomMemoryLayout

            // Point node to the Mesh geometry
            cubeNode.Entity = box;

            // Add Node to a scene
            scene.RootNode.ChildNodes.Add(cubeNode);

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir() + RunExamples.GetOutputFilePath("BoxToTriangleMeshCustomMemoryLayoutScene.fbx");

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);

            Console.WriteLine("\n Converted a Box mesh to triangle mesh with custom memory layout of the vertex successfully.\nFile saved at " + MyDir);
        }
        public static void Run()
        {
            // Initialize scene object
            Scene scene = new Scene();

            // Initialize Node class object
            Node cubeNode = new Node("sphere");

            Mesh sphere = (new Sphere()).ToMesh();
            //convert any mesh into typed TriMesh
            var myMesh = TriMesh <MyVertex> .FromMesh(sphere);

            //Get the vertex data in customized vertex structure.
            MyVertex[] vertex = myMesh.VerticesToTypedArray();
            //get the 32bit and 16bit indices
            int[]    indices32bit;
            ushort[] indices16bit;
            myMesh.IndicesToArray(out indices32bit);
            myMesh.IndicesToArray(out indices16bit);
            using (MemoryStream ms = new MemoryStream())
            {
                //or we can write the vertex directly into stream like:
                myMesh.WriteVerticesTo(ms);
                //the indice data can be directly write to stream, we support 32-bit and 16-bit indice.
                myMesh.Write16bIndicesTo(ms);
                myMesh.Write32bIndicesTo(ms);
            }
            // Point node to the Mesh geometry
            cubeNode.Entity = sphere;

            // Add Node to a scene
            scene.RootNode.ChildNodes.Add(cubeNode);

            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir() + RunExamples.GetOutputFilePath("SphereToTriangleMeshCustomMemoryLayoutScene.fbx");

            // Save 3D scene in the supported file formats
            scene.Save(MyDir, FileFormat.FBX7400ASCII);

            Console.WriteLine("Indices = {0}, Actual vertices = {1}, vertices before merging = {2}", myMesh.IndicesCount, myMesh.VerticesCount, myMesh.UnmergedVerticesCount);
            Console.WriteLine("Total bytes of vertices in memory {0}bytes", myMesh.VerticesSizeInBytes);
            Console.WriteLine("\n Converted a Sphere mesh to triangle mesh with custom memory layout of the vertex successfully.\nFile saved at " + MyDir);
        }