Loading...
Searching...
No Matches
ModelImporter.h
Go to the documentation of this file.
1//
2// Created by denzel on 08/12/2025.
3//
4
5#pragma once
6#include "ImportResult.h"
7#include "assimp/matrix4x4.h"
8#include "assimp/scene.h"
9#include "glm/detail/type_mat.hpp"
10#include "hellfire/assets/AssetRegistry.h"
11#include "hellfire/graphics/texture/Texture.h"
12
13namespace hellfire {
14
16 bool generate_normals = true;
17 bool generate_tangents = true;
18 bool triangulate = true;
19 bool flip_uvs = true;
20 bool optimize_meshes = true;
21 float scale_factor = 1.0f;
22 };
23
24 /**
25 * @brief Converts external model formats (FBX, GLTF, OBJ) into internal assets
26 * this runs once during asset import, NOT at runtime!
27 */
29 public:
30 ModelImporter(AssetRegistry& registry, const std::filesystem::path& output_dir);
31
32 ImportResult import(const std::filesystem::path& source_path, const ImportSettings& settings = {});
33
34 private:
36 std::filesystem::path output_dir_;
37
38 // Current import state
39 const aiScene* ai_scene_ = nullptr;
40 std::filesystem::path source_path_;
41 std::filesystem::path source_dir_;
42 std::string base_name_;
43
44 // Processing pipeline
45 unsigned int build_import_flags(const ImportSettings& settings) const;
46
47 // Node processing
48 void process_node_hierarchy(const aiNode* node, ImportResult& result,
49 size_t parent_index = SIZE_MAX);
50 ImportedNode convert_node(const aiNode* node) const;
51
52 // Mesh processing
53 AssetID process_mesh(const aiMesh* mesh, size_t mesh_index);
54
55 // Material processing
56 AssetID process_material(const aiMaterial* ai_mat, size_t material_index);
57 AssetID process_texture(const std::string& texture_path, TextureType type);
58
59 // Texture resolution
60 std::optional<std::filesystem::path> resolve_texture_path(
61 const std::string& texture_ref) const;
62 bool is_embedded_texture(const std::string& path) const;
63 std::filesystem::path extract_embedded_texture(size_t index);
64
65 // Utility
66 static glm::mat4 convert_matrix(const aiMatrix4x4& m);
67 static bool is_identity(const aiMatrix4x4& m);
68 std::string make_unique_name(const std::string& base,
69 const std::string& suffix,
70 size_t index) const;
71 };
72} // hellfire
std::filesystem::path get_imported_path(const AssetMetadata &meta, const std::string &extension) const
std::filesystem::path get_import_output_dir() const
void import_all_pending()
Import all unprocessed assets in registry.
bool import_model(const AssetMetadata &meta)
bool needs_import(AssetID id) const
AssetImportManager(AssetRegistry &registry, AssetManager &asset_manager, const std::filesystem::path &project_root)
std::filesystem::path project_root_
bool has_imported_mesh(AssetID original_id) const
bool import_model_threaded(const AssetMetadata &meta, std::mutex &registry_mutex)
bool import_texture(const AssetMetadata &meta)
std::filesystem::path import_output_dir_
std::shared_ptr< Mesh > get_mesh(AssetID id)
Registry for storing assets.
std::filesystem::path get_absolute_path(AssetID uuid)
Converts external model formats (FBX, GLTF, OBJ) into internal assets this runs once during asset imp...
unsigned int build_import_flags(const ImportSettings &settings) const
std::filesystem::path output_dir_
std::filesystem::path source_path_
bool is_embedded_texture(const std::string &path) const
static glm::mat4 convert_matrix(const aiMatrix4x4 &m)
std::filesystem::path extract_embedded_texture(size_t index)
static bool is_identity(const aiMatrix4x4 &m)
AssetID process_texture(const std::string &texture_path, TextureType type)
std::optional< std::filesystem::path > resolve_texture_path(const std::string &texture_ref) const
std::string make_unique_name(const std::string &base, const std::string &suffix, size_t index) const
ImportedNode convert_node(const aiNode *node) const
const aiScene * ai_scene_
ModelImporter(AssetRegistry &registry, const std::filesystem::path &output_dir)
std::filesystem::path source_dir_
ImportResult import(const std::filesystem::path &source_path, const ImportSettings &settings={})
AssetID process_mesh(const aiMesh *mesh, size_t mesh_index)
void process_node_hierarchy(const aiNode *node, ImportResult &result, size_t parent_index=SIZE_MAX)
AssetID process_material(const aiMaterial *ai_mat, size_t material_index)
AssetRegistry & registry_
Serializes the ImportResult to a .hfmodel file.
static bool save(const std::filesystem::path &filepath, const ImportResult &result)
static bool save_metadata(const std::filesystem::path &texture_path, const TextureMetadata &meta)
TextureType infer_texture_type(const std::string &name)
TextureType
Definition Texture.h:13
std::filesystem::path filepath
Complete result of importing a model file.
std::string error_message
Represents a node in the imported model hierarchy.
Metadata for texture assets.