Blender V5.3
BLI_mesh_boolean_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include <fstream>
8#include <iostream>
9#include <sstream>
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_array.hh"
14#include "BLI_map.hh"
15#include "BLI_math_mpq.hh"
17#include "BLI_mesh_boolean.hh"
18#include "BLI_vector.hh"
19
20#ifdef WITH_GMP
21namespace blender::meshintersect::tests {
22namespace {
23
24constexpr bool DO_OBJ = false;
25
26/* Build and hold an IMesh from a string spec. Also hold and own resources used by IMesh. */
27class IMeshBuilder {
28 public:
29 IMesh imesh;
30 IMeshArena arena;
31
32 /* "Edge orig" indices are an encoding of <input face#, position in face of start of edge>. */
33 static constexpr int MAX_FACE_LEN = 1000; /* Used for forming "orig edge" indices only. */
34
35 static int edge_index(int face_index, int facepos)
36 {
37 return face_index * MAX_FACE_LEN + facepos;
38 }
39
40 static std::pair<int, int> face_and_pos_for_edge_index(int e_index)
41 {
42 return std::pair<int, int>(e_index / MAX_FACE_LEN, e_index % MAX_FACE_LEN);
43 }
44
53 IMeshBuilder(const char *spec)
54 {
55 std::istringstream ss(spec);
56 std::string line;
57 getline(ss, line);
58 std::istringstream hdrss(line);
59 int nv, nf;
60 hdrss >> nv >> nf;
61 if (nv == 0 || nf == 0) {
62 return;
63 }
64 arena.reserve(nv, nf);
65 Vector<const Vert *> verts;
66 Vector<Face *> faces;
67 bool spec_ok = true;
68 int v_index = 0;
69 while (v_index < nv && spec_ok && getline(ss, line)) {
70 std::istringstream iss(line);
71 mpq_class p0;
72 mpq_class p1;
73 mpq_class p2;
74 iss >> p0 >> p1 >> p2;
75 spec_ok = !iss.fail();
76 verts.append(arena.add_or_find_vert(mpq3(p0, p1, p2), v_index));
77 ++v_index;
78 }
79 if (v_index != nv) {
80 spec_ok = false;
81 }
82 int f_index = 0;
83 while (f_index < nf && spec_ok && getline(ss, line)) {
84 std::istringstream fss(line);
85 Vector<const Vert *> face_verts;
86 Vector<int> edge_orig;
87 int fpos = 0;
88 while (spec_ok && fss >> v_index) {
89 if (v_index < 0 || v_index >= nv) {
90 spec_ok = false;
91 continue;
92 }
93 face_verts.append(verts[v_index]);
94 edge_orig.append(edge_index(f_index, fpos));
95 ++fpos;
96 }
97 Face *facep = arena.add_face(face_verts, f_index, edge_orig);
98 faces.append(facep);
99 ++f_index;
100 }
101 if (f_index != nf) {
102 spec_ok = false;
103 }
104 if (!spec_ok) {
105 std::cout << "Bad spec: " << spec;
106 return;
107 }
108 imesh = IMesh(faces);
109 }
110};
111
112static int all_shape_zero(int /*t*/)
113{
114 return 0;
115}
116
117TEST(boolean_trimesh, Empty)
118{
119 IMeshArena arena;
120 IMesh in;
121 IMesh out = boolean_trimesh(in, BoolOpType::None, 1, all_shape_zero, true, false, &arena);
122 out.populate_vert();
123 EXPECT_EQ(out.vert_size(), 0);
124 EXPECT_EQ(out.face_size(), 0);
125}
126
127TEST(boolean_trimesh, TetTetTrimesh)
128{
129 const char *spec = R"(8 8
130 0 0 0
131 2 0 0
132 1 2 0
133 1 1 2
134 0 0 1
135 2 0 1
136 1 2 1
137 1 1 3
138 0 2 1
139 0 1 3
140 1 2 3
141 2 0 3
142 4 6 5
143 4 5 7
144 5 6 7
145 6 4 7
146 )";
147
148 IMeshBuilder mb(spec);
149 IMesh out = boolean_trimesh(
150 mb.imesh, BoolOpType::None, 1, all_shape_zero, true, false, &mb.arena);
151 out.populate_vert();
152 EXPECT_EQ(out.vert_size(), 11);
153 EXPECT_EQ(out.face_size(), 20);
154 if (DO_OBJ) {
155 write_obj_mesh(out, "tettet_tm");
156 }
157
158 IMeshBuilder mb2(spec);
159 IMesh out2 = boolean_trimesh(
160 mb2.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, &mb2.arena);
161 out2.populate_vert();
162 EXPECT_EQ(out2.vert_size(), 10);
163 EXPECT_EQ(out2.face_size(), 16);
164 if (DO_OBJ) {
165 write_obj_mesh(out2, "tettet_union_tm");
166 }
167
168 IMeshBuilder mb3(spec);
169 IMesh out3 = boolean_trimesh(
170 mb3.imesh,
171 BoolOpType::Union,
172 2,
173 [](int t) { return t < 4 ? 0 : 1; },
174 false,
175 false,
176 &mb3.arena);
177 out3.populate_vert();
178 EXPECT_EQ(out3.vert_size(), 10);
179 EXPECT_EQ(out3.face_size(), 16);
180 if (DO_OBJ) {
181 write_obj_mesh(out3, "tettet_union_binary_tm");
182 }
183
184 IMeshBuilder mb4(spec);
185 IMesh out4 = boolean_trimesh(
186 mb4.imesh,
187 BoolOpType::Union,
188 2,
189 [](int t) { return t < 4 ? 0 : 1; },
190 true,
191 false,
192 &mb4.arena);
193 out4.populate_vert();
194 EXPECT_EQ(out4.vert_size(), 10);
195 EXPECT_EQ(out4.face_size(), 16);
196 if (DO_OBJ) {
197 write_obj_mesh(out4, "tettet_union_binary_self_tm");
198 }
199
200 IMeshBuilder mb5(spec);
201 IMesh out5 = boolean_trimesh(
202 mb5.imesh,
203 BoolOpType::Intersect,
204 2,
205 [](int t) { return t < 4 ? 0 : 1; },
206 false,
207 false,
208 &mb5.arena);
209 out5.populate_vert();
210 EXPECT_EQ(out5.vert_size(), 4);
211 EXPECT_EQ(out5.face_size(), 4);
212 if (DO_OBJ) {
213 write_obj_mesh(out5, "tettet_intersect_binary_tm");
214 }
215
216 IMeshBuilder mb6(spec);
217 IMesh out6 = boolean_trimesh(
218 mb6.imesh,
219 BoolOpType::Difference,
220 2,
221 [](int t) { return t < 4 ? 0 : 1; },
222 false,
223 false,
224 &mb6.arena);
225 out6.populate_vert();
226 EXPECT_EQ(out6.vert_size(), 6);
227 EXPECT_EQ(out6.face_size(), 8);
228 if (DO_OBJ) {
229 write_obj_mesh(out6, "tettet_difference_binary_tm");
230 }
231
232 IMeshBuilder mb7(spec);
233 IMesh out7 = boolean_trimesh(
234 mb7.imesh,
235 BoolOpType::Difference,
236 2,
237 [](int t) { return t < 4 ? 1 : 0; },
238 false,
239 false,
240 &mb7.arena);
241 out7.populate_vert();
242 EXPECT_EQ(out7.vert_size(), 8);
243 EXPECT_EQ(out7.face_size(), 12);
244 if (DO_OBJ) {
245 write_obj_mesh(out7, "tettet_difference_rev_binary_tm");
246 }
247}
248
249TEST(boolean_trimesh, TetTet2Trimesh)
250{
251 const char *spec = R"(8 8
252 0 1 -1
253 7/8 -1/2 -1
254 -7/8 -1/2 -1
255 0 0 1
256 0 1 0
257 7/8 -1/2 0
258 -7/8 -1/2 0
259 0 0 2
260 0 3 1
261 0 1 2
262 1 3 2
263 2 3 0
264 4 7 5
265 4 5 6
266 5 7 6
267 6 7 4
268 )";
269
270 IMeshBuilder mb(spec);
271 IMesh out = boolean_trimesh(
272 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, &mb.arena);
273 out.populate_vert();
274 EXPECT_EQ(out.vert_size(), 10);
275 EXPECT_EQ(out.face_size(), 16);
276 if (DO_OBJ) {
277 write_obj_mesh(out, "tettet2_union_tm");
278 }
279}
280
281TEST(boolean_trimesh, CubeTetTrimesh)
282{
283 const char *spec = R"(12 16
284 -1 -1 -1
285 -1 -1 1
286 -1 1 -1
287 -1 1 1
288 1 -1 -1
289 1 -1 1
290 1 1 -1
291 1 1 1
292 0 1/2 1/2
293 1/2 -1/4 1/2
294 -1/2 -1/4 1/2
295 0 0 3/2
296 0 1 3
297 0 3 2
298 2 3 7
299 2 7 6
300 6 7 5
301 6 5 4
302 4 5 1
303 4 1 0
304 2 6 4
305 2 4 0
306 7 3 1
307 7 1 5
308 8 11 9
309 8 9 10
310 9 11 10
311 10 11 8
312 )";
313
314 IMeshBuilder mb(spec);
315 IMesh out = boolean_trimesh(
316 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, &mb.arena);
317 out.populate_vert();
318 EXPECT_EQ(out.vert_size(), 14);
319 EXPECT_EQ(out.face_size(), 24);
320 if (DO_OBJ) {
321 write_obj_mesh(out, "cubetet_union_tm");
322 }
323}
324
325TEST(boolean_trimesh, BinaryTetTetTrimesh)
326{
327 const char *spec = R"(8 8
328 0 0 0
329 2 0 0
330 1 2 0
331 1 1 2
332 0 0 1
333 2 0 1
334 1 2 1
335 1 1 3
336 0 2 1
337 0 1 3
338 1 2 3
339 2 0 3
340 4 6 5
341 4 5 7
342 5 6 7
343 6 4 7
344 )";
345
346 IMeshBuilder mb(spec);
347 IMesh out = boolean_trimesh(
348 mb.imesh,
349 BoolOpType::Intersect,
350 2,
351 [](int t) { return t < 4 ? 0 : 1; },
352 false,
353 false,
354 &mb.arena);
355 out.populate_vert();
356 EXPECT_EQ(out.vert_size(), 4);
357 EXPECT_EQ(out.face_size(), 4);
358 if (DO_OBJ) {
359 write_obj_mesh(out, "binary_tettet_isect_tm");
360 }
361}
362
363TEST(boolean_trimesh, TetTetCoplanarTrimesh)
364{
365 const char *spec = R"(8 8
366 0 1 0
367 7/8 -1/2 0
368 -7/8 -1/2 0
369 0 0 1
370 0 1 0
371 7/8 -1/2 0
372 -7/8 -1/2 0
373 0 0 -1
374 0 3 1
375 0 1 2
376 1 3 2
377 2 3 0
378 4 5 7
379 4 6 5
380 5 6 7
381 6 4 7
382 )";
383
384 IMeshBuilder mb(spec);
385 IMesh out = boolean_trimesh(
386 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, &mb.arena);
387 out.populate_vert();
388 EXPECT_EQ(out.vert_size(), 5);
389 EXPECT_EQ(out.face_size(), 6);
390 if (DO_OBJ) {
391 write_obj_mesh(out, "tettet_coplanar_tm");
392 }
393}
394
395TEST(boolean_trimesh, TetInsideTetTrimesh)
396{
397 const char *spec = R"(8 8
398 0 0 0
399 2 0 0
400 1 2 0
401 1 1 2
402 -1 -3/4 -1/2
403 3 -3/4 -1/2
404 1 13/4 -1/2
405 1 5/4 7/2
406 0 2 1
407 0 1 3
408 1 2 3
409 2 0 3
410 4 6 5
411 4 5 7
412 5 6 7
413 6 4 7
414 )";
415
416 IMeshBuilder mb(spec);
417 IMesh out = boolean_trimesh(
418 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, &mb.arena);
419 out.populate_vert();
420 EXPECT_EQ(out.vert_size(), 4);
421 EXPECT_EQ(out.face_size(), 4);
422 if (DO_OBJ) {
423 write_obj_mesh(out, "tetinsidetet_tm");
424 }
425}
426
427TEST(boolean_trimesh, TetBesideTetTrimesh)
428{
429 const char *spec = R"(8 8
430 0 0 0
431 2 0 0
432 1 2 0
433 1 1 2
434 3 0 0
435 5 0 0
436 4 2 0
437 4 1 2
438 0 2 1
439 0 1 3
440 1 2 3
441 2 0 3
442 4 6 5
443 4 5 7
444 5 6 7
445 6 4 7
446 )";
447
448 IMeshBuilder mb(spec);
449 IMesh out = boolean_trimesh(
450 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, &mb.arena);
451 out.populate_vert();
452 EXPECT_EQ(out.vert_size(), 8);
453 EXPECT_EQ(out.face_size(), 8);
454 if (DO_OBJ) {
455 write_obj_mesh(out, "tetbesidetet_tm");
456 }
457}
458
459TEST(boolean_trimesh, DegenerateTris)
460{
461 const char *spec = R"(10 10
462 0 0 0
463 2 0 0
464 1 2 0
465 1 1 2
466 0 0 1
467 2 0 1
468 1 2 1
469 1 1 3
470 0 0 0
471 1 0 0
472 0 2 1
473 0 8 1
474 0 1 3
475 1 2 3
476 2 0 3
477 4 6 5
478 4 5 7
479 5 6 7
480 6 4 7
481 0 1 9
482 )";
483
484 IMeshBuilder mb(spec);
485 IMesh out = boolean_trimesh(
486 mb.imesh,
487 BoolOpType::Intersect,
488 2,
489 [](int t) { return t < 5 ? 0 : 1; },
490 false,
491 false,
492 &mb.arena);
493 out.populate_vert();
494 EXPECT_EQ(out.vert_size(), 4);
495 EXPECT_EQ(out.face_size(), 4);
496 if (DO_OBJ) {
497 write_obj_mesh(out, "degenerate_tris_tm");
498 }
499}
500
501TEST(boolean_polymesh, TetTet)
502{
503 const char *spec = R"(8 8
504 0 0 0
505 2 0 0
506 1 2 0
507 1 1 2
508 0 0 1
509 2 0 1
510 1 2 1
511 1 1 3
512 0 2 1
513 0 1 3
514 1 2 3
515 2 0 3
516 4 6 5
517 4 5 7
518 5 6 7
519 6 4 7
520 )";
521
522 IMeshBuilder mb(spec);
523 IMesh out = boolean_mesh(
524 mb.imesh, BoolOpType::None, 1, all_shape_zero, true, false, nullptr, &mb.arena);
525 out.populate_vert();
526 EXPECT_EQ(out.vert_size(), 11);
527 EXPECT_EQ(out.face_size(), 13);
528 if (DO_OBJ) {
529 write_obj_mesh(out, "tettet");
530 }
531
532 IMeshBuilder mb2(spec);
533 IMesh out2 = boolean_mesh(
534 mb2.imesh,
535 BoolOpType::None,
536 2,
537 [](int t) { return t < 4 ? 0 : 1; },
538 false,
539 false,
540 nullptr,
541 &mb2.arena);
542 out2.populate_vert();
543 EXPECT_EQ(out2.vert_size(), 11);
544 EXPECT_EQ(out2.face_size(), 13);
545 if (DO_OBJ) {
546 write_obj_mesh(out, "tettet2");
547 }
548}
549
550TEST(boolean_polymesh, CubeCube)
551{
552 const char *spec = R"(16 12
553 -1 -1 -1
554 -1 -1 1
555 -1 1 -1
556 -1 1 1
557 1 -1 -1
558 1 -1 1
559 1 1 -1
560 1 1 1
561 1/2 1/2 1/2
562 1/2 1/2 5/2
563 1/2 5/2 1/2
564 1/2 5/2 5/2
565 5/2 1/2 1/2
566 5/2 1/2 5/2
567 5/2 5/2 1/2
568 5/2 5/2 5/2
569 0 1 3 2
570 6 2 3 7
571 4 6 7 5
572 0 4 5 1
573 0 2 6 4
574 3 1 5 7
575 8 9 11 10
576 14 10 11 15
577 12 14 15 13
578 8 12 13 9
579 8 10 14 12
580 11 9 13 15
581 )";
582
583 IMeshBuilder mb(spec);
584 if (DO_OBJ) {
585 write_obj_mesh(mb.imesh, "cube_cube_in");
586 }
587 IMesh out = boolean_mesh(
588 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, nullptr, &mb.arena);
589 out.populate_vert();
590 EXPECT_EQ(out.vert_size(), 20);
591 EXPECT_EQ(out.face_size(), 12);
592 if (DO_OBJ) {
593 write_obj_mesh(out, "cubecube_union");
594 }
595
596 IMeshBuilder mb2(spec);
597 IMesh out2 = boolean_mesh(
598 mb2.imesh,
599 BoolOpType::None,
600 2,
601 [](int t) { return t < 6 ? 0 : 1; },
602 false,
603 false,
604 nullptr,
605 &mb2.arena);
606 out2.populate_vert();
607 EXPECT_EQ(out2.vert_size(), 22);
608 EXPECT_EQ(out2.face_size(), 18);
609 if (DO_OBJ) {
610 write_obj_mesh(out2, "cubecube_none");
611 }
612}
613
614TEST(boolean_polymesh, CubeCone)
615{
616 const char *spec = R"(14 12
617 -1 -1 -1
618 -1 -1 1
619 -1 1 -1
620 -1 1 1
621 1 -1 -1
622 1 -1 1
623 1 1 -1
624 1 1 1
625 0 1/2 3/4
626 119/250 31/200 3/4
627 147/500 -81/200 3/4
628 0 0 7/4
629 -147/500 -81/200 3/4
630 -119/250 31/200 3/4
631 0 1 3 2
632 2 3 7 6
633 6 7 5 4
634 4 5 1 0
635 2 6 4 0
636 7 3 1 5
637 8 11 9
638 9 11 10
639 10 11 12
640 12 11 13
641 13 11 8
642 8 9 10 12 13)";
643
644 IMeshBuilder mb(spec);
645 IMesh out = boolean_mesh(
646 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true, false, nullptr, &mb.arena);
647 out.populate_vert();
648 EXPECT_EQ(out.vert_size(), 14);
649 EXPECT_EQ(out.face_size(), 12);
650 if (DO_OBJ) {
651 write_obj_mesh(out, "cubeccone");
652 }
653}
654
655TEST(boolean_polymesh, CubeCubeCoplanar)
656{
657 const char *spec = R"(16 12
658 -1 -1 -1
659 -1 -1 1
660 -1 1 -1
661 -1 1 1
662 1 -1 -1
663 1 -1 1
664 1 1 -1
665 1 1 1
666 -1/2 -1/2 1
667 -1/2 -1/2 2
668 -1/2 1/2 1
669 -1/2 1/2 2
670 1/2 -1/2 1
671 1/2 -1/2 2
672 1/2 1/2 1
673 1/2 1/2 2
674 0 1 3 2
675 2 3 7 6
676 6 7 5 4
677 4 5 1 0
678 2 6 4 0
679 7 3 1 5
680 8 9 11 10
681 10 11 15 14
682 14 15 13 12
683 12 13 9 8
684 10 14 12 8
685 15 11 9 13
686 )";
687
688 IMeshBuilder mb(spec);
689 IMesh out = boolean_mesh(
690 mb.imesh,
691 BoolOpType::Union,
692 2,
693 [](int t) { return t < 6 ? 0 : 1; },
694 false,
695 false,
696 nullptr,
697 &mb.arena);
698 out.populate_vert();
699 EXPECT_EQ(out.vert_size(), 16);
700 EXPECT_EQ(out.face_size(), 12);
701 if (DO_OBJ) {
702 write_obj_mesh(out, "cubecube_coplanar");
703 }
704}
705
706TEST(boolean_polymesh, TetTeTCoplanarDiff)
707{
708 const char *spec = R"(8 8
709 0 1 0
710 7/8 -1/2 0
711 -7/8 -1/2 0
712 0 0 1
713 0 1 0
714 7/8 -1/2 0
715 -7/8 -1/2 0
716 0 0 -1
717 0 3 1
718 0 1 2
719 1 3 2
720 2 3 0
721 4 5 7
722 4 6 5
723 5 6 7
724 6 4 7
725 )";
726
727 IMeshBuilder mb(spec);
728 IMesh out = boolean_mesh(
729 mb.imesh,
730 BoolOpType::Difference,
731 2,
732 [](int t) { return t < 4 ? 0 : 1; },
733 false,
734 false,
735 nullptr,
736 &mb.arena);
737 out.populate_vert();
738 EXPECT_EQ(out.vert_size(), 4);
739 EXPECT_EQ(out.face_size(), 4);
740 if (DO_OBJ) {
741 write_obj_mesh(out, "tettet_coplanar_diff");
742 }
743}
744
745TEST(boolean_polymesh, CubeCubeStep)
746{
747 const char *spec = R"(16 12
748 0 -1 0
749 0 -1 2
750 0 1 0
751 0 1 2
752 2 -1 0
753 2 -1 2
754 2 1 0
755 2 1 2
756 -1 -1 -1
757 -1 -1 1
758 -1 1 -1
759 -1 1 1
760 1 -1 -1
761 1 -1 1
762 1 1 -1
763 1 1 1
764 0 1 3 2
765 2 3 7 6
766 6 7 5 4
767 4 5 1 0
768 2 6 4 0
769 7 3 1 5
770 8 9 11 10
771 10 11 15 14
772 14 15 13 12
773 12 13 9 8
774 10 14 12 8
775 15 11 9 13
776 )";
777
778 IMeshBuilder mb(spec);
779 IMesh out = boolean_mesh(
780 mb.imesh,
781 BoolOpType::Difference,
782 2,
783 [](int t) { return t < 6 ? 0 : 1; },
784 false,
785 false,
786 nullptr,
787 &mb.arena);
788 out.populate_vert();
789 EXPECT_EQ(out.vert_size(), 12);
790 EXPECT_EQ(out.face_size(), 8);
791 if (DO_OBJ) {
792 write_obj_mesh(out, "cubecubestep");
793 }
794}
795
796TEST(boolean_polymesh, CubeCyl4)
797{
798 const char *spec = R"(16 12
799 0 1 -1
800 0 1 1
801 1 0 -1
802 1 0 1
803 0 -1 -1
804 0 -1 1
805 -1 0 -1
806 -1 0 1
807 -1 -1 -1
808 -1 -1 1
809 -1 1 -1
810 -1 1 1
811 1 -1 -1
812 1 -1 1
813 1 1 -1
814 1 1 1
815 0 1 3 2
816 2 3 5 4
817 3 1 7 5
818 4 5 7 6
819 6 7 1 0
820 0 2 4 6
821 8 9 11 10
822 10 11 15 14
823 14 15 13 12
824 12 13 9 8
825 10 14 12 8
826 15 11 9 13
827 )";
828
829 IMeshBuilder mb(spec);
830 IMesh out = boolean_mesh(
831 mb.imesh,
832 BoolOpType::Difference,
833 2,
834 [](int t) { return t < 6 ? 1 : 0; },
835 false,
836 false,
837 nullptr,
838 &mb.arena);
839 out.populate_vert();
840 EXPECT_EQ(out.vert_size(), 16);
841 EXPECT_EQ(out.face_size(), 20);
842 if (DO_OBJ) {
843 write_obj_mesh(out, "cubecyl4");
844 }
845}
846
847TEST(boolean_polymesh, CubeCubesubdivDiff)
848{
849 /* A cube intersected by a subdivided cube that intersects first cubes edges exactly. */
850 const char *spec = R"(26 22
851 2 1/3 2
852 2 -1/3 2
853 2 -1/3 0
854 2 1/3 0
855 0 -1/3 2
856 0 1/3 2
857 0 1/3 0
858 0 -1/3 0
859 1 1/3 2
860 1 -1/3 2
861 1 1/3 0
862 1 -1/3 0
863 0 -1/3 1
864 0 1/3 1
865 2 1/3 1
866 2 -1/3 1
867 1 1/3 1
868 1 -1/3 1
869 -1 -1 -1
870 -1 -1 1
871 -1 1 -1
872 -1 1 1
873 1 -1 -1
874 1 -1 1
875 1 1 -1
876 1 1 1
877 17 9 4 12
878 13 6 7 12
879 15 2 3 14
880 11 7 6 10
881 16 13 5 8
882 9 1 0 8
883 4 9 8 5
884 14 16 8 0
885 2 11 10 3
886 15 1 9 17
887 2 15 17 11
888 3 10 16 14
889 10 6 13 16
890 1 15 14 0
891 5 13 12 4
892 11 17 12 7
893 19 21 20 18
894 21 25 24 20
895 25 23 22 24
896 23 19 18 22
897 18 20 24 22
898 23 25 21 19
899 )";
900
901 IMeshBuilder mb(spec);
902 IMesh out = boolean_mesh(
903 mb.imesh,
904 BoolOpType::Difference,
905 2,
906 [](int t) { return t < 16 ? 1 : 0; },
907 false,
908 false,
909 nullptr,
910 &mb.arena);
911 out.populate_vert();
912 EXPECT_EQ(out.vert_size(), 16);
913 EXPECT_EQ(out.face_size(), 10);
914 if (DO_OBJ) {
915 write_obj_mesh(out, "cubecubesubdivdiff");
916 }
917}
918
919TEST(boolean_polymesh, CubePlane)
920{
921 const char *spec = R"(12 7
922 -2 -2 0
923 2 -2 0
924 -2 2 0
925 2 2 0
926 -1 -1 -1
927 -1 -1 1
928 -1 1 -1
929 -1 1 1
930 1 -1 -1
931 1 -1 1
932 1 1 -1
933 1 1 1
934 0 1 3 2
935 4 5 7 6
936 6 7 11 10
937 10 11 9 8
938 8 9 5 4
939 6 10 8 4
940 11 7 5 9
941)";
942
943 IMeshBuilder mb(spec);
944 IMesh out = boolean_mesh(
945 mb.imesh,
946 BoolOpType::Difference,
947 2,
948 [](int t) { return t >= 1 ? 0 : 1; },
949 false,
950 false,
951 nullptr,
952 &mb.arena);
953 out.populate_vert();
954 EXPECT_EQ(out.vert_size(), 8);
955 EXPECT_EQ(out.face_size(), 6);
956 if (DO_OBJ) {
957 write_obj_mesh(out, "cubeplane");
958 }
959}
960
961} // namespace
962} // namespace blender::meshintersect::tests
963#endif
Read Blender memory allocation and freeing.
#define TEST(a, b)
#define EXPECT_EQ(result, expect)