MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ save_mesh() [3/5]

MAYAFLUX_API bool MayaFlux::IO::save_mesh ( const std::shared_ptr< Buffers::MeshNetworkBuffer > &  network_buffer,
const std::string &  filepath,
const ModelWriteOptions &  options = {} 
)

Save a MeshNetworkBuffer's current slots to disk as one multi-mesh file, one aiMesh per slot.

Each slot's vertices (position, normal, tangent) are baked into world space from that slot's current world_transform before export, so an exploded/rotated network exports in the pose it is actually in, not its local rest pose. A slot with no node, or a node with no vertices yet, is skipped rather than failing the whole export; the export fails only if every slot is empty.

Parameters
network_bufferSource network buffer.
filepathDestination path with extension.
optionsFormat-specific writer options.
Returns
True on success. Failure is logged.

Definition at line 214 of file ModelExport.cpp.

218{
219 if (!network_buffer) {
220 MF_ERROR(Journal::Component::IO, Journal::Context::FileIO, "save_mesh: null network_buffer");
221 return false;
222 }
223
224 auto net = network_buffer->get_network();
225 if (!net) {
226 MF_ERROR(Journal::Component::IO, Journal::Context::FileIO,
227 "save_mesh: MeshNetworkBuffer has no network");
228 return false;
229 }
230
231 std::vector<Kakshya::MeshData> meshes;
232 meshes.reserve(net->slots().size());
233 const std::string shared_diffuse_path = network_buffer->has_diffuse_texture()
234 ? pack_diffuse_texture(network_buffer->get_diffuse_texture(), filepath, "")
235 : std::string {};
236 for (const auto& slot : net->slots()) {
237 if (!slot.node) {
238 continue;
239 }
240 std::string diffuse_path = shared_diffuse_path;
241 if (slot.diffuse_texture) {
242 const auto suffix = !slot.name.empty() ? slot.name : std::to_string(slot.index);
243 diffuse_path = pack_diffuse_texture(slot.diffuse_texture, filepath, suffix);
244 }
245 if (auto packed = pack_node(slot.node, slot.world_transform, slot.name, diffuse_path)) {
246 meshes.push_back(std::move(*packed));
247 }
248 }
249
250 if (meshes.empty()) {
251 MF_ERROR(Journal::Component::IO, Journal::Context::FileIO,
252 "save_mesh: no exportable slots in network");
253 return false;
254 }
255
256 return write_via_registry(filepath, meshes, options);
257}
#define MF_ERROR(comp, ctx,...)
std::string diffuse_path

References diffuse_path, MayaFlux::Journal::FileIO, MayaFlux::Journal::IO, and MF_ERROR.