Move filament::Skybox object management into SceneView.
ModelObjects no longer directly manages any filament objects. PiperOrigin-RevId: 906873925 Change-Id: Iaa317cbeb9c5236745a5f0d04a740985bec54a5c
This commit is contained in:
committed by
Copybara-Service
parent
6f275b79c6
commit
32aeb377b5
@@ -26,12 +26,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/IndirectLight.h>
|
||||
#include <filament/Material.h>
|
||||
#include <filament/Skybox.h>
|
||||
#include <math/TVecHelpers.h>
|
||||
#include <math/mat3.h>
|
||||
#include <math/scalar.h>
|
||||
#include <math/vec2.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
@@ -47,7 +42,6 @@ namespace mujoco {
|
||||
using filament::math::float2;
|
||||
using filament::math::float3;
|
||||
using filament::math::float4;
|
||||
using filament::math::mat3f;
|
||||
|
||||
enum class MeshType {
|
||||
kNormal,
|
||||
@@ -534,12 +528,6 @@ ModelObjects::ModelObjects(const mjModel* model, filament::Engine* engine)
|
||||
}
|
||||
|
||||
ModelObjects::~ModelObjects() {
|
||||
for (auto& iter : skyboxes_) {
|
||||
engine_->destroy(iter);
|
||||
}
|
||||
for (auto& iter : indirect_lights_) {
|
||||
engine_->destroy(iter);
|
||||
}
|
||||
meshes_.clear();
|
||||
textures_.clear();
|
||||
}
|
||||
@@ -681,48 +669,13 @@ const Texture* ModelObjects::GetTexture(int mat_id, int role) const {
|
||||
return GetTexture(tex_id);
|
||||
}
|
||||
|
||||
filament::IndirectLight* ModelObjects::CreateIndirectLight(int tex_id,
|
||||
float intensity) {
|
||||
filament::Texture* texture = nullptr;
|
||||
const Texture::SphericalHarmonics* spherical_harmonics = nullptr;
|
||||
auto texture_iter = textures_.find(tex_id);
|
||||
if (texture_iter != textures_.end()) {
|
||||
texture = texture_iter->second->GetFilamentTexture();
|
||||
spherical_harmonics = texture_iter->second->GetSphericalHarmonics();
|
||||
}
|
||||
|
||||
filament::IndirectLight::Builder builder;
|
||||
builder.reflections(texture);
|
||||
if (spherical_harmonics != nullptr) {
|
||||
builder.irradiance(3, *spherical_harmonics);
|
||||
}
|
||||
builder.intensity(intensity);
|
||||
// Rotate the light to match mujoco's Z-up convention.
|
||||
builder.rotation(mat3f::rotation(filament::math::f::PI / 2, float3{1, 0, 0}));
|
||||
filament::IndirectLight* indirect_light = builder.build(*engine_);
|
||||
indirect_lights_.push_back(indirect_light);
|
||||
return indirect_light;
|
||||
}
|
||||
|
||||
filament::Skybox* ModelObjects::CreateSkybox() {
|
||||
filament::Texture* skybox_texture = nullptr;
|
||||
const Texture* ModelObjects::GetSkyboxTexture() const {
|
||||
for (auto& iter : textures_) {
|
||||
const int texture_type = model_->tex_type[iter.first];
|
||||
if (texture_type == mjTEXTURE_SKYBOX) {
|
||||
skybox_texture = iter.second->GetFilamentTexture();
|
||||
break;
|
||||
if (model_->tex_type[iter.first] == mjTEXTURE_SKYBOX) {
|
||||
return iter.second.get();
|
||||
}
|
||||
}
|
||||
|
||||
if (skybox_texture == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
filament::Skybox::Builder builder;
|
||||
builder.environment(skybox_texture);
|
||||
filament::Skybox* skybox = builder.build(*engine_);
|
||||
skyboxes_.push_back(skybox);
|
||||
return skybox;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace mujoco
|
||||
|
||||
@@ -18,11 +18,8 @@
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/IndirectLight.h>
|
||||
#include <filament/Skybox.h>
|
||||
#include <mujoco/mjmodel.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/mesh.h"
|
||||
@@ -30,7 +27,7 @@
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
// Creates and owns various filament objects based on the data in a mjrContext.
|
||||
// Creates and owns various filament objects based on the mjModel.
|
||||
class ModelObjects {
|
||||
public:
|
||||
ModelObjects(const mjModel* model, filament::Engine* engine);
|
||||
@@ -58,10 +55,6 @@ class ModelObjects {
|
||||
|
||||
void CreateSkinFlexMesh(const mjvScene* scene, const mjvGeom& geom);
|
||||
|
||||
// Returns the filament engine used by the ModelObjects to create filament
|
||||
// objects.
|
||||
filament::Engine* GetEngine() const { return engine_; }
|
||||
|
||||
// Returns the cached instance of a filament object created from the mjModel.
|
||||
const Mesh* GetShapeBuffer(ShapeType shape) const;
|
||||
const Mesh* GetMeshBuffer(int data_id) const;
|
||||
@@ -69,9 +62,7 @@ class ModelObjects {
|
||||
const Mesh* GetFlexSkinGeomMesh(int geom_id) const;
|
||||
const Texture* GetTexture(int tex_id) const;
|
||||
const Texture* GetTexture(int mat_id, int role) const;
|
||||
|
||||
filament::Skybox* CreateSkybox();
|
||||
filament::IndirectLight* CreateIndirectLight(int tex_id, float intensity);
|
||||
const Texture* GetSkyboxTexture() const;
|
||||
|
||||
float GetSpecularMultiplier() const { return specular_multiplier_; }
|
||||
float GetShininessMultiplier() const { return shininess_multiplier_; }
|
||||
@@ -85,8 +76,6 @@ class ModelObjects {
|
||||
private:
|
||||
const mjModel* model_ = nullptr;
|
||||
filament::Engine* engine_ = nullptr;
|
||||
std::vector<filament::Skybox*> skyboxes_;
|
||||
std::vector<filament::IndirectLight*> indirect_lights_;
|
||||
std::array<std::unique_ptr<Mesh>, kNumShapes> shapes_;
|
||||
std::unordered_map<int, std::unique_ptr<Mesh>> meshes_;
|
||||
std::unordered_map<int, std::unique_ptr<Mesh>> convex_hulls_;
|
||||
|
||||
@@ -322,10 +322,7 @@ void SceneBridge::PrepareLights() {
|
||||
}
|
||||
}
|
||||
|
||||
filament::Skybox* skybox = model_objects_->CreateSkybox();
|
||||
if (skybox) {
|
||||
scene_view_->AddToScene(skybox);
|
||||
}
|
||||
scene_view_->SetSkybox(model_objects_->GetSkyboxTexture());
|
||||
}
|
||||
|
||||
filament::math::mat4 CalculateClipFromWorld(const mjrRect& viewport,
|
||||
|
||||
@@ -158,6 +158,10 @@ SceneView::SceneView(filament::Engine* engine) : engine_(engine) {
|
||||
}
|
||||
|
||||
SceneView::~SceneView() {
|
||||
if (skybox_) {
|
||||
scene_->setSkybox(nullptr);
|
||||
engine_->destroy(skybox_);
|
||||
}
|
||||
for (auto& light : lights_) {
|
||||
light->RemoveFromScene(scene_);
|
||||
}
|
||||
@@ -210,15 +214,17 @@ void SceneView::RemoveFromScene(Renderable* renderable) {
|
||||
}
|
||||
}
|
||||
|
||||
void SceneView::AddToScene(filament::Skybox* skybox) {
|
||||
skybox_ = skybox;
|
||||
scene_->setSkybox(skybox);
|
||||
}
|
||||
|
||||
void SceneView::RemoveFromScene(filament::Skybox* skybox) {
|
||||
if (skybox_ == skybox) {
|
||||
skybox_ = nullptr;
|
||||
void SceneView::SetSkybox(const Texture* skybox_texture) {
|
||||
if (skybox_) {
|
||||
scene_->setSkybox(nullptr);
|
||||
engine_->destroy(skybox_);
|
||||
skybox_ = nullptr;
|
||||
}
|
||||
if (skybox_texture) {
|
||||
filament::Skybox::Builder builder;
|
||||
builder.environment(skybox_texture->GetFilamentTexture());
|
||||
skybox_ = builder.build(*engine_);
|
||||
scene_->setSkybox(skybox_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "experimental/filament/filament/light.h"
|
||||
#include "experimental/filament/filament/renderable.h"
|
||||
#include "experimental/filament/filament/render_target.h"
|
||||
#include "experimental/filament/filament/texture.h"
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
@@ -49,8 +50,7 @@ class SceneView {
|
||||
void RemoveFromScene(Light* light);
|
||||
void AddToScene(Renderable* renderable);
|
||||
void RemoveFromScene(Renderable* renderable);
|
||||
void AddToScene(filament::Skybox* skybox);
|
||||
void RemoveFromScene(filament::Skybox* skybox);
|
||||
void SetSkybox(const Texture* skybox_texture);
|
||||
|
||||
// Parameters for rendering the scene.
|
||||
struct RenderRequest {
|
||||
|
||||
Reference in New Issue
Block a user