Skip to content

Commit

Permalink
feat: allow circular_array operator to be run on objects, empties, an…
Browse files Browse the repository at this point in the history
…d at arbitrary rotations
  • Loading branch information
tristan-hm committed Apr 19, 2022
1 parent 09da9e8 commit 45cb48b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions power_mods/circular_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ def invoke(self, context, event):
self.reference_obj = a if a.name != context.object.name else b
self.rotator_obj = context.active_object

self.reference_obj_prev_location = self.reference_obj.location.copy()
self.reference_obj_prev_rotation = self.reference_obj.rotation_euler.copy()

self.new_empty = False
if self.rotator_obj.type != 'EMPTY':
empty_rotator_obj = bpy.data.objects.new("empty", None)
bpy.context.scene.collection.objects.link(empty_rotator_obj)
empty_rotator_obj.empty_display_size = 1
empty_rotator_obj.empty_display_type = 'PLAIN_AXES'
empty_rotator_obj.parent = self.rotator_obj
empty_rotator_obj.location = (0, 0, 0)
empty_rotator_obj.rotation_euler = (0, 0, 0)
empty_rotator_obj.scale = (1, 1, 1)

self.rotator_obj = empty_rotator_obj
self.new_empty = True

bpy.ops.nd.set_origin()

self.rotation_snapshot = self.rotator_obj.rotation_euler.copy()
self.add_array_modifier()
self.operate(context)
Expand Down Expand Up @@ -156,6 +175,19 @@ def revert(self, context):
self.select_reference_obj(context)
bpy.ops.object.modifier_remove(modifier=self.array.name)

self.select_reference_obj(context)
modifier_names = [mod.name for mod in self.reference_obj.modifiers]
for name in modifier_names:
if "Axis Displace" in name:
bpy.ops.object.modifier_remove(modifier=name)

self.reference_obj.location = self.reference_obj_prev_location
self.reference_obj.rotation_euler = self.reference_obj_prev_rotation

if self.new_empty:
bpy.context.scene.collection.objects.unlink(self.rotator_obj)
bpy.data.objects.remove(self.rotator_obj)

unregister_draw_handler()


Expand Down

0 comments on commit 45cb48b

Please sign in to comment.