forked from n1ckfg/MayaToolbox
/
dynamics.py
49 lines (39 loc) · 1.04 KB
/
dynamics.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
# DYNAMICS
import pymel.core as py
import maya.cmds as mc
import maya.mel as mel
from math import *
from xml.dom.minidom import *
from random import uniform as rnd
import os
import re
#~~
from mayatoolbox import *
from animation import *
def quickDyn(spread=5, num=10, joints=False, bake=False):
target = []
g = py.gravity()
for i in range(0,num):
c = py.polyCube()
target.append(c)
x = rnd(-spread,spread)
y = rnd(-spread,spread) + 10
z = rnd(-spread,spread)
py.move(x,y,z)
py.rotate(x,y,z)
s(target)
py.rigidBody()
for i in range(0,len(target)):
py.connectDynamic(target[i],f=g)
if(joints==False and bake==True):
bakeAnimation(target)
if(joints==True):
target2 = []
for i in range(0,len(target)):
s(target[i])
jnt = py.joint()
target2.append(jnt)
if(bake==True):
bakeAnimation(target2)
for i in range(0,len(target2)):
unparent(target2[i])