Skip to content

Commit

Permalink
fix: ensure circular_array operator allows for traditional (now defau…
Browse files Browse the repository at this point in the history
…lt) and faux origin translation
  • Loading branch information
tristan-hm committed Apr 23, 2022
1 parent fd6eae0 commit a21a46c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 20 additions & 1 deletion lib/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
12 changes: 10 additions & 2 deletions power_mods/circular_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a21a46c

Please sign in to comment.