Radium Engine  1.5.20
Loading...
Searching...
No Matches
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
10#include <assimp/mesh.h>
11
12#include <memory>
13#include <set>
14
15struct aiScene;
16struct aiMesh;
17struct aiFace;
18struct aiNode;
19struct aiMaterial;
20
21namespace Ra {
22namespace Core {
23namespace Asset {
24class GeometryData;
25}
26} // namespace Core
27
28namespace IO {
29
32class RA_IO_API AssimpGeometryDataLoader : public Core::Asset::DataLoader<Core::Asset::GeometryData>
33{
34 public:
35 explicit AssimpGeometryDataLoader( const std::string& filepath,
36 const bool VERBOSE_MODE = false );
37
39
41 void loadData( const aiScene* scene,
43
44 protected:
46 inline bool sceneHasGeometry( const aiScene* scene ) const;
47
49 uint sceneGeometrySize( const aiScene* scene ) const;
50
52 void loadGeometryData( const aiScene* scene,
54
56 void loadMaterial( const aiMaterial& material, Core::Asset::GeometryData& data ) const;
57
59 void loadMeshFrame( const aiNode* node,
60 const Core::Transform& parentFrame,
61 const std::map<uint, size_t>& indexTable,
63
64 private:
66 void loadMeshAttrib( const aiMesh& mesh,
68 std::set<std::string>& usedNames );
69
72 void fetchName( const aiMesh& mesh,
74 std::set<std::string>& usedNames ) const;
75
77 void fetchType( const aiMesh& mesh, Core::Asset::GeometryData& data ) const;
78
80 void fetchPolyhedron( const aiMesh& mesh, Core::Asset::GeometryData& data ) const;
81
83 template <typename T>
84 void fetchAttribute( T* aiData,
85 int size,
87 Core::Geometry::MeshAttrib a ) const;
88
90 template <typename T>
91 void fetchIndexLayer( aiFace* faces,
92 int numFaces,
94
96 std::string m_filepath;
97};
98
99template <typename T>
100void AssimpGeometryDataLoader::fetchAttribute( T* aiData,
101 int size,
103 Core::Geometry::MeshAttrib a ) const {
104 auto attribHandle = data.addAttrib<typename AssimpTypeWrapper<T>::Type>( getAttribName( a ) );
105 auto& attribData = data.vertexAttribs().getDataWithLock( attribHandle );
106 attribData.resize( size );
107#pragma omp parallel for
108 for ( int i = 0; i < size; ++i ) {
109 attribData.at( i ) = assimpToCore( aiData[i] );
110 }
111 data.vertexAttribs().unlock( attribHandle );
112}
113
114template <typename T>
115void AssimpGeometryDataLoader::fetchIndexLayer( aiFace* faces,
116 int numFaces,
117 Core::Geometry::MultiIndexedGeometry& data ) const {
118 auto layer = std::make_unique<T>();
119 auto& indices = layer->collection();
120 indices.resize( numFaces );
121#pragma omp parallel for
122 for ( int i = 0; i < numFaces; ++i ) {
123 indices[i] = assimpToCore<typename T::IndexType>( faces[i].mIndices, faces[i].mNumIndices );
124 }
125 data.addLayer( std::move( layer ), false, "indices" );
126}
127
128} // namespace IO
129} // 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:633
void unlock(const AttribHandle< T > &h)
Unlock the handle data.
Definition Attribs.hpp:643
T move(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3