Simpledeform origin is no longer attache to parent by default
authorAndre Susano Pinto <andresusanopinto@gmail.com>
Fri, 15 Aug 2008 00:51:44 +0000 (00:51 +0000)
committerAndre Susano Pinto <andresusanopinto@gmail.com>
Fri, 15 Aug 2008 00:51:44 +0000 (00:51 +0000)
That was due to a current limitation on dag system.. that leads to cyclic dependencies.

So now you can attach the origin of a simpledeform  to an empty and mark whether its
affected by the relative position of empty or the global one.

brecht found a workarround to solve the cyclic dependency by
using a parent of both the mesh and the control empty:

empty_parent
 |
 |-> empty controlling simpledeform
 |-> mesh with simpledeform modifier

source/blender/blenkernel/intern/simple_deform.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/src/buttons_editing.c

index 20cba28ab5ae9fa50a182667c0d6fb5b6a73edb9..2984b8fe9d8451d868e35c5fc2737d3ded57f2d2 100644 (file)
@@ -153,13 +153,24 @@ void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, s
        if(smd->origin)
        {
                //inverse is outdated
-               Mat4Invert(smd->origin->imat, smd->origin->obmat);
-               Mat4Invert(ob->imat, ob->obmat);
 
-               ob2mod = tmp_matrix[0];
-               mod2ob = tmp_matrix[1];
-               Mat4MulSerie(ob2mod, smd->origin->imat, ob->obmat, 0, 0, 0, 0, 0, 0);
-               Mat4Invert(mod2ob, ob2mod);
+               if(smd->originOpts & MOD_SIMPLEDEFORM_ORIGIN_LOCAL)
+               {
+                       Mat4Invert(smd->origin->imat, smd->origin->obmat);
+                       Mat4Invert(ob->imat, ob->obmat);
+                       
+                       ob2mod = tmp_matrix[0];
+                       mod2ob = tmp_matrix[1];
+                       Mat4MulSerie(ob2mod, smd->origin->imat, ob->obmat, 0, 0, 0, 0, 0, 0);
+                       Mat4Invert(mod2ob, ob2mod);
+               }
+               else
+               {
+                       Mat4Invert(smd->origin->imat, smd->origin->obmat);
+                       ob2mod = smd->origin->obmat;
+                       mod2ob = smd->origin->imat;
+               }
+
        }
 
 
index 30bec07f5fcf402c0f3c2defd49d3dbcd1c59945..9ce04c1c27217b18a46b8bd1d633404a5c7e1283 100644 (file)
@@ -544,7 +544,8 @@ typedef struct SimpleDeformModifierData {
 
        char mode;                              /* deform function */
        char axis;                              /* lock axis (for taper and strech) */
-       char pad[2];
+       char originOpts;                /* originOptions */
+       char pad;
 
 } SimpleDeformModifierData;
 
@@ -556,4 +557,8 @@ typedef struct SimpleDeformModifierData {
 #define MOD_SIMPLEDEFORM_LOCK_AXIS_X                   (1<<0)
 #define MOD_SIMPLEDEFORM_LOCK_AXIS_Y                   (1<<1)
 
+/* indicates whether simple deform should use the local
+   coordinates or global coordinates of origin */
+#define MOD_SIMPLEDEFORM_ORIGIN_LOCAL                  (1<<0)
+
 #endif
index 8ea6a6c191a70e40f121d600223efb25e9b7f7d6..63303467856bcaec5e96fa8bb817665b827b79e7 100644 (file)
@@ -1711,32 +1711,6 @@ static int modifier_is_fluid_particles(ModifierData *md) {
        return 0;
 }
 
-static void modifier_link_new_empty(void *pp_empty, void *p_parent)
-{
-       Object **empty = (Object**)pp_empty;
-       Object *parent = (Object*) p_parent;
-
-       /* Add object but witouth chaing layers and or changing active object */
-       Base *base= BASACT, *newbase;
-
-       (*empty) = add_object(OB_EMPTY);
-
-       newbase= BASACT;
-       newbase->lay= base->lay;
-       (*empty)->lay= newbase->lay;
-
-       /* restore, add_object sets active */
-       BASACT= base;
-
-       /* Makes parent relation and positions empty on center of object */
-       (*empty)->partype= PAROBJECT;
-       (*empty)->parent = parent;
-       Mat4CpyMat4( (*empty)->obmat, parent->obmat );
-       Mat4Invert(  (*empty)->parentinv, parent->obmat);
-       apply_obmat( (*empty) );
-       DAG_scene_sort(G.scene);
-}
-
 static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco, int *yco, int index, int cageIndex, int lastCageIndex)
 {
        ModifierTypeInfo *mti = modifierType_getInfo(md->type);
@@ -1912,9 +1886,8 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
 
                } else if (md->type==eModifierType_SimpleDeform) {
                        SimpleDeformModifierData *smd = (SimpleDeformModifierData*) md;
-
                        height += 19*4;
-
+                       if(smd->origin != NULL) height += 19;
                        if(smd->mode == MOD_SIMPLEDEFORM_MODE_STRETCH
                        || smd->mode == MOD_SIMPLEDEFORM_MODE_TAPER  )
                                height += 19;
@@ -2589,20 +2562,10 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
                        but=uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ",         lx, (cy-=19), buttonWidth,19, &smd->vgroup_name, 0, 31, 0, 0, "Vertex Group name");
                        uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ob);
 
-                       uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CHANGEDEP, "Ob: ",      lx, (cy-=19), buttonWidth-17,19, &smd->origin, "Origin of modifier space coordinates");
+                       uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CHANGEDEP, "Ob: ",      lx, (cy-=19), buttonWidth,19, &smd->origin, "Origin of modifier space coordinates");
+                       if(smd->origin != NULL)
+                               uiDefButBitC(block, TOG, MOD_SIMPLEDEFORM_ORIGIN_LOCAL, B_MODIFIER_RECALC, "Relative",lx,(cy-=19),buttonWidth,19, &smd->originOpts, 0, 0, 0, 0, "Sets the origin of deform space to be relative to the object");
 
-                       if(smd->origin)
-                       {
-                               uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_VIEW, REDRAWALL, ICON_RESTRICT_VIEW_OFF,
-                                                               lx + buttonWidth-17, cy, 17, 19,
-                                                               &(smd->origin->restrictflag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
-                       }
-                       else
-                       {
-                               uiBut *bt;
-                               bt= uiDefIconBut(block, BUT, B_CHANGEDEP, ICON_ZOOMIN, lx+buttonWidth-17, cy, 17, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Creates a new empty");
-                               uiButSetFunc(bt, modifier_link_new_empty, &smd->origin, ob);
-                       }
                        uiDefButF(block, NUM, B_MODIFIER_RECALC, "Factor:",     lx,(cy-=19),buttonWidth,19, &smd->factor, -10.0f, 10.0f, 0.5f, 0, "Deform Factor");
 
                        uiDefButF(block, NUM, B_MODIFIER_RECALC, "Upper Limit:",        lx,(cy-=19),buttonWidth,19, &smd->limit[1], -1000.0f, 1000.0f, 5.0f, 0, "Upper Limit Bend on X");