CubeBatch

Easy3D / Data & Batching / CubeBatch

Easy3D::CubeBatch collects axis-aligned cubes / tiles for later drawing. The intended use is simple cube/tile terrain — e.g. a Blupi level rendered as blocks. Add() stores one CubeItem per call; Items() exposes them for a CPU-side vertex builder (BuildCubeMesh already exists) or a future CNA draw path. This class does no GPU work itself.

#include <Easy3D/CubeBatch.hpp>

namespace Easy3D
{
    struct CubeItem;
    class  CubeBatch;
}
Queueing is pure data storage, but constructing the CNA Vector3 values you pass in calls CNA's compiled constructors — so executables using this class link CNA in practice. See Building & CMake.

CubeItem

One queued axis-aligned cube/tile:

FieldTypeDefaultMeaning
CenterVector3World-space center of the cube.
SizeVector3Full extents along X/Y/Z (so a unit cube is {1,1,1}).
UvUvRect{0, 0, 1, 1}Texture-atlas region (see TextureAtlas::GetUv/GetUvOrDefault) applied to every face. Defaults to the full texture.
CubeItem stores one atlas region per cube, not one per face — all six faces sample the same region. Per-face UVs are not part of the current scope.

Type aliases

AliasRefers to
CubeBatch::Vector3Microsoft::Xna::Framework::Vector3

API

void Begin() noexcept
Discard any queued cubes, starting a fresh batch.
void Add(const Vector3& center, const Vector3& size)
Queue one cube centred at center with the given size and a full-texture UV.
void Add(const Vector3& center, const Vector3& size, const UvRect& uv)
Queue one cube sampling the atlas region uv.
void Add(const CubeItem& item)
Queue a fully specified cube item.
void End() noexcept
Flush queued cubes — currently a no-op (no GPU work yet).
void Clear() noexcept
Discard any queued cubes (equivalent to Begin()).
[[nodiscard]] bool Empty() const noexcept
[[nodiscard]] std::size_t Count() const noexcept
Whether the queue is empty / how many items are queued.
[[nodiscard]] const std::vector<CubeItem>& Items() const noexcept
The queued cubes, in Add() order — consumed by BuildCubeMesh() or your own draw code.

Example — tile terrain from a 2D map

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

using Vector3 = Easy3D::CubeBatch::Vector3;

Easy3D::TextureAtlas tiles(128, 128);
tiles.AddGrid("tile", 32, 32, 4, 4);

Easy3D::CubeBatch terrain;
terrain.Begin();

for (int z = 0; z < mapDepth; ++z)
{
    for (int x = 0; x < mapWidth; ++x)
    {
        const int tile = map[z][x];          // the game's tile semantics stay in the game
        if (tile < 0) continue;             // empty cell
        terrain.Add(Vector3(x + 0.5f, 0.5f, z + 0.5f),   // cube center
                    Vector3(1.0f, 1.0f, 1.0f),
                    tiles.GetUv("tile_" + std::to_string(tile)));
    }
}

terrain.End();
// Turn the queued cubes into CPU-side geometry — see CubeMesh.

From queue to geometry

CubeBatch is the first stage of the data-first pipeline; BuildCubeMesh() is the second — it turns the queued items into plain vertex/index arrays you can upload and draw with CNA. See Architecture for the pipeline picture.