[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50259] trunk/blender/source/blender/ blenkernel/intern/mball.c: code cleanup: move static mball vars into their own struct, wasnt very clear from reading code what was defined in the function.
Campbell Barton
ideasman42 at gmail.com
Wed Aug 29 09:07:18 CEST 2012
Revision: 50259
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50259
Author: campbellbarton
Date: 2012-08-29 07:07:18 +0000 (Wed, 29 Aug 2012)
Log Message:
-----------
code cleanup: move static mball vars into their own struct, wasnt very clear from reading code what was defined in the function.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/mball.c
Modified: trunk/blender/source/blender/blenkernel/intern/mball.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mball.c 2012-08-29 00:53:29 UTC (rev 50258)
+++ trunk/blender/source/blender/blenkernel/intern/mball.c 2012-08-29 07:07:18 UTC (rev 50259)
@@ -163,11 +163,13 @@
float (*function)(float, float, float), float p[3], MetaBall *mb, int f);
/* Global variables */
+static struct {
+ float thresh;
+ int totelem;
+ MetaElem **mainb;
+ octal_tree *metaball_tree;
+} G_mb = {0};
-static float thresh = 0.6f;
-static int totelem = 0;
-static MetaElem **mainb;
-static octal_tree *metaball_tree = NULL;
/* Functions */
void BKE_mball_unlink(MetaBall *mb)
@@ -523,7 +525,7 @@
char basisname[MAX_ID_NAME], obname[MAX_ID_NAME];
BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.');
- totelem = 0;
+ G_mb.totelem = 0;
/* XXX recursion check, see scene.c, just too simple code this BKE_scene_base_iter_next() */
if (F_ERROR == BKE_scene_base_iter_next(&sce_iter, 0, NULL, NULL))
@@ -564,9 +566,10 @@
}
}
- while (ml) {
- if (!(ml->flag & MB_HIDE)) totelem++;
- ml = ml->next;
+ for ( ; ml; ml = ml->next) {
+ if (!(ml->flag & MB_HIDE)) {
+ G_mb.totelem++;
+ }
}
}
}
@@ -771,27 +774,27 @@
float dens = 0;
int a;
- if (totelem > 1) {
- node = find_metaball_octal_node(metaball_tree->first, x, y, z, metaball_tree->depth);
+ if (G_mb.totelem > 1) {
+ node = find_metaball_octal_node(G_mb.metaball_tree->first, x, y, z, G_mb.metaball_tree->depth);
if (node) {
for (ml_p = node->elems.first; ml_p; ml_p = ml_p->next) {
dens += densfunc(ml_p->ml, x, y, z);
}
- dens += -0.5f * (metaball_tree->pos - node->pos);
- dens += 0.5f * (metaball_tree->neg - node->neg);
+ dens += -0.5f * (G_mb.metaball_tree->pos - node->pos);
+ dens += 0.5f * (G_mb.metaball_tree->neg - node->neg);
}
else {
- for (a = 0; a < totelem; a++) {
- dens += densfunc(mainb[a], x, y, z);
+ for (a = 0; a < G_mb.totelem; a++) {
+ dens += densfunc(G_mb.mainb[a], x, y, z);
}
}
}
else {
- dens += densfunc(mainb[0], x, y, z);
+ dens += densfunc(G_mb.mainb[0], x, y, z);
}
- return thresh - dens;
+ return G_mb.thresh - dens;
}
/* ******************************************** */
@@ -1493,7 +1496,7 @@
MetaElem *ml;
float f = 0.0f;
- ml = mainb[a];
+ ml = G_mb.mainb[a];
f = 1.0 - (mb->thresh / ml->s);
/* Skip, when Stiffness of MetaElement is too small ... MetaElement can't be
@@ -1619,7 +1622,7 @@
mbproc->edges = MEM_callocN(2 * HASHSIZE * sizeof(EDGELIST *), "mbproc->edges");
makecubetable();
- for (a = 0; a < totelem; a++) {
+ for (a = 0; a < G_mb.totelem; a++) {
/* try to find 8 points on the surface for each MetaElem */
find_first_points(mbproc, mb, a);
@@ -1712,7 +1715,7 @@
ml_count++;
ml = ml->next;
}
- totelem -= ml_count;
+ G_mb.totelem -= ml_count;
}
else {
while (ml) {
@@ -1741,9 +1744,9 @@
mult_m4_m4m4(temp1, temp2, temp3);
/* make a copy because of duplicates */
- mainb[a] = new_pgn_element(sizeof(MetaElem));
- *(mainb[a]) = *ml;
- mainb[a]->bb = new_pgn_element(sizeof(BoundBox));
+ G_mb.mainb[a] = new_pgn_element(sizeof(MetaElem));
+ *(G_mb.mainb[a]) = *ml;
+ G_mb.mainb[a]->bb = new_pgn_element(sizeof(BoundBox));
mat = new_pgn_element(4 * 4 * sizeof(float));
imat = new_pgn_element(4 * 4 * sizeof(float));
@@ -1756,70 +1759,70 @@
invert_m4_m4(imat, mat);
- mainb[a]->rad2 = ml->rad * ml->rad;
+ G_mb.mainb[a]->rad2 = ml->rad * ml->rad;
- mainb[a]->mat = (float *) mat;
- mainb[a]->imat = (float *) imat;
+ G_mb.mainb[a]->mat = (float *) mat;
+ G_mb.mainb[a]->imat = (float *) imat;
/* untransformed Bounding Box of MetaElem */
/* 0 */
- mainb[a]->bb->vec[0][0] = -ml->expx;
- mainb[a]->bb->vec[0][1] = -ml->expy;
- mainb[a]->bb->vec[0][2] = -ml->expz;
+ G_mb.mainb[a]->bb->vec[0][0] = -ml->expx;
+ G_mb.mainb[a]->bb->vec[0][1] = -ml->expy;
+ G_mb.mainb[a]->bb->vec[0][2] = -ml->expz;
/* 1 */
- mainb[a]->bb->vec[1][0] = ml->expx;
- mainb[a]->bb->vec[1][1] = -ml->expy;
- mainb[a]->bb->vec[1][2] = -ml->expz;
+ G_mb.mainb[a]->bb->vec[1][0] = ml->expx;
+ G_mb.mainb[a]->bb->vec[1][1] = -ml->expy;
+ G_mb.mainb[a]->bb->vec[1][2] = -ml->expz;
/* 2 */
- mainb[a]->bb->vec[2][0] = ml->expx;
- mainb[a]->bb->vec[2][1] = ml->expy;
- mainb[a]->bb->vec[2][2] = -ml->expz;
+ G_mb.mainb[a]->bb->vec[2][0] = ml->expx;
+ G_mb.mainb[a]->bb->vec[2][1] = ml->expy;
+ G_mb.mainb[a]->bb->vec[2][2] = -ml->expz;
/* 3 */
- mainb[a]->bb->vec[3][0] = -ml->expx;
- mainb[a]->bb->vec[3][1] = ml->expy;
- mainb[a]->bb->vec[3][2] = -ml->expz;
+ G_mb.mainb[a]->bb->vec[3][0] = -ml->expx;
+ G_mb.mainb[a]->bb->vec[3][1] = ml->expy;
+ G_mb.mainb[a]->bb->vec[3][2] = -ml->expz;
/* 4 */
- mainb[a]->bb->vec[4][0] = -ml->expx;
- mainb[a]->bb->vec[4][1] = -ml->expy;
- mainb[a]->bb->vec[4][2] = ml->expz;
+ G_mb.mainb[a]->bb->vec[4][0] = -ml->expx;
+ G_mb.mainb[a]->bb->vec[4][1] = -ml->expy;
+ G_mb.mainb[a]->bb->vec[4][2] = ml->expz;
/* 5 */
- mainb[a]->bb->vec[5][0] = ml->expx;
- mainb[a]->bb->vec[5][1] = -ml->expy;
- mainb[a]->bb->vec[5][2] = ml->expz;
+ G_mb.mainb[a]->bb->vec[5][0] = ml->expx;
+ G_mb.mainb[a]->bb->vec[5][1] = -ml->expy;
+ G_mb.mainb[a]->bb->vec[5][2] = ml->expz;
/* 6 */
- mainb[a]->bb->vec[6][0] = ml->expx;
- mainb[a]->bb->vec[6][1] = ml->expy;
- mainb[a]->bb->vec[6][2] = ml->expz;
+ G_mb.mainb[a]->bb->vec[6][0] = ml->expx;
+ G_mb.mainb[a]->bb->vec[6][1] = ml->expy;
+ G_mb.mainb[a]->bb->vec[6][2] = ml->expz;
/* 7 */
- mainb[a]->bb->vec[7][0] = -ml->expx;
- mainb[a]->bb->vec[7][1] = ml->expy;
- mainb[a]->bb->vec[7][2] = ml->expz;
+ G_mb.mainb[a]->bb->vec[7][0] = -ml->expx;
+ G_mb.mainb[a]->bb->vec[7][1] = ml->expy;
+ G_mb.mainb[a]->bb->vec[7][2] = ml->expz;
/* transformation of Metalem bb */
for (i = 0; i < 8; i++)
- mul_m4_v3((float (*)[4])mat, mainb[a]->bb->vec[i]);
+ mul_m4_v3((float (*)[4])mat, G_mb.mainb[a]->bb->vec[i]);
/* find max and min of transformed bb */
for (i = 0; i < 8; i++) {
/* find maximums */
- if (mainb[a]->bb->vec[i][0] > max_x) max_x = mainb[a]->bb->vec[i][0];
- if (mainb[a]->bb->vec[i][1] > max_y) max_y = mainb[a]->bb->vec[i][1];
- if (mainb[a]->bb->vec[i][2] > max_z) max_z = mainb[a]->bb->vec[i][2];
+ if (G_mb.mainb[a]->bb->vec[i][0] > max_x) max_x = G_mb.mainb[a]->bb->vec[i][0];
+ if (G_mb.mainb[a]->bb->vec[i][1] > max_y) max_y = G_mb.mainb[a]->bb->vec[i][1];
+ if (G_mb.mainb[a]->bb->vec[i][2] > max_z) max_z = G_mb.mainb[a]->bb->vec[i][2];
/* find minimums */
- if (mainb[a]->bb->vec[i][0] < min_x) min_x = mainb[a]->bb->vec[i][0];
- if (mainb[a]->bb->vec[i][1] < min_y) min_y = mainb[a]->bb->vec[i][1];
- if (mainb[a]->bb->vec[i][2] < min_z) min_z = mainb[a]->bb->vec[i][2];
+ if (G_mb.mainb[a]->bb->vec[i][0] < min_x) min_x = G_mb.mainb[a]->bb->vec[i][0];
+ if (G_mb.mainb[a]->bb->vec[i][1] < min_y) min_y = G_mb.mainb[a]->bb->vec[i][1];
+ if (G_mb.mainb[a]->bb->vec[i][2] < min_z) min_z = G_mb.mainb[a]->bb->vec[i][2];
}
/* create "new" bb, only point 0 and 6, which are
* necessary for octal tree filling */
- mainb[a]->bb->vec[0][0] = min_x - ml->rad;
- mainb[a]->bb->vec[0][1] = min_y - ml->rad;
- mainb[a]->bb->vec[0][2] = min_z - ml->rad;
+ G_mb.mainb[a]->bb->vec[0][0] = min_x - ml->rad;
+ G_mb.mainb[a]->bb->vec[0][1] = min_y - ml->rad;
+ G_mb.mainb[a]->bb->vec[0][2] = min_z - ml->rad;
- mainb[a]->bb->vec[6][0] = max_x + ml->rad;
- mainb[a]->bb->vec[6][1] = max_y + ml->rad;
- mainb[a]->bb->vec[6][2] = max_z + ml->rad;
+ G_mb.mainb[a]->bb->vec[6][0] = max_x + ml->rad;
+ G_mb.mainb[a]->bb->vec[6][1] = max_y + ml->rad;
+ G_mb.mainb[a]->bb->vec[6][2] = max_z + ml->rad;
a++;
}
@@ -1832,13 +1835,13 @@
/* totsize (= 'manhattan' radius) */
totsize = 0.0;
- for (a = 0; a < totelem; a++) {
+ for (a = 0; a < G_mb.totelem; a++) {
- vec[0] = mainb[a]->x + mainb[a]->rad + mainb[a]->expx;
- vec[1] = mainb[a]->y + mainb[a]->rad + mainb[a]->expy;
- vec[2] = mainb[a]->z + mainb[a]->rad + mainb[a]->expz;
+ vec[0] = G_mb.mainb[a]->x + G_mb.mainb[a]->rad + G_mb.mainb[a]->expx;
+ vec[1] = G_mb.mainb[a]->y + G_mb.mainb[a]->rad + G_mb.mainb[a]->expy;
+ vec[2] = G_mb.mainb[a]->z + G_mb.mainb[a]->rad + G_mb.mainb[a]->expz;
- calc_mballco(mainb[a], vec);
+ calc_mballco(G_mb.mainb[a], vec);
size = fabsf(vec[0]);
if (size > totsize) totsize = size;
@@ -1847,11 +1850,11 @@
size = fabsf(vec[2]);
if (size > totsize) totsize = size;
- vec[0] = mainb[a]->x - mainb[a]->rad;
- vec[1] = mainb[a]->y - mainb[a]->rad;
- vec[2] = mainb[a]->z - mainb[a]->rad;
+ vec[0] = G_mb.mainb[a]->x - G_mb.mainb[a]->rad;
+ vec[1] = G_mb.mainb[a]->y - G_mb.mainb[a]->rad;
+ vec[2] = G_mb.mainb[a]->z - G_mb.mainb[a]->rad;
- calc_mballco(mainb[a], vec);
+ calc_mballco(G_mb.mainb[a], vec);
size = fabsf(vec[0]);
if (size > totsize) totsize = size;
@@ -1861,8 +1864,8 @@
if (size > totsize) totsize = size;
}
- for (a = 0; a < totelem; a++) {
- thresh += densfunc(mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize);
+ for (a = 0; a < G_mb.totelem; a++) {
+ G_mb.thresh += densfunc(G_mb.mainb[a], 2.0f * totsize, 2.0f * totsize, 2.0f * totsize);
}
return totsize;
@@ -2178,13 +2181,13 @@
float size[3];
int a;
- metaball_tree = MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree");
- metaball_tree->first = node = MEM_mallocN(sizeof(octal_node), "metaball_octal_node");
+ G_mb.metaball_tree = MEM_mallocN(sizeof(octal_tree), "metaball_octal_tree");
+ G_mb.metaball_tree->first = node = MEM_mallocN(sizeof(octal_node), "metaball_octal_node");
/* maximal depth of octree */
- metaball_tree->depth = depth;
+ G_mb.metaball_tree->depth = depth;
- metaball_tree->neg = node->neg = 0;
- metaball_tree->pos = node->pos = 0;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list