Implement section preview mesh builder

master
Jeremy HU 2022-10-18 19:39:48 +11:00
parent 066e16dcd6
commit 73f0404c2e
3 changed files with 30 additions and 54 deletions

View File

@ -860,7 +860,6 @@ void Document::generateMesh()
m_meshGenerator = new MeshGenerator(snapshot); m_meshGenerator = new MeshGenerator(snapshot);
m_meshGenerator->setId(m_nextMeshGenerationId++); m_meshGenerator->setId(m_nextMeshGenerationId++);
m_meshGenerator->setDefaultPartColor(dust3d::Color::createWhite()); m_meshGenerator->setDefaultPartColor(dust3d::Color::createWhite());
m_meshGenerator->setInterpolationEnabled(true);
if (nullptr == m_generatedCacheContext) if (nullptr == m_generatedCacheContext)
m_generatedCacheContext = new MeshGenerator::GeneratedCacheContext; m_generatedCacheContext = new MeshGenerator::GeneratedCacheContext;
m_meshGenerator->setGeneratedCacheContext((dust3d::MeshGenerator::GeneratedCacheContext *)m_generatedCacheContext); m_meshGenerator->setGeneratedCacheContext((dust3d::MeshGenerator::GeneratedCacheContext *)m_generatedCacheContext);

View File

@ -571,9 +571,7 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineStitchingMesh(const st
} }
std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::string &partIdString, std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::string &partIdString,
bool *hasError, bool *hasError)
bool *retryable,
bool addIntermediateNodes)
{ {
auto findPart = m_snapshot->parts.find(partIdString); auto findPart = m_snapshot->parts.find(partIdString);
if (findPart == m_snapshot->parts.end()) { if (findPart == m_snapshot->parts.end()) {
@ -583,8 +581,6 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
Uuid partId = Uuid(partIdString); Uuid partId = Uuid(partIdString);
auto &part = findPart->second; auto &part = findPart->second;
*retryable = true;
bool isDisabled = String::isTrue(String::valueOrEmpty(part, "disabled")); bool isDisabled = String::isTrue(String::valueOrEmpty(part, "disabled"));
std::string __mirroredByPartId = String::valueOrEmpty(part, "__mirroredByPartId"); std::string __mirroredByPartId = String::valueOrEmpty(part, "__mirroredByPartId");
std::string __mirrorFromPartId = String::valueOrEmpty(part, "__mirrorFromPartId"); std::string __mirrorFromPartId = String::valueOrEmpty(part, "__mirrorFromPartId");
@ -659,21 +655,6 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
if (!fetchPartOrderedNodes(searchPartIdString, &meshNodes, &isCircle)) if (!fetchPartOrderedNodes(searchPartIdString, &meshNodes, &isCircle))
return nullptr; return nullptr;
// TODO: Generate section preview mesh
// ... ...
std::unique_ptr<TubeMeshBuilder> tubeMeshBuilder;
TubeMeshBuilder::BuildParameters buildParameters;
buildParameters.deformThickness = deformThickness;
buildParameters.deformWidth = deformWidth;
buildParameters.deformUnified = deformUnified;
buildParameters.baseNormalRotation = cutRotation * Math::Pi;
buildParameters.cutFace = cutTemplate;
buildParameters.frontEndRounded = buildParameters.backEndRounded = rounded;
tubeMeshBuilder = std::make_unique<TubeMeshBuilder>(buildParameters, std::move(meshNodes), isCircle);
tubeMeshBuilder->build();
auto &partCache = m_cacheContext->parts[partIdString]; auto &partCache = m_cacheContext->parts[partIdString];
partCache.objectNodes.clear(); partCache.objectNodes.clear();
partCache.objectEdges.clear(); partCache.objectEdges.clear();
@ -685,6 +666,18 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
partCache.roughness = roughness; partCache.roughness = roughness;
partCache.isSuccessful = false; partCache.isSuccessful = false;
partCache.joined = (target == PartTarget::Model && !isDisabled); partCache.joined = (target == PartTarget::Model && !isDisabled);
if (PartTarget::Model == target) {
std::unique_ptr<TubeMeshBuilder> tubeMeshBuilder;
TubeMeshBuilder::BuildParameters buildParameters;
buildParameters.deformThickness = deformThickness;
buildParameters.deformWidth = deformWidth;
buildParameters.deformUnified = deformUnified;
buildParameters.baseNormalRotation = cutRotation * Math::Pi;
buildParameters.cutFace = cutTemplate;
buildParameters.frontEndRounded = buildParameters.backEndRounded = rounded;
tubeMeshBuilder = std::make_unique<TubeMeshBuilder>(buildParameters, std::move(meshNodes), isCircle);
tubeMeshBuilder->build();
partCache.vertices = tubeMeshBuilder->generatedVertices(); partCache.vertices = tubeMeshBuilder->generatedVertices();
partCache.faces = tubeMeshBuilder->generatedFaces(); partCache.faces = tubeMeshBuilder->generatedFaces();
if (!__mirrorFromPartId.empty()) { if (!__mirrorFromPartId.empty()) {
@ -693,6 +686,13 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
for (auto &it: partCache.faces) for (auto &it: partCache.faces)
std::reverse(it.begin(), it.end()); std::reverse(it.begin(), it.end());
} }
} else if (PartTarget::CutFace == target) {
std::unique_ptr<SectionPreviewMeshBuilder> sectionPreviewMeshBuilder;
sectionPreviewMeshBuilder = std::make_unique<SectionPreviewMeshBuilder>(cutTemplate);
sectionPreviewMeshBuilder->build();
partCache.vertices = sectionPreviewMeshBuilder->resultVertices();
partCache.faces = sectionPreviewMeshBuilder->resultTriangles();
}
bool hasMeshError = false; bool hasMeshError = false;
std::unique_ptr<MeshCombiner::Mesh> mesh; std::unique_ptr<MeshCombiner::Mesh> mesh;
@ -710,16 +710,10 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
mesh.reset(); mesh.reset();
} }
//if (target != PartTarget::Model) {
// mesh.reset();
//}
if (hasMeshError && target == PartTarget::Model) { if (hasMeshError && target == PartTarget::Model) {
*hasError = true; *hasError = true;
} }
// TODO:
return mesh; return mesh;
} }
@ -1150,18 +1144,10 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineComponentMesh(const st
if ("partId" == linkDataType) { if ("partId" == linkDataType) {
std::string partIdString = String::valueOrEmpty(*component, "linkData"); std::string partIdString = String::valueOrEmpty(*component, "linkData");
bool hasError = false; bool hasError = false;
bool retryable = true; mesh = combinePartMesh(partIdString, &hasError);
mesh = combinePartMesh(partIdString, &hasError, &retryable, m_interpolationEnabled);
if (hasError) {
mesh.reset();
if (retryable && m_interpolationEnabled) {
hasError = false;
mesh = combinePartMesh(partIdString, &hasError, &retryable, false);
}
if (hasError) { if (hasError) {
m_isSuccessful = false; m_isSuccessful = false;
} }
}
const auto &partCache = m_cacheContext->parts[partIdString]; const auto &partCache = m_cacheContext->parts[partIdString];
if (partCache.joined) { if (partCache.joined) {
for (const auto &vertex: partCache.vertices) for (const auto &vertex: partCache.vertices)
@ -1408,11 +1394,6 @@ void MeshGenerator::setSmoothShadingThresholdAngleDegrees(float degrees)
m_smoothShadingThresholdAngleDegrees = degrees; m_smoothShadingThresholdAngleDegrees = degrees;
} }
void MeshGenerator::setInterpolationEnabled(bool interpolationEnabled)
{
m_interpolationEnabled = interpolationEnabled;
}
void MeshGenerator::setWeldEnabled(bool enabled) void MeshGenerator::setWeldEnabled(bool enabled)
{ {
m_weldEnabled = enabled; m_weldEnabled = enabled;

View File

@ -95,7 +95,6 @@ public:
virtual void generate(); virtual void generate();
void setGeneratedCacheContext(GeneratedCacheContext *cacheContext); void setGeneratedCacheContext(GeneratedCacheContext *cacheContext);
void setSmoothShadingThresholdAngleDegrees(float degrees); void setSmoothShadingThresholdAngleDegrees(float degrees);
void setInterpolationEnabled(bool interpolationEnabled);
void setDefaultPartColor(const Color &color); void setDefaultPartColor(const Color &color);
void setId(uint64_t id); void setId(uint64_t id);
void setWeldEnabled(bool enabled); void setWeldEnabled(bool enabled);
@ -123,7 +122,6 @@ private:
float m_smoothShadingThresholdAngleDegrees = 60; float m_smoothShadingThresholdAngleDegrees = 60;
uint64_t m_id = 0; uint64_t m_id = 0;
bool m_weldEnabled = true; bool m_weldEnabled = true;
bool m_interpolationEnabled = true;
void collectParts(); void collectParts();
void collectIncombinableMesh(const MeshCombiner::Mesh *mesh, const GeneratedComponent &componentCache); void collectIncombinableMesh(const MeshCombiner::Mesh *mesh, const GeneratedComponent &componentCache);
@ -132,9 +130,7 @@ private:
bool checkIsPartDependencyDirty(const std::string &partIdString); bool checkIsPartDependencyDirty(const std::string &partIdString);
void checkDirtyFlags(); void checkDirtyFlags();
std::unique_ptr<MeshCombiner::Mesh> combinePartMesh(const std::string &partIdString, std::unique_ptr<MeshCombiner::Mesh> combinePartMesh(const std::string &partIdString,
bool *hasError, bool *hasError);
bool *retryable,
bool addIntermediateNodes=true);
std::unique_ptr<MeshCombiner::Mesh> combineComponentMesh(const std::string &componentIdString, CombineMode *combineMode); std::unique_ptr<MeshCombiner::Mesh> combineComponentMesh(const std::string &componentIdString, CombineMode *combineMode);
void makeXmirror(const std::vector<Vector3> &sourceVertices, const std::vector<std::vector<size_t>> &sourceFaces, void makeXmirror(const std::vector<Vector3> &sourceVertices, const std::vector<std::vector<size_t>> &sourceFaces,
std::vector<Vector3> *destVertices, std::vector<std::vector<size_t>> *destFaces); std::vector<Vector3> *destVertices, std::vector<std::vector<size_t>> *destFaces);