45# define BENCHMARK_FILE "/tmp/blender_benchmark.csv"
54#if defined(WITH_GMP) || defined(WITH_MANIFOLD)
58 const int meshes_num = meshes.
size();
77 for (
const int mesh_id : mesh_offsets.face_offsets.index_range()) {
78 if (mesh_offsets.face_offsets[mesh_id].contains(face_id)) {
92 mesh_offsets.vert_start[mesh_id + 1]);
97 const CPPType &type = dst.type();
98 IndexMaskMemory memory;
100 IndexRange(dst.size()), out_to_in_map, memory);
102 type.value_initialize_indices(dst.data(), valid_mask.complement(IndexRange(dst.size()), memory));
109struct CornerInterpolation {
110 IndexMaskMemory memory;
114 IndexMask interp_mask;
116 Array<int> group_offsets;
117 Array<int> src_corners;
118 Array<float> weights;
124static void calc_corner_interpolation(
const Mesh &output_mesh,
125 const Mesh &input_mesh,
126 const Span<int> out_to_in_corner_map,
127 const Span<int> out_to_in_face_map,
128 CornerInterpolation &r_interp)
130 const OffsetIndices<int> output_faces = output_mesh.faces();
131 const OffsetIndices<int> input_faces = input_mesh.faces();
132 const Span<int> input_corner_verts = input_mesh.corner_verts();
133 const Span<float3> input_vert_positions = input_mesh.vert_positions();
134 const Span<int> output_corner_verts = output_mesh.corner_verts();
135 const Span<float3> output_vert_positions = output_mesh.vert_positions();
138 Array<int> interp_corner_offsets_data(output_faces.size() + 1);
139 Array<int> weight_offsets_data(output_faces.size() + 1);
141 for (const int out_face : range) {
142 const Span<int> face_map = out_to_in_corner_map.slice(output_faces[out_face]);
143 const int interp_num = std::count(face_map.begin(), face_map.end(), -1);
144 const int in_face_size = input_faces[out_to_in_face_map[out_face]].size();
145 interp_corner_offsets_data[out_face] = interp_num;
146 weight_offsets_data[out_face] = interp_num * in_face_size;
150 interp_corner_offsets_data);
152 weight_offsets_data);
154 Array<int> interp_corners(interp_corner_offsets.total_size());
155 r_interp.group_offsets.reinitialize(interp_corner_offsets.total_size() + 1);
156 r_interp.flipped.reinitialize(interp_corner_offsets.total_size());
157 r_interp.src_corners.reinitialize(weight_offsets.total_size());
158 r_interp.weights.reinitialize(weight_offsets.total_size());
162 Vector<float2, 20> cos_2d;
163 for (const int out_face_index : range) {
164 const IndexRange interp_range = interp_corner_offsets[out_face_index];
165 if (interp_range.is_empty()) {
168 const int in_face_index = out_to_in_face_map[out_face_index];
169 const IndexRange in_face = input_faces[in_face_index];
170 const IndexRange out_face = output_faces[out_face_index];
173 const Span<int> in_face_verts = input_corner_verts.slice(in_face);
174 const int in_face_size = in_face.size();
175 const Span<int> out_face_verts = output_corner_verts.slice(out_face);
176 cos_2d.resize(in_face_size);
177 float (*cos_2d_p)[2] = reinterpret_cast<float (*)[2]>(cos_2d.data());
178 const float3 axis_dominant = bke::mesh::face_normal_calc(input_vert_positions,
181 axis_dominant_v3_to_m3(axis_mat.ptr(), axis_dominant);
185 const float3 out_face_normal = bke::mesh::face_normal_calc(output_vert_positions,
187 const bool face_is_flipped = math::dot(axis_dominant, out_face_normal) < 0.0;
188 for (const int i : in_face_verts.index_range()) {
189 const float3 &co = input_vert_positions[in_face_verts[i]];
190 cos_2d[i] = (axis_mat * co).xy();
193 const int weights_start = weight_offsets[out_face_index].start();
195 for (const int out_c : out_face) {
196 if (out_to_in_corner_map[out_c] != -1) {
199 const int corner_i = interp_range[interp_i];
200 const IndexRange group(weights_start + interp_i * in_face_size, in_face_size);
201 interp_corners[corner_i] = out_c;
202 r_interp.group_offsets[corner_i] = group.start();
203 r_interp.flipped[corner_i] = face_is_flipped;
204 array_utils::fill_index_range<int>(r_interp.src_corners.as_mutable_span().slice(group),
207 const int out_v = output_corner_verts[out_c];
209 mul_v2_m3v3(co, axis_mat.ptr(), output_vert_positions[out_v]);
210 interp_weights_poly_v2(&r_interp.weights[group.start()], cos_2d_p, in_face_size, co);
215 r_interp.group_offsets.last() = weight_offsets.total_size();
218 r_interp.copy_mask = r_interp.interp_mask.complement(
IndexRange(out_to_in_corner_map.
size()),
223 const bke::AttributeAccessor input_attrs,
225 const Mesh *input_mesh,
226 const Span<int> out_to_in_corner_map,
227 const Span<int> out_to_in_face_map)
230 timeit::ScopedTimer timer(
"interpolate corner attributes");
233 std::optional<CornerInterpolation>
interp;
235 input_attrs.foreach_attribute([&](
const bke::AttributeIter &iter) {
240 const bke::GAttributeReader reader = iter.get();
245 const CommonVArrayInfo info = reader.varray.common_info();
247 const bke::AttributeInitValue
init(
GPointer(reader.varray.type(), info.data));
248 output_attrs.add(iter.name, iter.domain, iter.data_type,
init);
254 calc_corner_interpolation(
255 *output_mesh, *input_mesh, out_to_in_corner_map, out_to_in_face_map, *
interp);
258 bke::GSpanAttributeWriter dst = output_attrs.lookup_or_add_for_write_only_span(
259 iter.name, iter.domain, iter.data_type);
260 const GVArraySpan src(*reader);
263 OffsetIndices<int>(
interp->group_offsets),
265 interp->weights.as_span(),
268 if (iter.name ==
"custom_normal" && dst.span.type().is<
float3>()) {
270 MutableSpan<float3> normals = dst.span.typed<
float3>();
271 interp->interp_mask.foreach_index(
272 [&](
const int corner,
const int pos) {
273 if (
interp->flipped[pos]) {
274 normals[corner] = -normals[corner];
284 const Span<Array<short>> material_remaps,
285 const Span<const Mesh *> meshes,
286 const MeshOffsets &mesh_offsets,
287 const MutableSpan<int> dst)
290 Array<VArray<int>> material_varrays(meshes.
size());
292 bke::AttributeAccessor input_attrs = meshes[i]->attributes();
293 material_varrays[i] = *input_attrs.lookup_or_default<
int>(
297 for (const int out_f : range) {
298 const int in_f = out_to_in_map[out_f];
299 const int mesh_id = mesh_id_for_face(in_f, mesh_offsets);
300 const int in_f_local = in_f - mesh_offsets.face_start[mesh_id];
301 const int orig = material_varrays[mesh_id][in_f_local];
302 const Array<short> &map = material_remaps[mesh_id];
303 dst[out_f] = (orig >= 0 && orig < map.size()) ? map[orig] : orig;
309 const Span<float4x4> transforms)
312 timeit::ScopedTimer jtimer(__func__);
314 bke::Instances instances;
315 instances.resize(meshes.
size());
316 instances.transforms_for_write().copy_from(transforms);
317 MutableSpan<int> handles = instances.reference_handles_for_write();
319 Map<const Mesh *, int> handle_by_mesh;
321 handles[i] = handle_by_mesh.lookup_or_add_cb(meshes[i], [&]() {
324 return instances.add_new_reference(std::move(geometry));
329 geometry::RealizeInstancesOptions())
343constexpr int estimated_max_facelen = 100;
355 const float fuzz = 1e-6f;
356 for (
int i = 0; i < 4; i++) {
357 for (
int j = 0; j < 4; j++) {
359 if (
fabsf(f) <= fuzz) {
362 else if (
fabsf(f - 1.0f) <= fuzz) {
365 else if (
fabsf(f + 1.0f) <= fuzz) {
377 if (!isfinite(co[0])) [[unlikely]] {
380 if (!isfinite(co[1])) [[unlikely]] {
383 if (!isfinite(co[2])) [[unlikely]] {
392class MeshesToIMeshInfo {
395 Span<const Mesh *> meshes;
396 MeshOffsets mesh_offsets;
398 const Mesh *joined_mesh;
401 Array<const meshintersect::Vert *> mesh_to_imesh_vert;
403 Array<meshintersect::Face *> mesh_to_imesh_face;
406 Array<float4x4> to_target_transform;
408 Array<bool> has_negative_transform;
411 Span<Array<short>> material_remaps;
413 MeshesToIMeshInfo(Span<const Mesh *> meshes) : mesh_offsets(meshes) {}
415 int input_mesh_for_imesh_vert(
int imesh_v)
const;
416 int input_mesh_for_imesh_edge(
int imesh_e)
const;
417 int input_mesh_for_imesh_face(
int imesh_f)
const;
422int MeshesToIMeshInfo::input_mesh_for_imesh_vert(
int imesh_v)
const
424 const Span<int> offsets = this->mesh_offsets.vert_offsets.data();
425 int n = int(offsets.
size());
426 for (
int i = 0; i < n - 1; ++i) {
427 if (imesh_v < offsets[i + 1]) {
436int MeshesToIMeshInfo::input_mesh_for_imesh_edge(
int imesh_e)
const
438 const Span<int> offsets = this->mesh_offsets.edge_offsets.
data();
439 int n = int(offsets.
size());
440 for (
int i = 0; i < n - 1; ++i) {
441 if (imesh_e < offsets[i + 1]) {
450int MeshesToIMeshInfo::input_mesh_for_imesh_face(
int imesh_f)
const
452 const Span<int> offsets = this->mesh_offsets.face_offsets.
data();
453 int n = int(offsets.
size());
454 for (
int i = 0; i < n - 1; ++i) {
455 if (imesh_f < offsets[i + 1]) {
474static meshintersect::IMesh meshes_to_imesh(Span<const Mesh *> meshes,
475 Span<float4x4> transforms,
476 Span<Array<short>> material_remaps,
477 meshintersect::IMeshArena &arena,
478 MeshesToIMeshInfo *r_info)
480 int nmeshes = meshes.
size();
482 r_info->meshes = meshes;
483 const int totvert = r_info->mesh_offsets.vert_offsets.total_size();
484 const int faces_num = r_info->mesh_offsets.face_offsets.total_size();
489 const int estimate_num_outv = 3 * totvert;
490 const int estimate_num_outf = 4 * faces_num;
491 arena.reserve(estimate_num_outv, estimate_num_outf);
492 r_info->mesh_to_imesh_vert.reinitialize(totvert);
493 r_info->mesh_to_imesh_face.reinitialize(faces_num);
494 r_info->to_target_transform.reinitialize(nmeshes);
495 r_info->has_negative_transform.reinitialize(nmeshes);
496 r_info->material_remaps = material_remaps;
518 const Mesh *mesh = meshes[mi];
522 clean_transform(transforms[mi]);
523 r_info->has_negative_transform[mi] =
math::is_negative(r_info->to_target_transform[mi]);
528 bool need_face_flip = r_info->has_negative_transform[mi] != r_info->has_negative_transform[0];
531 const Span<float3> vert_positions = mesh->vert_positions();
532 const OffsetIndices faces = mesh->faces();
533 const Span<int> corner_verts = mesh->corner_verts();
534 const Span<int> corner_edges = mesh->corner_edges();
542 for (int i : range) {
543 float3 co = clean_float3(vert_positions[i]);
544 mpq3 mco = mpq3(co.x, co.y, co.z);
545 double3 dco(mco[0].get_d(), mco[1].get_d(), mco[2].get_d());
546 verts[i] = new meshintersect::Vert(mco, dco, meshintersect::NO_INDEX, i);
552 for (int i : range) {
553 float3 co = math::transform_point(r_info->to_target_transform[mi],
554 clean_float3(vert_positions[i]));
555 mpq3 mco = mpq3(co.x, co.y, co.z);
556 double3 dco(mco[0].get_d(), mco[1].get_d(), mco[2].get_d());
557 verts[i] = new meshintersect::Vert(mco, dco, meshintersect::NO_INDEX, i);
561 for (
int i : vert_positions.index_range()) {
562 r_info->mesh_to_imesh_vert[
v] = arena.add_or_find_vert(verts[i]);
566 for (
const int face_i : faces.index_range()) {
567 const IndexRange face = faces[face_i];
568 int flen = face.size();
569 face_vert.resize(flen);
570 face_edge_orig.resize(flen);
571 for (
int i = 0; i < flen; ++i) {
572 const int corner_i = face[i];
573 int mverti = r_info->mesh_offsets.vert_offsets[mi][corner_verts[corner_i]];
574 const meshintersect::Vert *fv = r_info->mesh_to_imesh_vert[mverti];
575 if (need_face_flip) {
576 face_vert[flen - i - 1] = fv;
577 int iedge = i < flen - 1 ? flen - i - 2 : flen - 1;
578 face_edge_orig[iedge] =
e + corner_edges[corner_i];
582 face_edge_orig[i] =
e + corner_edges[corner_i];
585 r_info->mesh_to_imesh_face[f] = arena.add_face(face_vert, f, face_edge_orig);
588 e += mesh->edges_num;
590 return meshintersect::IMesh(r_info->mesh_to_imesh_face);
603static int fill_orig_loops(
const meshintersect::Face *f,
604 const IndexRange orig_face,
605 const Span<int> orig_corner_verts,
607 MeshesToIMeshInfo &mim,
608 MutableSpan<int> r_orig_loops)
610 r_orig_loops.fill(-1);
611 const IndexRange orig_mesh_verts_range = mim.mesh_offsets.vert_offsets[orig_me_index];
613 int orig_mplen = orig_face.size();
614 if (f->size() != orig_mplen) {
617 BLI_assert(r_orig_loops.size() == orig_mplen);
624 int first_orig_v = f->vert[0]->orig;
625 if (first_orig_v == meshintersect::NO_INDEX) {
629 if (orig_me_index != mim.input_mesh_for_imesh_vert(first_orig_v)) {
634 for (
int i = 0; i < orig_mplen; ++i) {
635 int loop_i = i + orig_face.start();
636 if (orig_corner_verts[loop_i] == first_orig_v) {
644 int num_orig_loops_found = 0;
645 for (
int mp_loop_index = 0; mp_loop_index < orig_mplen; ++mp_loop_index) {
646 int orig_mp_loop_index = (mp_loop_index + offset) % orig_mplen;
647 const int vert_i = orig_corner_verts[orig_face.start() + orig_mp_loop_index];
648 int fv_orig = f->vert[mp_loop_index]->orig;
649 if (fv_orig != meshintersect::NO_INDEX) {
650 if (!orig_mesh_verts_range.contains(fv_orig)) {
651 fv_orig = meshintersect::NO_INDEX;
654 if (vert_i == fv_orig) {
655 const int vert_next =
656 orig_corner_verts[orig_face.start() + ((orig_mp_loop_index + 1) % orig_mplen)];
657 int fvnext_orig = f->vert[(mp_loop_index + 1) % orig_mplen]->orig;
658 if (fvnext_orig != meshintersect::NO_INDEX) {
659 if (!orig_mesh_verts_range.contains(fvnext_orig)) {
660 fvnext_orig = meshintersect::NO_INDEX;
663 if (vert_next == fvnext_orig) {
664 r_orig_loops[mp_loop_index] = orig_face.start() + orig_mp_loop_index;
665 ++num_orig_loops_found;
669 return num_orig_loops_found;
675static void copy_or_interp_loop_attributes(
const meshintersect::IMesh *im,
677 const Span<int> dst_to_src_face_map,
678 MeshesToIMeshInfo &mim)
680 const OffsetIndices<int> src_faces = mim.joined_mesh->faces();
681 const Span<int> orig_corner_verts = mim.joined_mesh->corner_verts();
682 const OffsetIndices<int> dst_faces = dest_mesh->faces();
684 Array<int> dst_to_src_corner_map(dst_faces.total_size());
685 for (
const int face : dst_faces.index_range()) {
686 const meshintersect::Face *f = im->face(face);
693 dst_to_src_corner_map.as_mutable_span().slice(dst_faces[face]));
697 mim.joined_mesh->attributes(),
700 dst_to_src_corner_map,
701 dst_to_src_face_map);
704static void gather_attributes_with_check(
const bke::AttributeAccessor src_attributes,
707 const bke::AttributeFilter &attribute_filter,
708 const Span<int> dst_to_src_map,
709 bke::MutableAttributeAccessor dst_attributes)
711 src_attributes.foreach_attribute([&](
const bke::AttributeIter &iter) {
712 if (iter.domain != src_domain) {
718 if (attribute_filter.allow_skip(iter.name)) {
721 const bke::GAttributeReader src = iter.get(src_domain);
722 const CommonVArrayInfo info = src.varray.common_info();
724 const bke::AttributeInitValue
init(
GPointer(src.varray.type(), info.data));
725 dst_attributes.add(iter.name, iter.domain, iter.data_type,
init);
728 bke::GSpanAttributeWriter dst = dst_attributes.lookup_or_add_for_write_only_span(
729 iter.name, dst_domain, iter.data_type);
742static Mesh *imesh_to_mesh(meshintersect::IMesh *im, MeshesToIMeshInfo &mim)
744 constexpr int dbg_level = 0;
747 int out_totvert = im->vert_size();
748 int out_faces_num = im->face_size();
750 for (
const meshintersect::Face *f : im->faces()) {
751 out_totloop += f->size();
756 bke::MutableAttributeAccessor dst_attributes =
result->attributes_for_write();
758 static_assert(meshintersect::NO_INDEX == -1);
761 MutableSpan<float3> positions =
result->vert_positions_for_write();
763 for (const int vert : range) {
764 const meshintersect::Vert *v = im->vert(vert);
765 copy_v3fl_v3db(positions[vert], v->co);
770 Array<int> dst_to_src_vert(out_totvert);
772 for (const int vert : range) {
773 const meshintersect::Vert *v = im->vert(vert);
774 dst_to_src_vert[vert] = v->orig;
777 gather_attributes_with_check(mim.joined_mesh->attributes(),
786 OffsetIndices<int> dst_faces;
787 if (out_faces_num != 0) {
788 MutableSpan<int> face_offsets =
result->face_offsets_for_write();
790 for (const int face : range) {
791 const meshintersect::Face *f = im->face(face);
792 face_offsets[face] = f->size();
798 MutableSpan<int> dst_corner_verts =
result->corner_verts_for_write();
800 for (const int face : range) {
801 const meshintersect::Face *f = im->face(face);
802 MutableSpan<int> face_verts = dst_corner_verts.slice(dst_faces[face]);
803 for (const int i : face_verts.index_range()) {
804 face_verts[i] = im->lookup_vert(f->vert[i]);
809 Array<int> dst_to_src_face(out_faces_num);
811 for (const int face : range) {
812 const meshintersect::Face *f = im->face(face);
813 dst_to_src_face[face] = f->orig;
816 gather_attributes_with_check(mim.joined_mesh->attributes(),
823 if (mim.joined_mesh->attributes().contains(
"material_index")) {
824 bke::SpanAttributeWriter dst_indices = dst_attributes.lookup_or_add_for_write_only_span<
int>(
826 if (mim.material_remaps.is_empty()) {
827 const VArraySpan src = *mim.joined_mesh->attributes().lookup<
int>(
"material_index");
832 dst_to_src_face, mim.material_remaps, mim.meshes, mim.mesh_offsets, dst_indices.span);
834 dst_indices.finish();
837 copy_or_interp_loop_attributes(im,
result, dst_to_src_face, mim);
843 Array<int> dst_to_src_edge(
result->edges_num, -1);
844 const OffsetIndices dst_polys =
result->faces();
845 const Span<int> dst_corner_edges =
result->corner_edges();
846 for (
int fi : im->face_index_range()) {
847 const meshintersect::Face *f = im->face(fi);
848 const IndexRange face = dst_polys[fi];
849 for (
int j : f->index_range()) {
850 if (f->edge_orig[j] != meshintersect::NO_INDEX) {
851 dst_to_src_edge[dst_corner_edges[face[j]]] = f->edge_orig[j];
855 gather_attributes_with_check(mim.joined_mesh->attributes(),
869static meshintersect::BoolOpType operation_to_mesh_arr_mode(
const Operation operation)
872 case Operation::Intersect:
873 return meshintersect::BoolOpType::Intersect;
874 case Operation::Union:
875 return meshintersect::BoolOpType::Union;
876 case Operation::Difference:
877 return meshintersect::BoolOpType::Difference;
880 return meshintersect::BoolOpType::None;
883static Mesh *mesh_boolean_mesh_arr(Span<const Mesh *> meshes,
884 Span<float4x4> transforms,
885 Span<Array<short>> material_remaps,
887 const bool hole_tolerant,
888 const meshintersect::BoolOpType boolean_mode,
892 BLI_assert(material_remaps.is_empty() || material_remaps.size() == meshes.
size());
893 if (meshes.
size() <= 0) {
898 const Mesh *joined_mesh = joined_meshes_set.get_mesh();
903 const int dbg_level = 0;
905 std::cout <<
"\nOLD_MESH_INTERSECT, nmeshes = " << meshes.
size() <<
"\n";
907 MeshesToIMeshInfo mim(meshes);
908 mim.joined_mesh = joined_mesh;
909 meshintersect::IMeshArena arena;
910 meshintersect::IMesh m_in = meshes_to_imesh(meshes, transforms, material_remaps, arena, &mim);
911 const auto shape_fn = [&](
int f) {
return mesh_id_for_face(f, mim.mesh_offsets); };
912 meshintersect::IMesh m_out = boolean_mesh(
913 m_in, boolean_mode, meshes.
size(), shape_fn, use_self, hole_tolerant,
nullptr, &arena);
916 write_obj_mesh(m_out,
"m_out");
922 if (r_intersecting_edges !=
nullptr) {
923 const OffsetIndices faces =
result->faces();
924 const Span<int> corner_edges =
result->corner_edges();
925 for (
int fi : m_out.face_index_range()) {
926 const meshintersect::Face &face = *m_out.face(fi);
927 const IndexRange mesh_face = faces[fi];
928 for (
int i : face.index_range()) {
929 if (face.is_intersect[i]) {
930 int e_index = corner_edges[mesh_face[i]];
931 r_intersecting_edges->append(e_index);
949#define BM_FACE_TAG BM_ELEM_SELECT_UV
979 Array<std::array<BMLoop *, 3>> &r_looptris)
981 const int meshes_num = meshes.
size();
985 const int tsize = transforms.
size();
989 is_flip[i] = is_negative_transform[i] != is_negative_transform[0];
992 is_negative_transform[i] =
false;
1004 allocsize.
totvert += meshes[i]->verts_num;
1005 allocsize.
totedge += meshes[i]->edges_num;
1006 allocsize.
totloop += meshes[i]->corners_num;
1007 allocsize.
totface += meshes[i]->faces_num;
1014 bm,
const_cast<const Mesh **
>(meshes.
begin()), meshes_num, &allocsize);
1022 verts_end[0] = meshes[0]->verts_num;
1023 faces_end[0] = meshes[0]->faces_num;
1028 verts_end[i] = verts_end[i - 1] + meshes[i]->verts_num;
1029 faces_end[i] = faces_end[i - 1] + meshes[i]->faces_num;
1034 for (
int j = faces_end[i - 1]; j < faces_end[i]; j++) {
1045 r_looptris.reinitialize(looptris_tot);
1056 if (i == verts_end[mesh_index]) {
1068 if (is_negative_transform[mesh_index]) {
1074 if (i < faces_end[0]) {
1079 int cur_mat = efa->
mat_nr;
1080 if (cur_mat < material_remaps[mesh_index].size()) {
1081 int new_mat = material_remaps[mesh_index][cur_mat];
1083 efa->
mat_nr = material_remaps[mesh_index][cur_mat];
1088 if (i == faces_end[mesh_index]) {
1098 switch (operation) {
1113 const int boolean_mode,
1117 BLI_assert(material_remaps.size() == 0 || material_remaps.size() == meshes.
size());
1122 if (meshes.
size() == 1) {
1129 if (meshes.
size() == 2) {
1152 Mesh *prev_result_mesh =
nullptr;
1169 if (prev_result_mesh !=
nullptr) {
1174 if (i < meshes.
size() - 2) {
1175 two_meshes[0] = result_i_mesh;
1176 two_meshes[1] = meshes[i + 2];
1178 two_transforms[1] = transforms[i + 2];
1180 two_remaps[1] = material_remaps[i + 2];
1181 prev_result_mesh = result_i_mesh;
1184 return result_i_mesh;
1192#ifdef BENCHMARK_TIME
1194static void write_boolean_benchmark_time(
1199 const int num_faces_1 = mesh1 ? mesh1->
faces_num : 0;
1200 const int num_faces_2 = mesh2 ? mesh2->
faces_num : 0;
1201 const int num_tris_1 = mesh1 ? mesh1->corner_tris().size() : 0;
1202 const int num_tris_2 = mesh2 ? mesh2->corner_tris().size() : 0;
1206 bool first_time =
false;
1207 if (!std::filesystem::exists(BENCHMARK_FILE)) {
1211 std::ofstream outfile(BENCHMARK_FILE, std::ios_base::app);
1213 if (outfile.is_open()) {
1215 outfile <<
"solver,op,mesh1,mesh2,face1,face2,tris1,tris2,time_in_ms,threads" << std::endl;
1217 outfile << solver <<
"," << op <<
",\"" << mesh1_name <<
"\",\"" << mesh2_name <<
"\","
1218 << num_faces_1 <<
"," << num_faces_2 <<
"," << num_tris_1 <<
"," << num_tris_2 <<
","
1219 << time_ms <<
"," << threads << std::endl;
1223 std::cerr <<
"Unable to open benchmark file: " << BENCHMARK_FILE << std::endl;
1238 Mesh *ans =
nullptr;
1239#ifdef BENCHMARK_TIME
1249 r_intersecting_edges);
1254 ans = mesh_boolean_mesh_arr(meshes,
1260 r_intersecting_edges);
1268 meshes, transforms, material_remaps, op_params, r_intersecting_edges, r_error);
1276#ifdef BENCHMARK_TIME
1279 float time_ms = duration.count() / 1.0e6f;
1284 const Mesh *mesh1 = meshes.
size() > 0 ? meshes[0] :
nullptr;
1285 const Mesh *mesh2 = meshes.
size() > 0 ? meshes[1] :
nullptr;
1289 write_boolean_benchmark_time(solverstr, opstr, mesh1, mesh2, time_ms);
#define BLI_assert_unreachable()
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
constexpr const T * data() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
void reinitialize(const int64_t new_size)
static IndexMask from_indices(Span< T > indices, LinearAllocator<> &memory)
constexpr IndexRange drop_back(int64_t n) const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr IndexRange()=default
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr const T * begin() const
constexpr bool is_empty() const
ccl_device_inline float interp(const float a, const float b, const float t)
IndexMask indices_non_negative(const IndexMask &universe, Span< int > values, LinearAllocator<> &memory)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void mix_groups(GSpan src, OffsetIndices< int > groups, Span< int > all_indices, std::optional< Span< float > > all_weights, GMutableSpan dst)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
bool mesh_validate(Mesh &mesh, bool verbose=false, bool allow_missing_edges=false)
constexpr ParallelGrainSize grain_size(int grain_size)
static int operation_to_float_mode(const Operation operation)
void copy_attribute_using_map(GSpan src, Span< int > out_to_in_map, GMutableSpan dst)
int mesh_id_for_face(int face_id, const MeshOffsets &mesh_offsets)
Mesh * mesh_boolean_manifold(Span< const Mesh * > meshes, Span< float4x4 > transforms, Span< Array< short > > material_remaps, BooleanOpParameters op_params, Vector< int > *r_intersecting_edges, BooleanError *r_error)
void interpolate_corner_attributes(bke::MutableAttributeAccessor output_attrs, bke::AttributeAccessor input_attrs, Mesh *output_mesh, const Mesh *input_mesh, Span< int > out_to_in_corner_map, Span< int > out_to_in_face_map)
IndexRange vertex_range_for_face(int face_id, const MeshOffsets &mesh_offsets)
static Mesh * mesh_boolean_float(Span< const Mesh * > meshes, Span< float4x4 > transforms, Span< Array< short > > material_remaps, const int boolean_mode, Vector< int > *)
void set_material_from_map(Span< int > out_to_in_map, Span< Array< short > > material_remaps, Span< const Mesh * > meshes, const MeshOffsets &mesh_offsets, MutableSpan< int > dst)
static BMesh * mesh_bm_concat(Span< const Mesh * > meshes, Span< float4x4 > transforms, Span< Array< short > > material_remaps, Array< std::array< BMLoop *, 3 > > &r_looptris)
bke::GeometrySet join_meshes_with_transforms(Span< const Mesh * > meshes, Span< float4x4 > transforms)
Mesh * mesh_boolean(Span< const Mesh * > meshes, Span< float4x4 > transforms, Span< Array< short > > material_remaps, BooleanOpParameters op_params, Solver solver, Vector< int > *r_intersecting_edges, BooleanError *r_error)
static int face_boolean_operand(BMFace *f, void *)
RealizeInstancesResult realize_instances(bke::GeometrySet geometry_set, const RealizeInstancesOptions &options)
bool is_negative(const MatBase< T, 3, 3 > &mat)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
std::chrono::nanoseconds Nanoseconds
Clock::time_point TimePoint
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MatBase< float, 4, 4 > float4x4
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams *params)
Mesh -> BMesh.
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
bool BM_mesh_intersect(BMesh *bm, const Span< std::array< BMLoop *, 3 > > looptris, int(*test_fn)(BMFace *f, void *user_data), void *user_data, const bool use_self, const bool use_separate, const bool use_dissolve, const bool use_island_connect, const bool use_partial_connect, const bool use_edge_tag, const int boolean_mode, const float eps)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
void BM_mesh_calc_tessellation_beauty(BMesh *bm, MutableSpan< std::array< BMLoop *, 3 > > looptris)
@ BMESH_ISECT_BOOLEAN_NONE
@ BMESH_ISECT_BOOLEAN_DIFFERENCE
@ BMESH_ISECT_BOOLEAN_UNION
@ BMESH_ISECT_BOOLEAN_ISECT
MINLINE void negate_v3(float r[3])
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
void BKE_id_free(Main *bmain, void *idv)
MINLINE float normalize_v3(float n[3])
int BLI_system_num_threads_override_get()
void BM_face_normal_flip_ex(BMesh *bm, BMFace *f, const int cd_loop_mdisp_offset, const bool use_loop_mdisp_flip)
Face Flip Normal.
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
void BM_mesh_copy_init_customdata_from_mesh_array(BMesh *bm_dst, const Mesh *me_src_array[], const int me_src_array_len, const BMAllocTemplate *allocsize)
VecBase< float, 3 > float3
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static MatBase identity()
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_instances(std::unique_ptr< Instances > instances)
bke::GeometrySet geometry
bool no_self_intersections
OffsetIndices< int > corner_offsets
OffsetIndices< int > edge_offsets
OffsetIndices< int > face_offsets
OffsetIndices< int > vert_offsets
Array< int > corner_start