diff options
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 46 | ||||
-rw-r--r-- | source/blender/include/BDR_editobject.h | 2 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 79 |
4 files changed, 98 insertions, 31 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index ab76fc922ea..a4a06b704bc 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -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]); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index ec110c6ea7c..b5d080da247 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -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); } diff --git a/source/blender/include/BDR_editobject.h b/source/blender/include/BDR_editobject.h index ac60aece344..bc95c221b51 100644 --- a/source/blender/include/BDR_editobject.h +++ b/source/blender/include/BDR_editobject.h @@ -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); diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 370f116d318..250332c4afa 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -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; } } } |