diff --git a/src/document.cpp b/src/document.cpp index 4997b8bd..001f6da3 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -26,6 +26,9 @@ Document::Document() : textureColorImage(nullptr), textureNormalImage(nullptr), textureMetalnessRoughnessAmbientOcclusionImage(nullptr), + textureMetalnessImage(nullptr), + textureRoughnessImage(nullptr), + textureAmbientOcclusionImage(nullptr), rigType(RigType::None), weldEnabled(true), // private @@ -66,6 +69,9 @@ Document::~Document() delete textureColorImage; delete textureNormalImage; delete textureMetalnessRoughnessAmbientOcclusionImage; + delete textureMetalnessImage; + delete textureRoughnessImage; + delete textureAmbientOcclusionImage; delete textureBorderImage; delete m_resultTextureMesh; delete m_resultRigWeightMesh; @@ -1523,6 +1529,15 @@ void Document::textureReady() delete textureMetalnessRoughnessAmbientOcclusionImage; textureMetalnessRoughnessAmbientOcclusionImage = m_textureGenerator->takeResultTextureMetalnessRoughnessAmbientOcclusionImage(); + delete textureMetalnessImage; + textureMetalnessImage = m_textureGenerator->takeResultTextureMetalnessImage(); + + delete textureRoughnessImage; + textureRoughnessImage = m_textureGenerator->takeResultTextureRoughnessImage(); + + delete textureAmbientOcclusionImage; + textureAmbientOcclusionImage = m_textureGenerator->takeResultTextureAmbientOcclusionImage(); + delete m_resultTextureMesh; m_resultTextureMesh = m_textureGenerator->takeResultMesh(); diff --git a/src/document.h b/src/document.h index 97cb815d..3d557a97 100644 --- a/src/document.h +++ b/src/document.h @@ -453,6 +453,9 @@ public: // need initialize QImage *textureColorImage; QImage *textureNormalImage; QImage *textureMetalnessRoughnessAmbientOcclusionImage; + QImage *textureMetalnessImage; + QImage *textureRoughnessImage; + QImage *textureAmbientOcclusionImage; RigType rigType; bool weldEnabled; public: diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 900fabc7..245d8933 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -1270,7 +1270,11 @@ void DocumentWindow::exportFbxResult() exportMotions.push_back({motion->name, motion->jointNodeTrees}); } FbxFileWriter fbxFileWriter(skeletonResult, m_document->resultRigBones(), m_document->resultRigWeights(), filename, - m_document->textureImage, m_document->textureNormalImage, m_document->textureMetalnessRoughnessAmbientOcclusionImage, + m_document->textureImage, + m_document->textureNormalImage, + m_document->textureMetalnessImage, + m_document->textureRoughnessImage, + m_document->textureAmbientOcclusionImage, exportMotions.empty() ? nullptr : &exportMotions); fbxFileWriter.save(); QApplication::restoreOverrideCursor(); diff --git a/src/fbxfile.cpp b/src/fbxfile.cpp index a3e558bc..46353af5 100644 --- a/src/fbxfile.cpp +++ b/src/fbxfile.cpp @@ -2206,7 +2206,9 @@ FbxFileWriter::FbxFileWriter(Outcome &outcome, const QString &filename, QImage *textureImage, QImage *normalImage, - QImage *ormImage, + QImage *metalnessImage, + QImage *roughnessImage, + QImage *ambientOcclusionImage, const std::vector>>> *motions) : m_filename(filename), m_baseName(QFileInfo(m_filename).baseName()) @@ -2922,7 +2924,7 @@ FbxFileWriter::FbxFileWriter(Outcome &outcome, p.addProperty("float"); p.addProperty(""); p.addProperty(""); - p.addProperty((float)0.000000); + p.addProperty(metalnessImage ? (float)1.000000 : (float)0.000000); properties.addChild(p); } { @@ -2950,7 +2952,7 @@ FbxFileWriter::FbxFileWriter(Outcome &outcome, p.addProperty("float"); p.addProperty(""); p.addProperty(""); - p.addProperty((float)0.000000); + p.addProperty(roughnessImage ? (float)1.000000 : (float)0.000000); properties.addChild(p); } { @@ -3029,7 +3031,7 @@ FbxFileWriter::FbxFileWriter(Outcome &outcome, p.addProperty("float"); p.addProperty(""); p.addProperty(""); - p.addProperty((float)0.000000); + p.addProperty(ambientOcclusionImage ? (float)1.000000 : (float)0.000000); properties.addChild(p); } { @@ -3577,6 +3579,27 @@ FbxFileWriter::FbxFileWriter(Outcome &outcome, m_baseName + "_normal.png", "Maya|TEX_normal_map"); } + if (nullptr != metalnessImage) { + addTexture(metalnessImage, + std::vector({'V','i','d','e','o',0,1,'M','e','t','a','l','l','i','c'}), + std::vector({'T','e','x','t','u','r','e',0,1,'M','e','t','a','l','l','i','c'}), + m_baseName + "_metallic.png", + "Maya|TEX_metallic_map"); + } + if (nullptr != roughnessImage) { + addTexture(roughnessImage, + std::vector({'V','i','d','e','o',0,1,'R','o','u','g','h','n','e','s','s'}), + std::vector({'T','e','x','t','u','r','e',0,1,'R','o','u','g','h','n','e','s','s'}), + m_baseName + "_roughness.png", + "Maya|TEX_roughness_map"); + } + if (nullptr != ambientOcclusionImage) { + addTexture(ambientOcclusionImage, + std::vector({'V','i','d','e','o',0,1,'A','o'}), + std::vector({'T','e','x','t','u','r','e',0,1,'A','o'}), + m_baseName + "_ao.png", + "Maya|TEX_ao_map"); + } /* if (nullptr != textureImage) { addTexture(textureImage, diff --git a/src/fbxfile.h b/src/fbxfile.h index 2aef68ba..452e23fc 100644 --- a/src/fbxfile.h +++ b/src/fbxfile.h @@ -19,7 +19,9 @@ public: const QString &filename, QImage *textureImage=nullptr, QImage *normalImage=nullptr, - QImage *ormImage=nullptr, + QImage *metalnessImage=nullptr, + QImage *roughnessImage=nullptr, + QImage *ambientOcclusionImage=nullptr, const std::vector>>> *motions=nullptr); bool save(); diff --git a/src/texturegenerator.cpp b/src/texturegenerator.cpp index 94ef88c1..f3fd56e5 100644 --- a/src/texturegenerator.cpp +++ b/src/texturegenerator.cpp @@ -86,6 +86,27 @@ QImage *TextureGenerator::takeResultTextureMetalnessRoughnessAmbientOcclusionIma return resultTextureMetalnessRoughnessAmbientOcclusionImage; } +QImage *TextureGenerator::takeResultTextureRoughnessImage() +{ + QImage *resultTextureRoughnessImage = m_resultTextureRoughnessImage; + m_resultTextureRoughnessImage = nullptr; + return resultTextureRoughnessImage; +} + +QImage *TextureGenerator::takeResultTextureMetalnessImage() +{ + QImage *resultTextureMetalnessImage = m_resultTextureMetalnessImage; + m_resultTextureMetalnessImage = nullptr; + return resultTextureMetalnessImage; +} + +QImage *TextureGenerator::takeResultTextureAmbientOcclusionImage() +{ + QImage *resultTextureAmbientOcclusionImage = m_resultTextureAmbientOcclusionImage; + m_resultTextureAmbientOcclusionImage = nullptr; + return resultTextureAmbientOcclusionImage; +} + Outcome *TextureGenerator::takeOutcome() { Outcome *outcome = m_outcome; @@ -386,6 +407,18 @@ void TextureGenerator::generate() m_resultTextureMetalnessRoughnessAmbientOcclusionImage->setPixelColor(col, row, color); } } + if (!hasMetalnessMap) { + delete m_resultTextureMetalnessImage; + m_resultTextureMetalnessImage = nullptr; + } + if (!hasRoughnessMap) { + delete m_resultTextureRoughnessImage; + m_resultTextureRoughnessImage = nullptr; + } + if (!hasAmbientOcclusionMap) { + delete m_resultTextureAmbientOcclusionImage; + m_resultTextureAmbientOcclusionImage = nullptr; + } } auto mergeMetalnessRoughnessAmbientOcclusionEndTime = countTimeConsumed.elapsed(); diff --git a/src/texturegenerator.h b/src/texturegenerator.h index ad4fba09..43699b65 100644 --- a/src/texturegenerator.h +++ b/src/texturegenerator.h @@ -19,6 +19,9 @@ public: QImage *takeResultTextureColorImage(); QImage *takeResultTextureNormalImage(); QImage *takeResultTextureMetalnessRoughnessAmbientOcclusionImage(); + QImage *takeResultTextureRoughnessImage(); + QImage *takeResultTextureMetalnessImage(); + QImage *takeResultTextureAmbientOcclusionImage(); Outcome *takeOutcome(); MeshLoader *takeResultMesh(); void addPartColorMap(QUuid partId, const QImage *image);