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/Material.hpp>
10#include <Engine/Data/MaterialConverters.hpp>
11#include <Engine/Data/Mesh.hpp>
12#include <Engine/Rendering/RenderObject.hpp>
13#include <Engine/Scene/Component.hpp>
14#include <Engine/Scene/ComponentMessenger.hpp>
15#include <Engine/Scene/Entity.hpp>
30 Component( name, entity ), m_contentName( name ) {}
38 void setContentName(
const std::string& name ) { m_contentName = name; }
45 const Ra::Core::Utils::Index* roIndexRead()
const;
49 Ra::Core::Utils::Index m_roIndex {};
62template <
typename CoreMeshType>
68 using RenderMeshType =
typename Data::RenderMeshType::getType<CoreMeshType>::Type;
93 inline RenderMeshType* getDisplayable();
96 inline void setupIO(
const std::string&
id )
override;
97 inline void setDeformable(
bool b );
106 Core::Transform transform );
109 inline const CoreMeshType* getMeshOutput()
const;
110 inline CoreMeshType* getMeshRw();
139 Core::Geometry::PointCloud&& mesh,
144 void initialize()
override;
147 const Ra::Core::Geometry::PointCloud& getCoreGeometry()
const;
159 void setDeformable(
bool b );
167 const Ra::Core::Geometry::PointCloud* getMeshOutput()
const;
168 Ra::Core::Geometry::PointCloud* getPointCloudRw();
174 float m_splatSize { 0.0025f };
193 void initialize()
override;
201 Ra::Core::Utils::Index getRenderObjectIndex()
const;
210 const Ra::Core::Utils::Index* roIndexRead()
const;
213 Ra::Core::Utils::Index m_volumeIndex {};
218template <
typename CoreMeshType>
224 generateMesh( data );
227template <
typename CoreMeshType>
228SurfaceMeshComponent<CoreMeshType>::SurfaceMeshComponent(
const std::string& name,
231 GeometryComponent( name, entity ), m_displayMesh( data ) {
232 finalizeROFromGeometry( convertMatdataToMaterial(
nullptr ), Core::Transform::Identity() );
235template <
typename CoreMeshType>
241 m_displayMesh( new RenderMeshType( name,
std::move( mesh ) ) ) {
242 setContentName( name );
243 finalizeROFromGeometry( convertMatdataToMaterial( mat ), Core::Transform::Identity() );
246template <
typename CoreMeshType>
253 m_displayMesh( new RenderMeshType( name,
std::move( mesh ) ) ) {
254 setContentName( name );
255 finalizeROFromGeometry( mat, Core::Transform::Identity() );
257template <
typename CoreMeshType>
259 m_contentName = data->
getName();
263 m_displayMesh->loadGeometry(
std::move( mesh ) );
265 finalizeROFromGeometry(
270template <
typename CoreMeshType>
276 if ( data !=
nullptr ) {
278 auto mat = converter.second( data );
279 roMaterial.
reset( mat );
282 auto mat =
new Data::BlinnPhongMaterial( m_contentName +
"_DefaultBPMaterial" );
283 mat->setRenderAsSplat( m_displayMesh->getNumFaces() == 0 );
284 mat->setColoredByVertexAttrib( m_displayMesh->getCoreGeometry().hasAttrib(
285 Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::VERTEX_COLOR ) ) );
286 roMaterial.
reset( mat );
291template <
typename CoreMeshType>
292void SurfaceMeshComponent<CoreMeshType>::finalizeROFromGeometry(
294 Core::Transform transform ) {
297 std::string roName( m_name +
"_" + m_contentName +
"_RO" );
302 Rendering::RenderTechnique {} );
303 ro->setTransparent( roMaterial->isTransparent() );
304 ro->setMaterial( roMaterial );
305 setupIO( m_contentName );
306 ro->setLocalTransform( transform );
307 m_roIndex = addRenderObject( ro );
310#ifndef CHECK_MESH_NOT_NULL
311# define CHECK_MESH_NOT_NULL \
313 CORE_ASSERT( m_displayMesh != nullptr, \
314 "DisplayMesh should exist while component is alive" );
315# define CHECK_MESH_NOT_NULL_UNDEF
318template <
typename CoreMeshType>
321 return m_displayMesh->getCoreGeometry();
324template <
typename CoreMeshType>
325typename SurfaceMeshComponent<CoreMeshType>::RenderMeshType*
328 return m_displayMesh.get();
331template <
typename CoreMeshType>
332void SurfaceMeshComponent<CoreMeshType>::setupIO(
const std::string&
id ) {
335 const auto& cm = ComponentMessenger::getInstance();
336 auto cbOut =
std::bind( &SurfaceMeshComponent<CoreMeshType>::getMeshOutput,
this );
337 auto cbRw =
std::bind( &SurfaceMeshComponent<CoreMeshType>::getMeshRw,
this );
339 cm->registerOutput<CoreMeshType>( getEntity(),
this, id, cbOut );
340 cm->registerReadWrite<CoreMeshType>( getEntity(),
this, id, cbRw );
345template <
typename CoreMeshType>
346const CoreMeshType* SurfaceMeshComponent<CoreMeshType>::getMeshOutput()
const {
348 return &m_displayMesh->getCoreGeometry();
351template <
typename CoreMeshType>
352CoreMeshType* SurfaceMeshComponent<CoreMeshType>::getMeshRw() {
354 return &( m_displayMesh->getCoreGeometry() );
357#ifdef CHECK_MESH_NOT_NULL_UNDEF
358# 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::shared_ptr< T > make_shared(Args &&... args)
std::pair< bool, ConverterFunction > getMaterialConverter(const std::string &name)
CoreMeshType createCoreMeshFromGeometryData(const Ra::Core::Asset::GeometryData *data)
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet