MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ extract_meshes()

std::vector< Kakshya::MeshData > MayaFlux::IO::ModelReader::extract_meshes ( ) const

Load all meshes after open() has already been called.

Extracts from the currently imported scene. Returns empty if no scene is loaded. Does not call close().

Returns
One MeshData per aiMesh in the scene.

Definition at line 73 of file ModelReader.cpp.

74{
75 if (!m_impl->scene) {
76 set_error("No scene loaded");
77 return {};
78 }
79
80 const aiScene* s = m_impl->scene;
81 std::vector<Kakshya::MeshData> result;
82 result.reserve(s->mNumMeshes);
83
84 for (unsigned int i = 0; i < s->mNumMeshes; ++i) {
85 const aiMesh* mesh = s->mMeshes[i];
86
87 std::string mesh_name(mesh->mName.C_Str());
88
89 std::string mat_name;
90 if (s->mNumMaterials > 0 && mesh->mMaterialIndex < s->mNumMaterials) {
91 aiString ai_mat;
92 s->mMaterials[mesh->mMaterialIndex]->Get(AI_MATKEY_NAME, ai_mat);
93 mat_name = ai_mat.C_Str();
94 }
95
96 auto mesh_data = extract_single_mesh(mesh, s, mesh_name, mat_name);
97 if (mesh_data.is_valid()) {
98 result.push_back(std::move(mesh_data));
99 } else {
101 "ModelReader: mesh '{}' produced invalid MeshData, skipped",
102 mesh_name.empty() ? "<unnamed>" : mesh_name);
103 }
104 }
105
107 "ModelReader: extracted {}/{} meshes",
108 result.size(), s->mNumMeshes);
109
110 return result;
111}
#define MF_INFO(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::unique_ptr< Impl > m_impl
Kakshya::MeshData extract_single_mesh(const void *ai_mesh, const void *ai_scene, std::string_view mesh_name, std::string_view material_name) const
void set_error(std::string msg) const
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

References extract_single_mesh(), MayaFlux::Journal::FileIO, MayaFlux::Journal::IO, m_impl, MF_INFO, MF_WARN, and set_error().

Referenced by create_mesh_buffers(), and load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: