Move imgui_editor into filament library.
PiperOrigin-RevId: 911808107 Change-Id: I14318b1c7396e2eaf0df9d6afcc5298de01bcfa4
This commit is contained in:
committed by
Copybara-Service
parent
39c891e358
commit
8e214e5133
@@ -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
|
||||
|
||||
@@ -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_
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <mujoco/mjvisualize.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#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
|
||||
|
||||
@@ -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<mjrTexture> CreateFallbackIndirectLightTexture(
|
||||
mjrfContext* ctx, std::string_view filename = "") {
|
||||
if (filename.empty()) {
|
||||
filename = ObjectManager::kDefaultEnvironmentLight;
|
||||
}
|
||||
|
||||
mjrfContext* ctx) {
|
||||
std::unique_ptr<ObjectManager::Asset> 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<float3> SceneBridge::ClipFromWorld(const float3& pos) const{
|
||||
const float4 clip_pos = clip_from_world_ * float4(pos, 1.0f);
|
||||
if (clip_pos.w == 0.0f) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
+27
-29
@@ -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 <algorithm>
|
||||
#include <any>
|
||||
@@ -34,9 +33,9 @@
|
||||
#include <math/mathfwd.h>
|
||||
#include <math/scalar.h>
|
||||
#include <math/vec3.h>
|
||||
#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"
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user