Add 2 items to CTL-A menu: Scale to ObData and Rotation to ObData. These options...
authorBenoit Bolsee <benoit.bolsee@online.be>
Mon, 29 Sep 2008 20:13:40 +0000 (20:13 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Mon, 29 Sep 2008 20:13:40 +0000 (20:13 +0000)
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object.c
source/blender/include/BDR_editobject.h
source/blender/src/editobject.c

index ab76fc922eacd8ad82fa7edfc9a02db37b7893eb..a4a06b704bc6043a6f9d1b0937b4e2f40320ac59 100644 (file)
@@ -88,6 +88,8 @@ void set_field_offs(float field);
 void disable_speed_curve(int val);
 
 float bsystem_time(struct Object *ob, float cfra, float ofs);
+void object_scale_to_mat3(struct Object *ob, float mat[][3]);
+void object_rot_to_mat3(struct Object *ob, float mat[][3]);
 void object_to_mat3(struct Object *ob, float mat[][3]);
 void object_to_mat4(struct Object *ob, float mat[][4]);
 
index ec110c6ea7c0ccc63563cbbd2638bfb94332980e..b5d080da247b58aa011862b16764b8859a1eb3b2 100644 (file)
@@ -1479,22 +1479,42 @@ float bsystem_time(Object *ob, float cfra, float ofs)
        return cfra;
 }
 
-void object_to_mat3(Object *ob, float mat[][3])        /* no parent */
+void object_scale_to_mat3(Object *ob, float mat[][3])
 {
-       float smat[3][3], vec[3];
-       float rmat[3][3];
-       /*float q1[4];*/
-       
-       /* size */
+       float vec[3];
        if(ob->ipo) {
                vec[0]= ob->size[0]+ob->dsize[0];
                vec[1]= ob->size[1]+ob->dsize[1];
                vec[2]= ob->size[2]+ob->dsize[2];
-               SizeToMat3(vec, smat);
+               SizeToMat3(vec, mat);
+       }
+       else {
+               SizeToMat3(ob->size, mat);
+       }
+}
+
+void object_rot_to_mat3(Object *ob, float mat[][3])
+{
+       float vec[3];
+       if(ob->ipo) {
+               vec[0]= ob->rot[0]+ob->drot[0];
+               vec[1]= ob->rot[1]+ob->drot[1];
+               vec[2]= ob->rot[2]+ob->drot[2];
+               EulToMat3(vec, mat);
        }
        else {
-               SizeToMat3(ob->size, smat);
+               EulToMat3(ob->rot, mat);
        }
+}
+
+void object_to_mat3(Object *ob, float mat[][3])        /* no parent */
+{
+       float smat[3][3];
+       float rmat[3][3];
+       /*float q1[4];*/
+       
+       /* size */
+       object_scale_to_mat3(ob, smat);
 
        /* rot */
        /* Quats arnt used yet */
@@ -1508,15 +1528,7 @@ void object_to_mat3(Object *ob, float mat[][3])  /* no parent */
                }
        }
        else {*/
-               if(ob->ipo) {
-                       vec[0]= ob->rot[0]+ob->drot[0];
-                       vec[1]= ob->rot[1]+ob->drot[1];
-                       vec[2]= ob->rot[2]+ob->drot[2];
-                       EulToMat3(vec, rmat);
-               }
-               else {
-                       EulToMat3(ob->rot, rmat);
-               }
+               object_rot_to_mat3(ob, rmat);
        /*}*/
        Mat3MulMat3(mat, rmat, smat);
 }
index ac60aece34430788a504f6d468f285adc6eb6e25..bc95c221b511e7a82ded3c9f6155c7d976f17c2c 100644 (file)
@@ -77,6 +77,8 @@ void make_links_menu(void);
 void make_links(short event);
 void make_duplilist_real(void);
 void apply_objects_locrot(void);
+void apply_objects_scale(void);
+void apply_objects_rot(void);
 void apply_objects_visual_tx(void);
 void apply_object(void);
 
index 370f116d318b91ddcbb3ec07ebea1d0d0b887778..250332c4afa80ee120e2de8776d8fc23b191c97d 100644 (file)
@@ -3938,7 +3938,7 @@ void make_links(short event)
        BIF_undo_push("Create links");
 }
 
-void apply_objects_locrot( void )
+static void apply_objects_internal( int apply_scale, int apply_rot )
 {
        Base *base, *basact;
        Object *ob;
@@ -3952,7 +3952,11 @@ void apply_objects_locrot( void )
        float mat[3][3];
        int a, change = 0;
        
-       
+       if (!apply_scale && !apply_rot) {
+               /* do nothing? */
+               error("Nothing to do!");
+               return;
+       }
        /* first check if we can execute */
        for (base= FIRSTBASE; base; base= base->next) {
                if TESTBASELIB(base) {
@@ -4000,7 +4004,13 @@ void apply_objects_locrot( void )
                        ob= base->object;
                        
                        if(ob->type==OB_MESH) {
-                               object_to_mat3(ob, mat);
+                               if (apply_scale && apply_rot)
+                                       object_to_mat3(ob, mat);
+                               else if (apply_scale)
+                                       object_scale_to_mat3(ob, mat);
+                               else
+                                       object_rot_to_mat3(ob, mat);
+
                                me= ob->data;
                                
                                /* see checks above */
@@ -4009,8 +4019,10 @@ void apply_objects_locrot( void )
                                for(a=0; a<me->totvert; a++, mvert++) {
                                        Mat3MulVecfl(mat, mvert->co);
                                }
-                               ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
-                               ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
+                               if (apply_scale)
+                                       ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
+                               if (apply_rot)
+                                       ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
                                /*QuatOne(ob->quat);*/ /* Quats arnt used yet */
                                
                                where_is_object(ob);
@@ -4025,15 +4037,22 @@ void apply_objects_locrot( void )
                                change = 1;
                        }
                        else if (ob->type==OB_ARMATURE) {
-                               object_to_mat3(ob, mat);
+                               if (apply_scale && apply_rot)
+                                       object_to_mat3(ob, mat);
+                               else if (apply_scale)
+                                       object_scale_to_mat3(ob, mat);
+                               else
+                                       object_rot_to_mat3(ob, mat);
                                arm= ob->data;
                                
                                /* see checks above */
                                apply_rot_armature(ob, mat);
                                
                                /* Reset the object's transforms */
-                               ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
-                               ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
+                               if (apply_scale)
+                                       ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
+                               if (apply_rot)
+                                       ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
                                /*QuatOne(ob->quat); (not used anymore)*/
                                
                                where_is_object(ob);
@@ -4042,7 +4061,12 @@ void apply_objects_locrot( void )
                        }
                        else if ELEM(ob->type, OB_CURVE, OB_SURF) {
                                float scale;
-                               object_to_mat3(ob, mat);
+                               if (apply_scale && apply_rot)
+                                       object_to_mat3(ob, mat);
+                               else if (apply_scale)
+                                       object_scale_to_mat3(ob, mat);
+                               else
+                                       object_rot_to_mat3(ob, mat);
                                scale = Mat3ToScalef(mat);
                                cu= ob->data;
                                
@@ -4071,9 +4095,10 @@ void apply_objects_locrot( void )
                                        }
                                        nu= nu->next;
                                }
-                       
-                               ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
-                               ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
+                               if (apply_scale)
+                                       ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
+                               if (apply_rot)
+                                       ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
                                /*QuatOne(ob->quat); (quats arnt used anymore)*/
                                
                                where_is_object(ob);
@@ -4095,10 +4120,30 @@ void apply_objects_locrot( void )
        }
        if (change) {
                allqueue(REDRAWVIEW3D, 0);
-               BIF_undo_push("Apply Objects Scale & Rotation");
+               if (apply_scale && apply_rot)
+                       BIF_undo_push("Apply Objects Scale & Rotation");
+               else if (apply_scale)
+                       BIF_undo_push("Apply Objects Scale");
+               else
+                       BIF_undo_push("Apply Objects Rotation");
        }
 }
 
+void apply_objects_locrot(void)
+{
+       apply_objects_internal(1, 1);
+}
+
+void apply_objects_scale(void)
+{
+       apply_objects_internal(1, 0);
+}
+
+void apply_objects_rot(void)
+{
+       apply_objects_internal(0, 1);
+}
+
 void apply_objects_visual_tx( void )
 {
        Base *base;
@@ -4154,7 +4199,7 @@ void apply_object( void )
                if ((ob->pose) && (ob->flag & OB_POSEMODE))
                        evt = pupmenu("Apply Object%t|Current Pose as RestPose%x3");
                else
-                       evt = pupmenu("Apply Object%t|Scale and Rotation to ObData%x1|Visual Transform to Objects Loc/Scale/Rot%x2");
+                       evt = pupmenu("Apply Object%t|Scale and Rotation to ObData%x1|Visual Transform to Objects Loc/Scale/Rot%x2|Scale to ObData%x4|Rotation to ObData%x5");
                if (evt==-1) return;
                
                switch (evt) {
@@ -4167,6 +4212,12 @@ void apply_object( void )
                        case 3:
                                apply_armature_pose2bones();
                                break;
+                       case 4:
+                               apply_objects_scale();
+                               break;
+                       case 5:
+                               apply_objects_rot();
+                               break;
                }
        }
 }