44#define USE_ACCUM_NORMAL
46#define MBALL_ARRAY_LEN_INIT 4096
169 uint i = start, j = end - 1;
176 while (j >
i && div < (mainb[j]->bb->vec[6][s] + mainb[j]->
bb->
vec[0][s])) {
184 std::swap(mainb[
i], mainb[j]);
208 dim[0] = allbox->
max[0] - allbox->
min[0];
209 dim[1] = allbox->
max[1] - allbox->
min[1];
210 dim[2] = allbox->
max[2] - allbox->
min[2];
213 if (dim[1] > dim[0] && dim[1] > dim[2]) {
216 else if (dim[2] > dim[1] && dim[2] > dim[0]) {
220 div = allbox->
min[s] + (dim[s] / 2.0f);
225 node->
child[0] =
nullptr;
227 if (part > start + 1) {
228 for (j = start; j < part; j++) {
237 node->
child[1] =
nullptr;
241 if (part < end - 1) {
242 for (j = part; j < end; j++) {
293#define HASHSIZE size_t(1 << (3 * HASHBIT))
295#define HASH(i, j, k) ((((((i) & 31) << 5) | ((j) & 31)) << 5) | ((k) & 31))
297#define MB_BIT(i, bit) (((i) >> (bit)) & 1)
313 float dvec[3] = {
x,
y,
z};
317 switch (ball->
type) {
322 if (dvec[2] > ball->
expz) {
323 dvec[2] -= ball->
expz;
325 else if (dvec[2] < -ball->
expz) {
326 dvec[2] += ball->
expz;
333 if (dvec[1] > ball->
expy) {
334 dvec[1] -= ball->
expy;
336 else if (dvec[1] < -ball->
expy) {
337 dvec[1] += ball->
expy;
344 if (dvec[0] > ball->
expx) {
345 dvec[0] -= ball->
expx;
347 else if (dvec[0] < -ball->
expx) {
348 dvec[0] += ball->
expx;
355 dvec[0] /= ball->
expx;
356 dvec[1] /= ball->
expy;
357 dvec[2] /= ball->
expz;
362 if (dvec[0] > ball->
len) {
363 dvec[0] -= ball->
len;
365 else if (dvec[0] < -ball->
len) {
366 dvec[0] += ball->
len;
373 if (dvec[1] > ball->
len) {
374 dvec[1] -= ball->
len;
376 else if (dvec[1] < -ball->
len) {
377 dvec[1] += ball->
len;
384 if (dvec[2] > ball->
len) {
385 dvec[2] -= ball->
len;
387 else if (dvec[2] < -ball->
len) {
388 dvec[2] += ball->
len;
401 return (dist2 < 0.0f) ? 0.0f : (ball->
s * dist2 * dist2 * dist2);
411 uint front = 0, back = 0;
416 while (front != back) {
417 node =
process->bvh_queue[back++];
419 for (
int i = 0;
i < 2;
i++) {
441#ifdef USE_ACCUM_NORMAL
447 process->indices =
static_cast<int (*)[4]
>(
459#ifdef USE_ACCUM_NORMAL
597 int i, index = 0,
count, indexar[8];
600 for (
i = 0;
i < 8;
i++) {
601 if (cube->corners[
i]->value > 0.0f) {
632 for (edges = polys->
list; edges; edges = edges->
next) {
633 c1 = cube->corners[
corner1[edges->
i]];
634 c2 = cube->corners[
corner2[edges->
i]];
678 index =
HASH(
i, j, k);
681 for (; c !=
nullptr; c = c->
next) {
682 if (c->
i ==
i && c->
j == j && c->
k == k) {
711 return (face ==
L) ?
LF :
BN;
713 return (face ==
L) ?
LN :
TF;
715 return (face ==
L) ?
LB :
TN;
717 return (face ==
L) ?
LT :
BF;
719 return (face ==
R) ?
RN :
BF;
721 return (face ==
R) ?
RF :
TN;
723 return (face ==
R) ?
RT :
BN;
725 return (face ==
R) ?
RB :
TF;
727 return (face ==
B) ?
RB :
LN;
729 return (face ==
B) ?
LB :
RF;
731 return (face ==
T) ?
LT :
RN;
733 return (face ==
T) ?
RT :
LF;
744 return face == other ?
rightface[edge] : other;
752 static bool is_done =
false;
753 int i,
e, c, done[12],
pos[8];
760 for (
i = 0;
i < 256;
i++) {
761 for (
e = 0;
e < 12;
e++) {
764 for (c = 0; c < 8; c++) {
767 for (
e = 0;
e < 12;
e++) {
771 int start =
e, edge =
e;
799 for (
i = 0;
i < 256;
i++) {
805 for (edges = polys->
list; edges; edges = edges->
next) {
831 for (
int i = 0;
i < 256;
i++) {
860 index =
HASH(
i, j, k);
863 for (
l = q;
l !=
nullptr;
l =
l->next) {
864 if (
l->i ==
i &&
l->j == j &&
l->k == k) {
887 if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) {
898 index =
HASH(i1, j1, k1) +
HASH(i2, j2, k2);
919 if (i1 > i2 || (i1 == i2 && (j1 > j2 || (j1 == j2 && k1 > k2)))) {
930 q = table[
HASH(i1, j1, k1) +
HASH(i2, j2, k2)];
931 for (; q !=
nullptr; q = q->
next) {
932 if (q->
i1 == i1 && q->
j1 == j1 && q->
k1 == k1 && q->
i2 == i2 && q->
j2 == j2 && q->
k2 == k2) {
948#ifndef USE_ACCUM_NORMAL
954static void vnormal(
PROCESS *
process,
const float point[3],
float r_no[3])
956 const float delta =
process->delta;
981#ifdef USE_ACCUM_NORMAL
988 vid = int(
process->co.size()) - 1;
1000 float c1_value, c1_co[3];
1001 float c2_value, c2_co[3];
1004 c1_value = c2->
value;
1006 c2_value = c1->
value;
1010 c1_value = c1->
value;
1012 c2_value = c2->
value;
1030 float tmp = -c1_value / (c2_value - c1_value);
1054 for (n = 0; n < 8; n++) {
1097 for (dir[0] = -1; dir[0] <= 1; dir[0]++) {
1098 for (dir[1] = -1; dir[1] <= 1; dir[1]++) {
1099 for (dir[2] = -1; dir[2] <= 1; dir[2]++) {
1100 if (dir[0] == 0 && dir[1] == 0 && dir[2] == 0) {
1115 add[0] = it[0] - dir[0];
1116 add[1] = it[1] - dir[1];
1117 add[2] = it[2] - dir[2];
1122 }
while ((it[0] > lbn[0]) && (it[1] > lbn[1]) && (it[2] > lbn[2]) && (it[0] < rtf[0]) &&
1123 (it[1] < rtf[1]) && (it[2] < rtf[2]));
1143 "Metaball BVH Queue");
1151 while (
process->cubes !=
nullptr) {
1179 Scene *sce_iter = scene;
1189 float obinv[4][4], obmat[4][4];
1190 copy_m4_m4(obmat, ob->object_to_world().ptr());
1235 float pos[4][4],
rot[4][4];
1236 float expx, expy, expz;
1245 new_ml->
mat =
static_cast<float *
>(
1247 new_ml->
imat =
static_cast<float *
>(
1252 if (ml->s > 10.0f) {
1261 new_ml->
s = -new_ml->
s;
1286 new_ml->
rad2 = 1 / (ml->rad * ml->rad);
1325 for (
uint i = 0;
i < 8;
i++) {
1331 for (
uint i = 0;
i < 8;
i++) {
1368 if (
process.thresh < 0.001f) {
1371 else if (
process.thresh < 0.01f) {
1374 else if (
process.thresh < 0.1f) {
1417 const float eps = 0.00001f;
1419 for (
int i = 0;
i < 3;
i++) {
1437 int corners_num = 0;
1441 corners_num +=
count;
1445 mesh->vert_positions_for_write().copy_from(
process.co);
1449 int loop_offset = 0;
1454 face_offsets[
i] = loop_offset;
1456 corner_verts[loop_offset] =
indices[0];
1457 corner_verts[loop_offset + 1] =
indices[1];
1458 corner_verts[loop_offset + 2] =
indices[2];
1460 corner_verts[loop_offset + 3] =
indices[3];
1463 loop_offset +=
count;
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
General operations, lookup, etc. for blender objects.
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
int BKE_scene_base_iter_next(Depsgraph *depsgraph, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob)
#define LISTBASE_FOREACH(type, var, list)
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
float normal_quad_v3(float n[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
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])
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
bool has_zero_axis_m4(const float matrix[4][4])
void mul_m4_v3(const float M[4][4], float r[3])
#define mul_m4_series(...)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void unit_m4(float m[4][4])
void quat_to_mat4(float m[4][4], const float q[4])
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
MINLINE float normalize_v3(float n[3])
#define BLI_MEMARENA_STD_BUFSIZE
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
size_t BLI_string_split_name_number(const char *name, char delim, char *r_name_left, int *r_number) ATTR_NONNULL(1
#define INIT_MINMAX(min, max)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
BPy_StructRNA * depsgraph
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
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.
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
static void addtovertices(PROCESS *process, const float v[3], const float no[3])
static void makecubetable()
static void closest_latice(int r[3], const float pos[3], const float size)
static void find_first_points(PROCESS *process, const uint em)
#define MBALL_ARRAY_LEN_INIT
static INTLISTS * cubetable[256]
static void polygonize(PROCESS *process)
void BKE_mball_cubeTable_free()
static void make_box_from_metaelem(Box *r, const MetaElem *ml)
static bool object_has_zero_axis_matrix(const Object *bob)
static void docube(PROCESS *process, CUBE *cube)
static int getedge(EDGELIST *table[], int i1, int j1, int k1, int i2, int j2, int k2)
static void next_lattice(int r[3], const float pos[3], const float size)
Mesh * BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
static void freepolygonize(PROCESS *process)
static int nextcwedge(int edge, int face)
static CORNER * setcorner(PROCESS *process, int i, int j, int k)
static float metaball(PROCESS *process, float x, float y, float z)
static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Object *ob)
static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2)
static uint partition_mainb(MetaElem **mainb, uint start, uint end, uint s, float div)
static int otherface(int edge, int face)
static void prev_lattice(int r[3], const float pos[3], const float size)
static void make_box_union(const BoundBox *a, const Box *b, Box *r_out)
static void add_cube(PROCESS *process, int i, int j, int k)
static void build_bvh_spatial(PROCESS *process, MetaballBVHNode *node, uint start, uint end, const Box *allbox)
static void make_face(PROCESS *process, int i1, int i2, int i3, int i4)
static void setedge(PROCESS *process, int i1, int j1, int k1, int i2, int j2, int k2, int vid)
static int setcenter(PROCESS *process, CENTERLIST *table[], const int i, const int j, const int k)
static float densfunc(const MetaElem *ball, float x, float y, float z)
static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float r_p[3])
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
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)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3
blender::Vector< blender::float3 > co
MetaballBVHNode metaball_bvh
blender::Vector< blender::float3 > no
MetaballBVHNode ** bvh_queue