void OBJBaker::bakeOBJ() { // Read the OBJ file QFile objFile(_originalModelFilePath); if (!objFile.open(QIODevice::ReadOnly)) { handleError("Error opening " + _originalModelFilePath + " for reading"); return; } QByteArray objData = objFile.readAll(); bool combineParts = true; // set true so that OBJReader reads material info from material library OBJReader reader; auto geometry = reader.readOBJ(objData, QVariantHash(), combineParts, _modelURL); // Write OBJ Data as FBX tree nodes createFBXNodeTree(_rootNode, *geometry); checkIfTexturesFinished(); }
void ModelBaker::handleAbortedTexture() { // grab the texture bake that was aborted and remove it from our hash since we don't need to track it anymore TextureBaker* bakedTexture = qobject_cast<TextureBaker*>(sender()); qDebug() << "Texture aborted: " << bakedTexture->getTextureURL(); if (bakedTexture) { _bakingTextures.remove(bakedTexture->getTextureURL()); } // since a texture we were baking aborted, our status is also aborted _shouldAbort.store(true); // abort any other ongoing texture bakes since we know we'll end up failing for (auto& bakingTexture : _bakingTextures) { bakingTexture->abort(); } checkIfTexturesFinished(); }
void ModelBaker::handleBakedTexture() { TextureBaker* bakedTexture = qobject_cast<TextureBaker*>(sender()); qDebug() << "Handling baked texture" << bakedTexture->getTextureURL(); // make sure we haven't already run into errors, and that this is a valid texture if (bakedTexture) { if (!shouldStop()) { if (!bakedTexture->hasErrors()) { if (!_originalOutputDir.isEmpty()) { // we've been asked to make copies of the originals, so we need to make copies of this if it is a linked texture // 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 a folder with the name of the model // since that is the fake URL we provide when baking external textures if (!_modelURL.isParentOf(bakedTexture->getTextureURL())) { // for linked textures we want to save a copy of original texture beside the original model qCDebug(model_baking) << "Saving original texture for" << bakedTexture->getTextureURL(); // check if we have a relative path to use for the texture auto relativeTexturePath = texturePathRelativeToModel(_modelURL, bakedTexture->getTextureURL()); QFile originalTextureFile{ _originalOutputDir + "/" + 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" << _modelURL; } else { handleError("Could not save original external texture " + originalTextureFile.fileName() + " for " + _modelURL.toString()); return; } } } // now that this texture has been baked and handled, we can remove that TextureBaker from our hash _bakingTextures.remove(bakedTexture->getTextureURL()); checkIfTexturesFinished(); } else { // there was an error baking this texture - add it to our list of errors _errorList.append(bakedTexture->getErrors()); // we don't emit finished yet so that the other textures can finish baking first _pendingErrorEmission = true; // now that this texture has been baked, even though it failed, we can remove that TextureBaker from our list _bakingTextures.remove(bakedTexture->getTextureURL()); // abort any other ongoing texture bakes since we know we'll end up failing for (auto& bakingTexture : _bakingTextures) { bakingTexture->abort(); } checkIfTexturesFinished(); } } else { // we have errors to attend to, so we don't do extra processing for this texture // but we do need to remove that TextureBaker from our list // and then check if we're done with all textures _bakingTextures.remove(bakedTexture->getTextureURL()); checkIfTexturesFinished(); } } }