Skip to content

raisin::StreamedFoliage ​

class · #include <rayrai/StreamedFoliage.hpp>

Owns per-cell/species batches while the viewer retains shared mesh/texture assets. Providers may read baked files or generate deterministic placements. Call on the viewer's GL thread; it creates no simulation worker threads. The viewer/context must outlive this owner. The owner exclusively manages its prefixed visual names; call clear() before editing/removing them outside.

Nested classes ​

  • struct Species — One plant type. Each resident cell gets one InstancedVisuals batch per species.

Public types ​

Placements ​

cpp
using Placements = std::vector<std::vector<InstancedVisuals::InstanceSpec>>

Per-species instance lists for one cell; outer size must equal the species count.

Provider ​

cpp
using Provider = std::function<Placements(WorldCellKey, WorldCellBounds)>

Produces the placements of a cell from its key and world bounds.

Constructors & destructor ​

StreamedFoliage ​

cpp
StreamedFoliage(
    RayraiWindow &viewer,
    std::string prefix,
    WorldCells cells,
    std::vector<Species> species,
    Provider provider)

Parameters

ParameterDescription
viewerViewer that owns the batches; must outlive this object.
prefixName prefix; batches are named prefix/x/y/speciesIndex.
cellsResidency planner; must have no resident cells.
speciesPlant types (non-empty; each needs a mesh or a prototype).
providerPlacement source.

Exceptions

ExceptionDescription
std::invalid_argumentif any requirement above is violated.
cpp
StreamedFoliage(const StreamedFoliage &) = delete

~StreamedFoliage ​

cpp
~StreamedFoliage()

Public member functions ​

operator= ​

cpp
StreamedFoliage &operator=(const StreamedFoliage &) = delete

update ​

cpp
WorldCellPlan update(std::span<const WorldInterest> interests)

Unload released cells and load up to the planner's load budget.

A cell whose load fails is rolled back and the exception is rethrown.

Parameters

ParameterDescription
interestsPoints that want foliage nearby.

Returns The plan that was executed.

Exceptions

ExceptionDescription
std::length_errorif the resident budget cannot cover interests.
std::runtime_erroron a provider species-count mismatch, a name collision or a failed batch creation.

clear ​

cpp
void clear()

Remove every batch from the viewer and unload all cells.

residentCellCount ​

cpp
size_t residentCellCount() const

Returns Number of loaded cells.

residentCells ​

cpp
const std::vector<WorldCellKey> &residentCells() const

Returns Sorted keys of successfully loaded cells, including empty placements.

residentInstanceCount ​

cpp
size_t residentInstanceCount() const

Returns Total instances across all resident batches.

batches ​

cpp
std::vector<std::shared_ptr<InstancedVisuals>> batches() const

Returns All resident batches (a cell has none for a species with empty placements).

RaiSim — physics for robotics and AI.