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

◆ save_mesh() [3/5]

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 225 of file ModelExport.cpp.

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

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