2023-08-16 00:20:26 +10:00
|
|
|
# SPDX-FileCopyrightText: 2011-2023 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2011-09-22 19:50:41 +00:00
|
|
|
|
|
|
|
|
import bpy
|
2024-03-26 20:01:08 +01:00
|
|
|
from bpy.types import (
|
|
|
|
|
Operator,
|
|
|
|
|
FileHandler,
|
|
|
|
|
)
|
2019-05-14 15:05:19 +10:00
|
|
|
from bpy.props import (
|
|
|
|
|
BoolProperty,
|
|
|
|
|
EnumProperty,
|
|
|
|
|
)
|
2011-09-22 19:50:41 +00:00
|
|
|
|
2024-03-27 15:10:51 +11:00
|
|
|
bl_file_extensions_image_and_movie = ";".join((
|
|
|
|
|
*bpy.path.extensions_image,
|
|
|
|
|
*bpy.path.extensions_movie,
|
|
|
|
|
))
|
|
|
|
|
|
2011-09-22 19:50:41 +00:00
|
|
|
|
|
|
|
|
class VIEW3D_OT_edit_mesh_extrude_individual_move(Operator):
|
2019-05-05 21:36:12 +02:00
|
|
|
"""Extrude each individual face separately along local normals"""
|
2011-09-22 19:50:41 +00:00
|
|
|
bl_label = "Extrude Individual and Move"
|
|
|
|
|
bl_idname = "view3d.edit_mesh_extrude_individual_move"
|
|
|
|
|
|
2013-11-01 13:14:17 +00:00
|
|
|
@classmethod
|
|
|
|
|
def poll(cls, context):
|
2025-03-16 19:26:44 +11:00
|
|
|
return context.mode == 'EDIT_MESH'
|
2013-11-01 13:14:17 +00:00
|
|
|
|
2011-09-22 19:50:41 +00:00
|
|
|
def execute(self, context):
|
2024-01-19 11:52:08 +11:00
|
|
|
from bpy_extras.object_utils import object_report_if_active_shape_key_is_locked
|
|
|
|
|
|
2024-03-29 10:08:59 +11:00
|
|
|
ob = context.object
|
|
|
|
|
if object_report_if_active_shape_key_is_locked(ob, self):
|
2023-07-14 20:57:28 +03:00
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
2024-03-29 10:08:59 +11:00
|
|
|
mesh = ob.data
|
2011-09-22 19:50:41 +00:00
|
|
|
select_mode = context.tool_settings.mesh_select_mode
|
|
|
|
|
|
|
|
|
|
totface = mesh.total_face_sel
|
|
|
|
|
totedge = mesh.total_edge_sel
|
2018-06-26 19:41:37 +02:00
|
|
|
# totvert = mesh.total_vert_sel
|
2011-09-22 19:50:41 +00:00
|
|
|
|
|
|
|
|
if select_mode[2] and totface == 1:
|
2018-06-26 19:41:37 +02:00
|
|
|
bpy.ops.mesh.extrude_region_move(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
TRANSFORM_OT_translate={
|
2019-02-27 17:25:45 +11:00
|
|
|
"orient_type": 'NORMAL',
|
2018-06-26 19:41:37 +02:00
|
|
|
"constraint_axis": (False, False, True),
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2022-12-15 17:24:23 +11:00
|
|
|
},
|
2018-06-26 19:41:37 +02:00
|
|
|
)
|
2011-09-22 19:50:41 +00:00
|
|
|
elif select_mode[2] and totface > 1:
|
2023-06-05 16:36:34 -03:00
|
|
|
bpy.ops.mesh.extrude_faces_move(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
TRANSFORM_OT_shrink_fatten={
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2025-01-14 12:46:40 +11:00
|
|
|
},
|
|
|
|
|
)
|
2011-09-22 19:50:41 +00:00
|
|
|
elif select_mode[1] and totedge >= 1:
|
2023-06-05 16:36:34 -03:00
|
|
|
bpy.ops.mesh.extrude_edges_move(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
TRANSFORM_OT_translate={
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2023-06-05 16:36:34 -03:00
|
|
|
},
|
|
|
|
|
)
|
2011-09-22 19:50:41 +00:00
|
|
|
else:
|
2023-06-05 16:36:34 -03:00
|
|
|
bpy.ops.mesh.extrude_vertices_move(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
TRANSFORM_OT_translate={
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2023-06-05 16:36:34 -03:00
|
|
|
},
|
|
|
|
|
)
|
2011-09-22 19:50:41 +00:00
|
|
|
|
2011-09-26 15:39:15 +00:00
|
|
|
# ignore return from operators above because they are 'RUNNING_MODAL',
|
2023-02-12 14:37:16 +11:00
|
|
|
# and cause this one not to be freed. #24671.
|
2011-09-22 19:50:41 +00:00
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
2019-05-09 09:15:01 +10:00
|
|
|
def invoke(self, context, _event):
|
2011-09-22 19:50:41 +00:00
|
|
|
return self.execute(context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VIEW3D_OT_edit_mesh_extrude_move(Operator):
|
2019-05-05 21:36:12 +02:00
|
|
|
"""Extrude region together along the average normal"""
|
2011-09-22 19:50:41 +00:00
|
|
|
bl_label = "Extrude and Move on Normals"
|
|
|
|
|
bl_idname = "view3d.edit_mesh_extrude_move_normal"
|
|
|
|
|
|
2020-04-15 16:02:16 -03:00
|
|
|
dissolve_and_intersect: BoolProperty(
|
|
|
|
|
name="dissolve_and_intersect",
|
|
|
|
|
default=False,
|
2022-12-15 17:24:23 +11:00
|
|
|
description="Dissolves adjacent faces and intersects new geometry",
|
2020-04-15 16:02:16 -03:00
|
|
|
)
|
|
|
|
|
|
2013-11-01 13:14:17 +00:00
|
|
|
@classmethod
|
|
|
|
|
def poll(cls, context):
|
2025-03-16 19:26:44 +11:00
|
|
|
return context.mode == 'EDIT_MESH'
|
2013-11-01 13:14:17 +00:00
|
|
|
|
2013-10-15 18:30:49 +00:00
|
|
|
@staticmethod
|
2023-07-14 20:57:28 +03:00
|
|
|
def extrude_region(operator, context, use_vert_normals, dissolve_and_intersect):
|
2024-01-19 11:52:08 +11:00
|
|
|
from bpy_extras.object_utils import object_report_if_active_shape_key_is_locked
|
|
|
|
|
|
2024-03-29 10:08:59 +11:00
|
|
|
ob = context.object
|
|
|
|
|
if object_report_if_active_shape_key_is_locked(ob, operator):
|
2023-07-14 20:57:28 +03:00
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
2024-03-29 10:08:59 +11:00
|
|
|
mesh = ob.data
|
2011-09-22 19:50:41 +00:00
|
|
|
|
|
|
|
|
totface = mesh.total_face_sel
|
|
|
|
|
totedge = mesh.total_edge_sel
|
2018-06-26 19:41:37 +02:00
|
|
|
# totvert = mesh.total_vert_sel
|
2011-09-22 19:50:41 +00:00
|
|
|
|
|
|
|
|
if totface >= 1:
|
2013-10-15 18:30:49 +00:00
|
|
|
if use_vert_normals:
|
2018-06-26 19:41:37 +02:00
|
|
|
bpy.ops.mesh.extrude_region_shrink_fatten(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
2023-06-05 16:36:34 -03:00
|
|
|
TRANSFORM_OT_shrink_fatten={
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2023-06-05 16:36:34 -03:00
|
|
|
},
|
2018-06-26 19:41:37 +02:00
|
|
|
)
|
2020-04-15 16:02:16 -03:00
|
|
|
elif dissolve_and_intersect:
|
2020-06-22 09:20:43 -03:00
|
|
|
bpy.ops.mesh.extrude_manifold(
|
2020-04-15 16:02:16 -03:00
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
MESH_OT_extrude_region={
|
|
|
|
|
"use_dissolve_ortho_edges": True,
|
|
|
|
|
},
|
|
|
|
|
TRANSFORM_OT_translate={
|
|
|
|
|
"orient_type": 'NORMAL',
|
|
|
|
|
"constraint_axis": (False, False, True),
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2020-04-15 16:02:16 -03:00
|
|
|
},
|
|
|
|
|
)
|
2013-10-15 18:30:49 +00:00
|
|
|
else:
|
2018-06-26 19:41:37 +02:00
|
|
|
bpy.ops.mesh.extrude_region_move(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
2011-09-26 15:39:15 +00:00
|
|
|
TRANSFORM_OT_translate={
|
2019-02-27 17:25:45 +11:00
|
|
|
"orient_type": 'NORMAL',
|
2018-06-26 19:41:37 +02:00
|
|
|
"constraint_axis": (False, False, True),
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2018-06-26 19:41:37 +02:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
elif totedge == 1:
|
|
|
|
|
bpy.ops.mesh.extrude_region_move(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
TRANSFORM_OT_translate={
|
2019-02-27 02:05:18 +11:00
|
|
|
# Don't set the constraint axis since users will expect MMB
|
2023-02-12 14:37:16 +11:00
|
|
|
# to use the user setting, see: #61637
|
2019-02-27 17:25:45 +11:00
|
|
|
# "orient_type": 'NORMAL',
|
2024-05-04 15:24:46 +10:00
|
|
|
# Not a popular choice, too restrictive for retopology.
|
2023-09-29 14:32:54 +10:00
|
|
|
# "constraint_axis": (True, True, False),
|
2018-06-26 19:41:37 +02:00
|
|
|
"constraint_axis": (False, False, False),
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2018-06-26 19:41:37 +02:00
|
|
|
})
|
2011-09-22 19:50:41 +00:00
|
|
|
else:
|
2023-06-05 16:36:34 -03:00
|
|
|
bpy.ops.mesh.extrude_region_move(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
TRANSFORM_OT_translate={
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2023-06-05 16:36:34 -03:00
|
|
|
},
|
|
|
|
|
)
|
2011-09-22 19:50:41 +00:00
|
|
|
|
2011-09-26 15:39:15 +00:00
|
|
|
# ignore return from operators above because they are 'RUNNING_MODAL',
|
2023-02-12 14:37:16 +11:00
|
|
|
# and cause this one not to be freed. #24671.
|
2011-09-22 19:50:41 +00:00
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
2013-10-15 18:30:49 +00:00
|
|
|
def execute(self, context):
|
2024-03-15 10:04:03 +11:00
|
|
|
return VIEW3D_OT_edit_mesh_extrude_move.extrude_region(self, context, False, self.dissolve_and_intersect)
|
2013-10-15 18:30:49 +00:00
|
|
|
|
2019-05-09 09:15:01 +10:00
|
|
|
def invoke(self, context, _event):
|
2013-10-15 18:30:49 +00:00
|
|
|
return self.execute(context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VIEW3D_OT_edit_mesh_extrude_shrink_fatten(Operator):
|
2019-05-05 21:36:12 +02:00
|
|
|
"""Extrude region together along local normals"""
|
2013-10-15 18:30:49 +00:00
|
|
|
bl_label = "Extrude and Move on Individual Normals"
|
|
|
|
|
bl_idname = "view3d.edit_mesh_extrude_move_shrink_fatten"
|
|
|
|
|
|
2013-11-01 13:14:17 +00:00
|
|
|
@classmethod
|
|
|
|
|
def poll(cls, context):
|
2025-03-16 19:26:44 +11:00
|
|
|
return context.mode == 'EDIT_MESH'
|
2013-11-01 13:14:17 +00:00
|
|
|
|
2013-10-15 18:30:49 +00:00
|
|
|
def execute(self, context):
|
2023-07-14 20:57:28 +03:00
|
|
|
return VIEW3D_OT_edit_mesh_extrude_move.extrude_region(self, context, True, False)
|
2013-10-15 18:30:49 +00:00
|
|
|
|
2019-05-09 09:15:01 +10:00
|
|
|
def invoke(self, context, _event):
|
2011-09-22 20:37:22 +00:00
|
|
|
return self.execute(context)
|
2013-04-22 14:56:41 +00:00
|
|
|
|
|
|
|
|
|
2020-07-15 15:19:21 +10:00
|
|
|
class VIEW3D_OT_edit_mesh_extrude_manifold_normal(Operator):
|
|
|
|
|
"""Extrude manifold region along normals"""
|
|
|
|
|
bl_label = "Extrude Manifold Along Normals"
|
|
|
|
|
bl_idname = "view3d.edit_mesh_extrude_manifold_normal"
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def poll(cls, context):
|
2025-03-16 19:26:44 +11:00
|
|
|
return context.mode == 'EDIT_MESH'
|
2020-07-15 15:19:21 +10:00
|
|
|
|
2023-07-14 20:57:28 +03:00
|
|
|
def execute(self, context):
|
2024-01-19 11:52:08 +11:00
|
|
|
from bpy_extras.object_utils import object_report_if_active_shape_key_is_locked
|
|
|
|
|
|
2023-07-14 20:57:28 +03:00
|
|
|
if object_report_if_active_shape_key_is_locked(context.object, self):
|
|
|
|
|
return {'CANCELLED'}
|
2020-07-15 15:19:21 +10:00
|
|
|
bpy.ops.mesh.extrude_manifold(
|
|
|
|
|
'INVOKE_REGION_WIN',
|
|
|
|
|
MESH_OT_extrude_region={
|
|
|
|
|
"use_dissolve_ortho_edges": True,
|
|
|
|
|
},
|
|
|
|
|
TRANSFORM_OT_translate={
|
|
|
|
|
"orient_type": 'NORMAL',
|
|
|
|
|
"constraint_axis": (False, False, True),
|
2023-07-24 15:51:58 +02:00
|
|
|
"release_confirm": False,
|
2020-07-15 15:19:21 +10:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
def invoke(self, context, _event):
|
|
|
|
|
return self.execute(context)
|
|
|
|
|
|
|
|
|
|
|
2019-05-14 15:05:19 +10:00
|
|
|
class VIEW3D_OT_transform_gizmo_set(Operator):
|
|
|
|
|
"""Set the current transform gizmo"""
|
|
|
|
|
bl_label = "Transform Gizmo Set"
|
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
bl_idname = "view3d.transform_gizmo_set"
|
|
|
|
|
|
|
|
|
|
extend: BoolProperty(
|
2020-10-07 08:04:53 -05:00
|
|
|
name="Extend",
|
2019-05-14 15:05:19 +10:00
|
|
|
default=False,
|
|
|
|
|
)
|
|
|
|
|
type: EnumProperty(
|
2020-10-07 08:04:53 -05:00
|
|
|
name="Type",
|
2019-05-14 15:05:19 +10:00
|
|
|
items=(
|
|
|
|
|
('TRANSLATE', "Move", ""),
|
|
|
|
|
('ROTATE', "Rotate", ""),
|
|
|
|
|
('SCALE', "Scale", ""),
|
|
|
|
|
),
|
|
|
|
|
options={'ENUM_FLAG'},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def poll(cls, context):
|
2021-05-18 20:00:51 +10:00
|
|
|
area = context.area
|
|
|
|
|
return area and (area.type == 'VIEW_3D')
|
2019-05-14 15:05:19 +10:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
space_data = context.space_data
|
|
|
|
|
space_data.show_gizmo = True
|
|
|
|
|
attrs = ("show_gizmo_object_translate", "show_gizmo_object_rotate", "show_gizmo_object_scale")
|
|
|
|
|
attr_active = tuple(
|
|
|
|
|
attrs[('TRANSLATE', 'ROTATE', 'SCALE').index(t)]
|
|
|
|
|
for t in self.type
|
|
|
|
|
)
|
|
|
|
|
if self.extend:
|
|
|
|
|
for attr in attrs:
|
|
|
|
|
if attr in attr_active:
|
|
|
|
|
setattr(space_data, attr, True)
|
|
|
|
|
else:
|
|
|
|
|
for attr in attrs:
|
|
|
|
|
setattr(space_data, attr, attr in attr_active)
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
|
if not self.properties.is_property_set("extend"):
|
|
|
|
|
self.extend = event.shift
|
|
|
|
|
return self.execute(context)
|
|
|
|
|
|
|
|
|
|
|
2024-03-26 20:01:08 +01:00
|
|
|
class VIEW3D_FH_empty_image(FileHandler):
|
|
|
|
|
bl_idname = "VIEW3D_FH_empty_image"
|
|
|
|
|
bl_label = "Add empty image"
|
|
|
|
|
bl_import_operator = "OBJECT_OT_empty_image_add"
|
2024-03-27 15:10:51 +11:00
|
|
|
bl_file_extensions = bl_file_extensions_image_and_movie
|
2024-03-26 20:01:08 +01:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def poll_drop(cls, context):
|
|
|
|
|
if not context.space_data or context.space_data.type != 'VIEW_3D':
|
|
|
|
|
return False
|
|
|
|
|
rv3d = context.space_data.region_3d
|
|
|
|
|
return rv3d.view_perspective == 'PERSP' or rv3d.view_perspective == 'ORTHO'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VIEW3D_FH_camera_background_image(FileHandler):
|
|
|
|
|
bl_idname = "VIEW3D_FH_camera_background_image"
|
|
|
|
|
bl_label = "Add camera background image"
|
|
|
|
|
bl_import_operator = "VIEW3D_OT_camera_background_image_add"
|
2024-03-27 15:10:51 +11:00
|
|
|
bl_file_extensions = bl_file_extensions_image_and_movie
|
2024-03-26 20:01:08 +01:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def poll_drop(cls, context):
|
|
|
|
|
if not context.space_data or context.space_data.type != 'VIEW_3D':
|
|
|
|
|
return False
|
|
|
|
|
rv3d = context.space_data.region_3d
|
|
|
|
|
return rv3d.view_perspective == 'CAMERA'
|
|
|
|
|
|
|
|
|
|
|
2024-06-07 02:15:34 +02:00
|
|
|
class VIEW3D_FH_vdb_volume(FileHandler):
|
|
|
|
|
bl_idname = "VIEW3D_FH_vdb_volume"
|
|
|
|
|
bl_label = "OpenVDB volume"
|
|
|
|
|
bl_import_operator = "OBJECT_OT_volume_import"
|
|
|
|
|
bl_file_extensions = ".vdb"
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def poll_drop(cls, context):
|
|
|
|
|
return context.space_data and context.space_data.type == 'VIEW_3D'
|
|
|
|
|
|
|
|
|
|
|
2017-03-18 20:03:24 +11:00
|
|
|
classes = (
|
|
|
|
|
VIEW3D_OT_edit_mesh_extrude_individual_move,
|
|
|
|
|
VIEW3D_OT_edit_mesh_extrude_move,
|
|
|
|
|
VIEW3D_OT_edit_mesh_extrude_shrink_fatten,
|
2020-07-15 15:19:21 +10:00
|
|
|
VIEW3D_OT_edit_mesh_extrude_manifold_normal,
|
2019-05-14 15:05:19 +10:00
|
|
|
VIEW3D_OT_transform_gizmo_set,
|
2024-03-26 20:01:08 +01:00
|
|
|
VIEW3D_FH_camera_background_image,
|
|
|
|
|
VIEW3D_FH_empty_image,
|
2024-06-07 02:15:34 +02:00
|
|
|
VIEW3D_FH_vdb_volume,
|
2017-04-14 20:01:43 +10:00
|
|
|
)
|