-
Notifications
You must be signed in to change notification settings - Fork 13
--savemesh argument in example 12 #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YasInvolved
wants to merge
9
commits into
master
Choose a base branch
from
yas_mesh_loaders
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33015ee
parse --savemesh argument
YasInvolved 4a01642
save loaded mesh (requires improvements)
YasInvolved 4551f28
argparse by relative path
YasInvolved 128fe5b
only geometry is intended to be written
YasInvolved 4dabe03
fix naming, write mesh on reload
YasInvolved 7899653
prompt user to choose the file to which the geometry will be saved
YasInvolved 9c24b52
check if geometry is null on exit and null it out after saving, log w…
YasInvolved 2c879de
allow user to specify path in additional optional argument
YasInvolved b51add6
change sharedInputCWD to localOutputCWD in geometry saving function
YasInvolved File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. | ||
// This file is part of the "Nabla Engine". | ||
// For conditions of distribution and use, see copyright notice in nabla.h | ||
#include "../3rdparty/argparse/include/argparse/argparse.hpp" | ||
#include "argparse/argparse.hpp" | ||
#include "common.hpp" | ||
|
||
#include "../3rdparty/portable-file-dialogs/portable-file-dialogs.h" | ||
|
@@ -46,7 +46,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc | |
} | ||
|
||
if (parser["--savemesh"] == true) | ||
m_saveMeshOnExit = true; | ||
m_saveGeomOnExit = true; | ||
|
||
m_semaphore = m_device->createSemaphore(m_realFrameIx); | ||
if (!m_semaphore) | ||
|
@@ -197,22 +197,9 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc | |
|
||
inline bool onAppTerminated() override | ||
{ | ||
if (m_saveMeshOnExit) | ||
if (m_saveGeomOnExit) | ||
{ | ||
// make save path | ||
static const auto prefix = std::filesystem::absolute("saved/"); | ||
|
||
if (!std::filesystem::exists(prefix)) | ||
m_system->createDirectory(prefix); | ||
|
||
auto savePath = (prefix / path(m_modelPath).filename()).generic_string(); | ||
|
||
m_logger->log("Saving mesh to %S", ILogger::ELL_INFO, savePath.c_str()); | ||
// TODO (Yas): learn how to get out the geometry from renderer and transform it into IAsset | ||
|
||
auto& asset = m_currentBundle.getContents()[0]; | ||
IAssetWriter::SAssetWriteParams params{ asset.get() }; | ||
m_assetMgr->writeAsset(savePath, params); | ||
writeGeometry(); | ||
} | ||
|
||
if (!device_base_t::onAppTerminated()) | ||
|
@@ -286,6 +273,9 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc | |
m_modelPath = file.result()[0]; | ||
} | ||
|
||
if (m_saveGeomOnExit && m_currentGeom) | ||
writeGeometry(); | ||
|
||
// free up | ||
m_renderer->m_instances.clear(); | ||
m_renderer->clearGeometries({.semaphore=m_semaphore.get(),.value=m_realFrameIx}); | ||
|
@@ -294,16 +284,16 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc | |
//! load the geometry | ||
IAssetLoader::SAssetLoadParams params = {}; | ||
params.logger = m_logger.get(); | ||
m_currentBundle = m_assetMgr->getAsset(m_modelPath,params); | ||
if (m_currentBundle.getContents().empty()) | ||
auto asset = m_assetMgr->getAsset(m_modelPath,params); | ||
if (asset.getContents().empty()) | ||
return false; | ||
|
||
// | ||
core::vector<smart_refctd_ptr<const ICPUPolygonGeometry>> geometries; | ||
switch (m_currentBundle.getAssetType()) | ||
switch (asset.getAssetType()) | ||
{ | ||
case IAsset::E_TYPE::ET_GEOMETRY: | ||
for (const auto& item : m_currentBundle.getContents()) | ||
for (const auto& item : asset.getContents()) | ||
if (auto polyGeo=IAsset::castDown<ICPUPolygonGeometry>(item); polyGeo) | ||
geometries.push_back(polyGeo); | ||
break; | ||
|
@@ -314,6 +304,8 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc | |
if (geometries.empty()) | ||
return false; | ||
|
||
m_currentGeom = geometries[0]; | ||
|
||
using aabb_t = hlsl::shapes::AABB<3,double>; | ||
auto printAABB = [&](const aabb_t& aabb, const char* extraMsg="")->void | ||
{ | ||
|
@@ -446,6 +438,24 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc | |
return true; | ||
} | ||
|
||
void writeGeometry() | ||
{ | ||
// make save path | ||
static const auto prefix = std::filesystem::absolute("saved/"); | ||
|
||
if (!std::filesystem::exists(prefix)) | ||
m_system->createDirectory(prefix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. path is wrong, see the 4 CWD members of the apocalypse in the basic framework app |
||
|
||
auto savePath = (prefix / path(m_modelPath).filename()).generic_string(); | ||
|
||
m_logger->log("Saving mesh to %S", ILogger::ELL_INFO, savePath.c_str()); | ||
|
||
// should I do a const cast here? | ||
const IAsset* asset = m_currentGeom.get(); | ||
IAssetWriter::SAssetWriteParams params{ const_cast<IAsset*>(asset) }; | ||
m_assetMgr->writeAsset(savePath, params); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after writing out once, the `m_currentGeom needs to be nulled out |
||
} | ||
|
||
// Maximum frames which can be simultaneously submitted, used to cycle through our per-frame resources like command buffers | ||
constexpr static inline uint32_t MaxFramesInFlight = 3u; | ||
// | ||
|
@@ -462,10 +472,10 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc | |
// mutables | ||
std::string m_modelPath; | ||
|
||
SAssetBundle m_currentBundle; | ||
smart_refctd_ptr<const ICPUPolygonGeometry> m_currentGeom; | ||
|
||
std::string m_saveFileName; // NOTE: no extension | ||
bool m_saveMeshOnExit; | ||
bool m_saveGeomOnExit; | ||
}; | ||
|
||
NBL_MAIN_FUNC(MeshLoadersApp) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for current geom