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

◆ open()

bool MayaFlux::IO::ModelReader::open ( const std::string &  filepath,
FileReadOptions  options = FileReadOptions::ALL 
)
overridevirtual

Open a file for reading.

Parameters
filepathPath to the file.
optionsReading options (see FileReadOptions).
Returns
true if file was successfully opened.

Implements MayaFlux::IO::FileReader.

Definition at line 247 of file ModelReader.cpp.

248{
249 close();
250
251 auto resolved = resolve_path(filepath);
252
253 if (!std::filesystem::exists(resolved)) {
254 set_error("File not found: " + filepath);
256 "ModelReader: {}", m_last_error);
257 return false;
258 }
259
260 constexpr unsigned int flags = aiProcess_Triangulate
261 | aiProcess_GenSmoothNormals
262 | aiProcess_CalcTangentSpace
263 | aiProcess_FlipUVs
264 | aiProcess_JoinIdenticalVertices
265 | aiProcess_SortByPType;
266
267 m_impl->scene = m_impl->importer.ReadFile(resolved, flags);
268
269 if (!m_impl->scene
270 || (m_impl->scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE)
271 || !m_impl->scene->mRootNode) {
272 set_error(m_impl->importer.GetErrorString());
274 "ModelReader: Assimp import failed — {}", m_last_error);
275 m_impl->scene = nullptr;
276 return false;
277 }
278
279 m_is_open = true;
281 "ModelReader: opened '{}' — {} meshes, {} materials",
282 std::filesystem::path(resolved).filename().string(),
283 m_impl->scene->mNumMeshes,
284 m_impl->scene->mNumMaterials);
285
286 return true;
287}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
std::unique_ptr< Impl > m_impl
void set_error(std::string msg) const
void close() override
Close the currently open file.
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

References close(), MayaFlux::Journal::FileIO, MayaFlux::Journal::IO, m_impl, m_is_open, m_last_error, MF_ERROR, MF_INFO, MayaFlux::IO::FileReader::resolve_path(), and set_error().

Referenced by load().

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