From 54f9d52aa11035ba508e202e16f82a4c4017a232 Mon Sep 17 00:00:00 2001 From: utkarshgautamnyu Date: Wed, 25 Oct 2017 14:15:55 -0700 Subject: [PATCH] Moved _textureContent to parent class ModelBaker --- libraries/baking/src/FBXBaker.cpp | 33 ++++------------------------- libraries/baking/src/FBXBaker.h | 3 --- libraries/baking/src/ModelBaker.cpp | 14 ++++++------ libraries/baking/src/ModelBaker.h | 10 ++++++--- libraries/baking/src/OBJBaker.cpp | 7 ++---- 5 files changed, 19 insertions(+), 48 deletions(-) diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index c26a3d81a8..28b70c88a6 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -365,21 +365,18 @@ void FBXBaker::rewriteAndBakeSceneTextures() { textureContent = _textureContent.value(fbxTextureFileName.toLocal8Bit()); } - // Callback to get texture content and type - getTextureContentTypeCallback textureContentTypeCallback = [=]() { - QPair result; - result.first = textureContent; + // Callback to get texture type + getTextureTypeCallback textureTypeCallback = [=]() { // grab the ID for this texture so we can figure out the // texture type from the loaded materials auto textureID{ object->properties[0].toByteArray() }; auto textureType = textureTypes[textureID]; - result.second = textureType; - return result; + return textureType; }; // Compress the texture information and return the new filename to be added into the FBX scene QByteArray* bakedTextureFile = this->compressTexture(fbxTextureFileName, _fbxURL, _bakedOutputDir, _textureThreadGetter, - textureContentTypeCallback, _originalOutputDir); + textureTypeCallback, _originalOutputDir); // If no errors or warnings have occurred during texture compression add the filename to the FBX scene if (bakedTextureFile) { @@ -431,25 +428,3 @@ void FBXBaker::exportScene() { qCDebug(model_baking) << "Exported" << _fbxURL << "with re-written paths to" << _bakedFBXFilePath; } - -void FBXBaker::checkIfTexturesFinished() { - // check if we're done everything we need to do for this FBX - // and emit our finished signal if we're done - - if (_bakingTextures.isEmpty()) { - if (shouldStop()) { - // if we're checking for completion but we have errors - // that means one or more of our texture baking operations failed - - if (_pendingErrorEmission) { - setIsFinished(true); - } - - return; - } else { - qCDebug(model_baking) << "Finished baking, emitting finsihed" << _fbxURL; - - setIsFinished(true); - } - } -} diff --git a/libraries/baking/src/FBXBaker.h b/libraries/baking/src/FBXBaker.h index d0f95beebf..4bf883bf2f 100644 --- a/libraries/baking/src/FBXBaker.h +++ b/libraries/baking/src/FBXBaker.h @@ -62,13 +62,10 @@ private: void exportScene(); void removeEmbeddedMediaFolder(); - void checkIfTexturesFinished(); - QUrl _fbxURL; FBXNode _rootNode; FBXGeometry* _geometry; - QHash _textureContent; QString _bakedFBXFilePath; diff --git a/libraries/baking/src/ModelBaker.cpp b/libraries/baking/src/ModelBaker.cpp index 242d9794ef..dafd932135 100644 --- a/libraries/baking/src/ModelBaker.cpp +++ b/libraries/baking/src/ModelBaker.cpp @@ -207,21 +207,17 @@ bool ModelBaker::compressMesh(FBXMesh& mesh, bool hasDeformers,FBXNode& dracoMes } QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, QUrl modelURL, QString bakedOutputDir, TextureBakerThreadGetter textureThreadGetter, - getTextureContentTypeCallback textureContentTypeCallback, const QString& originalOutputDir) { + getTextureTypeCallback textureTypeCallback, const QString& originalOutputDir) { _modelURL = modelURL; _textureThreadGetter = textureThreadGetter; _originalOutputDir = originalOutputDir; static QByteArray textureChild; - - QPair textureContentType; QByteArray textureContent; image::TextureUsage::Type textureType; - if (textureContentTypeCallback) { - textureContentType = textureContentTypeCallback(); - textureContent = textureContentType.first; - textureType = textureContentType.second; + if (textureTypeCallback) { + textureType = textureTypeCallback(); } QFileInfo modelTextureFileInfo{ modelTextureFileName.replace("\\", "/") }; @@ -244,7 +240,9 @@ QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, QUrl model // check if this was an embedded texture that we already have in-memory content for // figure out the URL to this texture, embedded or external - qCDebug(model_baking) << "TextureContent" << !textureContent.isNull(); + if (!modelTextureFileInfo.filePath().isEmpty()) { + textureContent = _textureContent.value(modelTextureFileName.toLocal8Bit()); + } auto urlToTexture = getTextureURL(modelTextureFileInfo, modelTextureFileName, !textureContent.isNull()); QString bakedTextureFileName; diff --git a/libraries/baking/src/ModelBaker.h b/libraries/baking/src/ModelBaker.h index 8af95acac8..7f8efdf887 100644 --- a/libraries/baking/src/ModelBaker.h +++ b/libraries/baking/src/ModelBaker.h @@ -28,7 +28,7 @@ using TextureBakerThreadGetter = std::function; using getMaterialIDCallback = std::function ; -using getTextureContentTypeCallback = std::function()>; +using getTextureTypeCallback = std::function; class ModelBaker : public Baker{ Q_OBJECT @@ -37,8 +37,12 @@ public: ModelBaker(); bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, getMaterialIDCallback materialIDCallback = NULL); QByteArray* compressTexture(QString textureFileName, QUrl modelUrl, QString bakedOutputDir, TextureBakerThreadGetter textureThreadGetter, - getTextureContentTypeCallback textureContentTypeCallback = NULL, const QString& originalOutputDir = ""); + getTextureTypeCallback textureTypeCallback = NULL, const QString& originalOutputDir = ""); virtual void setWasAborted(bool wasAborted) override; + +protected: + void checkIfTexturesFinished(); + QHash _textureContent; public slots: virtual void bake() override; @@ -53,7 +57,7 @@ private: void bakeTexture(const QUrl & textureURL, image::TextureUsage::Type textureType, const QDir & outputDir, const QString & bakedFilename, const QByteArray & textureContent); QString texturePathRelativeToModel(QUrl modelURL, QUrl textureURL); - void checkIfTexturesFinished(); + QHash _textureNameMatchCount; QHash _remappedTexturePaths; diff --git a/libraries/baking/src/OBJBaker.cpp b/libraries/baking/src/OBJBaker.cpp index 3303bbd828..076b78501b 100644 --- a/libraries/baking/src/OBJBaker.cpp +++ b/libraries/baking/src/OBJBaker.cpp @@ -288,11 +288,8 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) { QByteArray textureFileName = (!currentMaterial.albedoTexture.filename.isEmpty()) ? currentMaterial.albedoTexture.filename : currentMaterial.specularTexture.filename; // Callback to get Texture content and type - getTextureContentTypeCallback textureContentTypeCallback = [=]() { - QPair result; - result.first = NULL; // No need of texture content as no embedded textures present in case of an OBJ - result.second = (!currentMaterial.albedoTexture.filename.isEmpty()) ? image::TextureUsage::Type::ALBEDO_TEXTURE : image::TextureUsage::Type::SPECULAR_TEXTURE; - return result; + getTextureTypeCallback textureContentTypeCallback = [=]() { + return (!currentMaterial.albedoTexture.filename.isEmpty()) ? image::TextureUsage::Type::ALBEDO_TEXTURE : image::TextureUsage::Type::SPECULAR_TEXTURE; }; // Compress the texture using ModelBaker::compressTexture() and store compressed file's name in the node