Files
Diabolo/tools/infernal_whip.py

28 lines
1.4 KiB
Python

"""Preserve the old animated whip and bind it to the retargeted right wrist."""
import bpy
def transfer_whip(scene,source,target):
whip=next((o for o in scene.objects if o.type=='MESH' and 'Flexible braided whip' in o.name),None)
if whip is None:return None
transform=target.data.bones['wrist.R'].matrix_local@source.data.bones['wrist.R'].matrix_local.inverted()
if whip.data.shape_keys:
for key in whip.data.shape_keys.key_blocks:
for point in key.data:point.co=transform@point.co
else:
for vertex in whip.data.vertices:vertex.co=transform@vertex.co
# Increase the actual cord radius, retaining its centreline and morph clips.
whip.data.update()
offsets=[vertex.normal.normalized()*.008 for vertex in whip.data.vertices]
if whip.data.shape_keys:
for key in whip.data.shape_keys.key_blocks:
for point,offset in zip(key.data,offsets):point.co+=offset
else:
for vertex,offset in zip(whip.data.vertices,offsets):vertex.co+=offset
whip.parent=target;whip.name='Infernal animated whip';whip.hide_render=False
for modifier in whip.modifiers:
if modifier.type=='ARMATURE':modifier.object=target
if whip.data.shape_keys and whip.data.shape_keys.animation_data:
whip.data.shape_keys.animation_data.action=None
for track in whip.data.shape_keys.animation_data.nla_tracks:track.mute=False
return whip