142 lines
5.7 KiB
Python
142 lines
5.7 KiB
Python
|
import bpy
|
||
|
from bpy.types import UIList
|
||
|
#import collections
|
||
|
#import inspect
|
||
|
from .core.addon_utils import get_operator_from_id
|
||
|
from .core.bl_utils import get_mat
|
||
|
|
||
|
import re
|
||
|
|
||
|
|
||
|
# class RP_UL_picker_source(UIList):
|
||
|
# def draw_item(self, context, layout, data, item, _icon, _active_data, _active_propname, _index):
|
||
|
# ob = context.object
|
||
|
# row = layout.row(align=True)
|
||
|
# is_packed = ('picker' in ob.data.rig_picker.keys())
|
||
|
# sub_row = row.row(align=True)
|
||
|
# sub_row.prop(item, 'source', text='')
|
||
|
# sub_row.enabled = not is_packed
|
||
|
# #row.operator('rigpicker.pack_picker', icon='PACKAGE' if is_packed else 'UGLYPACKAGE', text='')
|
||
|
|
||
|
|
||
|
class RP_PT_picker_maker_panel(bpy.types.Panel):
|
||
|
bl_label = 'Rig Picker'
|
||
|
bl_category = 'Rigging'
|
||
|
bl_space_type = 'VIEW_3D'
|
||
|
bl_region_type = 'UI'
|
||
|
|
||
|
@classmethod
|
||
|
def poll(cls, context):
|
||
|
return context.object
|
||
|
|
||
|
def draw(self, context):
|
||
|
ob = context.object
|
||
|
scn = context.scene
|
||
|
collection = next((c for c in ob.users_collection if c.rig_picker.enabled), None)
|
||
|
|
||
|
layout = self.layout
|
||
|
col = layout.column(align=False)
|
||
|
|
||
|
if collection:
|
||
|
col.prop_search(collection.rig_picker, 'rig', scn, 'objects', text='Rig ')
|
||
|
col.prop_search(collection.rig_picker, 'canvas', scn, 'objects', text='Canvas ')
|
||
|
col.prop_search(collection.rig_picker, 'symmetry', scn, 'objects', text='Symmetry ')
|
||
|
|
||
|
if ob.type == 'ARMATURE':
|
||
|
box = col.box()
|
||
|
box.enabled = not ob.data.library
|
||
|
col = box.column(align=False)
|
||
|
|
||
|
row = col.row(align=True)
|
||
|
row.separator(factor=0.5)
|
||
|
row.label(text="Sources")
|
||
|
|
||
|
is_packed = ('picker' in ob.data.rig_picker.keys())
|
||
|
row.operator('rigpicker.pack_picker', icon='PACKAGE' if is_packed else 'UGLYPACKAGE', text='', emboss=False)
|
||
|
row.operator("rigpicker.add_picker_source", icon ='ADD', text="", emboss=False)
|
||
|
|
||
|
for i, item in enumerate(ob.data.rig_picker.sources):
|
||
|
row = col.row(align=True)
|
||
|
is_packed = ('pickers' in ob.data.rig_picker.keys())
|
||
|
row.prop(item, 'source', text='')
|
||
|
row.operator("rigpicker.remove_picker_source", icon ='PANEL_CLOSE', text="", emboss=False).index=i
|
||
|
|
||
|
if collection:
|
||
|
#if context.collection and context.collection.rig_picker.enabled:
|
||
|
col = layout.column(align=True)
|
||
|
row = col.row(align=True)
|
||
|
row.operator('rigpicker.create_shape', icon='MESH_DATA', text='Create shape')
|
||
|
row.operator('rigpicker.mirror_shape', icon='MOD_MIRROR', text='Mirror shape')
|
||
|
col.operator('rigpicker.name_from_bone', icon='SORTALPHA' , text='Name from bones')
|
||
|
col.prop(scn.rig_picker, 'use_pick_bone', icon='EYEDROPPER', text='Auto bone assign')
|
||
|
|
||
|
if ob.type != 'ARMATURE':
|
||
|
box = layout.box()
|
||
|
col = box.column(align=False)
|
||
|
|
||
|
material_row = col.row(align=True)
|
||
|
material_row.operator('rigpicker.remove_mat', icon='REMOVE', text='')
|
||
|
material_row.operator('rigpicker.add_mat', icon='ADD', text='')
|
||
|
mat = False
|
||
|
if ob.type in ('MESH', 'CURVE', 'FONT') and ob.data.materials:
|
||
|
mat = get_mat(ob)
|
||
|
if mat and mat.node_tree:
|
||
|
emission_nodes = [n for n in mat.node_tree.nodes if n.type =='EMISSION']
|
||
|
if emission_nodes:
|
||
|
material_row.prop(emission_nodes[0].inputs[0], 'default_value', text='')
|
||
|
mat = True
|
||
|
if not mat:
|
||
|
material_row.label(text='No Material')
|
||
|
material_row.operator('rigpicker.eyedropper_mat', icon='EYEDROPPER', text='')
|
||
|
|
||
|
shape_type_row = col.row(align=True)
|
||
|
shape_type_row.prop(ob.rig_picker,'shape_type',expand = True)
|
||
|
shape_type_row.operator('rigpicker.select_shape_type', text='', icon='RESTRICT_SELECT_OFF')
|
||
|
|
||
|
|
||
|
if ob.rig_picker.shape_type == 'OPERATOR':
|
||
|
|
||
|
op_row = col.row(align=True)
|
||
|
op_row.prop(ob.rig_picker, 'operator', text='')
|
||
|
op_row.operator('rigpicker.operator_selector', text='', icon='COLLAPSEMENU')
|
||
|
|
||
|
if ob.rig_picker.operator:
|
||
|
col.prop(ob.rig_picker, 'name', text='Tooltip')
|
||
|
col.prop(ob.rig_picker,'shortcut', text='Shortcut')
|
||
|
|
||
|
else:
|
||
|
col.prop(ob.rig_picker, 'name', text='Tooltip')
|
||
|
|
||
|
'''
|
||
|
if ob.rig_picker.operator:
|
||
|
op = get_operator_from_id(ob.rig_picker.idname)
|
||
|
if op:
|
||
|
doc = re.findall(r'\(([^\)]+)\)', op.__doc__)[0]
|
||
|
else:
|
||
|
doc = 'Operator not found'
|
||
|
|
||
|
col.prop(ob.rig_picker,'name', text='Tooltip')
|
||
|
if op:
|
||
|
col.prop(ob.rig_picker,'shortcut', text='Shortcut')
|
||
|
col.prop(ob.rig_picker,'arguments', text='')
|
||
|
col.label(text=doc)
|
||
|
else:
|
||
|
col.label(text=doc)
|
||
|
'''
|
||
|
|
||
|
|
||
|
if ob.rig_picker.shape_type == 'BONE':
|
||
|
if collection and collection.rig_picker.rig:
|
||
|
col.prop_search(ob.rig_picker, 'name', collection.rig_picker.rig.pose, 'bones', text='Bone')
|
||
|
|
||
|
#layout.separator()
|
||
|
layout.prop(collection.rig_picker, 'destination', text='Filepath')
|
||
|
layout.operator('rigpicker.save_picker', icon='PASTEDOWN', text='Save Picker')
|
||
|
|
||
|
|
||
|
classes = (
|
||
|
#RP_UL_picker_source,
|
||
|
RP_PT_picker_maker_panel,
|
||
|
)
|
||
|
|
||
|
register, unregister = bpy.utils.register_classes_factory(classes)
|