Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.6.3
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AssimpGeometryDataLoader.hpp
1#pragma once
2
3#include <Core/Asset/DataLoader.hpp>
4#include <Core/Asset/GeometryData.hpp>
5#include <Core/Geometry/StandardAttribNames.hpp>
6#include <Core/Types.hpp>
7#include <IO/AssimpLoader/AssimpWrapper.hpp>
8#include <IO/RaIO.hpp>
9#include <assimp/mesh.h>
10#include <memory>
11#include <set>
12
13struct aiScene;
14struct aiMesh;
15struct aiFace;
16struct aiNode;
17struct aiMaterial;
18
19namespace Ra {
20namespace Core {
21namespace Asset {
22class GeometryData;
23}
24} // namespace Core
25
26namespace IO {
27
30class RA_IO_API AssimpGeometryDataLoader : public Core::Asset::DataLoader<Core::Asset::GeometryData>
31{
32 public:
33 explicit AssimpGeometryDataLoader( const std::string& filepath,
34 const bool VERBOSE_MODE = false );
35
37
39 void loadData( const aiScene* scene,
41
42 protected:
44 inline bool sceneHasGeometry( const aiScene* scene ) const;
45
47 uint sceneGeometrySize( const aiScene* scene ) const;
48
50 void loadGeometryData( const aiScene* scene,
52
54 void loadMaterial( const aiMaterial& material, Core::Asset::GeometryData& data ) const;
55
57 void loadMeshFrame( const aiNode* node,
58 const Core::Transform& parentFrame,
59 const std::map<uint, size_t>& indexTable,
61
62 private:
64 void loadMeshAttrib( const aiMesh& mesh,
66 std::set<std::string>& usedNames );
67
70 void fetchName( const aiMesh& mesh,
72 std::set<std::string>& usedNames ) const;
73
75 void fetchType( const aiMesh& mesh, Core::Asset::GeometryData& data ) const;
76
78 void fetchPolyhedron( const aiMesh& mesh, Core::Asset::GeometryData& data ) const;
79
81 template <typename T>
82 void fetchAttribute( T* aiData,
83 int size,
85 Core::Geometry::MeshAttrib a ) const;
86
88 template <typename T>
89 void fetchIndexLayer( aiFace* faces,
90 int numFaces,
92
94 std::string m_filepath;
95};
96
97template <typename T>
98void AssimpGeometryDataLoader::fetchAttribute( T* aiData,
99 int size,
101 Core::Geometry::MeshAttrib a ) const {
102 auto attribHandle = data.addAttrib<typename AssimpTypeWrapper<T>::Type>( getAttribName( a ) );
103 auto& attribData = data.vertexAttribs().getDataWithLock( attribHandle );
104 attribData.resize( size );
105#pragma omp parallel for
106 for ( int i = 0; i < size; ++i ) {
107 attribData.at( i ) = assimpToCore( aiData[i] );
108 }
109 data.vertexAttribs().unlock( attribHandle );
110}
111
112template <typename T>
113void AssimpGeometryDataLoader::fetchIndexLayer( aiFace* faces,
114 int numFaces,
115 Core::Geometry::MultiIndexedGeometry& data ) const {
116 auto layer = std::make_unique<T>();
117 auto& indices = layer->collection();
118 indices.resize( numFaces );
119#pragma omp parallel for
120 for ( int i = 0; i < numFaces; ++i ) {
121 indices[i] = assimpToCore<typename T::IndexType>( faces[i].mIndices, faces[i].mNumIndices );
122 }
123 data.addLayer( std::move( layer ), false, "indices" );
124}
125
126} // namespace IO
127} // namespace Ra
Utils::AttribHandle< T > addAttrib(const std::string &name)
AbstractGeometry with per-vertex attributes and layers of indices. Each layer represents a different ...
Attrib< T >::Container & getDataWithLock(const AttribHandle< T > &h)
Get the locked data container from the attrib handle.
Definition Attribs.hpp:641
void unlock(const AttribHandle< T > &h)
Unlock the handle data.
Definition Attribs.hpp:651
T move(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4