1#include <Engine/Scene/GeometryComponent.hpp>
5#include <Core/Asset/GeometryData.hpp>
6#include <Core/Containers/MakeShared.hpp>
7#include <Core/Utils/Color.hpp>
8#include <Core/Utils/Log.hpp>
10#include <Engine/Data/BlinnPhongMaterial.hpp>
11#include <Engine/Data/Material.hpp>
12#include <Engine/Data/MaterialConverters.hpp>
13#include <Engine/Data/Mesh.hpp>
14#include <Engine/Data/VolumeObject.hpp>
15#include <Engine/Data/VolumetricMaterial.hpp>
16#include <Engine/Rendering/RenderObject.hpp>
17#include <Engine/Rendering/RenderObjectManager.hpp>
18#include <Engine/Rendering/RenderObjectTypes.hpp>
19#include <Engine/Rendering/RenderTechnique.hpp>
20#include <Engine/Scene/ComponentMessenger.hpp>
22#define CHECK_MESH_NOT_NULL \
23 CORE_ASSERT( m_displayMesh != nullptr, "DisplayMesh should exist while component is alive" );
26using namespace Ra::Core::Utils;
32void GeometryComponent::setupIO(
const std::string&
id ) {
33 const auto& cm = ComponentMessenger::getInstance();
34 auto roOut =
std::bind( &GeometryComponent::roIndexRead,
this );
35 cm->registerOutput<Index>(
getEntity(),
this, id, roOut );
38const Index* GeometryComponent::roIndexRead()
const {
46PointCloudComponent::PointCloudComponent(
const std::string& name,
49 GeometryComponent( name, entity ), m_displayMesh( nullptr ) {
50 generatePointCloud( data );
53PointCloudComponent::PointCloudComponent(
const std::string& name,
55 Core::Geometry::PointCloud&& mesh,
58 m_displayMesh( new Data::PointCloud( name,
std::move( mesh ) ) ) {
59 finalizeROFromGeometry( mat, Core::Transform::Identity() );
70 m_contentName = data->
getName();
72 m_displayMesh->setRenderMode( Data::AttribArrayDisplayable::RM_POINTS );
74 Ra::Core::Geometry::PointCloud mesh;
79 m_displayMesh->loadGeometry(
std::move( mesh ) );
86 Core::Transform transform ) {
90 if ( data !=
nullptr ) {
92 auto mat = converter.second( data );
93 roMaterial.
reset( mat );
97 mat->setRenderAsSplat( m_displayMesh->getNumFaces() == 0 );
98 mat->setColoredByVertexAttrib( m_displayMesh->getCoreGeometry().hasAttrib(
99 Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::VERTEX_COLOR ) ) );
100 roMaterial.
reset( mat );
103 std::string roName( m_name +
"_" + m_contentName +
"_RO" );
109 ro->setTransparent( roMaterial->isTransparent() );
110 ro->setMaterial( roMaterial );
111 setupIO( m_contentName );
112 ro->setLocalTransform( transform );
118 return m_displayMesh->getCoreGeometry();
123 return m_displayMesh.get();
126void PointCloudComponent::setupIO(
const std::string&
id ) {
128 auto cbOut =
std::bind( &PointCloudComponent::getMeshOutput,
this );
129 auto cbRw =
std::bind( &PointCloudComponent::getPointCloudRw,
this );
131 const auto& cm = ComponentMessenger::getInstance();
133 cm->registerOutput<Ra::Core::Geometry::PointCloud>(
getEntity(),
this, id, cbOut );
134 cm->registerReadWrite<Ra::Core::Geometry::PointCloud>(
getEntity(),
this, id, cbRw );
138const Ra::Core::Geometry::PointCloud* PointCloudComponent::getMeshOutput()
const {
140 return &m_displayMesh->getCoreGeometry();
143Ra::Core::Geometry::PointCloud* PointCloudComponent::getPointCloudRw() {
145 return &( m_displayMesh->getCoreGeometry() );
151VolumeComponent::VolumeComponent(
const std::string& name,
154 Component( name, entity ), m_displayVolume { nullptr } {
155 generateVolumeRender( data );
158VolumeComponent::~VolumeComponent() =
default;
163 m_contentName = data->
getName();
169 roMaterial->setTexture(
const_cast<Data::Texture*
>( &( m_displayVolume->getDataTexture() ) ) );
170 roMaterial->m_sigma_a = data->
sigma_a;
171 roMaterial->m_sigma_s = data->
sigma_s;
174 std::string roName( m_name +
"_" + m_contentName +
"_RO" );
180 ro->setTransparent( roMaterial->isTransparent() );
181 ro->setMaterial( roMaterial );
184 setupIO( m_contentName );
188#define CHECK_VOL_NOT_NULL \
189 CORE_ASSERT( m_displayVolume != nullptr, \
190 "DisplayVolume should exist while component is alive" );
194 return m_displayVolume.get();
199 return m_volumeIndex;
202void VolumeComponent::setContentName(
const std::string& name ) {
203 this->m_contentName = name;
206void VolumeComponent::setupIO(
const std::string&
id ) {
209 const auto& cm = ComponentMessenger::getInstance();
210 auto cbOut =
std::bind( &VolumeComponent::getVolumeOutput,
this );
211 auto cbRw =
std::bind( &VolumeComponent::getVolumeRw,
this );
212 auto roOut =
std::bind( &VolumeComponent::roIndexRead,
this );
216 cm->registerOutput<Ra::Core::Utils::Index>(
getEntity(),
this, id, roOut );
219const Index* VolumeComponent::roIndexRead()
const {
221 return &m_volumeIndex;
226 return &m_displayVolume->getVolume();
231 return &m_displayVolume->getVolume();
virtual const std::string & getName() const
Acces to the name of the asset.
const MaterialData & getMaterial() const
Return the MaterialData associated to the objet.
Geometry::MultiIndexedGeometry & getGeometry()
Read/write access to the multiIndexedGeometry;.
Transform getFrame() const
Return the Transform of the object.
bool hasMaterial() const
Return true if the object has MaterialData.
represent material data loaded by a file loader. Material data must be identified by a unique name....
std::string getType() const
TYPE.
Utils::AttribManager & vertexAttribs()
void copyAllAttributes(const AttribManager &m)
A PointCloud without indices.
Represent a Texture of the engine.
static RenderObject * createRenderObject(const std::string &name, Scene::Component *comp, const RenderObjectType &type, std::shared_ptr< Data::Displayable > mesh, const RenderTechnique &techniqueConfig=RenderTechnique::createDefaultRenderTechnique())
virtual Entity * getEntity() const
Return the entity the component belongs to.
Core::Utils::Index addRenderObject(Rendering::RenderObject *renderObject)
Add a new render object to the component. This adds the RO to the manager for drawing.
An entity is an scene element. It ties together components with a transform.
Abstract interface of a geometric compoennet in the Engine.
void initialize() override
Pure virtual method to be overridden by any component. When this method is called you are guaranteed ...
const Ra::Core::Geometry::PointCloud & getCoreGeometry() const
Returns the current display geometry.
~PointCloudComponent() override
Ra::Core::Utils::Index getRenderObjectIndex() const
Returns the index of the associated RO (the display volume)
void initialize() override
Pure virtual method to be overridden by any component. When this method is called you are guaranteed ...
std::shared_ptr< T > make_shared(Args &&... args)
std::pair< bool, ConverterFunction > getMaterialConverter(const std::string &name)
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet
Aabb boundingBox
The bounding box of the volume.
Geometry::AbstractVolume * volume
The underlaying density matrix.
Transform modelToWorld
Transformation matrix of the object.
Utils::Color sigma_a
Absortion coefficient of the volume (default is Air)
Utils::Color sigma_s
Scattering coefficient of the volume (default is Air)