From 7665dd4f4f816731a9e76df32559c6e78c5b409a Mon Sep 17 00:00:00 2001 From: pullusb Date: Tue, 3 Dec 2024 16:37:42 +0100 Subject: [PATCH] Add optional object target for constant cursor follow --- OP_cursor_snap_canvas.py | 20 +++++++++++++++----- UI_tools.py | 2 ++ properties.py | 5 +++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/OP_cursor_snap_canvas.py b/OP_cursor_snap_canvas.py index e2a65ac..a49d86d 100644 --- a/OP_cursor_snap_canvas.py +++ b/OP_cursor_snap_canvas.py @@ -114,13 +114,17 @@ prev_matrix = None ## used in properties file to register in boolprop update def cursor_follow_update(self, context): '''append or remove cursor_follow handler according a boolean''' + ob = bpy.context.object + if bpy.context.scene.gptoolprops.cursor_follow_target: + ## override with target object is specified + ob = bpy.context.scene.gptoolprops.cursor_follow_target global prev_matrix # imported in properties to register in boolprop update if self.cursor_follow:#True + if ob: + # out of below condition to be called when setting target as well + prev_matrix = ob.matrix_world.copy() if not cursor_follow.__name__ in [hand.__name__ for hand in bpy.app.handlers.frame_change_post]: - if context.object: - prev_matrix = context.object.matrix_world.copy() - bpy.app.handlers.frame_change_post.append(cursor_follow) else:#False @@ -131,10 +135,13 @@ def cursor_follow_update(self, context): def cursor_follow(scene): '''Handler to make the cursor follow active object matrix changes on frame change''' - if not bpy.context.object: + ob = bpy.context.object + if bpy.context.scene.gptoolprops.cursor_follow_target: + ## override with target object is specified + ob = bpy.context.scene.gptoolprops.cursor_follow_target + if not ob: return global prev_matrix - ob = bpy.context.object current_matrix = ob.matrix_world if not prev_matrix: prev_matrix = current_matrix.copy() @@ -161,6 +168,9 @@ def selection_changed(): """Callback function for selection changes""" if not bpy.context.scene.gptoolprops.cursor_follow: return + if bpy.context.scene.gptoolprops.cursor_follow_target: + # we are following a target, nothing to update on selection change + return global prev_matrix, prev_active_obj if prev_active_obj != bpy.context.object: ## Set stored matrix to active object diff --git a/UI_tools.py b/UI_tools.py index e4f1182..67067d4 100644 --- a/UI_tools.py +++ b/UI_tools.py @@ -281,6 +281,8 @@ class GPTB_PT_anim_manager(Panel): col.use_property_split = False text, icon = ('Cursor Follow On', 'PIVOT_CURSOR') if context.scene.gptoolprops.cursor_follow else ('Cursor Follow Off', 'CURSOR') col.prop(context.scene.gptoolprops, 'cursor_follow', text=text, icon=icon) + if context.scene.gptoolprops.cursor_follow: + col.prop(context.scene.gptoolprops, 'cursor_follow_target', text='Target', icon='OBJECT_DATA') class GPTB_PT_toolbox_playblast(Panel): diff --git a/properties.py b/properties.py index 38da8dd..94c3534 100755 --- a/properties.py +++ b/properties.py @@ -178,6 +178,11 @@ class GP_PG_ToolsSettings(PropertyGroup): name='Cursor Follow', description="3D cursor follow active object animation when activated", default=False, update=cursor_follow_update) + cursor_follow_target : bpy.props.PointerProperty( + name='Cursor Follow Target', + description="Optional target object to follow for cursor instead of active object", + type=bpy.types.Object, update=cursor_follow_update) + ## gpv3 : no edit line color anymore # edit_lines_opacity : FloatProperty( # name="Edit Lines Opacity", description="Change edit lines opacity for all grease pencils",