Crease transformation
authorMartin Poirier <theeth@yahoo.com>
Mon, 4 Apr 2005 23:37:15 +0000 (23:37 +0000)
committerMartin Poirier <theeth@yahoo.com>
Mon, 4 Apr 2005 23:37:15 +0000 (23:37 +0000)
Behavior is a bit different. Instead of showing the weird two value thing like the old transform did, it always show the weight variation in +/- that is applied to every edge. Works a bit like scale. Move away from center to increase, move closer to decrease (between -1.0 and 1.0).
Works with PET (not using connection yet).

Also removed some missed global Trans variable abuse.

source/blender/include/BIF_transform.h
source/blender/src/space.c
source/blender/src/transform.c
source/blender/src/transform.h
source/blender/src/transform_generics.c

index 44b90991d9ff3fac9b3a323b210b43cff447f96b..6450d8c80a800f6cd78943c2f62cd01648b1f61d 100755 (executable)
@@ -48,6 +48,7 @@
 #define TFM_LAMP_ENERGY                10
 #define TFM_TRACKBALL          11
 #define TFM_PUSHPULL           12
+#define TFM_CREASE                     13
 
 /* TRANSFORM CONTEXTS */
 #define CTX_NONE                       0
index 0556aa7306aac908290356c690f024cc051bde32..3c831743206d600ed67102fcb1c740a0a6a6f64b 100644 (file)
@@ -1188,7 +1188,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                }
                                else if (G.qual==LR_SHIFTKEY) {
                                        if (G.obedit && G.obedit->type==OB_MESH) {
-                                               transform('e');
+                                               Transform(TFM_CREASE, CTX_EDGE);
                                        }
                                }
                                break;
index 2c3c2fa5c1b6103abe4ea6c1de54fb0c8a7648ab..bac4d59a7ba5b7a8166b86363ce1af8d6797fea0 100755 (executable)
@@ -244,6 +244,8 @@ static void set_prop_dist(TransInfo *t, short with_dist)
 
 /* ************************** CONVERSIONS ************************* */
 
+/* ********************* texture space ********* */
+
 static void createTransTexspace(TransInfo *t)
 {
        TransData *td;
@@ -291,6 +293,74 @@ static void createTransTexspace(TransInfo *t)
        VECCOPY(td->ext->isize, td->ext->size);
 }
 
+/* ********************* edge (for crease) ***** */
+
+static void createTransEdge(TransInfo *t) {
+       TransData *td = NULL;
+       EditMesh *em = G.editMesh;
+       EditEdge *eed;
+       Mesh *me = G.obedit->data;
+       EditVert **nears = NULL;
+       float *vectors = NULL;
+       float mtx[3][3], smtx[3][3];
+       int count=0, countsel=0;
+       int propmode = t->flag & T_PROP_EDIT;
+
+       /* THIS IS A REALLY STUPID HACK, MUST BE A BETTER WAY TO DO IT */
+       /* this is sufficient to invoke edges added in mesh, but only in editmode */
+       if(me->medge==NULL) {
+               me->medge= MEM_callocN(sizeof(MEdge), "fake medge");
+               me->totedge= 1;
+               allqueue(REDRAWBUTSEDIT, 0);
+       }
+                                       
+       for(eed= em->edges.first; eed; eed= eed->next) {
+               if(eed->h==0) {
+                       if (eed->f & SELECT) countsel++;
+                       if (propmode) count++;
+               }
+       }
+
+       if (countsel == 0)
+               return;
+
+       if(propmode) {
+               t->total = count;
+       }
+       else {
+               t->total = countsel;
+       }
+
+       td= t->data= MEM_callocN(t->total * sizeof(TransData), "TransCrease");
+
+       Mat3CpyMat4(mtx, G.obedit->obmat);
+       Mat3Inv(smtx, mtx);
+
+       for(eed= em->edges.first; eed; eed= eed->next) {
+               if(eed->h==0 && (eed->f & SELECT || propmode)) {
+                       /* need to set center for center calculations */
+                       VecAddf(td->center, eed->v1->co, eed->v2->co);
+                       VecMulf(td->center, 0.5f);
+
+                       td->loc= NULL;
+                       if (eed->f & SELECT)
+                               td->flag= TD_SELECTED;
+                       else 
+                               td->flag= 0;
+
+
+                       Mat3CpyMat3(td->smtx, smtx);
+                       Mat3CpyMat3(td->mtx, mtx);
+
+                       td->ext = NULL;
+                       td->tdi = NULL;
+                       td->val = &(eed->crease);
+                       td->ival = eed->crease;
+
+                       td++;
+               }
+       }
+}
 
 /* ********************* pose mode ************* */
 
@@ -411,8 +481,8 @@ static void createTransPose(TransInfo *t)
        if(t->total==0) return;
        
        /* init trans data */
-    td = t->data = MEM_mallocN(Trans.total*sizeof(TransData), "TransPoseBone");
-    tdx = t->ext = MEM_mallocN(Trans.total*sizeof(TransDataExtension), "TransPoseBoneExt");
+    td = t->data = MEM_mallocN(t->total*sizeof(TransData), "TransPoseBone");
+    tdx = t->ext = MEM_mallocN(t->total*sizeof(TransDataExtension), "TransPoseBoneExt");
        for(i=0; i<t->total; i++, td++, tdx++) {
                td->ext= tdx;
                td->tdi = NULL;
@@ -424,6 +494,8 @@ static void createTransPose(TransInfo *t)
        
 }
 
+/* ********************* armature ************** */
+
 static void createTransArmatureVerts(TransInfo *t)
 {
        EditBone *ebo;
@@ -445,7 +517,7 @@ static void createTransArmatureVerts(TransInfo *t)
        Mat3CpyMat4(mtx, G.obedit->obmat);
        Mat3Inv(smtx, mtx);
 
-    td = t->data = MEM_mallocN(Trans.total*sizeof(TransData), "TransEditBone");
+    td = t->data = MEM_mallocN(t->total*sizeof(TransData), "TransEditBone");
        
        for (ebo=G.edbo.first;ebo;ebo=ebo->next){
                if (ebo->flag & BONE_TIPSEL){
@@ -482,6 +554,8 @@ static void createTransArmatureVerts(TransInfo *t)
        }
 }
 
+/* ********************* meta elements ********* */
+
 static void createTransMBallVerts(TransInfo *t)
 {
        MetaElem *ml;
@@ -503,8 +577,8 @@ static void createTransMBallVerts(TransInfo *t)
        if(propmode) t->total = count; 
        else t->total = countsel;
        
-       td = t->data= MEM_mallocN(Trans.total*sizeof(TransData), "TransObData(MBall EditMode)");
-       tx = t->ext = MEM_mallocN(Trans.total*sizeof(TransDataExtension), "MetaElement_TransExtension");
+       td = t->data= MEM_mallocN(t->total*sizeof(TransData), "TransObData(MBall EditMode)");
+       tx = t->ext = MEM_mallocN(t->total*sizeof(TransDataExtension), "MetaElement_TransExtension");
 
        Mat3CpyMat4(mtx, G.obedit->obmat);
        Mat3Inv(smtx, mtx);
@@ -541,6 +615,8 @@ static void createTransMBallVerts(TransInfo *t)
        }
 } 
 
+/* ********************* curve/surface ********* */
+
 static void calc_distanceCurveVerts(TransData *head, TransData *tail) {
        TransData *td, *td_near = NULL;
        for (td = head; td<=tail; td++) {
@@ -622,7 +698,7 @@ static void createTransCurveVerts(TransInfo *t)
        
        if(propmode) Trans.total = count; 
        else t->total = countsel;
-       t->data= MEM_mallocN(Trans.total*sizeof(TransData), "TransObData(Curve EditMode)");
+       t->data= MEM_mallocN(t->total*sizeof(TransData), "TransObData(Curve EditMode)");
 
        Mat3CpyMat4(mtx, G.obedit->obmat);
        Mat3Inv(smtx, mtx);
@@ -715,6 +791,8 @@ static void createTransCurveVerts(TransInfo *t)
        }
 }
 
+/* ********************* lattice *************** */
+
 static void createTransLatticeVerts(TransInfo *t)
 {
        TransData *td = NULL;
@@ -737,7 +815,7 @@ static void createTransLatticeVerts(TransInfo *t)
        
        if(propmode) t->total = count; 
        else t->total = countsel;
-       t->data= MEM_mallocN(Trans.total*sizeof(TransData), "TransObData(Lattice EditMode)");
+       t->data= MEM_mallocN(t->total*sizeof(TransData), "TransObData(Lattice EditMode)");
        
        Mat3CpyMat4(mtx, G.obedit->obmat);
        Mat3Inv(smtx, mtx);
@@ -768,6 +846,8 @@ static void createTransLatticeVerts(TransInfo *t)
        }
 } 
 
+/* ********************* mesh ****************** */
+
 /* proportional distance based on connectivity  */
 #define E_VEC(a)       (vectors + (3 * (int)(a)->vn))
 #define E_NEAR(a)      (nears[((int)(a)->vn)])
@@ -905,8 +985,8 @@ static void createTransEditVerts(TransInfo *t)
        EditMesh *em = G.editMesh;
        EditVert *eve;
        EditVert **nears = NULL;
-       float mtx[3][3], smtx[3][3];
        float *vectors = NULL;
+       float mtx[3][3], smtx[3][3];
        int count=0, countsel=0;
        int propmode = t->flag & T_PROP_EDIT;
                
@@ -953,11 +1033,11 @@ static void createTransEditVerts(TransInfo *t)
                t->total = count; 
        
                /* allocating scratch arrays */
-               vectors = (float *)malloc(Trans.total * 3 * sizeof(float));
-               nears = (EditVert**)malloc(Trans.total * sizeof(EditVert*));
+               vectors = (float *)malloc(t->total * 3 * sizeof(float));
+               nears = (EditVert**)malloc(t->total * sizeof(EditVert*));
        }
        else t->total = countsel;
-       tob= t->data= MEM_mallocN(Trans.total*sizeof(TransData), "TransObData(Mesh EditMode)");
+       tob= t->data= MEM_mallocN(t->total*sizeof(TransData), "TransObData(Mesh EditMode)");
        
        Mat3CpyMat4(mtx, G.obedit->obmat);
        Mat3Inv(smtx, mtx);
@@ -1419,6 +1499,16 @@ static void createTransData(TransInfo *t)
                t->flag |= T_TEXTURE;
                createTransTexspace(t);
        }
+       else if (t->context == CTX_EDGE) {
+               t->ext = NULL;
+               t->flag |= T_EDIT;
+               createTransEdge(t);
+               if(t->data && t->flag & T_PROP_EDIT) {
+                       sort_trans_data(t);     // makes selected become first in array
+                       set_prop_dist(t, 1);
+                       sort_trans_data_dist(t);
+               }
+       }
        else if (G.obpose) {
                t->flag |= T_POSE;
                createTransPose(t);
@@ -1554,6 +1644,9 @@ void Transform(int mode, int context)
        case TFM_PUSHPULL:
                initPushPull(&Trans);
                break;
+       case TFM_CREASE:
+               initCrease(&Trans);
+               break;
        }
 
        initConstraint(&Trans);
@@ -3149,3 +3242,96 @@ int PushPull(TransInfo *t, short mval[2])
 
        return 1;
 }
+
+/* ************************** CREASE *************************** */
+
+void initCrease(TransInfo *t) 
+{
+       t->idx_max = 0;
+       t->num.idx_max = 0;
+       t->snap[0] = 0.0f;
+       t->snap[1] = 0.1f;
+       t->snap[2] = t->snap[1] * 0.1f;
+       t->transform = Crease;
+       t->fac = (float)sqrt( (float)
+               (
+                       (t->center2d[1] - t->imval[1])*(t->center2d[1] - t->imval[1])
+               +
+                       (t->center2d[0] - t->imval[0])*(t->center2d[0] - t->imval[0])
+               ) );
+
+       if(t->fac==0.0f) t->fac= 1.0f;  // prevent Inf
+}
+
+int Crease(TransInfo *t, short mval[2]) 
+{
+       TransData *td = t->data;
+       float crease;
+       int i;
+       char str[50];
+
+               
+       if(t->flag & T_SHIFT_MOD) {
+               /* calculate ratio for shiftkey pos, and for total, and blend these for precision */
+               float dx= (float)(t->center2d[0] - t->shiftmval[0]);
+               float dy= (float)(t->center2d[1] - t->shiftmval[1]);
+               crease = (float)sqrt( dx*dx + dy*dy)/t->fac;
+               
+               dx= (float)(t->center2d[0] - mval[0]);
+               dy= (float)(t->center2d[1] - mval[1]);
+               crease+= 0.1f*(float)(sqrt( dx*dx + dy*dy)/t->fac -crease);
+               
+       }
+       else {
+               float dx= (float)(t->center2d[0] - mval[0]);
+               float dy= (float)(t->center2d[1] - mval[1]);
+               crease = (float)sqrt( dx*dx + dy*dy)/t->fac;
+       }
+
+       crease -= 1.0f;
+       if (crease > 1.0f) crease = 1.0f;
+
+       snapGrid(t, &crease);
+
+       applyNumInput(&t->num, &crease);
+
+       /* header print for NumInput */
+       if (hasNumInput(&t->num)) {
+               char c[20];
+
+               outputNumInput(&(t->num), c);
+
+               if (crease >= 0.0f)
+                       sprintf(str, "Crease: +%s", c, t->proptext);
+               else
+                       sprintf(str, "Crease: %s", c, t->proptext);
+       }
+       else {
+               /* default header print */
+               if (crease >= 0.0f)
+                       sprintf(str, "Crease: +%.3f %s", crease, t->proptext);
+               else
+                       sprintf(str, "Crease: %.3f %s", crease, t->proptext);
+       }
+       
+       for(i = 0 ; i < t->total; i++, td++) {
+               if (td->flag & TD_NOACTION)
+                       break;
+
+               if (td->val) {
+                       *td->val = td->ival + crease * td->factor;
+                       if (*td->val < 0.0f) *td->val = 0.0f;
+                       if (*td->val > 1.0f) *td->val = 1.0f;
+               }
+       }
+
+       recalcData(t);
+
+       headerprint(str);
+
+       force_draw(0);
+
+       helpline (t->center);
+
+       return 1;
+}
index 8527407afcdb05adb97a2a79f1aa8b67de55529f..30d1bab30eccaf1a7aa0af8e763805e8595e1d1b 100755 (executable)
@@ -211,6 +211,9 @@ int Trackball(TransInfo *t, short mval[2]);
 void initPushPull(TransInfo *t);
 int PushPull(TransInfo *t, short mval[2]);
 
+void initCrease(TransInfo *t);
+int Crease(TransInfo *t, short mval[2]);
+
 /* exported from transform.c */
 struct ListBase;
 void count_bone_select(struct ListBase *lb, int *counter);
index 31641962ced552f210b39d8a031b81d19e8040f7..1aef46f6448fd211df0e72a71e90271826a2e68c 100755 (executable)
@@ -338,6 +338,9 @@ void initTransModeFlags(TransInfo *t, int mode)
        case TFM_SHEAR:
                t->flag |= T_NO_CONSTRAINT;
                break;
+       case TFM_CREASE:
+               t->flag |= T_NO_CONSTRAINT;
+               break;
        }
 }
 
@@ -523,7 +526,10 @@ static void restore_ipokey(float *poin, float *old)
 }
 
 void restoreElement(TransData *td) {
-       VECCOPY(td->loc, td->iloc);
+       /* TransData for crease has no loc */
+       if (td->loc) {
+               VECCOPY(td->loc, td->iloc);
+       }
        if (td->val) {
                *td->val = td->ival;
        }