Blender V5.3
mball_tessellate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cctype>
10#include <cfloat>
11#include <cmath>
12#include <cstdio>
13#include <cstdlib>
14#include <cstring>
15
16#include "MEM_guardedalloc.h"
17
18#include "DNA_layer_types.h"
19#include "DNA_meta_types.h"
20#include "DNA_object_types.h"
21#include "DNA_scene_types.h"
22
23#include "BLI_listbase.hh"
24#include "BLI_math_geom_c.hh"
25#include "BLI_math_matrix_c.hh"
27#include "BLI_math_vector.hh"
28#include "BLI_math_vector_c.hh"
29#include "BLI_memarena.hh"
30#include "BLI_string_utils.hh"
31#include "BLI_utildefines.hh"
32
33#include "BKE_global.hh"
34#include "BKE_mball_tessellate.hh" /* own include */
35#include "BKE_mesh.hh"
36#include "BKE_object.hh"
37#include "BKE_scene.hh"
38
39#include "DEG_depsgraph.hh"
41
42#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
43
44namespace blender {
45
46/* experimental (faster) normal calculation (see #103021) */
47#define USE_ACCUM_NORMAL
48
49#define MBALL_ARRAY_LEN_INIT 4096
50
51/* Data types */
52
54struct CORNER {
55 int i, j, k; /* (i, j, k) is index within lattice */
56 float co[3], value; /* location and function value */
58};
59
61struct CUBE {
62 int i, j, k; /* lattice location of cube */
63 CORNER *corners[8]; /* eight corners */
64};
65
67struct CUBES {
68 CUBE cube; /* a single cube */
69 CUBES *next; /* remaining elements */
70};
71
73struct CENTERLIST {
74 int i, j, k; /* cube location */
75 CENTERLIST *next; /* remaining elements */
76};
77
79struct EDGELIST {
80 int i1, j1, k1, i2, j2, k2; /* edge corner ids */
81 int vid; /* vertex id */
82 EDGELIST *next; /* remaining elements */
83};
84
86struct INTLIST {
87 int i; /* an integer */
88 INTLIST *next; /* remaining elements */
89};
90
92struct INTLISTS {
93 INTLIST *list; /* a list of integers */
94 INTLISTS *next; /* remaining elements */
95};
96
98struct Box {
99 float min[3], max[3];
100 const MetaElem *ml;
101};
102
103struct MetaballBVHNode { /* node */
104 Box bb[2]; /* AABB of children */
106};
107
109struct PROCESS {
110 float thresh, size; /* mball threshold, single cube size */
111 float delta; /* small delta for calculating normals */
112 uint converge_res; /* converge procedure resolution (more = slower) */
113
114 MetaElem **mainb; /* array of all meta-elems. */
115 uint totelem, mem; /* number of meta-elems. */
116
117 MetaballBVHNode metaball_bvh; /* The simplest bvh */
118 Box allbb; /* Bounding box of all meta-elems */
119
120 MetaballBVHNode **bvh_queue; /* Queue used during bvh traversal */
122
123 CUBES *cubes; /* stack of cubes waiting for polygonization */
124 CENTERLIST **centers; /* cube center hash table */
125 CORNER **corners; /* corner value hash table */
126 EDGELIST **edges; /* edge and vertex id hash table */
127
128 int (*indices)[4]; /* output indices */
129 uint totindex; /* size of memory allocated for indices */
130 uint curindex; /* number of currently added indices */
131
132 Vector<float3> co; /* surface vertices positions */
133 Vector<float3> no; /* surface vertex normals */
134
135 /* memory allocation from common pool */
137};
138
139/* Forward declarations */
140static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2);
141static void add_cube(PROCESS *process, int i, int j, int k);
142static void make_face(PROCESS *process, int i1, int i2, int i3, int i4);
143static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float r_p[3]);
144
145/* ******************* SIMPLE BVH ********************* */
146
147static void make_box_union(const BoundBox *a, const Box *b, Box *r_out)
148{
149 r_out->min[0] = min_ff(a->vec[0][0], b->min[0]);
150 r_out->min[1] = min_ff(a->vec[0][1], b->min[1]);
151 r_out->min[2] = min_ff(a->vec[0][2], b->min[2]);
152
153 r_out->max[0] = max_ff(a->vec[6][0], b->max[0]);
154 r_out->max[1] = max_ff(a->vec[6][1], b->max[1]);
155 r_out->max[2] = max_ff(a->vec[6][2], b->max[2]);
156}
157
158static void make_box_from_metaelem(Box *r, const MetaElem *ml)
159{
160 copy_v3_v3(r->max, ml->bb->vec[6]);
161 copy_v3_v3(r->min, ml->bb->vec[0]);
162 r->ml = ml;
163}
164
170static uint partition_mainb(MetaElem **mainb, uint start, uint end, uint s, float div)
171{
172 uint i = start, j = end - 1;
173 div *= 2.0f;
174
175 while (true) {
176 while (i < j && div > (mainb[i]->bb->vec[6][s] + mainb[i]->bb->vec[0][s])) {
177 i++;
178 }
179 while (j > i && div < (mainb[j]->bb->vec[6][s] + mainb[j]->bb->vec[0][s])) {
180 j--;
181 }
182
183 if (i >= j) {
184 break;
185 }
186
187 std::swap(mainb[i], mainb[j]);
188 i++;
189 j--;
190 }
191
192 if (i == start) {
193 i++;
194 }
195
196 return i;
197}
198
203 PROCESS *process, MetaballBVHNode *node, uint start, uint end, const Box *allbox)
204{
205 uint part, j, s;
206 float dim[3], div;
207
208 /* Maximum bvh queue size is number of nodes which are made, equals calls to this function. */
209 process->bvh_queue_size++;
210
211 dim[0] = allbox->max[0] - allbox->min[0];
212 dim[1] = allbox->max[1] - allbox->min[1];
213 dim[2] = allbox->max[2] - allbox->min[2];
214
215 s = 0;
216 if (dim[1] > dim[0] && dim[1] > dim[2]) {
217 s = 1;
218 }
219 else if (dim[2] > dim[1] && dim[2] > dim[0]) {
220 s = 2;
221 }
222
223 div = allbox->min[s] + (dim[s] / 2.0f);
224
225 part = partition_mainb(process->mainb, start, end, s, div);
226
227 make_box_from_metaelem(&node->bb[0], process->mainb[start]);
228 node->child[0] = nullptr;
229
230 if (part > start + 1) {
231 for (j = start; j < part; j++) {
232 make_box_union(process->mainb[j]->bb, &node->bb[0], &node->bb[0]);
233 }
234
235 node->child[0] = static_cast<MetaballBVHNode *>(
236 BLI_memarena_alloc(process->pgn_elements, sizeof(MetaballBVHNode)));
237 build_bvh_spatial(process, node->child[0], start, part, &node->bb[0]);
238 }
239
240 node->child[1] = nullptr;
241 if (part < end) {
242 make_box_from_metaelem(&node->bb[1], process->mainb[part]);
243
244 if (part < end - 1) {
245 for (j = part; j < end; j++) {
246 make_box_union(process->mainb[j]->bb, &node->bb[1], &node->bb[1]);
247 }
248
249 node->child[1] = static_cast<MetaballBVHNode *>(
250 BLI_memarena_alloc(process->pgn_elements, sizeof(MetaballBVHNode)));
251 build_bvh_spatial(process, node->child[1], part, end, &node->bb[1]);
252 }
253 }
254 else {
255 INIT_MINMAX(node->bb[1].min, node->bb[1].max);
256 }
257}
258
259/* ******************** ARITH ************************* */
260
273
274#define L 0 /* Left direction: -x, -i. */
275#define R 1 /* Right direction: +x, +i. */
276#define B 2 /* Bottom direction: -y, -j. */
277#define T 3 /* Top direction: +y, +j. */
278#define N 4 /* Near direction: -z, -k. */
279#define F 5 /* Far direction: +z, +k. */
280#define LBN 0 /* Left bottom near corner. */
281#define LBF 1 /* Left bottom far corner. */
282#define LTN 2 /* Left top near corner. */
283#define LTF 3 /* Left top far corner. */
284#define RBN 4 /* Right bottom near corner. */
285#define RBF 5 /* Right bottom far corner. */
286#define RTN 6 /* Right top near corner. */
287#define RTF 7 /* Right top far corner. */
288
293
294#define HASHBIT (5)
296#define HASHSIZE size_t(1 << (3 * HASHBIT))
297
298#define HASH(i, j, k) ((((((i) & 31) << 5) | ((j) & 31)) << 5) | ((k) & 31))
299
300#define MB_BIT(i, bit) (((i) >> (bit)) & 1)
301// #define FLIP(i, bit) ((i) ^ 1 << (bit)) /* flip the given bit of i */
302
303/* ******************** DENSITY COPMPUTATION ********************* */
304
313static float densfunc(const MetaElem *ball, float x, float y, float z)
314{
315 float dist2;
316 float dvec[3] = {x, y, z};
317
318 mul_m4_v3(reinterpret_cast<const float (*)[4]>(ball->imat), dvec);
319
320 switch (ball->type) {
321 case MB_BALL:
322 /* do nothing */
323 break;
324 case MB_CUBE:
325 if (dvec[2] > ball->expz) {
326 dvec[2] -= ball->expz;
327 }
328 else if (dvec[2] < -ball->expz) {
329 dvec[2] += ball->expz;
330 }
331 else {
332 dvec[2] = 0.0;
333 }
335 case MB_PLANE:
336 if (dvec[1] > ball->expy) {
337 dvec[1] -= ball->expy;
338 }
339 else if (dvec[1] < -ball->expy) {
340 dvec[1] += ball->expy;
341 }
342 else {
343 dvec[1] = 0.0;
344 }
346 case MB_TUBE:
347 if (dvec[0] > ball->expx) {
348 dvec[0] -= ball->expx;
349 }
350 else if (dvec[0] < -ball->expx) {
351 dvec[0] += ball->expx;
352 }
353 else {
354 dvec[0] = 0.0;
355 }
356 break;
357 case MB_ELLIPSOID:
358 dvec[0] /= ball->expx;
359 dvec[1] /= ball->expy;
360 dvec[2] /= ball->expz;
361 break;
362
363 /* *** deprecated, could be removed?, do-versioned at least *** */
364 case MB_TUBEX:
365 if (dvec[0] > ball->len) {
366 dvec[0] -= ball->len;
367 }
368 else if (dvec[0] < -ball->len) {
369 dvec[0] += ball->len;
370 }
371 else {
372 dvec[0] = 0.0;
373 }
374 break;
375 case MB_TUBEY:
376 if (dvec[1] > ball->len) {
377 dvec[1] -= ball->len;
378 }
379 else if (dvec[1] < -ball->len) {
380 dvec[1] += ball->len;
381 }
382 else {
383 dvec[1] = 0.0;
384 }
385 break;
386 case MB_TUBEZ:
387 if (dvec[2] > ball->len) {
388 dvec[2] -= ball->len;
389 }
390 else if (dvec[2] < -ball->len) {
391 dvec[2] += ball->len;
392 }
393 else {
394 dvec[2] = 0.0;
395 }
396 break;
397 /* *** end deprecated *** */
398 }
399
400 /* ball->rad2 is inverse of squared rad */
401 dist2 = 1.0f - (len_squared_v3(dvec) * ball->rad2);
402
403 /* ball->s is negative if metaball is negative */
404 return (dist2 < 0.0f) ? 0.0f : (ball->s * dist2 * dist2 * dist2);
405}
406
411static float metaball(PROCESS *process, float x, float y, float z)
412{
413 float dens = 0.0f;
414 uint front = 0, back = 0;
416
417 process->bvh_queue[front++] = &process->metaball_bvh;
418
419 while (front != back) {
420 node = process->bvh_queue[back++];
421
422 for (int i = 0; i < 2; i++) {
423 if ((node->bb[i].min[0] <= x) && (node->bb[i].max[0] >= x) && (node->bb[i].min[1] <= y) &&
424 (node->bb[i].max[1] >= y) && (node->bb[i].min[2] <= z) && (node->bb[i].max[2] >= z))
425 {
426 if (node->child[i]) {
427 process->bvh_queue[front++] = node->child[i];
428 }
429 else {
430 dens += densfunc(node->bb[i].ml, x, y, z);
431 }
432 }
433 }
434 }
435
436 return process->thresh - dens;
437}
438
442static void make_face(PROCESS *process, int i1, int i2, int i3, int i4)
443{
444#ifdef USE_ACCUM_NORMAL
445 float n[3];
446#endif
447
448 if (process->totindex == process->curindex) [[unlikely]] {
449 process->totindex = process->totindex ? (process->totindex * 2) : MBALL_ARRAY_LEN_INIT;
450 process->indices = static_cast<int (*)[4]>(
451 MEM_realloc_uninitialized(process->indices, sizeof(int[4]) * process->totindex));
452 }
453
454 int *cur = process->indices[process->curindex++];
455
456 /* Treat triangles as fake quads. */
457 cur[0] = i1;
458 cur[1] = i2;
459 cur[2] = i3;
460 cur[3] = i4;
461
462#ifdef USE_ACCUM_NORMAL
463 if (i4 == i3) {
464 normal_tri_v3(n, process->co[i1], process->co[i2], process->co[i3]);
466 process->no[i2],
467 process->no[i3],
468 nullptr,
469 n,
470 process->co[i1],
471 process->co[i2],
472 process->co[i3],
473 nullptr);
474 }
475 else {
476 normal_quad_v3(n, process->co[i1], process->co[i2], process->co[i3], process->co[i4]);
478 process->no[i2],
479 process->no[i3],
480 process->no[i4],
481 n,
482 process->co[i1],
483 process->co[i2],
484 process->co[i3],
485 process->co[i4]);
486 }
487#endif
488}
489
490/* Frees allocated memory */
492{
493 if (process->corners) {
494 MEM_delete(process->corners);
495 }
496 if (process->edges) {
497 MEM_delete(process->edges);
498 }
499 if (process->centers) {
500 MEM_delete(process->centers);
501 }
502 if (process->mainb) {
503 MEM_delete(process->mainb);
504 }
505 if (process->bvh_queue) {
506 MEM_delete(process->bvh_queue);
507 }
508 if (process->pgn_elements) {
509 BLI_memarena_free(process->pgn_elements);
510 }
511}
512
513/* **************** POLYGONIZATION ************************ */
514
515/**** Cubical Polygonization (optional) ****/
516
517#define LB 0 /* left bottom edge */
518#define LT 1 /* left top edge */
519#define LN 2 /* left near edge */
520#define LF 3 /* left far edge */
521#define RB 4 /* right bottom edge */
522#define RT 5 /* right top edge */
523#define RN 6 /* right near edge */
524#define RF 7 /* right far edge */
525#define BN 8 /* bottom near edge */
526#define BF 9 /* bottom far edge */
527#define TN 10 /* top near edge */
528#define TF 11 /* top far edge */
529
530static INTLISTS *cubetable[256];
531static char faces[256];
532
533/* edge: LB, LT, LN, LF, RB, RT, RN, RF, BN, BF, TN, TF */
534static int corner1[12] = {
535 LBN,
536 LTN,
537 LBN,
538 LBF,
539 RBN,
540 RTN,
541 RBN,
542 RBF,
543 LBN,
544 LBF,
545 LTN,
546 LTF,
547};
548static int corner2[12] = {
549 LBF,
550 LTF,
551 LTN,
552 LTF,
553 RBF,
554 RTF,
555 RTN,
556 RTF,
557 RBN,
558 RBF,
559 RTN,
560 RTF,
561};
562static int leftface[12] = {
563 B,
564 L,
565 L,
566 F,
567 R,
568 T,
569 N,
570 R,
571 N,
572 B,
573 T,
574 F,
575};
576/* face on left when going corner1 to corner2 */
577static int rightface[12] = {
578 L,
579 T,
580 N,
581 L,
582 B,
583 R,
584 R,
585 F,
586 B,
587 F,
588 N,
589 T,
590};
591/* face on right when going corner1 to corner2 */
592
596static void docube(PROCESS *process, CUBE *cube)
597{
598 INTLISTS *polys;
599 CORNER *c1, *c2;
600 int i, index = 0, count, indexar[8];
601
602 /* Determine which case cube falls into. */
603 for (i = 0; i < 8; i++) {
604 if (cube->corners[i]->value > 0.0f) {
605 index += (1 << i);
606 }
607 }
608
609 /* Using faces[] table, adds neighboring cube if surface intersects face in this direction. */
610 if (MB_BIT(faces[index], 0)) {
611 add_cube(process, cube->i - 1, cube->j, cube->k);
612 }
613 if (MB_BIT(faces[index], 1)) {
614 add_cube(process, cube->i + 1, cube->j, cube->k);
615 }
616 if (MB_BIT(faces[index], 2)) {
617 add_cube(process, cube->i, cube->j - 1, cube->k);
618 }
619 if (MB_BIT(faces[index], 3)) {
620 add_cube(process, cube->i, cube->j + 1, cube->k);
621 }
622 if (MB_BIT(faces[index], 4)) {
623 add_cube(process, cube->i, cube->j, cube->k - 1);
624 }
625 if (MB_BIT(faces[index], 5)) {
626 add_cube(process, cube->i, cube->j, cube->k + 1);
627 }
628
629 /* Using cubetable[], determines polygons for output. */
630 for (polys = cubetable[index]; polys; polys = polys->next) {
631 INTLIST *edges;
632
633 count = 0;
634 /* Sets needed vertex id's lying on the edges. */
635 for (edges = polys->list; edges; edges = edges->next) {
636 c1 = cube->corners[corner1[edges->i]];
637 c2 = cube->corners[corner2[edges->i]];
638
639 indexar[count] = vertid(process, c1, c2);
640 count++;
641 }
642
643 /* Adds faces to output. */
644 if (count > 2) {
645 switch (count) {
646 case 3:
647 make_face(process, indexar[2], indexar[1], indexar[0], indexar[0]); /* triangle */
648 break;
649 case 4:
650 make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
651 break;
652 case 5:
653 make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
654 make_face(process, indexar[4], indexar[3], indexar[0], indexar[0]); /* triangle */
655 break;
656 case 6:
657 make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
658 make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]);
659 break;
660 case 7:
661 make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
662 make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]);
663 make_face(process, indexar[6], indexar[5], indexar[0], indexar[0]); /* triangle */
664 break;
665 }
666 }
667 }
668}
669
674static CORNER *setcorner(PROCESS *process, int i, int j, int k)
675{
676 /* for speed, do corner value caching here */
677 CORNER *c;
678 int index;
679
680 /* does corner exist? */
681 index = HASH(i, j, k);
682 c = process->corners[index];
683
684 for (; c != nullptr; c = c->next) {
685 if (c->i == i && c->j == j && c->k == k) {
686 return c;
687 }
688 }
689
690 c = static_cast<CORNER *>(BLI_memarena_alloc(process->pgn_elements, sizeof(CORNER)));
691
692 c->i = i;
693 c->co[0] = (float(i) - 0.5f) * process->size;
694 c->j = j;
695 c->co[1] = (float(j) - 0.5f) * process->size;
696 c->k = k;
697 c->co[2] = (float(k) - 0.5f) * process->size;
698
699 c->value = metaball(process, c->co[0], c->co[1], c->co[2]);
700
701 c->next = process->corners[index];
702 process->corners[index] = c;
703
704 return c;
705}
706
710static int nextcwedge(int edge, int face)
711{
712 switch (edge) {
713 case LB:
714 return (face == L) ? LF : BN;
715 case LT:
716 return (face == L) ? LN : TF;
717 case LN:
718 return (face == L) ? LB : TN;
719 case LF:
720 return (face == L) ? LT : BF;
721 case RB:
722 return (face == R) ? RN : BF;
723 case RT:
724 return (face == R) ? RF : TN;
725 case RN:
726 return (face == R) ? RT : BN;
727 case RF:
728 return (face == R) ? RB : TF;
729 case BN:
730 return (face == B) ? RB : LN;
731 case BF:
732 return (face == B) ? LB : RF;
733 case TN:
734 return (face == T) ? LT : RN;
735 case TF:
736 return (face == T) ? RT : LF;
737 }
738 return 0;
739}
740
744static int otherface(int edge, int face)
745{
746 int other = leftface[edge];
747 return face == other ? rightface[edge] : other;
748}
749
753static void makecubetable()
754{
755 static bool is_done = false;
756 int i, e, c, done[12], pos[8];
757
758 if (is_done) {
759 return;
760 }
761 is_done = true;
762
763 for (i = 0; i < 256; i++) {
764 for (e = 0; e < 12; e++) {
765 done[e] = 0;
766 }
767 for (c = 0; c < 8; c++) {
768 pos[c] = MB_BIT(i, c);
769 }
770 for (e = 0; e < 12; e++) {
771 if (!done[e] && (pos[corner1[e]] != pos[corner2[e]])) {
772 INTLIST *ints = nullptr;
773 INTLISTS *lists = MEM_new_zeroed<INTLISTS>("mball_intlist");
774 int start = e, edge = e;
775
776 /* get face that is to right of edge from pos to neg corner: */
777 int face = pos[corner1[e]] ? rightface[e] : leftface[e];
778
779 while (true) {
780 edge = nextcwedge(edge, face);
781 done[edge] = 1;
782 if (pos[corner1[edge]] != pos[corner2[edge]]) {
783 INTLIST *tmp = ints;
784
785 ints = MEM_new_zeroed<INTLIST>("mball_intlist");
786 ints->i = edge;
787 ints->next = tmp; /* add edge to head of list */
788
789 if (edge == start) {
790 break;
791 }
792 face = otherface(edge, face);
793 }
794 }
795 lists->list = ints; /* add ints to head of table entry */
796 lists->next = cubetable[i];
797 cubetable[i] = lists;
798 }
799 }
800 }
801
802 for (i = 0; i < 256; i++) {
803 INTLISTS *polys;
804 faces[i] = 0;
805 for (polys = cubetable[i]; polys; polys = polys->next) {
806 INTLIST *edges;
807
808 for (edges = polys->list; edges; edges = edges->next) {
809 if (ELEM(edges->i, LB, LT, LN, LF)) {
810 faces[i] |= 1 << L;
811 }
812 if (ELEM(edges->i, RB, RT, RN, RF)) {
813 faces[i] |= 1 << R;
814 }
815 if (ELEM(edges->i, LB, RB, BN, BF)) {
816 faces[i] |= 1 << B;
817 }
818 if (ELEM(edges->i, LT, RT, TN, TF)) {
819 faces[i] |= 1 << T;
820 }
821 if (ELEM(edges->i, LN, RN, BN, TN)) {
822 faces[i] |= 1 << N;
823 }
824 if (ELEM(edges->i, LF, RF, BF, TF)) {
825 faces[i] |= 1 << F;
826 }
827 }
828 }
829 }
830}
831
833{
834 for (int i = 0; i < 256; i++) {
835 INTLISTS *lists = cubetable[i];
836 while (lists) {
837 INTLISTS *nlists = lists->next;
838
839 INTLIST *ints = lists->list;
840 while (ints) {
841 INTLIST *nints = ints->next;
842 MEM_delete(ints);
843 ints = nints;
844 }
845
846 MEM_delete(lists);
847 lists = nlists;
848 }
849 cubetable[i] = nullptr;
850 }
851}
852
853/**** Storage ****/
854
858static int setcenter(PROCESS *process, CENTERLIST *table[], const int i, const int j, const int k)
859{
860 int index;
861 CENTERLIST *newc, *l, *q;
862
863 index = HASH(i, j, k);
864 q = table[index];
865
866 for (l = q; l != nullptr; l = l->next) {
867 if (l->i == i && l->j == j && l->k == k) {
868 return 1;
869 }
870 }
871
872 newc = static_cast<CENTERLIST *>(BLI_memarena_alloc(process->pgn_elements, sizeof(CENTERLIST)));
873 newc->i = i;
874 newc->j = j;
875 newc->k = k;
876 newc->next = q;
877 table[index] = newc;
878
879 return 0;
880}
881
885static void setedge(PROCESS *process, int i1, int j1, int k1, int i2, int j2, int k2, int vid)
886{
887 int index;
888 EDGELIST *newe;
889
890 if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) {
891 int t = i1;
892 i1 = i2;
893 i2 = t;
894 t = j1;
895 j1 = j2;
896 j2 = t;
897 t = k1;
898 k1 = k2;
899 k2 = t;
900 }
901 index = HASH(i1, j1, k1) + HASH(i2, j2, k2);
902 newe = static_cast<EDGELIST *>(BLI_memarena_alloc(process->pgn_elements, sizeof(EDGELIST)));
903
904 newe->i1 = i1;
905 newe->j1 = j1;
906 newe->k1 = k1;
907 newe->i2 = i2;
908 newe->j2 = j2;
909 newe->k2 = k2;
910 newe->vid = vid;
911 newe->next = process->edges[index];
912 process->edges[index] = newe;
913}
914
918static int getedge(EDGELIST *table[], int i1, int j1, int k1, int i2, int j2, int k2)
919{
920 EDGELIST *q;
921
922 if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) {
923 int t = i1;
924 i1 = i2;
925 i2 = t;
926 t = j1;
927 j1 = j2;
928 j2 = t;
929 t = k1;
930 k1 = k2;
931 k2 = t;
932 }
933 q = table[HASH(i1, j1, k1) + HASH(i2, j2, k2)];
934 for (; q != nullptr; q = q->next) {
935 if (q->i1 == i1 && q->j1 == j1 && q->k1 == k1 && q->i2 == i2 && q->j2 == j2 && q->k2 == k2) {
936 return q->vid;
937 }
938 }
939 return -1;
940}
941
945static void addtovertices(PROCESS *process, const float v[3], const float no[3])
946{
947 process->co.append(v);
948 process->no.append(no);
949}
950
951#ifndef USE_ACCUM_NORMAL
957static void vnormal(PROCESS *process, const float point[3], float r_no[3])
958{
959 const float delta = process->delta;
960 const float f = metaball(process, point[0], point[1], point[2]);
961
962 r_no[0] = metaball(process, point[0] + delta, point[1], point[2]) - f;
963 r_no[1] = metaball(process, point[0], point[1] + delta, point[2]) - f;
964 r_no[2] = metaball(process, point[0], point[1], point[2] + delta) - f;
965}
966#endif /* !USE_ACCUM_NORMAL */
967
973static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2)
974{
975 float v[3], no[3];
976 int vid = getedge(process->edges, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k);
977
978 if (vid != -1) {
979 return vid; /* previously computed */
980 }
981
982 converge(process, c1, c2, v); /* position */
983
984#ifdef USE_ACCUM_NORMAL
985 zero_v3(no);
986#else
987 vnormal(process, v, no);
988#endif
989
990 addtovertices(process, v, no); /* save vertex */
991 vid = int(process->co.size()) - 1;
992 setedge(process, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k, vid);
993
994 return vid;
995}
996
1001static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float r_p[3])
1002{
1003 float c1_value, c1_co[3];
1004 float c2_value, c2_co[3];
1005
1006 if (c1->value < c2->value) {
1007 c1_value = c2->value;
1008 copy_v3_v3(c1_co, c2->co);
1009 c2_value = c1->value;
1010 copy_v3_v3(c2_co, c1->co);
1011 }
1012 else {
1013 c1_value = c1->value;
1014 copy_v3_v3(c1_co, c1->co);
1015 c2_value = c2->value;
1016 copy_v3_v3(c2_co, c2->co);
1017 }
1018
1019 for (uint i = 0; i < process->converge_res; i++) {
1020 interp_v3_v3v3(r_p, c1_co, c2_co, 0.5f);
1021 float dens = metaball(process, r_p[0], r_p[1], r_p[2]);
1022
1023 if (dens > 0.0f) {
1024 c1_value = dens;
1025 copy_v3_v3(c1_co, r_p);
1026 }
1027 else {
1028 c2_value = dens;
1029 copy_v3_v3(c2_co, r_p);
1030 }
1031 }
1032
1033 float tmp = -c1_value / (c2_value - c1_value);
1034 interp_v3_v3v3(r_p, c1_co, c2_co, tmp);
1035}
1036
1040static void add_cube(PROCESS *process, int i, int j, int k)
1041{
1042 CUBES *ncube;
1043 int n;
1044
1045 /* test if cube has been found before */
1046 if (setcenter(process, process->centers, i, j, k) == 0) {
1047 /* push cube on stack: */
1048 ncube = static_cast<CUBES *>(BLI_memarena_alloc(process->pgn_elements, sizeof(CUBES)));
1049 ncube->next = process->cubes;
1050 process->cubes = ncube;
1051
1052 ncube->cube.i = i;
1053 ncube->cube.j = j;
1054 ncube->cube.k = k;
1055
1056 /* set corners of initial cube: */
1057 for (n = 0; n < 8; n++) {
1058 ncube->cube.corners[n] = setcorner(
1059 process, i + MB_BIT(n, 2), j + MB_BIT(n, 1), k + MB_BIT(n, 0));
1060 }
1061 }
1062}
1063
1064static void next_lattice(int r[3], const float pos[3], const float size)
1065{
1066 r[0] = int(ceil((pos[0] / size) + 0.5f));
1067 r[1] = int(ceil((pos[1] / size) + 0.5f));
1068 r[2] = int(ceil((pos[2] / size) + 0.5f));
1069}
1070static void prev_lattice(int r[3], const float pos[3], const float size)
1071{
1072 next_lattice(r, pos, size);
1073 r[0]--;
1074 r[1]--;
1075 r[2]--;
1076}
1077static void closest_latice(int r[3], const float pos[3], const float size)
1078{
1079 r[0] = int(floorf(pos[0] / size + 1.0f));
1080 r[1] = int(floorf(pos[1] / size + 1.0f));
1081 r[2] = int(floorf(pos[2] / size + 1.0f));
1082}
1083
1087static void find_first_points(PROCESS *process, const uint em)
1088{
1089 const MetaElem *ml;
1090 int3 center, lbn, rtf, it, dir, add;
1091 float tmp[3], a, b;
1092
1093 ml = process->mainb[em];
1094
1095 mid_v3_v3v3(tmp, ml->bb->vec[0], ml->bb->vec[6]);
1096 closest_latice(center, tmp, process->size);
1097 prev_lattice(lbn, ml->bb->vec[0], process->size);
1098 next_lattice(rtf, ml->bb->vec[6], process->size);
1099
1100 for (dir[0] = -1; dir[0] <= 1; dir[0]++) {
1101 for (dir[1] = -1; dir[1] <= 1; dir[1]++) {
1102 for (dir[2] = -1; dir[2] <= 1; dir[2]++) {
1103 if (dir[0] == 0 && dir[1] == 0 && dir[2] == 0) {
1104 continue;
1105 }
1106
1107 copy_v3_v3_int(it, center);
1108
1109 b = setcorner(process, it[0], it[1], it[2])->value;
1110 do {
1111 it[0] += dir[0];
1112 it[1] += dir[1];
1113 it[2] += dir[2];
1114 a = b;
1115 b = setcorner(process, it[0], it[1], it[2])->value;
1116
1117 if (a * b < 0.0f) {
1118 add[0] = it[0] - dir[0];
1119 add[1] = it[1] - dir[1];
1120 add[2] = it[2] - dir[2];
1121 add = math::min(add, it);
1122 add_cube(process, add[0], add[1], add[2]);
1123 break;
1124 }
1125 } while ((it[0] > lbn[0]) && (it[1] > lbn[1]) && (it[2] > lbn[2]) && (it[0] < rtf[0]) &&
1126 (it[1] < rtf[1]) && (it[2] < rtf[2]));
1127 }
1128 }
1129 }
1130}
1131
1139{
1140 CUBE c;
1141
1142 process->centers = MEM_new_array_zeroed<CENTERLIST *>(HASHSIZE, "mbproc->centers");
1143 process->corners = MEM_new_array_zeroed<CORNER *>(HASHSIZE, "mbproc->corners");
1144 process->edges = MEM_new_array_zeroed<EDGELIST *>(2 * HASHSIZE, "mbproc->edges");
1145 process->bvh_queue = MEM_new_array_zeroed<MetaballBVHNode *>(process->bvh_queue_size,
1146 "Metaball BVH Queue");
1147
1148 makecubetable();
1149
1150 for (uint i = 0; i < process->totelem; i++) {
1152 }
1153
1154 while (process->cubes != nullptr) {
1155 c = process->cubes->cube;
1156 process->cubes = process->cubes->next;
1157
1158 docube(process, &c);
1159 }
1160}
1161
1163{
1164 if (has_zero_axis_m4(bob->object_to_world().ptr())) {
1165 return true;
1166 }
1167 for (Object *pob = bob->parent; pob; pob = pob->parent) {
1168 if (has_zero_axis_m4(pob->object_to_world().ptr())) {
1169 return true;
1170 }
1171 }
1172 return false;
1173}
1174
1180static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Object *ob)
1181{
1182 Scene *sce_iter = scene;
1183 Base *base;
1184 Object *bob;
1185 int obnr;
1186 char obname[MAX_ID_NAME];
1187 SceneBaseIter iter;
1188 const eEvaluationMode deg_eval_mode = DEG_get_mode(depsgraph);
1189 const short parenting_dupli_transflag = (OB_DUPLIFACES | OB_DUPLIVERTS);
1190
1191 /* Copy object matrices to cope with duplicators from #BKE_scene_base_iter_next. */
1192 float obinv[4][4], obmat[4][4];
1193 copy_m4_m4(obmat, ob->object_to_world().ptr());
1194 invert_m4_m4(obinv, ob->object_to_world().ptr());
1195
1196 BLI_string_split_name_number(ob->id.name + 2, '.', obname, &obnr);
1197
1198 /* make main array */
1199 BKE_scene_base_iter_next(depsgraph, &iter, &sce_iter, 0, nullptr, nullptr);
1200 while (BKE_scene_base_iter_next(depsgraph, &iter, &sce_iter, 1, &base, &bob)) {
1201 if (bob->type != OB_MBALL) {
1202 continue;
1203 }
1204
1205 /* If this metaball is the original that's used for duplication, only have it visible when
1206 * the instancer is visible too. */
1207 if ((base->flag_legacy & OB_FROMDUPLI) == 0 && ob->parent != nullptr &&
1208 (ob->parent->transflag & parenting_dupli_transflag) != 0 &&
1209 (BKE_object_visibility(ob->parent, deg_eval_mode) & OB_VISIBLE_SELF) == 0)
1210 {
1211 continue;
1212 }
1213
1214 if (bob == ob && (base->flag_legacy & OB_FROMDUPLI) == 0) {
1215 /* Pass. */
1216 }
1217 else {
1218 char name[MAX_ID_NAME];
1219 int nr;
1220 BLI_string_split_name_number(bob->id.name + 2, '.', name, &nr);
1221 if (!STREQ(obname, name)) {
1222 /* Not part of the mother-ball, continue. */
1223 continue;
1224 }
1225 }
1226
1227 /* When metaball object has zero scale, then MetaElem to this MetaBall
1228 * will not be put to `mainb` array. */
1229 if (object_has_zero_axis_matrix(bob)) {
1230 continue;
1231 }
1232
1233 const MetaBall *mb = id_cast<MetaBall *>(bob->data);
1234 for (const MetaElem &ml : mb->editelems ? *mb->editelems : mb->elems) {
1235 if (ml.flag & MB_HIDE) {
1236 continue;
1237 }
1238 float pos[4][4], rot[4][4];
1239 float expx, expy, expz;
1240 float3 tempmin, tempmax;
1241
1242 /* make a copy because of duplicates */
1243 MetaElem *new_ml = static_cast<MetaElem *>(
1244 BLI_memarena_alloc(process->pgn_elements, sizeof(MetaElem)));
1245 *(new_ml) = ml;
1246 new_ml->bb = static_cast<BoundBox *>(
1247 BLI_memarena_alloc(process->pgn_elements, sizeof(BoundBox)));
1248 new_ml->mat = static_cast<float *>(
1249 BLI_memarena_alloc(process->pgn_elements, sizeof(float[4][4])));
1250 new_ml->imat = static_cast<float *>(
1251 BLI_memarena_alloc(process->pgn_elements, sizeof(float[4][4])));
1252
1253 /* too big stiffness seems only ugly due to linear interpolation
1254 * no need to have possibility for too big stiffness */
1255 if (ml.s > 10.0f) {
1256 new_ml->s = 10.0f;
1257 }
1258 else {
1259 new_ml->s = ml.s;
1260 }
1261
1262 /* if metaball is negative, set stiffness negative */
1263 if (new_ml->flag & MB_NEGATIVE) {
1264 new_ml->s = -new_ml->s;
1265 }
1266
1267 /* Translation of MetaElem */
1268 unit_m4(pos);
1269 pos[3][0] = ml.x;
1270 pos[3][1] = ml.y;
1271 pos[3][2] = ml.z;
1272
1273 /* Rotation of MetaElem is stored in quat */
1274 quat_to_mat4(rot, ml.quat);
1275
1276 /* Matrix multiply is as follows:
1277 * basis object space ->
1278 * world ->
1279 * ml object space ->
1280 * position ->
1281 * rotation ->
1282 * ml local space
1283 */
1284 mul_m4_series((float (*)[4])new_ml->mat, obinv, bob->object_to_world().ptr(), pos, rot);
1285 /* ml local space -> basis object space */
1286 invert_m4_m4(reinterpret_cast<float (*)[4]>(new_ml->imat),
1287 reinterpret_cast<float (*)[4]>(new_ml->mat));
1288
1289 /* rad2 is inverse of squared radius */
1290 new_ml->rad2 = 1 / (ml.rad * ml.rad);
1291
1292 /* initial dimensions = radius */
1293 expx = ml.rad;
1294 expy = ml.rad;
1295 expz = ml.rad;
1296
1297 switch (ml.type) {
1298 case MB_BALL:
1299 case MB_TUBEX:
1300 case MB_TUBEY:
1301 case MB_TUBEZ:
1302 break;
1303 case MB_CUBE: /* cube is "expanded" by expz, expy and expx */
1304 expz += ml.expz;
1306 case MB_PLANE: /* plane is "expanded" by expy and expx */
1307 expy += ml.expy;
1309 case MB_TUBE: /* tube is "expanded" by expx */
1310 expx += ml.expx;
1311 break;
1312 case MB_ELLIPSOID: /* ellipsoid is "stretched" by exp* */
1313 expx *= ml.expx;
1314 expy *= ml.expy;
1315 expz *= ml.expz;
1316 break;
1317 }
1318
1319 /* untransformed Bounding Box of MetaElem */
1320 /* TODO: its possible the elem type has been changed and the exp*
1321 * values can use a fallback. */
1322 copy_v3_fl3(new_ml->bb->vec[0], -expx, -expy, -expz); /* 0 */
1323 copy_v3_fl3(new_ml->bb->vec[1], +expx, -expy, -expz); /* 1 */
1324 copy_v3_fl3(new_ml->bb->vec[2], +expx, +expy, -expz); /* 2 */
1325 copy_v3_fl3(new_ml->bb->vec[3], -expx, +expy, -expz); /* 3 */
1326 copy_v3_fl3(new_ml->bb->vec[4], -expx, -expy, +expz); /* 4 */
1327 copy_v3_fl3(new_ml->bb->vec[5], +expx, -expy, +expz); /* 5 */
1328 copy_v3_fl3(new_ml->bb->vec[6], +expx, +expy, +expz); /* 6 */
1329 copy_v3_fl3(new_ml->bb->vec[7], -expx, +expy, +expz); /* 7 */
1330
1331 /* Transformation of meta-elem bounding-box. */
1332 for (uint i = 0; i < 8; i++) {
1333 mul_m4_v3(reinterpret_cast<float (*)[4]>(new_ml->mat), new_ml->bb->vec[i]);
1334 }
1335
1336 /* Find max and min of transformed bounding-box. */
1337 INIT_MINMAX(tempmin, tempmax);
1338 for (uint i = 0; i < 8; i++) {
1339 math::min_max(float3(new_ml->bb->vec[i]), tempmin, tempmax);
1340 }
1341
1342 /* Set only point 0 and 6 - AABB of meta-elem. */
1343 copy_v3_v3(new_ml->bb->vec[0], tempmin);
1344 copy_v3_v3(new_ml->bb->vec[6], tempmax);
1345
1346 /* add new_ml to mainb[] */
1347 if (process->totelem == process->mem) [[unlikely]] {
1348 process->mem = process->mem * 2 + 10;
1349 process->mainb = static_cast<MetaElem **>(
1350 MEM_realloc_uninitialized(process->mainb, sizeof(MetaElem *) * process->mem));
1351 }
1352 process->mainb[process->totelem++] = new_ml;
1353 }
1354 }
1355
1356 /* Compute AABB of all meta-elems. */
1357 if (process->totelem > 0) {
1358 copy_v3_v3(process->allbb.min, process->mainb[0]->bb->vec[0]);
1359 copy_v3_v3(process->allbb.max, process->mainb[0]->bb->vec[6]);
1360 for (uint i = 1; i < process->totelem; i++) {
1361 make_box_union(process->mainb[i]->bb, &process->allbb, &process->allbb);
1362 }
1363 }
1364}
1365
1366Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
1367{
1368 PROCESS process{};
1369 const bool is_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
1370
1371 MetaBall *mb = id_cast<MetaBall *>(ob->data);
1372
1373 process.thresh = mb->thresh;
1374
1375 if (process.thresh < 0.001f) {
1376 process.converge_res = 16;
1377 }
1378 else if (process.thresh < 0.01f) {
1379 process.converge_res = 8;
1380 }
1381 else if (process.thresh < 0.1f) {
1382 process.converge_res = 4;
1383 }
1384 else {
1385 process.converge_res = 2;
1386 }
1387
1388 if (!is_render && (mb->flag == MB_UPDATE_NEVER)) {
1389 return nullptr;
1390 }
1391 if ((G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT)) && mb->flag == MB_UPDATE_FAST) {
1392 return nullptr;
1393 }
1394
1395 if (is_render) {
1396 process.size = mb->rendersize;
1397 }
1398 else {
1399 process.size = mb->wiresize;
1400 if ((G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT)) && mb->flag == MB_UPDATE_HALFRES) {
1401 process.size *= 2.0f;
1402 }
1403 }
1404
1405 process.delta = process.size * 0.001f;
1406
1407 process.co.reserve(MBALL_ARRAY_LEN_INIT);
1408 process.no.reserve(MBALL_ARRAY_LEN_INIT);
1409 process.pgn_elements = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "Metaball memarena");
1410
1411 /* initialize all mainb (MetaElems) */
1412 init_meta(depsgraph, &process, scene, ob);
1413 if (process.totelem == 0) {
1415 return nullptr;
1416 }
1417
1418 build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, &process.allbb);
1419
1420 {
1421 /* Don't polygonize meta-balls with too high resolution (base meta-ball too small).
1422 * NOTE: Epsilon was 0.0001f but this was giving problems for blood animation for
1423 * the open movie "Sintel", using 0.00001f. */
1424 const float eps = 0.00001f;
1425 const float4x4 &object_to_world = ob->object_to_world();
1426 for (int i = 0; i < 3; i++) {
1427 if (math::length_squared(object_to_world[i].xyz()) <
1428 math::square(eps * (process.allbb.max[i] - process.allbb.min[i])))
1429 {
1431 return nullptr;
1432 }
1433 }
1434 }
1435
1437 if (process.curindex == 0) {
1439 return nullptr;
1440 }
1441
1443
1444 int corners_num = 0;
1445 for (uint i = 0; i < process.curindex; i++) {
1446 const int *indices = process.indices[i];
1447 const int count = indices[2] != indices[3] ? 4 : 3;
1448 corners_num += count;
1449 }
1450
1451 Mesh *mesh = BKE_mesh_new_nomain(int(process.co.size()), 0, int(process.curindex), corners_num);
1452 mesh->vert_positions_for_write().copy_from(process.co);
1453 MutableSpan<int> face_offsets = mesh->face_offsets_for_write();
1454 MutableSpan<int> corner_verts = mesh->corner_verts_for_write();
1455
1456 int loop_offset = 0;
1457 for (int i = 0; i < mesh->faces_num; i++) {
1458 const int *indices = process.indices[i];
1459
1460 const int count = indices[2] != indices[3] ? 4 : 3;
1461 face_offsets[i] = loop_offset;
1462
1463 corner_verts[loop_offset] = indices[0];
1464 corner_verts[loop_offset + 1] = indices[1];
1465 corner_verts[loop_offset + 2] = indices[2];
1466 if (count == 4) {
1467 corner_verts[loop_offset + 3] = indices[3];
1468 }
1469
1470 loop_offset += count;
1471 }
1472 MEM_delete(process.indices);
1473
1474 for (int i = 0; i < mesh->verts_num; i++) {
1475 normalize_v3(process.no[i]);
1476 }
1478
1479 bke::mesh_calc_edges(*mesh, false, false);
1480
1481 return mesh;
1482}
1483
1484} // namespace blender
General operations, lookup, etc. for blender objects.
#define ATTR_FALLTHROUGH
#define mul_m4_series(...)
#define BLI_MEMARENA_STD_BUFSIZE
#define MAX_ID_NAME
Definition DNA_ID.h:367
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define INIT_MINMAX(min, max)
#define ELEM(...)
#define STREQ(a, b)
#define MEM_realloc_uninitialized(vmemh, len)
void process(btMatrix3x3 &B, btMatrix3x3 &U, btVector3 &sigma, btMatrix3x3 &V)
Helper function of 3X3 SVD for processing 2X2 SVD.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
#define rot(x, k)
#define ceil
#define N
#define RTN
#define T
#define B
#define RB
#define TF
#define BN
#define MBALL_ARRAY_LEN_INIT
#define HASHSIZE
#define LF
#define RBN
#define F
#define RTF
#define LTN
#define R
#define LTF
#define RF
#define HASH(i, j, k)
#define LN
#define LBF
#define L
#define LBN
#define LT
#define RBF
#define MB_BIT(i, bit)
#define BF
#define LB
#define RN
#define RT
#define TN
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
void mesh_vert_normals_assign(Mesh &mesh, Span< float3 > vert_normals)
T length_squared(const VecBase< T, Size > &a)
T min(const T &a, const T &b)
void min_max(const T &value, T &min, T &max)
T square(const T &a)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
static void polygonize(PROCESS *process)
static CORNER * setcorner(PROCESS *process, int i, int j, int k)
static bool object_has_zero_axis_matrix(const Object *bob)
static float densfunc(const MetaElem *ball, float x, float y, float z)
static void docube(PROCESS *process, CUBE *cube)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static char faces[256]
ATTR_WARN_UNUSED_RESULT const BMLoop * l
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
static void add_cube(PROCESS *process, int i, int j, int k)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
static void build_bvh_spatial(PROCESS *process, MetaballBVHNode *node, uint start, uint end, const Box *allbox)
ATTR_WARN_UNUSED_RESULT const BMVert * v
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:45
MatBase< float, 4, 4 > float4x4
static int corner2[12]
bool has_zero_axis_m4(const float matrix[4][4])
static int corner1[12]
static INTLISTS * cubetable[256]
static uint partition_mainb(MetaElem **mainb, uint start, uint end, uint s, float div)
int BKE_scene_base_iter_next(Depsgraph *depsgraph, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob)
Definition scene.cc:2268
static void addtovertices(PROCESS *process, const float v[3], const float no[3])
static int rightface[12]
Global G
Definition blender.cc:57
Mesh * BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
static int setcenter(PROCESS *process, CENTERLIST *table[], const int i, const int j, const int k)
void mul_m4_v3(const float M[4][4], float r[3])
VecBase< int32_t, 3 > int3
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void next_lattice(int r[3], const float pos[3], const float size)
static int getedge(EDGELIST *table[], int i1, int j1, int k1, int i2, int j2, int k2)
void BKE_mball_cubeTable_free()
float normal_quad_v3(float n[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
Definition math_geom.cc:62
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
Definition object.cc:2063
static float metaball(PROCESS *process, float x, float y, float z)
static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
static void makecubetable()
static void find_first_points(PROCESS *process, const uint em)
static void closest_latice(int r[3], const float pos[3], const float size)
void unit_m4(float m[4][4])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
static void setedge(PROCESS *process, int i1, int j1, int k1, int i2, int j2, int k2, int vid)
static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Object *ob)
static void make_box_from_metaelem(Box *r, const MetaElem *ml)
MINLINE void zero_v3(float r[3])
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
static void make_box_union(const BoundBox *a, const Box *b, Box *r_out)
static void make_face(PROCESS *process, int i1, int i2, int i3, int i4)
static int otherface(int edge, int face)
static int leftface[12]
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float r_p[3])
MINLINE float normalize_v3(float n[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
static int nextcwedge(int edge, int face)
MINLINE float max_ff(float a, float b)
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
@ G_TRANSFORM_OBJ
@ G_TRANSFORM_EDIT
@ MB_UPDATE_HALFRES
void accumulate_vertex_normals_v3(float n1[3], float n2[3], float n3[3], float n4[3], const float f_no[3], const float co1[3], const float co2[3], const float co3[3], const float co4[3])
size_t BLI_string_split_name_number(const char *name, char delim, char *r_name_left, int *r_number) ATTR_NONNULL(1
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
@ OB_VISIBLE_SELF
static void prev_lattice(int r[3], const float pos[3], const float size)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void quat_to_mat4(float m[4][4], const float q[4])
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void freepolygonize(PROCESS *process)
const btScalar eps
Definition poly34.cpp:11
#define floorf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const MetaElem * ml
CORNER * corners[8]
char name[258]
Definition DNA_ID.h:433
ListBaseT< MetaElem > elems
ListBaseT< MetaElem > * editelems
eMetaBall_Flag flag
eMetaElem_Type type
struct BoundBox * bb
eMetaElem_Flag flag
MetaballBVHNode * child[2]
struct Object * parent
eObject_TransFlag transflag
MetaballBVHNode ** bvh_queue
CENTERLIST ** centers
Vector< float3 > no
Vector< float3 > co
MetaballBVHNode metaball_bvh