diff options
-rw-r--r-- | source/blender/editors/include/ED_object.h | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_add.c | 49 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 96 |
3 files changed, 102 insertions, 47 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index aa6914ab0ad..334c700ba20 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -86,8 +86,8 @@ float ED_object_new_primitive_matrix(struct bContext *C, float *loc, float *rot, 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); -void ED_object_add_generic_get_opts(struct wmOperator *op, float *loc, float *rot, int *enter_editmode); -struct Object *ED_object_add_type(struct bContext *C, int type, float *loc, float *rot, int enter_editmode); +void ED_object_add_generic_get_opts(struct wmOperator *op, float *loc, float *rot, int *enter_editmode, unsigned int *layer); +struct Object *ED_object_add_type(struct bContext *C, int type, float *loc, float *rot, int enter_editmode, unsigned int layer); void ED_object_single_users(struct Scene *scene, int full); diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index d6b4b43c569..1f815aa18fa 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -1272,7 +1272,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se /* ********* add primitive operators ************* */ -static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmode, +static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmode, unsigned int layer, int type, int tot, int seg, int subdiv, float dia, float depth, int ext, int fill) { @@ -1281,7 +1281,7 @@ static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmod float mat[4][4]; if(obedit==NULL || obedit->type!=OB_MESH) { - obedit= ED_object_add_type(C, OB_MESH, loc, rot, FALSE); + obedit= ED_object_add_type(C, OB_MESH, loc, rot, FALSE, layer); /* create editmode */ ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */ @@ -1307,12 +1307,13 @@ static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmod static int add_primitive_plane_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */ - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_PLANE, 4, 0, 0, sqrt(2.0f), 0.0f, 0, 1); return OPERATOR_FINISHED; } @@ -1338,12 +1339,13 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) static int add_primitive_cube_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */ - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_CUBE, 4, 0, 0, sqrt(2.0f), 1.0f, 1, 1); return OPERATOR_FINISHED; } @@ -1369,11 +1371,12 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot) static int add_primitive_circle_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_CIRCLE, RNA_int_get(op->ptr, "vertices"), 0, 0, RNA_float_get(op->ptr,"radius"), 0.0f, 0, RNA_boolean_get(op->ptr, "fill")); @@ -1407,11 +1410,12 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) static int add_primitive_tube_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0, RNA_float_get(op->ptr,"radius"), RNA_float_get(op->ptr, "depth"), 1, @@ -1447,11 +1451,12 @@ void MESH_OT_primitive_tube_add(wmOperatorType *ot) static int add_primitive_cone_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_CONE, RNA_int_get(op->ptr, "vertices"), 0, 0, RNA_float_get(op->ptr,"radius"), RNA_float_get(op->ptr, "depth"), 0, RNA_boolean_get(op->ptr, "cap_end")); @@ -1486,11 +1491,12 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot) static int add_primitive_grid_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_GRID, RNA_int_get(op->ptr, "x_subdivisions"), RNA_int_get(op->ptr, "y_subdivisions"), 0, RNA_float_get(op->ptr,"size"), 0.0f, 0, 1); @@ -1524,11 +1530,12 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) static int add_primitive_monkey_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_MONKEY, 0, 0, 2, 0.0f, 0.0f, 0, 0); return OPERATOR_FINISHED; @@ -1555,11 +1562,12 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_UVSPHERE, RNA_int_get(op->ptr, "rings"), RNA_int_get(op->ptr, "segments"), 0, RNA_float_get(op->ptr,"size"), 0.0f, 0, 0); @@ -1593,11 +1601,12 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - make_prim_ext(C, loc, rot, enter_editmode, + make_prim_ext(C, loc, rot, enter_editmode, layer, PRIM_ICOSPHERE, 0, 0, RNA_int_get(op->ptr, "subdivisions"), RNA_float_get(op->ptr,"size"), 0.0f, 0, 0); diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 11ce7ec02fd..8a3c7c373ee 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -181,6 +181,7 @@ void add_object_draw(Scene *scene, View3D *v3d, int type) /* for toolbox or menu void ED_object_add_generic_props(wmOperatorType *ot, int do_editmode) { + PropertyRNA *prop; RNA_def_boolean(ot->srna, "view_align", 0, "Align to View", "Align the new object to the view."); if(do_editmode) @@ -188,6 +189,9 @@ void ED_object_add_generic_props(wmOperatorType *ot, int do_editmode) RNA_def_float_vector(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Location for the newly added object.", -FLT_MAX, FLT_MAX); RNA_def_float_rotation(ot->srna, "rotation", 3, NULL, -FLT_MAX, FLT_MAX, "Rotation", "Rotation for the newly added object", -FLT_MAX, FLT_MAX); + + prop = RNA_def_boolean_layer_member(ot->srna, "layer", 32, NULL, "Layer", ""); + RNA_def_property_flag(prop, PROP_HIDDEN); } static void object_add_generic_invoke_options(bContext *C, wmOperator *op) @@ -218,7 +222,30 @@ static void object_add_generic_invoke_options(bContext *C, wmOperator *op) RNA_float_set_array(op->ptr, "rotation", rot); } - + + if (!RNA_property_is_set(op->ptr, "layer")) { + View3D *v3d = CTX_wm_view3d(C); + Scene *scene = CTX_data_scene(C); + int a, values[32], layer; + + if (v3d) { + if (v3d->localvd) { + layer = v3d->layact + v3d->lay; + for(a=0; a<32; a++) + values[a]= (layer & (1<<a)); + } else { + layer = v3d->layact; + for(a=0; a<32; a++) + values[a]= (layer & (1<<a)); + } + } else { + layer = scene->lay; + for(a=0; a<32; a++) + values[a]= (layer & (1<<a)); + } + + RNA_boolean_set_array(op->ptr, "layer", values); + } } int ED_object_add_generic_invoke(bContext *C, wmOperator *op, wmEvent *event) @@ -227,20 +254,28 @@ int ED_object_add_generic_invoke(bContext *C, wmOperator *op, wmEvent *event) return op->type->exec(C, op); } -void ED_object_add_generic_get_opts(wmOperator *op, float *loc, float *rot, int *enter_editmode) +void ED_object_add_generic_get_opts(wmOperator *op, float *loc, float *rot, int *enter_editmode, unsigned int *layer) { + int a, layer_values[32]; + *enter_editmode = FALSE; - if(RNA_struct_find_property(op->ptr, "enter_editmode") && RNA_boolean_get(op->ptr, "enter_editmode")) { *enter_editmode = TRUE; } RNA_float_get_array(op->ptr, "location", loc); RNA_float_get_array(op->ptr, "rotation", rot); + RNA_boolean_get_array(op->ptr, "layer", layer_values); + + for(a=0; a<32; a++) + if(layer_values[a]) + *layer |= (1 << a); + else + *layer &= ~(1 << a); } /* for object add primitive operators */ -Object *ED_object_add_type(bContext *C, int type, float *loc, float *rot, int enter_editmode) +Object *ED_object_add_type(bContext *C, int type, float *loc, float *rot, int enter_editmode, unsigned int layer) { Scene *scene= CTX_data_scene(C); Object *ob; @@ -251,6 +286,7 @@ Object *ED_object_add_type(bContext *C, int type, float *loc, float *rot, int en /* deselects all, sets scene->basact */ ob= add_object(scene, type); + BASACT->lay = ob->lay = layer; /* editor level activate, notifiers */ ED_base_object_activate(C, BASACT); @@ -269,10 +305,11 @@ Object *ED_object_add_type(bContext *C, int type, float *loc, float *rot, int en static int object_add_exec(bContext *C, wmOperator *op) { int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); - ED_object_add_type(C, RNA_enum_get(op->ptr, "type"), loc, rot, enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); + ED_object_add_type(C, RNA_enum_get(op->ptr, "type"), loc, rot, enter_editmode, layer); return OPERATOR_FINISHED; } @@ -325,14 +362,15 @@ static Object *effector_add_type(bContext *C, wmOperator *op, int type) { Object *ob; int enter_editmode; + unsigned int layer; 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); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); if(type==PFIELD_GUIDE) { - ob= ED_object_add_type(C, OB_CURVE, loc, rot, FALSE); + ob= ED_object_add_type(C, OB_CURVE, loc, rot, FALSE, layer); rename_id(&ob->id, "CurveGuide"); ((Curve*)ob->data)->flag |= CU_PATH|CU_3D; @@ -344,7 +382,7 @@ static Object *effector_add_type(bContext *C, wmOperator *op, int type) ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO); } else { - ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE); + ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer); rename_id(&ob->id, "Field"); switch(type) { @@ -397,15 +435,16 @@ static int object_camera_add_exec(bContext *C, wmOperator *op) Scene *scene= CTX_data_scene(C); Object *ob; int enter_editmode; + unsigned int layer; float loc[3], rot[3]; /* force view align for cameras */ RNA_boolean_set(op->ptr, "view_align", 1); object_add_generic_invoke_options(C, op); - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - ob= ED_object_add_type(C, OB_CAMERA, loc, rot, FALSE); + ob= ED_object_add_type(C, OB_CAMERA, loc, rot, FALSE, layer); if (v3d) { if (v3d->camera == NULL) @@ -454,14 +493,15 @@ static int object_add_curve_exec(bContext *C, wmOperator *op) Nurb *nu; int newob= 0, type= RNA_enum_get(op->ptr, "type"); int enter_editmode; + unsigned int layer; 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); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); if(obedit==NULL || obedit->type!=OB_CURVE) { - obedit= ED_object_add_type(C, OB_CURVE, loc, rot, TRUE); + obedit= ED_object_add_type(C, OB_CURVE, loc, rot, TRUE, layer); newob = 1; if(type & CU_PRIM_PATH) @@ -542,14 +582,15 @@ static int object_add_surface_exec(bContext *C, wmOperator *op) Nurb *nu; int newob= 0; int enter_editmode; + unsigned int layer; 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); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); if(obedit==NULL || obedit->type!=OB_SURF) { - obedit= ED_object_add_type(C, OB_SURF, loc, rot, TRUE); + obedit= ED_object_add_type(C, OB_SURF, loc, rot, TRUE, layer); newob = 1; } else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); @@ -606,14 +647,15 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) MetaElem *elem; int newob= 0; int enter_editmode; + unsigned int layer; 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); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); if(obedit==NULL || obedit->type!=OB_MBALL) { - obedit= ED_object_add_type(C, OB_MBALL, loc, rot, TRUE); + obedit= ED_object_add_type(C, OB_MBALL, loc, rot, TRUE, layer); newob = 1; } else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); @@ -676,15 +718,16 @@ static int object_add_text_exec(bContext *C, wmOperator *op) { Object *obedit= CTX_data_edit_object(C); int enter_editmode; + unsigned int layer; float loc[3], rot[3]; 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); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); if(obedit && obedit->type==OB_FONT) return OPERATOR_CANCELLED; - obedit= ED_object_add_type(C, OB_FONT, loc, rot, enter_editmode); + obedit= ED_object_add_type(C, OB_FONT, loc, rot, enter_editmode, layer); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); @@ -715,13 +758,14 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) RegionView3D *rv3d= NULL; int newob= 0; int enter_editmode; + unsigned int layer; float loc[3], rot[3]; 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); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) { - obedit= ED_object_add_type(C, OB_ARMATURE, loc, rot, TRUE); + obedit= ED_object_add_type(C, OB_ARMATURE, loc, rot, TRUE, layer); ED_object_enter_editmode(C, 0); newob = 1; } @@ -770,12 +814,13 @@ static int object_lamp_add_exec(bContext *C, wmOperator *op) Object *ob; int type= RNA_enum_get(op->ptr, "type"); int enter_editmode; + unsigned int layer; float loc[3], rot[3]; object_add_generic_invoke_options(C, op); - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); - ob= ED_object_add_type(C, OB_LAMP, loc, rot, FALSE); + ob= ED_object_add_type(C, OB_LAMP, loc, rot, FALSE, layer); if(ob && ob->data) ((Lamp*)ob->data)->type= type; @@ -816,12 +861,13 @@ static int group_instance_add_exec(bContext *C, wmOperator *op) Group *group= BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "type")); int enter_editmode; + unsigned int layer; float loc[3], rot[3]; - ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode); + ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer); if(group) { - Object *ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE); + Object *ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer); rename_id(&ob->id, group->id.name+2); ob->dup_group= group; ob->transflag |= OB_DUPLIGROUP; |