From ba34a0ddef34269b072cc5421473233dccad238d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 28 Aug 2017 15:01:31 -0700 Subject: [PATCH 1/3] fail bake of partially baked FBX that references KTX --- libraries/baking/src/FBXBaker.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index 1a11071b5b..81b5de7546 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -105,11 +105,8 @@ void FBXBaker::bakeSourceCopy() { void FBXBaker::setupOutputFolder() { // make sure there isn't already an output directory using the same name - int iteration = 0; - if (QDir(_bakedOutputDir).exists()) { qWarning() << "Output path" << _bakedOutputDir << "already exists. Continuing."; - //_bakedOutputDir = _baseOutputPath + "/" + _fbxName + "-" + QString::number(++iteration) + "/"; } else { qCDebug(model_baking) << "Creating FBX output folder" << _bakedOutputDir; @@ -377,8 +374,15 @@ void FBXBaker::rewriteAndBakeSceneTextures() { QFileInfo textureFileInfo { fbxTextureFileName.replace("\\", "/") }; // make sure this texture points to something and isn't one we've already re-mapped - if (!textureFileInfo.filePath().isEmpty() - && textureFileInfo.suffix() != BAKED_TEXTURE_EXT.mid(1)) { + if (!textureFileInfo.filePath().isEmpty()) { + + if (textureFileInfo.suffix() == BAKED_TEXTURE_EXT.mid(1)) { + // re-baking an FBX that already references baked textures is a fail + // so we add an error and return from here + handleError("Cannot re-bake a partially baked FBX file that references baked KTX textures"); + + return; + } // construct the new baked texture file name and file path // ensuring that the baked texture will have a unique name From 6992bd6f48ab71145dd4c1b881682e50f8d30832 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 28 Aug 2017 15:38:31 -0700 Subject: [PATCH 2/3] add deletion of baked content when original removed --- assignment-client/src/assets/AssetServer.cpp | 31 +++++++++++++++----- assignment-client/src/assets/AssetServer.h | 3 ++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 212b9d8d19..753ca118cf 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -53,6 +53,8 @@ static const QList BAKEABLE_TEXTURE_EXTENSIONS = QImageReader::suppo static const QString BAKED_MODEL_SIMPLE_NAME = "asset.fbx"; static const QString BAKED_TEXTURE_SIMPLE_NAME = "texture.ktx"; +static const QString HIDDEN_BAKED_CONTENT_FOLDER = "/.baked/"; + BakeAssetTask::BakeAssetTask(const AssetHash& assetHash, const AssetPath& assetPath, const QString& filePath) : _assetHash(assetHash), _assetPath(assetPath), _filePath(filePath) { } @@ -115,7 +117,7 @@ BakingStatus AssetServer::getAssetStatus(const AssetPath& path, const AssetHash& return (*it)->isBaking() ? Baking : Pending; } - if (path.startsWith("/.baked/")) { + if (path.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { return Baked; } @@ -136,7 +138,7 @@ BakingStatus AssetServer::getAssetStatus(const AssetPath& path, const AssetHash& return Unrelevant; } - auto bakedPath = "/.baked/" + hash + "/" + bakedFilename; + auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + bakedFilename; auto jt = _fileMappings.find(bakedPath); if (jt != _fileMappings.end()) { if (jt->toString() == hash) { @@ -179,14 +181,14 @@ void AssetServer::createEmptyMetaFile(const AssetHash& hash) { } bool AssetServer::hasMetaFile(const AssetHash& hash) { - QString metaFilePath = "/.baked/" + hash + "/meta.json"; + QString metaFilePath = HIDDEN_BAKED_CONTENT_FOLDER + hash + "/meta.json"; qDebug() << "in mappings?" << metaFilePath; return _fileMappings.contains(metaFilePath); } bool AssetServer::needsToBeBaked(const AssetPath& path, const AssetHash& assetHash) { - if (path.startsWith("/.baked/")) { + if (path.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { return false; } @@ -207,7 +209,7 @@ bool AssetServer::needsToBeBaked(const AssetPath& path, const AssetHash& assetHa return false; } - auto bakedPath = "/.baked/" + assetHash + "/" + bakedFilename; + auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + assetHash + "/" + bakedFilename; return !_fileMappings.contains(bakedPath); } @@ -392,6 +394,8 @@ void AssetServer::cleanupUnmappedFiles() { if (removeableFile.remove()) { qCDebug(asset_server) << "\tDeleted" << fileInfo.fileName() << "from asset files directory since it is unmapped."; + + removeBakedPathsForDeletedAsset(fileInfo.fileName()); } else { qCDebug(asset_server) << "\tAttempt to delete unmapped file" << fileInfo.fileName() << "failed"; } @@ -464,7 +468,7 @@ void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNode if (!bakedRootFile.isEmpty()) { // we ran into an asset for which we could have a baked version, let's check if it's ready - bakedAssetPath = "/.baked/" + originalAssetHash + "/" + bakedRootFile; + bakedAssetPath = HIDDEN_BAKED_CONTENT_FOLDER + originalAssetHash + "/" + bakedRootFile; auto bakedIt = _fileMappings.find(bakedAssetPath); if (bakedIt != _fileMappings.end()) { @@ -858,6 +862,18 @@ bool pathIsFolder(const AssetPath& path) { return path.endsWith('/'); } +void AssetServer::removeBakedPathsForDeletedAsset(AssetHash hash) { + // we deleted the file with this hash + + // check if we had baked content for that file that should also now be removed + // by calling deleteMappings for the hidden baked content folder for this hash + AssetPathList hiddenBakedFolder { HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" }; + + qCDebug(asset_server) << "Deleting baked content below" << hiddenBakedFolder << "since" << hash << "was deleted"; + + deleteMappings(hiddenBakedFolder); +} + bool AssetServer::deleteMappings(AssetPathList& paths) { // take a copy of the current mappings in case persistence of these deletes fails auto oldMappings = _fileMappings; @@ -928,6 +944,8 @@ bool AssetServer::deleteMappings(AssetPathList& paths) { if (removeableFile.remove()) { qCDebug(asset_server) << "\tDeleted" << hash << "from asset files directory since it is now unmapped."; + + removeBakedPathsForDeletedAsset(hash); } else { qCDebug(asset_server) << "\tAttempt to delete unmapped file" << hash << "failed"; } @@ -1041,7 +1059,6 @@ bool AssetServer::renameMapping(AssetPath oldPath, AssetPath newPath) { } } -static const QString HIDDEN_BAKED_CONTENT_FOLDER = "/.baked/"; static const QString BAKED_ASSET_SIMPLE_FBX_NAME = "asset.fbx"; static const QString BAKED_ASSET_SIMPLE_TEXTURE_NAME = "texture.ktx"; diff --git a/assignment-client/src/assets/AssetServer.h b/assignment-client/src/assets/AssetServer.h index 94576b329d..cf193ba676 100644 --- a/assignment-client/src/assets/AssetServer.h +++ b/assignment-client/src/assets/AssetServer.h @@ -104,6 +104,9 @@ private: /// Create meta file to describe baked content for original asset bool createMetaFile(AssetHash originalAssetHash); + /// Remove baked paths when the original asset is deleteds + void removeBakedPathsForDeletedAsset(AssetHash originalAssetHash); + Mappings _fileMappings; QDir _resourcesDirectory; From 70430c009d2ac68a7e6c2a448c57b547f4f1cb92 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 30 Aug 2017 13:15:14 -0700 Subject: [PATCH 3/3] Fix ATP requests not keeping track of all mapping redirects --- libraries/networking/src/AssetResourceRequest.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/AssetResourceRequest.cpp b/libraries/networking/src/AssetResourceRequest.cpp index c2e0bc1215..c9ca6ebd43 100644 --- a/libraries/networking/src/AssetResourceRequest.cpp +++ b/libraries/networking/src/AssetResourceRequest.cpp @@ -92,10 +92,12 @@ void AssetResourceRequest::requestMappingForPath(const AssetPath& path) { statTracker->incrementStat(STAT_ATP_MAPPING_REQUEST_SUCCESS); // if we got a redirected path we need to store that with the resource request as relative path URL - if (request->wasRedirected() && _failOnRedirect) { + if (request->wasRedirected()) { _relativePathURL = ATP_SCHEME + request->getRedirectedPath(); - _result = RedirectFail; + } + if (request->wasRedirected() && _failOnRedirect) { + _result = RedirectFail; failed = true; } else { requestHash(request->getHash());