CubeMesh requires CNA link

Easy3D / Data & Batching / CubeMesh

The CubeMesh functions turn queued CubeBatch items into plain CPU-side vertex/index arrays (Roadmap Phase 3). No GPU work: no GraphicsDevice, no vertex/index buffers, no shaders — just std::vector data a caller can later upload.

#include <Easy3D/CubeMesh.hpp>

namespace Easy3D
{
    struct CubeVertex;

    void AppendCubeMesh(const CubeItem& item,
                        std::vector<CubeVertex>& vertices,
                        std::vector<std::uint32_t>& indices);

    void BuildCubeMesh(const CubeBatch& batch,
                       std::vector<CubeVertex>& vertices,
                       std::vector<std::uint32_t>& indices);
}

CubeVertex

One mesh vertex:

FieldTypeMeaning
PositionMicrosoft::Xna::Framework::Vector3World position.
UvMicrosoft::Xna::Framework::Vector2Normalized texture coordinate.

AppendCubeMesh

void AppendCubeMesh(const CubeItem& item,
                    std::vector<CubeVertex>& vertices,
                    std::vector<std::uint32_t>& indices)
Appends one cube's triangle mesh — 24 vertices, 36 indices (6 faces × 4 vertices, so each face can carry its own UV corners) — to existing output arrays. Indices are offset by the vertex count already present in vertices, so results from repeated calls concatenate correctly into one combined mesh.

Properties of the generated geometry:

BuildCubeMesh

void BuildCubeMesh(const CubeBatch& batch,
                   std::vector<CubeVertex>& vertices,
                   std::vector<std::uint32_t>& indices)
Builds a combined triangle mesh for every item in batch, in CubeBatch::Items() order. Equivalent to calling AppendCubeMesh for each item in turn against the same vertices / indices.

Both functions append — they never clear the output vectors. Clear them yourself when rebuilding from scratch, or exploit the appending to accumulate several batches into one mesh.

Example — level terrain to one mesh

#include <Easy3D/CubeBatch.hpp>
#include <Easy3D/CubeMesh.hpp>

Easy3D::CubeBatch terrain;
terrain.Begin();
// ... Add() one cube per solid tile (see the CubeBatch page) ...
terrain.End();

std::vector<Easy3D::CubeVertex> vertices;
std::vector<std::uint32_t>      indices;
Easy3D::BuildCubeMesh(terrain, vertices, indices);

// vertices.size() == terrain.Count() * 24
// indices.size()  == terrain.Count() * 36

// The game now owns plain geometry data. Upload it with CNA (vertex/index
// buffers + BasicEffect) and draw — Easy3D Phase 4 will add adapters for this.

Scope and status

CubeMesh is the first Phase 3 vertex builder. Builders for billboards and debug lines/boxes are planned next; issuing actual CNA draw calls is Phase 4. See the Roadmap.

There is no visibility optimization (no hidden-face removal between adjacent cubes, no meshing/greedy merge). For the small levels Easy3D targets this is fine; anything smarter would be scope creep until a real consumer needs it.