Ball Rig 1

前言

  1. Create selection List
  2. Add Non-Linear Squash
  3. Create Control Curves
  4. Logical Parenting of the controllers
  5. Work on wiring the stretch squash factors with the translate values
  6. Create an interface

Source Code

1
2
3
4
5
6
7
8
9
10
import maya.cmds as cmds
selectedBall=cmds.ls(sl=True)
bb=cmds.xform(selectedBall,q=True,ws=True,bb=True)
height=bb[4]-bb[1] #ymax-ymin
radius=height/2
cmds.xform(selectedBall,a=True,t=(0,radius,0),cp=True) #move object to center
strechSquash=cmds.nonLinear(selectedBall,typ="squash",lowBound=0,highBound=2)
cmds.xform(strechSquash,a=True,t=(0,0,0),cp=True)

程式說明

1.
bb=cmds.xform(selectedBall,q=True,ws=True,bb=True)
回傳boundingBox(bb),分別是xmin ymin zmin xmax ymax zmax

Returns the bounding box of an object. This includes the bounding boxes of all invisible children which are not included using the boundingBox flag. The values returned are in following order: xmin ymin zmin xmax ymax zmax.

2.
strechSquash=cmds.nonLinear(selectedBall,typ="squash",lowBound=0,highBound=2)

相當於MEL
nonLinear -type squash -lowBound -1 -highBound 1 -startSmoothness 0 -endSmoothness 0 -maxExpandPos 0.5 -expand 1 -factor 0;

3.
在擠壓的時候,原本是以中間為基準,若是要以下面為基準,就要lowBound=0/highBound=2

4.
cmds.xform(strechSquash,a=True,t=(0,0,0),cp=True)
若是直接用cmds.move(0,0,0)會連pivot也移到最下面

參考

https://www.youtube.com/watch?v=Jtw3WkTHGgg&list=PLdQnt7xu73OXBjKNlsA-lX9tWATVUjtA9&index=8

https://www.youtube.com/watch?v=euxCHrvHN0s&list=PLdQnt7xu73OXBjKNlsA-lX9tWATVUjtA9&index=12