diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-09-01 14:09:31 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-09-01 15:01:11 +0400 |
commit | e8f3fa99de8196a36736381b03015689492137bd (patch) | |
tree | f02e6a039cf55792053999a41220fbcbc8eaec59 /source/blender/editors | |
parent | d91916725d0d20f95c6d4c069428bd1076680087 (diff) |
Support more object types scene-scale (on creation)
- lamp
- camera
- font
- empty & effector
Also fix inconsistency with apply transform
(modified shape-keys for meshes but not curve/lattice)
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/armature/armature_add.c | 9 | ||||
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 31 | ||||
-rw-r--r-- | source/blender/editors/include/ED_armature.h | 4 | ||||
-rw-r--r-- | source/blender/editors/include/ED_curve.h | 1 | ||||
-rw-r--r-- | source/blender/editors/include/ED_lattice.h | 1 | ||||
-rw-r--r-- | source/blender/editors/include/ED_mball.h | 2 | ||||
-rw-r--r-- | source/blender/editors/include/ED_mesh.h | 1 | ||||
-rw-r--r-- | source/blender/editors/include/ED_object.h | 5 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 11 | ||||
-rw-r--r-- | source/blender/editors/metaball/mball_edit.c | 25 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 43 | ||||
-rw-r--r-- | source/blender/editors/object/object_lattice.c | 15 | ||||
-rw-r--r-- | source/blender/editors/object/object_lod.c | 7 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.c | 53 |
14 files changed, 50 insertions, 158 deletions
diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index 16975eed75e..eba1bc4d78d 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -84,7 +84,7 @@ EditBone *ED_armature_edit_bone_add(bArmature *arm, const char *name) return bone; } -void add_primitive_bone(Object *obedit_arm, bool view_aligned) +EditBone *ED_armature_edit_bone_add_primitive(Object *obedit_arm, float length, bool view_aligned) { bArmature *arm = obedit_arm->data; EditBone *bone; @@ -99,10 +99,9 @@ void add_primitive_bone(Object *obedit_arm, bool view_aligned) zero_v3(bone->head); zero_v3(bone->tail); - if (view_aligned) - bone->tail[1] = 1.0f; - else - bone->tail[2] = 1.0f; + bone->tail[view_aligned ? 1 : 2] = length; + + return bone; } diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index f3a6dfb2d35..a52b2a619dc 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1476,37 +1476,6 @@ void ED_curve_select_swap(EditNurb *editnurb, bool hide_handles) } } -/******************** transform operator **********************/ - -void ED_curve_transform(Curve *cu, float mat[4][4]) -{ - Nurb *nu; - BPoint *bp; - BezTriple *bezt; - int a; - - float scale = mat4_to_scale(mat); - - for (nu = cu->nurb.first; nu; nu = nu->next) { - if (nu->type == CU_BEZIER) { - a = nu->pntsu; - for (bezt = nu->bezt; a--; bezt++) { - mul_m4_v3(mat, bezt->vec[0]); - mul_m4_v3(mat, bezt->vec[1]); - mul_m4_v3(mat, bezt->vec[2]); - bezt->radius *= scale; - } - BKE_nurb_handles_calc(nu); - } - else { - a = nu->pntsu * nu->pntsv; - for (bp = nu->bp; a--; bp++) - mul_m4_v3(mat, bp->vec); - } - } - DAG_id_tag_update(&cu->id, 0); -} - /******************** separate operator ***********************/ static int separate_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index f6a1b493fac..6eac9f14bf6 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -133,8 +133,8 @@ EditBone *ED_armature_bone_get_mirrored(const struct ListBase *edbo, EditBone *e void ED_armature_sync_selection(struct ListBase *edbo); void ED_armature_validate_active(struct bArmature *arm); -void add_primitive_bone(struct Object *obedit_arm, bool view_aligned); -struct EditBone *ED_armature_edit_bone_add(struct bArmature *arm, const char *name); +EditBone *ED_armature_edit_bone_add_primitive(struct Object *obedit_arm, float length, bool view_aligned); +EditBone *ED_armature_edit_bone_add(struct bArmature *arm, const char *name); void ED_armature_edit_bone_remove(struct bArmature *arm, EditBone *exBone); bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebone_child); diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h index 330147db077..58e64f30b05 100644 --- a/source/blender/editors/include/ED_curve.h +++ b/source/blender/editors/include/ED_curve.h @@ -51,7 +51,6 @@ void ED_operatormacros_curve(void); void ED_keymap_curve(struct wmKeyConfig *keyconf); /* editcurve.c */ -void ED_curve_transform(struct Curve *cu, float mat[4][4]); void ED_curve_deselect_all(struct EditNurb *editnurb); void ED_curve_select_all(struct EditNurb *editnurb); void ED_curve_select_swap(struct EditNurb *editnurb, bool hide_handles); diff --git a/source/blender/editors/include/ED_lattice.h b/source/blender/editors/include/ED_lattice.h index 4d19b6d5548..6636319dc9b 100644 --- a/source/blender/editors/include/ED_lattice.h +++ b/source/blender/editors/include/ED_lattice.h @@ -37,6 +37,5 @@ struct Lattice; void free_editLatt(struct Object *ob); void make_editLatt(struct Object *obedit); void load_editLatt(struct Object *obedit); -void ED_lattice_transform(struct Lattice *lt, float mat[4][4]); #endif /* __ED_LATTICE_H__ */ diff --git a/source/blender/editors/include/ED_mball.h b/source/blender/editors/include/ED_mball.h index 680e9d79109..5e774c63841 100644 --- a/source/blender/editors/include/ED_mball.h +++ b/source/blender/editors/include/ED_mball.h @@ -50,6 +50,4 @@ void load_editMball(struct Object *obedit); void undo_push_mball(struct bContext *C, const char *name); -void ED_mball_transform(struct MetaBall *mb, float mat[4][4]); - #endif /* __ED_MBALL_H__ */ diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 4acc5279ba6..6a562da0a0e 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -264,7 +264,6 @@ void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int cou void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count); void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count); -void ED_mesh_transform(struct Mesh *me, float mat[4][4]); void ED_mesh_calc_tessface(struct Mesh *mesh); void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges, int calc_tessface); diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 5504b7e0352..2328f7d5135 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -150,8 +150,9 @@ bool ED_object_add_generic_get_opts(struct bContext *C, struct wmOperator *op, c float loc[3], float rot[3], bool *enter_editmode, unsigned int *layer, bool *is_view_aligned); -struct Object *ED_object_add_type(struct bContext *C, int type, const float loc[3], const float rot[3], - bool enter_editmode, unsigned int layer); +struct Object *ED_object_add_type( + struct bContext *C, int type, const float loc[3], const float rot[3], + bool enter_editmode, unsigned int layer) ATTR_RETURNS_NONNULL; void ED_object_single_users(struct Main *bmain, struct Scene *scene, bool full, bool copy_groups); void ED_object_single_user(struct Main *bmain, struct Scene *scene, struct Object *ob); diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 83947534d06..bf8559add6f 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -880,17 +880,6 @@ static void mesh_add_verts(Mesh *mesh, int len) mesh->totvert = totvert; } -void ED_mesh_transform(Mesh *me, float mat[4][4]) -{ - int i; - MVert *mvert = me->mvert; - - for (i = 0; i < me->totvert; i++, mvert++) - mul_m4_v3(mat, mvert->co); - - /* don't update normals, caller can do this explicitly */ -} - static void mesh_add_edges(Mesh *mesh, int len) { CustomData edata; diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index feac7f6ece3..f6a54beb8c8 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -743,28 +743,3 @@ void undo_push_mball(bContext *C, const char *name) { undo_editmode_push(C, name, get_data, free_undoMball, undoMball_to_editMball, editMball_to_undoMball, NULL); } - -void ED_mball_transform(MetaBall *mb, float mat[4][4]) -{ - MetaElem *me; - float quat[4]; - const float scale = mat4_to_scale(mat); - const float scale_sqrt = sqrtf(scale); - - mat4_to_quat(quat, mat); - - for (me = mb->elems.first; me; me = me->next) { - mul_m4_v3(mat, &me->x); - mul_qt_qtqt(me->quat, quat, me->quat); - me->rad *= scale; - /* hrmf, probably elems shouldn't be - * treating scale differently - campbell */ - if (!MB_TYPE_SIZE_SQUARED(me->type)) { - mul_v3_fl(&me->expx, scale); - } - else { - mul_v3_fl(&me->expx, scale_sqrt); - } - } - DAG_id_tag_update(&mb->id, 0); -} diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 6eb16a8a2d6..0c07f4a1288 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -96,6 +96,7 @@ #include "ED_armature.h" #include "ED_curve.h" +#include "ED_lattice.h" #include "ED_mball.h" #include "ED_mesh.h" #include "ED_node.h" @@ -447,14 +448,17 @@ Object *ED_object_add_type(bContext *C, int type, const float loc[3], const floa /* for object add operator */ static int object_add_exec(bContext *C, wmOperator *op) { + Object *ob; bool enter_editmode; unsigned int layer; float loc[3], rot[3]; + WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL)) return OPERATOR_CANCELLED; - ED_object_add_type(C, RNA_enum_get(op->ptr, "type"), loc, rot, enter_editmode, layer); + ob = ED_object_add_type(C, RNA_enum_get(op->ptr, "type"), loc, rot, enter_editmode, layer); + BKE_object_obdata_size_init(ob, RNA_float_get(op->ptr, "radius")); return OPERATOR_FINISHED; } @@ -473,6 +477,8 @@ void OBJECT_OT_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* properties */ + ED_object_add_unit_props(ot); RNA_def_enum(ot->srna, "type", object_type_items, 0, "Type", ""); ED_object_add_generic_props(ot, true); @@ -489,32 +495,31 @@ static int effector_add_exec(bContext *C, wmOperator *op) unsigned int layer; float loc[3], rot[3]; float mat[4][4]; + float dia; + WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL)) return OPERATOR_CANCELLED; type = RNA_enum_get(op->ptr, "type"); + dia = RNA_float_get(op->ptr, "radius"); if (type == PFIELD_GUIDE) { Curve *cu; ob = ED_object_add_type(C, OB_CURVE, loc, rot, false, layer); - if (!ob) - return OPERATOR_CANCELLED; rename_id(&ob->id, CTX_DATA_(BLF_I18NCONTEXT_ID_OBJECT, "CurveGuide")); cu = ob->data; cu->flag |= CU_PATH | CU_3D; ED_object_editmode_enter(C, 0); ED_object_new_primitive_matrix(C, ob, loc, rot, mat, false); - BLI_addtail(&cu->editnurb->nurbs, add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, 1)); + BLI_addtail(&cu->editnurb->nurbs, add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, dia)); if (!enter_editmode) ED_object_editmode_exit(C, EM_FREEDATA); } else { ob = ED_object_add_type(C, OB_EMPTY, loc, rot, false, layer); - if (!ob) - return OPERATOR_CANCELLED; - + BKE_object_obdata_size_init(ob, dia); rename_id(&ob->id, CTX_DATA_(BLF_I18NCONTEXT_ID_OBJECT, "Field")); if (ELEM(type, PFIELD_WIND, PFIELD_VORTEX)) ob->empty_drawtype = OB_SINGLE_ARROW; @@ -541,8 +546,10 @@ void OBJECT_OT_effector_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", field_type_items, 0, "Type", ""); + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -673,6 +680,7 @@ static int object_add_text_exec(bContext *C, wmOperator *op) unsigned int layer; float loc[3], rot[3]; + WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL)) return OPERATOR_CANCELLED; @@ -680,6 +688,7 @@ static int object_add_text_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; obedit = ED_object_add_type(C, OB_FONT, loc, rot, enter_editmode, layer); + BKE_object_obdata_size_init(obedit, RNA_float_get(op->ptr, "radius")); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); @@ -699,6 +708,9 @@ void OBJECT_OT_text_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -711,9 +723,10 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) bool newob = false; bool enter_editmode; unsigned int layer; - float loc[3], rot[3]; + float loc[3], rot[3], dia; bool view_aligned = rv3d && (U.flag & USER_ADD_VIEWALIGNED); + WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL)) return OPERATOR_CANCELLED; @@ -731,7 +744,8 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - add_primitive_bone(obedit, view_aligned); + dia = RNA_float_get(op->ptr, "radius"); + ED_armature_edit_bone_add_primitive(obedit, dia, view_aligned); /* userdef */ if (newob && !enter_editmode) @@ -755,6 +769,9 @@ void OBJECT_OT_armature_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); } @@ -767,12 +784,14 @@ static int object_empty_add_exec(bContext *C, wmOperator *op) unsigned int layer; float loc[3], rot[3]; + WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, &layer, NULL)) return OPERATOR_CANCELLED; ob = ED_object_add_type(C, OB_EMPTY, loc, rot, false, layer); BKE_object_empty_draw_type_set(ob, type); + BKE_object_obdata_size_init(ob, RNA_float_get(op->ptr, "radius")); return OPERATOR_FINISHED; } @@ -795,6 +814,7 @@ void OBJECT_OT_empty_add(wmOperatorType *ot) /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", object_empty_drawtype_items, 0, "Type", ""); + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, false); } @@ -904,12 +924,14 @@ static int object_lamp_add_exec(bContext *C, wmOperator *op) unsigned int layer; float loc[3], rot[3]; + WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, &layer, NULL)) return OPERATOR_CANCELLED; ob = ED_object_add_type(C, OB_LAMP, loc, rot, false, layer); - la = (Lamp *)ob->data; + BKE_object_obdata_size_init(ob, RNA_float_get(op->ptr, "radius")); + la = (Lamp *)ob->data; la->type = type; rename_id(&ob->id, get_lamp_defname(type)); rename_id(&la->id, get_lamp_defname(type)); @@ -941,6 +963,7 @@ void OBJECT_OT_lamp_add(wmOperatorType *ot) ot->prop = RNA_def_enum(ot->srna, "type", lamp_type_items, 0, "Type", ""); RNA_def_property_translation_context(ot->prop, BLF_I18NCONTEXT_ID_LAMP); + ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, false); } diff --git a/source/blender/editors/object/object_lattice.c b/source/blender/editors/object/object_lattice.c index 3897e452d0d..c24a127ed8b 100644 --- a/source/blender/editors/object/object_lattice.c +++ b/source/blender/editors/object/object_lattice.c @@ -174,21 +174,6 @@ void load_editLatt(Object *obedit) } } -/*************************** Transform Operator ************************/ - -void ED_lattice_transform(Lattice *lt, float mat[4][4]) -{ - BPoint *bp = lt->def; - int a = lt->pntsu * lt->pntsv * lt->pntsw; - - while (a--) { - mul_m4_v3(mat, bp->vec); - bp++; - } - - DAG_id_tag_update(<->id, 0); -} - static void bpoint_select_set(BPoint *bp, bool select) { if (select) { diff --git a/source/blender/editors/object/object_lod.c b/source/blender/editors/object/object_lod.c index 8bcbba6be96..48e980015a7 100644 --- a/source/blender/editors/object/object_lod.c +++ b/source/blender/editors/object/object_lod.c @@ -29,15 +29,11 @@ * \ingroup edobj */ - #include "DNA_object_types.h" #include "BKE_context.h" #include "BKE_object.h" -#include "ED_screen.h" -#include "ED_object.h" - #include "WM_api.h" #include "WM_types.h" @@ -45,6 +41,9 @@ #include "RNA_define.h" #include "RNA_enum_types.h" +#include "ED_screen.h" +#include "ED_object.h" + #include "object_intern.h" static int object_lod_add_exec(bContext *C, wmOperator *UNUSED(op)) diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index e2ebe583ecf..a1b8478a0e1 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -472,27 +472,12 @@ static int apply_objects_internal(bContext *C, ReportList *reports, bool apply_l /* apply to object data */ if (ob->type == OB_MESH) { Mesh *me = ob->data; - MVert *mvert; - int a; if (apply_scale) multiresModifier_scale_disp(scene, ob); /* adjust data */ - mvert = me->mvert; - for (a = 0; a < me->totvert; a++, mvert++) - mul_m4_v3(mat, mvert->co); - - if (me->key) { - KeyBlock *kb; - - for (kb = me->key->block.first; kb; kb = kb->next) { - float *fp = kb->data; - - for (a = 0; a < kb->totelem; a++, fp += 3) - mul_m4_v3(mat, fp); - } - } + BKE_mesh_transform(me, mat, true); /* update normals */ BKE_mesh_calc_normals(me); @@ -502,45 +487,17 @@ static int apply_objects_internal(bContext *C, ReportList *reports, bool apply_l } else if (ob->type == OB_LATTICE) { Lattice *lt = ob->data; - BPoint *bp = lt->def; - int a = lt->pntsu * lt->pntsv * lt->pntsw; - - while (a--) { - mul_m4_v3(mat, bp->vec); - bp++; - } + + BKE_lattice_transform(lt, mat, true); } else if (ob->type == OB_MBALL) { MetaBall *mb = ob->data; - ED_mball_transform(mb, mat); + BKE_mball_transform(mb, mat); } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = ob->data; - - Nurb *nu; - BPoint *bp; - BezTriple *bezt; - int a; - scale = mat3_to_scale(rsmat); - - for (nu = cu->nurb.first; nu; nu = nu->next) { - if (nu->type == CU_BEZIER) { - a = nu->pntsu; - for (bezt = nu->bezt; a--; bezt++) { - mul_m4_v3(mat, bezt->vec[0]); - mul_m4_v3(mat, bezt->vec[1]); - mul_m4_v3(mat, bezt->vec[2]); - bezt->radius *= scale; - } - BKE_nurb_handles_calc(nu); - } - else { - a = nu->pntsu * nu->pntsv; - for (bp = nu->bp; a--; bp++) - mul_m4_v3(mat, bp->vec); - } - } + BKE_curve_transform_ex(cu, mat, true, scale); } else if (ob->type == OB_CAMERA) { MovieClip *clip = BKE_object_movieclip_get(scene, ob, false); |