Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Rando
- # cwisbg.com
- import random as r
- from pymel.core import *
- def snapToSurface():
- # select list, then snap to object
- sl = selected()
- startL = spaceLocator(n="startL")
- endL = spaceLocator(n="endL")
- cp = createNode("closestPointOnMesh",n="snapperCheck")
- snapList = sl
- snapto = snapSurfaceMesh
- snapto.getShape().worldMatrix[0] >> cp.inputMatrix
- startL.translate >> cp.inPosition
- cp.position >> endL.translate
- snapto.getShape().worldMesh[0] >> cp.inMesh
- for s in snapList:
- st = s.getTranslation()
- move(startL, st)
- et = endL.getTranslation()
- move(s,et)
- delete(cp,startL,endL)
- alignToSurface()
- """
- sl = selected()
- startL = spaceLocator(n="startL")
- endL = spaceLocator(n="endL")
- cp = createNode("closestPointOnMesh",n="snapperCheck")
- snapList = sl
- snapto = snapSurfaceMesh
- snapto.getShape().worldMatrix[0] >> cp.inputMatrix
- startL.translate >> cp.inPosition
- cp.position >> endL.translate
- snapto.getShape().worldMesh[0] >> cp.inMesh
- for s in snapList:
- st = s.getTranslation()
- sr = s.getRotation()
- move(startL, st)
- et = endL.getTranslation()
- move(s,et)
- tempGrp = ls("tempAlignToSurface")
- if not tempGrp:
- tempGrp = group(em=1,n = "tempAlignToSurface")
- move(tempGrp, st)
- sPapa = listRelatives(s, p=1)
- parent(s,tempGrp)
- nc = normalConstraint(snapto, tempGrp, aim= [0,1,0],u= [0,1,0],wut = "vector",wu =[0,1,0])
- if sPapa:
- parent(s,sPapa)
- else:
- parent(s,w=1)
- delete(nc, tempGrp)
- delete(cp,startL,endL)
- """
- select(sl)
- def alignToSurface():
- alignCheck = alignToSurfaceBox.getValue()
- sl = selected()
- for s in sl:
- if alignCheck:
- nc = normalConstraint(snapSurfaceMesh, s, aim= [0,1,0],u= [0,1,0],wut = "vector",wu =[0,1,0])
- delete(nc)
- else:
- pass
- def checkMe():
- boxValue = checkBox1.getValue()
- print "Checked", boxValue
- def buttonPressed():
- cbScale = checkBoxScale.getValue()
- cbTrans = checkBoxTranslate.getValue()
- cbRot = checkBoxRotate.getValue()
- cbX = checkBoxX.getValue()
- cbY = checkBoxY.getValue()
- cbZ = checkBoxZ.getValue()
- keyCheck = keyBox.getValue()
- amntS = float(sText.getText())
- amntS1 = float(sText1.getText())
- amntT = float(tText.getText())
- amntR = float(rText.getText())
- sl = selected()
- slEnd = sl
- for s in sl:
- tx = 0
- ty = 0
- tz = 0
- rx = 0
- ry = 0
- rz = 0
- sx = 0
- sy = 0
- sz = 0
- if cbScale:
- if cbX or cbY or cbZ:
- sr = r.uniform(amntS,amntS1)
- scale(s,sr,sr,sr,r=1)
- if cbTrans:
- if cbX:
- tx = r.uniform(-amntT,amntT)
- if cbY:
- ty = r.uniform(-amntT,amntT)
- if cbZ:
- tz = r.uniform(-amntT,amntT)
- move(s,tx,ty,tz,os=1,r=1)
- if cbRot:
- if cbX:
- rx = r.uniform(0,amntR)
- if cbY:
- ry = r.uniform(0,amntR)
- if cbZ:
- rz = r.uniform(0,amntR)
- rotate(s,rx,ry,rz,os=1,r=1)
- if keyCheck:
- setKeyframe(s)
- snapCheck = snapToSurfaceBox.getValue()
- if snapCheck:
- snapToSurface()
- alignToSurface()
- def scaleCheck():
- sc = checkBoxScale.getValue()
- if sc:
- sText.setEnable(1)
- sText1.setEnable(1)
- else:
- sText.setEnable(0)
- sText1.setEnable(0)
- def transCheck():
- bc = checkBoxTranslate.getValue()
- if bc:
- tText.setEnable(1)
- else:
- tText.setEnable(0)
- def rotCheck():
- bc = checkBoxRotate.getValue()
- if bc:
- rText.setEnable(1)
- else:
- rText.setEnable(0)
- def addSnapSurface():
- global snapSurfaceMesh
- snapSurfaceMesh = selected()[0]
- snapSurface.setText(str(snapSurfaceMesh))
- snapToSurfaceBox.setEnable(1)
- snapToSurfaceBox.setValue(1)
- alignToSurfaceBox.setValue(1)
- alignToSurfaceBox.setEnable(1)
- print snapSurfaceMesh
- win = window(title= "Gui", s=0)
- mainLayout = frameLayout(l="Randor",cll=1)
- checkBoxLayout = frameLayout(l="Rando",p=mainLayout,cll=1)
- scaleLayout = rowColumnLayout(nc=1,p=checkBoxLayout)
- checkBoxScale = checkBox(l = "Scale",p=scaleLayout,cc =Callback(scaleCheck))
- scaleTxtLayout = rowColumnLayout(nr=1,p=scaleLayout)
- sText = textField(tx=".5",p=scaleTxtLayout,w=50,en=0)
- sText1 = textField(tx="1.5",p=scaleTxtLayout,w=50,en=0)
- transLayout = rowColumnLayout(nc=1,p=checkBoxLayout)
- checkBoxTranslate = checkBox(l = "Trans",p=transLayout,cc =Callback(transCheck))
- tText = textField(tx="10",p=transLayout,w=50,en=0)
- rotLayout = rowColumnLayout(nc=1,p=checkBoxLayout)
- checkBoxRotate = checkBox(l = "Rot",p=rotLayout,v=0,cc =Callback(rotCheck))
- rText = textField(tx="360",p=rotLayout,w=50)
- checkLayout = rowColumnLayout(nr=1,p=checkBoxLayout)
- checkBoxX = checkBox(l = "X",p=checkLayout,v=1)
- checkBoxY = checkBox(l = "Y",p=checkLayout,v=1)
- checkBoxZ = checkBox(l = "Z",p=checkLayout,v=1)
- keyBox = checkBox(l = "Key",p=checkBoxLayout,v=0)#,bgc =[1,0,0])
- snapToSurfaceBox = checkBox(l = "SnapToSurface",p=checkBoxLayout,v=0,en=0)
- alignToSurfaceBox = checkBox(l = "AlignToSurface",p=checkBoxLayout,v=0,en=0)
- randoBtn = button(l="Randomiz!", command=Callback(buttonPressed),p=checkBoxLayout,bgc =[.1,.9,.4])
- snapToSurfaceLayout = frameLayout(l = "snap surface",p=mainLayout,w=50,cll=1,cl=1)
- addSurfaceButton = button(l="Add Surface",p=snapToSurfaceLayout,command = Callback(addSnapSurface))
- snapSurface = textField("surface",p=snapToSurfaceLayout)
- snapToSurfaceBtn = button(l="Snap Selected",p=snapToSurfaceLayout,command = Callback(snapToSurface))
- win.show()
Advertisement
Add Comment
Please, Sign In to add comment