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
structChanges — What apply() changed, for the renderer's caches.
Constructors & destructor
RaisimObject
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
| Parameter | Description |
|---|---|
snapshot | Object state, copied; it must have a description. |
parent | Owning RayraiWindow (for shared textures and settings). |
asset | Asset cache to load primitive/mesh geometry. |
Public member functions
Snapshot state
sourceObject
raisim::Object *sourceObject() constReturns The source object, as an identity key only; it may no longer exist.
instanceId
uint64_t instanceId() constReturns An id no other RaisimObject in the process had, so a drawable built for another object at the same address is told apart.
objectType
raisim::ObjectType objectType() constbodyType
raisim::BodyType bodyType() constobjectId
raisim::Object::Id objectId() constrenderRevision
uint64_t renderRevision() constReturns Revision that advances whenever the drawn state changes.
worldPosition
glm::vec3 worldPosition() constReturns World position of the object origin (the plane height for a ground).
worldRotation
glm::mat3 worldRotation() constReturns World rotation of the object frame.
Material queries
Internal: renderer pass-selection queries over all cached meshes.
hasPbrMeshes
bool hasPbrMeshes() constReturns True when any cached mesh needs the PBR shader.
hasHighFidelityPbrMeshes
bool hasHighFidelityPbrMeshes() constReturns True when any PBR mesh requires the high-fidelity PBR path (Material::requiresHighFidelityPbr()).
hasTransmissivePbrMeshes
bool hasTransmissivePbrMeshes() constReturns True when any PBR mesh needs the transmission pass (Material::hasTransmissivePass()).
hasProximityFadePbrMeshes
bool hasProximityFadePbrMeshes() constReturns True when any PBR mesh uses proximity fade (Material::hasProximityFadePass()).
usesDefaultDepthAndStencilState
bool usesDefaultDepthAndStencilState() constReturns True when every mesh uses default depth/stencil state (Material::usesDefaultDepthAndStencilState()).
hasFullPbrMeshes
bool hasFullPbrMeshes() constReturns True when any PBR mesh cannot use the compact PBR shader (Material::canUseCompactPbr()).
hasFoliageFastPbrMeshes
bool hasFoliageFastPbrMeshes() constReturns True when any mesh can use the foliage fast-PBR path (Material::canUseFoliageFastPbr()).
hasWeatherEligiblePbrMeshes
bool hasWeatherEligiblePbrMeshes() constReturns True when any mesh reacts to active weather (Material::receivesActiveWeather()).
hasSimpleMeshes
bool hasSimpleMeshes() constReturns True when any mesh uses non-PBR (simple/textured) shading.
hasPlanarReflectionMeshes
bool hasPlanarReflectionMeshes() constReturns True when any PBR mesh enables Material::usePlanarReflection.
hasTransparentMaterials
bool hasTransparentMaterials() constReturns True when any cached mesh material must be rendered in the transparent pass.
hasSpecialBlendMode
bool hasSpecialBlendMode() constReturns True when any cached mesh uses a blend mode other than Material::BlendMode::Mix.
renderPriority
int renderPriority() constReturns Highest Material::renderPriority across cached meshes (0 if none).
apply
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
| Parameter | Description |
|---|---|
snapshot | Object state with the same object identity, copied when it changed. |
Returns What changed.
draw
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
| Parameter | Description |
|---|---|
shader | Shader used for rendering. |
showCollisionBodies | True to render collision geometry when available (articulated systems only). |
mode | Which material passes of each mesh to draw. |
isSelectable
bool isSelectable() constCheck if this object can be selected in the picker.
Returns True if not hidden, and not a heightmap or ground plane.
configureGroundMaterial
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
| Parameter | Description |
|---|---|
reflective | Use a reflective PBR ground. |
roughness | PBR roughness, clamped to [0.04, 1] (reflective only). |
metallic | PBR metallic factor, clamped to [0, 1] (reflective only). |
proceduralChecker | Draw a procedural checker instead of the ground texture. |
setHidden
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
| Parameter | Description |
|---|---|
h | True to hide. |
hidden
bool hidden() constCheck if object is hidden.
Returns True if hidden by setHidden() or by its appearance.
getColor
glm::vec4 getColor() constGet 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
float approximateRadius(bool showCollisionBodies) constConservative bounding radius for coarse culling.
Parameters
| Parameter | Description |
|---|---|
showCollisionBodies | Measure collision instead of visual geometry. |
Returns Radius from approximateBounds(), or 1 when bounds are unavailable.
shadowGeometryWithinBounds
bool shadowGeometryWithinBounds() constReturns True when shadow depth draws keep every vertex inside approximateBounds(): no material uses billboards, fixed-size scaling or height displacement.
shadowDepthMayDiscard
bool shadowDepthMayDiscard(
bool showCollisionBodies,
bool transparentShadowDithering) constReturns 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
bool approximateBounds(
bool showCollisionBodies,
glm::vec3 ¢er,
float &radius) constConservative 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
| Parameter | Description |
|---|---|
showCollisionBodies | Measure 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
void cullingBounds(
bool showCollisionBodies,
glm::vec3 ¢er,
float &radius) constBounds for coarse culling: approximateBounds(), or a unit sphere at the object origin when the object draws no geometry.
Parameters
| Parameter | Description |
|---|---|
showCollisionBodies | Measure collision instead of visual geometry. |
center (out) | Sphere center in world coordinates. |
radius (out) | Sphere radius in metres. |
getPrimitiveBatchData
bool getPrimitiveBatchData(
bool showCollisionBodies,
glm::mat4 &model,
raisim::Shape::Type &shape,
glm::vec4 &color) constReturn transform/color data for simple single-body primitive batching.
Parameters
| Parameter | Description |
|---|---|
showCollisionBodies | Batching 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
bool getPrimitiveBatchTemplate(
bool showCollisionBodies,
raisim::Shape::Type &shape,
glm::vec3 &scale,
glm::vec4 &color) constPose-independent part of getPrimitiveBatchData().
Parameters
| Parameter | Description |
|---|---|
showCollisionBodies | Batching is refused when true. |
shape (out) | Primitive shape. |
scale (out) | Primitive scale. |
color (out) | Object color. |
Returns True when this object is batchable.
setDefaultPrimitivePbrEnabled
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
| Parameter | Description |
|---|---|
enabled | True to use the default PBR primitive material. |
collectMaterialTextureIds
void collectMaterialTextureIds(std::vector<unsigned int> &textureIds) constAppend non-environment material texture ids used by this object's cached meshes.
Parameters
| Parameter | Description |
|---|---|
textureIds (in, out) | Ids are appended (duplicates are not removed here). |
accumulateGeometryDiagnostics
void accumulateGeometryDiagnostics(
OpenGLMesh::GeometryDiagnostics &diagnostics,
float tinyTriangleAreaThreshold) constAccumulate CPU-side mesh geometry diagnostics for this object.
Parameters
| Parameter | Description |
|---|---|
diagnostics (in, out) | Totals to add to. |
tinyTriangleAreaThreshold | Triangles below this area count as tiny. |
collectMeshDiagnostics
void collectMeshDiagnostics(
std::vector<OpenGLMesh::MeshDiagnostics> &diagnostics,
float tinyTriangleAreaThreshold) constAppend per-mesh geometry/material diagnostics for this object.
Parameters
| Parameter | Description |
|---|---|
diagnostics (in, out) | One entry is appended per mesh. |
tinyTriangleAreaThreshold | Triangles below this area count as tiny. |
debugModelMatrixCacheRebuilds
size_t debugModelMatrixCacheRebuilds() constReturns Number of model-matrix rebuilds, for tests and diagnostics.
debugMeshLists
const std::vector<std::shared_ptr<std::vector<std::shared_ptr<OpenGLMesh>>>> &debugMeshLists() constInternal:
Returns The cached mesh lists (tests/diagnostics).
debugHasMeshGeometry
bool debugHasMeshGeometry() constInternal:
Returns True when any cached mesh list is non-empty (tests/diagnostics).