def create_auto_uvmap(cls): """creates automatic uv maps for the selected objects and layouts the uvs. Fixes model problems along the way. """ for node in pm.selected(): pm.polyAutoProjection( node, lm=0, pb=0, ibd=1, cm=0, l=2, sc=1, o=1, p=6, ps=0.2, ws=0 ) pm.select(node) f = Modeling.select_zero_uv_area_faces() if f: print("DELETED Faces!") pm.delete(f) pm.select(node) try: pm.u3dLayout(node, res=256, scl=3, spc=0.0078125, mar=0.0078125, box=(0, 1, 0, 1)) except RuntimeError as e: if 'non-manifold UVs' in str(e): pm.mel.eval('Unfold3DFixNonManifold({"nonManifoldUV"})') pm.u3dLayout(node, res=256, scl=3, spc=0.0078125, mar=0.0078125, box=(0, 1, 0, 1)) pm.select(node) pm.mel.eval('DeleteHistory;') pm.select(node)
def fix(self): for node in self.selection: pm.polyAutoProjection(node) msg = self.fix_msg.format(len(self.selection), ", ".join(self.selection)) return True, msg
def applyUV(*args): pm.polyAutoProjection(lm=0, pb=0, ibd=1, cm=0, l=2, sc=1, o=1, p=6, ps=.2, ws=0)
def __init__(self, geoList=pm.ls(sl=True), mapRes=1024, texelDensity=16, autoSeamAngle=0, autoProject=True, autoSeam=True, autoCutUV=True): """ :param geoList: :param mapRes: :param texelDensity: :param autoSeamAngle: :param autoProject: :param autoSeam: :param autoCutUV: """ area = 0 for geo in geoList: print 'Current Geo: ', geo.name() # fi non Manifold UV self.fixNonManifoldUV(geo) # Automatic Projection UV if autoProject: pm.polyAutoProjection(geo.f[:], lm=0, pb=0, ibd=1, cm=0, l=0, sc=0, o=0, p=6, ps=0.2, ws=0) # Auto Seam 1 if autoSeam: self.autoSeamUV(geo, autoSeamAngle) # Unfold3D Optimize self.unfoldOptimizeUV(geo) # set Texel Density self.setTexelDensity(geo, texelDensity, mapRes) # Layout self.uvLayoutFast(geo) # check UV boundaries if autoCutUV: self.recursiveCutUV(geo) # delete history pm.delete(geo, ch=1) area = area + pm.polyEvaluate(geo, uvArea=True) print 'Total Area: ', area, ' -- RoundUp: ', math.ceil(area) # Layout with TexelDensity self.finalLayoutUV(geoList, area) # pm.select(geoList) print 'Auto UV Complete!'
def applyAutomaticUV(*arg): # Check meshList meshList = pm.ls(type='mesh') if not meshList: return [] # Check Missing UV Sets for mesh in meshList: if mesh.isIntermediate(): continue uv = mesh.getUVs()[0] if not uv: pm.polyAutoProjection(mesh.faces, ch=0) pm.select(cl=True) # Return Result return 'ok'
def auto_project(): sel = pm.ls(sl=True) for s in sel: shapes = pm.listRelatives(s, shapes=True) for shape in shapes: pm.polyAutoProjection(shape)
def import_model(body_index, settings, loading_box): global body_file global palette global resources lba_model = read_lba2_model(body_file[body_index]) materials = [] if settings.use_palette: pm.progressWindow(loading_box, edit=True, status="Generating Palette...", progress=5) # get list with all used palette values for i in range(len(lba_model.polygons)): materials.append(lba_model.polygons[i].colour) for i in range(len(lba_model.spheres)): materials.append(lba_model.spheres[i].colour) for i in range(len(lba_model.lines)): materials.append(lba_model.lines[i].colour) materials = list(dict.fromkeys(materials)) create_materials(materials) bones = None if settings.use_rigging: pm.progressWindow(loading_box, edit=True, status="Generating Bones...", progress=10) bones = bone_generator(lba_model.bones, lba_model.vertices) # generate the main mesh pm.progressWindow(loading_box, edit=True, status="Generating Mesh...", progress=15) model = mesh_generator(lba_model.vertices, lba_model.polygons, lba_model.normals, materials, lba_model.bones, bones, settings) # generate the spheres pm.progressWindow(loading_box, edit=True, status="Generating Spheres...", progress=20) spheres = sphere_generator(lba_model.spheres, lba_model.vertices, bones, settings) # generate the lines pm.progressWindow(loading_box, edit=True, status="Generating Lines...", progress=25) lines = line_generator(lba_model.lines, lba_model.vertices, bones, settings) # unite all the rigged meshes pm.progressWindow(loading_box, edit=True, status="Unifying...", progress=40) pm.select(clear=True) pm.select(model, add=True) pm.polyAutoProjection() pm.select(clear=True) pm.select(model, add=True) pm.select(spheres, add=True) pm.select(lines, add=True) unified_mesh = None if len(lba_model.spheres) > 0 or len(lba_model.lines) > 0: unified_mesh = pm.polyUniteSkinned( ) if settings.use_rigging else pm.polyUnite() if settings.use_rigging: if unified_mesh is None: pm.select(model, r=True) else: pm.select(unified_mesh, r=True) pm.select(bones[0], add=True) pm.group() # ## Load Animations ## # if settings.use_animation: pm.progressWindow(loading_box, edit=True, status="Loading Animations...", progress=45) for resource in resources: for body in resource.bodies: if body.realIndex == body_index: if len(resource.animations) > 0: pm.progressWindow( loading_box, edit=True, status="Generating Animations...", progress=50) anim_importer(bones, resource.animations, loading_box) pm.progressWindow(loading_box, endProgress=1) return else: pm.progressWindow(loading_box, endProgress=1)
def _deformPlanes(self, autoGrp, baseGrp=None): """ Create a plane and copy the deforms from base mesh, then constraint the autoGrp and baseGrp to the plane :param autoGrp:autoGrp, generally contains a controller as child :param baseGrp: to control a baseShape like wire deformer baseCure :return: planes """ # create a small plane per point, then combine them planes = [] for ctr in autoGrp: plane = pm.polyPlane(h=0.01, w=0.01, sh=1, sw=1, ch=False)[0] plane.setTranslation(ctr.getTranslation("world"), "world") planes.append(plane) # combine planes if len(planes) > 1: # len 1 gives an error with polyUnite planes = pm.polyUnite(planes, ch=False, mergeUVSets=True)[0] else: planes = planes[0] pm.makeIdentity(planes, a=True, r=True, s=True, t=True) planes.setPivots([0, 0, 0]) planes.rename("%s_planes" % self._baseName) # rename pm.polyAutoProjection(planes, ch=False, lm=0, pb=0, ibd=1, cm=0, l=2, sc=1, o=1, p=6, ps=0.2, ws=0) # uvs if self._MESH_SHAPE: # if skin sample, copy skin weights to planes # find skin node skinNode = pm.listHistory(self._MESH_SHAPE, type='skinCluster')[0] # joint list jointList = skinNode.influenceObjects() # create skinCluster copySkinCluster = pm.skinCluster(planes, jointList, mi=3) # copy skin weigths pm.copySkinWeights(ss=skinNode, ds=copySkinCluster, noMirror=True, surfaceAssociation='closestPoint', influenceAssociation=('closestJoint', 'closestJoint')) # connect each auto grp to each poly face numFaces = planes.getShape().numFaces() logger.debug("num Faces: %s" % numFaces) for i in range(numFaces): pm.select(planes.f[i], r=True) pm.select(autoGrp[i], add=True) pm.pointOnPolyConstraint(maintainOffset=True) pm.select(cl=True) if baseGrp: pm.select(planes.f[i], r=True) pm.select(baseGrp[i], add=True) pm.pointOnPolyConstraint(maintainOffset=True) pm.select(cl=True) #hammer weights try: #TODO: bad aproximation vertex = pm.modeling.polyListComponentConversion(planes.f[i], tv=True) pm.select(vertex, r=True) logger.debug("vertices %s:" % vertex) mel.eval("weightHammerVerts;") pm.select(cl=True) except: pm.select(cl=True) # parent planes to nonXform grp self._noXformGrp.addChild(planes) # parent to noXform return planes