From 8e214e513301bfe647d6b03f9b36b65ee5648be8 Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Thu, 7 May 2026 01:18:58 -0700 Subject: [PATCH] Move imgui_editor into filament library. PiperOrigin-RevId: 911808107 Change-Id: I14318b1c7396e2eaf0df9d6afcc5298de01bcfa4 --- src/experimental/filament/CMakeLists.txt | 3 +- .../filament/compat/imgui_editor.h | 27 --------- .../filament/compat/mjr_filament_renderer.cc | 5 +- .../filament/compat/scene_bridge.cc | 35 +----------- .../filament/compat/scene_bridge.h | 6 -- .../{compat => filament}/imgui_editor.cc | 56 +++++++++---------- .../filament/render_context_filament.h | 5 ++ 7 files changed, 39 insertions(+), 98 deletions(-) delete mode 100644 src/experimental/filament/compat/imgui_editor.h rename src/experimental/filament/{compat => filament}/imgui_editor.cc (95%) diff --git a/src/experimental/filament/CMakeLists.txt b/src/experimental/filament/CMakeLists.txt index 9c9a2434..20ae8c5e 100644 --- a/src/experimental/filament/CMakeLists.txt +++ b/src/experimental/filament/CMakeLists.txt @@ -32,6 +32,7 @@ target_sources(${MUJOCO_FILAMENT_TARGET_NAME} filament/filament_context.h filament/filament_platform_factory.cc filament/filament_platform_factory.h + filament/imgui_editor.cc filament/light.cc filament/light.h filament/material.cc @@ -53,8 +54,6 @@ target_sources(${MUJOCO_FILAMENT_TARGET_NAME} filament/texture.h compat/imgui_bridge.cc compat/imgui_bridge.h - compat/imgui_editor.cc - compat/imgui_editor.h compat/mjr_filament_renderer.cc compat/mjr_filament_renderer.h compat/model_objects.cc diff --git a/src/experimental/filament/compat/imgui_editor.h b/src/experimental/filament/compat/imgui_editor.h deleted file mode 100644 index 3457fd26..00000000 --- a/src/experimental/filament/compat/imgui_editor.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2025 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_IMGUI_EDITOR_H_ -#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_IMGUI_EDITOR_H_ - -#include "experimental/filament/compat/scene_bridge.h" - -namespace mujoco { - -// Generates a ImGui Window for the given scene views. -void DrawGui(SceneBridge* scene_bridge); - -} // namespace mujoco - -#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_IMGUI_EDITOR_H_ diff --git a/src/experimental/filament/compat/mjr_filament_renderer.cc b/src/experimental/filament/compat/mjr_filament_renderer.cc index 9331f93c..c56731d8 100644 --- a/src/experimental/filament/compat/mjr_filament_renderer.cc +++ b/src/experimental/filament/compat/mjr_filament_renderer.cc @@ -24,7 +24,6 @@ #include #include #include "experimental/filament/compat/imgui_bridge.h" -#include "experimental/filament/compat/imgui_editor.h" #include "experimental/filament/compat/scene_bridge.h" #include "experimental/filament/filament/filament_context.h" #include "experimental/filament/filament/model_util.h" @@ -185,6 +184,8 @@ uintptr_t MjrFilamentRenderer::UploadGuiImage(uintptr_t tex_id, return imgui_bridge_->UploadImage(tex_id, pixels, width, height, bpp); } -void MjrFilamentRenderer::UpdateGui() { DrawGui(scene_bridge_.get()); } +void MjrFilamentRenderer::UpdateGui() { + mjrf_DEBUG_drawImguiEditor(scene_bridge_->GetScene()); +} } // namespace mujoco diff --git a/src/experimental/filament/compat/scene_bridge.cc b/src/experimental/filament/compat/scene_bridge.cc index ad6d1518..9d9a355c 100644 --- a/src/experimental/filament/compat/scene_bridge.cc +++ b/src/experimental/filament/compat/scene_bridge.cc @@ -32,7 +32,6 @@ #include "experimental/filament/filament/object_manager.h" #include "experimental/filament/filament/math_util.h" #include "experimental/filament/filament/model_util.h" -#include "experimental/filament/filament/scene_view.h" #include "experimental/filament/render_context_filament.h" #include "experimental/filament/render_context_filament_cpp.h" @@ -44,13 +43,10 @@ using filament::math::mat3; using filament::math::mat4; static UniquePtr CreateFallbackIndirectLightTexture( - mjrfContext* ctx, std::string_view filename = "") { - if (filename.empty()) { - filename = ObjectManager::kDefaultEnvironmentLight; - } - + mjrfContext* ctx) { std::unique_ptr asset = - FilamentContext::downcast(ctx)->GetObjectManager()->LoadAsset(filename); + FilamentContext::downcast(ctx)->GetObjectManager()->LoadAsset( + ObjectManager::kDefaultEnvironmentLight); mjrTextureConfig config; mjr_defaultTextureConfig(&config); @@ -118,31 +114,6 @@ SceneBridge::~SceneBridge() { renderables_.clear(); } -void SceneBridge::SetEnvironmentLight(std::string_view filename, - float intensity) { - for (auto& light : lights_) { - if (mjrf_getLightType(light.get()) == mjLIGHT_IMAGE) { - mjrf_removeLightFromScene(scene_.get(), light.get()); - light.reset(); - break; - } - } - if (fallback_ibl_) { - mjrf_removeLightFromScene(scene_.get(), fallback_ibl_.get()); - fallback_ibl_.reset(); - } - - fallback_ibl_texture_ = CreateFallbackIndirectLightTexture(ctx_, filename); - - mjrLightParams params; - mjr_defaultLightParams(¶ms); - params.type = mjLIGHT_IMAGE; - params.texture = fallback_ibl_texture_.get(); - params.intensity = intensity; - fallback_ibl_ = CreateLight(ctx_, params); - mjrf_addLightToScene(scene_.get(), fallback_ibl_.get()); -} - std::optional SceneBridge::ClipFromWorld(const float3& pos) const{ const float4 clip_pos = clip_from_world_ * float4(pos, 1.0f); if (clip_pos.w == 0.0f) { diff --git a/src/experimental/filament/compat/scene_bridge.h b/src/experimental/filament/compat/scene_bridge.h index 0f04e402..19dca38a 100644 --- a/src/experimental/filament/compat/scene_bridge.h +++ b/src/experimental/filament/compat/scene_bridge.h @@ -37,12 +37,6 @@ class SceneBridge { SceneBridge(mjrfContext* ctx, const mjModel* model); ~SceneBridge(); - // Updates the environment light using the KTX image at the given path. - void SetEnvironmentLight(std::string_view filename, float intensity); - - // Updates the environment light to the fallback light - void SetFallbackEnvironmentLight(float intensity); - // Updates the Entities in the filament Scene to match the current mjvScene // state. void Update(const mjrRect& viewport, const mjvScene* scene); diff --git a/src/experimental/filament/compat/imgui_editor.cc b/src/experimental/filament/filament/imgui_editor.cc similarity index 95% rename from src/experimental/filament/compat/imgui_editor.cc rename to src/experimental/filament/filament/imgui_editor.cc index 54105aac..fe084307 100644 --- a/src/experimental/filament/compat/imgui_editor.cc +++ b/src/experimental/filament/filament/imgui_editor.cc @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "experimental/filament/compat/imgui_editor.h" #include #include @@ -34,9 +33,9 @@ #include #include #include -#include "experimental/filament/compat/scene_bridge.h" #include "experimental/filament/filament/color_grading_options.h" #include "experimental/filament/filament/scene_view.h" +#include "experimental/filament/render_context_filament.h" namespace mujoco { @@ -561,7 +560,7 @@ void DrawCameraGui(SceneView* scene_view) { Ui("Direction", &direction); } -void DrawIndirectLightGui(SceneBridge* scene_bridge, SceneView* scene_view) { +void DrawIndirectLightGui(SceneView* scene_view) { filament::View* view = scene_view->GetDefaultRenderView(); auto ibl = view->getScene()->getIndirectLight(); @@ -572,12 +571,6 @@ void DrawIndirectLightGui(SceneBridge* scene_bridge, SceneView* scene_view) { ibl->setIntensity(intensity); } } - - static char filename[256]; - ImGui::InputText("Filename", filename, sizeof(filename)); - if (ImGui::Button("Load")) { - scene_bridge->SetEnvironmentLight(filename, intensity); - } } void DrawLightGui(filament::LightManager& lm, @@ -650,75 +643,79 @@ void DrawLightGui(filament::LightManager& lm, } } -void DrawGui(SceneBridge* scene_bridge) { - SceneView* scene_view = SceneView::downcast(scene_bridge->GetScene()); +} // namespace mujoco + +extern "C" { + +void mjrf_DEBUG_drawImguiEditor(mjrScene* scene) { + mujoco::SceneView* scene_view = mujoco::SceneView::downcast(scene); filament::View* view = scene_view->GetDefaultRenderView(); filament::Engine* engine = scene_view->GetEngine(); filament::LightManager& lm = engine->getLightManager(); if (ImGui::TreeNodeEx("Ambient Occlusion")) { - DrawAmbientOcclusionGui(scene_view); + mujoco::DrawAmbientOcclusionGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Screen Space")) { - DrawScreenSpaceGui(scene_view); + mujoco::DrawScreenSpaceGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Shadowing")) { - DrawShadowingGui(scene_view); + mujoco::DrawShadowingGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Post Processing")) { - DrawPostProcessingGui(scene_view); + mujoco::DrawPostProcessingGui(scene_view); if (ImGui::TreeNodeEx("Anti Aliasing (FXAA)")) { - DrawFxaaGui(scene_view); + mujoco::DrawFxaaGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Anti Aliasing (MSAA)")) { - DrawMsaaGui(scene_view); + mujoco::DrawMsaaGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Anti Aliasing (Temporal)")) { - DrawTaaGui(scene_view); + mujoco::DrawTaaGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Bloom")) { - DrawBloomGui(scene_view); + mujoco::DrawBloomGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Color Grading")) { - DrawColorGradingGui(scene_view); + mujoco::DrawColorGradingGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Depth of Field")) { - DrawDepthOfFieldGui(scene_view); + mujoco::DrawDepthOfFieldGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Dithering")) { - DrawDitheringGui(scene_view); + mujoco::DrawDitheringGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Fog")) { - DrawFogGui(scene_view); + mujoco::DrawFogGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Vignette")) { - DrawVignetteGui(scene_view); + mujoco::DrawVignetteGui(scene_view); ImGui::TreePop(); } ImGui::TreePop(); } if (ImGui::TreeNodeEx("Visibility Layers")) { - DrawVisibleLayersGui(scene_view); + mujoco::DrawVisibleLayersGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Camera")) { - DrawCameraGui(scene_view); + mujoco::DrawCameraGui(scene_view); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Lights")) { if (ImGui::TreeNodeEx("Indirect (Image-based) Light")) { - DrawIndirectLightGui(scene_bridge, scene_view); + mujoco::DrawIndirectLightGui(scene_view); ImGui::TreePop(); } view->getScene()->forEach([&](utils::Entity entity) { @@ -732,11 +729,12 @@ void DrawGui(SceneBridge* scene_bridge) { : " (S)"; const std::string name = "Light " + std::to_string(entity.getId()) + type; if (ImGui::TreeNodeEx(name.c_str())) { - DrawLightGui(lm, li); + mujoco::DrawLightGui(lm, li); ImGui::TreePop(); } }); ImGui::TreePop(); } } -} // namespace mujoco + +} // extern "C" diff --git a/src/experimental/filament/render_context_filament.h b/src/experimental/filament/render_context_filament.h index 0881a0b6..29c403de 100644 --- a/src/experimental/filament/render_context_filament.h +++ b/src/experimental/filament/render_context_filament.h @@ -562,6 +562,11 @@ mjrFrameHandle mjrf_render(mjrfContext* ctx, const mjrRenderRequest* req, // Waits for the rendering to complete for the given frame handle. void mjrf_waitForFrame(mjrfContext* ctx, mjrFrameHandle frame); +// Draws an ImGui editor for the given scene, exposing filament-specific +// settings. +void mjrf_DEBUG_drawImguiEditor(mjrScene* scene); + + // Legacy API, to be deprecated. void mjrf_defaultFilamentConfig(mjrFilamentConfig* config);