Implement section preview mesh builder
parent
066e16dcd6
commit
73f0404c2e
|
@ -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);
|
||||||
|
|
|
@ -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()) {
|
||||||
|
@ -582,8 +580,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");
|
||||||
|
@ -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,13 +666,32 @@ 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);
|
||||||
partCache.vertices = tubeMeshBuilder->generatedVertices();
|
|
||||||
partCache.faces = tubeMeshBuilder->generatedFaces();
|
if (PartTarget::Model == target) {
|
||||||
if (!__mirrorFromPartId.empty()) {
|
std::unique_ptr<TubeMeshBuilder> tubeMeshBuilder;
|
||||||
for (auto &it: partCache.vertices)
|
TubeMeshBuilder::BuildParameters buildParameters;
|
||||||
it.setX(-it.x());
|
buildParameters.deformThickness = deformThickness;
|
||||||
for (auto &it: partCache.faces)
|
buildParameters.deformWidth = deformWidth;
|
||||||
std::reverse(it.begin(), it.end());
|
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;
|
bool hasMeshError = false;
|
||||||
|
@ -709,17 +709,11 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
|
||||||
if (mesh && mesh->isNull()) {
|
if (mesh && mesh->isNull()) {
|
||||||
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,17 +1144,9 @@ 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) {
|
if (hasError) {
|
||||||
mesh.reset();
|
m_isSuccessful = false;
|
||||||
if (retryable && m_interpolationEnabled) {
|
|
||||||
hasError = false;
|
|
||||||
mesh = combinePartMesh(partIdString, &hasError, &retryable, false);
|
|
||||||
}
|
|
||||||
if (hasError) {
|
|
||||||
m_isSuccessful = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const auto &partCache = m_cacheContext->parts[partIdString];
|
const auto &partCache = m_cacheContext->parts[partIdString];
|
||||||
if (partCache.joined) {
|
if (partCache.joined) {
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue