Radium Engine  1.5.20
Loading...
Searching...
No Matches
HandleData.hpp
1#pragma once
2
3#include <Core/Asset/AssetData.hpp>
4#include <Core/Containers/AlignedStdVector.hpp>
5#include <Core/RaCore.hpp>
6#include <Core/Types.hpp>
7#include <Core/Utils/Log.hpp>
8
9#include <map>
10#include <set>
11#include <string>
12#include <vector>
13
14namespace Ra {
15namespace Core {
16namespace Asset {
17
37
41class RA_CORE_API HandleData : public AssetData
42{
43 public:
47 enum HandleType { UNKNOWN = 1 << 0, POINT_CLOUD = 1 << 1, SKELETON = 1 << 2, CAGE = 1 << 3 };
48
49 HandleData( const std::string& name = "", const HandleType& type = UNKNOWN );
50
51 HandleData( const HandleData& data ) = default;
52
54
57
61 inline void setName( const std::string& name );
62
66 inline HandleType getType() const;
67
71 inline void setType( const HandleType& type );
72
76 inline Core::Transform getFrame() const;
77
81 inline void setFrame( const Core::Transform& frame );
82
86 inline void addBindMesh( const std::string& name );
87
91 inline const std::set<std::string>& getBindMeshes() const;
93
97 inline uint getVertexSize() const;
98
102 inline void setVertexSize( uint size );
103
107 inline void setNameTable( const std::map<std::string, uint>& nameTable );
108
112 inline void recomputeAllIndices();
113
116
120 inline uint getComponentDataSize() const;
121
125 inline const Core::AlignedStdVector<HandleComponentData>& getComponentData() const;
126
130 inline Core::AlignedStdVector<HandleComponentData>& getComponentData();
131
135 inline const HandleComponentData& getComponent( const uint i ) const;
136
140 inline HandleComponentData& getComponent( const uint i );
141
145 inline void setComponents( const Core::AlignedStdVector<HandleComponentData>& components );
146
150 inline const Core::AlignedStdVector<Core::Vector2ui>& getEdgeData() const;
151
155 inline Core::AlignedStdVector<Core::Vector2ui>& getEdgeData();
156
160 inline void setEdges( const Core::AlignedStdVector<Core::Vector2ui>& edgeList );
161
165 inline const Core::AlignedStdVector<Core::VectorNui>& getFaceData() const;
166
170 inline Core::AlignedStdVector<Core::VectorNui>& getFaceData();
171
175 inline void setFaces( const Core::AlignedStdVector<Core::VectorNui>& faceList );
176
180 inline void needEndNodes( bool need );
182
185
189 inline bool isPointCloud() const;
190
194 inline bool isSkeleton() const;
195
199 inline bool isCage() const;
200
204 inline bool hasComponents() const;
205
209 inline bool hasEdges() const;
210
214 inline bool hasFaces() const;
215
219 inline bool needsEndNodes() const;
220
225 inline int getIndexOf( const std::string& name ) const;
227
231 inline void displayInfo() const;
232
233 private:
235 HandleType m_type;
236
238 Core::Transform m_frame { Core::Transform::Identity() };
239
241 bool m_endNode { false };
242
244 uint m_vertexSize { 0 };
245
247 std::map<std::string, uint> m_nameTable;
248
250 std::set<std::string> m_bindMeshes;
251
253 Core::AlignedStdVector<HandleComponentData> m_component;
254
256 Core::AlignedStdVector<Core::Vector2ui> m_edge;
257
259 Core::AlignedStdVector<Core::VectorNui> m_face;
260};
261
262inline void HandleData::setName( const std::string& name ) {
263 m_name = name;
264}
265
267 return m_type;
268}
269
270inline void HandleData::setType( const HandleType& type ) {
271 m_type = type;
272}
273
274inline Core::Transform HandleData::getFrame() const {
275 return m_frame;
276}
277
278inline void HandleData::setFrame( const Core::Transform& frame ) {
279 m_frame = frame;
280}
281
282inline uint HandleData::getVertexSize() const {
283 return m_vertexSize;
284}
285inline void HandleData::setVertexSize( uint size ) {
286 m_vertexSize = size;
287}
288
290 m_nameTable = nameTable;
291}
292
294 return m_component.size();
295}
296
298 return m_component;
299}
300
304
305inline void
307 const uint size = components.size();
308 m_component.resize( size );
309#pragma omp parallel for
310 for ( int i = 0; i < int( size ); ++i ) {
311 m_component[i] = components[i];
312 }
313}
314
315inline const HandleComponentData& HandleData::getComponent( const uint i ) const {
316 CORE_ASSERT( ( i < m_component.size() ), "Index i out of bound" );
317 return m_component[i];
318}
319
321 CORE_ASSERT( ( i < m_component.size() ), "Index i out of bound" );
322 return m_component[i];
323}
324
326 return m_edge;
327}
328
332
334 const uint size = edgeList.size();
335 m_edge.resize( size );
336#pragma omp parallel for
337 for ( int i = 0; i < int( size ); ++i ) {
338 m_edge[i] = edgeList[i];
339 }
340}
341
343 return m_face;
344}
345
349
351 const uint size = faceList.size();
352 m_face.resize( size );
353#pragma omp parallel for
354 for ( int i = 0; i < int( size ); ++i ) {
355 m_face[i] = faceList[i];
356 }
357}
358
360 m_nameTable.clear();
361 for ( uint i = 0; i < getComponentDataSize(); ++i ) {
362 m_nameTable[m_component[i].m_name] = i;
363 }
364}
365
366inline bool HandleData::isPointCloud() const {
367 return ( m_type == POINT_CLOUD );
368}
369
370inline bool HandleData::isSkeleton() const {
371 return ( m_type == SKELETON );
372}
373
374inline bool HandleData::isCage() const {
375 return ( m_type == CAGE );
376}
377
378inline bool HandleData::hasComponents() const {
379 return !m_component.empty();
380}
381
382inline bool HandleData::hasEdges() const {
383 return !m_edge.empty();
384}
385
386inline bool HandleData::hasFaces() const {
387 return !m_face.empty();
388}
389
390inline bool HandleData::needsEndNodes() const {
391 return m_endNode;
392}
393
394inline int HandleData::getIndexOf( const std::string& name ) const {
395 auto it = m_nameTable.find( name );
396 if ( it == m_nameTable.end() ) { return -1; }
397 return it->second;
398}
399
400inline void HandleData::needEndNodes( bool need ) {
401 m_endNode = need;
402}
403
404inline void HandleData::addBindMesh( const std::string& name ) {
405 m_bindMeshes.insert( name );
406}
407
409 return m_bindMeshes;
410}
411
412inline void HandleData::displayInfo() const {
413 using namespace Core::Utils; // log
414 std::string type;
415 switch ( m_type ) {
416 case POINT_CLOUD:
417 type = "POINT CLOUD";
418 break;
419 case SKELETON:
420 type = "SKELETON";
421 break;
422 case CAGE:
423 type = "CAGE";
424 break;
425 case UNKNOWN:
426 default:
427 type = "UNKNOWN";
428 break;
429 }
430 LOG( logINFO ) << "======== HANDLE INFO ========";
431 LOG( logINFO ) << " Name : " << m_name;
432 LOG( logINFO ) << " Type : " << type;
433 LOG( logINFO ) << " Element # : " << m_component.size();
434 LOG( logINFO ) << " Edge # : " << m_edge.size();
435 LOG( logINFO ) << " Face # : " << m_face.size();
436 LOG( logINFO ) << " Need EndNodes ? : " << ( ( m_endNode ) ? "YES" : "NO" );
437}
438
439} // namespace Asset
440} // namespace Core
441} // namespace Ra
void setNameTable(const std::map< std::string, uint > &nameTable)
const Core::AlignedStdVector< HandleComponentData > & getComponentData() const
int getIndexOf(const std::string &name) const
void setFrame(const Core::Transform &frame)
void setEdges(const Core::AlignedStdVector< Core::Vector2ui > &edgeList)
const Core::AlignedStdVector< Core::VectorNui > & getFaceData() const
void setType(const HandleType &type)
const std::set< std::string > & getBindMeshes() const
const Core::AlignedStdVector< Core::Vector2ui > & getEdgeData() const
HandleType getType() const
void addBindMesh(const std::string &name)
void setFaces(const Core::AlignedStdVector< Core::VectorNui > &faceList)
const HandleComponentData & getComponent(const uint i) const
Core::Transform getFrame() const
void setComponents(const Core::AlignedStdVector< HandleComponentData > &components)
void setVertexSize(uint size)
void setName(const std::string &name)
T clear(T... args)
T end(T... args)
T find(T... args)
T insert(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3
T size(T... args)
std::map< std::string, Core::Transform > m_bindMatrices
Per skinned-mesh matrix from mesh space to bone space (local).
std::map< std::string, std::vector< std::pair< uint, Scalar > > > m_weights
Per skinned-mesh vertex weigths.
std::string m_name
Handle name.