diff options
-rw-r--r-- | release/scripts/modules/bpy_extras/object_utils.py | 18 | ||||
-rw-r--r-- | release/scripts/startup/bl_operators/add_mesh_torus.py | 17 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_add.c | 38 |
3 files changed, 57 insertions, 16 deletions
diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py index 838d22c1262..9381f49d408 100644 --- a/release/scripts/modules/bpy_extras/object_utils.py +++ b/release/scripts/modules/bpy_extras/object_utils.py @@ -22,6 +22,9 @@ __all__ = ( "add_object_align_init", "object_data_add", "AddObjectHelper", + "object_add_grid_scale", + "object_add_grid_scale_apply_operator", + "object_image_guess", ) @@ -210,6 +213,21 @@ def object_add_grid_scale(context): return 1.0 +def object_add_grid_scale_apply_operator(operator, context): + """ + Scale an operators distance values by the grid size. + """ + grid_scale = object_add_grid_scale(context) + + properties = operator.properties + properties_def = properties.bl_rna.properties + for prop_id in properties_def.keys(): + if not properties.is_property_set(prop_id): + prop_def = properties_def[prop_id] + if prop_def.unit == 'LENGTH' and prop_def.subtype == 'DISTANCE': + setattr(operator, prop_id, getattr(operator, prop_id) * grid_scale) + + def object_image_guess(obj, bm=None): """ Return a single image used by the object, diff --git a/release/scripts/startup/bl_operators/add_mesh_torus.py b/release/scripts/startup/bl_operators/add_mesh_torus.py index 948cb39f5b1..6b2f8be49d1 100644 --- a/release/scripts/startup/bl_operators/add_mesh_torus.py +++ b/release/scripts/startup/bl_operators/add_mesh_torus.py @@ -93,12 +93,16 @@ class AddTorus(Operator, object_utils.AddObjectHelper): "center of the cross sections"), min=0.01, max=100.0, default=1.0, + subtype='DISTANCE', + unit='LENGTH', ) minor_radius = FloatProperty( name="Minor Radius", description="Radius of the torus' cross section", min=0.01, max=100.0, default=0.25, + subtype='DISTANCE', + unit='LENGTH', ) major_segments = IntProperty( name="Major Segments", @@ -122,24 +126,31 @@ class AddTorus(Operator, object_utils.AddObjectHelper): description="Total Exterior Radius of the torus", min=0.01, max=100.0, default=1.0, + subtype='DISTANCE', + unit='LENGTH', ) abso_minor_rad = FloatProperty( name="Inside Radius", description="Total Interior Radius of the torus", min=0.01, max=100.0, default=0.5, + subtype='DISTANCE', + unit='LENGTH', ) + def invoke(self, context, event): + object_utils.object_add_grid_scale_apply_operator(self, context) + return self.execute(context) + def execute(self, context): - grid_scale = object_utils.object_add_grid_scale(context) if self.use_abso is True: extra_helper = (self.abso_major_rad - self.abso_minor_rad) * 0.5 self.major_radius = self.abso_minor_rad + extra_helper self.minor_radius = extra_helper - verts_loc, faces = add_torus(self.major_radius * grid_scale, - self.minor_radius * grid_scale, + verts_loc, faces = add_torus(self.major_radius, + self.minor_radius, self.major_segments, self.minor_segments) diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 2fb1f43a237..ed2744509a6 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -95,6 +95,15 @@ static void make_prim_finish(bContext *C, Object *obedit, bool was_editmode, int WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); } +static void make_prim_radius_prop(wmOperatorType *ot) +{ + PropertyRNA *prop; + + prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); + RNA_def_property_subtype(prop, PROP_DISTANCE); +} + + static int add_primitive_plane_exec(bContext *C, wmOperator *op) { Object *obedit; @@ -109,7 +118,8 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op) em = BKE_editmesh_from_object(obedit); if (!EDBM_op_call_and_selectf(em, op, "verts.out", - "create_grid x_segments=%i y_segments=%i size=%f matrix=%m4", 1, 1, dia, mat)) + "create_grid x_segments=%i y_segments=%i size=%f matrix=%m4", + 1, 1, RNA_float_get(op->ptr, "radius"), mat)) { return OPERATOR_CANCELLED; } @@ -127,12 +137,14 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_plane_add"; /* api callbacks */ + ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_plane_exec; ot->poll = ED_operator_scene_editable; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + make_prim_radius_prop(ot); ED_object_add_generic_props(ot, true); } @@ -149,7 +161,9 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op) obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Cube"), &dia, mat, &was_editmode, loc, rot, layer); em = BKE_editmesh_from_object(obedit); - if (!EDBM_op_call_and_selectf(em, op, "verts.out", "create_cube matrix=%m4 size=%f", mat, dia * 2.0f)) { + if (!EDBM_op_call_and_selectf(em, op, "verts.out", "create_cube matrix=%m4 size=%f", + mat, RNA_float_get(op->ptr, "radius") * 2.0f)) + { return OPERATOR_CANCELLED; } @@ -167,12 +181,14 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_cube_add"; /* api callbacks */ + ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_cube_exec; ot->poll = ED_operator_scene_editable; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + make_prim_radius_prop(ot); ED_object_add_generic_props(ot, true); } @@ -214,8 +230,6 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op) void MESH_OT_primitive_circle_add(wmOperatorType *ot) { - PropertyRNA *prop; - /* identifiers */ ot->name = "Add Circle"; ot->description = "Construct a circle mesh"; @@ -231,8 +245,7 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) /* props */ RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); - prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); - RNA_def_property_subtype(prop, PROP_DISTANCE); + make_prim_radius_prop(ot); RNA_def_enum(ot->srna, "fill_type", fill_type_items, 0, "Fill Type", ""); ED_object_add_generic_props(ot, true); @@ -290,8 +303,7 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) /* props */ RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); - prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); - RNA_def_property_subtype(prop, PROP_DISTANCE); + make_prim_radius_prop(ot); prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); RNA_def_enum(ot->srna, "end_fill_type", fill_type_items, 1, "Cap Fill Type", ""); @@ -376,7 +388,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) "create_grid x_segments=%i y_segments=%i size=%f matrix=%m4", RNA_int_get(op->ptr, "x_subdivisions"), RNA_int_get(op->ptr, "y_subdivisions"), - RNA_float_get(op->ptr, "size"), mat)) + RNA_float_get(op->ptr, "radius"), mat)) { return OPERATOR_CANCELLED; } @@ -388,8 +400,6 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op) void MESH_OT_primitive_grid_add(wmOperatorType *ot) { - PropertyRNA *prop; - /* identifiers */ ot->name = "Add Grid"; ot->description = "Construct a grid mesh"; @@ -406,8 +416,7 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) /* props */ RNA_def_int(ot->srna, "x_subdivisions", 10, 3, INT_MAX, "X Subdivisions", "", 3, 1000); RNA_def_int(ot->srna, "y_subdivisions", 10, 3, INT_MAX, "Y Subdivisions", "", 3, 1000); - prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, FLT_MAX); - RNA_def_property_subtype(prop, PROP_DISTANCE); + make_prim_radius_prop(ot); ED_object_add_generic_props(ot, true); } @@ -427,6 +436,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op) rot[0] += (float)M_PI / 2.0f; obedit = make_prim_init(C, CTX_DATA_(BLF_I18NCONTEXT_ID_MESH, "Suzanne"), &dia, mat, &was_editmode, loc, rot, layer); + dia = RNA_float_get(op->ptr, "radius"); mat[0][0] *= dia; mat[1][1] *= dia; mat[2][2] *= dia; @@ -450,10 +460,12 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot) ot->idname = "MESH_OT_primitive_monkey_add"; /* api callbacks */ + ot->invoke = WM_operator_view3d_distance_invoke; ot->exec = add_primitive_monkey_exec; ot->poll = ED_operator_scene_editable; /* flags */ + make_prim_radius_prop(ot); ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; ED_object_add_generic_props(ot, true); |