From d9efd4adef647ec0dc2329af374dad771cf13d56 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 7 Apr 2017 15:40:40 -0700 Subject: [PATCH] don't save copy of originals for one-off bake --- libraries/model-baking/src/FBXBaker.cpp | 19 ++++++++++++------- libraries/model-baking/src/FBXBaker.h | 7 +++++-- tools/oven/src/ui/ModelBakeWidget.cpp | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libraries/model-baking/src/FBXBaker.cpp b/libraries/model-baking/src/FBXBaker.cpp index 625d0ae963..af1c861623 100644 --- a/libraries/model-baking/src/FBXBaker.cpp +++ b/libraries/model-baking/src/FBXBaker.cpp @@ -22,9 +22,10 @@ #include "FBXBaker.h" -FBXBaker::FBXBaker(QUrl fbxURL, QString baseOutputPath) : +FBXBaker::FBXBaker(QUrl fbxURL, QString baseOutputPath, bool copyOriginals) : _fbxURL(fbxURL), - _baseOutputPath(baseOutputPath) + _baseOutputPath(baseOutputPath), + _copyOriginals(copyOriginals) { // create an FBX SDK manager _sdkManager = FbxManager::Create(); @@ -152,8 +153,8 @@ void FBXBaker::bake() { rewriteAndBakeSceneTextures(); exportScene(); - removeEmbeddedMediaFolder(); + possiblyCleanupOriginals(); } bool FBXBaker::importScene() { @@ -466,11 +467,15 @@ bool FBXBaker::exportScene() { } -bool FBXBaker::removeEmbeddedMediaFolder() { +void FBXBaker::removeEmbeddedMediaFolder() { // now that the bake is complete, remove the embedded media folder produced by the FBX SDK when it imports an FBX auto embeddedMediaFolderName = _fbxURL.fileName().replace(".fbx", ".fbm"); QDir(_uniqueOutputPath + ORIGINAL_OUTPUT_SUBFOLDER + embeddedMediaFolderName).removeRecursively(); - - // we always return true because a failure to delete the embedded media folder is not a failure of the bake - return true; +} + +void FBXBaker::possiblyCleanupOriginals() { + if (!_copyOriginals) { + // caller did not ask us to keep the original around, so delete the original output folder now + QDir(_uniqueOutputPath + ORIGINAL_OUTPUT_SUBFOLDER).removeRecursively(); + } } diff --git a/libraries/model-baking/src/FBXBaker.h b/libraries/model-baking/src/FBXBaker.h index 2e15e30bce..cc357cd251 100644 --- a/libraries/model-baking/src/FBXBaker.h +++ b/libraries/model-baking/src/FBXBaker.h @@ -47,7 +47,7 @@ class TextureBaker; class FBXBaker : public QObject { Q_OBJECT public: - FBXBaker(QUrl fbxURL, QString baseOutputPath); + FBXBaker(QUrl fbxURL, QString baseOutputPath, bool copyOriginals = true); ~FBXBaker(); void start(); @@ -66,7 +66,8 @@ private: bool importScene(); bool rewriteAndBakeSceneTextures(); bool exportScene(); - bool removeEmbeddedMediaFolder(); + void removeEmbeddedMediaFolder(); + void possiblyCleanupOriginals(); QString createBakedTextureFileName(const QFileInfo& textureFileInfo); QUrl getTextureURL(const QFileInfo& textureFileInfo, fbxsdk::FbxFileTexture* fileTexture); @@ -91,6 +92,8 @@ private: QHash _textureTypes; std::list> _bakingTextures; + + bool _copyOriginals { true }; }; #endif // hifi_FBXBaker_h diff --git a/tools/oven/src/ui/ModelBakeWidget.cpp b/tools/oven/src/ui/ModelBakeWidget.cpp index eb4f792c33..1fe214a7f6 100644 --- a/tools/oven/src/ui/ModelBakeWidget.cpp +++ b/tools/oven/src/ui/ModelBakeWidget.cpp @@ -157,6 +157,6 @@ void ModelBakeWidget::bakeButtonClicked() { } // everything seems to be in place, kick off a bake now - _baker.reset(new FBXBaker(modelToBakeURL, outputDirectory.absolutePath())); + _baker.reset(new FBXBaker(modelToBakeURL, outputDirectory.absolutePath(), false)); _baker->start(); }