fix [#34200] Metaball Tessellate error
authorCampbell Barton <ideasman42@gmail.com>
Mon, 11 Feb 2013 13:07:26 +0000 (13:07 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 11 Feb 2013 13:07:26 +0000 (13:07 +0000)
source/blender/blenkernel/intern/mball.c
source/blender/editors/metaball/mball_edit.c
source/blender/makesdna/DNA_meta_types.h

index d939b9cc3c01c42de3334aba70a0c12bc7358d22..867249c97dd8264fd5da7cfc7647ec3d965ad504 100644 (file)
@@ -1654,6 +1654,14 @@ static void polygonize(PROCESS *mbproc, MetaBall *mb)
        }
 }
 
+/* could move to math api */
+BLI_INLINE void copy_v3_fl3(float v[3], float x, float y, float z)
+{
+       v[0] = x;
+       v[1] = y;
+       v[2] = z;
+}
+
 static float init_meta(Scene *scene, Object *ob)    /* return totsize */
 {
        Scene *sce_iter = scene;
@@ -1730,6 +1738,7 @@ static float init_meta(Scene *scene, Object *ob)    /* return totsize */
                                                float temp1[4][4], temp2[4][4], temp3[4][4];
                                                float (*mat)[4] = NULL, (*imat)[4] = NULL;
                                                float max_x, max_y, max_z, min_x, min_y, min_z;
+                                               float expx, expy, expz;
 
                                                max_x = max_y = max_z = -3.4e38;
                                                min_x = min_y = min_z =  3.4e38;
@@ -1770,39 +1779,26 @@ static float init_meta(Scene *scene, Object *ob)    /* return totsize */
                                                G_mb.mainb[a]->mat = (float *) mat;
                                                G_mb.mainb[a]->imat = (float *) imat;
 
+                                               if (!MB_TYPE_SIZE_SQUARED(ml->type)) {
+                                                       expx = ml->expx;
+                                                       expy = ml->expy;
+                                                       expz = ml->expz;
+                                               }
+                                               else {
+                                                       expx = ml->expx * ml->expx;
+                                                       expy = ml->expy * ml->expy;
+                                                       expz = ml->expz * ml->expz;
+                                               }
+
                                                /* untransformed Bounding Box of MetaElem */
-                                               /* 0 */
-                                               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 */
-                                               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 */
-                                               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 */
-                                               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 */
-                                               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 */
-                                               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 */
-                                               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 */
-                                               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;
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[0], -expx, -expy, -expz);  /* 0 */
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[1], +expx, -expy, -expz);  /* 1 */
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[2], +expx, +expy, -expz);  /* 2 */
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[3], -expx, +expy, -expz);  /* 3 */
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[4], -expx, -expy, +expz);  /* 4 */
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[5], +expx, -expy, +expz);  /* 5 */
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[5], +expx, +expy, +expz);  /* 6 */
+                                               copy_v3_fl3(G_mb.mainb[a]->bb->vec[5], -expx, +expy, +expz);  /* 7 */
 
                                                /* transformation of Metalem bb */
                                                for (i = 0; i < 8; i++)
index 477a6dd815e2e2cb937504f99cc1e7e890f96b21..6c056df5a38c07acec21f865dcee9aef1d02358a 100644 (file)
@@ -602,7 +602,7 @@ void ED_mball_transform(MetaBall *mb, float *mat)
                me->rad *= scale;
                /* hrmf, probably elems shouldn't be
                 * treating scale differently - campbell */
-               if (ELEM3(me->type, MB_CUBE, MB_PLANE, MB_TUBE)) {
+               if (!MB_TYPE_SIZE_SQUARED(me->type)) {
                        mul_v3_fl(&me->expx, scale);
                }
                else {
index 5b37ff523cb68f637912bf79196ef0151746af28..56683bf47971f17d8fef74366bbba8daae6993ef 100644 (file)
@@ -121,6 +121,8 @@ typedef struct MetaBall {
 #define MB_ELIPSOID    6
 #define MB_CUBE        7
 
+#define MB_TYPE_SIZE_SQUARED(type)  (type == MB_ELIPSOID)
+
 /* ml->flag */
 #define MB_NEGATIVE    2
 #define MB_HIDE                8