@@ -50,7 +50,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
5050 }
5151
5252 if (parser[" --savemesh" ] == true )
53- m_saveGeomOnExit = true ;
53+ m_saveGeom = true ;
5454
5555 if (parser.present (" --savepath" ))
5656 {
@@ -61,8 +61,6 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
6161
6262 if (!std::filesystem::exists (tmp.parent_path ()))
6363 return logFail (" Path specified in --savepath argument doesn't exist" );
64-
65- m_geomSavePath.emplace (std::move (tmp));
6664 }
6765
6866 m_semaphore = m_device->createSemaphore (m_realFrameIx);
@@ -212,17 +210,6 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
212210 return retval;
213211 }
214212
215- inline bool onAppTerminated () override
216- {
217- if (m_saveGeomOnExit && m_currentGeom)
218- writeGeometry ();
219-
220- if (!device_base_t::onAppTerminated ())
221- return false ;
222-
223- return true ;
224- }
225-
226213 protected:
227214 const video::IGPURenderpass::SCreationParams::SSubpassDependency* getDefaultSubpassDependencies () const override
228215 {
@@ -269,8 +256,6 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
269256
270257 bool reloadModel ()
271258 {
272- m_currentGeom = nullptr ;
273-
274259 if (m_nonInteractiveTest) // TODO: maybe also take from argv and argc
275260 m_modelPath = (sharedInputCWD/" ply/Spanner-ply.ply" ).string ();
276261 else
@@ -290,9 +275,6 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
290275 m_modelPath = file.result ()[0 ];
291276 }
292277
293- if (m_saveGeomOnExit && m_currentGeom)
294- writeGeometry ();
295-
296278 // free up
297279 m_renderer->m_instances .clear ();
298280 m_renderer->clearGeometries ({.semaphore =m_semaphore.get (),.value =m_realFrameIx});
@@ -321,7 +303,12 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
321303 if (geometries.empty ())
322304 return false ;
323305
324- m_currentGeom = geometries[0 ];
306+ // TODO: do it async
307+ if (m_saveGeom)
308+ writeGeometry (
309+ const_cast <ICPUPolygonGeometry*>(geometries[0 ].get ()),
310+ m_specifiedGeomSavePath.value_or ((m_saveGeomPrefixPath / path (m_modelPath).filename ()).generic_string ())
311+ );
325312
326313 using aabb_t = hlsl::shapes::AABB<3 ,double >;
327314 auto printAABB = [&](const aabb_t & aabb, const char * extraMsg=" " )->void
@@ -455,29 +442,11 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
455442 return true ;
456443 }
457444
458- void writeGeometry ()
445+ void writeGeometry (ICPUPolygonGeometry* geometry, const std::string& savePath )
459446 {
460- if (!m_geomSavePath.has_value ())
461- m_geomSavePath = pfd::save_file (" Save Geometry" , localOutputCWD.string (),
462- { " All Supported Formats (.stl, .ply, .serialized)" , " *.stl *.ply *.serialized" },
463- pfd::opt::force_overwrite
464- ).result ();
465-
466- auto & dest = m_geomSavePath.value ();
467-
468- if (dest.empty ())
469- {
470- m_logger->log (" Invalid path has been selected. Geometry won't be saved." , ILogger::ELL_ERROR);
471- return ;
472- }
473-
474- m_logger->log (" Saving mesh to %S" , ILogger::ELL_INFO, dest.c_str ());
475-
476- // should I do a const cast here?
477- const IAsset* asset = m_currentGeom.get ();
478- IAssetWriter::SAssetWriteParams params{ const_cast <IAsset*>(asset) };
479- m_assetMgr->writeAsset (dest.string (), params);
480- m_currentGeom = nullptr ;
447+ IAssetWriter::SAssetWriteParams params{ reinterpret_cast <IAsset*>(geometry) };
448+ m_logger->log (" Saving mesh to %S" , ILogger::ELL_INFO, savePath.c_str ());
449+ m_assetMgr->writeAsset (savePath, params);
481450 }
482451
483452 // Maximum frames which can be simultaneously submitted, used to cycle through our per-frame resources like command buffers
@@ -496,10 +465,9 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
496465 // mutables
497466 std::string m_modelPath;
498467
499- smart_refctd_ptr<const ICPUPolygonGeometry> m_currentGeom;
500-
501- bool m_saveGeomOnExit;
502- std::optional<nbl::system::path> m_geomSavePath;
468+ bool m_saveGeom;
469+ std::optional<const std::string> m_specifiedGeomSavePath;
470+ const nbl::system::path m_saveGeomPrefixPath = localOutputCWD / " saved" ;
503471};
504472
505473NBL_MAIN_FUNC (MeshLoadersApp)
0 commit comments