16 #include <unordered_set>
20 #pragma warning(disable : 4068 4146 4293 4305)
23 #include <backend/PixelBufferDescriptor.h>
24 #include <filament/Engine.h>
25 #include <filament/IndirectLight.h>
26 #include <filament/LightManager.h>
27 #include <filament/MaterialInstance.h>
28 #include <filament/Renderer.h>
29 #include <filament/Scene.h>
30 #include <filament/Skybox.h>
31 #include <filament/SwapChain.h>
32 #include <filament/Texture.h>
33 #include <filament/TextureSampler.h>
34 #include <filament/TransformManager.h>
35 #include <filament/VertexBuffer.h>
36 #include <filament/View.h>
37 #include <geometry/SurfaceOrientation.h>
38 #include <utils/EntityManager.h>
74 static void DeallocateBuffer(
void* buffer,
size_t size,
void* user_ptr) {
78 const std::string kBackgroundName =
"__background";
79 const std::string kGroundPlaneName =
"__ground_plane";
80 const Eigen::Vector4f kDefaultGroundPlaneColor(0.5f, 0.5f, 0.5f, 1.f);
82 namespace defaults_mapping {
86 using ResourceManager =
89 std::unordered_map<std::string, MaterialHandle> shader_mappings = {
90 {
"defaultLit", ResourceManager::kDefaultLit},
91 {
"defaultLitTransparency",
92 ResourceManager::kDefaultLitWithTransparency},
93 {
"defaultLitSSR", ResourceManager::kDefaultLitSSR},
94 {
"defaultUnlitTransparency",
95 ResourceManager::kDefaultUnlitWithTransparency},
96 {
"defaultUnlit", ResourceManager::kDefaultUnlit},
97 {
"normals", ResourceManager::kDefaultNormalShader},
98 {
"depth", ResourceManager::kDefaultDepthShader},
99 {
"depthValue", ResourceManager::kDefaultDepthValueShader},
100 {
"unlitGradient", ResourceManager::kDefaultUnlitGradientShader},
101 {
"unlitSolidColor", ResourceManager::kDefaultUnlitSolidColorShader},
102 {
"unlitPolygonOffset",
103 ResourceManager::kDefaultUnlitPolygonOffsetShader},
104 {
"unlitBackground", ResourceManager::kDefaultUnlitBackgroundShader},
105 {
"infiniteGroundPlane", ResourceManager::kInfinitePlaneShader},
106 {
"unlitLine", ResourceManager::kDefaultLineShader},
107 {
"gaussianSplat", ResourceManager::kGaussianSplatShader}};
113 MaterialHandle kColoredPointcloud = ResourceManager::kDefaultUnlit;
120 namespace converters {
121 using EigenMatrix = cloudViewer::visualization::rendering::FilamentScene::
122 Transform::MatrixType;
123 using FilamentMatrix = filament::math::mat4f;
124 EigenMatrix EigenMatrixFromFilamentMatrix(
const filament::math::mat4f& fm) {
127 em << fm(0, 0), fm(0, 1), fm(0, 2), fm(0, 3), fm(1, 0), fm(1, 1), fm(1, 2),
128 fm(1, 3), fm(2, 0), fm(2, 1), fm(2, 2), fm(2, 3), fm(3, 0),
129 fm(3, 1), fm(3, 2), fm(3, 3);
134 FilamentMatrix FilamentMatrixFromEigenMatrix(
const EigenMatrix& em) {
136 return FilamentMatrix(FilamentMatrix::row_major_init{
137 em(0, 0), em(0, 1), em(0, 2), em(0, 3), em(1, 0), em(1, 1),
138 em(1, 2), em(1, 3), em(2, 0), em(2, 1), em(2, 2), em(2, 3),
139 em(3, 0), em(3, 1), em(3, 2), em(3, 3)});
146 namespace visualization {
147 namespace rendering {
154 :
Scene(renderer), engine_(engine), resource_mgr_(resource_mgr) {
155 scene_ = engine_.createScene();
156 CreateSunDirectionalLight();
163 for (
auto& le : lights_) {
164 engine_.destroy(le.second.filament_entity);
165 le.second.filament_entity.clear();
167 engine_.destroy(sun_.filament_entity);
168 sun_.filament_entity.clear();
170 resource_mgr_.
Destroy(ibl_handle_);
172 if (skybox_handle_) {
173 resource_mgr_.
Destroy(skybox_handle_);
175 engine_.destroy(scene_);
180 copy->geometries_ = this->geometries_;
181 copy->lights_ = this->lights_;
182 copy->model_geometries_ = this->model_geometries_;
183 copy->background_color_ = this->background_color_;
184 copy->background_image_ = this->background_image_;
185 copy->ibl_name_ = this->ibl_name_;
186 copy->ibl_enabled_ = this->ibl_enabled_;
187 copy->skybox_enabled_ = this->skybox_enabled_;
188 copy->indirect_light_ = this->indirect_light_;
189 copy->skybox_ = this->skybox_;
190 copy->sun_ = this->sun_;
192 for (
auto& name_geom :
copy->geometries_) {
193 auto&
name = name_geom.first;
194 auto& geom = name_geom.second;
196 auto& renderable_mgr =
copy->engine_.getRenderableManager();
197 auto inst = renderable_mgr.getInstance(geom.filament_entity);
198 auto box = renderable_mgr.getAxisAlignedBoundingBox(inst);
199 auto vbuf =
copy->resource_mgr_.GetVertexBuffer(geom.vb).lock();
200 auto ibuf =
copy->resource_mgr_.GetIndexBuffer(geom.ib).lock();
201 auto new_entity = utils::EntityManager::get().create();
202 filament::RenderableManager::Builder builder(1);
203 builder.boundingBox(box)
206 .castShadows(geom.cast_shadows)
207 .receiveShadows(geom.receive_shadows)
208 .culling(geom.culling_enabled)
209 .geometry(0, geom.primitive_type, vbuf.get(), ibuf.get());
210 if (geom.priority >= 0) {
211 builder.priority(uint8_t(geom.priority));
213 copy->resource_mgr_.ReuseVertexBuffer(geom.vb);
215 auto material_instance =
copy->AssignMaterialToFilamentGeometry(
216 builder, geom.mat.properties);
218 auto result = builder.build(
copy->engine_, new_entity);
219 if (
result == filament::RenderableManager::Builder::Success) {
221 copy->scene_->addEntity(new_entity);
223 geom.filament_entity = new_entity;
224 geom.mat.mat_instance = material_instance;
227 copy->SetGeometryTransform(
name, transform);
228 copy->UpdateMaterialProperties(
233 "Failed to copy Filament resources for geometry {}",
name);
244 auto view = std::make_unique<FilamentView>(engine_, *
this, resource_mgr_);
246 view->SetViewport(x, y, w, h);
247 if (!views_.empty()) {
252 c.view = std::move(view);
253 views_.emplace(handle, std::move(c));
259 auto found = views_.find(view_id);
260 if (found != views_.end()) {
261 return found->second.view.get();
268 auto found = views_.find(view_id);
269 if (found != views_.end()) {
270 found->second.is_active = is_active;
271 found->second.render_count = -1;
276 auto found = views_.find(view_id);
277 if (found != views_.end()) {
278 found->second.is_active =
true;
279 found->second.render_count = 1;
284 views_.erase(view_id);
288 std::shared_ptr<Camera> cam) {}
295 filament::RenderableManager::Builder& builder,
298 auto shader = defaults_mapping::shader_mappings[material.
shader];
299 if (!shader) shader = defaults_mapping::kColorOnlyMesh;
303 if (!wmat_instance.expired()) {
304 builder.material(0, wmat_instance.lock().get());
306 return material_instance;
312 const std::string& downsampled_name ,
313 size_t downsample_threshold ) {
314 if (geometries_.count(object_name) > 0) {
316 "Geometry {} has already been added to scene graph.",
324 "Geometry for object {} is empty. Not adding geometry to scene",
329 auto tris =
dynamic_cast<const ccMesh*
>(&geometry);
330 if (tris && !tris->hasNormals() && !tris->hasTriNormals() &&
331 (material.
shader ==
"defaultUnlit" ||
332 material.
shader ==
"defaultLitTransparency")) {
334 "Using a shader with lighting but geometry has no normals.");
339 if (!buffer_builder) {
344 if (!downsampled_name.empty()) {
345 buffer_builder->SetDownsampleThreshold(downsample_threshold);
347 buffer_builder->SetAdjustColorsForSRGBToneMapping(material.
sRGB_color);
348 if (material.
shader ==
"unlitLine") {
349 buffer_builder->SetWideLines();
352 auto buffers = buffer_builder->ConstructBuffers();
353 auto vb = std::get<0>(buffers);
354 auto ib = std::get<1>(buffers);
355 auto ib_downsampled = std::get<2>(buffers);
356 filament::Box aabb = buffer_builder->ComputeAABB();
357 bool success = CreateAndAddFilamentEntity(object_name, *buffer_builder,
358 aabb,
vb,
ib, material);
359 if (success && ib_downsampled) {
360 if (!CreateAndAddFilamentEntity(downsampled_name, *buffer_builder, aabb,
361 vb, ib_downsampled, material,
362 BufferReuse::kYes)) {
364 "Internal error: could not create downsampled point cloud");
373 const std::string& downsampled_name ,
374 size_t downsample_threshold ) {
381 if (!buffer_builder) {
383 "Unable to create GPU resources for object {}. Please check "
384 "console for further details.",
390 if (!downsampled_name.empty()) {
391 buffer_builder->SetDownsampleThreshold(downsample_threshold);
393 buffer_builder->SetAdjustColorsForSRGBToneMapping(material.
sRGB_color);
394 if (material.
shader ==
"unlitLine") {
395 buffer_builder->SetWideLines();
398 auto buffers = buffer_builder->ConstructBuffers();
399 auto vb = std::get<0>(buffers);
400 auto ib = std::get<1>(buffers);
401 auto ib_downsampled = std::get<2>(buffers);
402 filament::Box aabb = buffer_builder->ComputeAABB();
405 auto* drawable_geom =
408 if (drawable_geom->HasMaterial()) {
409 drawable_geom->GetMaterial().ToMaterialRecord(internal_material);
411 bool success = CreateAndAddFilamentEntity(object_name, *buffer_builder,
412 aabb,
vb,
ib, internal_material);
413 if (success && ib_downsampled) {
414 if (!CreateAndAddFilamentEntity(downsampled_name, *buffer_builder, aabb,
415 vb, ib_downsampled, internal_material,
416 BufferReuse::kYes)) {
421 "Internal error: could not create downsampled point cloud");
422 CreateAndAddFilamentEntity(downsampled_name, *buffer_builder, aabb,
423 vb,
ib, material, BufferReuse::kYes);
446 if (geometries_.count(object_name) > 0 ||
447 model_geometries_.count(object_name) > 0) {
453 std::vector<std::string> mesh_object_names;
454 std::unordered_multiset<std::string> check_duplicates;
455 for (
const auto& mesh : model.
meshes_) {
456 auto& mat = model.
materials_[mesh.material_idx];
457 std::string derived_name(object_name +
":" + mesh.mesh_name);
458 check_duplicates.insert(derived_name);
459 if (check_duplicates.count(derived_name) > 1) {
465 mesh_object_names.push_back(derived_name);
467 model_geometries_[object_name] = mesh_object_names;
472 bool FilamentScene::CreateAndAddFilamentEntity(
473 const std::string& object_name,
479 BufferReuse reusing_vertex_buffer ) {
483 auto filament_entity = utils::EntityManager::get().create();
484 filament::RenderableManager::Builder builder(1);
485 builder.boundingBox(aabb)
488 .receiveShadows(
true)
492 auto material_instance =
493 AssignMaterialToFilamentGeometry(builder, material);
495 auto result = builder.build(engine_, filament_entity);
496 if (
result == filament::RenderableManager::Builder::Success) {
497 scene_->addEntity(filament_entity);
501 RenderableGeometry{object_name,
508 {{}, material, material_instance},
515 UpdateMaterialProperties(giter.first->second);
520 "Failed to build Filament resources for geometry {}",
525 if (reusing_vertex_buffer == BufferReuse::kYes) {
533 if (GeometryIsModel(object_name)) {
536 auto geom_entry = geometries_.find(object_name);
537 return (geom_entry != geometries_.end());
542 uint32_t update_flags) {
543 auto geoms = GetGeometry(object_name,
false);
544 if (!geoms.empty()) {
548 auto vbuf = vbuf_ptr.get();
551 const size_t n_vertices =
points.GetLength();
558 if (n_vertices > vbuf->getVertexCount()) {
560 "Geometry for point cloud {} cannot be updated because the "
561 "number of points exceeds the existing point count (Old: "
563 object_name, vbuf->getVertexCount(), n_vertices);
567 bool geometry_update_needed = n_vertices != vbuf->getVertexCount();
572 cpu_pcloud = point_cloud.
CPU();
577 const size_t vertex_array_size = n_vertices * 3 *
sizeof(float);
580 static_cast<float*
>(malloc(vertex_array_size));
583 filament::VertexBuffer::BufferDescriptor pts_descriptor(
584 vertex_data, vertex_array_size, DeallocateBuffer);
585 vbuf->setBufferAt(engine_, 0, std::move(pts_descriptor));
587 filament::VertexBuffer::BufferDescriptor pts_descriptor(
588 points.GetDataPtr(), vertex_array_size);
589 vbuf->setBufferAt(engine_, 0, std::move(pts_descriptor));
594 const size_t color_array_size = n_vertices * 3 *
sizeof(float);
596 auto color_data =
static_cast<float*
>(malloc(color_array_size));
599 filament::VertexBuffer::BufferDescriptor color_descriptor(
600 color_data, color_array_size, DeallocateBuffer);
601 vbuf->setBufferAt(engine_, 1, std::move(color_descriptor));
603 filament::VertexBuffer::BufferDescriptor color_descriptor(
606 vbuf->setBufferAt(engine_, 1, std::move(color_descriptor));
612 const size_t normal_array_size = n_vertices * 4 *
sizeof(float);
613 const void* normal_data =
nullptr;
616 normal_data =
normals.GetDataPtr();
622 auto float4v_tangents =
static_cast<filament::math::quatf*
>(
623 malloc(normal_array_size));
624 auto orientation = filament::geometry::SurfaceOrientation::Builder()
625 .vertexCount(n_vertices)
626 .normals(
reinterpret_cast<
627 const filament::math::float3*
>(
630 orientation->getQuats(float4v_tangents, n_vertices);
631 filament::VertexBuffer::BufferDescriptor normals_descriptor(
632 float4v_tangents, normal_array_size, DeallocateBuffer);
633 vbuf->setBufferAt(engine_, 2, std::move(normals_descriptor));
638 const size_t uv_array_size = n_vertices * 2 *
sizeof(float);
640 filament::VertexBuffer::BufferDescriptor uv_descriptor(
643 vbuf->setBufferAt(engine_, 3, std::move(uv_descriptor));
644 }
else if (point_cloud.
HasPointAttr(
"__visualization_scalar")) {
647 float* uv_array =
static_cast<float*
>(malloc(uv_array_size));
648 memset(uv_array, 0, uv_array_size);
649 const float* src =
static_cast<const float*
>(
652 const size_t n = 2 * n_vertices;
653 for (
size_t i = 0; i < n; i += 2) {
654 uv_array[i] = *src++;
656 filament::VertexBuffer::BufferDescriptor uv_descriptor(
657 uv_array, uv_array_size, DeallocateBuffer);
658 vbuf->setBufferAt(engine_, 3, std::move(uv_descriptor));
663 if (geometry_update_needed) {
664 auto& renderable_mgr = engine_.getRenderableManager();
665 auto inst = renderable_mgr.getInstance(g->filament_entity);
666 renderable_mgr.setGeometryAt(
667 inst, 0, filament::RenderableManager::PrimitiveType::POINTS,
674 auto geoms = GetGeometry(object_name,
false);
675 if (!geoms.empty()) {
676 for (
auto* g : geoms) {
677 scene_->remove(g->filament_entity);
678 g->ReleaseResources(engine_, resource_mgr_);
679 geometries_.erase(g->name);
683 if (GeometryIsModel(object_name)) {
684 model_geometries_.erase(object_name);
689 auto geoms = GetGeometry(object_name);
690 for (
auto* g : geoms) {
691 if (g->visible != show) {
694 scene_->addEntity(g->filament_entity);
696 scene_->remove(g->filament_entity);
703 auto geoms = GetGeometry(object_name);
704 if (!geoms.empty()) {
707 return geoms[0]->visible;
713 utils::EntityInstance<filament::TransformManager>
714 FilamentScene::GetGeometryTransformInstance(RenderableGeometry* geom) {
715 filament::TransformManager::Instance itransform;
716 auto& transform_mgr = engine_.getTransformManager();
717 itransform = transform_mgr.getInstance(geom->filament_entity);
718 if (!itransform.isValid()) {
719 using namespace filament::math;
720 transform_mgr.create(geom->filament_entity);
721 itransform = transform_mgr.getInstance(geom->filament_entity);
722 transform_mgr.create(
723 geom->filament_entity, itransform,
724 mat4f::translation(filament::math::float3{0.0f, 0.0f, 0.0f}));
731 auto geoms = GetGeometry(object_name);
732 for (
auto* g : geoms) {
733 auto itransform = GetGeometryTransformInstance(g);
734 if (itransform.isValid()) {
735 const auto& ematrix = transform.matrix();
736 auto& transform_mgr = engine_.getTransformManager();
737 transform_mgr.setTransform(
739 converters::FilamentMatrixFromEigenMatrix(ematrix));
745 const std::string& object_name) {
747 auto geoms = GetGeometry(object_name);
748 if (!geoms.empty()) {
749 auto itransform = GetGeometryTransformInstance(geoms[0]);
750 if (itransform.isValid()) {
751 auto& transform_mgr = engine_.getTransformManager();
752 auto ftransform = transform_mgr.getTransform(itransform);
753 etransform = converters::EigenMatrixFromFilamentMatrix(ftransform);
761 auto geoms = GetGeometry(object_name);
762 for (
auto* g : geoms) {
763 auto& renderable_mgr = engine_.getRenderableManager();
764 auto inst = renderable_mgr.getInstance(g->filament_entity);
765 auto box = renderable_mgr.getAxisAlignedBoundingBox(inst);
767 auto& transform_mgr = engine_.getTransformManager();
768 auto itransform = transform_mgr.getInstance(g->filament_entity);
769 auto transform = transform_mgr.getWorldTransform(itransform);
771 box = rigidTransform(box, transform);
773 auto min = box.center - box.halfExtent;
774 auto max = box.center + box.halfExtent;
783 bool receive_shadows) {
784 auto geoms = GetGeometry(object_name);
785 for (
auto* g : geoms) {
786 auto& renderable_mgr = engine_.getRenderableManager();
787 filament::RenderableManager::Instance inst =
788 renderable_mgr.getInstance(g->filament_entity);
789 renderable_mgr.setCastShadows(inst, cast_shadows);
790 renderable_mgr.setReceiveShadows(inst, receive_shadows);
796 auto geoms = GetGeometry(object_name);
797 for (
auto* g : geoms) {
798 auto& renderable_mgr = engine_.getRenderableManager();
799 filament::RenderableManager::Instance inst =
800 renderable_mgr.getInstance(g->filament_entity);
801 renderable_mgr.setCulling(inst, enable);
802 g->culling_enabled = enable;
808 auto geoms = GetGeometry(object_name);
809 for (
auto* g : geoms) {
810 auto& renderable_mgr = engine_.getRenderableManager();
811 filament::RenderableManager::Instance inst =
812 renderable_mgr.getInstance(g->filament_entity);
813 renderable_mgr.setPriority(inst, priority);
814 g->priority = (int)priority;
818 void FilamentScene::UpdateDefaultLit(GeometryMaterialInstance& geom_mi) {
819 auto& material = geom_mi.properties;
820 auto& maps = geom_mi.maps;
836 .
SetTexture(
"ao_rough_metalMap", maps.ao_rough_metal_map,
838 .
SetTexture(
"reflectanceMap", maps.reflectance_map,
852 void FilamentScene::UpdateGaussianSplat(GeometryMaterialInstance& geom_mi) {
853 auto& material = geom_mi.properties;
854 auto& maps = geom_mi.maps;
871 .
SetTexture(
"ao_rough_metalMap", maps.ao_rough_metal_map,
873 .
SetTexture(
"reflectanceMap", maps.reflectance_map,
878 void FilamentScene::UpdateDefaultLitSSR(GeometryMaterialInstance& geom_mi) {
879 auto& material = geom_mi.properties;
880 auto& maps = geom_mi.maps;
882 auto absorption_float3 = filament::Color::absorptionAtDistance(
887 Eigen::Vector3f absorption(absorption_float3.x, absorption_float3.y,
888 absorption_float3.z);
907 .
SetTexture(
"ao_rough_metalMap", maps.ao_rough_metal_map,
909 .
SetTexture(
"reflectanceMap", maps.reflectance_map,
914 void FilamentScene::UpdateDefaultUnlit(GeometryMaterialInstance& geom_mi) {
915 float srgb = (geom_mi.properties.sRGB_vertex_color ? 1.f : 0.f);
918 .
SetColor(
"baseColor", geom_mi.properties.base_color,
true)
919 .
SetParameter(
"pointSize", geom_mi.properties.point_size)
921 .
SetTexture(
"albedo", geom_mi.maps.albedo_map,
926 void FilamentScene::UpdateNormalShader(GeometryMaterialInstance& geom_mi) {
928 .
SetParameter(
"pointSize", geom_mi.properties.point_size)
932 void FilamentScene::UpdateDepthShader(GeometryMaterialInstance& geom_mi) {
933 auto* camera = views_.begin()->second.view->GetCamera();
934 const float f = float(camera->GetFar());
935 const float n = float(camera->GetNear());
937 .
SetParameter(
"pointSize", geom_mi.properties.point_size)
943 void FilamentScene::UpdateDepthValueShader(GeometryMaterialInstance& geom_mi) {
945 .
SetParameter(
"pointSize", geom_mi.properties.point_size)
949 void FilamentScene::UpdateGradientShader(GeometryMaterialInstance& geom_mi) {
953 .
SetParameter(
"minValue", geom_mi.properties.scalar_min)
954 .
SetParameter(
"maxValue", geom_mi.properties.scalar_max)
956 .SetParameter(
"pointSize", geom_mi.properties.point_size)
958 "gradient", geom_mi.maps.gradient_texture,
964 void FilamentScene::UpdateSolidColorShader(GeometryMaterialInstance& geom_mi) {
966 .
SetColor(
"baseColor", geom_mi.properties.base_color,
true)
967 .
SetParameter(
"pointSize", geom_mi.properties.point_size)
971 void FilamentScene::UpdateBackgroundShader(GeometryMaterialInstance& geom_mi) {
973 .
SetColor(
"baseColor", geom_mi.properties.base_color,
true)
974 .
SetParameter(
"aspectRatio", geom_mi.properties.aspect_ratio)
976 .
SetTexture(
"albedo", geom_mi.maps.albedo_map,
981 void FilamentScene::UpdateGroundPlaneShader(GeometryMaterialInstance& geom_mi) {
983 .
SetColor(
"baseColor", geom_mi.properties.base_color,
true)
984 .
SetParameter(
"axis", geom_mi.properties.ground_plane_axis)
988 void FilamentScene::UpdateLineShader(GeometryMaterialInstance& geom_mi) {
990 .
SetColor(
"baseColor", geom_mi.properties.base_color,
true)
991 .
SetColor(
"emissiveColor", geom_mi.properties.emissive_color,
false)
992 .
SetParameter(
"lineWidth", geom_mi.properties.line_width)
996 void FilamentScene::UpdateUnlitPolygonOffsetShader(
997 GeometryMaterialInstance& geom_mi) {
999 .
SetParameter(
"pointSize", geom_mi.properties.point_size)
1004 std::shared_ptr<geometry::Image> ao,
1005 std::shared_ptr<geometry::Image> rough,
1006 std::shared_ptr<geometry::Image> metal) {
1008 if (ao && ao->HasData()) {
1012 if (rough && rough->HasData()) {
1014 width = rough->width_;
1016 }
else if (
width != rough->width_ ||
height != rough->height_) {
1018 "Attribute texture maps must have same dimensions");
1022 if (metal && metal->HasData()) {
1024 width = metal->width_;
1026 }
else if (
width != metal->width_ ||
height != metal->height_) {
1028 "Attribute texture maps must have same dimensions");
1038 auto image = std::make_shared<geometry::Image>();
1040 auto data =
reinterpret_cast<uint8_t*
>(
image->data_.data());
1042 auto set_pixel = [&data](std::shared_ptr<geometry::Image> map,
int i,
1044 if (map && map->HasData()) {
1045 *data++ = *(map->PointerAt<uint8_t>(j, i, 0));
1051 for (
int i = 0; i <
width; ++i) {
1052 for (
int j = 0; j <
height; ++j) {
1053 set_pixel(ao, i, j);
1054 set_pixel(rough, i, j);
1055 set_pixel(metal, i, j);
1063 std::shared_ptr<geometry::Image> rough_metal) {
1064 int width = rough_metal->width_;
1065 int height = rough_metal->height_;
1067 if (ao && ao->HasData()) {
1068 if (
width != ao->width_ ||
height != ao->height_) {
1070 "Attribute texture maps must have same dimensions");
1075 auto data =
reinterpret_cast<uint8_t*
>(rough_metal->data_.data());
1077 auto stride = rough_metal->num_of_channels_;
1078 for (
int i = 0; i <
width; ++i) {
1079 for (
int j = 0; j <
height; ++j) {
1080 if (ao && ao->HasData()) {
1081 *data = *(ao->PointerAt<uint8_t>(j, i, 0));
1090 void FilamentScene::UpdateMaterialProperties(RenderableGeometry& geom) {
1091 auto& props = geom.mat.properties;
1092 auto& maps = geom.mat.maps;
1095 auto is_map_valid = [](std::shared_ptr<geometry::Image> map) ->
bool {
1096 return map && map->HasData();
1098 if (is_map_valid(props.albedo_img)) {
1101 if (is_map_valid(props.normal_img)) {
1104 if (is_map_valid(props.reflectance_img)) {
1107 if (is_map_valid(props.clearcoat_img)) {
1110 if (is_map_valid(props.clearcoat_roughness_img)) {
1111 maps.clear_coat_roughness_map =
1114 if (is_map_valid(props.anisotropy_img)) {
1117 if (props.shader ==
"unlitGradient") {
1118 maps.gradient_texture = props.gradient->GetTextureHandle(
renderer_);
1122 if (is_map_valid(props.ao_rough_metal_img)) {
1124 maps.ao_rough_metal_map =
1126 }
else if (is_map_valid(props.ao_img) ||
1127 is_map_valid(props.roughness_img) ||
1128 is_map_valid(props.metallic_img)) {
1130 props.ao_img, props.roughness_img, props.metallic_img);
1131 maps.ao_rough_metal_map =
1137 if (props.shader ==
"defaultLit" ||
1138 props.shader ==
"defaultLitTransparency") {
1139 UpdateDefaultLit(geom.mat);
1140 }
else if (props.shader ==
"defaultLitSSR") {
1141 UpdateDefaultLitSSR(geom.mat);
1142 }
else if (props.shader ==
"defaultUnlit" ||
1143 props.shader ==
"defaultUnlitTransparency") {
1144 UpdateDefaultUnlit(geom.mat);
1145 }
else if (props.shader ==
"normals") {
1146 UpdateNormalShader(geom.mat);
1147 }
else if (props.shader ==
"depth") {
1148 UpdateDepthShader(geom.mat);
1149 }
else if (props.shader ==
"depthValue") {
1150 UpdateDepthValueShader(geom.mat);
1151 }
else if (props.shader ==
"unlitGradient") {
1152 UpdateGradientShader(geom.mat);
1153 }
else if (props.shader ==
"unlitSolidColor") {
1154 UpdateSolidColorShader(geom.mat);
1155 }
else if (props.shader ==
"unlitBackground") {
1156 UpdateBackgroundShader(geom.mat);
1157 }
else if (props.shader ==
"infiniteGroundPlane") {
1158 UpdateGroundPlaneShader(geom.mat);
1159 }
else if (props.shader ==
"unlitLine") {
1160 UpdateLineShader(geom.mat);
1161 }
else if (props.shader ==
"unlitPolygonOffset") {
1162 UpdateUnlitPolygonOffsetShader(geom.mat);
1163 }
else if (props.shader ==
"gaussianSplat") {
1164 UpdateGaussianSplat(geom.mat);
1170 void FilamentScene::OverrideMaterialInternal(RenderableGeometry* geom,
1171 const MaterialRecord& material,
1174 if (geom->mat.properties.shader != material.shader) {
1176 auto shader = defaults_mapping::shader_mappings[material.shader];
1177 if (!shader) shader = defaults_mapping::kColorOnlyMesh;
1178 auto old_mi = geom->mat.mat_instance;
1181 if (!wmat_instance.expired()) {
1182 auto& renderable_mgr = engine_.getRenderableManager();
1183 filament::RenderableManager::Instance inst =
1184 renderable_mgr.getInstance(geom->filament_entity);
1185 renderable_mgr.setMaterialInstanceAt(inst, 0,
1186 wmat_instance.lock().get());
1188 geom->mat.mat_instance = new_mi;
1189 resource_mgr_.
Destroy(old_mi);
1191 geom->mat.properties = material;
1193 if (material.shader ==
"defaultLit" ||
1194 material.shader ==
"defaultLitTransparency") {
1195 UpdateDefaultLit(geom->mat);
1196 }
else if (material.shader ==
"defaultLitSSR") {
1197 UpdateDefaultLitSSR(geom->mat);
1198 }
else if (material.shader ==
"defaultUnlit" ||
1199 material.shader ==
"defaultUnlitTransparency") {
1200 UpdateDefaultUnlit(geom->mat);
1201 }
else if (material.shader ==
"normals") {
1202 UpdateNormalShader(geom->mat);
1203 }
else if (material.shader ==
"unlitGradient") {
1204 UpdateGradientShader(geom->mat);
1205 }
else if (material.shader ==
"unlitColorMap") {
1206 UpdateGradientShader(geom->mat);
1207 }
else if (material.shader ==
"unlitSolidColor") {
1208 UpdateSolidColorShader(geom->mat);
1209 }
else if (material.shader ==
"unlitBackground") {
1210 UpdateBackgroundShader(geom->mat);
1211 }
else if (material.shader ==
"infiniteGroundPlane") {
1212 UpdateGroundPlaneShader(geom->mat);
1213 }
else if (material.shader ==
"unlitLine") {
1214 UpdateLineShader(geom->mat);
1215 }
else if (material.shader ==
"unlitPolygonOffset") {
1216 UpdateUnlitPolygonOffsetShader(geom->mat);
1217 }
else if (material.shader ==
"depthValue") {
1218 UpdateDepthValueShader(geom->mat);
1220 UpdateDepthShader(geom->mat);
1223 UpdateMaterialProperties(*geom);
1229 auto geoms = GetGeometry(object_name);
1230 for (
auto* g : geoms) {
1231 OverrideMaterialInternal(g, material);
1236 for (
const auto& ge : geometries_) {
1237 geometry.push_back(ge.first);
1243 for (
auto& ge : geometries_) {
1244 if (ge.first == kBackgroundName) {
1247 OverrideMaterialInternal(&ge.second, material, shader_only);
1252 const Eigen::Vector3f&
color,
1256 bool cast_shadows) {
1257 if (lights_.count(light_name) > 0) {
1259 "Cannot add point light because {} has already been added",
1264 filament::LightManager::Type light_type =
1265 filament::LightManager::Type::POINT;
1266 auto light = utils::EntityManager::get().create();
1267 auto result = filament::LightManager::Builder(light_type)
1269 .intensity(intensity)
1271 .castShadows(cast_shadows)
1273 .build(engine_,
light);
1275 if (
result == filament::LightManager::Builder::Success) {
1277 scene_->addEntity(
light);
1288 const Eigen::Vector3f&
color,
1290 const Eigen::Vector3f& direction,
1293 float inner_cone_angle,
1294 float outer_cone_angle,
1295 bool cast_shadows) {
1296 if (lights_.count(light_name) > 0) {
1298 "Cannot add point light because {} has already been added",
1303 filament::LightManager::Type light_type =
1304 filament::LightManager::Type::SPOT;
1305 auto light = utils::EntityManager::get().create();
1307 filament::LightManager::Builder(light_type)
1308 .direction({direction.x(), direction.y(), direction.z()})
1310 .intensity(intensity)
1312 .castShadows(cast_shadows)
1314 .spotLightCone(inner_cone_angle, outer_cone_angle)
1315 .build(engine_,
light);
1317 if (
result == filament::LightManager::Builder::Success) {
1319 scene_->addEntity(
light);
1330 const Eigen::Vector3f&
color,
1331 const Eigen::Vector3f& direction,
1333 bool cast_shadows) {
1334 if (lights_.count(light_name) > 0) {
1336 "Cannot add point light because {} has already been added",
1341 filament::LightManager::Type light_type =
1342 filament::LightManager::Type::DIRECTIONAL;
1343 auto light = utils::EntityManager::get().create();
1345 filament::LightManager::Builder(light_type)
1346 .castShadows(cast_shadows)
1347 .direction({direction.x(), direction.y(), direction.z()})
1349 .intensity(intensity)
1350 .build(engine_,
light);
1352 if (
result == filament::LightManager::Builder::Success) {
1354 scene_->addEntity(
light);
1376 auto light = GetLightInternal(light_name);
1378 scene_->remove(
light->filament_entity);
1379 engine_.destroy(
light->filament_entity);
1380 lights_.erase(light_name);
1385 const Eigen::Vector3f&
color) {
1386 auto light = GetLightInternal(light_name);
1388 auto& light_mgr = engine_.getLightManager();
1389 filament::LightManager::Instance inst =
1390 light_mgr.getInstance(
light->filament_entity);
1397 auto light = GetLightInternal(light_name);
1399 auto& light_mgr = engine_.getLightManager();
1400 filament::LightManager::Instance inst =
1401 light_mgr.getInstance(
light->filament_entity);
1402 if (!light_mgr.isDirectional(inst)) {
1403 light_mgr.setPosition(inst,
1410 const Eigen::Vector3f& direction) {
1411 auto light = GetLightInternal(light_name);
1413 auto& light_mgr = engine_.getLightManager();
1414 filament::LightManager::Instance inst =
1415 light_mgr.getInstance(
light->filament_entity);
1416 light_mgr.setDirection(inst,
1417 {direction.x(), direction.y(), direction.z()});
1423 auto light = GetLightInternal(light_name);
1425 auto& light_mgr = engine_.getLightManager();
1426 filament::LightManager::Instance inst =
1427 light_mgr.getInstance(
light->filament_entity);
1428 light_mgr.setIntensity(inst, intensity);
1434 auto light = GetLightInternal(light_name);
1436 auto& light_mgr = engine_.getLightManager();
1437 filament::LightManager::Instance inst =
1438 light_mgr.getInstance(
light->filament_entity);
1439 light_mgr.setFalloff(inst, falloff);
1444 float inner_cone_angle,
1445 float outer_cone_angle) {
1450 bool cast_shadows) {
1451 auto light = GetLightInternal(light_name);
1453 auto& light_mgr = engine_.getLightManager();
1454 filament::LightManager::Instance inst =
1455 light_mgr.getInstance(
light->filament_entity);
1456 light_mgr.setShadowCaster(inst, cast_shadows);
1460 void FilamentScene::CreateSunDirectionalLight() {
1461 filament::LightManager::Type light_type = filament::LightManager::Type::SUN;
1462 auto light = utils::EntityManager::get().create();
1463 auto result = filament::LightManager::Builder(light_type)
1464 .direction({0.f, 0.f, 1.f})
1465 .intensity(10000.0f)
1468 .color({1.f, 1.f, 1.f})
1469 .build(engine_,
light);
1471 if (
result == filament::LightManager::Builder::Success) {
1472 sun_.filament_entity =
light;
1473 scene_->addEntity(sun_.filament_entity);
1476 "Failed to build Filament light resources for sun light");
1481 const Eigen::Vector3f&
color,
1483 auto& light_mgr = engine_.getLightManager();
1484 filament::LightManager::Instance inst =
1485 light_mgr.getInstance(sun_.filament_entity);
1486 light_mgr.setDirection(inst, {direction.x(), direction.y(), direction.z()});
1488 light_mgr.setIntensity(inst, intensity);
1492 if (sun_.enabled != enable) {
1493 sun_.enabled = enable;
1495 scene_->addEntity(sun_.filament_entity);
1497 scene_->remove(sun_.filament_entity);
1503 auto& light_mgr = engine_.getLightManager();
1504 filament::LightManager::Instance inst =
1505 light_mgr.getInstance(sun_.filament_entity);
1506 return light_mgr.setShadowCaster(inst, enable);
1510 auto& light_mgr = engine_.getLightManager();
1511 filament::LightManager::Instance inst =
1512 light_mgr.getInstance(sun_.filament_entity);
1513 light_mgr.setIntensity(inst, intensity);
1517 auto& light_mgr = engine_.getLightManager();
1518 filament::LightManager::Instance inst =
1519 light_mgr.getInstance(sun_.filament_entity);
1520 return light_mgr.getIntensity(inst);
1524 auto& light_mgr = engine_.getLightManager();
1525 filament::LightManager::Instance inst =
1526 light_mgr.getInstance(sun_.filament_entity);
1531 auto& light_mgr = engine_.getLightManager();
1532 filament::LightManager::Instance inst =
1533 light_mgr.getInstance(sun_.filament_entity);
1534 auto dir = light_mgr.getColor(inst);
1535 return {dir[0], dir[1], dir[2]};
1539 auto& light_mgr = engine_.getLightManager();
1540 filament::LightManager::Instance inst =
1541 light_mgr.getInstance(sun_.filament_entity);
1542 light_mgr.setDirection(inst, {direction.x(), direction.y(), direction.z()});
1546 auto& light_mgr = engine_.getLightManager();
1547 filament::LightManager::Instance inst =
1548 light_mgr.getInstance(sun_.filament_entity);
1549 light_mgr.setSunAngularRadius(inst, radius);
1553 auto& light_mgr = engine_.getLightManager();
1554 filament::LightManager::Instance inst =
1555 light_mgr.getInstance(sun_.filament_entity);
1556 light_mgr.setSunHaloSize(inst,
size);
1560 auto& light_mgr = engine_.getLightManager();
1561 filament::LightManager::Instance inst =
1562 light_mgr.getInstance(sun_.filament_entity);
1563 light_mgr.setSunHaloFalloff(inst, falloff);
1567 auto& light_mgr = engine_.getLightManager();
1568 filament::LightManager::Instance inst =
1569 light_mgr.getInstance(sun_.filament_entity);
1570 auto dir = light_mgr.getDirection(inst);
1571 return {dir[0], dir[1], dir[2]};
1575 auto old_ibl = ibl_handle_;
1576 auto old_sky = skybox_handle_;
1579 std::string ibl_path = ibl_name + std::string(
"_ibl.ktx");
1587 if (
auto light = wlight.lock()) {
1588 indirect_light_ = wlight;
1589 if (ibl_enabled_) scene_->setIndirectLight(
light.get());
1590 ibl_name_ = ibl_name;
1591 ibl_handle_ = new_ibl;
1593 resource_mgr_.
Destroy(old_ibl);
1598 std::string skybox_path = ibl_name + std::string(
"_skybox.ktx");
1601 auto wskybox = resource_mgr_.
GetSkybox(sky);
1602 if (
auto skybox = wskybox.lock()) {
1604 if (skybox_enabled_) {
1605 scene_->setSkybox(skybox.get());
1608 skybox_handle_ = sky;
1610 resource_mgr_.
Destroy(old_sky);
1620 if (enable != ibl_enabled_) {
1622 if (
auto light = indirect_light_.lock()) {
1623 scene_->setIndirectLight(
light.get());
1626 scene_->setIndirectLight(
nullptr);
1628 ibl_enabled_ = enable;
1633 if (
auto light = indirect_light_.lock()) {
1634 light->setIntensity(intensity);
1639 if (
auto light = indirect_light_.lock()) {
1640 return light->getIntensity();
1646 if (
auto light = indirect_light_.lock()) {
1647 auto ft = converters::FilamentMatrixFromEigenMatrix(rotation.matrix());
1648 light->setRotation(ft.upperLeft());
1653 if (
auto light = indirect_light_.lock()) {
1654 converters::FilamentMatrix ft(
light->getRotation());
1655 auto et = converters::EigenMatrixFromFilamentMatrix(ft);
1663 if (show != skybox_enabled_) {
1665 if (
auto skybox = skybox_.lock()) {
1666 scene_->setSkybox(skybox.get());
1669 scene_->setSkybox(
nullptr);
1672 skybox_enabled_ = show;
1677 return (scene_->getSkybox() !=
nullptr);
1680 void FilamentScene::CreateBackgroundGeometry() {
1683 quad.CreateInternalCloud();
1698 m.shader =
"unlitBackground";
1699 m.base_color = {1.f, 1.f, 1.f, 1.f};
1700 m.aspect_ratio = 0.0;
1715 const Eigen::Vector4f&
color,
1716 const std::shared_ptr<geometry::Image>
image) {
1718 CreateBackgroundGeometry();
1720 std::shared_ptr<geometry::Image> new_image;
1726 m.
shader =
"unlitBackground";
1730 m.
aspect_ratio =
static_cast<float>(new_image->width_) /
1731 static_cast<float>(new_image->height_);
1735 if (new_image && background_image_) {
1736 auto geom_it = geometries_.find(kBackgroundName);
1737 if (geom_it != geometries_.end()) {
1741 geom_it->second.mat.maps.albedo_map, new_image,
1751 auto geom_it = geometries_.find(kBackgroundName);
1752 if (geom_it != geometries_.end()) {
1753 if (geom_it->second.mat.maps.albedo_map) {
1754 resource_mgr_.
Destroy(geom_it->second.mat.maps.albedo_map);
1755 geom_it->second.mat.maps.albedo_map =
1760 background_image_ = new_image;
1764 CreateBackgroundGeometry();
1765 auto geoms = GetGeometry(kBackgroundName);
1766 auto geom_mi = geoms[0]->mat;
1769 auto tex = tex_weak.lock();
1772 aspect =
static_cast<float>(tex->getWidth()) /
1773 static_cast<float>(tex->getHeight());
1784 void FilamentScene::CreateGroundPlaneGeometry() {
1786 quad.CreateInternalCloud();
1797 m.
shader =
"infiniteGroundPlane";
1807 CreateGroundPlaneGeometry();
1811 m.
shader =
"infiniteGroundPlane";
1826 CreateGroundPlaneGeometry();
1833 bool frame_done =
false;
1841 if (buffer_size > 0) {
1842 rr->image->data_ = std::vector<uint8_t>((uint8_t*)buffer,
1843 (uint8_t*)buffer + buffer_size);
1846 "0 buffer size encountered while rendering to image");
1851 std::function<
void(std::shared_ptr<geometry::Image>)>
callback) {
1852 auto view = views_.begin()->second.view.get();
1857 std::function<
void(std::shared_ptr<geometry::Image>)>
callback) {
1858 auto view = views_.begin()->second.view.get();
1862 std::vector<FilamentScene::RenderableGeometry*> FilamentScene::GetGeometry(
1863 const std::string& object_name,
bool warn_if_not_found) {
1864 std::vector<RenderableGeometry*> geoms;
1865 if (GeometryIsModel(object_name)) {
1866 for (
const auto&
name : model_geometries_[object_name]) {
1867 auto geom_entry = geometries_.find(
name);
1868 if (geom_entry == geometries_.end()) {
1869 if (warn_if_not_found) {
1874 geoms.push_back(&geom_entry->second);
1878 auto geom_entry = geometries_.find(object_name);
1879 if (geom_entry == geometries_.end()) {
1880 if (warn_if_not_found) {
1885 geoms.push_back(&geom_entry->second);
1892 bool FilamentScene::GeometryIsModel(
const std::string& object_name)
const {
1893 return model_geometries_.count(object_name) > 0;
1896 FilamentScene::LightEntity* FilamentScene::GetLightInternal(
1897 const std::string& light_name,
bool warn_if_not_found) {
1898 auto light_entry = lights_.find(light_name);
1899 if (light_entry == lights_.end()) {
1900 if (warn_if_not_found) {
1906 return &(light_entry->second);
1909 void FilamentScene::RenderableGeometry::ReleaseResources(
1910 filament::Engine& engine, FilamentResourceManager& manager) {
1911 if (
vb) manager.Destroy(
vb);
1912 if (
ib) manager.Destroy(
ib);
1913 engine.destroy(filament_entity);
1919 manager.Destroy(map);
1921 destroy_map(mat.maps.albedo_map);
1922 destroy_map(mat.maps.normal_map);
1923 destroy_map(mat.maps.ao_rough_metal_map);
1924 destroy_map(mat.maps.reflectance_map);
1925 destroy_map(mat.maps.clear_coat_map);
1926 destroy_map(mat.maps.clear_coat_roughness_map);
1927 destroy_map(mat.maps.anisotropy_map);
1929 manager.Destroy(mat.mat_instance);
1931 filament_entity.clear();
1935 for (
auto& pair : views_) {
1936 auto& container = pair.second;
1938 if (!container.is_active)
continue;
1939 if (container.render_count-- == 0) {
1940 container.is_active =
false;
1944 container.view->PreRender();
1945 renderer.render(container.view->GetNativeView());
1946 container.view->PostRender();
1951 for (
auto geom : geometries_) {
1952 if (geom.second.mat.properties.shader ==
"defaultLitSSR") {
1954 if (!geom.second.visible) {
1955 geom.second.was_hidden_before_picking =
true;
1960 if (!geom.second.was_hidden_before_picking) {
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
std::shared_ptr< core::Tensor > image
std::function< void(std::shared_ptr< core::Tensor >)> callback
std::vector< UVAtlasVertex > vb
std::vector< uint8_t > ib
Hierarchical CLOUDVIEWER Object.
virtual bool IsEmpty() const
CV_CLASS_ENUM getClassID() const override
Returns class ID.
void addEigenVertices(const std::vector< Eigen::Vector3d > &vertices)
void addTriangles(const std::vector< Eigen::Vector3i > &triangles)
bool reserve(std::size_t n)
Reserves the memory to store the vertex indexes (3 per triangle)
Mix-in class for geometry types that can be visualized.
virtual bool IsEmpty() const =0
Returns true iff the geometry is empty.
A point cloud contains a list of 3D points.
core::Tensor & GetPointNormals()
Get the value of the "normals" attribute. Convenience function.
bool HasPointAttr(const std::string &key) const
core::Tensor & GetPoints()
PointCloud CPU() const
Backward-compatible convenience method to obtain a CPU-resident copy.
bool HasPointNormals() const
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
core::Tensor & GetPointColors()
Get the value of the "colors" attribute. Convenience function.
bool HasPointColors() const
std::weak_ptr< filament::IndexBuffer > GetIndexBuffer(const IndexBufferHandle &id)
void Destroy(const REHandle_abstract &id)
std::weak_ptr< filament::IndirectLight > GetIndirectLight(const IndirectLightHandle &id)
bool UpdateTexture(TextureHandle texture, const std::shared_ptr< geometry::Image > image, bool srgb)
std::weak_ptr< filament::Texture > GetTexture(const TextureHandle &id)
std::weak_ptr< filament::Skybox > GetSkybox(const SkyboxHandle &id)
static const TextureHandle kDefaultNormalMap
void ReuseVertexBuffer(VertexBufferHandle vb)
std::weak_ptr< filament::VertexBuffer > GetVertexBuffer(const VertexBufferHandle &id)
std::weak_ptr< filament::MaterialInstance > GetMaterialInstance(const MaterialInstanceHandle &id)
MaterialInstanceHandle CreateMaterialInstance(const MaterialHandle &id)
static const TextureHandle kDefaultTexture
void HideRefractedMaterials(bool hide=true)
const std::string & GetIndirectLight() override
bool AddDirectionalLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &direction, float intensity, bool cast_shadows) override
void EnableSunLight(bool enable) override
bool AddSpotLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &position, const Eigen::Vector3f &direction, float intensity, float falloff, float inner_cone_angle, float outer_cone_angle, bool cast_shadows) override
void SetIndirectLightIntensity(float intensity) override
Transform GetGeometryTransform(const std::string &object_name) override
void SetSunLightIntensity(float intensity) override
View * GetView(const ViewHandle &view_id) const override
void EnableGroundPlane(bool enable, GroundPlane plane) override
ViewHandle AddView(std::int32_t x, std::int32_t y, std::uint32_t w, std::uint32_t h) override
void OverrideMaterial(const std::string &object_name, const MaterialRecord &material) override
void SetRenderOnce(const ViewHandle &view_id) override
void RemoveGeometry(const std::string &object_name) override
void SetSunHaloFalloff(float falloff) override
void UpdateGeometry(const std::string &object_name, const t::geometry::PointCloud &point_cloud, uint32_t update_flags) override
void SetSunHaloSize(float size) override
void SetSunLight(const Eigen::Vector3f &direction, const Eigen::Vector3f &color, float intensity) override
void UpdateLightPosition(const std::string &light_name, const Eigen::Vector3f &position) override
bool GeometryIsVisible(const std::string &object_name) override
void RemoveCamera(const std::string &camera_name) override
void EnableLightShadow(const std::string &light_name, bool cast_shadows) override
bool HasGeometry(const std::string &object_name) const override
void EnableIndirectLight(bool enable) override
void UpdateLight(const std::string &light_name, const Light &light) override
void SetActiveCamera(const std::string &camera_name) override
void SetSunLightColor(const Eigen::Vector3f &color) override
float GetIndirectLightIntensity() override
void SetBackground(const Eigen::Vector4f &color, const std::shared_ptr< geometry::Image > image=nullptr) override
float GetSunLightIntensity() override
Transform GetIndirectLightRotation() override
void AddCamera(const std::string &camera_name, std::shared_ptr< Camera > cam) override
void SetGeometryPriority(const std::string &object_name, uint8_t priority) override
void RenderToDepthImage(std::function< void(std::shared_ptr< geometry::Image >)> callback) override
Size of image is the size of the window.
Light & GetLight(const std::string &light_name) override
ccBBox GetGeometryBoundingBox(const std::string &object_name) override
void UpdateLightConeAngles(const std::string &light_name, float inner_cone_angle, float outer_cone_angle) override
void SetGroundPlaneColor(const Eigen::Vector4f &color) override
bool GetSkyboxVisible() const override
void SetGeometryTransform(const std::string &object_name, const Transform &transform) override
void GeometryShadows(const std::string &object_name, bool cast_shadows, bool receive_shadows) override
void UpdateLightColor(const std::string &light_name, const Eigen::Vector3f &color) override
void UpdateLightIntensity(const std::string &light_name, float intensity) override
void SetSunAngularRadius(float radius) override
bool SetIndirectLight(const std::string &ibl_name) override
void QueryGeometry(std::vector< std::string > &geometry) override
void EnableSunLightShadows(bool enable) override
Eigen::Vector3f GetSunLightColor() override
void OverrideMaterialAll(const MaterialRecord &material, bool shader_only=true) override
FilamentScene(filament::Engine &engine, FilamentResourceManager &resource_mgr, Renderer &renderer)
void ShowGeometry(const std::string &object_name, bool show) override
void RemoveLight(const std::string &light_name) override
void SetGeometryCulling(const std::string &object_name, bool enable) override
void RemoveView(const ViewHandle &view_id) override
void SetViewActive(const ViewHandle &view_id, bool is_active) override
bool AddGeometry(const std::string &object_name, const ccHObject &geometry, const MaterialRecord &material, const std::string &downsampled_name="", size_t downsample_threshold=SIZE_MAX) override
void UpdateLightDirection(const std::string &light_name, const Eigen::Vector3f &direction) override
void RenderToImage(std::function< void(std::shared_ptr< geometry::Image >)> callback) override
Size of image is the size of the window.
void SetIndirectLightRotation(const Transform &rotation) override
void UpdateLightFalloff(const std::string &light_name, float falloff) override
Eigen::Vector3f GetSunLightDirection() override
void ShowSkybox(bool show) override
void SetSunLightDirection(const Eigen::Vector3f &direction) override
bool AddPointLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &position, float intensity, float falloff, bool cast_shadows) override
void Draw(filament::Renderer &renderer)
static constexpr std::uint8_t kAllLayersMask
static constexpr std::uint8_t kMainLayer
virtual filament::RenderableManager::PrimitiveType GetPrimitiveType() const =0
static std::unique_ptr< GeometryBuffersBuilder > GetBuilder(const ccHObject &geometry)
@ kLUT
Normal gradient mode.
virtual MaterialModifier & SetParameter(const char *parameter, int value)=0
virtual MaterialInstanceHandle Finish()=0
virtual MaterialModifier & SetColor(const char *parameter, const Eigen::Vector3f &value, bool srgb)=0
virtual MaterialModifier & SetTexture(const char *parameter, const TextureHandle &texture, const TextureSamplerParameters &sampler)=0
virtual MaterialModifier & ModifyMaterial(const MaterialHandle &id)=0
virtual IndirectLightHandle AddIndirectLight(const ResourceLoadRequest &request)=0
void RenderToImage(View *view, Scene *scene, std::function< void(std::shared_ptr< geometry::Image >)> cb)
virtual TextureHandle AddTexture(const ResourceLoadRequest &request, bool srgb=false)=0
virtual SkyboxHandle AddSkybox(const ResourceLoadRequest &request)=0
void RenderToDepthImage(View *view, Scene *scene, std::function< void(std::shared_ptr< geometry::Image >)> cb, bool z_in_view_space=false)
Eigen::Transform< float, 3, Eigen::Affine > Transform
static const uint32_t kUpdateNormalsFlag
static const uint32_t kUpdatePointsFlag
static const uint32_t kUpdateColorsFlag
static const uint32_t kUpdateUv0Flag
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
void OutputMaterialProperties(const visualization::rendering::MaterialRecord &mat)
void ReadPixelsCallback(void *buffer, size_t buffer_size, void *user)
REHandle< EntityType::Material > MaterialHandle
std::shared_ptr< geometry::Image > CombineTextures(std::shared_ptr< geometry::Image > ao, std::shared_ptr< geometry::Image > rough, std::shared_ptr< geometry::Image > metal)
Generic file read and write utility for python interface.
constexpr Rgbaf light(0.66f, 0.66f, 0.66f, 1.00f)
std::string to_string(const T &n)
Eigen::Vector3f absorption_color
std::shared_ptr< geometry::Image > albedo_img
float base_clearcoat_roughness
float absorption_distance
Eigen::Vector4f base_color
std::shared_ptr< geometry::Image > image
static TextureSamplerParameters LinearClamp()
static TextureSamplerParameters Simple()
static TextureSamplerParameters Pretty()
std::vector< MeshInfo > meshes_
std::vector< visualization::rendering::MaterialRecord > materials_