# Path: mayaLib/rigLib/utils/common.py
# def centerPivot(obj, targetPivot=None):
# def freezeTranform(obj):
# def deleteHistory(obj):
# def deleteNonDeformerHistory(obj):
# def deleteConnection(objAttrList):
# def setDrivenKey(driver, driverValueList, driven, drivenValueList, cvType='linear'):
# 
# Path: mayaLib/rigLib/utils/name.py
# def removeSuffix(name):
# def getSide(name):
# def getAlpha(i):
# 
# Path: mayaLib/rigLib/utils/util.py
# def getDriverDrivenFromConstraint(constraint):
# def returnDriverObject(attribute, skipConversionNodes=False):
# def returnDrivenAttribute(attribute, skipConversionNodes=False):
# def returnDrivenObject(attribute, skipConversionNodes=True):
# def getAllObjectUnderGroup(group, type='mesh'):
# def moveShape(source, destination):
# def get_distance(obj1, obj2):
#     def ctr_dist(objA, objB):
# def get_distance_from_coords(bboxMin, bboxMax):
# def lock_and_hide_all(node):
# def unlock_and_unhide_all(node):
# def no_render(tgt):
# def invertSelection():
# def getPlanarRadiusBBOXFromTransform(transform, radiusFactor=2):
# def matrixConstrain(driver, driven, parent=None, translate=True, rotate=True, scale=False):


import pymel.core as pm
from mayaLib.rigLib.utils import common
from mayaLib.rigLib.utils import name
from mayaLib.rigLib.utils import util
    pm.matchTransform(loc, obj)
    pm.connectAttr(loc.translate, closestPointOnMesh.inPosition)

    u = closestPointOnMesh.result.parameterU.get()
    v = closestPointOnMesh.result.parameterV.get()

    pm.delete(closestPointOnMesh, loc)

    return u, v


def makeControlFollowSkin(geo, ctrl, drivenObj):
    geo = pm.ls(geo)[0]
    ctrl = pm.ls(ctrl)[0]
    drivenObj = pm.ls(drivenObj)[0]
    uv = findClosestUVCoordinate(geo, ctrl)
    prefix = name.removeSuffix(ctrl.name())
    follicle = createFollicle(geo, uv[0], uv[1], prefix)

    followGrp = pm.group(em=True, n=prefix + 'Follow_GRP', w=True)
    compensateGrp = pm.group(em=True, n=prefix + 'Compensate_GRP', w=True)

    common.centerPivot(compensateGrp, ctrl)
    common.centerPivot(followGrp, ctrl)

    pm.parent(compensateGrp, followGrp)
    pm.parent(followGrp, ctrl.getParent())
    pm.parent(ctrl, compensateGrp)

    # pm.pointConstraint(follicle, followGrp, mo=True)

# Path: mayaLib/rigLib/utils/common.py
# def centerPivot(obj, targetPivot=None):
# def freezeTranform(obj):
# def deleteHistory(obj):
# def deleteNonDeformerHistory(obj):
# def deleteConnection(objAttrList):
# def setDrivenKey(driver, driverValueList, driven, drivenValueList, cvType='linear'):
# 
# Path: mayaLib/rigLib/utils/name.py
# def removeSuffix(name):
# def getSide(name):
# def getAlpha(i):
# 
# Path: mayaLib/rigLib/utils/util.py
# def getDriverDrivenFromConstraint(constraint):
# def returnDriverObject(attribute, skipConversionNodes=False):
# def returnDrivenAttribute(attribute, skipConversionNodes=False):
# def returnDrivenObject(attribute, skipConversionNodes=True):
# def getAllObjectUnderGroup(group, type='mesh'):
# def moveShape(source, destination):
# def get_distance(obj1, obj2):
#     def ctr_dist(objA, objB):
# def get_distance_from_coords(bboxMin, bboxMax):
# def lock_and_hide_all(node):
# def unlock_and_unhide_all(node):
# def no_render(tgt):
# def invertSelection():
# def getPlanarRadiusBBOXFromTransform(transform, radiusFactor=2):
# def matrixConstrain(driver, driven, parent=None, translate=True, rotate=True, scale=False):


# Path: mayaLib/rigLib/utils/followCtrl.py
import pymel.core as pm
from mayaLib.rigLib.utils import common
from mayaLib.rigLib.utils import name
from mayaLib.rigLib.utils import util

    pm.matchTransform(loc, obj)
    pm.connectAttr(loc.translate, closestPointOnMesh.inPosition)

    u = closestPointOnMesh.result.parameterU.get()
    v = closestPointOnMesh.result.parameterV.get()

    pm.delete(closestPointOnMesh, loc)

    return u, v


def makeControlFollowSkin(geo, ctrl, drivenObj):
    geo = pm.ls(geo)[0]
    ctrl = pm.ls(ctrl)[0]
    drivenObj = pm.ls(drivenObj)[0]
    uv = findClosestUVCoordinate(geo, ctrl)
    prefix = name.removeSuffix(ctrl.name())
    follicle = createFollicle(geo, uv[0], uv[1], prefix)

    followGrp = pm.group(em=True, n=prefix + 'Follow_GRP', w=True)
    compensateGrp = pm.group(em=True, n=prefix + 'Compensate_GRP', w=True)

    common.centerPivot(compensateGrp, ctrl)
    common.centerPivot(followGrp, ctrl)

    pm.parent(compensateGrp, followGrp)
    pm.parent(followGrp, ctrl.getParent())
    pm.parent(ctrl, compensateGrp)

    # pm.pointConstraint(follicle, followGrp, mo=True)

    util.matrixConstrain(follicle, followGrp, rotate=False)