Loading...
Searching...
No Matches
ModelSerializer.h
Go to the documentation of this file.
1//
2// Created by denzel on 08/12/2025.
3//
4
5#pragma once
6#include <cstdint>
7#include <filesystem>
8#include <optional>
9
10#include "hellfire/assets/models/ImportResult.h"
11
12namespace hellfire {
13 /**
14 * @brief Serializes the ImportResult to a .hfmodel file
15 *
16 * This captures the hierarchy and asset references for instantiation
17 */
19 public:
20 static constexpr uint32_t MAGIC = 0x4C444F4D; // "MODL"
21 static constexpr uint32_t VERSION = 1;
22
23 static bool save(const std::filesystem::path& filepath, const ImportResult& result);
24 static std::optional<ImportResult> load(const std::filesystem::path& filepath);
25
26 // JSON for debugging
27 static bool save_json(const std::filesystem::path& filepath, const ImportResult& result);
28 static std::optional<ImportResult> load_json(const std::filesystem::path& filepath);
29 };
30} // 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 std::optional< ImportResult > load_json(const std::filesystem::path &filepath)
static constexpr uint32_t VERSION
static bool save(const std::filesystem::path &filepath, const ImportResult &result)
static constexpr uint32_t MAGIC
static bool save_json(const std::filesystem::path &filepath, const ImportResult &result)
static std::optional< ImportResult > load(const std::filesystem::path &filepath)
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::vector< AssetID > created_material_assets
std::string error_message
std::vector< AssetID > created_texture_assets
std::vector< ImportedNode > nodes
std::vector< ImportedMesh > meshes
std::vector< AssetID > created_mesh_assets
Represents an imported mesh with its material binding.
Represents a node in the imported model hierarchy.
std::vector< size_t > child_indices
Indices into ImportResult::nodes.
std::vector< size_t > mesh_indices
Indices into ImportResult::meshes.
Metadata for texture assets.