new addon simple_deform_helper #104464

Closed
EMM wants to merge 29 commits from Guai_Wo_Ge_EMM/blender-addons:simple_deform_helper into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
9 changed files with 101 additions and 69 deletions
Showing only changes of commit b471e648d5 - Show all commits

View File

@ -5,7 +5,7 @@ import gpu
from gpu_extras.batch import batch_for_shader
from mathutils import Vector
from .update import change_active_object, simple_update
from .update import ChangeActiveObject, simple_update
from .utils import GizmoUtils
@ -30,8 +30,8 @@ class DrawPublic(GizmoUtils):
@property
def draw_poll(self) -> bool:
if simple_update.timers_update_poll():
is_switch_obj = change_active_object.is_change_active_object(False)
if self.simple_deform_public_poll(bpy.context) and not is_switch_obj:
is_switch_obj = ChangeActiveObject.is_change_active_object(False)
if self.poll_simple_deform_public(bpy.context) and not is_switch_obj:
return True
return False
@ -137,7 +137,7 @@ class Draw3D(DrawHandler):
self.draw_limits_bound_box()
self.draw_text_handler()
elif self.simple_deform_show_bend_axis_witch_poll(context):
elif self.poll_simple_deform_show_bend_axis_witch(context):
self.draw_bound_box()
def draw_bound_box(self):

View File

@ -6,7 +6,7 @@ from bpy.types import (
GizmoGroup,
)
from ..update import change_active_modifier_parameter
from ..update import ChangeActiveModifierParameter
from ..utils import GizmoUtils, GizmoGroupUtils
@ -115,7 +115,7 @@ class AngleGizmo(Gizmo, AngleUpdate):
self.update_prop_value(event, tweak)
self.update_deform_wireframe()
self.update_header_text(context)
change_active_modifier_parameter.update_modifier_parameter()
ChangeActiveModifierParameter.update_modifier_parameter()
self.tag_redraw(context)
return self.event_handle(event)

View File

@ -38,7 +38,7 @@ class BendAxiSwitchGizmoGroup(GizmoGroup, GizmoGroupUtils):
@classmethod
def poll(cls, context):
return cls.simple_deform_show_bend_axis_witch_poll(context)
return cls.poll_simple_deform_show_bend_axis_witch(context)
def setup(self, context):
_draw_type = 'SimpleDeform_Bend_Direction_'

View File

@ -6,7 +6,7 @@ from bpy.types import Gizmo, GizmoGroup
from bpy_extras import view3d_utils
from mathutils import Vector
from ..update import change_active_modifier_parameter
from ..update import ChangeActiveModifierParameter
from ..utils import GizmoUtils, GizmoGroupUtils
@ -202,6 +202,7 @@ class UpDownLimitsGizmo(Gizmo, GizmoUpdate):
'down_limits', self.int_value_down_limits)
def modal(self, context, event, tweak):
st = time()
self.clear_point_cache()
if self.modifier_is_use_origin_axis:
@ -215,13 +216,15 @@ class UpDownLimitsGizmo(Gizmo, GizmoUpdate):
self.set_prop_value(event)
self.clear_point_cache()
self.update_object_origin_matrix()
except Exception:
...
except Exception as e:
print(e.args)
# ...
# return {'FINISHED'}
self.update_header_text(context)
return_handle = self.event_handle(event)
change_active_modifier_parameter.update_modifier_parameter()
ChangeActiveModifierParameter.update_modifier_parameter()
self.update_deform_wireframe()
print('run modal time:', time() - st)
return return_handle
@ -231,6 +234,7 @@ class UpDownLimitsGizmoGroup(GizmoGroup, GizmoGroupUtils):
@classmethod
def poll(cls, context):
return cls.simple_deform_show_gizmo_poll(context)
def setup(self, context):

View File

@ -16,13 +16,17 @@ class SimpleDeformHelperToolPanel(Panel, GizmoUtils):
@classmethod
def poll(cls, context):
return cls.simple_deform_public_poll(context)
show_in_tool_options = GizmoUtils.pref_().show_gizmo_property_location == 'ToolOptions'
return cls.poll_simple_deform_public(context) and show_in_tool_options
def draw(self, context):
if self.poll(context):
self.draw_property(self.layout, context)
@staticmethod
def draw_property(layout, context):
cls = SimpleDeformHelperToolPanel
if cls.poll(context):
pref = cls.pref_()
layout = self.layout
obj = context.object
mod = obj.modifiers.active
@ -49,6 +53,11 @@ class SimpleDeformHelperToolPanel(Panel, GizmoUtils):
'modifiers_limits_tolerance',
text='')
def draw_settings(self, context):
show_in_settings = GizmoUtils.pref_().show_gizmo_property_location == 'ToolSettings'
if show_in_settings:
SimpleDeformHelperToolPanel.draw_property(self.layout, context)
class_list = (
SimpleDeformHelperToolPanel,
@ -59,9 +68,9 @@ register_class, unregister_class = bpy.utils.register_classes_factory(class_list
def register():
register_class()
VIEW3D_HT_tool_header.append(SimpleDeformHelperToolPanel.draw)
VIEW3D_HT_tool_header.append(SimpleDeformHelperToolPanel.draw_settings)
def unregister():
unregister_class()
VIEW3D_HT_tool_header.remove(SimpleDeformHelperToolPanel.draw)
VIEW3D_HT_tool_header.remove(SimpleDeformHelperToolPanel.draw_settings)

View File

@ -60,6 +60,14 @@ class SimpleDeformGizmoAddonPreferences(AddonPreferences, GizmoUtils):
name='Show Set Axis Button',
default=False)
show_gizmo_property_location: EnumProperty(
name='Gizmo Property Show Location',
items=[('ToolSettings', 'Tool Settings', ''),
('ToolOptions', 'Tool Options', ''),
],
default='ToolSettings'
)
def draw(self, context):
col = self.layout.column()
box = col.box()
@ -73,13 +81,12 @@ class SimpleDeformGizmoAddonPreferences(AddonPreferences, GizmoUtils):
col.prop(self, 'deform_wireframe_color')
col.prop(self, 'bound_box_color')
col.prop(self, 'limits_bound_box_color')
col.prop(self, 'modifiers_limits_tolerance')
col.prop(self, 'display_bend_axis_switch_gizmo')
col.prop(self, 'update_deform_wireframe', icon='MOD_WIREFRAME', )
col.prop(self, 'show_set_axis_button', icon='EMPTY_AXIS', )
col.label(text='Gizmo Property Show Location')
col.prop(self, 'show_gizmo_property_location', expand=True)
def draw_header_tool_settings(self, context):
if GizmoUtils.simple_deform_public_poll(context):
if GizmoUtils.poll_simple_deform_public(context):
row = self.layout.row()
obj = context.object
mod = obj.modifiers.active

View File

@ -12,7 +12,7 @@ translations_dict = {
"zh_CN": {
("上下文", "原文"): "翻译文字",
("*", "Show Toggle Bend Axis Gizmo"): "显示切换弯曲轴向Gizmo",
("*", "Gizmo Property Show Location"): "Gizmo属性显示位置",
("*", "You can press the following shortcut keys when dragging values"):
"拖动值时可以按以下快捷键",
("*", " Wheel: Switch Origin Ctrl Mode"):
@ -25,7 +25,6 @@ translations_dict = {
" A: Switch To Select Bend Axis Mode(deform_method=='BEND')"):
" A: 切换到选择弯曲轴模式(形变方法='弯曲')",
("*", "Show Set Axis Button"): "显示设置轴向Gizmo",
("*", "Follow Upper Limit(Red)"): "跟随上限(红色)",
("*", "Follow Lower Limit(Green)"): "跟随下限(绿色)",
("*", "Lower limit(Green)"): "下限(绿色)",
@ -60,6 +59,7 @@ translations_dict = {
("*", "3D View -> Select an object and the active modifier is simple deformation"): "3D视图 -> 选择一个物体,"
"并且活动修改器为简易形修改器",
("*", "3D View: Simple Deform Helper"): "3D 视图: Simple Deform Helper 简易形变助手",
("*", "Simple Deform Helper"): "简易形变助手",
("*", ""): "",
}
}

View File

@ -83,7 +83,7 @@ class simple_update(update_public, GizmoUpdate):
@classmethod
def timers_update_poll(cls):
obj = bpy.context.object
if not cls.context_mode_is_object():
if not cls.poll_context_mode_is_object():
...
elif not obj:
...
@ -94,7 +94,7 @@ class simple_update(update_public, GizmoUpdate):
return False
class change_active_object(simple_update):
class ChangeActiveObject(simple_update):
@classmethod
@cache
def update_poll(cls):
@ -118,7 +118,7 @@ class change_active_object(simple_update):
return False
class change_active_simple_deform_modifier(simple_update):
class ChangeActiveSimpleDeformModifier(simple_update):
@classmethod
@cache
@ -134,7 +134,7 @@ class change_active_simple_deform_modifier(simple_update):
def update():
cls.tmp_save_data['modifiers'] = modifiers
if change_active_object.update_poll():
if ChangeActiveObject.update_poll():
update()
elif 'modifiers' not in cls.tmp_save_data:
update()
@ -150,7 +150,7 @@ class change_active_simple_deform_modifier(simple_update):
'modifiers': list(i.name for i in obj.modifiers)}
class change_active_modifier_parameter(simple_update):
class ChangeActiveModifierParameter(simple_update):
key = 'active_modifier_parameter'
@classmethod
@ -174,9 +174,9 @@ class change_active_modifier_parameter(simple_update):
@classmethod
def is_change_active_simple_parameter(cls):
parameter = cls.get_modifiers_parameter(gizmo.modifier)
if change_active_object.update_poll():
if ChangeActiveObject.update_poll():
cls.update_modifier_parameter(parameter)
elif change_active_simple_deform_modifier.update_poll():
elif ChangeActiveSimpleDeformModifier.update_poll():
cls.update_modifier_parameter(parameter)
elif cls.key not in cls.tmp_save_data:
cls.update_modifier_parameter(parameter)
@ -192,9 +192,9 @@ def register():
def p():
gizmo.update_multiple_modifiers_data()
change_active_object.append(p)
change_active_modifier_parameter.append(p)
change_active_simple_deform_modifier.append(p)
ChangeActiveObject.append(p)
ChangeActiveModifierParameter.append(p)
ChangeActiveSimpleDeformModifier.append(p)
def unregister():

View File

@ -107,11 +107,11 @@ class PublicClass(PublicData):
class PublicPoll(PublicClass):
@classmethod
def context_mode_is_object(cls) -> bool:
def poll_context_mode_is_object(cls) -> bool:
return bpy.context.mode == 'OBJECT'
@classmethod
def simple_deform_modifier_is_simple(cls, context):
def poll_modifier_type_is_simple(cls, context):
"""
Active Object in ('MESH', 'LATTICE')
Active Modifier Type Is 'SIMPLE_DEFORM' and show_viewport
@ -128,13 +128,23 @@ class PublicPoll(PublicClass):
available_obj_type = cls.obj_type_is_mesh_or_lattice(obj)
is_available_obj = cls.mod_is_simple_deform_type(mod) and available_obj_type
is_obj_mode = cls.context_mode_is_object()
is_obj_mode = cls.poll_context_mode_is_object()
show_mod = mod.show_viewport
not_is_self_mesh = obj.name != cls.G_NAME
return is_available_obj and is_obj_mode and show_mod and not_is_self_mesh
@classmethod
def simple_deform_public_poll(cls, context: 'bpy.types.context') -> bool:
def poll_object_is_show(cls, context: 'bpy.types.Context') -> bool:
"""
hava active object and object is show
:param context:
:return:
"""
obj = context.object
return obj and (not obj.hide_viewport) and (not obj.hide_get())
@classmethod
def poll_simple_deform_public(cls, context: 'bpy.types.context') -> bool:
"""Public poll
In 3D View
return True
@ -143,32 +153,33 @@ class PublicPoll(PublicClass):
if not space:
return False
show_gizmo = space.show_gizmo if space.type == 'VIEW_3D' else True
obj = cls.simple_deform_modifier_is_simple(context)
return obj and show_gizmo
is_simple = cls.poll_modifier_type_is_simple(context)
is_show = cls.poll_object_is_show(context)
return is_simple and show_gizmo and is_show
@classmethod
def _simple_deform_modifier_is_bend_poll(cls, context):
def poll_simple_deform_modifier_is_bend(cls, context):
"""
Public poll
active modifier deform_method =='BEND'
"""
simple = cls.simple_deform_public_poll(context)
simple = cls.poll_simple_deform_public(context)
is_bend = simple and (context.object.modifiers.active.deform_method == 'BEND')
return simple and is_bend
@classmethod
def simple_deform_show_bend_axis_witch_poll(cls, context):
def poll_simple_deform_show_bend_axis_witch(cls, context):
"""
Show D
"""
switch_axis = cls.pref_().display_bend_axis_switch_gizmo
bend = cls._simple_deform_modifier_is_bend_poll(context)
bend = cls.poll_simple_deform_modifier_is_bend(context)
return switch_axis and bend
@classmethod
def simple_deform_show_gizmo_poll(cls, context):
poll = cls.simple_deform_public_poll(context)
not_switch = (not cls.simple_deform_show_bend_axis_witch_poll(context))
poll = cls.poll_simple_deform_public(context)
not_switch = (not cls.poll_simple_deform_show_bend_axis_witch(context))
return poll and not_switch
@ -272,6 +283,8 @@ class GizmoClassMethod(PublicTranslate):
list_vertices = np.zeros(ver_len * 3, dtype=np.float32)
obj.data.points.foreach_get('co_deform', list_vertices)
list_vertices = list_vertices.reshape(ver_len, 3)
else:
list_vertices = np.zeros((3, 3), dtype=np.float32)
return Vector(list_vertices.min(axis=0)).freeze(), Vector(list_vertices.max(axis=0)).freeze()
@classmethod
@ -287,7 +300,6 @@ class GizmoClassMethod(PublicTranslate):
elif f == 1:
i[1] -= 0.1
j[1] += 0.1
else:
i[2] -= 0.1
j[2] += 0.1
@ -659,7 +671,7 @@ class GizmoUpdate(PublicProperty):
def update_multiple_modifiers_data(self):
obj = self.obj
context = bpy.context
if not self.obj_type_is_mesh_or_lattice(obj) or not self.simple_deform_modifier_is_simple(context):
if not self.obj_type_is_mesh_or_lattice(obj) or not self.poll_modifier_type_is_simple(context):
return
self.clear_point_cache()
self.clear_modifiers_data()