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.
3 changed files with 41 additions and 20 deletions
Showing only changes of commit f9ac35fdb0 - Show all commits

View File

@ -209,11 +209,13 @@ class UpDownLimitsGizmo(Gizmo, GizmoUpdate):
self.middle_limits_value = (self.modifier_up_limits + self.modifier_down_limits) / 2 self.middle_limits_value = (self.modifier_up_limits + self.modifier_down_limits) / 2
self.set_prop_value(event) self.set_prop_value(event)
self.update_object_origin_matrix() self.clear_data()
self.clear_cache()
self.update_multiple_modifiers_data() self.update_multiple_modifiers_data()
self.update_object_origin_matrix()
self.update_header_text(context) self.update_header_text(context)
return self.event_handle(event) return_handle = self.event_handle(event)
return return_handle
class UpDownLimitsGizmoGroup(GizmoGroup, GizmoGroupUtils): class UpDownLimitsGizmoGroup(GizmoGroup, GizmoGroupUtils):

View File

@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
from time import time
import bpy import bpy
from bpy.app.handlers import depsgraph_update_post, persistent from bpy.app.handlers import depsgraph_update_post, persistent
@ -13,9 +14,17 @@ def remove_not_use_empty(scene, dep):
remove_name: str = "ViewSimpleDeformGizmo_" remove_name: str = "ViewSimpleDeformGizmo_"
context = bpy.context context = bpy.context
gizmo = GizmoUpdate() gizmo = GizmoUpdate()
gizmo.clear_cache()
gizmo.fix_origin_parent_and_angle() gizmo.fix_origin_parent_and_angle()
# remove redundant empty object # remove redundant empty object
# simple update data if change active object on update
name = gizmo.obj.name
update_data = name not in gizmo.G_GizmoData or name != gizmo.G_GizmoData['active_object']
if update_data:
gizmo.clear_data()
gizmo.G_GizmoData[name] = name
gizmo.G_GizmoData['active_object'] = name
gizmo.G_Modifiers_TMP_Save_Data.clear()
if gizmo.simple_deform_modifier_is_simple(context): if gizmo.simple_deform_modifier_is_simple(context):
for obj in context.scene.objects: for obj in context.scene.objects:
is_empty = obj.type == "EMPTY" is_empty = obj.type == "EMPTY"
@ -23,11 +32,6 @@ def remove_not_use_empty(scene, dep):
if remove_name in obj.name and not_parent and is_empty: if remove_name in obj.name and not_parent and is_empty:
bpy.data.objects.remove(obj) bpy.data.objects.remove(obj)
# simple update data if change active object on update
update_data = gizmo.obj not in gizmo.G_GizmoData or gizmo.obj != gizmo.G_GizmoData[gizmo.obj]
if update_data:
gizmo.clear_data()
gizmo.G_GizmoData[gizmo.obj] = 'Emm'
def register(): def register():

View File

@ -17,6 +17,7 @@ class PublicData:
G_CustomShape = {} G_CustomShape = {}
G_GizmoData = {} G_GizmoData = {}
G_Modifiers_Data = {} G_Modifiers_Data = {}
G_Modifiers_TMP_Save_Data = {}
G_INDICES = ( G_INDICES = (
(0, 1), (0, 2), (1, 3), (2, 3), (0, 1), (0, 2), (1, 3), (2, 3),
(4, 5), (4, 6), (5, 7), (6, 7), (4, 5), (4, 6), (5, 7), (6, 7),
@ -314,6 +315,12 @@ class GizmoClassMethod(PublicUtils):
Vector((min_x, max_y, max_z)) Vector((min_x, max_y, max_z))
) )
@classmethod
def get_modifiers_data(cls, obj):
return {'obj': obj.name,
'active_modifier': obj.modifiers.active.name,
'modifiers': list(i.name for i in obj.modifiers)}
class PublicProperty(GizmoClassMethod): class PublicProperty(GizmoClassMethod):
@ -530,7 +537,7 @@ class GizmoUpdate(PublicProperty):
def fix_origin_parent_and_angle(self): def fix_origin_parent_and_angle(self):
obj = self.obj obj = self.obj
mod = self.modifier mod = self.modifier
if not obj or not mod: if not obj or not mod or not getattr(mod, 'origin', False):
return return
origin = mod.origin origin = mod.origin
@ -591,10 +598,11 @@ class GizmoUpdate(PublicProperty):
return origin_object return origin_object
def update_object_origin_matrix(self): def update_object_origin_matrix(self):
self.clear_cache()
origin_mode = self.origin_mode origin_mode = self.origin_mode
origin_object = self.modifier.origin origin_object = self.modifier.origin
if origin_object and self.modifier_is_use_origin_axis: is_use = self.modifier_is_use_origin_axis
if origin_object and is_use:
if origin_mode == 'UP_LIMITS': if origin_mode == 'UP_LIMITS':
origin_object.matrix_world.translation = Vector(self.point_limits_up) origin_object.matrix_world.translation = Vector(self.point_limits_up)
elif origin_mode == 'DOWN_LIMITS': elif origin_mode == 'DOWN_LIMITS':
@ -607,16 +615,23 @@ class GizmoUpdate(PublicProperty):
origin_object.matrix_world.translation = translation origin_object.matrix_world.translation = translation
def update_multiple_modifiers_data(self): def update_multiple_modifiers_data(self):
self.clear_data()
obj = self.obj obj = self.obj
data = bpy.data data = bpy.data
context = bpy.context context = bpy.context
name = self.G_NAME
origin_object = data.objects.get(name)
modifiers = self.G_Modifiers_TMP_Save_Data
mods_data = self.get_modifiers_data(obj)
if 114514 in modifiers and modifiers[114514] == mods_data:
if origin_object:
self.update_deform_wireframe(self.get_depsgraph(origin_object))
return
# add simple_deform mesh # add simple_deform mesh
name = self.G_NAME
if data.objects.get(name): if origin_object:
data.objects.remove(data.objects.get(name)) data.objects.remove(origin_object)
if data.meshes.get(name): if data.meshes.get(name):
data.meshes.remove(data.meshes.get(name)) data.meshes.remove(data.meshes.get(name))
@ -658,10 +673,10 @@ class GizmoUpdate(PublicProperty):
deform_obj.hide_select = True deform_obj.hide_select = True
deform_obj.hide_set(True) deform_obj.hide_set(True)
deform_obj.hide_viewport = False deform_obj.hide_viewport = False
self.update_deform_wireframe(self.get_depsgraph(deform_obj))
deform_obj.hide_render = True deform_obj.hide_render = True
deform_obj.hide_viewport = True deform_obj.hide_viewport = True
deform_obj.hide_set(True) deform_obj.hide_set(True)
self.G_Modifiers_TMP_Save_Data[114514] = mods_data
def update_deform_wireframe(self, obj): def update_deform_wireframe(self, obj):
if not self.pref.update_deform_wireframe: if not self.pref.update_deform_wireframe: