// Create the buffer for vertex positions. private static async Task SetVerticesAsync(Printing3DMesh mesh) { Printing3DBufferDescription description; description.Format = Printing3DBufferFormat.Printing3DDouble; description.Stride = 3; // Three values per vertex (x, y, z). mesh.VertexPositionsDescription = description; mesh.VertexCount = 8; // 8 total vertices in the cube // Create the buffer into which we will write the vertex positions. mesh.CreateVertexPositions(sizeof(double) * description.Stride * mesh.VertexCount); // Fill the buffer with vertex coordinates. using (var stream = mesh.GetVertexPositions().AsStream()) { double[] vertices = { 0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0, 0, 0, 10, 10, 0, 10, 0, 10, 10, 10, 10, 10, }; byte[] vertexData = vertices.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); await stream.WriteAsync(vertexData, 0, vertexData.Length); } }
private async Task GetVerticesAsync(Printing3DMesh mesh) { Printing3DBufferDescription description; description.Format = Printing3DBufferFormat.Printing3DDouble; description.Stride = 3; mesh.VertexCount = verticesCount; mesh.CreateVertexPositions(sizeof(double) * 3 * mesh.VertexCount); mesh.VertexPositionsDescription = description; using (var stream = mesh.GetVertexPositions().AsStream()) { var data = verticesPrint.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); await stream.WriteAsync(data, 0, data.Length); } }
//</SnippetTriangleIndices> //<SnippetVertices> private async Task GetVerticesAsync(Printing3DMesh mesh) { Printing3DBufferDescription description; description.Format = Printing3DBufferFormat.Printing3DDouble; // have 3 xyz values description.Stride = 3; // have 8 vertices in all in this mesh mesh.CreateVertexPositions(sizeof(double) * 3 * 8); mesh.VertexPositionsDescription = description; // set the locations (in 3D coordinate space) of each vertex using (var stream = mesh.GetVertexPositions().AsStream()) { double[] vertices = { 0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0, 0, 0, 10, 10, 0, 10, 0, 10, 10, 10, 10, 10, }; // convert vertex data to a byte array byte[] vertexData = vertices.SelectMany(v => BitConverter.GetBytes(v)).ToArray(); // write the locations to each vertex await stream.WriteAsync(vertexData, 0, vertexData.Length); } // update vertex count: 8 vertices in the cube mesh.VertexCount = 8; }