Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/mesh_boolean.cc
| Context not available. | |||||
| int nshapes; | int nshapes; | ||||
| /* A per-shape vector of parity of hits of that shape. */ | /* A per-shape vector of parity of hits of that shape. */ | ||||
| Array<int> hit_parity; | Array<int> hit_parity; | ||||
| const Array<bool> &flips; | |||||
| InsideShapeTestData(const IMesh &tm, std::function<int(int)> shape_fn, int nshapes) | InsideShapeTestData(const IMesh &tm, std::function<int(int)> shape_fn, int nshapes, const Array<bool> &flips) | ||||
| : tm(tm), shape_fn(shape_fn), nshapes(nshapes) | : tm(tm), shape_fn(shape_fn), nshapes(nshapes), flips(flips) | ||||
| { | { | ||||
| } | } | ||||
| }; | }; | ||||
| Context not available. | |||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| std::cout << "origin at " << o_db << ", parity = " << parity << "\n"; | std::cout << "origin at " << o_db << ", parity = " << parity << "\n"; | ||||
| } | } | ||||
| data->hit_parity[shape] += parity; | data->hit_parity[shape] += data->flips[shape] ? -parity : parity; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| int nshapes, | int nshapes, | ||||
| int test_t_index, | int test_t_index, | ||||
| BVHTree *tree, | BVHTree *tree, | ||||
| Array<float> &in_shape) | Array<float> &in_shape, | ||||
| const Array<bool> &flips) | |||||
| { | { | ||||
| const int dbg_level = 0; | const int dbg_level = 0; | ||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| Context not available. | |||||
| constexpr float rb = 0.009987025295199663f; | constexpr float rb = 0.009987025295199663f; | ||||
| const float test_rays[num_rays][3] = { | const float test_rays[num_rays][3] = { | ||||
| {r1, ra, rb}, {-r1, -ra, -rb}, {rb, r1, ra}, {-rb, -r1, -ra}, {ra, rb, r1}, {-ra, -rb, -r1}}; | {r1, ra, rb}, {-r1, -ra, -rb}, {rb, r1, ra}, {-rb, -r1, -ra}, {ra, rb, r1}, {-ra, -rb, -r1}}; | ||||
| InsideShapeTestData data(tm, shape_fn, nshapes); | InsideShapeTestData data(tm, shape_fn, nshapes, flips); | ||||
| data.hit_parity = Array<int>(nshapes, 0); | data.hit_parity = Array<int>(nshapes, 0); | ||||
| Array<int> count_insides(nshapes, 0); | Array<int> count_insides(nshapes, 0); | ||||
| const float co[3] = { | const float co[3] = { | ||||
| Context not available. | |||||
| BoolOpType op, | BoolOpType op, | ||||
| int nshapes, | int nshapes, | ||||
| std::function<int(int)> shape_fn, | std::function<int(int)> shape_fn, | ||||
| IMeshArena *arena) | IMeshArena *arena, | ||||
| const Array<bool> &flips) | |||||
| { | { | ||||
| constexpr int dbg_level = 0; | constexpr int dbg_level = 0; | ||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| Context not available. | |||||
| std::cout << "process triangle " << t << " = " << &tri << "\n"; | std::cout << "process triangle " << t << " = " << &tri << "\n"; | ||||
| std::cout << "shape = " << shape << "\n"; | std::cout << "shape = " << shape << "\n"; | ||||
| } | } | ||||
| test_tri_inside_shapes(tm, shape_fn, nshapes, t, tree, in_shape); | test_tri_inside_shapes(tm, shape_fn, nshapes, t, tree, in_shape, flips); | ||||
| for (int other_shape = 0; other_shape < nshapes; ++other_shape) { | for (int other_shape = 0; other_shape < nshapes; ++other_shape) { | ||||
| if (other_shape == shape) { | if (other_shape == shape) { | ||||
| continue; | continue; | ||||
| Context not available. | |||||
| int nshapes, | int nshapes, | ||||
| std::function<int(int)> shape_fn, | std::function<int(int)> shape_fn, | ||||
| const PatchesInfo &pinfo, | const PatchesInfo &pinfo, | ||||
| IMeshArena *arena) | IMeshArena *arena, | ||||
| const Array<bool> &flips) | |||||
| { | { | ||||
| constexpr int dbg_level = 0; | constexpr int dbg_level = 0; | ||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| Context not available. | |||||
| if (shape == -1) { | if (shape == -1) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| test_tri_inside_shapes(tm, shape_fn, nshapes, test_t_index, tree, in_shape); | test_tri_inside_shapes(tm, shape_fn, nshapes, test_t_index, tree, in_shape, flips); | ||||
| for (int other_shape = 0; other_shape < nshapes; ++other_shape) { | for (int other_shape = 0; other_shape < nshapes; ++other_shape) { | ||||
| if (other_shape == shape) { | if (other_shape == shape) { | ||||
| continue; | continue; | ||||
| Context not available. | |||||
| std::function<int(int)> shape_fn, | std::function<int(int)> shape_fn, | ||||
| bool use_self, | bool use_self, | ||||
| bool hole_tolerant, | bool hole_tolerant, | ||||
| IMeshArena *arena) | IMeshArena *arena, | ||||
| const Array<bool> &flips) | |||||
| { | { | ||||
| constexpr int dbg_level = 0; | constexpr int dbg_level = 0; | ||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| Context not available. | |||||
| std::cout << "Input is not PWN, using raycast method\n"; | std::cout << "Input is not PWN, using raycast method\n"; | ||||
| } | } | ||||
| if (hole_tolerant) { | if (hole_tolerant) { | ||||
| tm_out = raycast_tris_boolean(tm_si, op, nshapes, shape_fn, arena); | tm_out = raycast_tris_boolean(tm_si, op, nshapes, shape_fn, arena, flips); | ||||
| } | } | ||||
| else { | else { | ||||
| PatchesInfo pinfo = find_patches(tm_si, tm_si_topo); | PatchesInfo pinfo = find_patches(tm_si, tm_si_topo); | ||||
| tm_out = raycast_patches_boolean(tm_si, op, nshapes, shape_fn, pinfo, arena); | tm_out = raycast_patches_boolean(tm_si, op, nshapes, shape_fn, pinfo, arena, flips); | ||||
| } | } | ||||
| # ifdef PERFDEBUG | # ifdef PERFDEBUG | ||||
| double raycast_time = PIL_check_seconds_timer(); | double raycast_time = PIL_check_seconds_timer(); | ||||
| Context not available. | |||||
| std::cout << "\n"; | std::cout << "\n"; | ||||
| } | } | ||||
| } | } | ||||
| IMesh boolean_trimesh(IMesh &tm_in, | |||||
| BoolOpType op, | |||||
| int nshapes, | |||||
| std::function<int(int)> shape_fn, | |||||
| bool use_self, | |||||
| bool hole_tolerant, | |||||
| IMeshArena *arena) | |||||
| { | |||||
| return boolean_trimesh( | |||||
| tm_in, op, nshapes, shape_fn, use_self, hole_tolerant, arena, Array<bool>(nshapes, false)); | |||||
| } | |||||
| /** | /** | ||||
| * Do the boolean operation op on the polygon mesh imesh_in. | * Do the boolean operation op on the polygon mesh imesh_in. | ||||
| Context not available. | |||||
| bool use_self, | bool use_self, | ||||
| bool hole_tolerant, | bool hole_tolerant, | ||||
| IMesh *imesh_triangulated, | IMesh *imesh_triangulated, | ||||
| IMeshArena *arena) | IMeshArena *arena, | ||||
| const Array<bool> &flips) | |||||
| { | { | ||||
| constexpr int dbg_level = 0; | constexpr int dbg_level = 0; | ||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| Context not available. | |||||
| if (dbg_level > 1) { | if (dbg_level > 1) { | ||||
| write_obj_mesh(*tm_in, "boolean_tm_in"); | write_obj_mesh(*tm_in, "boolean_tm_in"); | ||||
| } | } | ||||
| IMesh tm_out = boolean_trimesh(*tm_in, op, nshapes, shape_fn, use_self, hole_tolerant, arena); | IMesh tm_out = boolean_trimesh(*tm_in, op, nshapes, shape_fn, use_self, hole_tolerant, arena, flips); | ||||
| # ifdef PERFDEBUG | # ifdef PERFDEBUG | ||||
| double bool_tri_time = PIL_check_seconds_timer(); | double bool_tri_time = PIL_check_seconds_timer(); | ||||
| std::cout << "boolean_trimesh done, time = " << bool_tri_time - tri_time << "\n"; | std::cout << "boolean_trimesh done, time = " << bool_tri_time - tri_time << "\n"; | ||||
| Context not available. | |||||
| # endif | # endif | ||||
| return ans; | return ans; | ||||
| } | } | ||||
| IMesh boolean_mesh(IMesh &imesh, | |||||
| BoolOpType op, | |||||
| int nshapes, | |||||
| std::function<int(int)> shape_fn, | |||||
| bool use_self, | |||||
| bool hole_tolerant, | |||||
| IMesh *imesh_triangulated, | |||||
| IMeshArena *arena) | |||||
| { | |||||
| return boolean_mesh(imesh, | |||||
| op, | |||||
| nshapes, | |||||
| shape_fn, | |||||
| use_self, | |||||
| hole_tolerant, | |||||
| imesh_triangulated, | |||||
| arena, | |||||
| Array<bool>(nshapes, false)); | |||||
| } | |||||
| } // namespace blender::meshintersect | } // namespace blender::meshintersect | ||||
| #endif // WITH_GMP | #endif // WITH_GMP | ||||
| Context not available. | |||||