Skip to content

raisin::RaisimObject ​

class · #include <rayrai/RaisimObject.hpp>

Render state of one raisim::Object, built from physics snapshots.

RaisimObject owns the meshes, colors and world transforms of an object as of the last applied PhysicsObjectSnapshot. It never reads the source raisim::Object, so it stays usable after the object is removed; the snapshot's object pointer is an identity key only.

Nested classes ​

  • struct Changes — What apply() changed, for the renderer's caches.

Constructors & destructor ​

RaisimObject ​

cpp
RaisimObject(
    const PhysicsObjectSnapshot &snapshot,
    RayraiWindow *parent,
    std::shared_ptr<RayraiGlobalAsset> asset)

Build the render state of a snapshot object.

Builds or fetches the geometry of every visual (articulated systems get both visual and collision meshes). Primitive and file meshes come from asset and are shared with other objects; meshes of hidden capsules and mesh files load once the object is shown. Requires a current GL context.

Parameters

ParameterDescription
snapshotObject state, copied; it must have a description.
parentOwning RayraiWindow (for shared textures and settings).
assetAsset cache to load primitive/mesh geometry.

Public member functions ​

Snapshot state

sourceObject ​

cpp
raisim::Object *sourceObject() const

Returns The source object, as an identity key only; it may no longer exist.

instanceId ​

cpp
uint64_t instanceId() const

Returns An id no other RaisimObject in the process had, so a drawable built for another object at the same address is told apart.

objectType ​

cpp
raisim::ObjectType objectType() const

bodyType ​

cpp
raisim::BodyType bodyType() const

objectId ​

cpp
raisim::Object::Id objectId() const

renderRevision ​

cpp
uint64_t renderRevision() const

Returns Revision that advances whenever the drawn state changes.

worldPosition ​

cpp
glm::vec3 worldPosition() const

Returns World position of the object origin (the plane height for a ground).

worldRotation ​

cpp
glm::mat3 worldRotation() const

Returns World rotation of the object frame.


Material queries

Internal: renderer pass-selection queries over all cached meshes.

hasPbrMeshes ​

cpp
bool hasPbrMeshes() const

Returns True when any cached mesh needs the PBR shader.

hasHighFidelityPbrMeshes ​

cpp
bool hasHighFidelityPbrMeshes() const

Returns True when any PBR mesh requires the high-fidelity PBR path (Material::requiresHighFidelityPbr()).

hasTransmissivePbrMeshes ​

cpp
bool hasTransmissivePbrMeshes() const

Returns True when any PBR mesh needs the transmission pass (Material::hasTransmissivePass()).

hasProximityFadePbrMeshes ​

cpp
bool hasProximityFadePbrMeshes() const

Returns True when any PBR mesh uses proximity fade (Material::hasProximityFadePass()).

usesDefaultDepthAndStencilState ​

cpp
bool usesDefaultDepthAndStencilState() const

Returns True when every mesh uses default depth/stencil state (Material::usesDefaultDepthAndStencilState()).

hasFullPbrMeshes ​

cpp
bool hasFullPbrMeshes() const

Returns True when any PBR mesh cannot use the compact PBR shader (Material::canUseCompactPbr()).

hasFoliageFastPbrMeshes ​

cpp
bool hasFoliageFastPbrMeshes() const

Returns True when any mesh can use the foliage fast-PBR path (Material::canUseFoliageFastPbr()).

hasWeatherEligiblePbrMeshes ​

cpp
bool hasWeatherEligiblePbrMeshes() const

Returns True when any mesh reacts to active weather (Material::receivesActiveWeather()).

hasSimpleMeshes ​

cpp
bool hasSimpleMeshes() const

Returns True when any mesh uses non-PBR (simple/textured) shading.

hasPlanarReflectionMeshes ​

cpp
bool hasPlanarReflectionMeshes() const

Returns True when any PBR mesh enables Material::usePlanarReflection.

hasTransparentMaterials ​

cpp
bool hasTransparentMaterials() const

Returns True when any cached mesh material must be rendered in the transparent pass.

hasSpecialBlendMode ​

cpp
bool hasSpecialBlendMode() const

Returns True when any cached mesh uses a blend mode other than Material::BlendMode::Mix.

renderPriority ​

cpp
int renderPriority() const

Returns Highest Material::renderPriority across cached meshes (0 if none).

apply ​

cpp
Changes apply(const PhysicsObjectSnapshot &snapshot)

Advance to a newer snapshot of the same object.

Uploads changed mesh vertices (a vertex delta when the snapshot provides one) and rebuilds meshes whose shapes changed. An unchanged revision costs a comparison. Requires a current GL context.

Parameters

ParameterDescription
snapshotObject state with the same object identity, copied when it changed.

Returns What changed.

draw ​

cpp
void draw(
    Shader &shader,
    bool showCollisionBodies,
    OpenGLMesh::RenderMode mode=OpenGLMesh::RenderMode::All)

Draw the object using the provided shader.

Sets the shadingType, model and objectColor uniforms per mesh; the shader must already be in use. No-op when hidden.

Parameters

ParameterDescription
shaderShader used for rendering.
showCollisionBodiesTrue to render collision geometry when available (articulated systems only).
modeWhich material passes of each mesh to draw.

isSelectable ​

cpp
bool isSelectable() const

Check if this object can be selected in the picker.

Returns True if not hidden, and not a heightmap or ground plane.

configureGroundMaterial ​

cpp
void configureGroundMaterial(
    bool reflective,
    float roughness,
    float metallic,
    bool proceduralChecker=false)

Configure ground and heightmap terrain materials. No-op for other objects.

For a ground plane, resets its material and makes it PBR with planar reflection when reflective, or simple/textured otherwise. For a heightmap, only the window's terrain overrides are reapplied and the other arguments are ignored.

Parameters

ParameterDescription
reflectiveUse a reflective PBR ground.
roughnessPBR roughness, clamped to [0.04, 1] (reflective only).
metallicPBR metallic factor, clamped to [0, 1] (reflective only).
proceduralCheckerDraw a procedural checker instead of the ground texture.

setHidden ​

cpp
void setHidden(bool h)

Hide or show this object in rendering, independent of its appearance.

The object is drawn only while neither this nor a "hidden" appearance hides it.

Parameters

ParameterDescription
hTrue to hide.

hidden ​

cpp
bool hidden() const

Check if object is hidden.

Returns True if hidden by setHidden() or by its appearance.

getColor ​

cpp
glm::vec4 getColor() const

Get object color used for rendering.

Returns RGBA color in [0, 1] parsed from the raisim appearance string (0.7 grey by default). A negative alpha on a mesh object means "use the mesh's own colors".

approximateRadius ​

cpp
float approximateRadius(bool showCollisionBodies) const

Conservative bounding radius for coarse culling.

Parameters

ParameterDescription
showCollisionBodiesMeasure collision instead of visual geometry.

Returns Radius from approximateBounds(), or 1 when bounds are unavailable.

shadowGeometryWithinBounds ​

cpp
bool shadowGeometryWithinBounds() const

Returns True when shadow depth draws keep every vertex inside approximateBounds(): no material uses billboards, fixed-size scaling or height displacement.

shadowDepthMayDiscard ​

cpp
bool shadowDepthMayDiscard(
    bool showCollisionBodies,
    bool transparentShadowDithering) const

Returns True when a shadow depth draw of this object can discard fragments: a mesh that draw() draws has an alpha-mask material, or an alpha-blend material while transparentShadowDithering is set. Deformable surfaces always report true.

approximateBounds ​

cpp
bool approximateBounds(
    bool showCollisionBodies,
    glm::vec3 &center,
    float &radius) const

Conservative world-space bounds for coarse culling.

The center is allowed to differ from the raisim object origin for offset meshes, articulated links, and deformables.

Parameters

ParameterDescription
showCollisionBodiesMeasure collision instead of visual geometry.
center (out)Sphere center in world coordinates.
radius (out)Sphere radius in metres.

Returns False when the object has no geometry.

cullingBounds ​

cpp
void cullingBounds(
    bool showCollisionBodies,
    glm::vec3 &center,
    float &radius) const

Bounds for coarse culling: approximateBounds(), or a unit sphere at the object origin when the object draws no geometry.

Parameters

ParameterDescription
showCollisionBodiesMeasure collision instead of visual geometry.
center (out)Sphere center in world coordinates.
radius (out)Sphere radius in metres.

getPrimitiveBatchData ​

cpp
bool getPrimitiveBatchData(
    bool showCollisionBodies,
    glm::mat4 &model,
    raisim::Shape::Type &shape,
    glm::vec4 &color) const

Return transform/color data for simple single-body primitive batching.

Parameters

ParameterDescription
showCollisionBodiesBatching is refused when true.
model (out)World model matrix including the primitive scale.
shape (out)Primitive shape (sphere, box, cylinder or capsule).
color (out)Object color.

Returns True when this object can be drawn by the internal primitive batch path (visible, opaque, single sphere/box/cylinder/capsule).

getPrimitiveBatchTemplate ​

cpp
bool getPrimitiveBatchTemplate(
    bool showCollisionBodies,
    raisim::Shape::Type &shape,
    glm::vec3 &scale,
    glm::vec4 &color) const

Pose-independent part of getPrimitiveBatchData().

Parameters

ParameterDescription
showCollisionBodiesBatching is refused when true.
shape (out)Primitive shape.
scale (out)Primitive scale.
color (out)Object color.

Returns True when this object is batchable.

setDefaultPrimitivePbrEnabled ​

cpp
void setDefaultPrimitivePbrEnabled(bool enabled)

Toggle High/Ultra default PBR shading for built-in primitive meshes.

Box/sphere/cylinder meshes come from the shared asset cache, so this changes their material for every object that shares them.

Parameters

ParameterDescription
enabledTrue to use the default PBR primitive material.

collectMaterialTextureIds ​

cpp
void collectMaterialTextureIds(std::vector<unsigned int> &textureIds) const

Append non-environment material texture ids used by this object's cached meshes.

Parameters

ParameterDescription
textureIds (in, out)Ids are appended (duplicates are not removed here).

accumulateGeometryDiagnostics ​

cpp
void accumulateGeometryDiagnostics(
    OpenGLMesh::GeometryDiagnostics &diagnostics,
    float tinyTriangleAreaThreshold) const

Accumulate CPU-side mesh geometry diagnostics for this object.

Parameters

ParameterDescription
diagnostics (in, out)Totals to add to.
tinyTriangleAreaThresholdTriangles below this area count as tiny.

collectMeshDiagnostics ​

cpp
void collectMeshDiagnostics(
    std::vector<OpenGLMesh::MeshDiagnostics> &diagnostics,
    float tinyTriangleAreaThreshold) const

Append per-mesh geometry/material diagnostics for this object.

Parameters

ParameterDescription
diagnostics (in, out)One entry is appended per mesh.
tinyTriangleAreaThresholdTriangles below this area count as tiny.

debugModelMatrixCacheRebuilds ​

cpp
size_t debugModelMatrixCacheRebuilds() const

Returns Number of model-matrix rebuilds, for tests and diagnostics.

debugMeshLists ​

cpp
const std::vector<std::shared_ptr<std::vector<std::shared_ptr<OpenGLMesh>>>> &debugMeshLists() const

Internal:

Returns The cached mesh lists (tests/diagnostics).

debugHasMeshGeometry ​

cpp
bool debugHasMeshGeometry() const

Internal:

Returns True when any cached mesh list is non-empty (tests/diagnostics).

RaiSim — physics for robotics and AI.