Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Get closest point on crv
- # find parent stroke end clip position/value
- from pymel.core import *
- import maya.api.OpenMaya as om
- import random as r
- class OnCrvObj:
- def __init__(self):
- self.CrvObj = self
- self.CrvPos = self.getTransform()
- def MakeMoPath(CrvObj):
- cpCheck = ls("CrvPointMoPath")
- if cpCheck:
- delete(cpCheck)
- cp = createNode("motionPath",n="CrvPointMoPath")
- setAttr(cp+".fractionMode", 1)
- CrvObj.worldSpace >> cp.geometryPath
- lCheck = ls("ClosestPoint_lctr")
- if lCheck:
- delete(lCheck)
- l = spaceLocator(n = "ClosestPoint_lctr")
- cp.allCoordinates >> l.translate
- #target.getShape().worldMatrix[0] >> cp.inputMatrix
- #target.getShape().worldMesh[0] >> cp.inMesh
- return cp, l
- def getDist(p1,p2):
- dist = defAttr.srt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 + (p1[2] - p2[2])**2)
- return dist
- sampleAmnt = 100
- xInc = 0.01
- #sl = selected()
- objects = sl[:-1]
- Crv = sl[-1]
- moPathNode, lctr = MakeMoPath(Crv)
- x = 0
- bestPos = 10000
- bestLoc = 0
- xSave = 0
- for i in range(0,sampleAmnt):
- if x < 1:
- setAttr(moPathNode+".uValue", x)
- LctrPos = lctr.getTranslation()
- PointOnPathPos = objects[0].getTranslation()
- dist = getDist(LctrPos,PointOnPathPos)
- if dist < bestPos:
- bestPos = dist
- bestLoc = LctrPos
- xSave = x
- x += xInc
- #EndPos = spaceLocator(n = "Lctr_"+str(xSave))
- #move(EndPos, bestLoc)
- CrvObjectStroke = listConnections(objects[0].worldSpace[0])
- CrvCrvStroke = listConnections(Crv.worldSpace[0])[1]
- GrowStuff = [CrvCrvStroke, CrvObjectStroke[0], str(xSave), str(0.05)]
- GrowExpression = "if("+GrowStuff[0]+".maxClip>="+GrowStuff[2]+"){if("+GrowStuff[0]+".maxClip<1){"+GrowStuff[1]+".maxClip="+GrowStuff[0]+".maxClip-"+GrowStuff[2]+";}else{if("+GrowStuff[1]+".maxClip < 1)"+GrowStuff[1]+".maxClip += "+GrowStuff[3]+" ;}}else{"+GrowStuff[1]+".maxClip = 0 ;}"
- #ex = expression(CrvObjectStroke[0], uc="all", td=1, s = GrowExpression, ae=1, n = CrvObjectStroke[0]+"_exp",an=1 )
- ex = expression(CrvObjectStroke[0], s = GrowExpression, n = CrvObjectStroke[0]+"_exp")
- expression(ex, e=1,s=GrowExpression,ae=1, uc="all")
- delete(moPathNode,lctr)
Advertisement
Add Comment
Please, Sign In to add comment