Fix alphaMode of glb exporting

Only export alphaMode as BLEND when there are transparent parts.
master
Jeremy Hu 2020-02-27 19:27:09 +09:30
parent 9e7f39e0d4
commit c4639d77ae
7 changed files with 22 additions and 2 deletions

View File

@ -37,6 +37,7 @@ Document::Document() :
textureMetalnessImage(nullptr), textureMetalnessImage(nullptr),
textureRoughnessImage(nullptr), textureRoughnessImage(nullptr),
textureAmbientOcclusionImage(nullptr), textureAmbientOcclusionImage(nullptr),
textureHasTransparencySettings(false),
rigType(RigType::None), rigType(RigType::None),
weldEnabled(true), weldEnabled(true),
polyCount(PolyCount::Original), polyCount(PolyCount::Original),
@ -2087,6 +2088,8 @@ void Document::textureReady()
delete m_resultTextureMesh; delete m_resultTextureMesh;
m_resultTextureMesh = m_textureGenerator->takeResultMesh(); m_resultTextureMesh = m_textureGenerator->takeResultMesh();
textureHasTransparencySettings = m_textureGenerator->hasTransparencySettings();
//addToolToMesh(m_resultTextureMesh); //addToolToMesh(m_resultTextureMesh);
m_textureImageUpdateVersion++; m_textureImageUpdateVersion++;

View File

@ -534,6 +534,7 @@ public: // need initialize
QImage *textureMetalnessImage; QImage *textureMetalnessImage;
QImage *textureRoughnessImage; QImage *textureRoughnessImage;
QImage *textureAmbientOcclusionImage; QImage *textureAmbientOcclusionImage;
bool textureHasTransparencySettings;
RigType rigType; RigType rigType;
bool weldEnabled; bool weldEnabled;
PolyCount polyCount; PolyCount polyCount;

View File

@ -1703,6 +1703,7 @@ void DocumentWindow::exportGlbToFilename(const QString &filename)
exportMotions.push_back({motion->name, motion->jointNodeTrees}); exportMotions.push_back({motion->name, motion->jointNodeTrees});
} }
GlbFileWriter glbFileWriter(skeletonResult, m_document->resultRigBones(), m_document->resultRigWeights(), filename, GlbFileWriter glbFileWriter(skeletonResult, m_document->resultRigBones(), m_document->resultRigWeights(), filename,
m_document->textureHasTransparencySettings,
m_document->textureImage, m_document->textureNormalImage, m_document->textureMetalnessRoughnessAmbientOcclusionImage, exportMotions.empty() ? nullptr : &exportMotions); m_document->textureImage, m_document->textureNormalImage, m_document->textureMetalnessRoughnessAmbientOcclusionImage, exportMotions.empty() ? nullptr : &exportMotions);
glbFileWriter.save(); glbFileWriter.save();
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();

View File

@ -26,6 +26,7 @@ GlbFileWriter::GlbFileWriter(Outcome &outcome,
const std::vector<RiggerBone> *resultRigBones, const std::vector<RiggerBone> *resultRigBones,
const std::map<int, RiggerVertexWeights> *resultRigWeights, const std::map<int, RiggerVertexWeights> *resultRigWeights,
const QString &filename, const QString &filename,
bool textureHasTransparencySettings,
QImage *textureImage, QImage *textureImage,
QImage *normalImage, QImage *normalImage,
QImage *ormImage, QImage *ormImage,
@ -169,7 +170,8 @@ GlbFileWriter::GlbFileWriter(Outcome &outcome,
m_json["materials"][primitiveIndex]["pbrMetallicRoughness"]["baseColorTexture"]["index"] = textureIndex++; m_json["materials"][primitiveIndex]["pbrMetallicRoughness"]["baseColorTexture"]["index"] = textureIndex++;
m_json["materials"][primitiveIndex]["pbrMetallicRoughness"]["metallicFactor"] = MeshLoader::m_defaultMetalness; m_json["materials"][primitiveIndex]["pbrMetallicRoughness"]["metallicFactor"] = MeshLoader::m_defaultMetalness;
m_json["materials"][primitiveIndex]["pbrMetallicRoughness"]["roughnessFactor"] = MeshLoader::m_defaultRoughness; m_json["materials"][primitiveIndex]["pbrMetallicRoughness"]["roughnessFactor"] = MeshLoader::m_defaultRoughness;
m_json["materials"][primitiveIndex]["alphaMode"] = "BLEND"; if (textureHasTransparencySettings)
m_json["materials"][primitiveIndex]["alphaMode"] = "BLEND";
if (normalImage) { if (normalImage) {
m_json["materials"][primitiveIndex]["normalTexture"]["index"] = textureIndex++; m_json["materials"][primitiveIndex]["normalTexture"]["index"] = textureIndex++;
} }

View File

@ -19,6 +19,7 @@ public:
const std::vector<RiggerBone> *resultRigBones, const std::vector<RiggerBone> *resultRigBones,
const std::map<int, RiggerVertexWeights> *resultRigWeights, const std::map<int, RiggerVertexWeights> *resultRigWeights,
const QString &filename, const QString &filename,
bool textureHasTransparencySettings,
QImage *textureImage=nullptr, QImage *textureImage=nullptr,
QImage *normalImage=nullptr, QImage *normalImage=nullptr,
QImage *ormImage=nullptr, QImage *ormImage=nullptr,

View File

@ -24,7 +24,8 @@ TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) :
m_resultTextureMetalnessImage(nullptr), m_resultTextureMetalnessImage(nullptr),
m_resultTextureAmbientOcclusionImage(nullptr), m_resultTextureAmbientOcclusionImage(nullptr),
m_resultMesh(nullptr), m_resultMesh(nullptr),
m_snapshot(snapshot) m_snapshot(snapshot),
m_hasTransparencySettings(false)
{ {
m_outcome = new Outcome(); m_outcome = new Outcome();
*m_outcome = outcome; *m_outcome = outcome;
@ -210,6 +211,11 @@ void TextureGenerator::prepare()
} }
} }
bool TextureGenerator::hasTransparencySettings()
{
return m_hasTransparencySettings;
}
void TextureGenerator::generate() void TextureGenerator::generate()
{ {
m_resultMesh = new MeshLoader(*m_outcome); m_resultMesh = new MeshLoader(*m_outcome);
@ -240,6 +246,10 @@ void TextureGenerator::generate()
std::map<std::pair<QUuid, QUuid>, const OutcomeNode *> nodeMap; std::map<std::pair<QUuid, QUuid>, const OutcomeNode *> nodeMap;
std::map<QUuid, float> partColorSolubilityMap; std::map<QUuid, float> partColorSolubilityMap;
for (const auto &item: m_outcome->nodes) { for (const auto &item: m_outcome->nodes) {
if (!m_hasTransparencySettings) {
if (!qFuzzyCompare(1.0, item.color.alphaF()))
m_hasTransparencySettings = true;
}
nodeMap.insert({{item.partId, item.nodeId}, &item}); nodeMap.insert({{item.partId, item.nodeId}, &item});
partColorMap.insert({item.partId, item.color}); partColorMap.insert({item.partId, item.color});
partColorSolubilityMap.insert({item.partId, item.colorSolubility}); partColorSolubilityMap.insert({item.partId, item.colorSolubility});

View File

@ -26,6 +26,7 @@ public:
QImage *takeResultTextureAmbientOcclusionImage(); QImage *takeResultTextureAmbientOcclusionImage();
Outcome *takeOutcome(); Outcome *takeOutcome();
MeshLoader *takeResultMesh(); MeshLoader *takeResultMesh();
bool hasTransparencySettings();
void addPartColorMap(QUuid partId, const QImage *image, float tileScale); void addPartColorMap(QUuid partId, const QImage *image, float tileScale);
void addPartNormalMap(QUuid partId, const QImage *image, float tileScale); void addPartNormalMap(QUuid partId, const QImage *image, float tileScale);
void addPartMetalnessMap(QUuid partId, const QImage *image, float tileScale); void addPartMetalnessMap(QUuid partId, const QImage *image, float tileScale);
@ -60,6 +61,7 @@ private:
std::map<QUuid, std::pair<QImage, float>> m_partAmbientOcclusionTextureMap; std::map<QUuid, std::pair<QImage, float>> m_partAmbientOcclusionTextureMap;
std::set<QUuid> m_countershadedPartIds; std::set<QUuid> m_countershadedPartIds;
Snapshot *m_snapshot; Snapshot *m_snapshot;
bool m_hasTransparencySettings;
}; };
#endif #endif