Beispiel #1
0
def prepareWireframe(selected):
    
    # List relatives
    relatives = pc.listRelatives(selected)
    
    # We scan if any relative is a group, if so we dig deeper
    for relative in relatives:
        if relative.type() == 'transform':
            prepareWireframe(relative)
            
        # We assign values if everything is ok
        elif relative.type() == 'mesh':
            
                
            # Get all the edges
            edgesList = [relative.edges[v] for v in range(len(relative.edges))]
            
            # Select edges and store them in a set
            pc.select(edgesList)
            wireSet = pc.sets(name='wireSet')
            
            # Smooth object
            subdiv = relative.smoothLevel.get()
            pc.polySmooth( edgesList, dv=subdiv)
#            
#            # Smooth normals
#            edgesList2 = [relative.edges[v] for v in range(len(relative.edges))]
#            pc.polySoftEdge(edgesList2, a=180)
#            
            # Select base edges and harden them
            pc.select(wireSet)
            pc.polySoftEdge(a=0)
Beispiel #2
0
def convertSmoothSkin(
        name,
        path='C:/Users/Darrick/Documents/Maya/projects/_UE4-Chars/scenes'):

    pm.newFile(force=True)
    pm.importFile(path + '/Mesh/Ref/Mesh_' + name + '.ma')
    pm.importFile(path + '/Rig/Ref/Skel_' + name + '.ma')

    print('Smoothing meshes.  Please wait...')
    for mesh in pm.ls(type='mesh'):
        pm.polySmooth(mesh, ch=False)

    pm.select(None)

    print('Averaging seam vertex normals...')
    edge_dict = FIGURE_EDGES['g8f']
    for name, edge in edge_dict.items():
        mesh = pm.ls(name + ':Mesh')[0]
        pm.polySelect(mesh, edgeBorder=edge, add=True)

    pm.select(pm.polyListComponentConversion(pm.ls(sl=True), toVertex=True))
    pm.polyAverageNormal()
    pm.select(None)

    print('Applying skins...')
    applySkins()
    print('Saving file to {}'.format('{0}/Rig/Ref/Skin_{1}.ma'.format(
        path, name)))
    print('Completed.')
Beispiel #3
0
 def polySmoothFace(cls, method):
     selection = pm.ls(sl=1)
     for item in selection:
         pm.polySmooth(
             item, mth=method, dv=1, c=1, kb=0, ksb=0, khe=0, kt=1, kmb=0,
             suv=1, peh=0, sl=1, dpe=1, ps=0.1, ro=1, ch=1
         )
     pm.select(selection)
Beispiel #4
0
def create(quads=True, it=1):
    name = pm.polyPlatonicSolid(n="geoSphere", st=1)
    for i in xrange(0, it):
        pm.polySmooth(name, mth=int(not quads), dv=1)

    vertices = pm.polyEvaluate(name, v=True)

    def make_vtxname(index):
        return str(name[0]) + ".vtx[" + str(index) + "]"

    for vtxname in (make_vtxname(vert) for vert in xrange(0, vertices)):
        p = pm.xform(vtxname, q=True, t=True)
        p = dt.Vector(p).normal()

        pm.move(p.x, p.y, p.z, vtxname)
Beispiel #5
0
def create(quads=True, it=1):
	name = pm.polyPlatonicSolid(n="geoSphere", st=1)
	for i in xrange(0, it):
		pm.polySmooth(name, mth=int(not quads), dv=1)

	vertices = pm.polyEvaluate(name, v=True)

	def make_vtxname(index):
		return str(name[0]) + ".vtx[" + str(index) + "]"

	for vtxname in (make_vtxname(vert) for vert in xrange(0, vertices)):
	    p = pm.xform(vtxname, q=True, t=True);
	    p = dt.Vector(p).normal()
	    
	    pm.move(p.x, p.y, p.z, vtxname)
Beispiel #6
0
def export_surfacing_project(project,
                             subdiv_level=0,
                             single_export=True,
                             folder_path=False):
    """
    Export surfacing Project to Alembic.

    Args:
        project (PyNode): surfacing project

    Kwargs:
        single_export (bool): is single export
        folder_path (str): Export folder path

    """
    current_file = pm.sceneName()
    if single_export:
        save_unsaved_scene_()
    if not folder_path:
        folder_path = qtutils.get_folder_path()
    project_geo_list = []
    if ldtutils.is_directory(folder_path) and is_surfacing_project(project):
        for each in get_surfacing_objects(project):
            merged_geo = merge_surfacing_object_meshes(each)
            if merged_geo:
                project_geo_list.append(merged_geo)
        if project_geo_list:
            if subdiv_level:
                for geo in project_geo_list:
                    logger.info("subdivision level: %s" % subdiv_level)
                    logger.info("subdividing merged members: %s" % geo)
                    # -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 0 -ocr 0 -dv 3
                    # -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1
                    # -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1
                    pm.polySmooth(geo, mth=0, sdt=2, ovb=1, dv=subdiv_level)
            export_file_path = os.path.join(folder_path, str(project) + ".abc")
            export_alembic(project_geo_list, export_file_path)
            export_surfacing_object_dir = os.path.join(folder_path,
                                                       str(project))
            ldtutils.create_directoy(export_surfacing_object_dir)
            for geo in project_geo_list:
                export_root = " -root |" + geo
                export_surfacing_object_path = os.path.join(
                    export_surfacing_object_dir + "/" + geo + ".abc")
                export_alembic([geo], export_surfacing_object_path)

    if single_export:
        pm.openFile(current_file, force=True)
Beispiel #7
0
	def setObjectSmooth(self , layou= None , *args):
		
		meshSmooth = self.checkObjectSmooth()
		
		for mh in meshSmooth:
			listSmooth = mh.listHistory(type = 'polySmoothFace')
			if not listSmooth:
				listSmooth = pm.polySmooth(mh)
			if not listSmooth[0].continuity.isConnected():
				pm.PyNode('smooth_ctrl').smooth.connect(listSmooth[0].continuity , f = True)
			if not listSmooth[0].divisions.isConnected():
				pm.PyNode('smooth_ctrl').smooth.connect(listSmooth[0].divisions , f = True)		
	
		pm.frameLayout(layou , e = True , l = '(0个)smooth节点:')
		distribution = pm.frameLayout(layou , q = True , ca = True)
		pm.textScrollList(distribution[0] , e = True , ra = True)
Beispiel #8
0
def createEasySmooth():
    sel = pm.selected()
    objs = sel[0:]
    cruveGen = generateCurve(sel[-1])
    slider = cruveGen[0]
    sliderField = cruveGen[1]
    smoothCtls = [cruveGen[2]]
    ctl = sliderField
    for currentSel in (sel[:-1]):
        smoothCtls.append(generateChildCurve(currentSel))
    pm.group(smoothCtls, n=smoothCtls[0] + '_Group')
    # ctl = sel[-1] #[-1]で要素の末尾を取得
    #新しいアトリビュートを作成する
    pm.addAttr(ctl, ln='divisions', nn='div', at='long', min=0, max=4, dv=0)
    #作成したアトリビュートの編集を有効可する
    ctlDiv = pm.Attribute(ctl + '.divisions')
    pm.setAttr(
        ctlDiv,
        e=True,
        keyable=True,
    )
    for obj in objs:
        smthChk = False
        for cnct in set(obj.getShape().inputs()):
            if isinstance(
                    cnct, pm.nt.PolySmoothFace
            ):  #セットでinputsノードの重複を無くし、cnctの方がpolysmoothfaceだった場合(すでにスムースノードがある場合)はsmthckをtrueにする
                smthChk = True
                break
        if smthChk:
            ctlDiv >> cnct.divisions  #すでにスムースノードがある場合は、それをctlDivアトリビュートと接続
        else:
            smthNode = pm.polySmooth(obj)  #objに新しくスムースを追加し
            ctlDiv >> smthNode[
                0].divisions  #スムースノードのdivisionsアトリビュートとctlのdivisionアトリビュート(ctlDiv)をつなぐ

    pm.transformLimits(slider, tx=(0, 1.23), etx=(True, True))
    pm.setDrivenKeyframe("%s.divisions" % ctl, cd="%s.tx" % slider, dv=0, v=0)
    pm.setDrivenKeyframe("%s.divisions" % ctl,
                         cd="%s.tx" % slider,
                         dv=1.23,
                         v=4)
Beispiel #9
0
    def startSimulation(self):

        if len(self.surface) == 0:
            self.printErr("No surface select!")
            return

        if len(self.listInstanceOrig) == 0:
            self.printErr("No instance select!")
            return

        pm.currentTime(100)
        if self.IsFirstStart:
            self.IsFirstStart = False
            # Delete the root group if exists

            if pm.objExists(self.worldParent):
                pm.delete(self.worldParent)
            if pm.objExists("forestGenerator_exp"):
                pm.delete("forestGenerator_exp")

            # Create root group
            self.worldParent = pm.group(em=1, w=1, name=self.worldParent)

            # Duplicate instance
            pm.select(cl=1)
            self.listInstance = []
            for inst in self.listInstanceOrig:
                tmp = pm.duplicate(inst, name=inst.name() + "_inst")[0]
                self.connectOriginaleMesh(inst, tmp)
                pm.select(tmp, add=True)

                # Instance radius computation

                bbx = pm.polyEvaluate(tmp, b=True)
                ltmp = [abs(bbx[0][1] - bbx[0][0]), abs(bbx[2][1] - bbx[2][0])]
                self.listInstanceInfo[str(tmp)] = {"meshOriginal": inst, "radius": min(ltmp) / 2}
            self.listInstance = pm.ls(sl=1)

            grpInstance = pm.group(n="instance_grp")
            pm.parent(grpInstance, self.worldParent)
            pm.select(cl=1)

            self.meshCollider = self.createCollider(self.surface)
            if self.ui.surfaceSmooth_cb.isChecked():
                pm.polySmooth(self.meshCollider, dv=self.meshCollider.getAttr("displaySmoothMesh"), method=0)

            pm.parent(self.meshCollider, self.worldParent)
            self.meshCollider.setAttr("v", 0)

            self.meshEmitter = self.createEmitter(self.meshCollider)
            pm.parent(self.meshEmitter, self.worldParent)
            self.meshEmitter.setAttr("v", 0)

            self.createParticleEmitter(self.meshEmitter, collider=self.meshCollider)

        # Init expresionn at Creation
        self.updateDynExpressionCreation(self.partShape)

        # Play Interractive playback
        pm.playbackOptions(aet=20000, max=20000)
        self.simulate()
Beispiel #10
0
    def __init__(self,
                 mainSkinGeo,
                 mainClothGeo,
                 proxySkinGeo='',
                 proxyClothGeo='',
                 rigModelGrp=None):
        """
        Setup Sliding Cloth deformation
        :param mainSkinGeo: str
        :param mainClothGeo: str
        :param proxySkinGeo: str
        :param proxyClothGeo: str
        """
        if mainSkinGeo and mainClothGeo:
            self.mainSkinGeo = pm.ls(mainSkinGeo)[0]
            self.mainClothGeo = pm.ls(mainClothGeo)[0]
        else:
            print 'No valid Geo!'

        if proxySkinGeo:
            self.proxySkinGeo = pm.ls(proxySkinGeo)[0]
        else:
            self.proxySkinGeo = self.makeProxyGeo(self.mainSkinGeo)

        if proxyClothGeo:
            self.proxyClothGeo = pm.ls(proxyClothGeo)[0]
        else:
            self.proxyClothGeo = self.makeProxyGeo(self.mainClothGeo)

        # setup skin proxy geo
        skin.copyBind(self.mainSkinGeo, self.proxySkinGeo)

        # setup cloth proxy geo
        skin.copyBind(self.mainSkinGeo, self.proxyClothGeo)

        cMuscleDeformer = deform.cMuscleSystemDeformer(self.proxyClothGeo)
        cMuscleDeformer.enableRelax.set(1)
        cMuscleDeformer.relaxCompress.set(10)
        cMuscleDeformer.enableSmooth.set(1)

        shrinkWrapDeformer = deform.shrinkWrapDeformer(self.proxyClothGeo,
                                                       self.proxySkinGeo)
        shrinkWrapDeformer.shapePreservationEnable.set(1)
        shrinkWrapDeformer.projection.set(4)
        shrinkWrapDeformer.targetInflation.set(0.01)

        polySmoothDeformer = pm.polySmooth(self.proxyClothGeo)[0]

        # wrap main Cloth Geo
        wrapDeformer = deform.wrapDeformer(self.mainClothGeo,
                                           self.proxyClothGeo)
        baseObj = pm.listConnections(wrapDeformer.basePoints, source=True)[0]

        # regroup
        grpName = name.removeSuffix(self.mainClothGeo.name()) + 'Cloth_GRP'
        clothGrp = pm.group(self.proxySkinGeo,
                            self.proxyClothGeo,
                            baseObj,
                            n=grpName)
        if rigModelGrp:
            pm.parent(clothGrp, rigModelGrp)

        # save attribute
        self.baseObj = baseObj
        self.wrapDeformer = wrapDeformer
        self.shrinkWrapDeformer = shrinkWrapDeformer
        self.cMuscleDeformer = cMuscleDeformer
Beispiel #11
0
def export_fbx(force, transf, triangulate, smooth):
    initial_selection = pmc.ls(sl=True)

    # Duplicate and triangulate if wanted
    dup = None

    if smooth and triangulate:
        dup = pmc.duplicate(transf)
        pmc.polySmooth(dup,
                       mth=0,
                       sdt=2,
                       ovb=1,
                       ofb=1,
                       ofc=0,
                       ost=0,
                       ocr=0,
                       dv=2,
                       bnr=1,
                       c=1,
                       kb=1,
                       ksb=1,
                       khe=0,
                       kt=1,
                       kmb=1,
                       suv=1,
                       peh=0,
                       sl=1,
                       dpe=1,
                       ps=0.1,
                       ro=1,
                       ch=1)
        pmc.polyTriangulate(dup)
        pmc.select(dup)
    elif smooth:
        dup = pmc.duplicate(transf)
        pmc.polySmooth(dup,
                       mth=0,
                       sdt=2,
                       ovb=1,
                       ofb=1,
                       ofc=0,
                       ost=0,
                       ocr=0,
                       dv=2,
                       bnr=1,
                       c=1,
                       kb=1,
                       ksb=1,
                       khe=0,
                       kt=1,
                       kmb=1,
                       suv=1,
                       peh=0,
                       sl=1,
                       dpe=1,
                       ps=0.1,
                       ro=1,
                       ch=1)
        pmc.select(dup)
    elif triangulate:
        dup = pmc.duplicate(transf)
        pmc.polyTriangulate(dup)
        pmc.select(dup)
    else:
        pmc.select(transf)

    export_path = build_export_path(transf=transf, extension=".fbx")

    try:
        pmc.exportSelected(export_path,
                           force=force,
                           preserveReferences=True,
                           type="FBX export")
        success = True
    except RuntimeError as e:
        logger.error("Could not export node {}".format(transf))
        logger.error(e)
        success = False

    # delete triangulated duplicate again (if created)
    if dup:
        pmc.delete(dup)

    pmc.select(initial_selection)

    return success
Beispiel #12
0
def export_obj(force, transf, triangulate, smooth):
    initial_selection = pmc.ls(sl=True)

    # Duplicate and triangulate if wanted
    dup = None

    if smooth and triangulate:
        dup = pmc.duplicate(transf)
        pmc.polySmooth(dup,
                       mth=0,
                       sdt=2,
                       ovb=1,
                       ofb=1,
                       ofc=0,
                       ost=0,
                       ocr=0,
                       dv=2,
                       bnr=1,
                       c=1,
                       kb=1,
                       ksb=1,
                       khe=0,
                       kt=1,
                       kmb=1,
                       suv=1,
                       peh=0,
                       sl=1,
                       dpe=1,
                       ps=0.1,
                       ro=1,
                       ch=1)
        pmc.polyTriangulate(dup)
        pmc.select(dup)
    elif smooth:
        dup = pmc.duplicate(transf)
        pmc.polySmooth(dup,
                       mth=0,
                       sdt=2,
                       ovb=1,
                       ofb=1,
                       ofc=0,
                       ost=0,
                       ocr=0,
                       dv=2,
                       bnr=1,
                       c=1,
                       kb=1,
                       ksb=1,
                       khe=0,
                       kt=1,
                       kmb=1,
                       suv=1,
                       peh=0,
                       sl=1,
                       dpe=1,
                       ps=0.1,
                       ro=1,
                       ch=1)
        pmc.select(dup)
    elif triangulate:
        dup = pmc.duplicate(transf)
        pmc.polyTriangulate(dup)
        pmc.select(dup)
    else:
        pmc.select(transf)

    export_path = build_export_path(transf=transf, extension=".obj")

    try:
        exported_file = pmc.exportSelected(
            export_path,
            force=force,
            preserveReferences=True,
            type="OBJExport",
            options="groups=1;ptgroups=1;materials=1;smoothing=1;normals=1")

        # MAYA BUG WORKAROUND (.obj extension missing)
        if not exported_file[-4:] == ".obj":
            os.rename(exported_file, export_path)
            os.rename(exported_file + "mtl", exported_file + ".mtl")

        success = True
    except RuntimeError as e:
        logger.error("Could not export node {}".format(transf))
        logger.error(e)
        success = False

    # delete triangulated duplicate again (if created)
    if dup:
        pmc.delete(dup)

    pmc.select(initial_selection)

    return success
#- to TEX export

import pymel.core as pm
import maya.cmds as cmds
import os

asset_name = pm.ls(sl=1)[0].name()
pm.duplicate(rr=1)
pm.move([-30, 0, 0], r=1)
pm.select(hierarchy=1)
for i in pm.ls(sl=1):
    if i.type() == 'mesh':
        pm.polySmooth(i)

fbx_path = os.path.dirname(pm.sceneName()) + '/' + asset_name + '_totex.fbx'
cmds.file(fbx_path, force=1, options="v=0;", typ="FBX export", pr=1, es=1)

trans_node = pm.ls(sl=1, type='transform')[0]
pm.select(trans_node)
pm.delete()
Beispiel #14
0
    def startSimulation(self):

        if len(self.surface) == 0:
            self.printErr('No surface select!')
            return

        if len(self.listInstanceOrig) == 0:
            self.printErr("No instance select!")
            return

        pm.currentTime(100)
        if self.IsFirstStart:
            self.IsFirstStart = False
            #Delete the root group if exists

            if pm.objExists(self.worldParent):
                pm.delete(self.worldParent)
            if pm.objExists("forestGenerator_exp"):
                pm.delete("forestGenerator_exp")

            #Create root group
            self.worldParent = pm.group(em=1, w=1, name=self.worldParent)

            #Duplicate instance
            pm.select(cl=1)
            self.listInstance = []
            for inst in self.listInstanceOrig:
                tmp = pm.duplicate(inst, name=inst.name() + "_inst")[0]
                self.connectOriginaleMesh(inst, tmp)
                pm.select(tmp, add=True)

                #Instance radius computation

                bbx = pm.polyEvaluate(tmp, b=True)
                ltmp = [abs(bbx[0][1] - bbx[0][0]), abs(bbx[2][1] - bbx[2][0])]
                self.listInstanceInfo[str(tmp)] = {
                    "meshOriginal": inst,
                    "radius": min(ltmp) / 2
                }
            self.listInstance = pm.ls(sl=1)

            grpInstance = pm.group(n="instance_grp")
            pm.parent(grpInstance, self.worldParent)
            pm.select(cl=1)

            self.meshCollider = self.createCollider(self.surface)
            if self.ui.surfaceSmooth_cb.isChecked():
                pm.polySmooth(
                    self.meshCollider,
                    dv=self.meshCollider.getAttr("displaySmoothMesh"),
                    method=0)

            pm.parent(self.meshCollider, self.worldParent)
            self.meshCollider.setAttr("v", 0)

            self.meshEmitter = self.createEmitter(self.meshCollider)
            pm.parent(self.meshEmitter, self.worldParent)
            self.meshEmitter.setAttr("v", 0)

            self.createParticleEmitter(self.meshEmitter,
                                       collider=self.meshCollider)

        # Init expresionn at Creation
        self.updateDynExpressionCreation(self.partShape)

        #Play Interractive playback
        pm.playbackOptions(aet=20000, max=20000)
        self.simulate()
Beispiel #15
0
                                       'x__ik_spline_proxy__msh__', 'z')
folli_proxy = adbProxy.plane_proxy(ik_spline_joints, 'x__folli_proxy__msh__',
                                   'z')

pm.polySmooth(ik_curve_proxy,
              ch=0,
              ost=1,
              khe=0,
              ps=0.1,
              kmb=1,
              bnr=1,
              mth=0,
              suv=1,
              peh=0,
              ksb=1,
              ro=1,
              sdt=2,
              ofc=0,
              kt=1,
              ovb=1,
              dv=1,
              ofb=3,
              kb=1,
              c=1,
              ocr=0,
              dpe=1,
              sl=1)
pm.polySmooth(ik_spline_proxy,
              ch=0,
              ost=1,
              khe=0,