def marge_uvs(self, mode='after'): #print self.s_edges if mode == 'after' and self.s_edges is not None: saw_edges = self.saw_edges + self.s_edges self.n_uvs = [] else: saw_edges = self.s_edges if not saw_edges: return cmds.polyMergeUV(saw_edges, ch=1, d=0.01) if mode == 'after': cmds.select(self.ex_edges, r=True)
def runMorph2UV(): baseObj = cmds.ls(sl=1, o=1) #1. inputmesh baseObjDup = cmds.duplicate() #2. duplicate mel.eval("FreezeTransformations") mel.eval("ResetTransformations") baseObj = baseObjDup[0] deleteNoUV() splitIfOnUVBorder() morph2UV() currentSelection = cmds.ls(sl=1) currentUV = cmds.polyListComponentConversion(currentSelection, tuv=1) cmds.polyMergeVertex(currentSelection, d=0.0001, cch=0) cmds.polyMergeUV(currentUV, d=0.001, cch=0) # fix split cmds.select(baseObj, r=1)
def mergeUVs(meshList=[], dist=0.0001): ''' Merge UVs @param meshList: List of meshes to merge UVs on. If empty, check all mesh objects in the scene. @type meshList: list ''' # Check meshList if not meshList: meshList = getMeshList(meshList) if not meshList: return [] # Merge UVs for mesh in meshList: mc.polyMergeUV(mesh, d=dist, ch=False) # Return Result return meshList
def move_uv(self, face): #print 'uv_edge :', self.uv_edge uvs = common.conv_comp(face, mode='uv') #作成したフェースのUV edge_uvs = common.conv_comp(self.uv_edge, mode='uv') #選択エッジのUV for uv in uvs: try: vtx = common.conv_comp(uv, mode='vtx') #UVが属する頂点 vtx_uv = common.conv_comp(vtx, mode='uv') #頂点の共有UVたち target_uv = list((set(vtx_uv) & set(edge_uvs)) - set(uvs)) #print 'get_target uv', target_uv, uv pos = cmds.polyEditUV(target_uv[0], query=True) cmds.polyEditUV(uv, u=pos[0], v=pos[1], r=False) except: return #UVつないでおく face_edges = common.conv_comp(face, mode='edge') cmds.polyMergeUV(face_edges, ch=1, d=0.01)
def mergeUVs(meshList=[], dist=0.0001): """ Merge UVs @param dist: @param meshList: List of meshes to merge UVs on. If empty, check all mesh objects in the scene. @type meshList: list """ # Check meshList if not meshList: meshList = getMeshList(meshList) if not meshList: return [] # Merge UVs for mesh in meshList: cmds.polyMergeUV(mesh, d=dist, ch=False) # Return Result return meshList
def tieOff(): global balloonRadius, balloonQuantity knotVals = mc.pointPosition('balloonTemp.vtx[96]', w=True) knotThickness = balloonRadius * .05 endHeight = balloonRadius * .15 knotRadius = knotVals[0] knotPos = ( knotVals[1] - (.5 * knotThickness)) mc.polyCylinder( n="knotTemp", r=knotRadius, h=knotThickness, sx=12, sy=3, sz=0, rcp=0, cuv=3) mc.delete( 'knotTemp.f[36:37]') mc.setAttr( 'knotTemp.translateY', knotPos ) mc.scale(1.25, 1.75, 1.25, 'knotTemp.vtx[12:35]', r=True ) mc.lattice( n='knot', cp=True, dv =(2, 2, 2), objectCentered=True, ldv=(2,2,2)) mc.move( (.75 * knotThickness), 'knotLattice.pt[1][0][0:1]', r=True, y=True) mc.move( (.25 * knotThickness), 'knotLattice.pt[0][0][0:1]', r=True, y=True) mc.duplicate('knotTemp') mc.rotate(180, 'knotTemp1', z=True) mc.polyCone( n="endTemp", r=knotRadius*2, h=endHeight, sx=12, sy=6, sz=3, rcp=0, cuv=3) mc.delete( 'endTemp.f[60:83]', 'endTemp.f[96:107]') mc.setAttr( 'endTemp.translateY', knotPos - knotThickness/2 ) mc.scale( 1.15, 1, 1.15, 'endTemp.vtx[36:59]') mc.move((.5 * endHeight), 'endTemp.vtx[0:11]', 'endTemp.vtx[72]', y=True, r=True) mc.polyUnite( 'balloonTemp', 'knotTemp', 'knotTemp1', 'endTemp', ch=True ) mc.polySoftEdge( a = 180 ) mc.polyMergeVertex( d=.001) mc.polyEditUV('polySurface1.map[0:126]', pu=0.5, pv=1, su=1, sv=0.575) mc.polyEditUV('polySurface1.map[127:230]', pu=0.5, pv=0.35, su=2, sv=.25) mc.polyEditUV('polySurface1.map[267:318]', u=0, v=-0.1, pu=0.5, pv=0, su=1, sv=.5) mc.polyEditUV('polySurface1.map[231:266]', 'polySurface1.map[319]', u=0, v=-.175, pu=0.5, pv=0.25, su=0.25, sv=0.25) mc.polyMergeUV('polySurface1.map[103:126]', d=0.5, ch=True ) mc.polyEditUV('polySurface1.map[104]', r=False, u=0) mc.polyEditUV('polySurface1.map[103]', r=False, u=1) mc.polySmooth('polySurface1', mth=0, dv=1, c=1, kb=0, ksb=1, khe=0, kt=1, kmb=0, suv=0, peh=0, sl=1, dpe=1, ps=0.1 , ro=1, ch=True) mc.DeleteHistory() mc.delete( 'knotTemp1') mc.rename('polySurface1', 'balloon1') mc.select(cl=True) return
def ImportToMaya(vertexArray, polygonConnects, uvArray, texturePath, texture): global g_Mesh_Index printMessage("Creating mesh...") polygonCounts = OpenMaya.MIntArray(polygonConnects.length() / 3, 3) mesh = OpenMaya.MFnMesh() transform = mesh.create(vertexArray.length(), polygonCounts.length(), vertexArray, polygonCounts, polygonConnects) printDebug("connects cnt {}".format(polygonConnects.length())) printDebug("cnt {}".format(polygonCounts.length())) printDebug("u cnt {}".format(uvArray[0].length())) printDebug("v cnt {}".format(uvArray[1].length())) # UV map. printMessage("Mapping UVs...") mesh.setUVs(uvArray[0], uvArray[1]) try: mesh.assignUVs(polygonCounts, polygonConnects) except RuntimeError: printDebug("mesh.assignUVs() failed. Assign manually...") for i in range(0, polygonConnects.length()): try: mesh.assignUV(i / 3, i % 3, polygonConnects[i]) except RuntimeError: printMessage("AssignUV failed: " + "[{}] = {}".format(i, polygonConnects[i])) # Rename mesh. printMessage("Renaming mesh...") transformDagPath = OpenMaya.MDagPath() OpenMaya.MDagPath.getAPathTo(transform, transformDagPath) meshName = cmds.rename(transformDagPath.fullPathName(), "NinjaMesh_{}".format(g_Mesh_Index)) g_Mesh_Index = g_Mesh_Index + 1 # Apply textures. printMessage("Applying textures...") shader = cmds.shadingNode("lambert", name="NinjaTexture_{}".format(g_Mesh_Index), asShader=True) cmds.select(meshName) cmds.hyperShade(assign=shader) colorMap = cmds.shadingNode("file", name="{}_colorMap".format(texture), asTexture=True) cmds.connectAttr("{}.outColor".format(colorMap), "{}.color".format(shader)) cmds.setAttr("{}.fileTextureName".format(colorMap), "{}/{}".format(texturePath, texture), type='string') # Set vertex color to White. printMessage("Forcing vertex color to white...") cmds.select(meshName) cmds.polyColorPerVertex(cdo=True, rgb=[1, 1, 1]) # Apply transformations. printMessage("Applying transformations...") cmds.setAttr("{}.rotateX".format(meshName), g_ninjarotX) cmds.setAttr("{}.rotateY".format(meshName), g_ninjarotY) cmds.setAttr("{}.rotateZ".format(meshName), g_ninjarotZ) cmds.setAttr("{}.scaleX".format(meshName), mdlscaler) cmds.setAttr("{}.scaleY".format(meshName), mdlscaler) cmds.setAttr("{}.scaleZ".format(meshName), mdlscaler) # Freeze transformations. printMessage("Zeroing new transform values...") cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0, pn=1) # Scale UVs. printMessage("Scaling UVs...") uvs = cmds.polyListComponentConversion(meshName, tuv=True) cmds.select(uvs) cmds.polyEditUV(su=uvscaler, sv=uvscaler * g_flipUV) # Normalize UV. if g_normalizeUV: printMessage("Normalizing UVs...") cmds.polyNormalizeUV(nt=1, pa=True, centerOnTile=True) # Merge duplicates. printMessage("Removing duplicate vertex...") cmds.select(cl=True) cmds.select(meshName) cmds.polyMergeVertex(d=0.01, am=True, ch=1) cmds.polyMergeUV(d=0.01, ch=True) # Reverse normals (First met in MWR) if g_reverseNormals: printMessage("Reversing normals...") cmds.select(cl=True) cmds.select(meshName) cmds.polyNormal(meshName, ch=1) cmds.select(cl=True) print("Import done for mesh '{}'".format(meshName))
def polyMergeUV(*args, **kwargs): res = cmds.polyMergeUV(*args, **kwargs) if not kwargs.get('query', kwargs.get('q', False)): res = _factories.maybeConvert(res, _general.PyNode) return res
def ImportToMaya(vertexArray, polygonConnects, uvArray, texturePath, texture): global g_Mesh_Index printMessage("Creating mesh...") polygonCounts = OpenMaya.MIntArray(polygonConnects.length() / 3, 3) mesh = OpenMaya.MFnMesh() transform = mesh.create( vertexArray.length(), polygonCounts.length(), vertexArray, polygonCounts, polygonConnects ) printDebug("connects cnt {}".format(polygonConnects.length())) printDebug("cnt {}".format(polygonCounts.length())) printDebug("u cnt {}".format(uvArray[0].length())) printDebug("v cnt {}".format(uvArray[1].length())) # UV map. printMessage("Mapping UVs...") mesh.setUVs(uvArray[0], uvArray[1]) try: mesh.assignUVs(polygonCounts, polygonConnects) except RuntimeError: printDebug("mesh.assignUVs() failed. Assign manually...") for i in range(0, polygonConnects.length()): try: mesh.assignUV(i / 3, i % 3, polygonConnects[i]) except RuntimeError: printMessage("AssignUV failed: " + "[{}] = {}".format(i, polygonConnects[i])) # Rename mesh. printMessage("Renaming mesh...") transformDagPath = OpenMaya.MDagPath() OpenMaya.MDagPath.getAPathTo(transform, transformDagPath) meshName = cmds.rename( transformDagPath.fullPathName(), "NinjaMesh_{}".format(g_Mesh_Index) ) g_Mesh_Index = g_Mesh_Index + 1 # Apply textures. printMessage("Applying textures...") shader = cmds.shadingNode( "lambert", name="NinjaTexture_{}".format(g_Mesh_Index), asShader=True ) cmds.select(meshName) cmds.hyperShade(assign=shader) colorMap = cmds.shadingNode( "file", name="{}_colorMap".format(texture), asTexture=True ) cmds.connectAttr( "{}.outColor".format(colorMap), "{}.color".format(shader) ) cmds.setAttr( "{}.fileTextureName".format(colorMap), "{}/{}".format(texturePath, texture), type='string' ) # Set vertex color to White. printMessage("Forcing vertex color to white...") cmds.select(meshName) cmds.polyColorPerVertex(cdo=True, rgb=[1, 1, 1]) # Apply transformations. printMessage("Applying transformations...") cmds.setAttr("{}.rotateX".format(meshName), g_ninjarotX) cmds.setAttr("{}.rotateY".format(meshName), g_ninjarotY) cmds.setAttr("{}.rotateZ".format(meshName), g_ninjarotZ) cmds.setAttr("{}.scaleX".format(meshName), mdlscaler) cmds.setAttr("{}.scaleY".format(meshName), mdlscaler) cmds.setAttr("{}.scaleZ".format(meshName), mdlscaler) # Freeze transformations. printMessage("Zeroing new transform values...") cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0, pn=1) # Scale UVs. printMessage("Scaling UVs...") uvs = cmds.polyListComponentConversion(meshName, tuv=True) cmds.select(uvs) cmds.polyEditUV(su=uvscaler, sv=uvscaler*g_flipUV) # Normalize UV. if g_normalizeUV: printMessage("Normalizing UVs...") cmds.polyNormalizeUV(nt=1, pa=True, centerOnTile=True) # Merge duplicates. printMessage("Removing duplicate vertex...") cmds.select(cl=True) cmds.select(meshName) cmds.polyMergeVertex(d=0.01, am=True, ch=1) cmds.polyMergeUV(d=0.01, ch=True) # Reverse normals (First met in MWR) if g_reverseNormals: printMessage("Reversing normals...") cmds.select(cl=True) cmds.select(meshName) cmds.polyNormal(meshName, ch=1) cmds.select(cl=True) print("Import done for mesh '{}'".format(meshName))