Compare commits

..

No commits in common. "abb61ca6d45ad9cc059a2edd848c21f1229aaed7" and "f5c20a349925f4852fd32d714401b5342bb1851e" have entirely different histories.

5 changed files with 20 additions and 73 deletions

View File

@ -2,8 +2,6 @@
import bpy import bpy
import mathutils import mathutils
from bpy_extras import view3d_utils from bpy_extras import view3d_utils
from bpy.app.handlers import persistent
from .utils import get_gp_draw_plane, region_to_location, get_view_origin_position from .utils import get_gp_draw_plane, region_to_location, get_view_origin_position
## override all sursor snap shortcut with this in keymap ## override all sursor snap shortcut with this in keymap
@ -107,12 +105,12 @@ def swap_keymap_by_id(org_idname, new_idname):
k.idname = new_idname k.idname = new_idname
# prev_matrix = mathutils.Matrix()
prev_matrix = None prev_matrix = None
# @call_once(bpy.app.handlers.frame_change_post) # @call_once(bpy.app.handlers.frame_change_post)
## used in properties file to register in boolprop update def cursor_follow_update(self,context):
def cursor_follow_update(self, context):
'''append or remove cursor_follow handler according a boolean''' '''append or remove cursor_follow handler according a boolean'''
global prev_matrix global prev_matrix
# imported in properties to register in boolprop update # imported in properties to register in boolprop update
@ -157,35 +155,6 @@ def cursor_follow(scene):
# store for next use # store for next use
prev_matrix = current_matrix.copy() prev_matrix = current_matrix.copy()
prev_active_obj = None
## Add check for object selection change
def selection_changed():
"""Callback function for selection changes"""
if not bpy.context.scene.gptoolprops.cursor_follow:
return
print('select_changed')
global prev_matrix, prev_active_obj
if prev_active_obj != bpy.context.object:
## Set stored matrix to active object
prev_matrix = bpy.context.object.matrix_world
prev_active_obj = bpy.context.object
## Note: Same owner as layer manager (will be removed as well)
def subscribe_object_change():
subscribe_to = (bpy.types.LayerObjects, 'active')
bpy.msgbus.subscribe_rna(
key=subscribe_to,
# owner of msgbus subcribe (for clearing later)
owner=bpy.types.GreasePencilv3, # <-- attach to ID during it's lifetime.
args=(),
notify=selection_changed,
options={'PERSISTENT'},
)
@persistent
def subscribe_object_change_handler(dummy):
subscribe_object_change()
classes = ( classes = (
GPTB_OT_cusor_snap, GPTB_OT_cusor_snap,
@ -194,18 +163,14 @@ GPTB_OT_cusor_snap,
def register(): def register():
for cls in classes: for cls in classes:
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
# swap_keymap_by_id('view3d.cursor3d','view3d.cursor_snap')#auto swap to custom GP snap wrap
## Follow cursor matrix update on object change # swap_keymap_by_id('view3d.cursor3d','view3d.cursor_snap')#auto swap to custom GP snap wrap
# bpy.app.handlers.load_post.append(subscribe_object_change_handler) # select_change
# ## Directly set msgbus to work at first addon activation # select_change
# bpy.app.timers.register(subscribe_object_change, first_interval=1) # select_change
## No need to frame_change_post.append(cursor_follow). Added by property update, when activating 'cursor follow' # bpy.app.handlers.frame_change_post.append(cursor_follow)
def unregister(): def unregister():
# bpy.app.handlers.load_post.remove(subscribe_object_change_handler) # select_change # bpy.app.handlers.frame_change_post.remove(cursor_follow)
# swap_keymap_by_id('view3d.cursor_snap','view3d.cursor3d')#Restore normal snap # swap_keymap_by_id('view3d.cursor_snap','view3d.cursor3d')#Restore normal snap
@ -214,6 +179,4 @@ def unregister():
# force remove handler if it's there at unregister # force remove handler if it's there at unregister
if cursor_follow.__name__ in [hand.__name__ for hand in bpy.app.handlers.frame_change_post]: if cursor_follow.__name__ in [hand.__name__ for hand in bpy.app.handlers.frame_change_post]:
bpy.app.handlers.frame_change_post.remove(cursor_follow) bpy.app.handlers.frame_change_post.remove(cursor_follow)
bpy.msgbus.clear_by_owner(bpy.types.GreasePencilv3)

View File

@ -475,7 +475,7 @@ class GPTB_OT_toggle_hide_gp_modifier(Operator):
for o in pool: for o in pool:
if o.type != 'GREASEPENCIL': if o.type != 'GREASEPENCIL':
continue continue
for m in o.modifiers: for m in o.modifier:
# skip modifier that are not visible in render # skip modifier that are not visible in render
if not m.show_render: if not m.show_render:
continue continue

View File

@ -78,7 +78,7 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
# maybe a more elegant way exists to find all objects users ? # maybe a more elegant way exists to find all objects users ?
# update Gpencil modifier targets # update Gpencil modifier targets
for mod in ob_user.modifiers: for mod in ob_user.modifier:
if not hasattr(mod, 'layer_filter'): if not hasattr(mod, 'layer_filter'):
continue continue
if mod.layer_filter == old: if mod.layer_filter == old:
@ -675,28 +675,14 @@ def obj_layer_name_callback():
# print('inc:', res.group('inc')) # print('inc:', res.group('inc'))
bpy.context.scene.gptoolprops['layer_name'] = res.group('name') bpy.context.scene.gptoolprops['layer_name'] = res.group('name')
## old gpv2
# def subscribe_layer_change():
# subscribe_to = (bpy.types.GreasePencilLayers, "active_index")
# bpy.msgbus.subscribe_rna(
# key=subscribe_to,
# # owner of msgbus subcribe (for clearing later)
# # owner=handle,
# owner=bpy.types.GreasePencil, # <-- can attach to an ID during all it's lifetime...
# # Args passed to callback function (tuple)
# args=(),
# # Callback function for property update
# notify=obj_layer_name_callback,
# options={'PERSISTENT'},
# )
def subscribe_layer_change(): def subscribe_layer_change():
subscribe_to = (bpy.types.GreasePencilv3Layers, "active") subscribe_to = (bpy.types.GreasePencilLayers, "active_index")
bpy.msgbus.subscribe_rna( bpy.msgbus.subscribe_rna(
key=subscribe_to, key=subscribe_to,
# owner of msgbus subcribe (for clearing later) # owner of msgbus subcribe (for clearing later)
# owner=handle, # owner=handle,
owner=bpy.types.GreasePencilv3, # <-- can attach to an ID during all it's lifetime... owner=bpy.types.GreasePencil, # <-- can attach to an ID during all it's lifetime...
# Args passed to callback function (tuple) # Args passed to callback function (tuple)
args=(), args=(),
# Callback function for property update # Callback function for property update
@ -704,7 +690,6 @@ def subscribe_layer_change():
options={'PERSISTENT'}, options={'PERSISTENT'},
) )
@persistent @persistent
def subscribe_layer_change_handler(dummy): def subscribe_layer_change_handler(dummy):
subscribe_layer_change() subscribe_layer_change()
@ -738,7 +723,7 @@ class GPTB_PT_layer_name_ui(bpy.types.Panel):
row = layout.row() row = layout.row()
row.activate_init = True row.activate_init = True
row.label(icon='OUTLINER_DATA_GP_LAYER') row.label(icon='OUTLINER_DATA_GP_LAYER')
row.prop(context.object.data.layers.active, 'name', text='') row.prop(context.object.data.layers.active, 'info', text='')
def add_layer(context): def add_layer(context):
bpy.ops.gpencil.layer_add() bpy.ops.gpencil.layer_add()
@ -851,6 +836,5 @@ def unregister():
for cls in reversed(classes): for cls in reversed(classes):
bpy.utils.unregister_class(cls) bpy.utils.unregister_class(cls)
# Delete layer index trigger # delete layer index trigger
# /!\ can remove msgbus made for other functions or other addons using same owner bpy.msgbus.clear_by_owner(bpy.types.GreasePencil)
bpy.msgbus.clear_by_owner(bpy.types.GreasePencilv3)

View File

@ -26,10 +26,10 @@ class GPT_OT_layer_nav(bpy.types.Operator):
prefs = utils.get_addon_prefs() prefs = utils.get_addon_prefs()
if not prefs.nav_use_fade: if not prefs.nav_use_fade:
if self.direction == 'DOWN': if self.direction == 'DOWN':
utils.iterate_selector(context.object.data.layers, 'active_index', -1, info_attr = 'name') utils.iterate_selector(context.object.data.layers, 'active_index', -1, info_attr = 'info')
if self.direction == 'UP': if self.direction == 'UP':
utils.iterate_selector(context.object.data.layers, 'active_index', 1, info_attr = 'name') utils.iterate_selector(context.object.data.layers, 'active_index', 1, info_attr = 'info')
return {'FINISHED'} return {'FINISHED'}
## get up and down keys for use in modal ## get up and down keys for use in modal
@ -91,12 +91,12 @@ class GPT_OT_layer_nav(bpy.types.Operator):
context.space_data.overlay.gpencil_fade_layer = fade context.space_data.overlay.gpencil_fade_layer = fade
if self.direction == 'DOWN' or ((event.type in self.down_keys) and event.value == 'PRESS'): if self.direction == 'DOWN' or ((event.type in self.down_keys) and event.value == 'PRESS'):
_val = utils.iterate_selector(context.object.data.layers, 'active_index', -1, info_attr = 'name') _val = utils.iterate_selector(context.object.data.layers, 'active_index', -1, info_attr = 'info')
trigger = True trigger = True
if self.direction == 'UP' or ((event.type in self.up_keys) and event.value == 'PRESS'): if self.direction == 'UP' or ((event.type in self.up_keys) and event.value == 'PRESS'):
_val = utils.iterate_selector(context.object.data.layers, 'active_index', 1, info_attr = 'name') _val = utils.iterate_selector(context.object.data.layers, 'active_index', 1, info_attr = 'info')
# utils.iterate_selector(bpy.context.scene.grease_pencil.layers, 'active_index', 1, info_attr = 'name')#layers # utils.iterate_selector(bpy.context.scene.grease_pencil.layers, 'active_index', 1, info_attr = 'info')#layers
trigger = True trigger = True
if trigger: if trigger:

View File

@ -1396,7 +1396,7 @@ def all_object_modifier_enabled(objects) -> bool:
for o in objects: for o in objects:
if o.type != 'GREASEPENCIL': if o.type != 'GREASEPENCIL':
continue continue
for m in o.modifiers: for m in o.modifier:
if m.show_render and not m.show_viewport: if m.show_render and not m.show_viewport:
return False return False
@ -1500,7 +1500,7 @@ def gp_modifier_status(objects) -> tuple((str, str)):
## Skip hided object ## Skip hided object
if o.hide_get() and o.hide_render: if o.hide_get() and o.hide_render:
continue continue
for m in o.modifiers: for m in o.modifier:
if m.show_render and not m.show_viewport: if m.show_render and not m.show_viewport:
off_count += 1 off_count += 1
else: else: