def __init__(self):
        # The script will try to find itself in your home/maya/Scripts folder
        # It needs to be in a folder called EyeRig
        self.SCRIPT_LOCATION = os.path.join(os.environ['HOME'], "maya",
                                            "Scripts", "EyeRig")

        # If you want to use it script from another location, comment out the line above and uncomment the line below
        # Change the path to the location where you put the EyeRig folder

        #self.SCRIPT_LOCATION = r"T:/Tools/Maya/PythonScript/EyeRig"

        self.ui = None

        self.lid_vertices = []
        self.lower_lid_vertices = []

        self.head_joint = None
        self.head_skin = None
        self.head_controller = None

        self.eyelid_high_res_curve = None
        self.eyelid_low_res_curve = None
        self.joint_radius = 0.03

        self.center_eye_position = None
        self.side_prefix = None
        self.up_down_prefix = None

        self.do_not_touch_group = None

        # make sure selection order is tracked, why this is not on by default is beyond me...
        pm.selectPref(trackSelectionOrder=True)

        self.build_ui()
Beispiel #2
0
def assign_shader_as():
    # List objects and components that are currently selected in their order of selection.
    pm.selectPref(trackSelectionOrder=True)
    sel_face = pm.ls(os=True)
    # Clears the active list
    pm.select(cl=True)

    # Check user selection
    run = True

    if sel_face:
        # If the last selection is not mesh type
        if sel_face[-1].nodeType() != 'mesh':
            # If the last selection is (e.g.: " nt.Transform(u'pSphere1') ")
            if sel_face[-1].getShape():
                # Will select override f[0] as last selection
                sel_face[-1] = sel_face[-1].getShape().faces[0]

            else:
                run = False

    else:
        run = False

    # If the user selects the mesh face, run the script
    if run:
        # Get the selected face shader
        pm.select(sel_face[-1], r=True)
        sel_shader = get_face_shader()

        if sel_shader:
            # Filter the selected list
            results = []
            for each in sel_face:
                # Ignore the selection not mesh type
                if each.nodeType() != 'mesh':
                    # If the last selection is not (e.g.: " nt.Transform(u'pSphere1') "), continue
                    if not each.getShape():
                        continue
                try:
                    # If each == nt.Mesh(u'pSphereShape1')
                    results.append(each.faces)
                except:
                    # If each == MeshFace(u'pSphereShape1.f[0:399]')
                    results.append(each)

            # Assign the shader on selected faces
            pm.select(results, r=True)
            pm.hyperShade(assign=sel_shader)

            # Reselect the first selection
            pm.select(sel_face[-1], add=True)

    # If the user didn't select the mesh face, pop out the warning
    else:
        # pm.warning("The last selection need to be mesh face.")

        pm.confirmDialog(
            title='WARNING!',
            message='The last selection need to be mesh face.      ',
            button=['Ok'],
            defaultButton='Ok',
            cancelButton='Cancel',
            dismissString='Cancel',
        )
Beispiel #3
0
# coding:utf-8

__author__ = 'timmyliang'
__email__ = '*****@*****.**'
__date__ = '2019-11-25 15:42:22'
"""
选顶点生成曲线
"""

import pymel.core as pm

# NOTE 开启顺序获取
if not pm.selectPref(q=1, tso=1):
    pm.selectPref(tso=1)

vtx_list = []
for vtx in pm.ls(sl=1, fl=1, os=1):
    if type(vtx) == pm.general.MeshVertex:
        vtx_list.append(vtx)

# NOTE 生成曲线
curve = pm.curve(d=1, p=[vtx.getPosition(space="world") for vtx in vtx_list])
# NOTE 闭合曲线
pm.closeCurve(curve, ch=0, rpo=1)
import pymel.core as pm
import re
pm.selectPref(trackSelectionOrder=True)

getSel  = pm.ls(os=1)
vtxGrp = pm.ls(pm.polyListComponentConversion(getSel,fe=1,tv=1),fl=1)
vtxNum = len(vtxGrp)

vtxPosGrp = [pm.xform(vtx, q=True, ws=True, t=True)for vtx in vtxGrp]

tmpPoly = mc.polyCreateFacet(p=[tuple(vec) for vec in vtxPosGrp ])[0]
pm.xform(tmpPoly,cp=1)
centerPos = mc.xform(tmpPoly, q=True, ws=True, rp=True)
distGrp = [((vec[0] - centerPos[0]) ** 2 + (vec[1] - centerPos[1]) ** 2 + (vec[2] - centerPos[2]) ** 2) ** 0.5 for vec in vtxPosGrp]
dist = sum(distGrp)/vtxNum

circle = pm.circle(s=vtxNum, r=dist, c=(0, 0, 0), d=3, ch=False)[0]
pm.xform(circle, ws=True, t=tuple(centerPos))

wu = (vtxPosGrp[0][0] - centerPos[0]),(vtxPosGrp[0][1] - centerPos[1]),(vtxPosGrp[0][2] - centerPos[2])

pm.normalConstraint(tmpPoly,circle,aim=[0,0,1],u=[0,1,0],wu=(0,1,0))

e2vInfos= pm.polyInfo(getSel,ev=1)
e2vDict = {}
for info in e2vInfos:
    evList = [ int(i) for i in re.findall('\\d+', info) ]
    e2vDict.update(dict([(evList[0], evList[1:])]))


# average normal
Beispiel #5
0
def patternSelection():

	with pm.UndoChunk():

		#pm.scriptEditorInfo(suppressInfo=True)

		selOrderTrackingEnabled = pm.selectPref(q=1, trackSelectionOrder=1)
		if not selOrderTrackingEnabled:
			#pm.confirmDialog( title='Warning', message='For pattern selection to work you need to enable selection order tracking [Windows > Settings/Preferences > Preferences > Selection > Track selection order]', button=['OK'])
			pm.selectPref(trackSelectionOrder=1)
			pm.mel.eval("selectPref -trackSelectionOrder true")
			return


		sel = pm.ls(orderedSelection=1,fl=1)

		if len(sel) <= 1:
			return

		# get name of mesh object containing selected components
		mesh = pm.ls(sel[0].name().split(".")[0])[0]


		##########
		# VERTEX #
		##########

		if sel[0].__class__.__name__ == "MeshVertex" and sel[1].__class__.__name__ == "MeshVertex":

			print "vepe"

			vertFirst = sel[-2].indices()[0]
			vertLast = sel[-1].indices()[0]

			# detect if two last selected vertices are next to each other
			nextToEachother = False
			pm.select( mesh+".vtx["+str(vertFirst)+"]",r=1)
			pm.select( mesh+".vtx["+str(vertLast)+"]",add=1)
			pm.mel.eval("ConvertSelectionToContainedEdges;")

			if len(pm.ls(sl=1)) == 1:
				nextToEachother = True

			# restore selection order stack
			pm.mel.eval("ConvertSelectionToVertices;") # avoid getting stuck in edge/multi-component mode
			pm.select(sel,r=1)
			pm.select(sel[-1],d=1)
			pm.select(sel[-2],d=1)
			pm.select(sel[-2],add=1)
			pm.select(sel[-1],add=1)

			if nextToEachother:
				selectNextVertex("next")
				return

			# detect if two last selected vertices are on same edge loop
			pm.select( mesh+".vtx["+str(vertFirst)+"]",r=1)
			pm.select( mesh+".vtx["+str(vertLast)+"]",add=1)

			# converting two verts on the same loop to and edge loop
			# results in selecting all verts between them (why?)
			pm.mel.eval("SelectEdgeLoopSp;")

			path = pm.ls(sl=1,fl=1)

			if ( path ): # on same loop

				# get edge loop, needed for inversion later
				pm.mel.eval("ConvertSelectionToContainedEdges;")
				edgePath = pm.ls(sl=1,fl=1)

				# SelectEdgeRingSp is sometimes unreliable with multiple consecutive
				# edges selected so we use just one edge to find the current loop
				pm.select(edgePath[0],r=1)

				pm.mel.eval("SelectEdgeLoopSp;")
				loop = pm.ls(sl=1)

			# restore selection order stack
			pm.select(sel,r=1)
			pm.select(sel[-1],d=1)
			pm.select(sel[-2],d=1)
			pm.select(sel[-2],add=1)
			pm.select(sel[-1],add=1)

			if ( path ): # on same loop
				selectNextVertex("pattern", mesh, len(edgePath)-1, loop)


		########
		# EDGE #
		########

		if sel[0].__class__.__name__ == "MeshEdge" and sel[1].__class__.__name__ == "MeshEdge":
			edgeFirst = sel[-2].indices()[0]
			edgeLast = sel[-1].indices()[0]

			ring = pm.polySelect( mesh.name(), q=1, edgeRingPath=[edgeFirst,edgeLast] )
			if ( ring ):
				if ( len(ring) == 2 ):
					selectNextEdge("ring")

				if ( len(ring) > 2 ):
					selectNextEdge("ringPattern", mesh, len(ring)-2)

			loop = pm.polySelect( mesh.name(), q=1, edgeLoopPath=[edgeFirst,edgeLast] )
			if ( loop ):
				if (len(loop) == 2 ):
					selectNextEdge("loop")

				if ( len(loop) > 2 ):
					selectNextEdge("loopPattern", mesh, len(loop)-2)


		########
		# FACE #
		########

		if sel[0].__class__.__name__ == "MeshFace" and sel[1].__class__.__name__ == "MeshFace":
			faceFirst = sel[-2].indices()[0]
			faceLast = sel[-1].indices()[0]

			path = pm.polySelect( mesh.name(), q=1, shortestFacePath=[faceFirst,faceLast] )

			if (path):

				if len(path) == 2:
					selectNextFace("next")

				if len(path) > 2:
					pm.select( mesh+".f["+str(faceFirst)+"]",r=1)
					pm.select( mesh+".f["+str(faceLast)+"]",add=1)

					pm.mel.eval("SelectEdgeLoopSp;")
					facePath = pm.ls(sl=1,fl=1)

					if (facePath):
						# face path isnt sorted
						pm.mel.eval("ConvertSelectionToContainedEdges;")
						pm.select(pm.ls(sl=1,fl=1)[0],r=1)
						pm.mel.eval("SelectEdgeRingSp;")
						pm.mel.eval("ConvertSelectionToVertices;") # TODO REM buggy command was: pm.mel.eval("GrowPolygonSelectionRegion;")
						pm.mel.eval("ConvertSelectionToContainedFaces;")
						loop = pm.ls(sl=1)
						print loop
						print "-------------------"

					# restore selection order stack
					pm.select(sel,r=1)
					pm.select(sel[-1],d=1)
					pm.select(sel[-2],d=1)
					pm.select(sel[-2],add=1)
					pm.select(sel[-1],add=1)

					#print len(facePath)

					if (facePath):
						selectNextFace("pattern", mesh, len(facePath)-2, loop)
Beispiel #6
0
"""
:created: 2017-12
:author: Alex BROSSARD <*****@*****.**>
"""
from PySide2 import QtWidgets, QtCore, QtGui

from pymel import core as pmc

from auri.auri_lib import AuriScriptView, AuriScriptController, AuriScriptModel, is_checked, grpbox
from auri.scripts.Maya_Scripts import rig_lib
from auri.scripts.Maya_Scripts.rig_lib import RigController

reload(rig_lib)

try:
    pref = pmc.selectPref(query=True, trackSelectionOrder=True)
    if not pref:
        pmc.selectPref(trackSelectionOrder=True)
        pmc.select(clear=True)
        pmc.warning("Turning on 'Selection-Order Tracking' option.")
except TypeError:
    pmc.error("Can't find the 'Selection Order' option in Maya Preferences.")


class View(AuriScriptView):
    def __init__(self, *args, **kwargs):
        self.prebuild_btn = QtWidgets.QPushButton("Prebuild")
        self.mesh_to_follow = QtWidgets.QLineEdit()
        self.set_top_btn = QtWidgets.QPushButton("Set Selection")
        self.set_bot_btn = QtWidgets.QPushButton("Set Selection")
        self.add_top_btn = QtWidgets.QPushButton("Add to Selection")