import maya.cmds as cmds
from functools import partial
from random import uniform as rand
from functools import partial
from random import uniform as rand
cmds.file(force=True, new=True)
cmds.playbackOptions(minTime='0sec', maxTime='10sec')
cmds.playbackOptions(minTime='0sec', maxTime='10sec')
def close():
if cmds.window("Vine",exists=True) == True:
cmds.deleteUI("Vine")
def openWindow():
if cmds.window("Vine", exists = True):
cmds.deleteUI("Vine")
myWindow = cmds.window("Vine", title="Vine Generator", resizeToFitChildren=True, sizeable=True)
if cmds.window("Vine",exists=True) == True:
cmds.deleteUI("Vine")
def openWindow():
if cmds.window("Vine", exists = True):
cmds.deleteUI("Vine")
myWindow = cmds.window("Vine", title="Vine Generator", resizeToFitChildren=True, sizeable=True)
main_form = cmds.formLayout(numberOfDivisions=100)
main_column = cmds.columnLayout(adjustableColumn=True)
cmds.text(label=" " )
cmds.text(label="Choose Object and Vine Orientation", backgroundColor=[0.4,0.4,0.4], font="boldLabelFont" )
cmds.text(label=" " )
top_sep = cmds.separator(parent=main_form, height=10,style='in')
left_sep = cmds.separator(parent=main_form, style='in',horizontal=False)
right_sep = cmds.separator(parent=main_form, style='out',horizontal=False)
btm_sep = cmds.separator(parent=main_form, height=10, style='out')
mid_sep = cmds.separator(parent=main_form, height=10, style='out')
mid_sep2 = cmds.separator(parent=main_form, height=10, style='out')
cmds.separator(h=3, style = "none")
cmds.optionMenuGrp("geo", label='Objetcts: ',changeCommand=geometrySelection)
allGeo = cmds.ls(geometry=True)
cmds.menuItem( label='Torus' )
cmds.menuItem( label='Plane' )
cmds.menuItem( label='Cylinder' )
cmds.menuItem( label='Rectangle' )
cmds.menuItem( label='Sphere' )
cmds.menuItem( label='Cone' )
for geo in allGeo:
cmds.menuItem(label=geo)
cmds.radioButtonGrp("uv", select=2, label='Direction: ', labelArray2=['Horizontal', 'Vertical'], numberOfRadioButtons=2 )
main_column = cmds.columnLayout(adjustableColumn=True)
cmds.text(label=" " )
cmds.text(label="Choose Object and Vine Orientation", backgroundColor=[0.4,0.4,0.4], font="boldLabelFont" )
cmds.text(label=" " )
top_sep = cmds.separator(parent=main_form, height=10,style='in')
left_sep = cmds.separator(parent=main_form, style='in',horizontal=False)
right_sep = cmds.separator(parent=main_form, style='out',horizontal=False)
btm_sep = cmds.separator(parent=main_form, height=10, style='out')
mid_sep = cmds.separator(parent=main_form, height=10, style='out')
mid_sep2 = cmds.separator(parent=main_form, height=10, style='out')
cmds.separator(h=3, style = "none")
cmds.optionMenuGrp("geo", label='Objetcts: ',changeCommand=geometrySelection)
allGeo = cmds.ls(geometry=True)
cmds.menuItem( label='Torus' )
cmds.menuItem( label='Plane' )
cmds.menuItem( label='Cylinder' )
cmds.menuItem( label='Rectangle' )
cmds.menuItem( label='Sphere' )
cmds.menuItem( label='Cone' )
for geo in allGeo:
cmds.menuItem(label=geo)
cmds.radioButtonGrp("uv", select=2, label='Direction: ', labelArray2=['Horizontal', 'Vertical'], numberOfRadioButtons=2 )
create = cmds.button(parent=main_form, label="Generate",command="run()")
close = cmds.button(parent=main_form, label="Close Window",command="close()")
cmds.formLayout(main_form, edit=True,
attachPosition=[(top_sep,"top",-3,0),
(top_sep,"left",2,0),
(top_sep,"right",4,100),
(left_sep,"top",1,0),
(left_sep,"left",2,0),
(left_sep,"bottom",32,100),
(right_sep,"top",2,0),
(right_sep,"right",2,100),
(right_sep,"bottom",32,100),
(btm_sep,"bottom",25,100),
(btm_sep,"left",3,0),
(btm_sep,"right",4,100),
(create, 'bottom', 4,100),
(create, 'left', 4,0),
(create, 'right', 2,50),
(close, 'bottom', 4,100),
(close, 'left', 2,50),
(close, 'right', 4,100)])
cmds.showWindow(myWindow)
close = cmds.button(parent=main_form, label="Close Window",command="close()")
cmds.formLayout(main_form, edit=True,
attachPosition=[(top_sep,"top",-3,0),
(top_sep,"left",2,0),
(top_sep,"right",4,100),
(left_sep,"top",1,0),
(left_sep,"left",2,0),
(left_sep,"bottom",32,100),
(right_sep,"top",2,0),
(right_sep,"right",2,100),
(right_sep,"bottom",32,100),
(btm_sep,"bottom",25,100),
(btm_sep,"left",3,0),
(btm_sep,"right",4,100),
(create, 'bottom', 4,100),
(create, 'left', 4,0),
(create, 'right', 2,50),
(close, 'bottom', 4,100),
(close, 'left', 2,50),
(close, 'right', 4,100)])
cmds.showWindow(myWindow)
cmds.text(label=" " )
cmds.text(label="Object Attributes", backgroundColor=[0.4,0.4,0.4], font="boldLabelFont" )
cmds.text(label=" " )
cmds.text(label = "For Torus", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("torusradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.intSliderGrp("torussectionradius",value=100,label="Section Radius: ",min=2,max=10,field=True)
cmds.text(label = "For Plane", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("planewidth",value=100,label="Width: ",min=2,max=40,field=True)
cmds.intSliderGrp("planeheight",value=100,label="Height: ",min=2,max=40,field=True)
cmds.text(label = "For Cylinder", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("cylinderradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.intSliderGrp("cylinderheight",value=100,label="Height: ",min=2,max=40,field=True)
cmds.text(label = "For Rectangle", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("rectanglewidth",value=100,label="Width: ",min=2,max=40,field=True)
cmds.intSliderGrp("rectangleheight",value=100,label="Height: ",min=2,max=40,field=True)
cmds.intSliderGrp("rectangledepth",value=100,label="Depth: ",min=2,max=40,field=True)
cmds.text(label = "For Sphere", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("sphereradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.text(label = "For Cone", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("coneradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.intSliderGrp("coneheight",value=100,label="Height: ",min=2,max=40,field=True)
def geometrySelection(item, *args):
return item
def run():
geo = cmds.optionMenuGrp("geo", query=True, value=True)
uv = cmds.radioButtonGrp("uv", query=True, select=True)
frames = 100
density = 70
particlesRef =True
numCurves = 5
vineRadius = 0.2
defOrCustom = select=True
animation = True
subCurves = False
visibility = True
projected = True
if defOrCustom == True:
if geo == "Torus":
hi = cmds.polyTorus(radius=cmds.intSliderGrp("torusradius",query=True, value=True), sectionRadius=cmds.intSliderGrp("torussectionradius",query=True, value=True))[0]
elif geo == "Plane":
hi = cmds.polyPlane(width=cmds.intSliderGrp("planewidth",query=True, value=True), height=cmds.intSliderGrp("planeheight",query=True, value=True))[0]
elif geo == "Cylinder":
hi = cmds.polyCylinder(radius=cmds.intSliderGrp("cylinderradius",query=True, value=True), height=cmds.intSliderGrp("cylinderheight",query=True, value=True))[0]
elif geo == "Rectangle":
hi = cmds.polyCube(width=cmds.intSliderGrp("rectanglewidth",query=True, value=True), height=cmds.intSliderGrp("rectangleheight",query=True, value=True), depth=cmds.intSliderGrp("rectangledepth",query=True, value=True))[0]
elif geo == "Sphere":
hi = cmds.polySphere(radius=cmds.intSliderGrp("sphereradius",query=True, value=True))[0]
elif geo == "Cone":
hi = cmds.polyCone(radius=cmds.intSliderGrp("coneradius",query=True, value=True), height=cmds.intSliderGrp("coneheight",query=True, value=True))[0]
cmds.text(label="Object Attributes", backgroundColor=[0.4,0.4,0.4], font="boldLabelFont" )
cmds.text(label=" " )
cmds.text(label = "For Torus", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("torusradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.intSliderGrp("torussectionradius",value=100,label="Section Radius: ",min=2,max=10,field=True)
cmds.text(label = "For Plane", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("planewidth",value=100,label="Width: ",min=2,max=40,field=True)
cmds.intSliderGrp("planeheight",value=100,label="Height: ",min=2,max=40,field=True)
cmds.text(label = "For Cylinder", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("cylinderradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.intSliderGrp("cylinderheight",value=100,label="Height: ",min=2,max=40,field=True)
cmds.text(label = "For Rectangle", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("rectanglewidth",value=100,label="Width: ",min=2,max=40,field=True)
cmds.intSliderGrp("rectangleheight",value=100,label="Height: ",min=2,max=40,field=True)
cmds.intSliderGrp("rectangledepth",value=100,label="Depth: ",min=2,max=40,field=True)
cmds.text(label = "For Sphere", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("sphereradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.text(label = "For Cone", backgroundColor=[0.2,0.2,0.2])
cmds.intSliderGrp("coneradius",value=100,label="Radius: ",min=2,max=10,field=True)
cmds.intSliderGrp("coneheight",value=100,label="Height: ",min=2,max=40,field=True)
def geometrySelection(item, *args):
return item
def run():
geo = cmds.optionMenuGrp("geo", query=True, value=True)
uv = cmds.radioButtonGrp("uv", query=True, select=True)
frames = 100
density = 70
particlesRef =True
numCurves = 5
vineRadius = 0.2
defOrCustom = select=True
animation = True
subCurves = False
visibility = True
projected = True
if defOrCustom == True:
if geo == "Torus":
hi = cmds.polyTorus(radius=cmds.intSliderGrp("torusradius",query=True, value=True), sectionRadius=cmds.intSliderGrp("torussectionradius",query=True, value=True))[0]
elif geo == "Plane":
hi = cmds.polyPlane(width=cmds.intSliderGrp("planewidth",query=True, value=True), height=cmds.intSliderGrp("planeheight",query=True, value=True))[0]
elif geo == "Cylinder":
hi = cmds.polyCylinder(radius=cmds.intSliderGrp("cylinderradius",query=True, value=True), height=cmds.intSliderGrp("cylinderheight",query=True, value=True))[0]
elif geo == "Rectangle":
hi = cmds.polyCube(width=cmds.intSliderGrp("rectanglewidth",query=True, value=True), height=cmds.intSliderGrp("rectangleheight",query=True, value=True), depth=cmds.intSliderGrp("rectangledepth",query=True, value=True))[0]
elif geo == "Sphere":
hi = cmds.polySphere(radius=cmds.intSliderGrp("sphereradius",query=True, value=True))[0]
elif geo == "Cone":
hi = cmds.polyCone(radius=cmds.intSliderGrp("coneradius",query=True, value=True), height=cmds.intSliderGrp("coneheight",query=True, value=True))[0]
else:
hi = cmds.ls(geometry=True)[0]
hi = cmds.ls(geometry=True)[0]
cmds.emitter(hi, type='surface', rate=density, sro=0, nuv=0, cycleEmission='None', cyi=1, spd=0, srn=0, nsp=0, tsp=0, mxd=0, mnd=0, dx=1, dy=0, dz=0, sp=0, n='tocreate')
cmds.particle( name='Particles' )
cmds.connectDynamic( 'Particles', em='tocreate' )
cmds.particle( name='Particles' )
cmds.connectDynamic( 'Particles', em='tocreate' )
cmds.goal('Particles', goal=hi, weight=1, useTransformAsGoal=0)
cmds.addAttr('ParticlesShape', longName='goalU', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='goalU0', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='goalV', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='goalV0', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentU', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentU0', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentV', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentV0', dataType='doubleArray')
if uv == 2:
cmds.dynExpression( 'ParticlesShape', string="parentU = rand(0.01,0.99);\nparentV = rand(.9,1);\ngoalU = parentU;\ngoalV = parentV;", creation=True)
cmds.dynExpression( 'ParticlesShape', string="parentV -= .01;\ngoalV = parentV;\nparentU += rand(-0.01,0.01);\ngoalU = parentU;", runtimeBeforeDynamics=True)
elif uv == 1:
cmds.dynExpression( 'ParticlesShape', string="parentV = rand(0.01,0.99);\nparentU = rand(0,.1);\ngoalU = parentU;\ngoalV = parentV;", creation=True)
cmds.dynExpression( 'ParticlesShape', string="parentU += .01;\ngoalU = parentU;\nparentV += rand(-0.01,0.01);\ngoalV = parentV;", runtimeBeforeDynamics=True)
cmds.currentTime(frames, edit=True)
lastFrame = int(cmds.currentTime(query=True))
cmds.addAttr('ParticlesShape', longName='goalU', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='goalU0', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='goalV', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='goalV0', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentU', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentU0', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentV', dataType='doubleArray')
cmds.addAttr('ParticlesShape', longName='parentV0', dataType='doubleArray')
if uv == 2:
cmds.dynExpression( 'ParticlesShape', string="parentU = rand(0.01,0.99);\nparentV = rand(.9,1);\ngoalU = parentU;\ngoalV = parentV;", creation=True)
cmds.dynExpression( 'ParticlesShape', string="parentV -= .01;\ngoalV = parentV;\nparentU += rand(-0.01,0.01);\ngoalU = parentU;", runtimeBeforeDynamics=True)
elif uv == 1:
cmds.dynExpression( 'ParticlesShape', string="parentV = rand(0.01,0.99);\nparentU = rand(0,.1);\ngoalU = parentU;\ngoalV = parentV;", creation=True)
cmds.dynExpression( 'ParticlesShape', string="parentU += .01;\ngoalU = parentU;\nparentV += rand(-0.01,0.01);\ngoalV = parentV;", runtimeBeforeDynamics=True)
cmds.currentTime(frames, edit=True)
lastFrame = int(cmds.currentTime(query=True))
particlePositions = []
frame = []
allCurves = []
smallCurves = []
smallCurvesOther = []
curveGeometry = []
projectedCurves = []
branchCurves = []
branchCurvesGeo = []
for time in range(lastFrame):
cmds.currentTime(time)
if time > 0:
for i in range(cmds.particle("Particles", query=True, count=True)):
particlePositions.append( cmds.particle("Particles", query=True, attribute='position', particleId=i) )
frame.append(particlePositions)
particlePositions = []
allParticleCount = cmds.particle("Particles", query=True, count=True)
frame = []
allCurves = []
smallCurves = []
smallCurvesOther = []
curveGeometry = []
projectedCurves = []
branchCurves = []
branchCurvesGeo = []
for time in range(lastFrame):
cmds.currentTime(time)
if time > 0:
for i in range(cmds.particle("Particles", query=True, count=True)):
particlePositions.append( cmds.particle("Particles", query=True, attribute='position', particleId=i) )
frame.append(particlePositions)
particlePositions = []
allParticleCount = cmds.particle("Particles", query=True, count=True)
for p in range(allParticleCount):
pos = []
for f in frame:
if len(f) > p+1 :
pos.append(f[p])
if len(pos) > 30:
allCurves.append( cmds.curve(p=pos))
cmds.group( allCurves, name="curves")
for p in range(len(allCurves)):
if subCurves == True:
for i in [float(j) / numCurves for j in range(0, numCurves, 1)]:
pos = []
for f in frame:
if len(f) > p+1 :
pos.append(f[p])
if len(pos) > 30:
allCurves.append( cmds.curve(p=pos))
cmds.group( allCurves, name="curves")
for p in range(len(allCurves)):
if subCurves == True:
for i in [float(j) / numCurves for j in range(0, numCurves, 1)]:
pointPosXYZ = cmds.pointOnCurve(allCurves[p], parameter=i, position=True, turnOnPercentage=True )
pointDir = cmds.pointOnCurve( allCurves[p], parameter=i, normalizedTangent=True )
pointDir = cmds.pointOnCurve( allCurves[p], parameter=i, normalizedTangent=True )
cmds.xform(allCurves[p], pivots=pointPosXYZ)
variation = 0
gi= pointPosXYZ[0]+pointDir[0]
gi2= pointPosXYZ[1]+pointDir[1]
gi3= pointPosXYZ[2]+pointDir[2]
pi= pointPosXYZ[0]-pointDir[0]
pi2= pointPosXYZ[1]-pointDir[1]
pi3= pointPosXYZ[2]-pointDir[2]
pointPosAlt = (gi, gi2, gi3)
pointPosAlt2 = (gi, gi2, gi3)
pointPosAlt3 = (gi, gi2, gi3)
ointPosAlt = (pi, pi2, pi3)
ointPosAlt2 = (pi, pi2, pi3)
ointPosAlt3 = (pi, pi2, pi3)
smallCurves.append(cmds.curve(name="smallCurve1", point=[(pointPosXYZ), pointPosAlt, pointPosAlt, pointPosAlt]))
cmds.xform(pivots=pointPosXYZ)
cmds.rotate(0,45,0)
smallCurvesOther.append(cmds.curve(name="smallOtherCurve1", point=[(pointPosXYZ), ointPosAlt, ointPosAlt, ointPosAlt]))
cmds.xform(pivots=pointPosXYZ)
cmds.rotate(0,135,0)
else:
pass
elif subCurves == False:
pass
cmds.rebuildCurve( allCurves[p], rpo=True, end=True, kr=False, kep=True, kt=False, s=30, d=3, tol=.01)
cmds.smoothCurve(allCurves[p]+".cv[*]", ch=1, rpo=1, s=50)
first = cmds.getAttr(allCurves[p]+".cv[0]")
val = list(first[0])
curveGeometry.append((cmds.circle(radius=vineRadius)[0]))
cmds.move(val[0], val[1], val[2], r=True)
curveGeometry.append((cmds.extrude( ("nurbsCircle"+str(p+1)), allCurves[p], scale=.000001, fixedPath=True, constructionHistory=True, range=True, extrudeType=2, useProfileNormal=True, reverseSurfaceIfPathReversed=True, useComponentPivot=1)[0]))
if animation == True:
q = (p+1)*2
selectedCurve = "subCurve"+ str(q) + ".maxValue"
cmds.setAttr( selectedCurve, .075)
cmds.currentTime(1, update=False)
cmds.setKeyframe(selectedCurve, itt='flat', ott='flat')
cmds.setAttr( selectedCurve, 1)
cmds.currentTime(rand(150,200), update=False)
cmds.setKeyframe(selectedCurve, itt='flat', ott='flat')
cmds.group(curveGeometry, name="curveGeometries")
openWindow()
variation = 0
gi= pointPosXYZ[0]+pointDir[0]
gi2= pointPosXYZ[1]+pointDir[1]
gi3= pointPosXYZ[2]+pointDir[2]
pi= pointPosXYZ[0]-pointDir[0]
pi2= pointPosXYZ[1]-pointDir[1]
pi3= pointPosXYZ[2]-pointDir[2]
pointPosAlt = (gi, gi2, gi3)
pointPosAlt2 = (gi, gi2, gi3)
pointPosAlt3 = (gi, gi2, gi3)
ointPosAlt = (pi, pi2, pi3)
ointPosAlt2 = (pi, pi2, pi3)
ointPosAlt3 = (pi, pi2, pi3)
smallCurves.append(cmds.curve(name="smallCurve1", point=[(pointPosXYZ), pointPosAlt, pointPosAlt, pointPosAlt]))
cmds.xform(pivots=pointPosXYZ)
cmds.rotate(0,45,0)
smallCurvesOther.append(cmds.curve(name="smallOtherCurve1", point=[(pointPosXYZ), ointPosAlt, ointPosAlt, ointPosAlt]))
cmds.xform(pivots=pointPosXYZ)
cmds.rotate(0,135,0)
else:
pass
elif subCurves == False:
pass
cmds.rebuildCurve( allCurves[p], rpo=True, end=True, kr=False, kep=True, kt=False, s=30, d=3, tol=.01)
cmds.smoothCurve(allCurves[p]+".cv[*]", ch=1, rpo=1, s=50)
first = cmds.getAttr(allCurves[p]+".cv[0]")
val = list(first[0])
curveGeometry.append((cmds.circle(radius=vineRadius)[0]))
cmds.move(val[0], val[1], val[2], r=True)
curveGeometry.append((cmds.extrude( ("nurbsCircle"+str(p+1)), allCurves[p], scale=.000001, fixedPath=True, constructionHistory=True, range=True, extrudeType=2, useProfileNormal=True, reverseSurfaceIfPathReversed=True, useComponentPivot=1)[0]))
if animation == True:
q = (p+1)*2
selectedCurve = "subCurve"+ str(q) + ".maxValue"
cmds.setAttr( selectedCurve, .075)
cmds.currentTime(1, update=False)
cmds.setKeyframe(selectedCurve, itt='flat', ott='flat')
cmds.setAttr( selectedCurve, 1)
cmds.currentTime(rand(150,200), update=False)
cmds.setKeyframe(selectedCurve, itt='flat', ott='flat')
cmds.group(curveGeometry, name="curveGeometries")
openWindow()