Correctly apply visibility state from mjvOption.

PiperOrigin-RevId: 948792559
Change-Id: Ic0357c7841519e8e5c903b45f045831745f0b2b3
This commit is contained in:
Haroon Qureshi
2026-07-16 00:23:15 -07:00
committed by Copybara-Service
parent f841b67c17
commit 3b63fbc6ba
2 changed files with 207 additions and 126 deletions
@@ -15,7 +15,8 @@
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_RENDERABLE_MANAGER_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_RENDERABLE_MANAGER_H_
#include <optional>
#include <array>
#include <unordered_map>
#include <vector>
#include <math/vec4.h>
#include <mujoco/mjdata.h>
@@ -38,7 +39,13 @@ class RenderableManager {
void Update(const mjData* data);
// Returns the renderable corresponding to the given model object.
mjrfRenderable* GetRenderable(mjtObj obj_type, int obj_index);
// For most objects, the sub_index is ignored. For slider-crank actuators,
// sub_index=0 returns the slider, sub_index=1 returns the crank. For tendons,
// sub_index is the tendon segment index. The number of segments can vary
// between frames so is undefined. If obj_type == mjOBJ_BODY, returns the
// geom or site associated with the body.
mjrfRenderable* GetRenderable(mjtObj obj_type, int obj_index,
int sub_index = -1);
// Returns the default material (as defined in the mjModel) for the given
// object. Useful if you want to "reset" the material of a renderable back
@@ -47,15 +54,21 @@ class RenderableManager {
// Marks the given object as "selected", unmarking any previously selected
// object.
void SelectObject(mjtObj obj_type, int obj_index);
void MarkAsSelected(mjtObj obj_type, int obj_index);
// Sets the visibility of all renderables of the given type. If `group` is
// specified, only applies to renderables in that group.
void SetVisibility(mjtObj obj_type, bool visible,
std::optional<int> group = std::nullopt);
// Sets the visualization options on the renderables. The following options
// are supported:
// - shows/hides renderables based on the group visibility
// - shows/hides renderables based on mjVIS_SKIN, mjVIS_FLEXSKIN,
// mjVIS_TENDON, and mjVIS_ACTUATOR flags
// - adds island state to materials if mjVIS_ISLAND is enabled
// - switches meshes to convex hull mode if mjVIS_CONVEXHULL is enabled
// - adjusts alpha values if mjVIS_TRANSPARENT is enabled
void SetOptions(const mjvOption& opt);
// Returns the current visualization options.
const mjvOption& GetOptions() const { return vopts_; }
// Applies the visualization options to the renderables in the scene.
void Apply(const mjvOption& vopts);
RenderableManager(const RenderableManager&) = delete;
RenderableManager& operator=(const RenderableManager&) = delete;
@@ -70,29 +83,29 @@ class RenderableManager {
void UpdateSpatialTendons(const mjData* data, int tendon_id);
void AppendSegmentToTendon(int tendon_id);
void RemoveSegmentFromTendon(int tendon_id);
void UpdateSliderCranks(const mjData* data, int actuator_id, int index);
void UpdateSliderCranks(const mjData* data, int actuator_id);
int GetSegmentationId(mjtObj obj_type, int obj_index);
void SetVisibility(mjtObj obj_type, int idx, bool visible);
mjrfScene* scene_;
ModelObjects* model_objects_;
mjvOption vopts_;
mjtObj selected_obj_type_ = mjOBJ_UNKNOWN;
int selected_obj_index_ = -1;
std::vector<UniquePtr<mjrfRenderable>> geoms_;
std::vector<UniquePtr<mjrfRenderable>> sites_;
std::vector<UniquePtr<mjrfRenderable>> flexes_;
std::vector<UniquePtr<mjrfRenderable>> skins_;
std::vector<UniquePtr<mjrfRenderable>> sliders_;
std::vector<UniquePtr<mjrfRenderable>> cranks_;
std::unordered_map<int, std::array<UniquePtr<mjrfRenderable>, 2>> slider_cranks_;
std::vector<std::vector<UniquePtr<mjrfRenderable>>> tendons_;
std::vector<UniquePtr<mjrfMesh>> flex_meshes_;
std::vector<UniquePtr<mjrfMesh>> skin_meshes_;
std::vector<filament::math::float4> point_cache_;
mjtObj selected_obj_type_ = mjOBJ_UNKNOWN;
int selected_obj_index_ = -1;
};
} // namespace mujoco