Remove direct dependency between SceneBridge and ImguiBridge.
PiperOrigin-RevId: 911366540 Change-Id: I05c348ea6b1d08c034f2bb26e4c770079073c61d
This commit is contained in:
committed by
Copybara-Service
parent
9ffd50ce6a
commit
2b67fe3c3a
@@ -17,7 +17,9 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#include <math/mathfwd.h>
|
||||||
#include <math/vec4.h>
|
#include <math/vec4.h>
|
||||||
#include <mujoco/mjmodel.h>
|
#include <mujoco/mjmodel.h>
|
||||||
#include <mujoco/mjvisualize.h>
|
#include <mujoco/mjvisualize.h>
|
||||||
@@ -39,6 +41,7 @@ MjrFilamentRenderer::MjrFilamentRenderer(const mjrFilamentConfig* config) {
|
|||||||
void MjrFilamentRenderer::Init(const mjModel* model) {
|
void MjrFilamentRenderer::Init(const mjModel* model) {
|
||||||
scene_bridge_ = std::make_unique<SceneBridge>(filament_context_.get(), model);
|
scene_bridge_ = std::make_unique<SceneBridge>(filament_context_.get(), model);
|
||||||
imgui_bridge_ = std::make_unique<ImguiBridge>(filament_context_.get());
|
imgui_bridge_ = std::make_unique<ImguiBridge>(filament_context_.get());
|
||||||
|
scene_bridge_->SetDrawTextFunction(DrawTextAt);
|
||||||
|
|
||||||
mjr_defaultRenderRequest(&render_requests_[0]);
|
mjr_defaultRenderRequest(&render_requests_[0]);
|
||||||
mjr_defaultRenderRequest(&render_requests_[1]);
|
mjr_defaultRenderRequest(&render_requests_[1]);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
#include <math/vec4.h>
|
#include <math/vec4.h>
|
||||||
#include <math/TVecHelpers.h>
|
#include <math/TVecHelpers.h>
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "experimental/filament/compat/imgui_bridge.h"
|
|
||||||
#include "experimental/filament/compat/model_objects.h"
|
#include "experimental/filament/compat/model_objects.h"
|
||||||
#include "experimental/filament/compat/scene_geom_util.h"
|
#include "experimental/filament/compat/scene_geom_util.h"
|
||||||
#include "experimental/filament/filament/filament_context.h"
|
#include "experimental/filament/filament/filament_context.h"
|
||||||
@@ -302,9 +301,9 @@ void SceneBridge::Update(const mjrRect& viewport, const mjvScene* scene) {
|
|||||||
for (int i = 0; i < scene->ngeom; ++i) {
|
for (int i = 0; i < scene->ngeom; ++i) {
|
||||||
const mjvGeom* geom = scene->geoms + i;
|
const mjvGeom* geom = scene->geoms + i;
|
||||||
|
|
||||||
if (geom->label[0] != 0) {
|
if (draw_text_callback_ && geom->label[0] != 0) {
|
||||||
if (auto pos = ClipFromWorld(ReadFloat3(geom->pos))) {
|
if (auto pos = ClipFromWorld(ReadFloat3(geom->pos))) {
|
||||||
DrawTextAt(geom->label, pos->x, pos->y, pos->z);
|
draw_text_callback_(geom->label, pos->x, pos->y, pos->z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,4 +360,9 @@ void SceneBridge::UploadTexture(const mjModel* model, int id) {
|
|||||||
void SceneBridge::UploadHeightField(const mjModel* model, int id) {
|
void SceneBridge::UploadHeightField(const mjModel* model, int id) {
|
||||||
model_objects_->UploadHeightField(model, id);
|
model_objects_->UploadHeightField(model, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneBridge::SetDrawTextFunction(DrawTextAtFn fn) {
|
||||||
|
draw_text_callback_ = std::move(fn);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mujoco
|
} // namespace mujoco
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_SCENE_BRIDGE_H_
|
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_SCENE_BRIDGE_H_
|
||||||
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_SCENE_BRIDGE_H_
|
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_COMPAT_SCENE_BRIDGE_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -51,6 +52,9 @@ class SceneBridge {
|
|||||||
void UploadTexture(const mjModel* model, int id);
|
void UploadTexture(const mjModel* model, int id);
|
||||||
void UploadHeightField(const mjModel* model, int id);
|
void UploadHeightField(const mjModel* model, int id);
|
||||||
|
|
||||||
|
using DrawTextAtFn = std::function<void(const char*, float, float, float)>;
|
||||||
|
void SetDrawTextFunction(DrawTextAtFn fn);
|
||||||
|
|
||||||
// Returns the managed scene.
|
// Returns the managed scene.
|
||||||
mjrScene* GetScene() const { return scene_.get(); }
|
mjrScene* GetScene() const { return scene_.get(); }
|
||||||
|
|
||||||
@@ -67,6 +71,7 @@ class SceneBridge {
|
|||||||
|
|
||||||
mjrfContext* ctx_ = nullptr;
|
mjrfContext* ctx_ = nullptr;
|
||||||
std::unique_ptr<ModelObjects> model_objects_;
|
std::unique_ptr<ModelObjects> model_objects_;
|
||||||
|
DrawTextAtFn draw_text_callback_;
|
||||||
UniquePtr<mjrScene> scene_{nullptr, nullptr};
|
UniquePtr<mjrScene> scene_{nullptr, nullptr};
|
||||||
UniquePtr<mjrLight> fallback_ibl_{nullptr, nullptr};
|
UniquePtr<mjrLight> fallback_ibl_{nullptr, nullptr};
|
||||||
UniquePtr<mjrTexture> fallback_ibl_texture_{nullptr, nullptr};
|
UniquePtr<mjrTexture> fallback_ibl_texture_{nullptr, nullptr};
|
||||||
|
|||||||
Reference in New Issue
Block a user