diff --git a/application/application.pro b/application/application.pro index 0b2f1a39..079906d7 100644 --- a/application/application.pro +++ b/application/application.pro @@ -294,6 +294,8 @@ HEADERS += ../dust3d/mesh/resolve_triangle_tangent.h SOURCES += ../dust3d/mesh/resolve_triangle_tangent.cc HEADERS += ../dust3d/mesh/rope_mesh.h SOURCES += ../dust3d/mesh/rope_mesh.cc +HEADERS += ../dust3d/mesh/section_preview_mesh_builder.h +SOURCES += ../dust3d/mesh/section_preview_mesh_builder.cc HEADERS += ../dust3d/mesh/smooth_normal.h SOURCES += ../dust3d/mesh/smooth_normal.cc HEADERS += ../dust3d/mesh/stitch_mesh_builder.h diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index 38f9ca7a..9c06f195 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -38,6 +38,7 @@ #include #include #include +#include namespace dust3d { @@ -658,6 +659,11 @@ std::unique_ptr MeshGenerator::combinePartMesh(const std::st if (!fetchPartOrderedNodes(searchPartIdString, &meshNodes, &isCircle)) return nullptr; + // TODO: Generate section preview mesh + // ... ... + + std::unique_ptr tubeMeshBuilder; + TubeMeshBuilder::BuildParameters buildParameters; buildParameters.deformThickness = deformThickness; buildParameters.deformWidth = deformWidth; @@ -665,7 +671,7 @@ std::unique_ptr MeshGenerator::combinePartMesh(const std::st buildParameters.baseNormalRotation = cutRotation * Math::Pi; buildParameters.cutFace = cutTemplate; buildParameters.frontEndRounded = buildParameters.backEndRounded = rounded; - auto tubeMeshBuilder = std::make_unique(buildParameters, std::move(meshNodes), isCircle); + tubeMeshBuilder = std::make_unique(buildParameters, std::move(meshNodes), isCircle); tubeMeshBuilder->build(); auto &partCache = m_cacheContext->parts[partIdString]; @@ -704,9 +710,9 @@ std::unique_ptr MeshGenerator::combinePartMesh(const std::st mesh.reset(); } - if (target != PartTarget::Model) { - mesh.reset(); - } + //if (target != PartTarget::Model) { + // mesh.reset(); + //} if (hasMeshError && target == PartTarget::Model) { *hasError = true; diff --git a/dust3d/mesh/section_preview_mesh_builder.cc b/dust3d/mesh/section_preview_mesh_builder.cc new file mode 100644 index 00000000..dc224915 --- /dev/null +++ b/dust3d/mesh/section_preview_mesh_builder.cc @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016-2022 Jeremy HU . All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +namespace dust3d +{ + +SectionPreviewMeshBuilder::SectionPreviewMeshBuilder(const std::vector &cutFace): + m_cutFace(cutFace) +{ +} + +const std::vector &SectionPreviewMeshBuilder::resultVertices() +{ + return m_resultVertices; +} + +const std::vector> &SectionPreviewMeshBuilder::resultTriangles() +{ + return m_resultTriangles; +} + +void SectionPreviewMeshBuilder::build() +{ + m_resultVertices.resize(m_cutFace.size()); + for (size_t i = 0; i < m_cutFace.size(); ++i) { + m_resultVertices[i] = Vector3(m_cutFace[i][0], m_cutFace[i][1], 0); + } + std::vector cutFaceIndices(m_resultVertices.size()); + for (size_t i = 0; i < cutFaceIndices.size(); ++i) + cutFaceIndices[i] = i; + triangulate(m_resultVertices, cutFaceIndices, &m_resultTriangles); +} + +} \ No newline at end of file diff --git a/dust3d/mesh/section_preview_mesh_builder.h b/dust3d/mesh/section_preview_mesh_builder.h new file mode 100644 index 00000000..d428b3b4 --- /dev/null +++ b/dust3d/mesh/section_preview_mesh_builder.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016-2022 Jeremy HU . All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef DUST3D_MESH_SECTION_PREVIEW_MESH_BUILDER_H_ +#define DUST3D_MESH_SECTION_PREVIEW_MESH_BUILDER_H_ + +#include +#include +#include + +namespace dust3d +{ + +class SectionPreviewMeshBuilder +{ +public: + SectionPreviewMeshBuilder(const std::vector &cutFace); + void build(); + const std::vector &resultVertices(); + const std::vector> &resultTriangles(); +private: + std::vector m_cutFace; + std::vector m_resultVertices; + std::vector> m_resultTriangles; +}; + +} + + +#endif