mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 12:42:58 +02:00
don't save copy of embedded raw textures
This commit is contained in:
parent
1a17da6ecc
commit
679580a620
3 changed files with 73 additions and 21 deletions
|
@ -39,10 +39,10 @@ FBXBaker::~FBXBaker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const QString BAKED_OUTPUT_SUBFOLDER = "baked/";
|
static const QString BAKED_OUTPUT_SUBFOLDER = "baked/";
|
||||||
static const QString ORIGINAL_OUTPUT_SUBFOLDER = "original/";
|
static const QString RAW_OUTPUT_SUBFOLDER = "raw/";
|
||||||
|
|
||||||
QString FBXBaker::pathToCopyOfOriginal() const {
|
QString FBXBaker::pathToCopyOfRaw() const {
|
||||||
return _uniqueOutputPath + ORIGINAL_OUTPUT_SUBFOLDER + _fbxURL.fileName();
|
return _uniqueOutputPath + RAW_OUTPUT_SUBFOLDER + _fbxURL.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FBXBaker::start() {
|
void FBXBaker::start() {
|
||||||
|
@ -59,7 +59,7 @@ void FBXBaker::start() {
|
||||||
QFile localFBX { _fbxURL.toLocalFile() };
|
QFile localFBX { _fbxURL.toLocalFile() };
|
||||||
|
|
||||||
// make a copy in the output folder
|
// make a copy in the output folder
|
||||||
localFBX.copy(pathToCopyOfOriginal());
|
localFBX.copy(pathToCopyOfRaw());
|
||||||
|
|
||||||
// start the bake now that we have everything in place
|
// start the bake now that we have everything in place
|
||||||
bake();
|
bake();
|
||||||
|
@ -103,10 +103,10 @@ bool FBXBaker::setupOutputFolder() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the baked and original sub-folders used during export
|
// make the baked and raw sub-folders used during export
|
||||||
QDir uniqueOutputDir = _uniqueOutputPath;
|
QDir uniqueOutputDir = _uniqueOutputPath;
|
||||||
if (!uniqueOutputDir.mkdir(BAKED_OUTPUT_SUBFOLDER) || !uniqueOutputDir.mkdir(ORIGINAL_OUTPUT_SUBFOLDER)) {
|
if (!uniqueOutputDir.mkdir(BAKED_OUTPUT_SUBFOLDER) || !uniqueOutputDir.mkdir(RAW_OUTPUT_SUBFOLDER)) {
|
||||||
qCCritical(model_baking) << "Failed to create baked/original subfolders in" << _uniqueOutputPath;
|
qCCritical(model_baking) << "Failed to create baked/raw subfolders in" << _uniqueOutputPath;
|
||||||
|
|
||||||
emit finished();
|
emit finished();
|
||||||
return false;
|
return false;
|
||||||
|
@ -122,19 +122,19 @@ void FBXBaker::handleFBXNetworkReply() {
|
||||||
qCDebug(model_baking) << "Downloaded" << _fbxURL;
|
qCDebug(model_baking) << "Downloaded" << _fbxURL;
|
||||||
|
|
||||||
// grab the contents of the reply and make a copy in the output folder
|
// grab the contents of the reply and make a copy in the output folder
|
||||||
QFile copyOfOriginal(pathToCopyOfOriginal());
|
QFile copyOfRaw(pathToCopyOfRaw());
|
||||||
|
|
||||||
qDebug(model_baking) << "Writing copy of original FBX to" << copyOfOriginal.fileName();
|
qDebug(model_baking) << "Writing copy of raw FBX to" << copyOfRaw.fileName();
|
||||||
|
|
||||||
if (!copyOfOriginal.open(QIODevice::WriteOnly) || (copyOfOriginal.write(requestReply->readAll()) == -1)) {
|
if (!copyOfRaw.open(QIODevice::WriteOnly) || (copyOfRaw.write(requestReply->readAll()) == -1)) {
|
||||||
|
|
||||||
// add an error to the error list for this FBX stating that a duplicate of the original could not be made
|
// add an error to the error list for this FBX stating that a duplicate of the raw FBX could not be made
|
||||||
emit finished();
|
emit finished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// close that file now that we are done writing to it
|
// close that file now that we are done writing to it
|
||||||
copyOfOriginal.close();
|
copyOfRaw.close();
|
||||||
|
|
||||||
// kick off the bake process now that everything is ready to go
|
// kick off the bake process now that everything is ready to go
|
||||||
bake();
|
bake();
|
||||||
|
@ -157,9 +157,9 @@ bool FBXBaker::importScene() {
|
||||||
// create an FBX SDK importer
|
// create an FBX SDK importer
|
||||||
FbxImporter* importer = FbxImporter::Create(_sdkManager, "");
|
FbxImporter* importer = FbxImporter::Create(_sdkManager, "");
|
||||||
|
|
||||||
// import the copy of the original FBX file
|
// import the copy of the raw FBX file
|
||||||
QString originalCopyPath = pathToCopyOfOriginal();
|
QString rawCopyPath = pathToCopyOfRaw();
|
||||||
bool importStatus = importer->Initialize(originalCopyPath.toLocal8Bit().data());
|
bool importStatus = importer->Initialize(rawCopyPath.toLocal8Bit().data());
|
||||||
|
|
||||||
if (!importStatus) {
|
if (!importStatus) {
|
||||||
// failed to initialize importer, print an error and return
|
// failed to initialize importer, print an error and return
|
||||||
|
@ -296,10 +296,8 @@ bool FBXBaker::rewriteAndBakeSceneTextures() {
|
||||||
// add the deduced url to the texture, associated with the resulting baked texture file name, to our hash
|
// add the deduced url to the texture, associated with the resulting baked texture file name, to our hash
|
||||||
_unbakedTextures.insert(urlToTexture, bakedTextureFileName);
|
_unbakedTextures.insert(urlToTexture, bakedTextureFileName);
|
||||||
|
|
||||||
// start a bake for this texture and add it to our list to keep track of
|
// bake this texture asynchronously
|
||||||
auto bakingTexture = new TextureBaker(urlToTexture);
|
bakeTexture(urlToTexture);
|
||||||
bakingTexture->start();
|
|
||||||
_bakingTextures.emplace_back(bakingTexture);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,6 +305,53 @@ bool FBXBaker::rewriteAndBakeSceneTextures() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FBXBaker::bakeTexture(const QUrl& textureURL) {
|
||||||
|
// start a bake for this texture and add it to our list to keep track of
|
||||||
|
auto bakingTexture = new TextureBaker(textureURL);
|
||||||
|
|
||||||
|
connect(bakingTexture, &TextureBaker::finished, this, &FBXBaker::handleBakedTexture);
|
||||||
|
|
||||||
|
bakingTexture->start();
|
||||||
|
|
||||||
|
_bakingTextures.emplace_back(bakingTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FBXBaker::handleBakedTexture() {
|
||||||
|
auto bakedTexture = qobject_cast<TextureBaker*>(sender());
|
||||||
|
|
||||||
|
// use the path to the texture being baked to determine if this was an embedded or a linked texture
|
||||||
|
|
||||||
|
// it is embeddded if the texure being baked was inside the unbaked output folder
|
||||||
|
//
|
||||||
|
|
||||||
|
auto rawOutputFolder = QUrl::fromLocalFile(_uniqueOutputPath + RAW_OUTPUT_SUBFOLDER);
|
||||||
|
|
||||||
|
if (!rawOutputFolder.isParentOf(bakedTexture->getTextureURL())) {
|
||||||
|
// for linked textures we want to save a copy of original texture beside the original FBX
|
||||||
|
|
||||||
|
qCDebug(model_baking) << "Saving raw texture for" << bakedTexture->getTextureURL();
|
||||||
|
|
||||||
|
// check if we have a relative path to use for the texture
|
||||||
|
auto relativeTexturePath = texturePathRelativeToFBX(_fbxURL, bakedTexture->getTextureURL());
|
||||||
|
|
||||||
|
QFile originalTextureFile {
|
||||||
|
_uniqueOutputPath + RAW_OUTPUT_SUBFOLDER + relativeTexturePath + bakedTexture->getTextureURL().fileName()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (relativeTexturePath.length() > 0) {
|
||||||
|
// make the folders needed by the relative path
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originalTextureFile.open(QIODevice::WriteOnly) && originalTextureFile.write(bakedTexture->getOriginalTexture()) != -1) {
|
||||||
|
qCDebug(model_baking) << "Saved original texture file" << originalTextureFile.fileName()
|
||||||
|
<< "for" << _fbxURL;
|
||||||
|
} else {
|
||||||
|
qCWarning(model_baking) << "Could not save original external texture" << originalTextureFile.fileName()
|
||||||
|
<< "for" << _fbxURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const QString BAKED_FBX_EXTENSION = ".baked.fbx";
|
static const QString BAKED_FBX_EXTENSION = ".baked.fbx";
|
||||||
|
|
||||||
bool FBXBaker::exportScene() {
|
bool FBXBaker::exportScene() {
|
||||||
|
@ -336,7 +381,7 @@ bool FBXBaker::exportScene() {
|
||||||
bool FBXBaker::removeEmbeddedMediaFolder() {
|
bool FBXBaker::removeEmbeddedMediaFolder() {
|
||||||
// now that the bake is complete, remove the embedded media folder produced by the FBX SDK when it imports an FBX
|
// 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");
|
auto embeddedMediaFolderName = _fbxURL.fileName().replace(".fbx", ".fbm");
|
||||||
QDir(_uniqueOutputPath + ORIGINAL_OUTPUT_SUBFOLDER + embeddedMediaFolderName).removeRecursively();
|
QDir(_uniqueOutputPath + RAW_OUTPUT_SUBFOLDER + embeddedMediaFolderName).removeRecursively();
|
||||||
|
|
||||||
// we always return true because a failure to delete the embedded media folder is not a failure of the bake
|
// we always return true because a failure to delete the embedded media folder is not a failure of the bake
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -38,6 +38,7 @@ signals:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleFBXNetworkReply();
|
void handleFBXNetworkReply();
|
||||||
|
void handleBakedTexture();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void bake();
|
void bake();
|
||||||
|
@ -48,7 +49,9 @@ private:
|
||||||
bool exportScene();
|
bool exportScene();
|
||||||
bool removeEmbeddedMediaFolder();
|
bool removeEmbeddedMediaFolder();
|
||||||
|
|
||||||
QString pathToCopyOfOriginal() const;
|
void bakeTexture(const QUrl& textureURL);
|
||||||
|
|
||||||
|
QString pathToCopyOfRaw() const;
|
||||||
|
|
||||||
QUrl _fbxURL;
|
QUrl _fbxURL;
|
||||||
QString _fbxName;
|
QString _fbxName;
|
||||||
|
|
|
@ -69,6 +69,9 @@ void TextureBaker::handleTextureNetworkReply() {
|
||||||
|
|
||||||
// store the original texture so it can be passed along for the bake
|
// store the original texture so it can be passed along for the bake
|
||||||
_originalTexture = requestReply->readAll();
|
_originalTexture = requestReply->readAll();
|
||||||
|
|
||||||
|
// kickoff the texture bake now that everything is ready to go
|
||||||
|
bake();
|
||||||
} else {
|
} else {
|
||||||
qCDebug(model_baking) << "Error downloading texture" << requestReply->errorString();
|
qCDebug(model_baking) << "Error downloading texture" << requestReply->errorString();
|
||||||
}
|
}
|
||||||
|
@ -78,4 +81,5 @@ void TextureBaker::bake() {
|
||||||
qCDebug(model_baking) << "Baking texture at" << _textureURL;
|
qCDebug(model_baking) << "Baking texture at" << _textureURL;
|
||||||
|
|
||||||
// call image library to asynchronously bake this texture
|
// call image library to asynchronously bake this texture
|
||||||
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue