def dupHairMesh(mirror=False, axis='x', space='world'): '''duplicate a HairTube''' hairInfoAll = selHair(returnInfo=True) if not hairInfoAll: return Cgroups = [] for hair in hairInfoAll: pm.select(hair[0][0], hair[1]) ctrls = hair[1].listRelatives(type=pm.nt.Transform) pm.duplicate(ic=1, un=1) if mirror: #mirrorTransform(hair[1]) pm.polyNormal(hair[0][0], nm=3) oldPos = hair[1].getTranslation(space='world') print oldPos if not hair[1].isVisible(): c.show() for c in ctrls: if not c.isVisible(): c.show() if space == 'world': pm.parent(c, w=1) mirrorTransform(c, axis=axis) pm.parent(c, hair[1]) else: mirrorTransform(c, axis=axis) #c.hide() #hair[1].hide() pm.select(hair[0][0], r=1) randU() selHair(setPivot=True) if mirror and space != 'world': hair[1].setTranslation(oldPos, space='world') Cgroups.append(hair[1]) pm.select(Cgroups, r=1)
def fix_normals(cls): selection = pm.ls(sl=1) pm.polySetToFaceNormal() for item in selection: pm.polyNormal(item, normalMode=2, userNormalMode=0, ch=1) pm.polySoftEdge(item, a=30, ch=1) pm.delete(ch=1) pm.select(selection)
def mirror_transform(ob, axis="x",xform=[0,4]): axisDict = { "x":('tx', 'ry', 'rz', 'sx'), "y":('ty', 'rx', 'rz', 'sy'), "z":('tz', 'rx', 'ry', 'sz')} #print obs for at in axisDict[axis][xform[0]:xform[1]]: ob.attr(at).set(ob.attr(at).get()*-1) pm.makeIdentity(ob,s=True,apply=True) if get_shape(ob): pm.polyNormal(ob, nm=0) pm.bakePartialHistory(ob, all=True) for obs in ob.listRelatives(type='transform'): if get_shape(obs): pm.polyNormal(obs, nm=0) pm.bakePartialHistory(obs, all=True) pm.select(ob)
def reverseOppositeGeometry(): """ Finds and reverses meshes under selection with opposite flag set. """ sel_list = pm.ls( sl=1, dag=1, type="mesh" ) if not sel_list: mel.warning( "No meshes found in selection." ) count = 0 for obj in sel_list: if obj.opposite.get(): obj.opposite.set( 0 ) pm.polyNormal( obj, normalMode=0, userNormalMode=0, ch=0 ) count += 1 print '// Results: %d opposite meshes reversed.' % count
def reverseNormalsAndPreserveUVs(mesh): ''' reverse normals but keep the uvs the same (don't change from blue to red, etc) this will break uv seams!!! ''' # duplicate the mesh to keep a copy of the correct uvs dupMesh = pm.duplicate(mesh) # reverse normals on the mesh pm.polyNormal(mesh, nm=0, ch=0) # transfer correct uvs back to mesh pm.transferAttributes(dupMesh, mesh, uvs=2, spa=4) pm.delete(mesh, ch=True) # cleanup pm.delete(dupMesh)
def reverse_normals(cls): selection = pm.ls(sl=1) for item in selection: pm.polyNormal(item, normalMode=0, userNormalMode=0, ch=1) pm.delete(ch=1) pm.select(selection)
def selHair(selectTip=False, selectRoot=False, selectAll=False, pivot=0, setPivot=True, returnInfo=False, rebuild=[False, 7, 4], cShape=(False, 'circle', 1)): '''Select Hair Controls''' sel = pm.selected() if not sel: return ### check for right Selection hairMeshes = [] for o in sel: #print o.getParent() == pm.ls('HairCtrlGroup')[0] if (type(o.getShape()) == pm.nodetypes.NurbsCurve or o.getParent() == pm.ls('HairCtrlGroup')[0]): try: if o.getParent() == pm.ls('HairCtrlGroup')[0]: o = o.listRelatives(type=pm.nodetypes.Transform)[0] hairLoft = o.getShape().listConnections( type=pm.nodetypes.Loft)[0] hairTes = hairLoft.listConnections( type=pm.nodetypes.NurbsTessellate)[0] hair = hairTes.listConnections(type=pm.nodetypes.Transform)[0] except: continue elif (type(o.getShape()) == pm.nodetypes.Mesh and o.listConnections(type=pm.nodetypes.NurbsTessellate)): hair = o hairTes = o.listConnections(type=pm.nodetypes.NurbsTessellate)[0] hairLoft = hairTes.listConnections(type=pm.nodetypes.Loft)[0] #print hair, hairTes, hairLoft else: continue if all([hair, hairTes, hairLoft]): hairMeshes.append((hair, hairTes, hairLoft)) else: print "Something wrong with getting hair Tesselate and Loft" return if hairMeshes: #print hairMeshes ### getting all Controls Cgroups = [] for hair in hairMeshes: try: #print hair hairLoft = hair[2] ctrls = [ c for c in hairLoft.listConnections() if type(c) == pm.nt.Transform ] ControlGroup = ctrls[0].getParent() #print ControlGroup if setPivot: pm.xform(ControlGroup, ws=1, piv=pm.xform(ControlGroup.listRelatives( type=pm.nodetypes.Transform)[pivot], q=1, ws=1, piv=1)[:3]) if rebuild[0]: NewControls = ControlGroup.listRelatives( type=pm.nodetypes.Transform) #print NewControls if cShape[0]: for c in NewControls: rebuildControl(c, obshape=cShape[1], ra=cShape[2]) oldname = hair[0].name() oldParent = hair[0].getParent() curMaterial = hair[0].getShape().listConnections( type=pm.nodetypes.ShadingEngine)[0].name() pm.rename(hair[0], '_'.join([oldname, 'old'])) newHair = createHairMesh(NewControls, name=oldname, mat=curMaterial, lengthDivs=rebuild[1], widthDivs=rebuild[2]) pm.parent(newHair[0], oldParent) #print hair[0] #print hair[0].getShape().listConnections(type=pm.nt.PolyTweakUV)[0].listConnections(type=pm.nt.PolyNormal) if hair[0].getShape().listConnections( type=pm.nt.PolyTweakUV)[0].listConnections( type=pm.nt.PolyNormal): try: pm.polyNormal(newHair[0], nm=3) except: print "can't reverse" pm.delete(hair[0]) del hair hair = newHair[0] except: continue if ControlGroup: #print ControlGroup Cgroups.append((hair, ControlGroup)) ### select as Requested if Cgroups: #print Cgroups if not returnInfo: pm.select(d=1) for cGroup in Cgroups: #print cGroup[1] for c in cGroup[1].listRelatives(type=pm.nt.Transform): c.show() if selectTip: hairTipsList = cGroup[1].listRelatives( type=pm.nt.Transform)[-1] pm.select(hairTipsList, add=1) elif selectRoot: hairRootsList = cGroup[1].listRelatives( type=pm.nt.Transform)[0] pm.select(hairRootsList, add=1) elif selectAll: pm.select( cGroup[1].listRelatives(type=pm.nt.Transform), add=1) else: pm.select(cGroup[1], add=1) else: return Cgroups