From a21a46c6be4e73bdbe47707f7d77d236ebe52f55 Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Sun, 24 Apr 2022 09:48:02 +1000 Subject: [PATCH] fix: ensure circular_array operator allows for traditional (now default) and faux origin translation --- lib/objects.py | 21 ++++++++++++++++++++- power_mods/circular_array.py | 12 ++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/objects.py b/lib/objects.py index a9923c1..5b10ce8 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -27,4 +27,23 @@ def add_single_vertex_object(cls, context, name): def align_object_to_3d_cursor(cls, context): cls.obj.location = context.scene.cursor.location - cls.obj.rotation_euler = context.scene.cursor.rotation_euler \ No newline at end of file + cls.obj.rotation_euler = context.scene.cursor.rotation_euler + + +def set_origin(obj, mx): + update_child_matrices(obj, mx) + + new_matrix = mx.inverted_safe() @ obj.matrix_world + + obj.matrix_world = mx + obj.data.transform(new_matrix) + obj.data.update() + + +def update_child_matrices(obj, mx): + orig_matrix = obj.matrix_world.copy() + new_matrix = mx.inverted_safe() @ orig_matrix + + for c in obj.children: + parent_matrix = c.matrix_parent_inverse + c.matrix_parent_inverse = new_matrix @ parent_matrix \ No newline at end of file diff --git a/power_mods/circular_array.py b/power_mods/circular_array.py index bc29df2..734113c 100644 --- a/power_mods/circular_array.py +++ b/power_mods/circular_array.py @@ -6,13 +6,16 @@ from .. lib.events import capture_modifier_keys from .. lib.collections import move_to_utils_collection from .. lib.preferences import get_preferences +from .. lib.objects import set_origin class ND_OT_circular_array(bpy.types.Operator): bl_idname = "nd.circular_array" bl_label = "Circular Array" bl_description = """Array an object around another in a circular fashion -SHIFT — Do not place rotator object in utils collection""" +ALT — Use faux origin translation (for origin-reliant geometry) +SHIFT — Do not place rotator object in utils collection +""" bl_options = {'UNDO'} @@ -82,6 +85,7 @@ def modal(self, context, event): def invoke(self, context, event): self.skip_utils = event.shift + self.faux_origin = event.alt self.dirty = False self.axis = 2 @@ -109,7 +113,11 @@ def invoke(self, context, event): self.rotator_obj = empty_rotator_obj self.new_empty = True - bpy.ops.nd.set_origin() + if self.faux_origin: + bpy.ops.nd.set_origin() + else: + mx = self.rotator_obj.matrix_world + set_origin(self.reference_obj, mx) self.rotation_snapshot = self.rotator_obj.rotation_euler.copy() self.add_array_modifier()