MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ModelExport.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6class MeshBuffer;
7class MeshNetworkBuffer;
8class ComputeMeshBuffer;
9}
10
12class MeshWriterNode;
13}
14
16class MeshNetwork;
17}
18
19namespace MayaFlux::IO {
20
21/**
22 * @brief Save a MeshBuffer's current mesh data to disk via ModelWriterRegistry.
23 *
24 * Synchronous: MeshData is always CPU-authoritative for MeshBuffer (every
25 * mutation path writes the CPU copy first, GPU is upload-only), so there is
26 * no GPU download step here, unlike save_image/save_volume.
27 *
28 * @param buffer Source mesh.
29 * @param filepath Destination path with extension; selects the writer via
30 * ModelWriterRegistry.
31 * @param options Format-specific writer options.
32 * @return True on success. Failure is logged.
33 */
34[[nodiscard]] bool save_mesh(
35 const std::shared_ptr<Buffers::MeshBuffer>& buffer,
36 const std::string& filepath,
37 const ModelWriteOptions& options = {});
38
39/**
40 * @brief Save a MeshNetworkBuffer's current slots to disk as one multi-mesh
41 * file, one aiMesh per slot.
42 *
43 * Each slot's vertices (position, normal, tangent) are baked into world
44 * space from that slot's current world_transform before export, so an
45 * exploded/rotated network exports in the pose it is actually in, not its
46 * local rest pose. A slot with no node, or a node with no vertices yet, is
47 * skipped rather than failing the whole export; the export fails only if
48 * every slot is empty.
49 *
50 * @param network_buffer Source network buffer.
51 * @param filepath Destination path with extension.
52 * @param options Format-specific writer options.
53 * @return True on success. Failure is logged.
54 */
55[[nodiscard]] bool save_mesh(
56 const std::shared_ptr<Buffers::MeshNetworkBuffer>& network_buffer,
57 const std::string& filepath,
58 const ModelWriteOptions& options = {});
59
60/**
61 * @brief Save a MeshNetwork's current slots to disk as one multi-mesh file.
62 *
63 * Same shape as the MeshNetworkBuffer overload (each slot's vertices baked
64 * into world space from its current world_transform), but works directly
65 * on the network: slot data lives on MeshNetwork itself, not on the GPU
66 * buffer, so a network never wrapped in a MeshNetworkBuffer, or not yet
67 * rendered, is still exportable. The MeshNetworkBuffer overload forwards
68 * here via get_network().
69 *
70 * @param network Source network.
71 * @param filepath Destination path with extension.
72 * @param options Format-specific writer options.
73 * @return True on success. Failure is logged.
74 */
75[[nodiscard]] bool save_mesh(
76 const std::shared_ptr<Nodes::Network::MeshNetwork>& network,
77 const std::string& filepath,
78 const ModelWriteOptions& options = {});
79
80/**
81 * @brief Save a bare MeshWriterNode's current vertices/indices to disk.
82 *
83 * For geometry driven directly through GeometryBuffer rather than wrapped
84 * in a MeshBuffer. No world transform is applied: a bare node has none of
85 * its own, unlike a MeshNetwork slot.
86 *
87 * @param node Source node. Must have both vertices and indices set.
88 * @param filepath Destination path with extension.
89 * @param options Format-specific writer options.
90 * @return True on success. Failure is logged.
91 */
92[[nodiscard]] bool save_mesh(
93 const std::shared_ptr<Nodes::GpuSync::MeshWriterNode>& node,
94 const std::string& filepath,
95 const ModelWriteOptions& options = {});
96
97/**
98 * @brief Download a ComputeMeshBuffer's current live geometry to CPU.
99 *
100 * ComputeMeshBuffer's own doc states its live rendering path never reads
101 * back vertex data; this is the deliberate, one-shot exception for export.
102 * Reads the true live vertex count off the atomic counter buffer's mapped
103 * pointer (host-visible, no transfer), then downloads exactly that many
104 * vertices from the buffer itself, not its worst-case allocated capacity.
105 * The result is non-indexed triangles, so a trivial sequential index array
106 * (0..N-1) is synthesized to satisfy Kakshya::MeshData's index requirement.
107 *
108 * @param buffer Source buffer. setup_processors() must have run.
109 * @return The current geometry, or nullopt if the buffer is null, has no
110 * mesh processor yet, or the live vertex count is zero.
111 */
112[[nodiscard]] std::optional<Kakshya::MeshData> download_compute_mesh(
113 const std::shared_ptr<Buffers::ComputeMeshBuffer>& buffer);
114
115/**
116 * @brief Save a ComputeMeshBuffer's current live geometry to disk.
117 *
118 * Wraps download_compute_mesh() and write_via_registry() in one call. See
119 * download_compute_mesh's own doc for the one-shot readback this performs.
120 */
121[[nodiscard]] bool save_mesh(
122 const std::shared_ptr<Buffers::ComputeMeshBuffer>& buffer,
123 const std::string& filepath,
124 const ModelWriteOptions& options = {});
125
126/**
127 * @brief Save a ComputeMeshBuffer with a millisecond epoch timestamp
128 * spliced into the path. See the MeshBuffer overload's doc for the
129 * case this serves.
130 */
131[[nodiscard]] bool save_mesh_snapshot(
132 const std::shared_ptr<Buffers::ComputeMeshBuffer>& buffer,
133 const std::string& path_pattern,
134 const ModelWriteOptions& options = {});
135
136/**
137 * @brief Save with a millisecond epoch timestamp spliced into the path.
138 *
139 * For the "save whenever, whatever it looks like right now" case: a caller
140 * watching a live-deforming mesh who wants to catch a particular passing
141 * state, as many times as they like, without managing a counter or
142 * overwriting the last capture. Needs no state of its own, unlike a
143 * frame-numbered sequence.
144 *
145 * @param buffer Source mesh.
146 * @param path_pattern Path with one std::format replacement field for the
147 * timestamp, e.g. "drone_{}.obj".
148 * @param options Format-specific writer options.
149 * @return True on success. Failure is logged.
150 */
151[[nodiscard]] bool save_mesh_snapshot(
152 const std::shared_ptr<Buffers::MeshBuffer>& buffer,
153 const std::string& path_pattern,
154 const ModelWriteOptions& options = {});
155
156/**
157 * @brief Save a MeshNetworkBuffer with a millisecond epoch timestamp spliced
158 * into the path. See the MeshBuffer overload's doc for the case this
159 * serves.
160 */
161[[nodiscard]] bool save_mesh_snapshot(
162 const std::shared_ptr<Buffers::MeshNetworkBuffer>& network_buffer,
163 const std::string& path_pattern,
164 const ModelWriteOptions& options = {});
165
166/**
167 * @brief Save a MeshNetwork with a millisecond epoch timestamp spliced into
168 * the path. See the MeshBuffer overload's doc for the case this serves.
169 */
170[[nodiscard]] bool save_mesh_snapshot(
171 const std::shared_ptr<Nodes::Network::MeshNetwork>& network,
172 const std::string& path_pattern,
173 const ModelWriteOptions& options = {});
174
175/**
176 * @brief Save a bare MeshWriterNode with a millisecond epoch timestamp
177 * spliced into the path. See the MeshBuffer overload's doc for the
178 * case this serves.
179 */
180[[nodiscard]] bool save_mesh_snapshot(
181 const std::shared_ptr<Nodes::GpuSync::MeshWriterNode>& node,
182 const std::string& path_pattern,
183 const ModelWriteOptions& options = {});
184
185} // namespace MayaFlux::IO
Core::GlobalNetworkConfig network
Definition Config.cpp:39
std::shared_ptr< NetworkGeometryBuffer > buffer
bool save_mesh_snapshot(const std::shared_ptr< Buffers::ComputeMeshBuffer > &buffer, const std::string &path_pattern, const ModelWriteOptions &options)
Save a ComputeMeshBuffer with a millisecond epoch timestamp spliced into the path.
bool save_mesh(const std::shared_ptr< Buffers::MeshBuffer > &buffer, const std::string &filepath, const ModelWriteOptions &options)
Save a MeshBuffer's current mesh data to disk via ModelWriterRegistry.
std::optional< Kakshya::MeshData > download_compute_mesh(const std::shared_ptr< Buffers::ComputeMeshBuffer > &buffer)
Download a ComputeMeshBuffer's current live geometry to CPU.