MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
AssimpModelWriter.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::IO {
6
7/**
8 * @class AssimpModelWriter
9 * @brief ModelWriter implementation backed by Assimp::Exporter.
10 *
11 * Packs one or more Kakshya::MeshData into an aiScene (one aiMesh per
12 * MeshData, one aiMaterial per aiMesh sourced from the MeshData's submesh
13 * Region: name, material_name, diffuse_path) and calls Assimp::Exporter.
14 *
15 * Vertex bytes must be in the canonical 60-byte MeshVertex layout
16 * (MeshData::layout.stride_bytes == sizeof(Kakshya::MeshVertex)), the same
17 * assumption ModelReader/MeshInsertion make on the way in. A MeshData with
18 * any other stride is rejected rather than misinterpreted.
19 *
20 * Mesh-only: this writer targets triangle geometry exclusively. It does not
21 * attempt point/line export. Assimp's own topology support for those is
22 * format-dependent and, for two formats (STL, Collada), silently drops the
23 * geometry entirely rather than erroring. That case is out of scope here by
24 * design.
25 *
26 * format_id resolution (ModelWriteOptions::format_id):
27 * Assimp dispatches by an internal format id string, not by extension;
28 * several extensions are genuinely ambiguous (.obj with or without a
29 * sidecar .mtl; .fbx binary vs. ascii both use the same extension). When
30 * format_id is empty, this table supplies a default:
31 *
32 * .dae -> "collada"
33 * .obj -> "obj" (with .mtl; pass "objnomtl" explicitly to omit it)
34 * .stl -> "stlb" (binary; pass "stl" explicitly for ascii)
35 * .ply -> "ply" (ascii; pass "plyb" explicitly for binary)
36 * .3ds -> "3ds"
37 * .gltf -> "gltf2" (not the legacy v1 "gltf" format id)
38 * .glb -> "glb2"
39 * .fbx -> "fbx" (binary; pass "fbxa" explicitly for ascii)
40 * .x3d -> "x3d"
41 * .json -> "assjson" (Assimp's own scene dump, round-trips through
42 * Assimp faithfully; not a general DCC target)
43 *
44 * Textures: only a diffuse texture path is written (AI_MATKEY_TEXTURE,
45 * aiTextureType_DIFFUSE), taken verbatim from the source submesh Region's
46 * diffuse_path attribute. No image bytes are embedded and no path
47 * resolution or copying happens. The caller is responsible for the
48 * referenced file existing relative to the exported model, same contract
49 * ModelReader expects on the way back in via its TextureResolver.
50 */
51class MAYAFLUX_API AssimpModelWriter : public ModelWriter {
52public:
53 AssimpModelWriter() = default;
54 ~AssimpModelWriter() override = default;
55
56 [[nodiscard]] bool can_write(const std::string& filepath) const override;
57
58 bool write(
59 const std::string& filepath,
60 const std::vector<Kakshya::MeshData>& meshes,
61 const ModelWriteOptions& options = {}) override;
62
63 [[nodiscard]] std::vector<std::string> get_supported_extensions() const override;
64 [[nodiscard]] std::string get_last_error() const override { return m_last_error; }
65
66 /**
67 * @brief Register this writer with the ModelWriterRegistry.
68 *
69 * Called from engine/subsystem init. Idempotent.
70 */
71 static void register_with_registry();
72
73private:
74 mutable std::string m_last_error;
75
76 void set_error(std::string msg) const { m_last_error = std::move(msg); }
77};
78
79} // namespace MayaFlux::IO
~AssimpModelWriter() override=default
std::string get_last_error() const override
Last error message or empty string.
void set_error(std::string msg) const
ModelWriter implementation backed by Assimp::Exporter.
Abstract base for 3D model format writers.
Configuration for model writing.