static void TranslateVertices( VertexPositionColor[] vertices, byte[] vertexByteArray, int vertexStride, Vector3 colorAsVector, int vertexNumber) { var vertexPositionX = BitConverter.ToSingle(vertexByteArray, vertexNumber * vertexStride + 0); var vertexPositionY = BitConverter.ToSingle(vertexByteArray, vertexNumber * vertexStride + 4); var vertexPositionZ = BitConverter.ToSingle(vertexByteArray, vertexNumber * vertexStride + 8); var vertexPositionColor = new VertexPositionColor(new Vector3(vertexPositionX, vertexPositionY, vertexPositionZ), color); vertices[vertexNumber] = vertexPositionColor; }
void CalculateVertices(SpatialSurfaceMesh mesh, out VertexPositionColor[] vertices, out ushort[] indices, out Matrix4x4 finalMatrix) { var transformMatrix = Matrix4x4.Identity; var tryTransform = mesh.CoordinateSystem.TryGetTransformTo(CoordinateSystem); if (tryTransform != null) { transformMatrix = tryTransform.Value; } var vertexByteArray = mesh.VertexPositions.Data.ToArray(); var vertexStride = (int)mesh.VertexPositions.Stride; var vertexCount = mesh.VertexPositions.ElementCount; var triangleIndexByteArray = mesh.TriangleIndices.Data.ToArray(); var triangleCount = mesh.TriangleIndices.ElementCount; var vertexScale = mesh.VertexPositionScale; var scaleMatrix = Matrix4x4.CreateScale(vertexScale); finalMatrix = Matrix4x4.Transpose(scaleMatrix * transformMatrix); vertices = new VertexPositionColor[vertexCount]; for (var i = 0; i < vertexCount; i++) { TranslateVertices(vertices, vertexByteArray, vertexStride, color, i); } indices = new ushort[triangleCount]; var indexOffset = 0; for (var i = 0; i < triangleCount; i++) { var index = BitConverter.ToUInt16(triangleIndexByteArray, indexOffset); indexOffset += 2; indices[i] = index; } }