Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Created August 23, 2014 01:33
Show Gist options
  • Save gregtemp/d1623e223ec36a508cfc to your computer and use it in GitHub Desktop.
Save gregtemp/d1623e223ec36a508cfc to your computer and use it in GitHub Desktop.
fractals 1 (not working)
# 1. Select the object you want to randomly extrude
# or use the "Make eCube" button to make one.
# 2. Press Check Selection.
# 3. Select the amount of random extrusion loops
# you would like to make and click Random Extrude
# 4. Click Keyframe to key the current frame for all
# vertices
import maya.cmds as cmds
import random
shapeName =''
objectName =''
def makeNewCube(*args):
global objectName
global shapeName
cubes = list()
cubes = cmds.ls('eCube')
if (len(cubes)>0):
cmds.delete(cubes)
else:
print('no cubes')
cmds.polyCube(n='eCube', sx=10, sy=15, sz=5, h=5, w=5, d=5 )
selectionList = cmds.ls(selection=True)
objectName = selectionList[0]
selectionList = cmds.listRelatives(s=True)
shapeName = selectionList[0]
#print(shapeName + ' ' + objectName)
def checkSelectName(*args):
global objectName
global shapeName
selectionList = cmds.ls(selection=True)
objectName = selectionList[-1]
selectionList = cmds.listRelatives(s=True)
#print selectionList
shapeName = selectionList[-1]
#print('---shapeName--- 'shapeName + ' ---objectName--- ' + objectName)
print('---objectName--- ' + objectName)
def moveFace(*args):
global objectName
global shapeName
inputInt = cmds.intSliderGrp('extI', query=True, value=True)
cmds.select(objectName)
amountOfFaces = cmds.polyEvaluate(f=True)
for mmm in range(0, inputInt):
n1 = random.randrange(0,amountOfFaces)
n2 = random.randrange(0,amountOfFaces)
if n1>n2:
faceStr = '%s.f[%i:%i]' %(objectName, n2, n1)
else:
faceStr = '%s.f[%i:%i]' %(objectName, n1, n2)
#print ('selected faces -> ' + faceStr)
cmds.select(faceStr)
m1 = random.uniform(-3, 3)
direction = random.randrange(0,3)
if direction == 0:
cmds.move(m1, 0, 0, r=True, os=True, wd=True)
elif direction == 1:
cmds.move(0, m1, 0, r=True, os=True, wd=True)
else:
cmds.move(0, 0, m1, r=True, os=True, wd=True)
def makeFractal(*args):
checkSelectName()
global objectName
global shapeName
inputInt = cmds.intSliderGrp('fracI', query=True, value=True)
cmds.select(objectName)
newName = objectName + '*'
cmds.duplicate(objectName,n=newName)
cmds.select(newName)
#cmds.move(0, 0, 2, r=True, os=True, wd=True)
cmds.scale(-0.9,-0.9, -0.9, r=True)
xp = cmds.getAttr(objectName + '.scaleX')
yp = cmds.getAttr(objectName + '.scaleY')
zp = cmds.getAttr(objectName + '.scaleZ')
print ('this --: %f', pf)
cmds.rotate( '10deg', 0, 0, r=True, pivot=(xp,0,0) )
def setKey(*args):
global objectName
global shapeName
kFrameStr = '%s.pt[:]' %(shapeName)
cmds.setKeyframe(kFrameStr)
#cmds.selectKey(shapeName, time=(pStartTime, pEndTime), attribute=pTargetAttribute, keyframe=True)
cmds.keyTangent(inTangentType='linear', outTangentType='linear')
print('keyed')
cmds.autoKeyframe(state=False)
#makeNewCube()
#moveFace(thisManyTimes)
#setKey()
class rexUI():
def __init__(self):
rexUi = 'rexUi'
if cmds.window(rexUi, exists=True):
cmds.deleteUI(rexUi)
rexUi = cmds.window(rexUi, t='REX', tb=True, rtf=True)
form = cmds.columnLayout(adjustableColumn=True)
bChSel = cmds.button('Check Selection', command=checkSelectName)
bBuild = cmds.button('Build eCube', command=makeNewCube)
cmds.separator(h=10, style="none")
cmds.text(label="Fractal Iterations")
cmds.intSliderGrp('fracI', field=True, minValue=1, maxValue=200, value=10)
cmds.separator(h=10, style="none")
cmds.text(label="Fractal Iterations")
cmds.intSliderGrp('fracI2', field=True, minValue=1, maxValue=200, value=10)
cmds.separator(h=10, style="none")
cmds.text(label="Fractal Iterations")
cmds.intSliderGrp('fracI3', field=True, minValue=1, maxValue=200, value=10)
cmds.separator(h=5, style="none")
bRandomize = cmds.button('Random Extrude', command=moveFace)
bFractal = cmds.button('Fractal', command=makeFractal)
bKeyframe = cmds.button('Keyframe', command=setKey)
cmds.showWindow(rexUi)
cmds.window(rexUi, edit=True, widthHeight=(150,250))
rexUser = rexUI()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment