Newer
Older
Thomas Larsson
committed
row.label("")
row.label("Left")
row.label("Right")
Thomas Larsson
committed
layout.label("FK/IK switch")
Thomas Larsson
committed
row = layout.row()
row.label("Arm")
self.toggleButton(row, rig, "&ArmIk_L", " 3", " 2")
self.toggleButton(row, rig, "&ArmIk_R", " 19", " 18")
row = layout.row()
row.label("Leg")
self.toggleButton(row, rig, "&LegIk_L", " 5", " 4")
self.toggleButton(row, rig, "&LegIk_R", " 21", " 20")
layout.label("Snap Arm bones")
Thomas Larsson
committed
row = layout.row()
row.label("FK Arm")
row.operator("mhx.snap_fk_ik", text="Snap L FK Arm").data = "&ArmIk_L 2 3 12"
row.operator("mhx.snap_fk_ik", text="Snap R FK Arm").data = "&ArmIk_R 18 19 28"
Thomas Larsson
committed
row = layout.row()
row.label("IK Arm")
row.operator("mhx.snap_ik_fk", text="Snap L IK Arm").data = "&ArmIk_L 2 3 12"
row.operator("mhx.snap_ik_fk", text="Snap R IK Arm").data = "&ArmIk_R 18 19 28"
Thomas Larsson
committed
layout.label("Snap Leg bones")
Thomas Larsson
committed
row = layout.row()
row.label("FK Leg")
row.operator("mhx.snap_fk_ik", text="Snap L FK Leg").data = "&LegIk_L 4 5 12"
row.operator("mhx.snap_fk_ik", text="Snap R FK Leg").data = "&LegIk_R 20 21 28"
row = layout.row()
row.label("IK Leg")
row.operator("mhx.snap_ik_fk", text="Snap L IK Leg").data = "&LegIk_L 4 5 12"
row.operator("mhx.snap_ik_fk", text="Snap R IK Leg").data = "&LegIk_R 20 21 28"
row = layout.row()
row.label("Show")
row.prop(rig.data, "layers", index=12, toggle=True, text="L Ankle")
row.prop(rig.data, "layers", index=28, toggle=True, text="R Ankle")
Thomas Larsson
committed
Thomas Larsson
committed
row = layout.row()
row.operator("mhx.set_inverse")
row.operator("mhx.clear_inverse")
Thomas Larsson
committed
Thomas Larsson
committed
def toggleButton(self, row, rig, prop, fk, ik):
if rig[prop] > 0.5:
row.operator("mhx.toggle_fk_ik", text="IK").toggle = prop + " 0" + fk + ik
else:
row.operator("mhx.toggle_fk_ik", text="FK").toggle = prop + " 1" + ik + fk
###################################################################################
#
# Posing panel
#
###################################################################################
#
# class MhxDriversPanel(bpy.types.Panel):
#
class MhxDriversPanel(bpy.types.Panel):
bl_label = "MHX Drivers"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return pollMhxRig(context.object)
def draw(self, context):
lProps = []
rProps = []
props = []
plist = list(context.object.keys())
plist.sort()
for prop in plist:
Thomas Larsson
committed
if prop[0] == '&':
prop1 = prop[1:]
else:
continue
if prop[-2:] == '_L':
Thomas Larsson
committed
lProps.append((prop, prop1[:-2]))
elif prop[-2:] == '_R':
Thomas Larsson
committed
rProps.append((prop, prop1[:-2]))
Thomas Larsson
committed
props.append((prop, prop1))
ob = context.object
layout = self.layout
Thomas Larsson
committed
for (prop, pname) in props:
layout.prop(ob, '["%s"]' % prop, text=pname)
layout.label("Left")
for (prop, pname) in lProps:
layout.prop(ob, '["%s"]' % prop, text=pname)
layout.label("Right")
for (prop, pname) in rProps:
layout.prop(ob, '["%s"]' % prop, text=pname)
return
###################################################################################
#
# Visibility panel
#
###################################################################################
#
# class MhxVisibilityPanel(bpy.types.Panel):
#
class MhxVisibilityPanel(bpy.types.Panel):
bl_label = "MHX Visibility"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return pollMhxRig(context.object)
def draw(self, context):
ob = context.object
Thomas Larsson
committed
layout = self.layout
props = list(ob.keys())
props.sort()
for prop in props:
if prop[0:4] == "Hide":
Thomas Larsson
committed
layout.prop(ob, '["%s"]' % prop)
layout.separator()
layout.operator("mhx.update_textures")
layout.separator()
layout.operator("mhx.add_hiders")
layout.operator("mhx.remove_hiders")
Thomas Larsson
committed
class VIEW3D_OT_MhxUpdateTexturesButton(bpy.types.Operator):
bl_idname = "mhx.update_textures"
bl_label = "Update"
def execute(self, context):
scn = context.scene
for mat in bpy.data.materials:
if mat.animation_data:
try:
mat["MhxDriven"]
except:
continue
for driver in mat.animation_data.drivers:
prop = mat.path_resolve(driver.data_path)
value = driver.evaluate(scn.frame_current)
#print("Update %s[%d] = %s" % (driver.data_path, driver.array_index, value))
prop[driver.array_index] = value
return{'FINISHED'}
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
class VIEW3D_OT_MhxAddHidersButton(bpy.types.Operator):
bl_idname = "mhx.add_hiders"
bl_label = "Add Hide Property"
def execute(self, context):
rig = context.object
for ob in context.scene.objects:
if ob.select and ob != rig:
prop = "Hide%s" % ob.name
rig[prop] = False
addHider(ob, "hide", rig, prop)
addHider(ob, "hide_render", rig, prop)
return{'FINISHED'}
def addHider(ob, attr, rig, prop):
fcu = ob.driver_add(attr)
drv = fcu.driver
drv.type = 'SCRIPTED'
drv.expression = "x"
drv.show_debug_info = True
var = drv.variables.new()
var.name = "x"
targ = var.targets[0]
targ.id = rig
targ.data_path = '["%s"]' % prop
return
class VIEW3D_OT_MhxRemoveHidersButton(bpy.types.Operator):
bl_idname = "mhx.remove_hiders"
bl_label = "Remove Hide Property"
Thomas Larsson
committed
def execute(self, context):
rig = context.object
for ob in context.scene.objects:
if ob.select and ob != rig:
ob.driver_remove("hide")
ob.driver_remove("hide_render")
del rig["Hide%s" % ob.name]
return{'FINISHED'}
###################################################################################
#
# Layers panel
#
###################################################################################
MhxLayers = [
(( 0, 'Root', 'MhxRoot'),
( 8, 'Face', 'MhxFace')),
(( 9, 'Tweak', 'MhxTweak'),
(10, 'Head', 'MhxHead')),
(( 1, 'FK Spine', 'MhxFKSpine'),
(17, 'IK Spine', 'MhxIKSpine')),
((13, 'Inv FK Spine', 'MhxInvFKSpine'),
(16, 'Clothes', 'MhxClothes')),
('Left', 'Right'),
(( 2, 'IK Arm', 'MhxIKArm'),
(18, 'IK Arm', 'MhxIKArm')),
(( 3, 'FK Arm', 'MhxFKArm'),
(19, 'FK Arm', 'MhxFKArm')),
(( 4, 'IK Leg', 'MhxIKLeg'),
(20, 'IK Leg', 'MhxIKLeg')),
(( 5, 'FK Leg', 'MhxFKLeg'),
(21, 'FK Leg', 'MhxFKLeg')),
((12, 'Extra', 'MhxExtra'),
(28, 'Extra', 'MhxExtra')),
(( 6, 'Fingers', 'MhxFingers'),
(22, 'Fingers', 'MhxFingers')),
(( 7, 'Links', 'MhxLinks'),
(23, 'Links', 'MhxLinks')),
((11, 'Palm', 'MhxPalm'),
(27, 'Palm', 'MhxPalm')),
]
#
# class MhxLayersPanel(bpy.types.Panel):
#
class MhxLayersPanel(bpy.types.Panel):
bl_label = "MHX Layers"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
#bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return pollMhxRig(context.object)
def draw(self, context):
layout = self.layout
Thomas Larsson
committed
layout.operator("mhx.pose_enable_all_layers")
layout.operator("mhx.pose_disable_all_layers")
amt = context.object.data
for (left,right) in MhxLayers:
row = layout.row()
if type(left) == str:
row.label(left)
row.label(right)
else:
for (n, name, prop) in [left,right]:
row.prop(amt, "layers", index=n, toggle=True, text=name)
return
Thomas Larsson
committed
class VIEW3D_OT_MhxEnableAllLayersButton(bpy.types.Operator):
bl_idname = "mhx.pose_enable_all_layers"
bl_label = "Enable all layers"
def execute(self, context):
rig = getMhxRig(context.object)
for (left,right) in MhxLayers:
if type(left) != str:
for (n, name, prop) in [left,right]:
Thomas Larsson
committed
rig.data.layers[n] = True
return{'FINISHED'}
class VIEW3D_OT_MhxDisableAllLayersButton(bpy.types.Operator):
bl_idname = "mhx.pose_disable_all_layers"
bl_label = "Disable all layers"
def execute(self, context):
rig = getMhxRig(context.object)
layers = 32*[False]
pb = context.active_pose_bone
if pb:
for n in range(32):
if pb.bone.layers[n]:
layers[n] = True
break
else:
layers[0] = True
rig.data.layers = layers
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
return{'FINISHED'}
###################################################################################
#
# Common functions
#
###################################################################################
#
# pollMhxRig(ob):
# getMhxRig(ob):
#
def pollMhxRig(ob):
try:
return (ob["MhxRig"] == "MHX")
except:
return False
def getMhxRig(ob):
if ob.type == 'ARMATURE':
rig = ob
elif ob.type == 'MESH':
rig = ob.parent
else:
return None
try:
if (rig["MhxRig"] == "MHX"):
return rig
else:
return None
except:
return None
#
# setInterpolation(rig):
#
def setInterpolation(rig):
if not rig.animation_data:
return
act = rig.animation_data.action
if not act:
return
for fcu in act.fcurves:
for pt in fcu.keyframe_points:
pt.interpolation = 'LINEAR'
fcu.extrapolation = 'CONSTANT'
return
###################################################################################
#
# initialize and register
#
###################################################################################
def menu_func(self, context):
self.layout.operator(ImportMhx.bl_idname, text="MakeHuman (.mhx)...")
Campbell Barton
committed
bpy.utils.register_module(__name__)
Thomas Larsson
committed
bpy.utils.unregister_module(__name__)
Thomas Larsson
committed
try:
bpy.types.INFO_MT_file_import.remove(menu_func)
except:
pass
if __name__ == "__main__":
unregister()