Pack picker

blender3.6
ChristopheSeux 2022-04-12 18:14:56 +02:00
parent 89941a9d30
commit ee03c36c01
4 changed files with 71 additions and 20 deletions

View File

@ -24,7 +24,7 @@ modules = [
] ]
functions = [ functions = [
'.func_picker', #'.func_picker',
'.func_shape', '.func_shape',
'.snapping_utils', '.snapping_utils',
'.utils' '.utils'

View File

@ -8,7 +8,8 @@ import gpu
import bgl import bgl
from mathutils import Vector from mathutils import Vector
from gpu_extras.batch import batch_for_shader from gpu_extras.batch import batch_for_shader
from pathlib import Path
import json
vertex_shader = ''' vertex_shader = '''
@ -79,6 +80,13 @@ def draw_callback(self):
bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_BLEND)
def is_picker_space(context):
sp = context.space_data
if sp and (sp.type == 'NODE_EDITOR' and sp.tree_type == 'RigPickerTree'):
return True
return False
class RP_OT_box_select(bpy.types.Operator): class RP_OT_box_select(bpy.types.Operator):
"""Tooltip""" """Tooltip"""
@ -92,9 +100,7 @@ class RP_OT_box_select(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
sp = context.space_data if not is_picker_space(context):
if not sp.tree_type == 'RigPickerTree':
return return
ob = context.object ob = context.object
@ -276,7 +282,7 @@ class RP_OT_toogle_bone_layer(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
if not context.space_data.tree_type == 'RigPickerTree': if not is_picker_space(context):
return return
ob = context.object ob = context.object
@ -306,6 +312,35 @@ class RP_OT_toogle_bone_layer(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
class RP_OT_pack_picker(bpy.types.Operator):
"""Pack Unpack the picker on the rig"""
bl_idname = "rigpicker.pack_picker"
bl_label = 'Toogle Bone Layer'
@classmethod
def poll(cls, context):
ob = context.object
return (ob and ob.type == 'ARMATURE' and ob.data.rig_picker.source)
def execute(self, context):
print('Pack Picker')
ob = context.object
picker_src = Path(bpy.path.abspath(ob.data.rig_picker.source, library=ob.data.library))
if 'picker' in ob.data.rig_picker.keys():
del ob.data.rig_picker['picker']
return {"FINISHED"}
if not picker_src.exists():
self.report({"ERROR"}, f'The path of the picker not exist: {picker_src}')
return {"CANCELLED"}
ob.data.rig_picker['picker'] = json.loads(picker_src.read_text())
return {"FINISHED"}
class RP_OT_call_operator(bpy.types.Operator): class RP_OT_call_operator(bpy.types.Operator):
bl_idname = "rigpicker.call_operator" bl_idname = "rigpicker.call_operator"
bl_label = 'Toogle Bone Layer' bl_label = 'Toogle Bone Layer'
@ -314,14 +349,16 @@ class RP_OT_call_operator(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
sp = context.space_data return is_picker_space(context)
return (sp.type=='NODE_EDITOR' and sp.tree_type != 'RigPickerTree')
def execute(self, context): def execute(self, context):
print('CALL OPERATOR', self.operator) print('CALL OPERATOR', self.operator)
try:
exec(self.operator) exec(self.operator)
except Exception as e:
self.report({"ERROR"}, e)
context.region.tag_redraw() context.region.tag_redraw()
@ -330,7 +367,7 @@ class RP_OT_call_operator(bpy.types.Operator):
class RP_MT_context_menu(bpy.types.Menu): class RP_MT_context_menu(bpy.types.Menu):
bl_label = "Context Menu" bl_label = "Context Menu"
bl_idname = "rigpicker.context_menu" #bl_idname = "RP_MT_context_menu"
# Set the menu operators and draw functions # Set the menu operators and draw functions
def draw(self, context): def draw(self, context):
@ -486,7 +523,7 @@ def register_keymaps():
keymaps.append((km, kmi)) keymaps.append((km, kmi))
kmi = km.keymap_items.new("wm.call_menu", type="RIGHTMOUSE", value="PRESS") kmi = km.keymap_items.new("wm.call_menu", type="RIGHTMOUSE", value="PRESS")
kmi.properties.name = "rigpicker.context_menu" kmi.properties.name = "RP_MT_context_menu"
keymaps.append((km, kmi)) keymaps.append((km, kmi))
kmi = km.keymap_items.new("node.rp_box_select", type="LEFTMOUSE", value="PRESS") kmi = km.keymap_items.new("node.rp_box_select", type="LEFTMOUSE", value="PRESS")
@ -515,7 +552,8 @@ classes = (
RP_OT_toogle_bone_layer, RP_OT_toogle_bone_layer,
RP_OT_call_operator, RP_OT_call_operator,
RP_MT_context_menu, RP_MT_context_menu,
RP_OT_move_bone RP_OT_move_bone,
RP_OT_pack_picker
#RP_OT_ui_draw #RP_OT_ui_draw
) )

View File

@ -29,7 +29,12 @@ class RP_PT_picker_maker_panel(bpy.types.Panel):
col.prop_search(scn.rig_picker, 'symmetry', scn, 'objects', text='Symmetry ') col.prop_search(scn.rig_picker, 'symmetry', scn, 'objects', text='Symmetry ')
if ob.type == 'ARMATURE': if ob.type == 'ARMATURE':
layout.prop(ob.data.rig_picker, 'source', text='Picker') row = layout.row(align=True)
is_packed = ('picker' in ob.data.rig_picker.keys())
sub_row = row.row(align=True)
sub_row.prop(ob.data.rig_picker, 'source', text='Picker')
sub_row.enabled = not is_packed
row.operator('rigpicker.pack_picker', icon='PACKAGE' if is_packed else 'UGLYPACKAGE', text='')
col = layout.column(align=True) col = layout.column(align=True)

View File

@ -523,7 +523,7 @@ class Picker:
def draw_callback_view(): def draw_callback_view():
sp = bpy.context.space_data sp = bpy.context.space_data
if not sp.tree_type == 'RigPickerTree': if not sp or not sp.tree_type == 'RigPickerTree':
return return
ob = bpy.context.object ob = bpy.context.object
@ -531,7 +531,15 @@ def draw_callback_view():
return return
if ob not in PICKERS: if ob not in PICKERS:
if 'picker' in ob.data.rig_picker:
picker_datas = [s.to_dict() for s in ob.data.rig_picker['picker']]
else:
picker_path = Path(bpy.path.abspath(ob.data.rig_picker.source, library=ob.data.library)) picker_path = Path(bpy.path.abspath(ob.data.rig_picker.source, library=ob.data.library))
if not picker_path.exists():
print(f'Picker path not exists: {picker_path.resolve()}')
return
print('Load picker from', picker_path.resolve()) print('Load picker from', picker_path.resolve())
picker_datas = json.loads(picker_path.read_text()) picker_datas = json.loads(picker_path.read_text())
#shapes = [s.to_dict() for s in ob.data.rig_picker['shapes']] #shapes = [s.to_dict() for s in ob.data.rig_picker['shapes']]