/// <summary>
        /// Set materialindices on the mesh
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        //<SnippetMaterialIndices>
        private static async Task SetMaterialIndicesAsync(Printing3DMesh mesh)
        {
            // declare a description of the material indices
            Printing3DBufferDescription description;

            description.Format = Printing3DBufferFormat.Printing3DUInt;
            // 4 indices for material description per triangle
            description.Stride = 4;
            // 12 triangles total
            mesh.IndexCount = 12;
            mesh.TriangleMaterialIndicesDescription = description;

            // create space for storing this data
            mesh.CreateTriangleMaterialIndices(sizeof(UInt32) * 4 * 12);

            {
                // each row is a triangle face (in the order they were created)
                // first column is the id of the material group, last 3 columns show which material id (within that group)
                // maps to each triangle vertex (in the order they were listed when creating triangles)
                UInt32[] indices =
                {
                    // base materials:
                    // in  the BaseMaterialGroup (id=1), the BaseMaterial with id=0 will be applied to these triangle vertices
                    1, 0, 0, 0,
                    1, 0, 0, 0,
                    // color materials:
                    // in the ColorMaterialGroup (id=2), the ColorMaterials with these ids will be applied to these triangle vertices
                    2, 1, 1, 1,
                    2, 1, 1, 1,
                    2, 0, 0, 0,
                    2, 0, 0, 0,
                    2, 0, 1, 2,
                    2, 1, 0, 2,
                    // composite materials:
                    // in the CompositeMaterialGroup (id=3), the CompositeMaterial with id=0 will be applied to these triangles
                    3, 0, 0, 0,
                    3, 0, 0, 0,
                    // texture materials:
                    // in the Texture2CoordMaterialGroup (id=4), each texture coordinate is mapped to the appropriate vertex on these
                    // two adjacent triangle faces, so that the square face they create displays the original rectangular image
                    4, 0, 3, 1,
                    4, 2, 3, 0,
                };

                // get the current (unassigned) vertex data as a stream and write our new 'indices' data to it.
                var stream     = mesh.GetTriangleMaterialIndices().AsStream();
                var vertexData = indices.SelectMany(v => BitConverter.GetBytes(v)).ToArray();
                var len        = vertexData.Length;
                await stream.WriteAsync(vertexData, 0, vertexData.Length);
            }
        }
예제 #2
0
파일: Print3D.cs 프로젝트: ice0/test
    private static async Task GetMaterialIndicesAsync(Printing3DMesh mesh)
    {
        Printing3DBufferDescription description;

        description.Format = Printing3DBufferFormat.Printing3DUInt;
        description.Stride = 4;
        mesh.IndexCount    = verticesMaterialCount;
        mesh.TriangleMaterialIndicesDescription = description;

        mesh.CreateTriangleMaterialIndices(sizeof(UInt32) * 4 * mesh.IndexCount);

        var stream = mesh.GetTriangleMaterialIndices().AsStream();
        {
            var data = indicesMaterialPrint.SelectMany(v => BitConverter.GetBytes(v)).ToArray();
            await stream.WriteAsync(data, 0, data.Length);
        }
    }
예제 #3
0
        // Create the buffer for material  indices.
        private static async Task SetMaterialIndicesAsync(Printing3DMesh mesh)
        {
            Printing3DBufferDescription description;

            description.Format = Printing3DBufferFormat.Printing3DUInt;
            description.Stride = 4;  // 4 indices per material
            mesh.IndexCount    = 12; // 12 triangles with material
            mesh.TriangleMaterialIndicesDescription = description;

            // Create the buffer into which we will write the material indices.
            mesh.CreateTriangleMaterialIndices(sizeof(UInt32) * description.Stride * mesh.IndexCount);

            // Fill the buffer with material indices.
            using (var stream = mesh.GetTriangleMaterialIndices().AsStream())
            {
                UInt32[] indices =
                {
                    // base materials:
                    // in  the BaseMaterialGroup, the BaseMaterial with id=0 will be applied to these triangle vertices
                    2, 0, 0, 0,
                    2, 0, 0, 0,
                    // color materials:
                    // in the ColorMaterialGroup, the ColorMaterials with these ids will be applied to these triangle vertices
                    1, 1, 1, 1,
                    1, 1, 1, 1,
                    1, 0, 0, 0,
                    1, 0, 0, 0,
                    1, 0, 1, 0,
                    1, 0, 1, 1,
                    // composite materials:
                    // in the CompositeMaterialGroup, the CompositeMaterial with id=0 will be applied to these triangles
                    3, 0, 0, 0,
                    3, 0, 0, 0,
                    // texture materials:
                    // in the Texture2CoordMaterialGroup, each texture coordinate is mapped to the appropriate vertex on these
                    // two adjacent triangle faces, so that the square face they create displays the original rectangular image
                    4, 0, 3, 1,
                    4, 2, 3, 0,
                };

                var vertexData = indices.SelectMany(v => BitConverter.GetBytes(v)).ToArray();
                await stream.WriteAsync(vertexData, 0, vertexData.Length);
            }
        }
예제 #4
0
    private static async Task GetMaterialIndicesAsync(Printing3DMesh mesh)
    {
        Printing3DBufferDescription description;

        description.Format = Printing3DBufferFormat.Printing3DUInt;
        description.Stride = 4;
        mesh.IndexCount = verticesMaterialCount;
        mesh.TriangleMaterialIndicesDescription = description;

        mesh.CreateTriangleMaterialIndices(sizeof(UInt32) * 4 * mesh.IndexCount);

        var stream = mesh.GetTriangleMaterialIndices().AsStream();
        {
            var data = indicesMaterialPrint.SelectMany(v => BitConverter.GetBytes(v)).ToArray();
            await stream.WriteAsync(data, 0, data.Length);
        }
    }
        // Create the buffer for material  indices.
        private static async Task SetMaterialIndicesAsync(Printing3DMesh mesh)
        {
            Printing3DBufferDescription description;
            description.Format = Printing3DBufferFormat.Printing3DUInt;
            description.Stride = 4; // 4 indices per material
            mesh.IndexCount = 12; // 12 triangles with material
            mesh.TriangleMaterialIndicesDescription = description;

            // Create the buffer into which we will write the material indices.
            mesh.CreateTriangleMaterialIndices(sizeof(UInt32) * description.Stride * mesh.IndexCount);

            // Fill the buffer with material indices.
            using (var stream = mesh.GetTriangleMaterialIndices().AsStream())
            {
                UInt32[] indices =
                {
                    // base materials:
                    // in  the BaseMaterialGroup, the BaseMaterial with id=0 will be applied to these triangle vertices
                    2, 0, 0, 0,
                    2, 0, 0, 0,
                    // color materials:
                    // in the ColorMaterialGroup, the ColorMaterials with these ids will be applied to these triangle vertices
                    1, 1, 1, 1,
                    1, 1, 1, 1,
                    1, 0, 0, 0,
                    1, 0, 0, 0,
                    1, 0, 1, 0,
                    1, 0, 1, 1,
                    // composite materials:
                    // in the CompositeMaterialGroup, the CompositeMaterial with id=0 will be applied to these triangles
                    3,0,0,0,
                    3,0,0,0,
                    // texture materials:
                    // in the Texture2CoordMaterialGroup, each texture coordinate is mapped to the appropriate vertex on these
                    // two adjacent triangle faces, so that the square face they create displays the original rectangular image
                    4, 0, 3, 1,
                    4, 2, 3, 0,
                };

                var vertexData = indices.SelectMany(v => BitConverter.GetBytes(v)).ToArray();
                await stream.WriteAsync(vertexData, 0, vertexData.Length);
            }
        }