47#define USE_ACCUM_NORMAL
49#define MBALL_ARRAY_LEN_INIT 4096
172 uint i = start, j = end - 1;
176 while (i < j && div > (mainb[i]->bb->vec[6][s] + mainb[i]->
bb->
vec[0][s])) {
179 while (j > i && div < (mainb[j]->bb->vec[6][s] + mainb[j]->
bb->
vec[0][s])) {
187 std::swap(mainb[i], mainb[j]);
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];
216 if (dim[1] > dim[0] && dim[1] > dim[2]) {
219 else if (dim[2] > dim[1] && dim[2] > dim[0]) {
223 div = allbox->
min[s] + (dim[s] / 2.0f);
228 node->child[0] =
nullptr;
230 if (part > start + 1) {
231 for (j = start; j < part; j++) {
240 node->child[1] =
nullptr;
244 if (part < end - 1) {
245 for (j = part; j < end; j++) {
296#define HASHSIZE size_t(1 << (3 * HASHBIT))
298#define HASH(i, j, k) ((((((i) & 31) << 5) | ((j) & 31)) << 5) | ((k) & 31))
300#define MB_BIT(i, bit) (((i) >> (bit)) & 1)
316 float dvec[3] = {
x,
y,
z};
318 mul_m4_v3(
reinterpret_cast<const float (*)[4]
>(ball->
imat), dvec);
320 switch (ball->
type) {
325 if (dvec[2] > ball->
expz) {
326 dvec[2] -= ball->
expz;
328 else if (dvec[2] < -ball->
expz) {
329 dvec[2] += ball->
expz;
336 if (dvec[1] > ball->
expy) {
337 dvec[1] -= ball->
expy;
339 else if (dvec[1] < -ball->
expy) {
340 dvec[1] += ball->
expy;
347 if (dvec[0] > ball->
expx) {
348 dvec[0] -= ball->
expx;
350 else if (dvec[0] < -ball->
expx) {
351 dvec[0] += ball->
expx;
358 dvec[0] /= ball->
expx;
359 dvec[1] /= ball->
expy;
360 dvec[2] /= ball->
expz;
365 if (dvec[0] > ball->
len) {
366 dvec[0] -= ball->
len;
368 else if (dvec[0] < -ball->
len) {
369 dvec[0] += ball->
len;
376 if (dvec[1] > ball->
len) {
377 dvec[1] -= ball->
len;
379 else if (dvec[1] < -ball->
len) {
380 dvec[1] += ball->
len;
387 if (dvec[2] > ball->
len) {
388 dvec[2] -= ball->
len;
390 else if (dvec[2] < -ball->
len) {
391 dvec[2] += ball->
len;
404 return (dist2 < 0.0f) ? 0.0f : (ball->
s * dist2 * dist2 * dist2);
414 uint front = 0, back = 0;
419 while (front != back) {
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))
426 if (
node->child[i]) {
444#ifdef USE_ACCUM_NORMAL
450 process->indices =
static_cast<int (*)[4]
>(
462#ifdef USE_ACCUM_NORMAL
506 MEM_delete(
process->bvh_queue);
600 int i,
index = 0, count, indexar[8];
603 for (i = 0; i < 8; i++) {
604 if (cube->corners[i]->value > 0.0f) {
635 for (edges = polys->
list; edges; edges = edges->
next) {
636 c1 = cube->corners[
corner1[edges->
i]];
637 c2 = cube->corners[
corner2[edges->
i]];
684 for (; c !=
nullptr; c = c->
next) {
685 if (c->
i == i && c->
j == j && c->
k == k) {
714 return (face ==
L) ?
LF :
BN;
716 return (face ==
L) ?
LN :
TF;
718 return (face ==
L) ?
LB :
TN;
720 return (face ==
L) ?
LT :
BF;
722 return (face ==
R) ?
RN :
BF;
724 return (face ==
R) ?
RF :
TN;
726 return (face ==
R) ?
RT :
BN;
728 return (face ==
R) ?
RB :
TF;
730 return (face ==
B) ?
RB :
LN;
732 return (face ==
B) ?
LB :
RF;
734 return (face ==
T) ?
LT :
RN;
736 return (face ==
T) ?
RT :
LF;
747 return face == other ?
rightface[edge] : other;
755 static bool is_done =
false;
756 int i,
e, c, done[12], pos[8];
763 for (i = 0; i < 256; i++) {
764 for (
e = 0;
e < 12;
e++) {
767 for (c = 0; c < 8; c++) {
770 for (
e = 0;
e < 12;
e++) {
774 int start =
e, edge =
e;
802 for (i = 0; i < 256; i++) {
808 for (edges = polys->
list; edges; edges = edges->
next) {
834 for (
int i = 0; i < 256; i++) {
866 for (
l = q;
l !=
nullptr;
l =
l->
next) {
867 if (
l->i == i &&
l->j == j &&
l->k == k) {
890 if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) {
922 if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) {
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) {
951#ifndef USE_ACCUM_NORMAL
957static void vnormal(PROCESS *
process,
const float point[3],
float r_no[3])
959 const float delta =
process->delta;
960 const float f = metaball(
process, point[0], point[1], point[2]);
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;
984#ifdef USE_ACCUM_NORMAL
991 vid = int(
process->co.size()) - 1;
1003 float c1_value, c1_co[3];
1004 float c2_value, c2_co[3];
1007 c1_value = c2->
value;
1009 c2_value = c1->
value;
1013 c1_value = c1->
value;
1015 c2_value = c2->
value;
1019 for (
uint i = 0; i <
process->converge_res; i++) {
1033 float tmp = -c1_value / (c2_value - c1_value);
1057 for (n = 0; n < 8; n++) {
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));
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));
1090 int3 center, lbn, rtf, it, dir, add;
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) {
1118 add[0] = it[0] - dir[0];
1119 add[1] = it[1] - dir[1];
1120 add[2] = it[2] - dir[2];
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]));
1146 "Metaball BVH Queue");
1154 while (
process->cubes !=
nullptr) {
1182 Scene *sce_iter = scene;
1192 float obinv[4][4], obmat[4][4];
1193 copy_m4_m4(obmat, ob->object_to_world().ptr());
1221 if (!
STREQ(obname, name)) {
1238 float pos[4][4],
rot[4][4];
1239 float expx, expy, expz;
1248 new_ml->
mat =
static_cast<float *
>(
1250 new_ml->
imat =
static_cast<float *
>(
1264 new_ml->
s = -new_ml->
s;
1287 reinterpret_cast<float (*)[4]
>(new_ml->
mat));
1332 for (
uint i = 0; i < 8; i++) {
1338 for (
uint i = 0; i < 8; i++) {
1375 if (
process.thresh < 0.001f) {
1378 else if (
process.thresh < 0.01f) {
1381 else if (
process.thresh < 0.1f) {
1424 const float eps = 0.00001f;
1425 const float4x4 &object_to_world = ob->object_to_world();
1426 for (
int i = 0; i < 3; i++) {
1444 int corners_num = 0;
1446 const int *indices =
process.indices[i];
1447 const int count = indices[2] != indices[3] ? 4 : 3;
1448 corners_num += count;
1452 mesh->vert_positions_for_write().copy_from(
process.co);
1456 int loop_offset = 0;
1457 for (
int i = 0; i <
mesh->faces_num; i++) {
1458 const int *indices =
process.indices[i];
1460 const int count = indices[2] != indices[3] ? 4 : 3;
1461 face_offsets[i] = loop_offset;
1463 corner_verts[loop_offset] = indices[0];
1464 corner_verts[loop_offset + 1] = indices[1];
1465 corner_verts[loop_offset + 2] = indices[2];
1467 corner_verts[loop_offset + 3] = indices[3];
1470 loop_offset += count;
1474 for (
int i = 0; i <
mesh->verts_num; i++) {
General operations, lookup, etc. for blender objects.
#define mul_m4_series(...)
#define BLI_MEMARENA_STD_BUFSIZE
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define INIT_MINMAX(min, max)
#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.
#define MBALL_ARRAY_LEN_INIT
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)
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])
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])
MatBase< float, 4, 4 > float4x4
bool has_zero_axis_m4(const float matrix[4][4])
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)
static void addtovertices(PROCESS *process, const float v[3], const float no[3])
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])
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
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)
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
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
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)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eObject_TransFlag transflag
MetaballBVHNode ** bvh_queue
MetaballBVHNode metaball_bvh