MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ModelWriter.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::IO {
7
8/**
9 * @struct ModelWriteOptions
10 * @brief Configuration for model writing.
11 *
12 * Format-specific knobs are interpreted by the concrete writer; unsupported
13 * options are silently ignored.
14 */
16 /**
17 * @brief Assimp export format id, e.g. "gltf2", "objnomtl", "collada",
18 * "stl", "fbx", "fbxa".
19 *
20 * File extension alone is ambiguous for several formats Assimp exports:
21 * OBJ with or without a sidecar .mtl, FBX binary vs. ASCII both use
22 * ".fbx". Empty (the default) derives a format id from the extension
23 * via a small, deliberately short allow-list; see AssimpModelWriter's
24 * own doc for exactly which extensions resolve on their own and which
25 * require this to be set explicitly.
26 */
27 std::string format_id;
28
29 /**
30 * @brief Name to embed for the exported material, if the target format
31 * carries one. Empty uses the source submesh's material_name.
32 */
34};
35
36/**
37 * @class ModelWriter
38 * @brief Abstract base for 3D model format writers.
39 *
40 * Parallels ImageWriter/VolumeWriter. A writer accepts one or more
41 * Kakshya::MeshData (one per aiMesh in the exported scene, mirroring how
42 * ModelReader produces one MeshData per aiMesh on import) and is
43 * responsible for validating that the target format can express what it's
44 * given: a format with no non-triangle primitive support rejects point/line
45 * data rather than silently dropping it. See AssimpModelWriter's own doc
46 * for the concrete list of formats verified safe for which topology.
47 *
48 * Writers are single-shot: one call to write() produces one file. MeshData
49 * is always CPU-authoritative in this codebase (see MeshBuffer's mutation
50 * path), so no GPU download step belongs here. A caller with GPU-only
51 * mesh state (ComputeMeshBuffer) downloads to MeshData first via
52 * IO::download_compute_mesh, then calls write() like any other source.
53 */
54class MAYAFLUX_API ModelWriter {
55public:
56 virtual ~ModelWriter() = default;
57
58 /**
59 * @brief Check whether this writer handles the given filepath.
60 */
61 [[nodiscard]] virtual bool can_write(const std::string& filepath) const = 0;
62
63 /**
64 * @brief Write one or more meshes to disk as a single scene.
65 * @param filepath Destination path.
66 * @param meshes One or more meshes. Must each satisfy MeshData::is_valid().
67 * @param options Format-specific options.
68 * @return true on success. On failure call get_last_error().
69 */
70 virtual bool write(
71 const std::string& filepath,
72 const std::vector<Kakshya::MeshData>& meshes,
73 const ModelWriteOptions& options = {})
74 = 0;
75
76 /**
77 * @brief File extensions handled by this writer (without dot).
78 */
79 [[nodiscard]] virtual std::vector<std::string> get_supported_extensions() const = 0;
80
81 /**
82 * @brief Last error message or empty string.
83 */
84 [[nodiscard]] virtual std::string get_last_error() const = 0;
85};
86
88
89/**
90 * @brief Singleton registry dispatching model writes by file extension.
91 *
92 * See WriterRegistry for behavior. Concrete writers register themselves
93 * during subsystem init.
94 */
96
97} // namespace MayaFlux::IO
virtual ~ModelWriter()=default
virtual std::vector< std::string > get_supported_extensions() const =0
File extensions handled by this writer (without dot).
virtual bool can_write(const std::string &filepath) const =0
Check whether this writer handles the given filepath.
virtual std::string get_last_error() const =0
Last error message or empty string.
virtual bool write(const std::string &filepath, const std::vector< Kakshya::MeshData > &meshes, const ModelWriteOptions &options={})=0
Write one or more meshes to disk as a single scene.
Abstract base for 3D model format writers.
Singleton registry dispatching single-shot writes by file extension.
WriterRegistry< ModelWriter > ModelWriterRegistry
Singleton registry dispatching model writes by file extension.
WriterFactory< ModelWriter > ModelWriterFactory
std::function< std::unique_ptr< Writer >()> WriterFactory
std::string material_name_override
Name to embed for the exported material, if the target format carries one.
std::string format_id
Assimp export format id, e.g.
Configuration for model writing.