// Create the buffer for triangle indices. private static async Task SetTriangleIndicesAsync(Printing3DMesh mesh) { Printing3DBufferDescription description; description.Format = Printing3DBufferFormat.Printing3DUInt; description.Stride = 3; // 3 vertex position indices per triangle mesh.IndexCount = 12; // 12 triangles in the cube mesh.TriangleIndicesDescription = description; // Create the buffer into which we will write the triangle vertex indices. mesh.CreateTriangleIndices(sizeof(UInt32) * description.Stride * mesh.IndexCount); // Fill the buffer with triangle vertex indices. using (var stream = mesh.GetTriangleIndices().AsStream()) { UInt32[] indices = { 1, 0, 2, 1, 2, 3, 0, 1, 5, 0, 5, 4, 1, 3, 7, 1, 7, 5, 2, 7, 3, 2, 6, 7, 0, 6, 2, 0, 4, 6, 6, 5, 7, 4, 5, 6, }; var vertexData = indices.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); await stream.WriteAsync(vertexData, 0, vertexData.Length); } }
private static async Task GetIndicesAsync(Printing3DMesh mesh) { Printing3DBufferDescription description; description.Format = Printing3DBufferFormat.Printing3DUInt; description.Stride = 3; mesh.IndexCount = indicesCount; mesh.TriangleIndicesDescription = description; mesh.CreateTriangleIndices(sizeof(UInt32) * 3 * mesh.IndexCount); var stream = mesh.GetTriangleIndices().AsStream(); { var data = indicesPrint.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); await stream.WriteAsync(data, 0, data.Length); } }
//</SnippetMaterialIndices> /// <summary> /// Set the triangle indices on the mesh /// </summary> /// <param name="mesh">Printing3DMesh</param> /// <returns></returns> //<SnippetTriangleIndices> private static async Task SetTriangleIndicesAsync(Printing3DMesh mesh) { Printing3DBufferDescription description; description.Format = Printing3DBufferFormat.Printing3DUInt; // 3 vertex indices description.Stride = 3; // 12 triangles in all in the cube mesh.IndexCount = 12; mesh.TriangleIndicesDescription = description; // allocate space for 12 triangles mesh.CreateTriangleIndices(sizeof(UInt32) * 3 * 12); // get a datastream of the triangle indices (should be blank at this point) var stream2 = mesh.GetTriangleIndices().AsStream(); { // define a set of triangle indices: each row is one triangle. The values in each row // correspond to the index of the vertex. UInt32[] indices = { 1, 0, 2, 1, 2, 3, 0, 1, 5, 0, 5, 4, 1, 3, 7, 1, 7, 5, 2, 7, 3, 2, 6, 7, 0, 6, 2, 0, 4, 6, 6, 5, 7, 4, 5, 6, }; // convert index data to byte array var vertexData = indices.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); var len = vertexData.Length; // write index data to the triangle indices stream await stream2.WriteAsync(vertexData, 0, vertexData.Length); } }