Object: new add object tool, currently for primitive types

- Interactively adding primitives with two clicks.
- Scene orientation used for new objects.
- Depth [view-plane, axis-plane, surface]
- Origin [base, center]
- Primitive types [cube, cylinder, cone, uv-sphere, ico-sphere ]
- Settings for object types in the top-bar.

Shortcuts:

- Snapping (Ctrl).
- Constrain 1:1 aspect (Shift).
- Toggle center (Alt).

Part of T57210 design task.
This commit is contained in:
Campbell Barton
2020-05-28 14:34:17 +10:00
parent 16943c0146
commit 122cb1aea8
9 changed files with 1365 additions and 24 deletions

View File

@@ -436,10 +436,124 @@ class _defs_view3d_select:
)
class _defs_view3d_add:
# Layout tweaks here would be good to avoid,
# this shows limits in layout engine, as buttons are using a lot of space.
@staticmethod
def draw_settings_interactive_add(layout, tool):
props = tool.operator_properties("view3d.interactive_add")
row = layout.row()
row.scale_x = 0.8
row.label(text="Depth:")
row = layout.row()
row.scale_x = 0.9
row.prop(props, "plane_depth", text="")
row = layout.row()
row.prop(props, "plane_axis", text="")
row = layout.row()
row.scale_x = 0.7
row.prop(props, "plane_origin")
@ToolDef.from_fn
def cube_add():
def draw_settings(_context, layout, tool):
_defs_view3d_add.draw_settings_interactive_add(layout, tool)
return dict(
idname="builtin.primitive_cube_add",
label="Add Cube",
icon="ops.mesh.primitive_cube_add_gizmo",
description=(
"Add cube to mesh interactively"
),
widget="VIEW3D_GGT_placement",
keymap="3D View Tool: Object, Add Primitive",
draw_settings=draw_settings,
)
@ToolDef.from_fn
def cone_add():
def draw_settings(_context, layout, tool):
_defs_view3d_add.draw_settings_interactive_add(layout, tool)
props = tool.operator_properties("mesh.primitive_cone_add")
layout.prop(props, "vertices")
layout.prop(props, "end_fill_type")
return dict(
idname="builtin.primitive_cone_add",
label="Add Cone",
icon="ops.mesh.primitive_cube_add_gizmo",
description=(
"Add cone to mesh interactively"
),
widget="VIEW3D_GGT_placement",
keymap="3D View Tool: Object, Add Primitive",
draw_settings=draw_settings,
)
@ToolDef.from_fn
def cylinder_add():
def draw_settings(_context, layout, tool):
_defs_view3d_add.draw_settings_interactive_add(layout, tool)
props = tool.operator_properties("mesh.primitive_cylinder_add")
layout.prop(props, "vertices")
layout.prop(props, "end_fill_type")
return dict(
idname="builtin.primitive_cylinder_add",
label="Add Cylinder",
icon="ops.mesh.primitive_cylinder_add_gizmo",
description=(
"Add cylinder to mesh interactively"
),
widget="VIEW3D_GGT_placement",
keymap="3D View Tool: Object, Add Primitive",
draw_settings=draw_settings,
)
@ToolDef.from_fn
def uv_sphere_add():
def draw_settings(_context, layout, tool):
_defs_view3d_add.draw_settings_interactive_add(layout, tool)
props = tool.operator_properties("mesh.primitive_uv_sphere_add")
layout.prop(props, "segments")
layout.prop(props, "ring_count")
return dict(
idname="builtin.primitive_uv_sphere_add",
label="Add UV Sphere",
icon="ops.mesh.primitive_sphere_add_gizmo",
description=(
"Add cylinder to mesh interactively"
),
widget="VIEW3D_GGT_placement",
keymap="3D View Tool: Object, Add Primitive",
draw_settings=draw_settings,
)
@ToolDef.from_fn
def ico_sphere_add():
def draw_settings(_context, layout, tool):
_defs_view3d_add.draw_settings_interactive_add(layout, tool)
props = tool.operator_properties("mesh.primitive_ico_sphere_add")
layout.prop(props, "subdivisions")
return dict(
idname="builtin.primitive_ico_sphere_add",
label="Add Ico Sphere",
icon="ops.mesh.primitive_sphere_add_gizmo",
description=(
"Add cylinder to mesh interactively"
),
widget="VIEW3D_GGT_placement",
keymap="3D View Tool: Object, Add Primitive",
draw_settings=draw_settings,
)
# -----------------------------------------------------------------------------
# Object Modes (named based on context.mode)
class _defs_edit_armature:
@ToolDef.from_fn
@@ -497,19 +611,6 @@ class _defs_edit_armature:
class _defs_edit_mesh:
@ToolDef.from_fn
def cube_add():
return dict(
idname="builtin.add_cube",
label="Add Cube",
icon="ops.mesh.primitive_cube_add_gizmo",
description=(
"Add cube to mesh interactively"
),
widget=None,
keymap=(),
)
@ToolDef.from_fn
def rip_region():
def draw_settings(_context, layout, tool):
@@ -2147,6 +2248,14 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
),
)
_tools_view3d_add = (
_defs_view3d_add.cube_add,
_defs_view3d_add.cone_add,
_defs_view3d_add.cylinder_add,
_defs_view3d_add.uv_sphere_add,
_defs_view3d_add.ico_sphere_add,
)
_tools_default = (
*_tools_select,
_defs_view3d_generic.cursor,
@@ -2165,6 +2274,9 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
],
'OBJECT': [
*_tools_default,
None,
_tools_view3d_add,
],
'POSE': [
*_tools_default,
@@ -2193,6 +2305,8 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
'EDIT_MESH': [
*_tools_default,
None,
_tools_view3d_add,
None,
(
_defs_edit_mesh.extrude,
_defs_edit_mesh.extrude_dissolve_and_intersect,