diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2022-06-07 14:08:11 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2022-06-07 14:10:13 +0300 |
commit | 2935b6a2acb525ec804082ca0cffa8a33a7aa637 (patch) | |
tree | cd5514dde7c9a8ad0a5acc9b841a2ad0affa7791 /release/scripts/startup/bl_operators | |
parent | 3a8a44b3f905850fe82b93b1316e9412f5bb7a8b (diff) |
Add Instance Offset operators to Collections property panel
Add three operators to the Collections properties panel:
- `object.instance_offset_to_cursor`, which is already available from
the Object properties panel. The operator works on the active
collection, though, so it's weird to not have it in the Collections
panel.
- `object.instance_offset_from_object` is a new operator, which performs
the same operation as above, but then based on the active object's
evaluated world position.
- `object.instance_offset_to_cursor` is also new, and performs the
opposite of the first operator: it moves the 3D cursor to the
collection's instance offset.
The first two operators make it easier to set the instance offset. The
last operator makes it possible to actually see the offset in the 3D
viewport; drawing it using some overlay could also work, but that would
be more effort to get right, and then snapping the 3D cursor would still
be useful.
The operators are placed in a popup menu, as to not clutter the
interface too much with various buttons.
Reviewed By: dfelinto, eyecandy
Differential Revision: https://developer.blender.org/D14966
Diffstat (limited to 'release/scripts/startup/bl_operators')
-rw-r--r-- | release/scripts/startup/bl_operators/object.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py index f5759255e22..60f534b3ab6 100644 --- a/release/scripts/startup/bl_operators/object.py +++ b/release/scripts/startup/bl_operators/object.py @@ -855,6 +855,37 @@ class DupliOffsetFromCursor(Operator): return {'FINISHED'} +class DupliOffsetToCursor(Operator): + """Set cursor position to the offset used for collection instances""" + bl_idname = "object.instance_offset_to_cursor" + bl_label = "Set Cursor to Offset" + bl_options = {'INTERNAL', 'UNDO'} + + def execute(self, context): + scene = context.scene + collection = context.collection + scene.cursor.location = collection.instance_offset + return {'FINISHED'} + + +class DupliOffsetFromObject(Operator): + """Set offset used for collection instances based on the active object position""" + bl_idname = "object.instance_offset_from_object" + bl_label = "Set Offset from Object" + bl_options = {'INTERNAL', 'UNDO'} + + @classmethod + def poll(cls, context): + return (context.active_object is not None) + + def execute(self, context): + ob_eval = context.active_object.evaluated_get(context.view_layer.depsgraph) + world_loc = ob_eval.matrix_world.to_translation() + collection = context.collection + collection.instance_offset = world_loc + return {'FINISHED'} + + class LoadImageAsEmpty: bl_options = {'REGISTER', 'UNDO'} @@ -976,6 +1007,8 @@ class OBJECT_OT_assign_property_defaults(Operator): classes = ( ClearAllRestrictRender, DupliOffsetFromCursor, + DupliOffsetToCursor, + DupliOffsetFromObject, IsolateTypeRender, JoinUVs, LoadBackgroundImage, |