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:
| Field | Type | Meaning |
|---|---|---|
Position | Microsoft::Xna::Framework::Vector3 | World position. |
Uv | Microsoft::Xna::Framework::Vector2 | Normalized texture coordinate. |
AppendCubeMesh
void AppendCubeMesh(const CubeItem& item,
std::vector<CubeVertex>& vertices,
std::vector<std::uint32_t>& indices)
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:
- Per-cube counts: 24 vertices and 36 indices (12 triangles). Vertices are not shared between faces so each face keeps its own UV corners.
- Face order: +Z, −Z, +X, −X, +Y, −Y.
- Winding: faces are wound counter-clockwise as seen from outside the cube, matching CNA/XNA's right-handed coordinate system (outward face normal =
(v1−v0) × (v2−v0)). Standard back-face culling works out of the box. - UVs: every face uses the item's single
Uvregion on all four of its corners, laid out as(U0,V0)-(U1,V0)-(U1,V1)-(U0,V1)—CubeItemstores one atlas region per cube, not one per face. - Index type:
std::uint32_t, so large combined meshes (> 65k vertices) are fine.
BuildCubeMesh
void BuildCubeMesh(const CubeBatch& batch,
std::vector<CubeVertex>& vertices,
std::vector<std::uint32_t>& indices)
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.