CubeGenerator

cube face generator pass Yes.normals as parameter to get vertices normals

Members

Aliases

GV
alias GV = GenVertex!normals
Undocumented in source.

Functions

face
Quad!GV face(size_t fi)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
Quad!GV opIndex(size_t fIdx)
Undocumented in source. Be warned that the author may not have intended to support it.
popBack
void popBack()
Undocumented in source. Be warned that the author may not have intended to support it.
popFront
void popFront()
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

back
Quad!GV back [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
empty
bool empty [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
front
Quad!GV front [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
length
size_t length [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
save
auto save [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

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]));
}

Meta