More rigging work on Insurrectionist
This commit is contained in:
parent
50074f7dee
commit
277bd92783
Binary file not shown.
@ -1,12 +1,82 @@
|
||||
import bpy
|
||||
from bpy.types import Constraint
|
||||
|
||||
rig = bpy.data.objects["insurrectionist"]
|
||||
|
||||
## FIX PARENTS
|
||||
def reparent(b: str, newParent: str = 'DEF-spine'):
|
||||
rig.data.edit_bones[b].parent = rig.data.edit_bones[newParent]
|
||||
def fix(b: str):
|
||||
p = rig.data.edit_bones[b].parent.name.replace('ORG','DEF')
|
||||
reparent(b, p)
|
||||
|
||||
# Switch to EDIT mode to modify bone hiearchy to be proper for Unreal
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
pass
|
||||
# List of bones that need to be reparented to their deforming counterparts
|
||||
fixList = [
|
||||
# Hands
|
||||
'DEF-thumb01.L',
|
||||
'DEF-index01.L',
|
||||
'DEF-middle01.L',
|
||||
'DEF-ring01.L',
|
||||
'DEF-pinky01.L',
|
||||
'DEF-palm.01.L',
|
||||
'DEF-palm.02.L',
|
||||
'DEF-palm.03.L',
|
||||
'DEF-palm.04.L',
|
||||
|
||||
# Legs
|
||||
'DEF-thigh.L',
|
||||
]
|
||||
# Iterate through and fix each bone
|
||||
for item in fixList:
|
||||
fix(item)
|
||||
if item.endswith('.L'): # If it's left-sided, fix right-side counterparts too
|
||||
fix(item.replace('.L','.R'))
|
||||
|
||||
bpy.ops.object.mode_set(mode='POSE')
|
||||
# Pelvis parents work a little differently
|
||||
reparent('DEF-pelvis.L', 'DEF-spine')
|
||||
reparent('DEF-pelvis.R', 'DEF-spine')
|
||||
|
||||
# Switch into POSE mode to set up animation constraints
|
||||
bpy.ops.object.mode_set(mode='POSE')
|
||||
|
||||
|
||||
## Declare Functions for animation constraints
|
||||
def drv_blend_1D(shape_target: str, key_target: str, bone_name: str, max_x: float, prop: str = 'LOC_Z', formula: str = ''):
|
||||
block = bpy.data.shape_keys[shape_target].key_blocks[key_target]
|
||||
bmin = block.slider_min
|
||||
bmax = block.slider_max
|
||||
|
||||
block.driver_remove('value')
|
||||
fcurve = block.driver_add('value')
|
||||
d = fcurve.driver
|
||||
d.type = 'SCRIPTED'
|
||||
|
||||
if formula == '':
|
||||
d.expression = str(bmax / max_x) + '*x'
|
||||
else:
|
||||
d.expression = formula
|
||||
|
||||
v = d.variables.new()
|
||||
v.name = 'x'
|
||||
v.type = 'TRANSFORMS'
|
||||
t = v.targets[0]
|
||||
t.id = rig
|
||||
t.bone_target = bone_name
|
||||
t.transform_type = prop
|
||||
t.transform_space = 'LOCAL_SPACE'
|
||||
|
||||
|
||||
# Arm and Hand switch for Axe Base
|
||||
# https://blender.stackexchange.com/questions/46928/set-bone-constraints-via-python-api#46986
|
||||
axe_base = rig.pose.bones.get("axe_base")
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user