20 #pragma warning(disable : 4068 4146 4293 4305)
23 #include <filament/LightManager.h>
24 #include <filament/RenderableManager.h>
25 #include <utils/Entity.h>
31 #include <Eigen/Geometry>
32 #include <unordered_map>
50 class TransformManager;
56 namespace visualization {
60 class GeometryBuffersBuilder;
68 using Transform = Eigen::Transform<float, 3, Eigen::Affine>;
89 void AddCamera(
const std::string& camera_name,
90 std::shared_ptr<Camera> cam)
override;
91 void RemoveCamera(
const std::string& camera_name)
override;
98 const std::string& downsampled_name =
"",
99 size_t downsample_threshold = SIZE_MAX)
override;
103 const std::string& downsampled_name =
"",
104 size_t downsample_threshold = SIZE_MAX)
override;
107 bool HasGeometry(
const std::string& object_name)
const override;
112 void ShowGeometry(
const std::string& object_name,
bool show)
override;
118 const std::string& object_name)
override;
121 bool receive_shadows)
override;
123 bool enable)
override;
125 uint8_t priority)
override;
128 void QueryGeometry(std::vector<std::string>& geometry)
override;
131 bool shader_only =
true)
override;
135 const Eigen::Vector3f&
color,
139 bool cast_shadows)
override;
141 const Eigen::Vector3f&
color,
143 const Eigen::Vector3f& direction,
146 float inner_cone_angle,
147 float outer_cone_angle,
148 bool cast_shadows)
override;
150 const Eigen::Vector3f&
color,
151 const Eigen::Vector3f& direction,
153 bool cast_shadows)
override;
155 void RemoveLight(
const std::string& light_name)
override;
157 const Light& light)
override;
159 const Eigen::Vector3f&
color)
override;
161 const Eigen::Vector3f&
position)
override;
163 const Eigen::Vector3f& direction)
override;
165 float intensity)
override;
167 float falloff)
override;
169 float inner_cone_angle,
170 float outer_cone_angle)
override;
172 bool cast_shadows)
override;
175 const Eigen::Vector3f&
color,
176 float intensity)
override;
199 const Eigen::Vector4f&
color,
200 const std::shared_ptr<geometry::Image>
image =
nullptr)
override;
205 void RenderToImage(std::function<
void(std::shared_ptr<geometry::Image>)>
208 std::function<
void(std::shared_ptr<geometry::Image>)>
callback)
211 void Draw(filament::Renderer& renderer);
224 filament::RenderableManager::Builder& builder,
226 enum BufferReuse { kNo, kYes };
227 bool CreateAndAddFilamentEntity(
228 const std::string& object_name,
229 GeometryBuffersBuilder& buffer_builder,
233 const MaterialRecord& material,
234 BufferReuse reusing_vertex_buffer = BufferReuse::kNo);
236 filament::Engine& engine_;
237 FilamentResourceManager& resource_mgr_;
238 filament::Scene* scene_ =
nullptr;
259 struct GeometryMaterialInstance {
261 MaterialRecord properties;
265 struct RenderableGeometry {
268 bool was_hidden_before_picking =
false;
269 bool cast_shadows =
true;
270 bool receive_shadows =
true;
271 bool culling_enabled =
true;
274 GeometryMaterialInstance mat;
277 utils::Entity filament_entity;
278 filament::RenderableManager::PrimitiveType primitive_type;
281 void ReleaseResources(filament::Engine& engine,
282 FilamentResourceManager& manager);
287 utils::Entity filament_entity;
291 struct ViewContainer {
292 std::unique_ptr<FilamentView> view;
293 bool is_active =
true;
294 int render_count = -1;
296 std::unordered_map<REHandle_abstract, ViewContainer> views_;
298 std::vector<RenderableGeometry*> GetGeometry(
const std::string& object_name,
299 bool warn_if_not_found =
true);
300 bool GeometryIsModel(
const std::string& object_name)
const;
301 LightEntity* GetLightInternal(
const std::string& light_name,
302 bool warn_if_not_found =
true);
303 void OverrideMaterialInternal(RenderableGeometry* geom,
304 const MaterialRecord& material,
305 bool shader_only =
false);
306 void UpdateMaterialProperties(RenderableGeometry& geom);
307 void UpdateDefaultLit(GeometryMaterialInstance& geom_mi);
308 void UpdateDefaultLitSSR(GeometryMaterialInstance& geom_mi);
309 void UpdateDefaultUnlit(GeometryMaterialInstance& geom_mi);
310 void UpdateNormalShader(GeometryMaterialInstance& geom_mi);
311 void UpdateDepthShader(GeometryMaterialInstance& geom_mi);
312 void UpdateDepthValueShader(GeometryMaterialInstance& geom_mi);
313 void UpdateGradientShader(GeometryMaterialInstance& geom_mi);
314 void UpdateSolidColorShader(GeometryMaterialInstance& geom_mi);
315 void UpdateBackgroundShader(GeometryMaterialInstance& geom_mi);
316 void UpdateGroundPlaneShader(GeometryMaterialInstance& geom_mi);
317 void UpdateLineShader(GeometryMaterialInstance& geom_mi);
318 void UpdateUnlitPolygonOffsetShader(GeometryMaterialInstance& geom_mi);
319 utils::EntityInstance<filament::TransformManager>
320 GetGeometryTransformInstance(RenderableGeometry* geom);
321 void CreateSunDirectionalLight();
322 void CreateBackgroundGeometry();
323 void CreateGroundPlaneGeometry();
325 std::unordered_map<std::string, RenderableGeometry> geometries_;
326 std::unordered_map<std::string, LightEntity> lights_;
327 std::unordered_map<std::string, std::vector<std::string>> model_geometries_;
329 Eigen::Vector4f background_color_;
330 std::shared_ptr<geometry::Image> background_image_;
331 std::string ibl_name_;
332 bool ibl_enabled_ =
false;
333 bool skybox_enabled_ =
false;
334 std::weak_ptr<filament::IndirectLight> indirect_light_;
335 std::weak_ptr<filament::Skybox> skybox_;
std::shared_ptr< core::Tensor > image
Definition: FilamentRenderer.cpp:183
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:182
math::float4 color
Definition: LineSetBuffers.cpp:45
math::float3 position
Definition: LineSetBuffers.cpp:43
std::vector< UVAtlasVertex > vb
Definition: UVUnwrapping.cpp:27
std::vector< uint8_t > ib
Definition: UVUnwrapping.cpp:29
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:159
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
The base geometry class.
Definition: Geometry.h:21
A point cloud contains a list of 3D points.
Definition: PointCloud.h:80
Definition: FilamentResourceManager.h:50
static const TextureHandle kDefaultNormalMap
Definition: FilamentResourceManager.h:71
static const TextureHandle kDefaultTexture
Definition: FilamentResourceManager.h:69
Definition: FilamentScene.h:66
void UpdateLightDirection(const std::string &light_name, const Eigen::Vector3f &direction) override
Definition: FilamentScene.cpp:1378
Eigen::Vector3f GetSunLightColor() override
Definition: FilamentScene.cpp:1499
void UpdateLightIntensity(const std::string &light_name, float intensity) override
Definition: FilamentScene.cpp:1390
const std::string & GetIndirectLight() override
Definition: FilamentScene.cpp:1586
void EnableIndirectLight(bool enable) override
Definition: FilamentScene.cpp:1588
~FilamentScene()
Definition: FilamentScene.cpp:158
void SetActiveCamera(const std::string &camera_name) override
Definition: FilamentScene.cpp:288
void SetSunLightColor(const Eigen::Vector3f &color) override
Definition: FilamentScene.cpp:1492
void RenderToDepthImage(std::function< void(std::shared_ptr< geometry::Image >)> callback) override
Size of image is the size of the window.
Definition: FilamentScene.cpp:1819
void SetGeometryTransform(const std::string &object_name, const Transform &transform) override
Definition: FilamentScene.cpp:726
Eigen::Vector3f GetSunLightDirection() override
Definition: FilamentScene.cpp:1535
bool AddPointLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &position, float intensity, float falloff, bool cast_shadows) override
Definition: FilamentScene.cpp:1220
void SetSunLightDirection(const Eigen::Vector3f &direction) override
Definition: FilamentScene.cpp:1507
void Draw(filament::Renderer &renderer)
Definition: FilamentScene.cpp:1897
void HideRefractedMaterials(bool hide=true)
Definition: FilamentScene.cpp:1913
void RenderToImage(std::function< void(std::shared_ptr< geometry::Image >)> callback) override
Size of image is the size of the window.
Definition: FilamentScene.cpp:1813
void EnableSunLight(bool enable) override
Definition: FilamentScene.cpp:1460
void SetBackground(const Eigen::Vector4f &color, const std::shared_ptr< geometry::Image > image=nullptr) override
Definition: FilamentScene.cpp:1679
void UpdateLightColor(const std::string &light_name, const Eigen::Vector3f &color) override
Definition: FilamentScene.cpp:1353
Transform GetIndirectLightRotation() override
Definition: FilamentScene.cpp:1621
void EnableLightShadow(const std::string &light_name, bool cast_shadows) override
Definition: FilamentScene.cpp:1418
bool AddDirectionalLight(const std::string &light_name, const Eigen::Vector3f &color, const Eigen::Vector3f &direction, float intensity, bool cast_shadows) override
Definition: FilamentScene.cpp:1298
void SetSunLightIntensity(float intensity) override
Definition: FilamentScene.cpp:1478
geometry::AxisAlignedBoundingBox GetGeometryBoundingBox(const std::string &object_name) override
Definition: FilamentScene.cpp:756
void UpdateLightPosition(const std::string &light_name, const Eigen::Vector3f &position) override
Definition: FilamentScene.cpp:1364
Transform GetGeometryTransform(const std::string &object_name) override
Definition: FilamentScene.cpp:741
void RemoveGeometry(const std::string &object_name) override
Definition: FilamentScene.cpp:671
bool SetIndirectLight(const std::string &ibl_name) override
Definition: FilamentScene.cpp:1543
void SetGroundPlaneColor(const Eigen::Vector4f &color) override
Definition: FilamentScene.cpp:1787
bool GeometryIsVisible(const std::string &object_name) override
Definition: FilamentScene.cpp:700
Light & GetLight(const std::string &light_name) override
Definition: FilamentScene.cpp:1333
void SetIndirectLightIntensity(float intensity) override
Definition: FilamentScene.cpp:1601
ViewHandle AddView(std::int32_t x, std::int32_t y, std::uint32_t w, std::uint32_t h) override
Definition: FilamentScene.cpp:235
void SetSunAngularRadius(float radius) override
Definition: FilamentScene.cpp:1514
float GetSunLightIntensity() override
Definition: FilamentScene.cpp:1485
void UpdateLightFalloff(const std::string &light_name, float falloff) override
Definition: FilamentScene.cpp:1401
void EnableSunLightShadows(bool enable) override
Definition: FilamentScene.cpp:1471
void RemoveView(const ViewHandle &view_id) override
Definition: FilamentScene.cpp:279
bool GetSkyboxVisible() const override
Definition: FilamentScene.cpp:1645
View * GetView(const ViewHandle &view_id) const override
Definition: FilamentScene.cpp:254
void OverrideMaterialAll(const MaterialRecord &material, bool shader_only=true) override
Definition: FilamentScene.cpp:1210
void SetRenderOnce(const ViewHandle &view_id) override
Definition: FilamentScene.cpp:271
Scene * Copy() override
Definition: FilamentScene.cpp:174
void AddCamera(const std::string &camera_name, std::shared_ptr< Camera > cam) override
Definition: FilamentScene.cpp:283
void SetGeometryCulling(const std::string &object_name, bool enable) override
Definition: FilamentScene.cpp:791
void EnableGroundPlane(bool enable, GroundPlane plane) override
Definition: FilamentScene.cpp:1768
void SetSunHaloSize(float size) override
Definition: FilamentScene.cpp:1521
filament::Scene * GetNativeScene() const
Definition: FilamentScene.h:220
void ShowSkybox(bool show) override
Definition: FilamentScene.cpp:1631
FilamentScene(filament::Engine &engine, FilamentResourceManager &resource_mgr, Renderer &renderer)
Definition: FilamentScene.cpp:147
bool AddGeometry(const std::string &object_name, const geometry::Geometry3D &geometry, const MaterialRecord &material, const std::string &downsampled_name="", size_t downsample_threshold=SIZE_MAX) override
Definition: FilamentScene.cpp:305
void UpdateGeometry(const std::string &object_name, const t::geometry::PointCloud &point_cloud, uint32_t update_flags) override
Definition: FilamentScene.cpp:537
void SetGeometryPriority(const std::string &object_name, uint8_t priority) override
Definition: FilamentScene.cpp:803
void SetViewActive(const ViewHandle &view_id, bool is_active) override
Definition: FilamentScene.cpp:263
void ShowGeometry(const std::string &object_name, bool show) override
Definition: FilamentScene.cpp:686
void RemoveLight(const std::string &light_name) override
Definition: FilamentScene.cpp:1344
void SetSunHaloFalloff(float falloff) override
Definition: FilamentScene.cpp:1528
void QueryGeometry(std::vector< std::string > &geometry) override
Definition: FilamentScene.cpp:1204
void SetSunLight(const Eigen::Vector3f &direction, const Eigen::Vector3f &color, float intensity) override
Definition: FilamentScene.cpp:1449
void SetIndirectLightRotation(const Transform &rotation) override
Definition: FilamentScene.cpp:1614
float GetIndirectLightIntensity() override
Definition: FilamentScene.cpp:1607
void GeometryShadows(const std::string &object_name, bool cast_shadows, bool receive_shadows) override
Definition: FilamentScene.cpp:778
Eigen::Transform< float, 3, Eigen::Affine > Transform
Definition: FilamentScene.h:68
void UpdateLightConeAngles(const std::string &light_name, float inner_cone_angle, float outer_cone_angle) override
Definition: FilamentScene.cpp:1412
void RemoveCamera(const std::string &camera_name) override
Definition: FilamentScene.cpp:286
bool HasGeometry(const std::string &object_name) const override
Definition: FilamentScene.cpp:529
void UpdateLight(const std::string &light_name, const Light &light) override
Definition: FilamentScene.cpp:1339
void OverrideMaterial(const std::string &object_name, const MaterialRecord &material) override
Definition: FilamentScene.cpp:1196
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
Definition: FilamentScene.cpp:1256
Definition: Renderer.h:55
GroundPlane
Definition: Scene.h:181
Definition: FilamentEngine.h:12
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition: K4aPlugin.cpp:548
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:395
REHandle< EntityType::IndexBuffer > IndexBufferHandle
Definition: RendererHandle.h:139
REHandle< EntityType::VertexBuffer > VertexBufferHandle
Definition: RendererHandle.h:138
REHandle< EntityType::MaterialInstance > MaterialInstanceHandle
Definition: RendererHandle.h:135
REHandle< EntityType::Skybox > SkyboxHandle
Definition: RendererHandle.h:132
REHandle< EntityType::IndirectLight > IndirectLightHandle
Definition: RendererHandle.h:131
Definition: PinholeCameraIntrinsic.cpp:16
Definition: MaterialRecord.h:22