Ejemplo n.º 1
0
def createFromTo(objs=[], divisions=4, degree=3):
	from maya.cmds import ls, attributeQuery, xform, pointPosition, curve
	from ezLib import transform
	# no objs put it: get from selection
	if not objs:
		objs = ls(sl=1)
	if len(objs) != 2:
		raise IOError, 'need 2 objs to get start & end from!'

	print ('objs: ' + str(objs))

	pos = []
	for i in range(2):
		# to get transforms/joints or anything that has translate attributes
		if attributeQuery('t', node=objs[i], exists=1):
			pos.append(xform(objs[i],q=1,t=1,ws=1))
		else:
			try:
				pos.append(pointPosition(objs[i], world=1))
			except IOError:
				print 'cannot get position from ' + objs[i]

	#vector from start to end
	posArray = transform.posRange(pos[0], pos[1], divisions + 1)
	crv = curve(p=posArray)
	# center pivot and reset pivot
	xform(crv, centerPivots=1)
	transform.resetPivot(crv)
Ejemplo n.º 2
0
def ribbonize(crv=[], shader='lambert1', divLen=32, divWid=1):
	'''
	creates a basic curve driven mesh stream
	future versions shall have a twist, shift and width value
	that can be animated over lenght of the curve
	'''
	from ezLib import transform
	
	numInput = len(crv)
	crv = get(crv)
	for c in crv:
		crvShp = ls(c, s=1, dag=1)[0]
		o1 = createNode('offsetCurve')
		o2 = createNode('offsetCurve')
		connectAttr(crvShp + '.worldSpace[0]', o1 + '.inputCurve')
		connectAttr(crvShp + '.worldSpace[0]', o2 + '.inputCurve')
		# create visible attr at the curveShape to control ribbon width
		rw = 'ribbonWidth'
		if not attributeQuery(rw, node=crvShp, exists=1):
			addAttr(crvShp, ln=rw, at='float')
			setAttr(crvShp + '.' + rw, 10, keyable=1)
		connectAttr(crvShp + '.' + rw, o1 + '.distance')
		mtply = createNode('multiplyDivide')
		setAttr(mtply + '.input2X', -1)
		connectAttr(crvShp + '.' + rw, mtply + '.input1X')
		connectAttr(mtply + '.outputX', o2 + '.distance')
		# loft the 2 offsets
		loft = createNode('loft')
		connectAttr(o1 + '.outputCurve[0]', loft + '.inputCurve[0]')
		connectAttr(o2 + '.outputCurve[0]', loft + '.inputCurve[1]')
		tess = createNode('nurbsTessellate')
		connectAttr(loft + '.outputSurface', tess + '.inputSurface')

		# setup the surface creation
		setAttr(tess + '.format', 2) # 0 or 2 is useful. 0 'count' tries to create square quads
		setAttr(tess + '.polygonType', 1)
		setAttr(tess + '.chordHeightRatio', 0.9)
		setAttr(tess + '.uNumber', divWid)
		setAttr(tess + '.vNumber', divLen)
		setAttr(tess + '.uType', 3)
		setAttr(tess + '.vType', 1) # makes up the distribution: 2 is cv based, 1 is even distribution
		
		mesh = createNode('mesh')
		sets(mesh, e=1,forceElement='initialShadingGroup')
		tr = listRelatives(mesh, p=1)[0]
		xform(tr, pivots=xform(c, q=1,t=1, ws=1))
		connectAttr(tess + '.outputPolygon', mesh + '.inMesh')
		transform.resetPivot(tr)
		rename(tr, c + 'Ribbon')
		
	if not numInput:
		select(crv)