Beispiel #1
0
def pointOnPolyHelper(maintainoffset=1):
	'''
	utilites the built in maya command but maintains offset and
	adds a nearesPointOnSurface node to get hold of the correct UV values
	'''
	from ezLib.list import uniquify
	from maya.cmds import *
	sel = ls(sl=1)
	shape = uniquify(ls(ls(sel, s=1, o=1, dag=1), type='mesh'))
	shapeTrans = uniquify(listRelatives(shape, parent=1))
	if len(shapeTrans) > 1:
		raise IOError, 'multiple mesh transforms! Select the shape that you want to attach to directly!'
	shapeTrans = shapeTrans[0]

	# check for underworld shapes
	nonIntermediates = []
	if len(shape) > 1:
		for s in shape:
			if not getAttr(s + '.intermediateObject'):
				nonIntermediates.append(s)
	if len(nonIntermediates) > 1:
		raise IOError, 'multiple visible mesh shapes selected! Select the shape that you want to attach to directly!'
	shape = nonIntermediates[0]

	tr = ls(sel, tr=1)
	if tr.count(shapeTrans):
		tr.remove(shapeTrans)

	npom = createNode('nearestPointOnMesh')
	connectAttr(shape + '.worldMesh[0]', npom + '.inMesh')
	for t in tr:
		tpos = xform(t, q=1, t=1)
		trot = xform(t, q=1, ro=1)
		setAttr(npom + '.inPosition', tpos[0], tpos[1], tpos[2])
		nuv = [getAttr(npom + '.parameterU'), getAttr(npom + '.parameterV')]
		# selection order is important!
		select(shape, t)
		maya.mel.eval('performPointOnPolyConstraint 0;')
		# get new constraint
		popc = listRelatives(t, type='constraint')[0]
		setAttr(popc + '.' + shapeTrans + 'U0', nuv[0])
		setAttr(popc + '.' + shapeTrans + 'V0', nuv[1])
		if maintainoffset:
			npos = getAttr(npom + '.position')[0]
			setAttr(popc + '.offsetTranslate', tpos[0] - npos[0], tpos[1] - npos[1], tpos[2] - npos[2])

	delete(npom)
	select(sel)
Beispiel #2
0
def selObjectsFromShaderWithinSelection(shader):
	from maya.cmds import ls, polyListComponentConversion, listConnections, select, sets
	from ezLib.list import uniquify
	selShapes = ls(sl=1, s=1, o=1, dag=1)
	selFaces = ls(polyListComponentConversion(tf=1), fl=1)
	selSGs = uniquify(listConnections(selShapes, type='shadingEngine'))
	inSGs  = listConnections(shader, type='shadingEngine')
	# get only SGs that are connected to the shaders in question
	# and are connected to the selected surfaces
	inSGs  = [sg for sg in inSGs if sg in selSGs]
	print 'inSGs:' + str(inSGs)
	# get remaining faces that are: connected to incoming shaders
	# and in selection
	inSGFaces = ls(polyListComponentConversion(sets(inSGs, q=1), tf=1), fl=1)
	faces = [f for f in selFaces if f in inSGFaces]
	select(faces)