예제 #1
0
def edgeLoopsToCurve(edgeList,form=2,degree=1):
	'''
	Generate edge loop curves from the specified list of edges.
	@param edgeList: The list of mesh edges to generate edge loop curves from.
	@type edgeList: list
	@param form: NURBS curve form. 0 = Periodic, 1 = Open, 2 = Best Guess.
	@type form: str
	@param degree: NURBS curve degree.
	@type degree: str
	'''
	# Filter/Check Edge List
	edgeList = mc.filterExpand(edgeList,ex=True,sm=32)
	if not edgeList: raise Exception('Invalid edge list!')

	# For Each Edge
	edgeCurveList = []
	for edge in edgeList:

		# Get Mesh
		edgeId = glTools.utils.component.index(edge)
		meshShape = mc.ls(edge,o=True)[0]
		mesh = mc.listRelatives(meshShape,p=True)[0]
		prefix = mesh.split(':')[-1]

		# To Edge Loop
		mc.polySelect(mesh,edgeLoop=edgeId)

		# Edge Loop to Curve
		edgeCurve = mc.polyToCurve(ch=False,form=form,degree=degree)[0]

		# Append List
		edgeCurveList.append(edgeCurve)

	# Return Result
	return edgeCurveList
예제 #2
0
파일: mesh.py 프로젝트: auqeyjf/glTools
def edgeLoopsToCurve(edgeList,form=2,degree=1):
	'''
	Generate edge loop curves from the specified list of edges.
	@param edgeList: The list of mesh edges to generate edge loop curves from.
	@type edgeList: list
	@param form: NURBS curve form. 0 = Periodic, 1 = Open, 2 = Best Guess.
	@type form: str
	@param degree: NURBS curve degree.
	@type degree: str
	'''
	# Filter/Check Edge List
	edgeList = mc.filterExpand(edgeList,ex=True,sm=32)
	if not edgeList: raise Exception('Invalid edge list!')
	
	# For Each Edge
	edgeCurveList = []
	for edge in edgeList:
		
		# Get Mesh
		edgeId = glTools.utils.component.index(edge)
		meshShape = mc.ls(edge,o=True)[0]
		mesh = mc.listRelatives(meshShape,p=True)[0]
		prefix = mesh.split(':')[-1]
		
		# To Edge Loop
		mc.polySelect(mesh,edgeLoop=edgeId)
		
		# Edge Loop to Curve
		edgeCurve = mc.polyToCurve(ch=False,form=form,degree=degree)[0]
		
		# Append List
		edgeCurveList.append(edgeCurve)
	
	# Return Result
	return edgeCurveList
예제 #3
0
def smoothEdgeLine(edgeList,
                   smooth=4,
                   falloff=0.01,
                   snapToOrig=False,
                   keepEdgeSpacing=False,
                   deleteHistory=False):
    """
    @param edgeList:
    @param smooth:
    @param falloff:
    @param snapToOrig:
    @param keepEdgeSpacing:
    @param deleteHistory:
    """
    # Get Edge List
    edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or []
    if not edgeList:
        raise Exception(
            'Invalid or empty edge list! Unable to even edge spacing...')

    edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves(
        edgeList, keepHistory=False)
    smoothCrvList = []
    for edgeCrv in edgeCrvList:

        # Smooth Edge Line
        smoothCrv = cmds.duplicate(edgeCrv, n=edgeCrv + '_smoothed')[0]
        smoothCurve(crv=smoothCrv,
                    iterations=smooth,
                    keepEnds=True,
                    keepSpacing=keepEdgeSpacing)

        # Snap To Mesh
        mesh = cmds.ls(edgeList, o=True)[0]
        if snapToOrig:
            pts = glTools.utils.component.getComponentStrList(smoothCrv)
            glTools.utils.mesh.snapPtsToMesh(mesh, pts)

        # Append List
        smoothCrvList.append(smoothCrv)

    # Apply Smoothed Edge to Vertices
    wire = glTools.utils.wire.createMulti(mesh,
                                          edgeCrvList,
                                          dropoffDist=falloff,
                                          prefix=mesh.split(':')[-1])
    cmds.setAttr(wire[0] + '.rotation', 0)

    # Blend to Smooth Curve
    for i in range(len(edgeCrvList)):
        blendShape = glTools.utils.blendShape.create(
            baseGeo=edgeCrvList[i], targetGeo=[smoothCrvList[i]])
        cmds.setAttr(blendShape + '.' + smoothCrvList[i], 1)

    # ==================
    # - Delete History -
    # ==================

    if deleteHistory:
        wireBaseList = glTools.utils.wire.getWireBase(wire[0])
        cmds.delete(mesh, ch=True)
        for edgeCrv in edgeCrvList:
            if cmds.objExists(edgeCrv):
                cmds.delete(edgeCrv)
        for smoothCrv in smoothCrvList:
            if cmds.objExists(smoothCrv):
                cmds.delete(smoothCrv)
        for wireBase in wireBaseList:
            if cmds.objExists(wireBase):
                cmds.delete(wireBase)

    # =================
    # - Return Result -
    # =================

    if edgeList:
        cmds.hilite(mesh)
        cmds.select(edgeList)

    return edgeList
예제 #4
0
def evenEdgeSpacing(edgeList,
                    smooth=0,
                    influence=1.0,
                    snapToOrig=False,
                    deleteHistory=False):
    """
    @param edgeList: List of polygon edges to evenly space
    @type edgeList: list
    @param smooth: Number of smooth iterations to apply
    @type smooth: int
    @param influence: Amount of result to apply to original vertex positions
    @type influence: float
    @param snapToOrig: Snap points back to original mesh
    @type snapToOrig: bool
    @param deleteHistory: Delete construction history.
    @type deleteHistory: bool
    """
    # Get Edge List
    edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or []
    if not edgeList:
        raise Exception(
            'Invalid or empty edge list! Unable to even edge spacing...')

    edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves(
        edgeList, keepHistory=False)
    evenCrvList = []
    for edgeCrv in edgeCrvList:

        # Rebuild Even Curve
        evenCrv = cmds.rebuildCurve(edgeCrv,
                                    ch=False,
                                    rpo=False,
                                    rt=0,
                                    end=1,
                                    kr=False,
                                    kcp=False,
                                    kep=True,
                                    kt=False,
                                    s=0,
                                    d=1,
                                    tol=0)[0]

        # Smooth Curve
        if smooth: smoothCurve(evenCrv, smooth, True)

        # Snap To Mesh
        mesh = cmds.ls(edgeList, o=True)[0]
        if snapToOrig:
            pts = glTools.utils.component.getComponentStrList(evenCrv)
            glTools.utils.mesh.snapPtsToMesh(mesh, pts)

        evenCrvList.append(evenCrv)

    # Apply Even Spacing to Mesh Edge Vertices
    wire = glTools.utils.wire.createMulti(mesh,
                                          edgeCrvList,
                                          dropoffDist=0.01,
                                          prefix=mesh.split(':')[-1])
    cmds.setAttr(wire[0] + '.rotation', 0)
    cmds.setAttr(wire[0] + '.envelope', influence)

    # Blend to Even Curve
    for i in range(len(edgeCrvList)):
        blendShape = glTools.utils.blendShape.create(
            baseGeo=edgeCrvList[i], targetGeo=[evenCrvList[i]])
        cmds.setAttr(blendShape + '.' + evenCrvList[i], 1)

    # ==================
    # - Delete History -
    # ==================

    if deleteHistory:
        wireBaseList = glTools.utils.wire.getWireBase(wire[0])
        cmds.delete(mesh, ch=True)
        for edgeCrv in edgeCrvList:
            if cmds.objExists(edgeCrv):
                cmds.delete(edgeCrv)
        for evenCrv in evenCrvList:
            if cmds.objExists(evenCrv):
                cmds.delete(evenCrv)
        for wireBase in wireBaseList:
            if cmds.objExists(wireBase):
                cmds.delete(wireBase)

    # =================
    # - Return Result -
    # =================

    if edgeList:
        cmds.hilite(mesh)
        cmds.select(edgeList)

    return edgeList
예제 #5
0
def straightenVerts(edgeList,
                    falloff=0.01,
                    influence=1.0,
                    snapToOriginal=False,
                    keepEdgeSpacing=False,
                    deleteHistory=False):
    """
    Straighten specified polygon vertices.
    @param influence:
    @param keepEdgeSpacing:
    @param edgeList: List of polygon edges to straighten.
    @type edgeList: list
    @param falloff: Falloff distance around selected vertices.
    @type falloff: float
    @param snapToOriginal: Snap vertices back to closest point on original mesh.
    @type snapToOriginal: bool
    @param deleteHistory: Delete construction history.
    @type deleteHistory: bool
    """
    # Get Edge List
    edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or []
    if not edgeList:
        raise Exception(
            'Invalid or empty edge list! Unable to straighten vertices...')

    # Build Edge Curve from Vertices
    edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves(
        edgeList, keepHistory=False)
    straightCrvList = []
    for edgeCrv in edgeCrvList:

        # Build Straight Curve
        straightCrv = cmds.rebuildCurve(edgeCrv,
                                        ch=False,
                                        rpo=False,
                                        rt=0,
                                        end=1,
                                        kr=False,
                                        kcp=False,
                                        kep=True,
                                        kt=False,
                                        s=1,
                                        d=1,
                                        tol=0)[0]

        # Rebuild Straight Curve
        dist = []
        total = 0.0
        params = []
        pts = glTools.utils.base.getMPointArray(edgeCrv)
        max = cmds.getAttr(straightCrv + '.maxValue')
        if keepEdgeSpacing:
            for i in range(pts.length() - 1):
                d = (pts[i] - pts[i + 1]).length()
                dist.append(d)
                total += d
            for i in range(len(dist)):
                d = dist[i] / total * max
                if i: d += params[-1]
                params.append(d)
        else:
            params = glTools.utils.mathUtils.distributeValue(
                pts.length(), rangeEnd=max)[1:-1]

        params = [straightCrv + '.u[' + str(i) + ']' for i in params]
        cmds.insertKnotCurve(params,
                             ch=False,
                             numberOfKnots=1,
                             add=True,
                             ib=False,
                             rpo=True)

        # Snap To Mesh
        mesh = cmds.ls(edgeList, o=True)[0]
        if snapToOriginal:
            pts = glTools.utils.component.getComponentStrList(straightCrv)
            glTools.utils.mesh.snapPtsToMesh(mesh, pts)

        # Append List
        straightCrvList.append(straightCrv)

    # =================
    # - Deform Points -
    # =================

    # Build Wire Deformer
    wire = glTools.utils.wire.createMulti(mesh,
                                          edgeCrvList,
                                          dropoffDist=falloff,
                                          prefix=mesh.split(':')[-1])
    cmds.setAttr(wire[0] + '.rotation', 0)

    # Blend to Straight Curve
    for i in range(len(edgeCrvList)):
        blendShape = glTools.utils.blendShape.create(
            baseGeo=edgeCrvList[i], targetGeo=[straightCrvList[i]])
        cmds.setAttr(blendShape + '.' + straightCrvList[i], influence)

    # ==================
    # - Delete History -
    # ==================

    if deleteHistory:
        wireBaseList = glTools.utils.wire.getWireBase(wire[0])
        cmds.delete(mesh, ch=True)
        for edgeCrv in edgeCrvList:
            if cmds.objExists(edgeCrv):
                cmds.delete(edgeCrv)
        for straightCrv in straightCrvList:
            if cmds.objExists(straightCrv):
                cmds.delete(straightCrv)
        for wireBase in wireBaseList:
            if cmds.objExists(wireBase):
                cmds.delete(wireBase)

    # =================
    # - Return Result -
    # =================

    if edgeList:
        cmds.hilite(mesh)
        cmds.select(edgeList)

    return edgeList
예제 #6
0
def smoothEdgeLine(edgeList,
                   smooth=4,
                   falloff=0.01,
                   snapToOrig=False,
                   keepEdgeSpacing=False,
                   deleteHistory=False):
    """
    @param edgeList:
    @param smooth:
    @param falloff:
    @param snapToOrig:
    @param keepEdgeSpacing:
    @param deleteHistory:
    """
    # Get Edge List
    edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or []
    if not edgeList:
        raise Exception('Invalid or empty edge list! Unable to even edge spacing...')

    edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves(edgeList, keepHistory=False)
    smoothCrvList = []
    for edgeCrv in edgeCrvList:

        # Smooth Edge Line
        smoothCrv = cmds.duplicate(edgeCrv, n=edgeCrv + '_smoothed')[0]
        smoothCurve(crv=smoothCrv,
                    iterations=smooth,
                    keepEnds=True,
                    keepSpacing=keepEdgeSpacing)

        # Snap To Mesh
        mesh = cmds.ls(edgeList, o=True)[0]
        if snapToOrig:
            pts = glTools.utils.component.getComponentStrList(smoothCrv)
            glTools.utils.mesh.snapPtsToMesh(mesh, pts)

        # Append List
        smoothCrvList.append(smoothCrv)

    # Apply Smoothed Edge to Vertices
    wire = glTools.utils.wire.createMulti(mesh, edgeCrvList, dropoffDist=falloff, prefix=mesh.split(':')[-1])
    cmds.setAttr(wire[0] + '.rotation', 0)

    # Blend to Smooth Curve
    for i in range(len(edgeCrvList)):
        blendShape = glTools.utils.blendShape.create(baseGeo=edgeCrvList[i], targetGeo=[smoothCrvList[i]])
        cmds.setAttr(blendShape + '.' + smoothCrvList[i], 1)

    # ==================
    # - Delete History -
    # ==================

    if deleteHistory:
        wireBaseList = glTools.utils.wire.getWireBase(wire[0])
        cmds.delete(mesh, ch=True)
        for edgeCrv in edgeCrvList:
            if cmds.objExists(edgeCrv):
                cmds.delete(edgeCrv)
        for smoothCrv in smoothCrvList:
            if cmds.objExists(smoothCrv):
                cmds.delete(smoothCrv)
        for wireBase in wireBaseList:
            if cmds.objExists(wireBase):
                cmds.delete(wireBase)

    # =================
    # - Return Result -
    # =================

    if edgeList:
        cmds.hilite(mesh)
        cmds.select(edgeList)

    return edgeList
예제 #7
0
def evenEdgeSpacing(edgeList,
                    smooth=0,
                    influence=1.0,
                    snapToOrig=False,
                    deleteHistory=False):
    """
    @param edgeList: List of polygon edges to evenly space
    @type edgeList: list
    @param smooth: Number of smooth iterations to apply
    @type smooth: int
    @param influence: Amount of result to apply to original vertex positions
    @type influence: float
    @param snapToOrig: Snap points back to original mesh
    @type snapToOrig: bool
    @param deleteHistory: Delete construction history.
    @type deleteHistory: bool
    """
    # Get Edge List
    edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or []
    if not edgeList:
        raise Exception('Invalid or empty edge list! Unable to even edge spacing...')

    edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves(edgeList, keepHistory=False)
    evenCrvList = []
    for edgeCrv in edgeCrvList:

        # Rebuild Even Curve
        evenCrv = cmds.rebuildCurve(edgeCrv,
                                  ch=False,
                                  rpo=False,
                                  rt=0,
                                  end=1,
                                  kr=False,
                                  kcp=False,
                                  kep=True,
                                  kt=False,
                                  s=0,
                                  d=1,
                                  tol=0)[0]

        # Smooth Curve
        if smooth: smoothCurve(evenCrv, smooth, True)

        # Snap To Mesh
        mesh = cmds.ls(edgeList, o=True)[0]
        if snapToOrig:
            pts = glTools.utils.component.getComponentStrList(evenCrv)
            glTools.utils.mesh.snapPtsToMesh(mesh, pts)

        evenCrvList.append(evenCrv)

    # Apply Even Spacing to Mesh Edge Vertices
    wire = glTools.utils.wire.createMulti(mesh, edgeCrvList, dropoffDist=0.01, prefix=mesh.split(':')[-1])
    cmds.setAttr(wire[0] + '.rotation', 0)
    cmds.setAttr(wire[0] + '.envelope', influence)

    # Blend to Even Curve
    for i in range(len(edgeCrvList)):
        blendShape = glTools.utils.blendShape.create(baseGeo=edgeCrvList[i], targetGeo=[evenCrvList[i]])
        cmds.setAttr(blendShape + '.' + evenCrvList[i], 1)

    # ==================
    # - Delete History -
    # ==================

    if deleteHistory:
        wireBaseList = glTools.utils.wire.getWireBase(wire[0])
        cmds.delete(mesh, ch=True)
        for edgeCrv in edgeCrvList:
            if cmds.objExists(edgeCrv):
                cmds.delete(edgeCrv)
        for evenCrv in evenCrvList:
            if cmds.objExists(evenCrv):
                cmds.delete(evenCrv)
        for wireBase in wireBaseList:
            if cmds.objExists(wireBase):
                cmds.delete(wireBase)

    # =================
    # - Return Result -
    # =================

    if edgeList:
        cmds.hilite(mesh)
        cmds.select(edgeList)

    return edgeList
예제 #8
0
def straightenVerts(edgeList,
                    falloff=0.01,
                    influence=1.0,
                    snapToOriginal=False,
                    keepEdgeSpacing=False,
                    deleteHistory=False):
    """
    Straighten specified polygon vertices.
    @param influence:
    @param keepEdgeSpacing:
    @param edgeList: List of polygon edges to straighten.
    @type edgeList: list
    @param falloff: Falloff distance around selected vertices.
    @type falloff: float
    @param snapToOriginal: Snap vertices back to closest point on original mesh.
    @type snapToOriginal: bool
    @param deleteHistory: Delete construction history.
    @type deleteHistory: bool
    """
    # Get Edge List
    edgeList = cmds.filterExpand(edgeList, ex=True, sm=32) or []
    if not edgeList:
        raise Exception('Invalid or empty edge list! Unable to straighten vertices...')

    # Build Edge Curve from Vertices
    edgeCrvList = glTools.tools.extractCurves.extractEdgeCurves(edgeList, keepHistory=False)
    straightCrvList = []
    for edgeCrv in edgeCrvList:

        # Build Straight Curve
        straightCrv = cmds.rebuildCurve(edgeCrv,
                                      ch=False,
                                      rpo=False,
                                      rt=0,
                                      end=1,
                                      kr=False,
                                      kcp=False,
                                      kep=True,
                                      kt=False,
                                      s=1,
                                      d=1,
                                      tol=0)[0]

        # Rebuild Straight Curve
        dist = []
        total = 0.0
        params = []
        pts = glTools.utils.base.getMPointArray(edgeCrv)
        max = cmds.getAttr(straightCrv + '.maxValue')
        if keepEdgeSpacing:
            for i in range(pts.length() - 1):
                d = (pts[i] - pts[i + 1]).length()
                dist.append(d)
                total += d
            for i in range(len(dist)):
                d = dist[i] / total * max
                if i: d += params[-1]
                params.append(d)
        else:
            params = glTools.utils.mathUtils.distributeValue(pts.length(), rangeEnd=max)[1:-1]

        params = [straightCrv + '.u[' + str(i) + ']' for i in params]
        cmds.insertKnotCurve(params, ch=False, numberOfKnots=1, add=True, ib=False, rpo=True)

        # Snap To Mesh
        mesh = cmds.ls(edgeList, o=True)[0]
        if snapToOriginal:
            pts = glTools.utils.component.getComponentStrList(straightCrv)
            glTools.utils.mesh.snapPtsToMesh(mesh, pts)

        # Append List
        straightCrvList.append(straightCrv)

    # =================
    # - Deform Points -
    # =================

    # Build Wire Deformer
    wire = glTools.utils.wire.createMulti(mesh, edgeCrvList, dropoffDist=falloff, prefix=mesh.split(':')[-1])
    cmds.setAttr(wire[0] + '.rotation', 0)

    # Blend to Straight Curve
    for i in range(len(edgeCrvList)):
        blendShape = glTools.utils.blendShape.create(baseGeo=edgeCrvList[i], targetGeo=[straightCrvList[i]])
        cmds.setAttr(blendShape + '.' + straightCrvList[i], influence)

    # ==================
    # - Delete History -
    # ==================

    if deleteHistory:
        wireBaseList = glTools.utils.wire.getWireBase(wire[0])
        cmds.delete(mesh, ch=True)
        for edgeCrv in edgeCrvList:
            if cmds.objExists(edgeCrv):
                cmds.delete(edgeCrv)
        for straightCrv in straightCrvList:
            if cmds.objExists(straightCrv):
                cmds.delete(straightCrv)
        for wireBase in wireBaseList:
            if cmds.objExists(wireBase):
                cmds.delete(wireBase)

    # =================
    # - Return Result -
    # =================

    if edgeList:
        cmds.hilite(mesh)
        cmds.select(edgeList)

    return edgeList
예제 #9
0
def pointOnPolyConstraintCmd(pt):
    """
    Generate a pointOnPolyConstraint setup command string.
    @param pt: Mesh point to generate pointOnPolyConstraint command for.
    @type pt: str
    """
    # ==================
    # - Initialize Cmd -
    # ==================

    cmd = ''

    # ===============================
    # - Get Mesh from Point on Poly -
    # ===============================

    fullname = cmds.ls(pt, o=True)[0]
    mesh = fullname.split(':')[-1]
    meshSN = mesh.split('|')[-1]

    # Get Mesh Component ID
    meshID = glTools.utils.component.index(pt)

    prevID = OpenMaya.MScriptUtil()
    prevID.createFromInt(0)
    prevIDPtr = prevID.asIntPtr()

    # =======================
    # - Constrain to Vertex -
    # =======================

    if '.vtx[' in pt:

        # Initialize MItMeshVertex
        meshIt = glTools.utils.mesh.getMeshVertexIter(mesh)
        meshIt.setIndex(meshID, prevIDPtr)

        # Get Vertex UV
        uv = OpenMaya.MScriptUtil()
        uv.createFromDouble(0.0)
        uvPtr = uv.asFloat2Ptr()
        meshIt.getUV(uvPtr)
        uv = [
            OpenMaya.MScriptUtil.getFloat2ArrayItem(uvPtr, 0, j)
            for j in [0, 1]
        ]
        cmd += '; setAttr ($constraint[0]+".%sU%d") %f; setAttr ($constraint[0]+".%sV%d") %f' % (
            meshSN, 0, uv[0], meshSN, 0, uv[1])

    # =====================
    # - Constrain to Edge -
    # =====================

    elif '.e[' in pt:

        # Initialize MItMeshEdge
        meshIt = glTools.utils.mesh.getMeshEdgeIter(mesh)
        meshIt.setIndex(meshID, prevIDPtr)

        # Get Edge/Vertices UV
        vtx = [meshIt.index(j) for j in [0, 1]]
        vtxIt = glTools.utils.mesh.getMeshVertexIter(mesh)
        uvs = []
        for v in vtx:
            vtxIt.setIndex(v, prevIDPtr)
            uv = OpenMaya.MScriptUtil()
            uv.createFromDouble(0.0)
            uvPtr = uv.asFloat2Ptr()
            vtxIt.getUV(uvPtr)
            uvs.append([
                OpenMaya.MScriptUtil.getFloat2ArrayItem(uvPtr, 0, j)
                for j in [0, 1]
            ])
        uv = [0.5 * (uvs[0][j] + uvs[1][j]) for j in [0, 1]]
        cmd += '; setAttr ($constraint[0]+".%sU%d") %f; setAttr ($constraint[0]+".%sV%d") %f' % (
            meshSN, 0, uv[0], meshSN, 0, uv[1])

    # =====================
    # - Constrain to Face -
    # =====================

    elif '.f[' in pt:

        # Initialize MItMeshface
        meshIt = glTools.utils.mesh.getMeshFaceIter(mesh)
        meshIt.setIndex(meshID, prevIDPtr)

        # Get Face UV
        u, v = OpenMaya.MFloatArray(), OpenMaya.MFloatArray()
        meshIt.getUVs(u, v)
        uv = (sum(u) / len(u), sum(v) / len(v))
        cmd += '; setAttr ($constraint[0]+".%sU%d") %f; setAttr ($constraint[0]+".%sV%d") %f' % (
            meshSN, 0, uv[0], meshSN, 0, uv[1])

    # =================
    # - Return Result -
    # =================

    return cmd
예제 #10
0
def pointOnPolyConstraintCmd(pt):
    """
    Generate a pointOnPolyConstraint setup command string.
    @param pt: Mesh point to generate pointOnPolyConstraint command for.
    @type pt: str
    """
    # ==================
    # - Initialize Cmd -
    # ==================

    cmd = ''

    # ===============================
    # - Get Mesh from Point on Poly -
    # ===============================

    fullname = cmds.ls(pt, o=True)[0]
    mesh = fullname.split(':')[-1]
    meshSN = mesh.split('|')[-1]

    # Get Mesh Component ID
    meshID = glTools.utils.component.index(pt)

    prevID = OpenMaya.MScriptUtil()
    prevID.createFromInt(0)
    prevIDPtr = prevID.asIntPtr()

    # =======================
    # - Constrain to Vertex -
    # =======================

    if '.vtx[' in pt:

        # Initialize MItMeshVertex
        meshIt = glTools.utils.mesh.getMeshVertexIter(mesh)
        meshIt.setIndex(meshID, prevIDPtr)

        # Get Vertex UV
        uv = OpenMaya.MScriptUtil()
        uv.createFromDouble(0.0)
        uvPtr = uv.asFloat2Ptr()
        meshIt.getUV(uvPtr)
        uv = [OpenMaya.MScriptUtil.getFloat2ArrayItem(uvPtr, 0, j) for j in [0, 1]]
        cmd += '; setAttr ($constraint[0]+".%sU%d") %f; setAttr ($constraint[0]+".%sV%d") %f' % (
        meshSN, 0, uv[0], meshSN, 0, uv[1])

    # =====================
    # - Constrain to Edge -
    # =====================

    elif '.e[' in pt:

        # Initialize MItMeshEdge
        meshIt = glTools.utils.mesh.getMeshEdgeIter(mesh)
        meshIt.setIndex(meshID, prevIDPtr)

        # Get Edge/Vertices UV
        vtx = [meshIt.index(j) for j in [0, 1]]
        vtxIt = glTools.utils.mesh.getMeshVertexIter(mesh)
        uvs = []
        for v in vtx:
            vtxIt.setIndex(v, prevIDPtr)
            uv = OpenMaya.MScriptUtil()
            uv.createFromDouble(0.0)
            uvPtr = uv.asFloat2Ptr()
            vtxIt.getUV(uvPtr)
            uvs.append([OpenMaya.MScriptUtil.getFloat2ArrayItem(uvPtr, 0, j) for j in [0, 1]])
        uv = [0.5 * (uvs[0][j] + uvs[1][j]) for j in [0, 1]]
        cmd += '; setAttr ($constraint[0]+".%sU%d") %f; setAttr ($constraint[0]+".%sV%d") %f' % (
        meshSN, 0, uv[0], meshSN, 0, uv[1])

    # =====================
    # - Constrain to Face -
    # =====================

    elif '.f[' in pt:

        # Initialize MItMeshface
        meshIt = glTools.utils.mesh.getMeshFaceIter(mesh)
        meshIt.setIndex(meshID, prevIDPtr)

        # Get Face UV
        u, v = OpenMaya.MFloatArray(), OpenMaya.MFloatArray()
        meshIt.getUVs(u, v)
        uv = (sum(u) / len(u), sum(v) / len(v))
        cmd += '; setAttr ($constraint[0]+".%sU%d") %f; setAttr ($constraint[0]+".%sV%d") %f' % (
        meshSN, 0, uv[0], meshSN, 0, uv[1])

    # =================
    # - Return Result -
    # =================

    return cmd