From 1a17da6ecc447115dc88724fcff2e6371f0f04f2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 5 Apr 2017 18:21:53 -0700 Subject: [PATCH] add helper to deduce texture relative URL after download --- libraries/model-baking/src/FBXBaker.cpp | 13 +++++++++++++ libraries/model-baking/src/TextureBaker.cpp | 2 ++ 2 files changed, 15 insertions(+) diff --git a/libraries/model-baking/src/FBXBaker.cpp b/libraries/model-baking/src/FBXBaker.cpp index 3370698738..5f9037ddb9 100644 --- a/libraries/model-baking/src/FBXBaker.cpp +++ b/libraries/model-baking/src/FBXBaker.cpp @@ -186,6 +186,19 @@ bool FBXBaker::importScene() { static const QString BAKED_TEXTURE_DIRECTORY = "textures/"; static const QString BAKED_TEXTURE_EXT = ".ktx"; +QString texturePathRelativeToFBX(QUrl fbxURL, QUrl textureURL) { + auto fbxPath = fbxURL.toString(QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment); + auto texturePath = textureURL.toString(QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment); + + if (texturePath.startsWith(fbxPath)) { + // texture path is a child of the FBX path, return the texture path without the fbx path + return texturePath.mid(fbxPath.length()); + } else { + // the texture path was not a child of the FBX path, return the empty string + return ""; + } +} + bool FBXBaker::rewriteAndBakeSceneTextures() { // get a count of the textures used in the scene int numTextures = _scene->GetTextureCount(); diff --git a/libraries/model-baking/src/TextureBaker.cpp b/libraries/model-baking/src/TextureBaker.cpp index ce86b18479..4f21ccd624 100644 --- a/libraries/model-baking/src/TextureBaker.cpp +++ b/libraries/model-baking/src/TextureBaker.cpp @@ -66,6 +66,8 @@ void TextureBaker::handleTextureNetworkReply() { if (requestReply->error() == QNetworkReply::NoError) { qCDebug(model_baking) << "Downloaded texture at" << _textureURL; + + // store the original texture so it can be passed along for the bake _originalTexture = requestReply->readAll(); } else { qCDebug(model_baking) << "Error downloading texture" << requestReply->errorString();