/
rig_spline.py
111 lines (89 loc) · 3.14 KB
/
rig_spline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pymel.all as pm
from tree import TreeNode
# from chain_basic import Jointchain
from rig_basic import *
from rig_ikfk import FkRig
from controls import *
import controls
import utils, settings
class SplineIkRig( BasicRig ) :
PARTNAME = 'splineRig'
def create( self, _jointchain=None ) :
super( SplineIkRig, self ).create( _jointchain )
jointchain = self.tree_children( 'jointchain' )[0]
# get start and end joints
rigjoints = jointchain.rigjoints
# # create controls and store start/end controls/rigjoints
controlsdriverslist = []
for i, rigjoint in enumerate( [ rigjoints[0], rigjoints[-1] ] ) :
# create control
control = RigControl( n=rigjoint.name() )
control.setRotationOrder(
utils.aim_axis_to_rotate_order( settings.rotationorder ),
False
)
control.position_to_object( rigjoint )
self.add_child( control )
# create driver joint and store it with it's corresponding control
driverrigjoint = rigjoint.duplicate(
n=utils.name_from_tags( rigjoint, 'spline', 'driver' )
)[0]
self.add_child( driverrigjoint )
controlsdriverslist.append( ( control, driverrigjoint ) )
startjoint = jointchain.rigjoints[0]
startdriver = controlsdriverslist[0][1]
endjoint = jointchain.rigjoints[-1]
enddriver = controlsdriverslist[-1][1]
# create ik spline between them
ikhandlename = utils.name_from_tags( startjoint, 'ikhandle' )
ikhandle, ikeffector, ikcurve = pm.ikHandle(
startJoint=startjoint,
endEffector=endjoint,
solver='ikSplineSolver',
numSpans=len( jointchain.rigjoints ) - 1,
name=ikhandlename
)
ikeffector.rename( utils.name_from_tags( endjoint, 'ikeffector' ) )
ikcurve.rename( utils.name_from_tags( startjoint, 'curve' ) )
self.add_child( ikhandle )
self.add_child( ikcurve )
# bind curve to driver joints
tobind = [ ikcurve ] + [ i[1] for i in controlsdriverslist ]
pm.skinCluster(
tobind,
bindMethod=0,
maximumInfluences=len( tobind ) - 1,
)
# set twist control
ikhandle.dTwistControlEnable.set( True )
ikhandle.dWorldUpType.set( 4 )
startdriver.worldMatrix[0] >> ikhandle.dWorldUpMatrix
enddriver.worldMatrix[0] >> ikhandle.dWorldUpMatrixEnd
# parent drivers to controls
for control, driver in controlsdriverslist :
pm.parentConstraint(
[ control, driver ],
mo=False
)
class SplineIkFkRig( BaseRig ) :
PARTNAME = 'splineRig'
def __init__( self ) :
super( SplineIkFkRig, self ).__init__()
self.splineikrig = SplineIkRig()
self.add_child( self.splineikrig )
self.fkrig = FkRig()
self.add_child( self.fkrig )
def create( self, _jointchain=None ) :
# print self.tree_root()
self.splineikrig.create( _jointchain )
self.fkrig.create( _jointchain )
# now we'll connect the two rigs
# first hide the start and end controls of teh fkrig
self.fkrig.tree_children( 'rigControl' )[0].zero_group().hide()
self.fkrig.tree_children( 'rigControl' )[-1].zero_group().hide()
# now we can parent the upper spline control to the last fk rigjoint
pm.parentConstraint(
[ self.fkrig.tree_children( 'jointchain' )[0].rigjoints[-1],
self.splineikrig.tree_children( 'rigControl' )[-1].zero_group() ],
mo=True
)