@@ -274,6 +274,36 @@ struct CoplanarEdge {
274
274
}
275
275
};
276
276
277
+ struct CheckCoplanarity {
278
+ int * comp2tri;
279
+ const Halfedge* halfedge;
280
+ const glm::vec3* vertPos;
281
+ const int * components;
282
+ const float precision;
283
+
284
+ __host__ __device__ void operator ()(int tri) {
285
+ const int component = components[tri];
286
+ const int referenceTri = comp2tri[component];
287
+ if (referenceTri < 0 || referenceTri == tri) return ;
288
+
289
+ const glm::vec3 origin = vertPos[halfedge[3 * referenceTri].startVert ];
290
+ const glm::vec3 normal = glm::normalize (
291
+ glm::cross (vertPos[halfedge[3 * referenceTri + 1 ].startVert ] - origin,
292
+ vertPos[halfedge[3 * referenceTri + 2 ].startVert ] - origin));
293
+
294
+ for (const int i : {0 , 1 , 2 }) {
295
+ const glm::vec3 vert = vertPos[halfedge[3 * tri + i].startVert ];
296
+ // If any component vertex is not coplanar with the component's reference
297
+ // triangle, unmark the entire component so that none of its triangles are
298
+ // marked coplanar.
299
+ if (glm::abs (glm::dot (normal , vert - origin)) > precision) {
300
+ comp2tri[component] = -1 ;
301
+ break ;
302
+ }
303
+ }
304
+ }
305
+ };
306
+
277
307
struct EdgeBox {
278
308
const glm::vec3* vertPos;
279
309
@@ -326,6 +356,7 @@ uint32_t Manifold::Impl::ReserveIDs(uint32_t n) {
326
356
Manifold::Impl::Impl (const MeshGL& meshGL,
327
357
std::vector<float > propertyTolerance) {
328
358
Mesh mesh;
359
+ mesh.precision = meshGL.precision ;
329
360
const int numVert = meshGL.NumVert ();
330
361
const int numTri = meshGL.NumTri ();
331
362
@@ -472,7 +503,7 @@ Manifold::Impl::Impl(const Mesh& mesh, const MeshRelationD& relation,
472
503
MarkFailure (Error::NonFiniteVertex);
473
504
return ;
474
505
}
475
- SetPrecision ();
506
+ SetPrecision (mesh. precision );
476
507
477
508
CreateHalfedges (triVerts);
478
509
if (!IsManifold ()) {
@@ -609,9 +640,20 @@ void Manifold::Impl::CreateFaces(const std::vector<float>& propertyTolerance) {
609
640
}
610
641
}
611
642
643
+ VecDH<int > componentsD (components);
644
+ VecDH<int > comp2triD (comp2tri);
645
+ for_each_n (
646
+ autoPolicy (halfedge_.size ()), countAt (0 ), NumTri (),
647
+ CheckCoplanarity ({comp2triD.ptrD (), halfedge_.cptrD (), vertPos_.cptrD (),
648
+ componentsD.cptrD (), precision_}));
649
+
612
650
VecDH<TriRef>& triRef = meshRelation_.triRef ;
613
- for (int tri = 0 ; tri < NumTri (); ++tri)
614
- triRef[tri].tri = comp2tri[components[tri]];
651
+ for (int tri = 0 ; tri < NumTri (); ++tri) {
652
+ const int referenceTri = comp2triD[components[tri]];
653
+ if (referenceTri >= 0 ) {
654
+ triRef[tri].tri = referenceTri;
655
+ }
656
+ }
615
657
}
616
658
617
659
/* *
0 commit comments