Exemplo n.º 1
0
 def kmReduce(self):
     selectionList = mc.ls(selection=True)
     if selectionList:
         for obj in selectionList:
             mc.polyReduce(obj, version=1, termination=0, percentage=50, sharpness=0, preserveTopology=1,
                           keepQuadsWeight=1,
                           cachingReduce=1)
     else:
         print ">> No selection"
Exemplo n.º 2
0
def applyCallback(noOfRocksField, scaleMultiplierField, *pArgs):
    noOfRocks = cmds.intField(noOfRocksField, q=True, v=True)
    scaleMultiplier = cmds.intField(scaleMultiplierField, q=True, v=True)

    for i in range(noOfRocks):
        rock = cmds.polyPlatonic(r=random.uniform(7.5, 12.5),
                                 primitive=random.choice(
                                     [3, 4])), cmds.rename('rock_#')

        cmds.polyReduce(ver=1,
                        trm=1,
                        vct=random.choice([4, 5, 7, 8, 9]),
                        p=random.uniform(40, 75),
                        shp=random.uniform(0, 1),
                        kqw=random.uniform(0, 1),
                        kev=random.choice([True, False]),
                        kmw=random.uniform(0, 1))

        if noOfRocks > 1:
            x = random.uniform(-10 * noOfRocks,
                               10 * noOfRocks) * scaleMultiplier
            y = 0
            z = random.uniform(-10 * noOfRocks,
                               10 * noOfRocks) * scaleMultiplier

            cmds.move(x, y, z)

        allEdges = cmds.ls('.e[:]', flatten=1)
        cmds.select(allEdges)
        cmds.polyBevel3(n='rockBevel_#',
                        mv=True,
                        ch=True,
                        sa=180,
                        sn=True,
                        sg=random.choice([2, 3, 4]),
                        d=random.uniform(0.25, 1),
                        o=random.uniform(0.5, 1.5))

        cmds.select(rock)
        cmds.polySmooth(c=random.uniform(0, 1),
                        kb=random.choice([True, False]),
                        khe=random.choice([True, False]),
                        mth=random.choice([1, 2]),
                        ro=random.uniform(0, 1))

        cmds.select(rock)
        cmds.scale(random.uniform(0.3, 1.3) * scaleMultiplier,
                   random.uniform(0.75, 1.25) * scaleMultiplier,
                   random.uniform(0.75, 1.25) * scaleMultiplier,
                   r=True,
                   a=True)
        cmds.manipPivot(r=True)

    cmds.deleteUI(windowName)
    def _export_hook(self, maya_object):
        """
            Export routine concrete implementation
        """
        # group asset
        grp = cmds.group(maya_object, n='ENV_ASSET')

        # create lods for environment assets (example)
        object_renamed = cmds.rename(maya_object, maya_object + "_LOD0")
        for i in range(2):
            new_lod = cmds.duplicate(object_renamed)
            cmds.polyReduce(new_lod, p=50.0)
            cmds.delete(new_lod, ch=1)
            object_renamed = cmds.rename(new_lod, maya_object + "_LOD" + str(i+1))

        return maya_object
Exemplo n.º 4
0
def import_obj () :

	#import obj files  
	cmds.file( wrspFldr + '//' + filename + '.obj', i = True, type = 'OBJ', iv = True, ra = True, ns = 'VR', mnc = True)
	cmds.select('VR:Mesh',r = True)
	cmds.rename('VR:Mesh' ,'Object1')

	#center the pivot and freeze transformation
	cmds.xform(cp = True)
	cmds.move(0,0,0, rpr = True)
	cmds.setAttr('Object1.rx', -90)
	cmds.scale(3,3,3,'Object1', scaleXYZ = True)
	cmds.makeIdentity('Object1', apply = True, t = 1, r = 1, s = 1, n = 0, pn = 1)

	#reduce dimension
	cmds.select('Object1',r = True)
	cmds.polyReduce(ver = 1, p = 60.0)
Exemplo n.º 5
0
def generateLods(objLs, lodLvl, reduceIter):
    mc.select(objLs[0])
    objLod = mc.duplicate(n='%s_%s' % (objLs[0], lodLvl), rr=True, rc=True)[0]
    allObjLs = mc.listRelatives(objLod, ad=True, typ='transform')
    for obj in allObjLs:
        try:
            mc.listRelatives(obj, s=True)[0]
            mc.select(obj, r=True)
            mel.eval(
                'polyCleanupArgList 3 { "0","1","1","0","0","0","0","0","0","1e-05","0","1e-05","0","1e-05","0","1","0" }'
            )
            for i in range(0, reduceIter):
                mc.polyReduce(ver=1, trm=0, p=25, top=True, kqw=1, shp=0.5)
            mc.select(obj, r=True)
            mc.delete(ch=True, c=True, e=True, cn=True)
        except:
            pass
    return objLod
Exemplo n.º 6
0
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
Exemplo n.º 7
0
def cutSkin_reduce(mesh, percent=50):
    """
    Basic mesh cleanup and reduce.
    @param mesh: Mesh to cleanup and reduce
    @type mesh: str
    @param percent: Poly reduce percent amount
    @type percent: int or float
    """
    # Get Influence Mesh Attributes
    infProxy = None
    infProxyAttr = 'influenceProxy'
    if cmds.objExists(mesh + '.' + infProxyAttr): infProxy = cmds.getAttr(mesh + '.' + infProxyAttr)
    meshProxy = None
    meshProxyAttr = 'meshProxy'
    if cmds.objExists(mesh + '.' + meshProxyAttr): meshProxy = cmds.getAttr(mesh + '.' + meshProxyAttr)

    # Separate to Shells
    meshItems = [mesh]
    try:
        meshItems = cmds.polySeparate(mesh, ch=False)
    except:
        pass

    # Clean Non-manifold Geometry
    glTools.utils.mesh.polyCleanup(meshList=meshItems,
                                   nonManifold=True,
                                   keepHistory=False,
                                   fix=True)

    # Poly Reduce
    for meshItem in meshItems:
        try:
            cmds.polyReduce(meshItem,
                          version=1,  # New
                          termination=0,  # Percentage termination
                          percentage=percent,
                          sharpness=1,
                          keepBorder=1,
                          keepMapBorder=1,
                          keepColorBorder=0,
                          keepFaceGroupBorder=0,
                          keepHardEdge=0,
                          keepCreaseEdge=0,
                          keepBorderWeight=1,
                          keepMapBorderWeight=1,
                          preserveTopology=1,
                          keepQuadsWeight=1,
                          replaceOriginal=1,
                          cachingReduce=0,
                          constructionHistory=0)
        except:
            pass

    # Cleanup
    if len(meshItems) > 1:
        meshResult = cmds.polyUnite(meshItems, ch=False, mergeUVSets=True)
        if cmds.objExists(mesh): cmds.delete(mesh)
        mesh = cmds.rename(meshResult, mesh)

    # Rebuild Influence Mesh Attributes
    if infProxy and not cmds.objExists(mesh + '.' + infProxyAttr):
        cmds.addAttr(mesh, ln=infProxyAttr, dt='string')
        cmds.setAttr(mesh + '.' + infProxyAttr, infProxy, type='string', l=True)
    if meshProxy and not cmds.objExists(mesh + '.' + meshProxyAttr):
        cmds.addAttr(mesh, ln=meshProxyAttr, dt='string')
        cmds.setAttr(mesh + '.' + meshProxyAttr, meshProxy, type='string', l=True)

    # Return Result
    return mesh
Exemplo n.º 8
0
import os
import maya.cmds as cmds
import maya.mel as mel
import pymel.core as pm

cleanPath = ""
originalPath = cmds.fileDialog2(cap="Choose folder to reduce", ds=1, fm=3)

if originalPath != None and originalPath != "":
    cleanPath = str(originalPath[0])

for root, dirs, files in os.walk(cleanPath):
    print root, dirs, files
    for fileName in files:
        if fileName.endswith('.fbx'):
            print(fileName)
            filePath = root + "/" + fileName
            cmds.file(filePath, open=True, force=True)
            obj = cmds.ls(geometry=True)
            for item in obj:
                try:
                    cmds.polyReduce(p=50, n=cmds.select(item))
                except:
                    pass
            pm.mel.FBXExport(f=filePath)
Exemplo n.º 9
0
def cutSkin_reduce(mesh, percent=50):
    '''
	Basic mesh cleanup and reduce.
	@param mesh: Mesh to cleanup and reduce
	@type mesh: str
	@param percent: Poly reduce percent amount
	@type percent: int or float
	'''
    # Get Influence Mesh Attributes
    infProxy = None
    infProxyAttr = 'influenceProxy'
    if mc.objExists(mesh + '.' + infProxyAttr):
        infProxy = mc.getAttr(mesh + '.' + infProxyAttr)
    meshProxy = None
    meshProxyAttr = 'meshProxy'
    if mc.objExists(mesh + '.' + meshProxyAttr):
        meshProxy = mc.getAttr(mesh + '.' + meshProxyAttr)

    # Separate to Shells
    meshItems = [mesh]
    try:
        meshItems = mc.polySeparate(mesh, ch=False)
    except:
        pass

    # Clean Non-manifold Geometry
    glTools.utils.mesh.polyCleanup(meshList=meshItems,
                                   nonManifold=True,
                                   keepHistory=False,
                                   fix=True)

    # Poly Reduce
    for meshItem in meshItems:
        try:
            mc.polyReduce(
                meshItem,
                version=1,  # New
                termination=0,  # Percentage termination
                percentage=percent,
                sharpness=1,
                keepBorder=1,
                keepMapBorder=1,
                keepColorBorder=0,
                keepFaceGroupBorder=0,
                keepHardEdge=0,
                keepCreaseEdge=0,
                keepBorderWeight=1,
                keepMapBorderWeight=1,
                preserveTopology=1,
                keepQuadsWeight=1,
                replaceOriginal=1,
                cachingReduce=0,
                constructionHistory=0)
        except:
            pass

    # Cleanup
    if len(meshItems) > 1:
        meshResult = mc.polyUnite(meshItems, ch=False, mergeUVSets=True)
        if mc.objExists(mesh): mc.delete(mesh)
        mesh = mc.rename(meshResult, mesh)

    # Rebuild Influence Mesh Attributes
    if infProxy and not mc.objExists(mesh + '.' + infProxyAttr):
        mc.addAttr(mesh, ln=infProxyAttr, dt='string')
        mc.setAttr(mesh + '.' + infProxyAttr, infProxy, type='string', l=True)
    if meshProxy and not mc.objExists(mesh + '.' + meshProxyAttr):
        mc.addAttr(mesh, ln=meshProxyAttr, dt='string')
        mc.setAttr(mesh + '.' + meshProxyAttr,
                   meshProxy,
                   type='string',
                   l=True)

    # Return Result
    return mesh
Exemplo n.º 10
0
def polyReduce(*args, **kwargs):
    res = cmds.polyReduce(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
Exemplo n.º 11
0
from maya import standalone as std
std.initialize()

from maya import cmds

cube = cmds.polyCube(ch=0)[0]
cmds.polySmooth(cube,sdt=2)
cmds.polySmooth(cube,sdt=2)
cmds.polyReduce(cube)


import os
import sys
DIR = os.path.dirname(__file__)
file_path = os.path.realpath(os.path.join(DIR,"a.ma"))
cmds.file(rename=file_path)
cmds.file(save=1,type="mayaAscii")

# mel.eval("$temp = $gMainWindow")

Exemplo n.º 12
0
def decimate(objLs, iterations=1):
    for obj in objLs:
        mc.select(obj, r=True)
        for i in range(0, iterations):
            mc.polyReduce(ver=1, trm=0, p=25, top=True, kqw=1, shp=0.5)
Exemplo n.º 13
0
'''

import maya.cmds as mc
from math import sqrt

def sortByValue(inDict):        # sort Dict items by value
    _items = inDict.items()
    _rotateItems = [ [i[1],i[0]] for i in _items ]        # rotate key and values for each item
    _rotateItems.sort()        # sort by value
    return [ _rotateItems[i][1] for i in range(0, len(_rotateItems)) ]        #returen key

selObjVal = {}
camPos = mc.getAttr("camera1.translate")

for i in mc.ls(sl=True):
    objPos = mc.getAttr( i + ".translate" )
    
    # assign the value of distance form camera for each obj to key in selObjSel{}
    selObjVal[i] = sqrt((objPos[0][0]-camPos[0][0])**2 + (objPos[0][1]-camPos[0][1])**2 + (objPos[0][2]-camPos[0][2])**2)

mc.select(cl=True)
sortedKey = sortByValue(selObjVal)
# distance from min-dist obj to max-dist-obj 
distMinMax = ( selObjVal[sortedKey[-1]] - selObjVal[sortedKey[0]] )

for key in selObjVal.keys():
    # caculate the distant ratio for each object
    _distRatio = 1 - (selObjVal[sortedKey[-1]] - selObjVal[key]) / distMinMax 
    # add polyReduce() fed parameter by _distRatio
    mc.polyReduce( key, compactness = 0.5, percentage = _distRatio * 90 )
Exemplo n.º 14
0
 def genFunction(self, createdLOD, reductionNumber):
     mesh = cmds.select(createdLOD)
     #mel.eval('polyCleanupArgList 3 { "0","2","1","0","1","1","1","0","0","1e-005","1","1e-005","1","1e-005","0","1","1" };')
     cmds.polyReduce(ver=1, termination=2, tct=reductionNumber)
     cmds.delete(ch=True)
Exemplo n.º 15
0
import maya.cmds as cmds

cmds.duplicate('polySurface1')
cmds.select('polySurface2')
cmds.polyReduce(p=80, ch=False, kev=True)
cmds.select('polySurface2')
nor = []
nb = cmds.polyEvaluate(v=True)
for i in range(nb):
    nor.append(0.367418)
print(nor)
cmds.select('polySurface2.vtx[:]')
cmds.moveVertexAlongDirection(n=nor)