mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:28:09 +02:00
Moved _textureContent to parent class ModelBaker
This commit is contained in:
parent
221b293daf
commit
54f9d52aa1
5 changed files with 19 additions and 48 deletions
|
@ -365,21 +365,18 @@ void FBXBaker::rewriteAndBakeSceneTextures() {
|
||||||
textureContent = _textureContent.value(fbxTextureFileName.toLocal8Bit());
|
textureContent = _textureContent.value(fbxTextureFileName.toLocal8Bit());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback to get texture content and type
|
// Callback to get texture type
|
||||||
getTextureContentTypeCallback textureContentTypeCallback = [=]() {
|
getTextureTypeCallback textureTypeCallback = [=]() {
|
||||||
QPair<QByteArray, image::TextureUsage::Type> result;
|
|
||||||
result.first = textureContent;
|
|
||||||
// grab the ID for this texture so we can figure out the
|
// grab the ID for this texture so we can figure out the
|
||||||
// texture type from the loaded materials
|
// texture type from the loaded materials
|
||||||
auto textureID{ object->properties[0].toByteArray() };
|
auto textureID{ object->properties[0].toByteArray() };
|
||||||
auto textureType = textureTypes[textureID];
|
auto textureType = textureTypes[textureID];
|
||||||
result.second = textureType;
|
return textureType;
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compress the texture information and return the new filename to be added into the FBX scene
|
// Compress the texture information and return the new filename to be added into the FBX scene
|
||||||
QByteArray* bakedTextureFile = this->compressTexture(fbxTextureFileName, _fbxURL, _bakedOutputDir, _textureThreadGetter,
|
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 no errors or warnings have occurred during texture compression add the filename to the FBX scene
|
||||||
if (bakedTextureFile) {
|
if (bakedTextureFile) {
|
||||||
|
@ -431,25 +428,3 @@ void FBXBaker::exportScene() {
|
||||||
|
|
||||||
qCDebug(model_baking) << "Exported" << _fbxURL << "with re-written paths to" << _bakedFBXFilePath;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -62,13 +62,10 @@ private:
|
||||||
void exportScene();
|
void exportScene();
|
||||||
void removeEmbeddedMediaFolder();
|
void removeEmbeddedMediaFolder();
|
||||||
|
|
||||||
void checkIfTexturesFinished();
|
|
||||||
|
|
||||||
QUrl _fbxURL;
|
QUrl _fbxURL;
|
||||||
|
|
||||||
FBXNode _rootNode;
|
FBXNode _rootNode;
|
||||||
FBXGeometry* _geometry;
|
FBXGeometry* _geometry;
|
||||||
QHash<QByteArray, QByteArray> _textureContent;
|
|
||||||
|
|
||||||
QString _bakedFBXFilePath;
|
QString _bakedFBXFilePath;
|
||||||
|
|
||||||
|
|
|
@ -207,21 +207,17 @@ bool ModelBaker::compressMesh(FBXMesh& mesh, bool hasDeformers,FBXNode& dracoMes
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, QUrl modelURL, QString bakedOutputDir, TextureBakerThreadGetter textureThreadGetter,
|
QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, QUrl modelURL, QString bakedOutputDir, TextureBakerThreadGetter textureThreadGetter,
|
||||||
getTextureContentTypeCallback textureContentTypeCallback, const QString& originalOutputDir) {
|
getTextureTypeCallback textureTypeCallback, const QString& originalOutputDir) {
|
||||||
_modelURL = modelURL;
|
_modelURL = modelURL;
|
||||||
_textureThreadGetter = textureThreadGetter;
|
_textureThreadGetter = textureThreadGetter;
|
||||||
_originalOutputDir = originalOutputDir;
|
_originalOutputDir = originalOutputDir;
|
||||||
|
|
||||||
static QByteArray textureChild;
|
static QByteArray textureChild;
|
||||||
|
|
||||||
QPair<QByteArray, image::TextureUsage::Type> textureContentType;
|
|
||||||
QByteArray textureContent;
|
QByteArray textureContent;
|
||||||
image::TextureUsage::Type textureType;
|
image::TextureUsage::Type textureType;
|
||||||
|
|
||||||
if (textureContentTypeCallback) {
|
if (textureTypeCallback) {
|
||||||
textureContentType = textureContentTypeCallback();
|
textureType = textureTypeCallback();
|
||||||
textureContent = textureContentType.first;
|
|
||||||
textureType = textureContentType.second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo modelTextureFileInfo{ modelTextureFileName.replace("\\", "/") };
|
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
|
// 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
|
// 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());
|
auto urlToTexture = getTextureURL(modelTextureFileInfo, modelTextureFileName, !textureContent.isNull());
|
||||||
|
|
||||||
QString bakedTextureFileName;
|
QString bakedTextureFileName;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
using TextureBakerThreadGetter = std::function<QThread*()>;
|
using TextureBakerThreadGetter = std::function<QThread*()>;
|
||||||
using getMaterialIDCallback = std::function <int(int)>;
|
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{
|
class ModelBaker : public Baker{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -37,8 +37,12 @@ public:
|
||||||
ModelBaker();
|
ModelBaker();
|
||||||
bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, getMaterialIDCallback materialIDCallback = NULL);
|
bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, getMaterialIDCallback materialIDCallback = NULL);
|
||||||
QByteArray* compressTexture(QString textureFileName, QUrl modelUrl, QString bakedOutputDir, TextureBakerThreadGetter textureThreadGetter,
|
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;
|
virtual void setWasAborted(bool wasAborted) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void checkIfTexturesFinished();
|
||||||
|
QHash<QByteArray, QByteArray> _textureContent;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void bake() override;
|
virtual void bake() override;
|
||||||
|
@ -53,7 +57,7 @@ private:
|
||||||
void bakeTexture(const QUrl & textureURL, image::TextureUsage::Type textureType, const QDir & outputDir,
|
void bakeTexture(const QUrl & textureURL, image::TextureUsage::Type textureType, const QDir & outputDir,
|
||||||
const QString & bakedFilename, const QByteArray & textureContent);
|
const QString & bakedFilename, const QByteArray & textureContent);
|
||||||
QString texturePathRelativeToModel(QUrl modelURL, QUrl textureURL);
|
QString texturePathRelativeToModel(QUrl modelURL, QUrl textureURL);
|
||||||
void checkIfTexturesFinished();
|
|
||||||
|
|
||||||
QHash<QString, int> _textureNameMatchCount;
|
QHash<QString, int> _textureNameMatchCount;
|
||||||
QHash<QUrl, QString> _remappedTexturePaths;
|
QHash<QUrl, QString> _remappedTexturePaths;
|
||||||
|
|
|
@ -288,11 +288,8 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
QByteArray textureFileName = (!currentMaterial.albedoTexture.filename.isEmpty()) ? currentMaterial.albedoTexture.filename : currentMaterial.specularTexture.filename;
|
QByteArray textureFileName = (!currentMaterial.albedoTexture.filename.isEmpty()) ? currentMaterial.albedoTexture.filename : currentMaterial.specularTexture.filename;
|
||||||
|
|
||||||
// Callback to get Texture content and type
|
// Callback to get Texture content and type
|
||||||
getTextureContentTypeCallback textureContentTypeCallback = [=]() {
|
getTextureTypeCallback textureContentTypeCallback = [=]() {
|
||||||
QPair<QByteArray, image::TextureUsage::Type> result;
|
return (!currentMaterial.albedoTexture.filename.isEmpty()) ? image::TextureUsage::Type::ALBEDO_TEXTURE : image::TextureUsage::Type::SPECULAR_TEXTURE;
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compress the texture using ModelBaker::compressTexture() and store compressed file's name in the node
|
// Compress the texture using ModelBaker::compressTexture() and store compressed file's name in the node
|
||||||
|
|
Loading…
Reference in a new issue