Ejemplo n.º 1
0
    def NewConceiveDit(self):
        allMesh = [a.getParent() for a in pm.ls(type=("mesh","nurbsSurface") ,ni = True,  v =1,l=1) if a.getParent().find('_feetMask_') == -1]
        print allMesh,self.rootList
        
        newAllMesh = list(set([x for x in allMesh for y in self.rootList if self.objFirstGroup(str(x)) != self.objFirstGroup(str(y)) ]))

        self.allSkiList = [a for a in newAllMesh if a not in self.rootList]

        roltDit = {}
        if self.rootList != []:
            for i,x in enumerate(self.rootList):
                pos = pm.objectCenter(x,gl=1)
                p = [round(pi,2) for pi in pos ]
                roltDit[str(p)] = self.rootList[i]

        akltDit = {}
        if self.allSkiList != []:
            for i,x in enumerate(self.allSkiList):
                pos = pm.objectCenter(x,gl=1)
                p = [round(pi,2) for pi in pos ]
                akltDit[str(p)] = self.allSkiList[i]

        #print roltDit
        #print akltDit
        if roltDit != {} and akltDit != {}:
            for x in roltDit.keys():
                if x in akltDit.keys():
                    self.dit[roltDit[x]] = akltDit[x]
Ejemplo n.º 2
0
	def mirrorSepratedShapes(self,*args):
		# Select good shape then bad shape, run the script
		geo = pm.ls(sl=1,fl=1)
		Lgeo=[]
		Rgeo=[]
		if len(geo)==2:
			for x in geo:
				oc=pm.objectCenter(x)
				if oc>0:
					Lgeo.append(x)
				elif oc<0:
					Rgeo.append(x)
		
		Lshape=Lgeo.getShape()
		Rshape=Rgeo.getShape()
		
		Lvert=pm.polyEvaluate(Lshape[0], v=True)
		Rvert=pm.polyEvaluate(Rshape[0], v=True) 
		
		if not Lvert==Rvert:
		    print 'Vertex count not matching between the two sides'
		   
		if geo[0]==Lgeo[0]:
		    base=Lgeo[0]
		    target=Rgeo[0]
		   
		if geo[0]==Rgeo[0]:
		    base=Rgeo[0]
		    target=Lgeo[0]
		
		for i in range(0,Lvert):
		    #print('%s.vtx[%d]'%(Lgeo,i))
		    pos=cmds.xform(('%s.vtx[%d]'%(base,i)), q=True, ws=True, t=True)
		    cmds.xform(('%s.vtx[%d]'%(target,i)), t=((pos[0]*-1),pos[1],pos[2]), ws=True)
Ejemplo n.º 3
0
 def _get_bounds(sel):
     if sel > 1 and isinstance(sel[0], pm.Component):
         transform = sel[0].node().getTransform()
         t = pm.polyEvaluate(bc=True)
         bb = pm.dt.BoundingBox(pm.dt.Point(t[0][0], t[1][0], t[2][0]), pm.dt.Point(t[0][1], t[1][1], t[2][1]))
         verts = [i.getPosition() for i in pm.ls(pm.polyListComponentConversion(sel, tv=True), fl=True)]
         center = sum(verts) / len(verts)
     else:
         transform = sel[0]
         bb = sel[0].getBoundingBox()
         center = pm.objectCenter(sel[0])
     return bb, center, transform
Ejemplo n.º 4
0
 def _get_bounds(sel):
     if sel > 1 and isinstance(sel[0], pm.Component):
         transform = sel[0].node().getTransform()
         t = pm.polyEvaluate(bc=True)
         bb = pm.dt.BoundingBox(pm.dt.Point(t[0][0], t[1][0], t[2][0]),
                                pm.dt.Point(t[0][1], t[1][1], t[2][1]))
         verts = [
             i.getPosition()
             for i in pm.ls(pm.polyListComponentConversion(sel, tv=True),
                            fl=True)
         ]
         center = sum(verts) / len(verts)
     else:
         transform = sel[0]
         bb = sel[0].getBoundingBox()
         center = pm.objectCenter(sel[0])
     return bb, center, transform
Ejemplo n.º 5
0
def move_to_object():
	get_sel = pm.ls(sl=1,fl=1)
	if len(get_sel) == 2:
		src = get_sel[1]
		target = get_sel[0]
		src_oc_x = pm.objectCenter(src,x=1)
		src_oc_y = pm.objectCenter(src,y=1)
		src_oc_z = pm.objectCenter(src,z=1)
		target_oc_x = pm.objectCenter(target,x=1)
		target_oc_y = pm.objectCenter(target,y=1)
		target_oc_z = pm.objectCenter(target,z=1)
		src_oc = [src_oc_x,src_oc_y,src_oc_z]
		target_oc = [target_oc_x,target_oc_y,target_oc_z]
		vector = (src_oc_x-target_oc_x),(src_oc_y-target_oc_y),(src_oc_z-target_oc_z)
		pm.xform(target,t=vector,r=1)
def averageCoords(selection):
    all_x = []
    all_y = []
    all_z = []

    for each in selection:
        x, y, z = pm.objectCenter(each, gl=True)

        all_x.append(x)
        all_y.append(y)
        all_z.append(z)

    totX = float(sum(all_x))
    totY = float(sum(all_y))
    totZ = float(sum(all_z))

    avg_X = totX / len(all_x)
    avg_Y = totY / len(all_y)
    avg_Z = totZ / len(all_z)

    return [avg_X, avg_Y, avg_Z]
Ejemplo n.º 7
0
def bdJointOnSelCenter():
    selection = pm.ls(sl=True, fl=True)

    vtxPosArray = []
    vertices = pm.polyListComponentConversion(selection, toVertex=True)
    pm.select(vertices)
    selection = pm.ls(sl=True, fl=True)

    if type(selection[0]).__name__ == 'MeshVertex':
        for sel in selection:
            vtxPos = sel.getPosition(space='world')
            print vtxPos, sel.name()
            vtxPosArray.append(om.MVector(vtxPos[0], vtxPos[1], vtxPos[2]))
            loc = pm.spaceLocator(p=vtxPos)
            loc.centerPivots()
        #vtx1Pos = selection[0].getPoint(1,space='world')
        #vtxPos.append(om.MVector(vtx1Pos[0],vtx1Pos[1],vtx1Pos[2]))

        area = 0

        centroids = []
        areas = []
        for i in range(1, len(vtxPosArray) - 1):
            area = area + (
                (vtxPosArray[i] - vtxPosArray[0]) ^
                (vtxPosArray[i + 1] - vtxPosArray[0])).length() / 2.0
            areas.append(
                ((vtxPosArray[i] - vtxPosArray[0]) ^
                 (vtxPosArray[i + 1] - vtxPosArray[0])).length() / 2.0)
            centroid = (vtxPosArray[0] + vtxPosArray[i] +
                        vtxPosArray[i + 1]) / 3.0
            centroids.append(centroid)
            loc = pm.spaceLocator(p=[centroid.x, centroid.y, centroid.z])
            loc.centerPivots()
        '''
        center = om.MVector(0,0,0)
        
        print len(vtxPos), len(centroids), len(areas), 'MUIE'
        
        for i in range(len(centroids)):
            center = center + (centroids[i]*areas[i])
            
        
        
        center = center/area
        pm.spaceLocator(p=[center.x,center.y,center.z],a=True)
            
        '''
        '''
        sumCrossProducts = om.MVector()
        normal = (vtxPos[0]^vtxPos[1]).normal()
        print normal.x,normal.y,normal.z
        for i in range(len(vtxPos)-1):
            sumCrossProducts +=  (vtxPos[i]^vtxPos[i+1])
            
        area = (normal/2.0)*sumCrossProducts
        
        cx= cy = cz = 0
        for i in range(len(vtxPos)-1):
            cx = cx + (vtxPos[i].x + vtxPos[i+1].x)*(vtxPos[i].x*vtxPos[i+1].y - vtxPos[i+1].x*vtxPos[i].y)
            cy = cy + (vtxPos[i].y + vtxPos[i+1].y)*(vtxPos[i].x*vtxPos[i+1].y - vtxPos[i+1].x*vtxPos[i].y)
            cz = cx + (vtxPos[i].z + vtxPos[i+1].z)*(vtxPos[i].x*vtxPos[i+1].z- vtxPos[i+1].x*vtxPos[i].z)
        cx = cx/(6.0*area)
        cy = cy/(6.0*area)
        cz = cz/(6.0*area)
        '''

        print area
        #pm.spaceLocator(p=[cx,cy,cz])
    if type(selection[0]).__name__ == 'MeshFace':
        for sel in selection:
            print sel.getArea(), pm.objectCenter(sel)
            center = pm.objectCenter(sel)
            pm.spaceLocator(p=[center[0], center[1], center[2]])
def main(attemptsLeft, outputDir, typeName):
    sel = pm.ls(o=True)

    if (attemptsLeft == 0):
        return

    numExported = 0
    tilesExpected = [
        "1000_0000", "1000_1000", "1100_0000", "1100_0100", "1100_1000",
        "1100_1100", "1101_1100", "1110_0000", "1110_0010", "1110_0100",
        "1110_1000", "1110_1010", "1110_1100", "1110_1110", "1111_0000",
        "1111_1000", "1111_1010", "1111_1100", "1111_1110", "1010_1000",
        "1010_1010"
    ]
    filesExported = []
    missingTiles = []

    execute = False
    for x in sel:
        if (x.lower().startswith("tile_") and x.type() == "transform"):
            execute = True
            break

    if (execute == False):
        pm.error("Can't find meshes that start with 'tile_', so not exporting")
    else:
        if outputDir == "":
            result = pm.promptDialog(title='Export Options',
                                     message='Output Directory',
                                     button=['OK', 'Cancel'],
                                     cancelButton='Cancel',
                                     dismissString='Cancel')
            dir = pm.promptDialog(q=True, text=True)
        else:
            result = 'OK'
            dir = outputDir
        if result == 'OK':
            if (dir[-1] != "\\" and dir[-1] != "/"):
                dir += "\\"
            if (typeName == ""):
                result = pm.promptDialog(title='Export Options',
                                         message='Tileset',
                                         button=['OK', 'Cancel'],
                                         cancelButton='Cancel',
                                         dismissString='Cancel')
                type = pm.promptDialog(q=True, text=True)
            else:
                result == 'OK'
                type = typeName
            if result == 'OK':
                try:
                    for obj in sel:
                        pm.select(obj)

                        if (obj.lower().startswith("tile_")):
                            if (obj.type() != "transform"):
                                continue
                            children = pm.listRelatives(obj, c=True)
                            name = obj

                            pos = pm.xform(obj, q=True, t=True)
                            rot = pm.xform(obj, q=True, ro=True)
                            pm.xform(obj, a=1, ws=1, t=(0, 0, 0), ro=(0, 0, 0))

                            if len(children) > 1:
                                toMerge = children[1:]
                                toMerge.append(obj)
                                merged = pm.polyUnite(toMerge)
                                pm.delete(merged, ch=True)
                                pm.rename(pm.ls(os=True)[0], str(name))
                                obj = name
                            bbox = pm.objectCenter(obj)
                            dst = math.sqrt(bbox[0] * bbox[0] +
                                            bbox[1] * bbox[1] +
                                            bbox[2] * bbox[2])

                            if (dst > 1):
                                pm.warning(
                                    "Center point of " + obj +
                                    " is more than 1 (" + str(dst) +
                                    ") units away from origin. Is it's pivot in the correct place?"
                                )
                            name = type + obj[4:]
                            print(dir + name)

                            cmds.file(
                                dir + name,
                                pr=1,
                                typ="OBJexport",
                                es=1,
                                f=1,
                                op=
                                "groups=1; ptgroups=1; materials=1; smoothing=1; normals=1;"
                            )
                            numExported += 1
                            filesExported.append(name)
                            pm.xform(obj, a=1, t=pos, ro=rot)

                    print(str(numExported) + " tiles created")
                except:
                    main(attemptsLeft - 1, dir, type)
                for t in tilesExpected:
                    found = False
                    for f in filesExported:
                        code = f[len(type) + 1:len(type) + 10]
                        if code == t:
                            found = True
                            break
                    if not found:
                        missingTiles.append(t)

                if (len(missingTiles) > 0):
                    pm.warning("Less than " + str(len(tilesExpected)) +
                               " tile types created. Missing: " +
                               str(missingTiles))
            else:
                pm.warning("Export cancelled!")
        else:
            pm.warning("Export cancelled!")
Ejemplo n.º 9
0
def bdJointOnSelCenter():
    selection = pm.ls(sl=True,fl=True)

    vtxPosArray = []
    vertices = pm.polyListComponentConversion(selection,toVertex=True)
    pm.select(vertices)
    selection = pm.ls(sl=True,fl=True)
    
    if type(selection[0]).__name__ == 'MeshVertex':
        for sel in selection:
            vtxPos = sel.getPosition(space='world')
            print vtxPos, sel.name() 
            vtxPosArray.append(om.MVector(vtxPos[0],vtxPos[1],vtxPos[2]))
            loc = pm.spaceLocator(p=vtxPos)
            loc.centerPivots()
        #vtx1Pos = selection[0].getPoint(1,space='world')
        #vtxPos.append(om.MVector(vtx1Pos[0],vtx1Pos[1],vtx1Pos[2]))
    
        area = 0
        
        centroids = []
        areas = []
        for i in range(1,len(vtxPosArray)-1):
            area = area + ((vtxPosArray[i] - vtxPosArray[0]) ^ (vtxPosArray[i+1] - vtxPosArray[0])).length()/2.0
            areas.append(((vtxPosArray[i] - vtxPosArray[0]) ^ (vtxPosArray[i+1] - vtxPosArray[0])).length()/2.0)
            centroid = (vtxPosArray[0] + vtxPosArray[i] + vtxPosArray[i+1])/3.0
            centroids.append(centroid)
            loc = pm.spaceLocator(p=[centroid.x,centroid.y,centroid.z])
            loc.centerPivots()            
            
           
        '''
        center = om.MVector(0,0,0)
        
        print len(vtxPos), len(centroids), len(areas), 'MUIE'
        
        for i in range(len(centroids)):
            center = center + (centroids[i]*areas[i])
            
        
        
        center = center/area
        pm.spaceLocator(p=[center.x,center.y,center.z],a=True)
            
        '''
        
        '''
        sumCrossProducts = om.MVector()
        normal = (vtxPos[0]^vtxPos[1]).normal()
        print normal.x,normal.y,normal.z
        for i in range(len(vtxPos)-1):
            sumCrossProducts +=  (vtxPos[i]^vtxPos[i+1])
            
        area = (normal/2.0)*sumCrossProducts
        
        cx= cy = cz = 0
        for i in range(len(vtxPos)-1):
            cx = cx + (vtxPos[i].x + vtxPos[i+1].x)*(vtxPos[i].x*vtxPos[i+1].y - vtxPos[i+1].x*vtxPos[i].y)
            cy = cy + (vtxPos[i].y + vtxPos[i+1].y)*(vtxPos[i].x*vtxPos[i+1].y - vtxPos[i+1].x*vtxPos[i].y)
            cz = cx + (vtxPos[i].z + vtxPos[i+1].z)*(vtxPos[i].x*vtxPos[i+1].z- vtxPos[i+1].x*vtxPos[i].z)
        cx = cx/(6.0*area)
        cy = cy/(6.0*area)
        cz = cz/(6.0*area)
        '''
        
        print area
        #pm.spaceLocator(p=[cx,cy,cz])
    if type(selection[0]).__name__ == 'MeshFace':
        for sel in selection:
            print sel.getArea(),pm.objectCenter(sel)
            center = pm.objectCenter(sel)
            pm.spaceLocator(p=[center[0],center[1],center[2]])