-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenTentaclesAnim.py
85 lines (60 loc) · 1.83 KB
/
GenTentaclesAnim.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
import maya.cmds as cmds
import maya.mel as mel
import random
import time
#random.seed(0)
baseTentacle = "BaseTentacle"
def RandTwist ():
twistAmount = random.uniform(100.0, 400.0)
if (random.random() < 0.5):
twistAmount = twistAmount * float(-1.0)
return twistAmount
allTentacles = []
def GenTentacles (n):
for i in range(0, n):
# create a new cone
cmds.select(baseTentacle)
newTentacle = cmds.duplicate()[0]
cmds.move(0, 0, 0)
# vary tentacle size
sx = random.uniform(0.1, 0.3)
sy = random.uniform(0.5, 1.3)
cmds.scale(sx, sy, sx)
# create twist deformer
twist = cmds.nonLinear(type="twist", lowBound=-1, highBound=1)[0]
cmds.move(-11.25, 44, 0)
# hide the deformer
mel.eval("editDisplayLayerMembers -noRecurse hidden `ls -selection`;")
# combine twist and model, rotate it
rx = random.uniform(-360, 360)
ry = random.uniform(-360, 360)
rz = random.uniform(-360, 360)
cmds.select(newTentacle, add=True)
mel.eval("doGroup 0 1 1")
cmds.rotate(rx, ry, rz);
tentacleGroup = cmds.ls(selection=True)
# move to frame 0
cmds.currentTime(0)
for j in range(0, 40): #TODO this is frames
# do the twist
cmds.select(twist)
twistAmount = RandTwist()
cmds.setAttr(twist + ".endAngle", twistAmount);
cmds.setKeyframe(twist + ".ea")
# rotate a bit
cmds.select(tentacleGroup)
rx = random.uniform(-36, 36)
ry = random.uniform(-36, 36)
rz = random.uniform(-36, 36)
cmds.rotate(rx, ry, rz, relative=True)
cmds.setKeyframe(tentacleGroup)
# move to next key frame
cmds.currentTime(30 * j + random.uniform(-10, 10))
allTentacles.append(tentacleGroup)
GenTentacles(50)
cmds.select(clear=True)
# select all the tentacles, merge them
for i in range(0, len(allTentacles)):
cmds.select(allTentacles[i], add=True)
mel.eval("doGroup 0 1 1")
print(cmds.ls(selection=True))