Improve mesh generation

1. All components recombined regardless of color groups
2. Contour main view contribute to x-coord only when width and height is different (Offset greater than radius)
3. Fix generating indicator
master
Jeremy Hu 2020-01-02 22:06:43 +09:30
parent f2093bd42a
commit ee53e3ed4f
5 changed files with 33 additions and 8 deletions

View File

@ -219,11 +219,18 @@ void ContourToPartConverter::convert()
if (!sideSkeleton.empty()) { if (!sideSkeleton.empty()) {
alignSkeleton(sideSkeleton, mainSkeleton); alignSkeleton(sideSkeleton, mainSkeleton);
float defaultX = mainBoundingBox.center().x() / m_canvasSize.height(); float defaultX = mainBoundingBox.center().x() / m_canvasSize.height();
float area = mainBoundingBox.width() * mainBoundingBox.height();
float mainBoundingBoxWidthHeightOffset = std::abs(mainBoundingBox.width() - mainBoundingBox.height());
float rectRadius = std::sqrt(area) * 0.5;
bool useCalculatedX = mainBoundingBoxWidthHeightOffset >= rectRadius;
m_nodes.reserve(sideSkeleton.size()); m_nodes.reserve(sideSkeleton.size());
for (size_t i = 0; i < sideSkeleton.size(); ++i) { for (size_t i = 0; i < sideSkeleton.size(); ++i) {
const auto &it = sideSkeleton[i]; const auto &it = sideSkeleton[i];
float x = defaultX;
if (useCalculatedX) {
size_t j = ((float)i / sideSkeleton.size()) * mainSkeleton.size(); size_t j = ((float)i / sideSkeleton.size()) * mainSkeleton.size();
float x = j < mainSkeleton.size() ? mainSkeleton[j].first.x() : defaultX; x = j < mainSkeleton.size() ? mainSkeleton[j].first.x() : defaultX;
}
m_nodes.push_back(std::make_pair(QVector3D(x, it.first.y(), it.first.x()), m_nodes.push_back(std::make_pair(QVector3D(x, it.first.y(), it.first.x()),
it.second)); it.second));
} }
@ -243,6 +250,7 @@ void ContourToPartConverter::nodesToSnapshot()
snapshotPart["id"] = partIdString; snapshotPart["id"] = partIdString;
snapshotPart["subdived"] = "true"; snapshotPart["subdived"] = "true";
snapshotPart["rounded"] = "true"; snapshotPart["rounded"] = "true";
snapshotPart["base"] = "YZ";
m_snapshot.parts[partIdString] = snapshotPart; m_snapshot.parts[partIdString] = snapshotPart;
auto componentId = QUuid::createUuid(); auto componentId = QUuid::createUuid();

View File

@ -2037,6 +2037,8 @@ void Document::generateMesh()
return; return;
} }
emit meshGenerating();
qDebug() << "Mesh generating.."; qDebug() << "Mesh generating..";
settleOrigin(); settleOrigin();
@ -2060,7 +2062,6 @@ void Document::generateMesh()
connect(m_meshGenerator, &MeshGenerator::finished, this, &Document::meshReady); connect(m_meshGenerator, &MeshGenerator::finished, this, &Document::meshReady);
connect(m_meshGenerator, &MeshGenerator::finished, thread, &QThread::quit); connect(m_meshGenerator, &MeshGenerator::finished, thread, &QThread::quit);
connect(thread, &QThread::finished, thread, &QThread::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater);
emit meshGenerating();
thread->start(); thread->start();
} }
@ -2072,6 +2073,7 @@ void Document::generateTexture()
} }
qDebug() << "Texture guide generating.."; qDebug() << "Texture guide generating..";
emit textureGenerating();
m_isTextureObsolete = false; m_isTextureObsolete = false;
@ -2085,7 +2087,6 @@ void Document::generateTexture()
connect(m_textureGenerator, &TextureGenerator::finished, this, &Document::textureReady); connect(m_textureGenerator, &TextureGenerator::finished, this, &Document::textureReady);
connect(m_textureGenerator, &TextureGenerator::finished, thread, &QThread::quit); connect(m_textureGenerator, &TextureGenerator::finished, thread, &QThread::quit);
connect(thread, &QThread::finished, thread, &QThread::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater);
emit textureGenerating();
thread->start(); thread->start();
} }
@ -2154,6 +2155,7 @@ void Document::postProcess()
} }
qDebug() << "Post processing.."; qDebug() << "Post processing..";
emit postProcessing();
QThread *thread = new QThread; QThread *thread = new QThread;
m_postProcessor = new MeshResultPostProcessor(*m_currentOutcome); m_postProcessor = new MeshResultPostProcessor(*m_currentOutcome);
@ -2162,7 +2164,6 @@ void Document::postProcess()
connect(m_postProcessor, &MeshResultPostProcessor::finished, this, &Document::postProcessedMeshResultReady); connect(m_postProcessor, &MeshResultPostProcessor::finished, this, &Document::postProcessedMeshResultReady);
connect(m_postProcessor, &MeshResultPostProcessor::finished, thread, &QThread::quit); connect(m_postProcessor, &MeshResultPostProcessor::finished, thread, &QThread::quit);
connect(thread, &QThread::finished, thread, &QThread::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater);
emit postProcessing();
thread->start(); thread->start();
} }
@ -3782,6 +3783,16 @@ bool Document::isMeshGenerating() const
return nullptr != m_meshGenerator; return nullptr != m_meshGenerator;
} }
bool Document::isPostProcessing() const
{
return nullptr != m_postProcessor;
}
bool Document::isTextureGenerating() const
{
return nullptr != m_textureGenerator;
}
void Document::copyNodes(std::set<QUuid> nodeIdSet) const void Document::copyNodes(std::set<QUuid> nodeIdSet) const
{ {
Snapshot snapshot; Snapshot snapshot;

View File

@ -558,6 +558,8 @@ public:
const Outcome &currentRiggedOutcome() const; const Outcome &currentRiggedOutcome() const;
bool currentRigSucceed() const; bool currentRigSucceed() const;
bool isMeshGenerating() const; bool isMeshGenerating() const;
bool isPostProcessing() const;
bool isTextureGenerating() const;
const QString &script() const; const QString &script() const;
const std::map<QString, std::map<QString, QString>> &variables() const; const std::map<QString, std::map<QString, QString>> &variables() const;
const QString &scriptError() const; const QString &scriptError() const;

View File

@ -238,7 +238,11 @@ DocumentWindow::DocumentWindow() :
regenerateButton->showSpinner(true); regenerateButton->showSpinner(true);
}); });
connect(m_document, &Document::resultTextureChanged, this, [=]() { connect(m_document, &Document::resultTextureChanged, this, [=]() {
if (!m_document->isMeshGenerating() &&
!m_document->isPostProcessing() &&
!m_document->isTextureGenerating()) {
regenerateButton->showSpinner(false); regenerateButton->showSpinner(false);
}
}); });
connect(regenerateButton->button(), &QPushButton::clicked, m_document, &Document::regenerateMesh); connect(regenerateButton->button(), &QPushButton::clicked, m_document, &Document::regenerateMesh);

View File

@ -1010,12 +1010,12 @@ MeshCombiner::Mesh *MeshGenerator::combineComponentMesh(const QString &component
subGroupMeshIdStringList += componentChildGroupIdStringListString; subGroupMeshIdStringList += componentChildGroupIdStringListString;
multipleMeshes.push_back(std::make_tuple(childMesh, CombineMode::Normal, componentChildGroupIdStringListString)); multipleMeshes.push_back(std::make_tuple(childMesh, CombineMode::Normal, componentChildGroupIdStringListString));
} }
MeshCombiner::Mesh *subGroupMesh = combineMultipleMeshes(multipleMeshes, foundColorSolubilitySetting); MeshCombiner::Mesh *subGroupMesh = combineMultipleMeshes(multipleMeshes, true/*foundColorSolubilitySetting*/);
if (nullptr == subGroupMesh) if (nullptr == subGroupMesh)
continue; continue;
groupMeshes.push_back(std::make_tuple(subGroupMesh, group.first, subGroupMeshIdStringList.join("&"))); groupMeshes.push_back(std::make_tuple(subGroupMesh, group.first, subGroupMeshIdStringList.join("&")));
} }
mesh = combineMultipleMeshes(groupMeshes, false); mesh = combineMultipleMeshes(groupMeshes, true);
} }
if (nullptr != mesh) if (nullptr != mesh)