BaseMesh* BoolOp::Diff (BaseMesh* mesh1, BaseMesh* mesh2) { BaseMesh* result = NULL; if (mesh1 != NULL) { if (mesh2 == NULL || !(mesh1->AABB().Intersects(mesh2->AABB()))) result = mesh1->Clone(); else{ result = ComputeBoolean(mesh1, mesh2,eDiff); if (result && result->PrimitiveCount() ==0 ) { delete result; result = NULL; } } } if (result != NULL) { result->GenID(); // result->GenSurface(); // result->GenAABB(true); } return result ; }
BaseMesh* BoolOp::Union ( BaseMesh* mesh1, BaseMesh* mesh2) { tbb::tick_count t0 = tbb::tick_count::now(); if (mesh1 == NULL && mesh2 == NULL) return NULL; if ( mesh1 == NULL) return mesh2->Clone(); if (mesh2 == NULL) return mesh1->Clone(); BaseMesh* result = NULL; if (mesh1->AABB().Intersects(mesh2->AABB())) { result = ComputeBoolean(mesh1, mesh2, eUnion); if (result && result->PrimitiveCount() ==0 ) { delete result; result = NULL; } } else { result = mesh1->Clone(); for (int i = 0; i < mesh2->PrimitiveCount(); i++) { const TriInfo& info= mesh2->TriangleInfo(i); result->Add(mesh2->Vertex(info.VertexId[0]) , mesh2->Vertex(info.VertexId[1]), mesh2->Vertex(info.VertexId[2])); } } if (result != NULL) { result->GenID(); // result->GenSurface(); // result->GenAABB(true); } /* tbb::tick_count t1 = tbb::tick_count::now(); WCHAR buffer [100]; ::swprintf_s(buffer, 100, L"Time %f mec", (t1-t0).seconds()); ::MessageBox(NULL, buffer, L"Warning", MB_OK); */ return result ; }
BaseMesh* FixedPlaneMesh::ToBaseMesh() { std::vector<Point3D> pts; ListOfvertices results; BaseMesh* pMesh = new BaseMesh; pMesh->SetTransformedAABB(AABB()); //auto center = AABB().Center(); //auto scale = AABB().Diagonal(); for (int i = 0 ; i < mPolygons.size(); i++) { for (int j = 0 ; j < mPolygons[i].bplanes.size(); j++) { int prevPtIdx = j == 0? mPolygons[i].bplanes.size() -1 : j -1; Point3D pt = InexactComputePoint(mPolygons[i].splane, mPolygons[i].bplanes[prevPtIdx], mPolygons[i].bplanes[j] ); //pt = denormalize(pt, center, scale); if (!pts.size() || !IsSimilar(pt, pts.back())) pts.push_back(pt); } auto normal = normalize(mPolygons[i].splane.Normal()); TrianglatePolygon(normal, pts, results); //catch (...){ // wchar_t ch[64]; // swprintf(ch, 64, L"Error, %u", i); // OutputDebugString(ch); // results.clear(); //} for (int k = 0 ; k < results.size(); k+=3) { pMesh->Add(results[k], results[k+1], results[k+2], normal); } pts.clear(); results.clear(); } pMesh->GenID(); return pMesh; }
BaseMesh* BoolOp::Intersect (BaseMesh* mesh1, BaseMesh* mesh2) { BaseMesh* result = NULL; if (mesh1 != NULL && mesh2 != NULL && (mesh1->AABB().Intersects(mesh2->AABB()))) { result = ComputeBoolean(mesh1, mesh2, eIntersect); if (result && result->PrimitiveCount() ==0 ) { delete result; result = NULL; } } if (result != NULL) { result->GenID(); // result->GenSurface(); // result->GenAABB(true); } return result ; }