diff --git a/src/ifcgeom/kernels/manifold/ManifoldConversionResult.cpp b/src/ifcgeom/kernels/manifold/ManifoldConversionResult.cpp index 82931f87ad..ec53254bcd 100644 --- a/src/ifcgeom/kernels/manifold/ManifoldConversionResult.cpp +++ b/src/ifcgeom/kernels/manifold/ManifoldConversionResult.cpp @@ -180,6 +180,12 @@ namespace { } } +ifcopenshell::geometry::ManifoldShape::ManifoldShape(const manifold::Manifold& solid) { + auto copy = solid; + auto with_normals = copy.CalculateNormals(3); + parts_.push_back({with_normals.GetMeshGL64(), solid}); +} + ifcopenshell::geometry::ManifoldShape::ManifoldShape(const ManifoldPart& part) : parts_{ part } {} @@ -221,6 +227,12 @@ void ifcopenshell::geometry::ManifoldShape::Triangulate(ifcopenshell::geometry:: mesh.vertProperties[i * mesh.numProp + 0], mesh.vertProperties[i * mesh.numProp + 1], mesh.vertProperties[i * mesh.numProp + 2]); + if (mesh.numProp == 6) { + t->addNormal( + mesh.vertProperties[i * mesh.numProp + 3], + mesh.vertProperties[i * mesh.numProp + 4], + mesh.vertProperties[i * mesh.numProp + 5]); + } } auto edges = count_edges(mesh); for (size_t i = 0; i < mesh.NumTri(); ++i) { @@ -499,7 +511,7 @@ ConversionResultShape* ifcopenshell::geometry::ManifoldShape::moved(ifcopenshell if (part.solid && !solid) { throw std::runtime_error("Failed to transform shape"); } - moved_parts.push_back({ std::move(mesh), std::move(solid) }); + moved_parts.emplace_back(mesh, *solid); } return new ManifoldShape(std::move(moved_parts)); } diff --git a/src/ifcgeom/kernels/manifold/ManifoldConversionResult.h b/src/ifcgeom/kernels/manifold/ManifoldConversionResult.h index 9250dbfd53..1feb466287 100644 --- a/src/ifcgeom/kernels/manifold/ManifoldConversionResult.h +++ b/src/ifcgeom/kernels/manifold/ManifoldConversionResult.h @@ -14,12 +14,24 @@ namespace geometry { struct IFC_GEOMLIBRARY_API ManifoldPart { manifold::MeshGL64 mesh; std::optional solid; + + ManifoldPart(const manifold::Manifold& s) { + auto copy = s; + copy.CalculateNormals(3); + mesh = copy.GetMeshGL64(); + solid = s; + } + + ManifoldPart(const manifold::MeshGL64& s) : mesh(s) {} + + ManifoldPart(const manifold::MeshGL64& s, const manifold::Manifold& m) : mesh(s), solid(m) {} }; class IFC_GEOMLIBRARY_API ManifoldShape : public IfcGeom::ConversionResultShape { public: ManifoldShape() = default; - explicit ManifoldShape(const ManifoldPart& part); + explicit ManifoldShape(const manifold::Manifold& part); + explicit ManifoldShape(const ManifoldPart& part); explicit ManifoldShape(ManifoldPart&& part); explicit ManifoldShape(const std::vector& parts); explicit ManifoldShape(std::vector&& parts); diff --git a/src/ifcgeom/kernels/manifold/ManifoldKernel.cpp b/src/ifcgeom/kernels/manifold/ManifoldKernel.cpp index bb9b34211c..109d54f02d 100644 --- a/src/ifcgeom/kernels/manifold/ManifoldKernel.cpp +++ b/src/ifcgeom/kernels/manifold/ManifoldKernel.cpp @@ -1066,9 +1066,9 @@ namespace { return std::nullopt; } if (solid) { - return Part{ solid->GetMeshGL64(), solid }; + return *solid; } - return Part{ mesh, std::nullopt }; + return mesh; } std::optional part_from_shell(const taxonomy::shell::ptr& shell, double precision, double dilation, manifold::Manifold::Error* status_ptr = nullptr) { @@ -1544,7 +1544,7 @@ bool ManifoldKernel::convert_impl(const taxonomy::solid::ptr solid, IfcGeom::Con results.emplace_back(IfcGeom::ConversionResult( solid->instance.id(), solid->matrix, - new ifcopenshell::geometry::ManifoldShape(Part{ result.GetMeshGL64(), result }), + new ifcopenshell::geometry::ManifoldShape(result), solid->surface_style)); return true; } @@ -1622,7 +1622,7 @@ bool ManifoldKernel::convert_impl(const taxonomy::boolean_result::ptr br, IfcGeo results.emplace_back(IfcGeom::ConversionResult( br->instance.id(), br->matrix, - new ifcopenshell::geometry::ManifoldShape(Part{ result->GetMeshGL64(), *result }), + new ifcopenshell::geometry::ManifoldShape(*result), br->surface_style ? br->surface_style : style)); return true; } @@ -1671,7 +1671,7 @@ bool ManifoldKernel::convert_openings(const express::Base&, const std::vector