import gfx.genmesh.algorithm; import std.algorithm : map, each, equal; import std.stdio; struct Vertex { float[3] pos; float[3] normal; float[2] texCoord; } auto cube = genCube() // faces of internal vertex type .vertexMap!((v) { return typeof(v)([2*v.p[0], 2*v.p[1], 2*v.p[2]], v.n); }) // same face type with a transform (scaled by 2) .map!(f => quad( Vertex(f[0].p, f[0].n, [0f, 0f]), Vertex(f[1].p, f[1].n, [0f, 1f]), Vertex(f[2].p, f[2].n, [1f, 1f]), Vertex(f[3].p, f[3].n, [1f, 0f]), )) // faces with application vertex type (tex coord added) .triangulate() // triangular faces (with app vertex type) .vertices() // application vertices .indexCollectMesh(); // mesh type with array members "indices" and "vertices" // only the last step actually pull and transform the data all along the chain foreach (f; 0 .. 6) { immutable f6 = f*6; immutable f4 = f*4; assert(cube.indices[f6 .. f6+6].equal([f4, f4+1, f4+2, f4, f4+2, f4+3])); }
cube face generator pass Yes.normals as parameter to get vertices normals