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->setId(m_nextMeshGenerationId++);
m_meshGenerator->setDefaultPartColor(dust3d::Color::createWhite());
m_meshGenerator->setInterpolationEnabled(true);
if (nullptr == m_generatedCacheContext)
m_generatedCacheContext = new MeshGenerator::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,
bool *hasError,
bool *retryable,
bool addIntermediateNodes)
bool *hasError)
{
auto findPart = m_snapshot->parts.find(partIdString);
if (findPart == m_snapshot->parts.end()) {
@ -582,8 +580,6 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
Uuid partId = Uuid(partIdString);
auto &part = findPart->second;
*retryable = true;
bool isDisabled = String::isTrue(String::valueOrEmpty(part, "disabled"));
std::string __mirroredByPartId = String::valueOrEmpty(part, "__mirroredByPartId");
@ -659,21 +655,6 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
if (!fetchPartOrderedNodes(searchPartIdString, &meshNodes, &isCircle))
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];
partCache.objectNodes.clear();
partCache.objectEdges.clear();
@ -685,13 +666,32 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
partCache.roughness = roughness;
partCache.isSuccessful = false;
partCache.joined = (target == PartTarget::Model && !isDisabled);
partCache.vertices = tubeMeshBuilder->generatedVertices();
partCache.faces = tubeMeshBuilder->generatedFaces();
if (!__mirrorFromPartId.empty()) {
for (auto &it: partCache.vertices)
it.setX(-it.x());
for (auto &it: partCache.faces)
std::reverse(it.begin(), it.end());
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.faces = tubeMeshBuilder->generatedFaces();
if (!__mirrorFromPartId.empty()) {
for (auto &it: partCache.vertices)
it.setX(-it.x());
for (auto &it: partCache.faces)
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;
@ -709,17 +709,11 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
if (mesh && mesh->isNull()) {
mesh.reset();
}
//if (target != PartTarget::Model) {
// mesh.reset();
//}
if (hasMeshError && target == PartTarget::Model) {
*hasError = true;
}
// TODO:
return mesh;
}
@ -1150,17 +1144,9 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineComponentMesh(const st
if ("partId" == linkDataType) {
std::string partIdString = String::valueOrEmpty(*component, "linkData");
bool hasError = false;
bool retryable = true;
mesh = combinePartMesh(partIdString, &hasError, &retryable, m_interpolationEnabled);
mesh = combinePartMesh(partIdString, &hasError);
if (hasError) {
mesh.reset();
if (retryable && m_interpolationEnabled) {
hasError = false;
mesh = combinePartMesh(partIdString, &hasError, &retryable, false);
}
if (hasError) {
m_isSuccessful = false;
}
m_isSuccessful = false;
}
const auto &partCache = m_cacheContext->parts[partIdString];
if (partCache.joined) {
@ -1408,11 +1394,6 @@ void MeshGenerator::setSmoothShadingThresholdAngleDegrees(float degrees)
m_smoothShadingThresholdAngleDegrees = degrees;
}
void MeshGenerator::setInterpolationEnabled(bool interpolationEnabled)
{
m_interpolationEnabled = interpolationEnabled;
}
void MeshGenerator::setWeldEnabled(bool enabled)
{
m_weldEnabled = enabled;

View File

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