本文整理汇总了Python中maya.cmds.polyEvaluate函数的典型用法代码示例。如果您正苦于以下问题:Python polyEvaluate函数的具体用法?Python polyEvaluate怎么用?Python polyEvaluate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了polyEvaluate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getFaces
def getFaces():
# count faces
faceCount = cmds.polyEvaluate(geometryName[0],f=True)
# make a list of face count
faceRange = list(range(1,faceCount))
# empty list for face
faceList = []
# for each face in faceRange, get the name of the face
for f in faceRange:
# get the name of each face on the model
face = (str(geometryName[0])+'.f['+str(f)+']')
# append each face to the faceList
faceList.append(face)
faceCount = cmds.polyEvaluate(geometryName[0],f=True)
# empty list for facebounds
fb = []
# if the faceList is equal to the number of faces found
if len(faceList) == faceCount-1:
# for each face name found in face list
for face in faceList:
# select each face
cmds.select(face)
# get the UV bounding box on each face
faceBounds = cmds.polyEvaluate(bc2=True)
# print the facebounds
fb.append(faceBounds)
if len(fb) == len(faceList):
return fb,faceList
示例2: MeshDict
def MeshDict(mesh = None, pointCounts = True, calledFrom = None):
"""
Validates a mesh and returns a dict of data.
If a shape is the calling object, it will be the shape returned, otherwise, the first shape in the chain will be
:param mesh: mesh to evaluate
:returns:
dict -- mesh,meshType,shapes,shape,pointCount,pointCountPerShape
"""
_str_funcName = 'MeshDict'
if calledFrom: _str_funcName = "{0} calling {1}".format(calledFrom,_str_funcName)
_mesh = None
if mesh is None:
_bfr = mc.ls(sl=True)
if not _bfr:raise ValueError,"No selection found and no source arg"
mesh = _bfr[0]
log.info("{0}>> No source specified, found: '{1}'".format(_str_funcName,mesh))
_type = search.returnObjectType(mesh)
_shape = None
_callObjType = None
if _type in ['mesh']:
_mesh = mesh
_callObjType = 'meshCall'
elif _type in ['shape']:
_shape = mesh
_callObjType = 'shapeCall'
_mesh = getTransform(mesh)
else:
raise ValueError,"{0} error. Not a usable mesh type : obj: '{1}' | type: {2}".format(_str_funcName, mesh, _type)
_shapes = mc.listRelatives(_mesh,shapes=True,fullPath=False)
if _shape is None:
_shape = _shapes[0]
_return = {'mesh':_mesh,
'meshType':_type,
'shapes':_shapes,
'shape':_shape,
'callType':_callObjType,
}
if pointCounts:
if _callObjType == 'shapeCall':
_return['pointCount'] = mc.polyEvaluate(_shape, vertex=True)
else:
_l_counts = []
for s in _return['shapes']:
_l_counts.append( mc.polyEvaluate(s, vertex=True))
_return['pointCountPerShape'] = _l_counts
_return['pointCount'] = sum(_l_counts)
return _return
示例3: returnObjectSize
def returnObjectSize(obj,debugReport = False):
"""
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DESCRIPTION:
Semi intelligent object sizer. Currently works for verts, edges,
faces, poly meshes, nurbs surfaces, nurbs curve
ARGUMENTS:
obj(string) - mesh or mesh group
RETURNS:
size(float)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"""
objType = search.returnObjectType(obj)
#>>> Poly
if objType == 'mesh':
size = mc.polyEvaluate(obj,worldArea = True)
if debugReport: print ('%s%f' %('mesh area is ',size))
return size
elif objType == 'polyVertex':
meshArea = mc.polyEvaluate(obj,worldArea = True)
splitBuffer = obj.split('.')
vertices = mc.ls ([splitBuffer[0]+'.vtx[*]'],flatten=True)
size = meshArea/len(vertices)
if debugReport: print ('%s%f' %('Average mesh area per vert is ',size))
return size
elif objType == 'polyEdge':
size = returnEdgeLength(obj)
if debugReport: print ('%s%f' %('The Edge length is ',size))
return size
elif objType == 'polyFace':
size = returnFaceArea(obj)
if debugReport: print ('%s%f' %('face area is ',size))
return size
#>>> Nurbs
elif objType == 'nurbsSurface':
boundingBoxSize = returnBoundingBoxSize(obj)
size = cgmMath.multiplyList(boundingBoxSize)
if debugReport: print ('%s%f' %('Bounding box volume is ',size))
return size
elif objType == 'nurbsCurve':
size = returnCurveLength(obj)
if debugReport: print ('%s%f' %('Curve length is ',size))
return size
else:
if debugReport: print ("Don't know how to handle that one")
return False
示例4: copyWeights
def copyWeights(sourceMesh, targetMesh, sourceDeformer, targetDeformer):
"""
Copy deformer weights from one mesh to another.
Source and Target mesh objects must have matching point order!
@param sourceMesh: Mesh to copy weights from
@type sourceMesh: str
@param targetMesh: Mesh to copy weights to
@type targetMesh: str
@param sourceDeformer: Deformer to query weights from
@type sourceDeformer: str
@param targetDeformer: Deformer to apply weights to
@type targetDeformer: str
"""
# Check source and target mesh
if not mc.objExists(sourceMesh):
raise Exception('Source mesh "' + sourceMesh + '" does not exist!!')
if not mc.objExists(targetMesh):
raise Exception('Target mesh "' + targetMesh + '" does not exist!!')
# Check deformers
if not mc.objExists(sourceDeformer):
raise Exception('Source deformer "' + sourceDeformer + '" does not exist!!')
if targetDeformer and not mc.objExists(targetDeformer):
raise Exception('Target deformer "' + targetDeformer + '" does not exist!!')
if not targetDeformer:
targetDeformer = sourceDeformer
# Compare vertex count
if mc.polyEvaluate(sourceMesh, v=True) != mc.polyEvaluate(targetMesh, v=True):
raise Exception("Source and Target mesh vertex counts do not match!!")
# Copy weights
wtList = glTools.utils.deformer.getWeights(sourceDeformer, sourceMesh)
# Paste weights
glTools.utils.deformer.setWeights(targetDeformer, wtList, targetMesh)
示例5: triangulateMesh
def triangulateMesh(isObj, simplify, smoothe):
if isObj and not cmds.objExists('triObj'):
cmds.select(baseObject)
cmds.duplicate(baseObject, name = "triObj")
cmds.select('triObj')
if smoothe:
cmds.polySmooth('triObj', c=smoothe)
cmds.polyReduce(ver = 1)
cmds.polyReduce(ver = 1)
if simplify > 0:
cmds.polyReduce(ver = 1, p = simplify)
num_faces = cmds.polyEvaluate('triObj', f=True)
print "Triangulating faces..."
#iterate over faces
face_i = 0
while face_i < num_faces:
if ((num_faces - face_i) % 5 == 0):
print "Triangulate check: Approximately " + str(num_faces - face_i) + " faces remaining...."
face = cmds.select('triObj.f['+ str(face_i)+']')
verts = getCorners(isObj,face_i)
if not isCoplanar(verts):
cmds.polyTriangulate('triObj.f['+ str(face_i)+']')
num_faces = cmds.polyEvaluate('triObj', f=True)
face_i +=1
示例6: get_invalid
def get_invalid(cls, instance):
invalid = []
for node in cmds.ls(instance, type='mesh'):
uv = cmds.polyEvaluate(node, uv=True)
if uv == 0:
invalid.append(node)
continue
vertex = cmds.polyEvaluate(node, vertex=True)
if uv < vertex:
# Workaround:
# Maya can have instanced UVs in a single mesh, for example
# imported from an Alembic. With instanced UVs the UV count from
# `maya.cmds.polyEvaluate(uv=True)` will only result in the unique
# UV count instead of for all vertices.
#
# Note: Maya can save instanced UVs to `mayaAscii` but cannot
# load this as instanced. So saving, opening and saving
# again will lose this information.
uv_to_vertex = cmds.polyListComponentConversion(node + ".map[*]",
toVertex=True)
uv_vertex_count = len_flattened(uv_to_vertex)
if uv_vertex_count < vertex:
invalid.append(node)
else:
cls.log.warning("Node has instanced UV points: {0}".format(node))
return invalid
示例7: hfSplitBadShaded
def hfSplitBadShaded(self, engines):
modifiedShapes = []
for sg in engines:
print('checking shading group: '+sg)
cmds.hyperShade(objects=sg)
components = cmds.ls(sl=1)
uniqueShapes = []
for entry in components:
uniqueShapes.append(entry.split('.')[0])
# remove whole shapes (not components) from the list.
if entry.rfind('.f') == -1:
components.remove(entry)
if len(components) > 0:
components.sort()
# remove duplicates from uniqueShapes.
uniqueShapes = list(set(uniqueShapes))
modifiedShapes.extend(uniqueShapes)
# print('\nunique shapes under shading group: ')
# print(uniqueShapes)
for shape in uniqueShapes:
cmds.select(cl=1)
# get the total num of faces for the shape for later use.
totalFaces = cmds.polyEvaluate(shape, f=1)
for comp in components:
testStr = shape+'.f['
if testStr in comp:
# the current component is a member of the current mesh we're splitting and it has the shader we want.
cmds.select(comp, add=1)
selFaces = cmds.ls(sl=1)
# print 'selection:'
# print selFaces
# extract the selected faces if we aren't selecting every face of the current mesh.
if len(selFaces) < int(totalFaces) and len(selFaces) > 0:
cmds.polyChipOff(selFaces, kft=1, dup=0)
cmds.delete(shape,ch=1)
# now the mesh is broken into shells. separate it if possible.
if cmds.polyEvaluate(shape, s=1) > 1:
newObjects = cmds.polySeparate(shape, ch=0)
modifiedShapes.extend(newObjects)
# print('split new shapes: ')
# print(newObjects)
cmds.select(newObjects)
# print(cmds.ls(sl=1))
cmds.delete(ch=1)
cmds.select(cl=1)
# now in order to return all the new meshes we made, we should sort through uniqueShapes and remove anything that no longer
# exists. anything that's been split, etc.
modifiedShapes = list(set(modifiedShapes))
returnShapes = []
for shape in modifiedShapes:
if cmds.objExists(shape) == 0:
modifiedShapes.remove(shape)
else:
meshNodes = cmds.listRelatives(shape, s=1)
if meshNodes != None:
# if we are not testing an xform, meshNodes will be a 'NoneType' object so we should include an exception.
returnShapes.extend(meshNodes)
return returnShapes
示例8: ftb_gen_shell_doIt
def ftb_gen_shell_doIt(dist,distUV,div):
if (mc.window('shellUiWin',q=True,exists=True)):
mc.deleteUI('shellUiWin')
#mc.loadPlugin( 'c:/ftb_mayaplugins/ppl/2011 x64/shellNode.mll')
sel = mc.ls(sl=True)
if(len(sel)!= 0):
shape = mc.listRelatives(sel[0],noIntermediate = True,shapes=True)
His = mc.listHistory(shape[0])
shell = ''
for h in His:
if(mc.nodeType(h) == 'polyShell'):
shell = h
if(shell == ''):
if(mc.attributeQuery('shThickness',node=shape[0],ex=True)):
dist = mc.getAttr(shape[0]+'.shThickness')
else:
mc.addAttr(shape[0],ln="shThickness",at='double',dv=0)
mc.setAttr(shape[0]+'.shThickness',e=True,keyable=True)
if(mc.attributeQuery('shUvThickness',node=shape[0],ex=True)):
distUV = mc.getAttr(shape[0]+'.shUvThickness')
else:
mc.addAttr(shape[0],ln="shUvThickness",at='double',dv=0)
mc.setAttr(shape[0]+'.shUvThickness',e=True,keyable=True)
if(mc.attributeQuery('shDiv',node=shape[0],ex=True)):
div = mc.getAttr(shape[0]+'.shDiv')
else:
mc.addAttr(shape[0],ln="shDiv",at='long',dv=0,min=0)
mc.setAttr(shape[0]+'.shDiv',e=True,keyable=True)
faceInitalCount = mc.polyEvaluate(sel[0],f=True)
mc.polyShell(thickness = dist,uvOffset = distUV);
sel2 = mc.ls(sl=True)
faceFinalCount = mc.polyEvaluate(sel[0],f=True)
mc.addAttr(sel2[0],ln="div",at='long',min=0,dv=0)
mc.setAttr(sel2[0]+'.div',e=True,keyable=True)
mc.setAttr(sel2[0]+'.div',div)
mc.addAttr(sel2[0],ln="splits",dt="string")
mc.setAttr(sel2[0]+'.splits',e=True,keyable=True)
mc.select((sel[0]+'.f[%i' % (faceInitalCount*2)+':%i' % faceFinalCount+']'))
faceList = mc.ls(sl=True,fl=True)
facesRings = makeFaceRingGroups(faceList)
for faceRing in facesRings:
mc.select(facesRings[faceRing])
mc.ConvertSelectionToContainedEdges()
mc.setAttr(sel2[0]+'.thickness',0.2)
split = mc.polySplitRing(mc.ls(sl=True),ch=True,splitType=2,divisions=0,useEqualMultiplier=1,smoothingAngle=30,fixQuads=1)
splits = mc.getAttr(sel2[0]+'.splits')
if(splits == None):
splits = ""
mc.setAttr(sel2[0]+'.splits',("%s"%splits+"%s,"%split[0]),type="string")
mc.connectAttr(sel2[0]+'.div', (split[0]+'.divisions'))
mc.setAttr(sel2[0]+'.thickness',dist)
mc.connectAttr(sel2[0]+'.thickness',shape[0]+'.shThickness')
mc.connectAttr(sel2[0]+'.uvOffset',shape[0]+'.shUvThickness')
mc.connectAttr(sel2[0]+'.div',shape[0]+'.shDiv')
else:
print('This mesh have a shellModifier allready!!!!!')
else:
mc.error("please select some mesh")
示例9: setObjectAsCanvas
def setObjectAsCanvas(name):
cmds.polyEvaluate(f=True)
subdivSurface = cmds.polyToSubdiv(maxPolyCount=cmds.polyEvaluate(f=True), maxEdgesPerVert=32, ch=False)[0]
liveSurface = cmds.subdToNurbs(subdivSurface, ot=0, ch=False)
cmds.delete(subdivSurface)
cmds.hide(liveSurface)
cmds.makeLive(liveSurface)
return liveSurface
示例10: cutCell
def cutCell(obj, mat, pos, rot, shardsGRP):
#do the cut procedure
tocut = mc.polyEvaluate(obj, face = True)
mc.polyCut( ('%s.f[0:%d]'% (obj,tocut)), pc = (pos[0], pos[1], pos[2]), ro = (rot[0], rot[1], rot[2]), ch = False, df = True)
cutFaces = mc.polyEvaluate(obj, face = True)
mc.polyCloseBorder(obj, ch = False)
newFaces = mc.polyEvaluate(obj, face = True)
newFaces = newFaces - cutFaces
#assign material to faces
for face in range(newFaces):
mc.sets( ( '%s.f[ %d ]' % (obj, (cutFaces + newFaces - 1))), forceElement = ('%sSG' % (mat)), e = True)
示例11: initMeshFromMayaMesh
def initMeshFromMayaMesh(self, meshName):
_vs = []
_faces = []
numV = mc.polyEvaluate(meshName, v=True)
numF = mc.polyEvaluate(meshName, f=True)
for i in range(numV):
_vs.append(mc.pointPosition(meshName+".vtx["+str(i)+"]"))
for i in range(numF):
_faces.append(self.faceVtxList(meshName+".f["+str(i)+"]"))
self.vs = _vs
self.faces = _faces
示例12: rec
def rec(object_name, volume_total, cut_planes, volume_ratios, threshold, result, loop_num):
# base cases
if loop_num == 0:
print 'insert more coins to continue'
return False
elif mc.polyEvaluate(object_name, shell = True) > 1:
# more than one shell in object named 'object_name'
print 'NO REDEMPTION'
return False
elif len(volume_ratios) == 1:
# check ratio matches
this_ratio = mm.eval('meshVolume(\"' + object_name + '\")') / volume_total
# since its last one, might have more errors
if abs(this_ratio - volume_ratios[0]) < threshold * 4:
# duplicate the object
temp = mc.duplicate(object_name)
mc.select(temp[0], r = True)
# move away the duplication
mc.move(kMoveAwayXDistance, 0, 0, temp[0])
# remove the current object
mc.delete(object_name)
print 'DONE with last object!'
result.append(temp[0])
print result
return True
else:
print 'last object did NOT match last ratio!', this_ratio, volume_ratios[0]
return False
# recursive step
random.shuffle(cut_planes)
result_from_cutting = cut_object_with_planes_and_ratios(object_name, volume_total, cut_planes, volume_ratios, threshold)
if isinstance(result_from_cutting, list):
# this list contains all successfully cut objects and we are done
result.extend(result_from_cutting)
print 'lucky!'
print result
return True
else:
print 'Enter recursive step'
# dictionary returned
# extend result list with what we have now
result.extend(result_from_cutting['good_cut_objs'])
# merge the remaining objects into one
bad_cut_objs = result_from_cutting['bad_cut_objs']
if mc.polyEvaluate(bad_cut_objs, shell = True) > 1:
united_objects = mc.polyUnite(bad_cut_objs)[0]
mc.polyMergeVertex(united_objects)
else:
united_objects = bad_cut_objs[0]
# get list of ratios un-resolved
ratios_remaining = result_from_cutting['ratios_remaining']
recursion_result = rec(united_objects, volume_total, cut_planes, ratios_remaining, threshold, result, loop_num-1)
return recursion_result
示例13: create
def create(self):
"""create hairsystem for lock"""
numFace = mc.polyEvaluate( self.mesh.shape.name, f = True )
numVert = mc.polyEvaluate( self.mesh.shape.name, v = True )
if not self.hairSystem:
print 'There is no hairSystem assigned to this HairLock --> init with one or assign one.... '
if not numFace % 2 or not numVert == ( numFace + 3 ):
print 'This mesh dosen\'t have odd number of faces', self.mesh.name, 'SKYPING'
return
self._curveMesh = mn.createNode('curvesFromMesh' )
self._curveMesh.name = self.mesh.name + '_curveMesh'
self.mesh.shape.a.outMesh >> self._curveMesh.a.inMesh
self.mesh.shape.a.worldMatrix >> self._curveMesh.a.inWorldMatrix
for i in range(5):
hairCurve = mn.createNode('nurbsCurve' )
hairCurveParent = hairCurve.parent
hairCurveParent.name = self.mesh.name + '_%i'%i + '_crv'
hairCurve = hairCurveParent.shape
self._curveMesh.attr( 'outCurve[%i'%i + ']' ) >> hairCurve.a.create
follicle = mn.createNode('follicle')
folliclePar = follicle.parent
folliclePar.name = self.mesh.name + '_%i'%i + '_foll'
follicle = folliclePar.shape
hairSustemOutHairSize = self.hairSystem.a.outputHair.size
follicle.a.outHair >> self.hairSystem.attr( 'inputHair[%i'%hairSustemOutHairSize + ']' )
#follicle.a.outHair >> self.hairSystem.attr( 'inputHair[%i'%i + ']' )
hairCurve.a.worldSpace >> follicle.a.startPosition
self.hairSystem.attr( 'outputHair[%i'%hairSustemOutHairSize + ']' ) >> follicle.a.currentPosition
self._follicles.append(follicle)
self._curves.append(hairCurve)
#if there is a scalp mesh use that for the position of the follicle
if self.scalp:
self.scalp.shape.a.outMesh >> follicle.a.inputMesh
self.scalp.a.worldMatrix >> follicle.a.inputWorldMatrix
u,v = self._getUVCoordFromScalpForFollicle( hairCurve )
follicle.a.parameterV.v = v
follicle.a.parameterU.v = u
#hairCurveParent.parent = folliclePar
else:
self.mesh.shape.a.outMesh >> follicle.a.inputMesh
self.mesh.a.worldMatrix >> follicle.a.inputWorldMatrix
follicle.a.parameterV.v = 0.5
follicle.a.parameterU.v = 0.5
follicle.a.overrideDynamics.v = 0
follicle.a.startDirection.v = 1
follicle.a.clumpWidthMult.v = 1.5
follicle.a.densityMult.v = 0.5
follicle.a.sampleDensity.v = 1.5
follicle.a.outTranslate >> follicle.parent.a.translate
follicle.a.outRotate >> follicle.parent.a.rotate
示例14: flipWeights
def flipWeights(sourceDeformer,targetDeformer,sourceInfluence,targetInfluence,axis='x'):
'''
'''
# Check dnBurlyDeformer
if not glTools.utils.dnBurlyDeformer.isBurlyDeformer(sourceDeformer):
raise Exception('A valid source dnBurlyDeformer must be provided!')
if not isBurlyDeformer(targetDeformer):
raise Exception('A valid target dnBurlyDeformer must be provided!')
# Get influence indices
sourceInfluenceIndex = glTools.utils.dnBurlyDeformer.getInfluenceIndex(sourceDeformer,sourceInfluence)
targetInfluenceIndex = glTools.utils.dnBurlyDeformer.getInfluenceIndex(targetDeformer,targetInfluence)
# Get affected geometry
sourceGeo = glTools.utils.deformer.getAffectedGeometry(sourceDeformer).keys()[0]
targetGeo = glTools.utils.deformer.getAffectedGeometry(targetDeformer).keys()[0]
sourceGeoPntNum = mc.polyEvaluate(sourceGeo,v=True)
targetGeoPntNum = mc.polyEvaluate(targetGeo,v=True)
# Get source influence weights
sourceInfluenceWeights = glTools.utils.dnBurlyDeformer.getInfluenceWeights(dnBurlyDeformer,sourceInfluence)
# Get affected geometry
targetInfluenceWeights = [0.0 for i in range(targetGeoPntNum)]
# Build vertex correspondence table
vtxTable = []
for i in range(sourceGeoPntNum):
# Get source vertex position
pos = glTools.utils.base.getPosition(sourceGeo+'.vtx['+str(i)+']')
# Get mirror position
mPos = pos
mPos[axisInd] *= -1.0
# Get closest vertex to mirror position
mVtx = glTools.utils.mesh.closestVertex(targetGeo,mPos)
vtxTable.append(mVtx)
# Build target influence weights
for i in range(len(sourceInfluenceWeights)):
targetInfluenceWeights[vtxTable[i]] = sourceInfluenceWeights[i]
# Set influence weights
glTools.utils.dnBurlyDeformer.setInfluenceWeights(targetDeformer,targetInfluence,targetInfluenceWeights)
# Rebind influence
mm.eval('dnBurlyDeformer -rebindMuscle "'+targetDeformer+'" "'+targetInfluence+'"')
示例15: isComponent
def isComponent(shape):
result = None
cmds.select(shape)
vert = cmds.polyEvaluate(vertexComponent=True)
face = cmds.polyEvaluate(faceComponent=True)
edge = cmds.polyEvaluate(edgeComponent=True)
if vert > 0:
result = "vert"
elif face > 0:
result = "face"
elif edge > 0:
result = "edge"
else:
result = False
return result