Finalize baton rig

This commit is contained in:
Alan O'Cull 2024-02-20 22:19:11 -05:00
parent 440a6715a9
commit 5e084cc96e
2 changed files with 31 additions and 36 deletions

BIN
characters/infantry/p9-lopoly.blend (Stored with Git LFS)

Binary file not shown.

View File

@ -2,6 +2,9 @@ import bpy
from bpy.types import Constraint, PoseBone from bpy.types import Constraint, PoseBone
rig = bpy.data.objects["infantry"] rig = bpy.data.objects["infantry"]
BGRP_SPECIAL = 2
BGRP_TWEAK = 3
BGRP_EXTRA = 4
## FIX PARENTS ## FIX PARENTS
def reparent(b: str, newParent: str = 'DEF-spine'): def reparent(b: str, newParent: str = 'DEF-spine'):
@ -103,7 +106,7 @@ def drv_constraint_1D(c: Constraint, bone_name: str, max_x: float, prop: str = '
t.bone_target = bone_name t.bone_target = bone_name
t.transform_type = prop t.transform_type = prop
t.transform_space = 'LOCAL_SPACE' t.transform_space = 'LOCAL_SPACE'
def drv_toggle_1D(): def drv_toggle_1D(a: PoseBone, b: PoseBone, slider: PoseBone):
pass pass
def constrain_slider(b: PoseBone, minimum: float = 0, maximum: float = 0.06): def constrain_slider(b: PoseBone, minimum: float = 0, maximum: float = 0.06):
c = b.constraints.new('LIMIT_LOCATION') c = b.constraints.new('LIMIT_LOCATION')
@ -130,6 +133,7 @@ for b in rig.pose.bones:
b.custom_shape_translation = (0.0, 0.03, 0.0) b.custom_shape_translation = (0.0, 0.03, 0.0)
b.custom_shape_scale_xyz = (0.06, 0.06, 0.0) b.custom_shape_scale_xyz = (0.06, 0.06, 0.0)
arrcopy(b.lock_scale, [False, True, False]) arrcopy(b.lock_scale, [False, True, False])
b.bone_group_index = BGRP_EXTRA
elif b.name.startswith("slider1d"): elif b.name.startswith("slider1d"):
b.use_custom_shape_bone_size = False b.use_custom_shape_bone_size = False
b.custom_shape_scale_xyz = (0.02, 0.003, 0.005) b.custom_shape_scale_xyz = (0.02, 0.003, 0.005)
@ -138,54 +142,45 @@ for b in rig.pose.bones:
arrcopy(b.lock_rotation, [True, True, True]) arrcopy(b.lock_rotation, [True, True, True])
arrcopy(b.lock_scale, [True, True, True]) arrcopy(b.lock_scale, [True, True, True])
b.lock_rotation_w = True b.lock_rotation_w = True
b.bone_group_index = BGRP_SPECIAL
## WEAPONS ## WEAPONS
elif b.name.endswith("_slide"):
b.bone_group_index = BGRP_TWEAK
b.custom_shape_scale_xyz = (2.0, 2.0, 2.0)
arrcopy(b.lock_location, [True, False, True])
arrcopy(b.lock_scale, [True, True, True])
arrcopy(b.lock_rotation, [False, False, True])
### BATON
elif b.name.startswith("grip_baton"): elif b.name.startswith("grip_baton"):
b.custom_shape_scale_xyz = (0.2, 2.6, 0.2) b.custom_shape_scale_xyz = (0.2, 2.6, 0.2)
b.custom_shape_translation = (0.0, 0.25, 0.0) b.custom_shape_translation = (0.0, 0.25, 0.0)
if not b.name.endswith("_free"): if b.name.endswith("_constrained"):
b.custom_shape_scale_xyz *= 0.9 b.custom_shape_scale_xyz *= 0.9
b.bone_group_index = BGRP_EXTRA
elif b.name == "baton_handR_grip":
b.custom_shape_scale_xyz = (0.2, 1.0, 0.8)
## BODY ## BODY
elif b.name == "neck.001": elif b.name == "neck.001":
arrcopy(b.lock_location, [True, True, True]) arrcopy(b.lock_location, [True, True, True])
## Constrain menu sliders so they are limited to proper bounds
#constrain_slider(rig.pose.bones.get('slider1d_axe_gripadjust'))
#constrain_slider(rig.pose.bones.get('slider1d_axe_lefthand_grip'))
#constrain_slider(rig.pose.bones.get('slider1d_axe_smear'), -0.03, 0.03)
## Arm and Hand switch for Axe Base # Constrain slider widgets
## https://blender.stackexchange.com/questions/46928/set-bone-constraints-via-python-api#46986 constrain_slider(rig.pose.bones.get('slider1d_baton_constrain'), 0.0, 0.06)
#axe_base = rig.pose.bones.get("axe_base") constrain_slider(rig.pose.bones.get('slider1d_baton_handIK'), 0.0, 0.06)
#axe_constraint: Constraint = None
#if axe_base is not None:
# axe_constraint = axe_base.constraints.new('COPY_TRANSFORMS')
# axe_constraint.target = rig
# axe_constraint.subtarget = 'DEF-hand.R' # note subtarget uses name not object
# axe_constraint.target_space = 'POSE'
# axe_constraint.owner_space = 'POSE'
# axe_constraint.influence = 0.0
## Left-Hand grip switch for Axe
#left_hand = rig.pose.bones.get("hand_ik.L")
#lh_constraint: Constraint = None
#if axe_base is not None:
# lh_constraint = left_hand.constraints.new('COPY_TRANSFORMS')
# lh_constraint.target = rig
# lh_constraint.subtarget = 'axe_grip_lefthand' # note subtarget uses name not object
# lh_constraint.target_space = 'POSE'
# lh_constraint.owner_space = 'POSE'
# lh_constraint.influence = 0.0
# Switch Baton Grip's bound parent, default parent to arm, but can switch to separate control
baton_grip = rig.pose.bones.get("grip_baton") baton_grip = rig.pose.bones.get("grip_baton")
bg_constraint = cpy_transforms(baton_grip, 'grip_baton_free', 1.0) cpy_transforms(baton_grip, 'grip_baton_constrained', 1.0) # Default to hand grip
bg_constraint = cpy_transforms(baton_grip, 'grip_baton_free', 0.0)
drv_constraint_1D(bg_constraint, 'slider1d_baton_constrain', 0.06)
drv_constrain_1D(bg_constraint, 'slider1d_baton_IK-FK', 0.06) # Align right hand to baton grip
rightHand = rig.pose.bones.get("MCH-upper_arm_ik_target.R")
### Set up driver constraint for the switches bh_constraint = cpy_transforms(rightHand, 'baton_handR_grip', 0.0) # Default to hand grip
#drv_constraint_1D(axe_constraint, 'slider1d_axe_gripadjust', 0.06) drv_constraint_1D(bh_constraint, 'slider1d_baton_handIK', 0.06)
#drv_constraint_1D(lh_constraint, 'slider1d_axe_lefthand_grip', 0.06)
### Set up smear effect drivers for axe ### Set up smear effect drivers for axe
#drv_blend_1D('Key', 'smear_down', 'slider1d_axe_smear', 0.03) #drv_blend_1D('Key', 'smear_down', 'slider1d_axe_smear', 0.03)