TriMesh and VertexDeclaration classes are really useful for turning Meshes, with their combinations of vertex element mappings and references modes, into a consistent format. It looks like its intended to be used for serialization/buffer purposes.
I’m curious if this class can be expanded so you can enumerate the Vertexes and get the field values for each vertex.
Example code:
[Test]
private void Test_mesh_vertex_declaration()
{
var mesh = GenerateTestMesh();
VertexDeclaration layout = new VertexDeclaration();
var pos = layout.AddField( VertexFieldDataType.Vector3, VertexFieldSemantic.Position );
var normal = layout.AddField( VertexFieldDataType.Vector3, VertexFieldSemantic.Normal );
var uv = layout.AddField( VertexFieldDataType.Vector2, VertexFieldSemantic.UV );
TriMesh triMesh = TriMesh.FromMesh( layout, mesh );
// Cant do this currently
foreach ( Vertex vertex in triMesh )
{
Vector3 vertexPosition = vertex.GetVector3( pos );
Vector3 vertexNormal = vertex.GetVector3( normal );
Vector2 vertexUv = vertex.GetVector2( uv );
}
}