Moved _textureContent to parent class ModelBaker

This commit is contained in:
utkarshgautamnyu 2017-10-25 14:15:55 -07:00
parent 221b293daf
commit 54f9d52aa1
5 changed files with 19 additions and 48 deletions

View file

@ -365,21 +365,18 @@ void FBXBaker::rewriteAndBakeSceneTextures() {
textureContent = _textureContent.value(fbxTextureFileName.toLocal8Bit());
}
// Callback to get texture content and type
getTextureContentTypeCallback textureContentTypeCallback = [=]() {
QPair<QByteArray, image::TextureUsage::Type> 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);
}
}
}

View file

@ -62,13 +62,10 @@ private:
void exportScene();
void removeEmbeddedMediaFolder();
void checkIfTexturesFinished();
QUrl _fbxURL;
FBXNode _rootNode;
FBXGeometry* _geometry;
QHash<QByteArray, QByteArray> _textureContent;
QString _bakedFBXFilePath;

View file

@ -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<QByteArray, image::TextureUsage::Type> 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;

View file

@ -28,7 +28,7 @@
using TextureBakerThreadGetter = std::function<QThread*()>;
using getMaterialIDCallback = std::function <int(int)>;
using getTextureContentTypeCallback = std::function<QPair<QByteArray, image::TextureUsage::Type>()>;
using getTextureTypeCallback = std::function<image::TextureUsage::Type()>;
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<QByteArray, QByteArray> _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<QString, int> _textureNameMatchCount;
QHash<QUrl, QString> _remappedTexturePaths;

View file

@ -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<QByteArray, image::TextureUsage::Type> 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