diff options
author | Matt Ebb <matt@mke3.net> | 2010-01-12 04:50:34 +0300 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-01-12 04:50:34 +0300 |
commit | e6c61acb68927519d869d150444e1a58798976d3 (patch) | |
tree | e45a8f5180cb09235916dbd9f4e5bdd0755cf999 /source/blender | |
parent | 44068d96aa16f7561dfec224776bb16b7f694551 (diff) |
Fix [#20644] new curve sets itself to the origin, but the pivot to the cursor
+ Cleaned up the nurbs spin operator and gave it properties rather than
relying on context
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 173 | ||||
-rw-r--r-- | source/blender/editors/include/ED_curve.h | 2 | ||||
-rw-r--r-- | source/blender/editors/include/ED_mball.h | 2 | ||||
-rw-r--r-- | source/blender/editors/include/ED_object.h | 1 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_add.c | 32 | ||||
-rw-r--r-- | source/blender/editors/metaball/mball_edit.c | 37 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 49 |
7 files changed, 118 insertions, 178 deletions
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 20aece9a5fc..f61596f397f 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -3202,45 +3202,25 @@ int mouse_nurb(bContext *C, short mval[2], int extend) * orientation of the global 3d view (yuck yuck!) mode==1 does the same, but doesn't bridge up * up the new geometry, mode==2 now does the same as 0, but aligned to world axes, not the view. */ -static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, short mode) +static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, float *cent, short mode) { ListBase *editnurb= curve_get_editcurve(obedit); - View3D *v3d= CTX_wm_view3d(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); Nurb *nu; - float *curs, si,phi,n[3],q[4],cmat[3][3],tmat[3][3],imat[3][3]; - float cent[3],bmat[3][3], rotmat[3][3], scalemat1[3][3], scalemat2[3][3]; + float si,phi,n[3],q[4],cmat[3][3],tmat[3][3],imat[3][3]; + float bmat[3][3], rotmat[3][3], scalemat1[3][3], scalemat2[3][3]; float persmat[3][3], persinv[3][3]; short a,ok, changed= 0; - if(mode != 2 && rv3d) copy_m3_m4(persmat, rv3d->viewmat); - else unit_m3(persmat); + unit_m3(persmat); invert_m3_m3(persinv, persmat); /* imat and center and size */ copy_m3_m4(bmat, obedit->obmat); invert_m3_m3(imat, bmat); - if(v3d) { - curs= give_cursor(scene, v3d); - VECCOPY(cent, curs); - } - else - cent[0]= cent[1]= cent[2]= 0.0f; - - sub_v3_v3v3(cent, cent, obedit->obmat[3]); - mul_m3_v3(imat,cent); - - if(dvec || mode==2 || !rv3d) { - n[0]=n[1]= 0.0; - n[2]= 1.0; - } else { - n[0]= rv3d->viewinv[2][0]; - n[1]= rv3d->viewinv[2][1]; - n[2]= rv3d->viewinv[2][2]; - normalize_v3(n); - } - + n[0]=n[1]= 0.0; + n[2]= 1.0; + phi= M_PI/8.0; q[0]= cos(phi); si= sin(phi); @@ -3315,8 +3295,12 @@ static int spin_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); - - if(!spin_nurb(C, scene, obedit, 0, 0)) { + float cent[3], axis[3]; + + RNA_float_get_array(op->ptr, "center", cent); + RNA_float_get_array(op->ptr, "axis", axis); + + if(!spin_nurb(C, scene, obedit, axis, cent, 0)) { BKE_report(op->reports, RPT_ERROR, "Can't spin"); return OPERATOR_CANCELLED; } @@ -3327,6 +3311,18 @@ static int spin_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int spin_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + Scene *scene = CTX_data_scene(C); + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d= ED_view3d_context_rv3d(C); + + RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d)); + RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]); + + return spin_exec(C, op); +} + void CURVE_OT_spin(wmOperatorType *ot) { /* identifiers */ @@ -3335,10 +3331,14 @@ void CURVE_OT_spin(wmOperatorType *ot) /* api callbacks */ ot->exec= spin_exec; + ot->invoke = spin_invoke; ot->poll= ED_operator_editsurf; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX); + RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX); } /***************** add vertex operator **********************/ @@ -4734,19 +4734,18 @@ int join_curve_exec(bContext *C, wmOperator *op) /************ add primitive, used by object/ module ****************/ -Nurb *add_nurbs_primitive(bContext *C, int type, int newname) +Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) { static int xzproj= 0; /* this function calls itself... */ Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); ListBase *editnurb= curve_get_editcurve(obedit); View3D *v3d= CTX_wm_view3d(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); Nurb *nu = NULL; BezTriple *bezt; BPoint *bp; - float *curs, cent[3],vec[3],imat[3][3],mat[3][3]; - float fac,cmat[3][3], grid; + float vec[3]; + float fac, grid; int a, b, cutype, stype; int force_3d = ((Curve *)obedit->data)->flag & CU_3D; /* could be adding to an existing 3D curve */ @@ -4756,38 +4755,8 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) if (v3d) grid = v3d->grid; else grid = 1.0; - /* imat and center and size */ - if(obedit) { - - copy_m3_m4(mat, obedit->obmat); - if(v3d) { - curs= give_cursor(scene, v3d); - VECCOPY(cent, curs); - } - else - cent[0]= cent[1]= cent[2]= 0.0f; - - cent[0]-= obedit->obmat[3][0]; - cent[1]-= obedit->obmat[3][1]; - cent[2]-= obedit->obmat[3][2]; - - if(rv3d) { - if (!newname && (U.flag & USER_ADD_VIEWALIGNED)) - copy_m3_m4(imat, rv3d->viewmat); - else - unit_m3(imat); - - mul_m3_v3(imat, cent); - mul_m3_m3m3(cmat, imat, mat); - invert_m3_m3(imat, cmat); - } - else - unit_m3(imat); - setflagsNurb(editnurb, 0); - } - else - return NULL; + setflagsNurb(editnurb, 0); /* these types call this function to return a Nurb */ if (stype!=CU_PRIM_TUBE && stype!=CU_PRIM_DONUT) { @@ -4814,26 +4783,25 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->radius = 1.0; - for(a=0;a<3;a++) { - VECCOPY(bezt->vec[a], cent); - } bezt->vec[1][0]+= -grid; bezt->vec[0][0]+= -1.5*grid; bezt->vec[0][1]+= -0.5*grid; bezt->vec[2][0]+= -0.5*grid; bezt->vec[2][1]+= 0.5*grid; - for(a=0;a<3;a++) mul_m3_v3(imat, bezt->vec[a]); + for(a=0;a<3;a++) mul_m4_v3(mat, bezt->vec[a]); bezt++; bezt->h1= bezt->h2= HD_ALIGN; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->radius = bezt->weight = 1.0; - for(a=0;a<3;a++) { - VECCOPY(bezt->vec[a], cent); - } - bezt->vec[1][0]+= grid; - for(a=0;a<3;a++) mul_m3_v3(imat, bezt->vec[a]); + bezt->vec[0][0] = 0; + bezt->vec[0][1] = 0; + bezt->vec[1][0] = grid; + bezt->vec[1][1] = 0; + bezt->vec[2][0] = grid*2; + bezt->vec[2][1] = 0; + for(a=0;a<3;a++) mul_m4_v3(mat, bezt->vec[a]); calchandlesNurb(nu); } @@ -4846,7 +4814,6 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bp= nu->bp; for(a=0;a<4;a++, bp++) { - VECCOPY(bp->vec, cent); bp->vec[3]= 1.0; bp->f1= SELECT; bp->radius = bp->weight = 1.0; @@ -4864,7 +4831,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bp->vec[0]+= 1.5*grid; bp= nu->bp; - for(a=0;a<4;a++, bp++) mul_m3_v3(imat,bp->vec); + for(a=0;a<4;a++, bp++) mul_m4_v3(mat,bp->vec); if(cutype==CU_NURBS) { nu->knotsu= 0; /* makeknots allocates */ @@ -4883,7 +4850,6 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bp= nu->bp; for(a=0;a<5;a++, bp++) { - VECCOPY(bp->vec, cent); bp->vec[3]= 1.0; bp->f1= SELECT; bp->radius = bp->weight = 1.0; @@ -4899,7 +4865,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bp->vec[0]+= 2.0*grid; bp= nu->bp; - for(a=0;a<5;a++, bp++) mul_m3_v3(imat,bp->vec); + for(a=0;a<5;a++, bp++) mul_m4_v3(mat,bp->vec); if(cutype==CU_NURBS) { nu->knotsu= 0; /* makeknots allocates */ @@ -4920,43 +4886,31 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) nu->flagu= CU_CYCLIC; bezt= nu->bezt; - for(a=0;a<3;a++) { - VECCOPY(bezt->vec[a], cent); - } bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][0]+= -grid; - for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m4_v3(mat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; bezt++; - for(a=0;a<3;a++) { - VECCOPY(bezt->vec[a], cent); - } bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][1]+= grid; - for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m4_v3(mat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; bezt++; - for(a=0;a<3;a++) { - VECCOPY(bezt->vec[a], cent); - } bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][0]+= grid; - for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m4_v3(mat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; bezt++; - for(a=0;a<3;a++) { - VECCOPY(bezt->vec[a], cent); - } bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][1]+= -grid; - for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m4_v3(mat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; calchandlesNurb(nu); @@ -4971,8 +4925,6 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) for(a=0; a<8; a++) { bp->f1= SELECT; - VECCOPY(bp->vec, cent); - if(xzproj==0) { bp->vec[0]+= nurbcircle[a][0]*grid; bp->vec[1]+= nurbcircle[a][1]*grid; @@ -4983,7 +4935,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) } if(a & 1) bp->vec[3]= 0.25*sqrt(2.0); else bp->vec[3]= 1.0; - mul_m3_v3(imat,bp->vec); + mul_m4_v3(mat,bp->vec); bp->radius = bp->weight = 1.0; bp++; @@ -5011,7 +4963,6 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) for(a=0; a<4; a++) { for(b=0; b<4; b++) { - VECCOPY(bp->vec, cent); bp->f1= SELECT; fac= (float)a -1.5; bp->vec[0]+= fac*grid; @@ -5020,7 +4971,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) if(a==1 || a==2) if(b==1 || b==2) { bp->vec[2]+= grid; } - mul_m3_v3(imat,bp->vec); + mul_m4_v3(mat,bp->vec); bp->vec[3]= 1.0; bp++; } @@ -5032,18 +4983,19 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) break; case CU_PRIM_TUBE: /* tube */ if( cutype==CU_NURBS ) { + if(newname) { rename_id((ID *)obedit, "SurfTube"); rename_id((ID *)obedit->data, "SurfTube"); } - - nu= add_nurbs_primitive(C, CU_NURBS|CU_PRIM_CIRCLE, 0); /* circle */ + + nu= add_nurbs_primitive(C, mat, CU_NURBS|CU_PRIM_CIRCLE, 0); /* circle */ nu->resolu= 4; nu->flag= CU_SMOOTH; BLI_addtail(editnurb, nu); /* temporal for extrude and translate */ vec[0]=vec[1]= 0.0; vec[2]= -grid; - mul_m3_v3(imat, vec); + translateflagNurb(editnurb, 1, vec); extrudeflagNurb(editnurb, 1); vec[0]= -2*vec[0]; @@ -5063,6 +5015,9 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) break; case CU_PRIM_SPHERE: /* sphere */ if( cutype==CU_NURBS ) { + float tmp_cent[3] = {0.f, 0.f, 0.f}; + float tmp_vec[3] = {0.f, 0.f, 0.f}; + if(newname) { rename_id((ID *)obedit, "SurfSphere"); rename_id((ID *)obedit->data, "SurfSphere"); @@ -5080,12 +5035,11 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) for(a=0; a<5; a++) { bp->f1= SELECT; - VECCOPY(bp->vec, cent); bp->vec[0]+= nurbcircle[a][0]*grid; bp->vec[2]+= nurbcircle[a][1]*grid; if(a & 1) bp->vec[3]= 0.5*sqrt(2.0); else bp->vec[3]= 1.0; - mul_m3_v3(imat,bp->vec); + mul_m4_v3(mat,bp->vec); bp++; } nu->flagu= 4; @@ -5093,9 +5047,9 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) BLI_addtail(editnurb, nu); /* temporal for spin */ if(newname && (U.flag & USER_ADD_VIEWALIGNED) == 0) - spin_nurb(C, scene, obedit, 0, 2); + spin_nurb(C, scene, obedit, tmp_vec, tmp_cent, 2); else - spin_nurb(C, scene, obedit, 0, 0); + spin_nurb(C, scene, obedit, tmp_vec, mat[3], 2); makeknots(nu, 2); @@ -5110,22 +5064,25 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) break; case CU_PRIM_DONUT: /* donut */ if( cutype==CU_NURBS ) { + float tmp_cent[3] = {0.f, 0.f, 0.f}; + float tmp_vec[3] = {0.f, 0.f, 0.f}; + if(newname) { rename_id((ID *)obedit, "SurfDonut"); rename_id((ID *)obedit->data, "SurfDonut"); } xzproj= 1; - nu= add_nurbs_primitive(C, CU_NURBS|CU_PRIM_CIRCLE, 0); /* circle */ + nu= add_nurbs_primitive(C, mat, CU_NURBS|CU_PRIM_CIRCLE, 0); /* circle */ xzproj= 0; nu->resolu= 4; nu->resolv= 4; nu->flag= CU_SMOOTH; BLI_addtail(editnurb, nu); /* temporal for extrude and translate */ if(newname && (U.flag & USER_ADD_VIEWALIGNED) == 0) - spin_nurb(C, scene, obedit, 0, 2); + spin_nurb(C, scene, obedit, tmp_vec, tmp_cent, 2); else - spin_nurb(C, scene, obedit, 0, 0); + spin_nurb(C, scene, obedit, tmp_vec, mat[3], 2); BLI_remlink(editnurb, nu); diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h index 0cfa743b0fa..e6bb178c90a 100644 --- a/source/blender/editors/include/ED_curve.h +++ b/source/blender/editors/include/ED_curve.h @@ -57,7 +57,7 @@ void free_editNurb (struct Object *obedit); int mouse_nurb (struct bContext *C, short mval[2], int extend); -struct Nurb *add_nurbs_primitive(struct bContext *C, int type, int newname); +struct Nurb *add_nurbs_primitive(struct bContext *C, float mat[4][4], int type, int newname); int isNurbsel (struct Nurb *nu);; diff --git a/source/blender/editors/include/ED_mball.h b/source/blender/editors/include/ED_mball.h index b21bcb0cc09..bc4b79ad176 100644 --- a/source/blender/editors/include/ED_mball.h +++ b/source/blender/editors/include/ED_mball.h @@ -33,7 +33,7 @@ struct wmKeyConfig; void ED_operatortypes_metaball(void); void ED_keymap_metaball(struct wmKeyConfig *keyconf); -struct MetaElem *add_metaball_primitive(struct bContext *C, int type, int newname); +struct MetaElem *add_metaball_primitive(struct bContext *C, float mat[4][4], int type, int newname); int mouse_mball(struct bContext *C, short mval[2], int extend); diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 4e3fed6b9f8..91b297b7581 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -82,6 +82,7 @@ void ED_object_enter_editmode(struct bContext *C, int flag); void ED_object_location_from_view(struct bContext *C, float *loc); void ED_object_rotation_from_view(struct bContext *C, float *rot); void ED_object_base_init_transform(struct bContext *C, struct Base *base, float *loc, float *rot); +float ED_object_new_primitive_matrix(struct bContext *C, float *loc, float *rot, float primmat[][4]); void ED_object_add_generic_props(struct wmOperatorType *ot, int do_editmode); int ED_object_add_generic_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event); diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 572cf214c6a..3a80d7c69bb 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -1270,36 +1270,6 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se BKE_mesh_end_editmesh(obedit->data, em); } - -/* uses context to figure out transform for primitive */ -/* returns standard diameter */ -static float new_primitive_matrix(bContext *C, float *loc, float *rot, float primmat[][4]) -{ - Object *obedit= CTX_data_edit_object(C); - View3D *v3d =CTX_wm_view3d(C); - float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3]; - - unit_m4(primmat); - - eul_to_mat3(rmat, rot); - invert_m3(rmat); - - /* inverse transform for initial rotation and object */ - copy_m3_m4(mat, obedit->obmat); - mul_m3_m3m3(cmat, rmat, mat); - invert_m3_m3(imat, cmat); - copy_m4_m3(primmat, imat); - - /* center */ - VECCOPY(primmat[3], loc); - VECSUB(primmat[3], primmat[3], obedit->obmat[3]); - invert_m3_m3(imat, mat); - mul_m3_v3(imat, primmat[3]); - - if(v3d) return v3d->grid; - return 1.0f; -} - /* ********* add primitive operators ************* */ static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmode, @@ -1319,7 +1289,7 @@ static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmod } else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); - dia *= new_primitive_matrix(C, loc, rot, mat); + dia *= ED_object_new_primitive_matrix(C, loc, rot, mat); make_prim(obedit, type, mat, tot, seg, subdiv, dia, depth, ext, fill); diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index d8e36a503f1..c3afbe0d9e7 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -97,15 +97,11 @@ void load_editMball(Object *obedit) } /* Add metaelem primitive to metaball object (which is in edit mode) */ -MetaElem *add_metaball_primitive(bContext *C, int type, int newname) +MetaElem *add_metaball_primitive(bContext *C, float mat[4][4], int type, int newname) { - Scene *scene= CTX_data_scene(C); - View3D *v3d= CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); Object *obedit= CTX_data_edit_object(C); MetaBall *mball = (MetaBall*)obedit->data; MetaElem *ml; - float *curs, mat[3][3], cent[3], imat[3][3], cmat[3][3]; if(!obedit) return NULL; @@ -116,36 +112,11 @@ MetaElem *add_metaball_primitive(bContext *C, int type, int newname) ml= ml->next; } - copy_m3_m4(mat, obedit->obmat); - if(v3d) { - curs= give_cursor(scene, v3d); - VECCOPY(cent, curs); - } - else - cent[0]= cent[1]= cent[2]= 0.0f; - - cent[0]-= obedit->obmat[3][0]; - cent[1]-= obedit->obmat[3][1]; - cent[2]-= obedit->obmat[3][2]; - - if (rv3d) { - if (!(newname) || U.flag & USER_ADD_VIEWALIGNED) - copy_m3_m4(imat, rv3d->viewmat); - else - unit_m3(imat); - mul_m3_v3(imat, cent); - mul_m3_m3m3(cmat, imat, mat); - invert_m3_m3(imat,cmat); - mul_m3_v3(imat, cent); - } - else - unit_m3(imat); - ml= MEM_callocN(sizeof(MetaElem), "metaelem"); - ml->x= cent[0]; - ml->y= cent[1]; - ml->z= cent[2]; + ml->x= mat[3][0]; + ml->y= mat[3][1]; + ml->z= mat[3][2]; ml->quat[0]= 1.0; ml->quat[1]= 0.0; ml->quat[2]= 0.0; diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 28ddf07fe8e..9740a1cba01 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -143,6 +143,35 @@ void ED_object_base_init_transform(bContext *C, Base *base, float *loc, float *r where_is_object(scene, ob); } +/* uses context to figure out transform for primitive */ +/* returns standard diameter */ +float ED_object_new_primitive_matrix(bContext *C, float *loc, float *rot, float primmat[][4]) +{ + Object *obedit= CTX_data_edit_object(C); + View3D *v3d =CTX_wm_view3d(C); + float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3]; + + unit_m4(primmat); + + eul_to_mat3(rmat, rot); + invert_m3(rmat); + + /* inverse transform for initial rotation and object */ + copy_m3_m4(mat, obedit->obmat); + mul_m3_m3m3(cmat, rmat, mat); + invert_m3_m3(imat, cmat); + copy_m4_m3(primmat, imat); + + /* center */ + VECCOPY(primmat[3], loc); + VECSUB(primmat[3], primmat[3], obedit->obmat[3]); + invert_m3_m3(imat, mat); + mul_m3_v3(imat, primmat[3]); + + if(v3d) return v3d->grid; + return 1.0f; +} + /********************* Add Object Operator ********************/ void add_object_draw(Scene *scene, View3D *v3d, int type) /* for toolbox or menus, only non-editmode stuff */ @@ -297,6 +326,7 @@ static Object *effector_add_type(bContext *C, wmOperator *op, int type) Object *ob; int enter_editmode; float loc[3], rot[3]; + float mat[4][4]; object_add_generic_invoke_options(C, op); ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); @@ -307,7 +337,8 @@ static Object *effector_add_type(bContext *C, wmOperator *op, int type) ((Curve*)ob->data)->flag |= CU_PATH|CU_3D; ED_object_enter_editmode(C, 0); - BLI_addtail(curve_get_editcurve(ob), add_nurbs_primitive(C, CU_NURBS|CU_PRIM_PATH, 1)); + ED_object_new_primitive_matrix(C, loc, rot, mat); + BLI_addtail(curve_get_editcurve(ob), add_nurbs_primitive(C, mat, CU_NURBS|CU_PRIM_PATH, 1)); if(!enter_editmode) ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO); @@ -424,6 +455,7 @@ static int object_add_curve_exec(bContext *C, wmOperator *op) int newob= 0, type= RNA_enum_get(op->ptr, "type"); int enter_editmode; float loc[3], rot[3]; + float mat[4][4]; object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); @@ -437,7 +469,9 @@ static int object_add_curve_exec(bContext *C, wmOperator *op) } else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); - nu= add_nurbs_primitive(C, type, newob); + ED_object_new_primitive_matrix(C, loc, rot, mat); + + nu= add_nurbs_primitive(C, mat, type, newob); editnurb= curve_get_editcurve(obedit); BLI_addtail(editnurb, nu); @@ -509,6 +543,7 @@ static int object_add_surface_exec(bContext *C, wmOperator *op) int newob= 0; int enter_editmode; float loc[3], rot[3]; + float mat[4][4]; object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); @@ -519,7 +554,9 @@ static int object_add_surface_exec(bContext *C, wmOperator *op) } else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); - nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob); + ED_object_new_primitive_matrix(C, loc, rot, mat); + + nu= add_nurbs_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob); editnurb= curve_get_editcurve(obedit); BLI_addtail(editnurb, nu); @@ -570,6 +607,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) int newob= 0; int enter_editmode; float loc[3], rot[3]; + float mat[4][4]; object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); @@ -580,7 +618,9 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) } else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); - elem= (MetaElem*)add_metaball_primitive(C, RNA_enum_get(op->ptr, "type"), newob); + ED_object_new_primitive_matrix(C, loc, rot, mat); + + elem= (MetaElem*)add_metaball_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob); mball= (MetaBall*)obedit->data; BLI_addtail(mball->editelems, elem); @@ -732,6 +772,7 @@ static int object_lamp_add_exec(bContext *C, wmOperator *op) int enter_editmode; float loc[3], rot[3]; + object_add_generic_invoke_options(C, op); ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); ob= ED_object_add_type(C, OB_LAMP, loc, rot, FALSE); |