3 #include <Core/Asset/GeometryData.hpp>
4 #include <Core/Asset/VolumeData.hpp>
5 #include <Core/Containers/MakeShared.hpp>
6 #include <Core/Geometry/TriangleMesh.hpp>
7 #include <Core/Geometry/Volume.hpp>
8 #include <Engine/Data/BlinnPhongMaterial.hpp>
9 #include <Engine/Data/MaterialConverters.hpp>
10 #include <Engine/Data/Mesh.hpp>
11 #include <Engine/Rendering/RenderObject.hpp>
12 #include <Engine/Scene/Component.hpp>
13 #include <Engine/Scene/ComponentMessenger.hpp>
14 #include <Engine/Scene/Entity.hpp>
29 Component( name, entity ), m_contentName( name ) {}
36 virtual void setupIO(
const std::string&
id );
37 void setContentName(
const std::string& name ) { m_contentName = name; }
44 const Ra::Core::Utils::Index* roIndexRead()
const;
48 Ra::Core::Utils::Index m_roIndex {};
49 std::string m_contentName {};
61 template <
typename CoreMeshType>
67 using RenderMeshType =
typename Data::RenderMeshType::getType<CoreMeshType>::Type;
74 std::shared_ptr<RenderMeshType> data );
89 inline RenderMeshType* getDisplayable();
92 inline void setupIO(
const std::string&
id )
override;
93 inline void setDeformable(
bool b );
99 Core::Transform transform );
102 inline const CoreMeshType* getMeshOutput()
const;
103 inline CoreMeshType* getMeshRw();
107 std::shared_ptr<RenderMeshType> m_displayMesh {
nullptr };
132 Core::Geometry::PointCloud&& mesh,
137 void initialize()
override;
140 const Ra::Core::Geometry::PointCloud& getCoreGeometry()
const;
151 void setupIO(
const std::string&
id )
override;
152 void setDeformable(
bool b );
160 const Ra::Core::Geometry::PointCloud* getMeshOutput()
const;
161 Ra::Core::Geometry::PointCloud* getPointCloudRw();
165 std::shared_ptr<Data::PointCloud> m_displayMesh {
nullptr };
167 float m_splatSize { 0.0025f };
186 void initialize()
override;
190 void setupIO(
const std::string&
id );
191 void setContentName(
const std::string& name );
194 Ra::Core::Utils::Index getRenderObjectIndex()
const;
203 const Ra::Core::Utils::Index* roIndexRead()
const;
206 Ra::Core::Utils::Index m_volumeIndex {};
207 std::string m_contentName {};
208 std::shared_ptr<Data::VolumeObject> m_displayVolume {
nullptr };
211 template <
typename CoreMeshType>
213 const std::string& name,
217 generateMesh( data );
220 template <
typename CoreMeshType>
221 SurfaceMeshComponent<CoreMeshType>::SurfaceMeshComponent(
const std::string& name,
223 std::shared_ptr<RenderMeshType> data ) :
224 GeometryComponent( name, entity ), m_displayMesh( data ) {
225 finalizeROFromGeometry(
nullptr, Core::Transform::Identity() );
228 template <
typename CoreMeshType>
234 m_displayMesh( new RenderMeshType( name, std::move( mesh ) ) ) {
235 setContentName( name );
236 finalizeROFromGeometry( mat, Core::Transform::Identity() );
239 template <
typename CoreMeshType>
241 m_contentName = data->
getName();
242 m_displayMesh = Ra::Core::make_shared<RenderMeshType>( m_contentName );
243 CoreMeshType mesh = Data::createCoreMeshFromGeometryData<CoreMeshType>( data );
245 m_displayMesh->loadGeometry( std::move( mesh ) );
251 template <
typename CoreMeshType>
252 void SurfaceMeshComponent<CoreMeshType>::finalizeROFromGeometry(
254 Core::Transform transform ) {
256 std::shared_ptr<Data::Material> roMaterial;
258 if ( data !=
nullptr ) {
260 auto mat = converter.second( data );
261 roMaterial.reset( mat );
265 mat->m_renderAsSplat = m_displayMesh->getNumFaces() == 0;
266 mat->m_perVertexColor = m_displayMesh->getCoreGeometry().hasAttrib(
267 Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::VERTEX_COLOR ) );
268 roMaterial.reset( mat );
271 std::string roName( m_name +
"_" + m_contentName +
"_RO" );
274 Rendering::RenderObjectType::Geometry,
276 Rendering::RenderTechnique {} );
277 ro->setTransparent( roMaterial->isTransparent() );
278 ro->setMaterial( roMaterial );
279 setupIO( m_contentName );
280 ro->setLocalTransform( transform );
281 m_roIndex = addRenderObject( ro );
284 #ifndef CHECK_MESH_NOT_NULL
285 # define CHECK_MESH_NOT_NULL \
286 CORE_ASSERT( m_displayMesh != nullptr, \
287 "DisplayMesh should exist while component is alive" );
288 # define CHECK_MESH_NOT_NULL_UNDEF
291 template <
typename CoreMeshType>
294 return m_displayMesh->getCoreGeometry();
297 template <
typename CoreMeshType>
298 typename SurfaceMeshComponent<CoreMeshType>::RenderMeshType*
301 return m_displayMesh.get();
304 template <
typename CoreMeshType>
305 void SurfaceMeshComponent<CoreMeshType>::setupIO(
const std::string&
id ) {
308 const auto& cm = ComponentMessenger::getInstance();
309 auto cbOut = std::bind( &SurfaceMeshComponent<CoreMeshType>::getMeshOutput,
this );
310 auto cbRw = std::bind( &SurfaceMeshComponent<CoreMeshType>::getMeshRw,
this );
312 cm->registerOutput<CoreMeshType>( getEntity(),
this, id, cbOut );
313 cm->registerReadWrite<CoreMeshType>( getEntity(),
this, id, cbRw );
318 template <
typename CoreMeshType>
319 const CoreMeshType* SurfaceMeshComponent<CoreMeshType>::getMeshOutput()
const {
321 return &m_displayMesh->getCoreGeometry();
324 template <
typename CoreMeshType>
325 CoreMeshType* SurfaceMeshComponent<CoreMeshType>::getMeshRw() {
327 return &( m_displayMesh->getCoreGeometry() );
330 #ifdef CHECK_MESH_NOT_NULL_UNDEF
331 # undef CHECK_MESH_NOT_NULL
virtual const std::string & getName() const
Acces to the name of the asset.
const MaterialData & getMaterial() const
Return the MaterialData associated to the objet.
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.
A PointCloud without indices.
static RenderObject * createRenderObject(const std::string &name, Scene::Component *comp, const RenderObjectType &type, std::shared_ptr< Data::Displayable > mesh, const RenderTechnique &techniqueConfig=RenderTechnique::createDefaultRenderTechnique())
A component is an element that can be updated by a system. It is also linked to some other components...
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 ...
void setSplatSize(float s)
set the splat size for rendering
float getSplatSize() const
get the splat size for rendering
~PointCloudComponent() override
Main class to convert Ra::Core::Asset::GeometryData to Ra::Engine::Mesh.
const CoreMeshType & getCoreGeometry() const
Returns the current display geometry.
Main class to convert Ra::Core::Asset::VolumeData to Ra::Engine::VolumeObject.
std::pair< bool, ConverterFunction > getMaterialConverter(const std::string &name)