Пример #1
0
def curveInfo(curve, baseName='curveInfo'):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Creates a curve lenght measuring node

    ARGUMENTS:
    polyFace(string) - face of a poly

    RETURNS:
    length(float)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    _str_func = 'curveInfo'

    if VALID.is_shape(curve):
        l_shapes = [curve]
    else:
        l_shapes = mc.listRelatives(curve, s=True, fullPath=True)

    if len(l_shapes) > 1:
        raise ValueError, cgmGeneral.logString_msg(
            __str_func, "Must have one shape. Found {0} | {1}".format(
                len(l_shapes), l_shapes))

    infoNode = create(baseName, 'curveInfo')
    ATTR.connect((l_shapes[0] + '.worldSpace'), (infoNode + '.inputCurve'))
    return infoNode
Пример #2
0
def offsetShape_byVector(dag=None,
                         distance=1,
                         origin=None,
                         component='cv',
                         vector=None,
                         mode='origin',
                         factor=.5,
                         offsetMode='fixed'):
    """
    Attempt for more consistency 
    
    If origin is None, juse the center of each shape
    """
    _str_func = 'offsetShape_byVector'
    log.debug(
        "|{0}| >> dag: {1} | distance: {2} | origin: {3} | component: {4}".
        format(_str_func, dag, distance, origin, component))

    _originUse = None

    if VALID.isListArg(origin):
        _originUse = origin
    elif VALID.objString(origin, noneValid=True):
        log.debug(
            "|{0}| >> Getting origin from transform of origin string: {1}".
            format(_str_func, origin))
        _originUse = POS.get(origin)

    if VALID.is_shape(dag):
        l_shapes = [dag]
    else:
        l_shapes = mc.listRelatives(dag, shapes=True, fullPath=True)

    for i, s in enumerate(l_shapes):
        log.debug("|{0}| >> On shape: {1}".format(_str_func, s))
        if _originUse is None:
            #_trans = VALID.getTransform(dag)
            _origin = POS.get_bb_center(s)
            log.debug("|{0}| >> Getting origin from center of s: {1}".format(
                _str_func, _origin))
        else:
            _origin = _originUse

        _l_source = mc.ls("{0}.{1}[*]".format(s, component),
                          flatten=True,
                          long=True)

        for ii, c in enumerate(_l_source):
            log.debug("|{0}| >> Shape {1} | Comp: {2} | {3}".format(
                _str_func, i, ii, c))
            if offsetMode == 'fixed':
                set_vectorOffset(c, _origin, distance, vector, mode=mode)
            else:
                pMe = POS.get(c)
                _vec = MATHUTILS.get_vector_of_two_points(_origin, pMe)
                d = get_distance_between_points(_origin, pMe)
                newPos = get_pos_by_vec_dist(POS.get(c), _vec, d * factor)
                POS.set(c, newPos)

    return True
Пример #3
0
def get_size_byShapes(arg, mode='max'):
    _str_func = 'get_sizeByShapes'
    _arg = VALID.mNodeString(arg)
    log.debug("|{0}| >> arg: '{1}' ".format(_str_func, _arg))

    _l_bb = []
    _sizeX = []
    _sizeY = []
    _sizeZ = []

    _shapes = mc.listRelatives(_arg, s=True, fullPath=True)
    if not _shapes:
        if VALID.is_shape(arg):
            _shapes = [arg]
        else:
            raise ValueError, "|{0}| >> '{1}' has no shapes.".format(
                _str_func, _arg)
    for s in _shapes:
        _bfr = get_bb_size(s)
        _l_bb.append(_bfr)
        _sizeX.append(_bfr[0])
        _sizeY.append(_bfr[1])
        _sizeZ.append(_bfr[2])

    log.debug("|{0}| >> sx: '{1}' ".format(_str_func, _sizeX))
    log.debug("|{0}| >> sy: '{1}' ".format(_str_func, _sizeY))
    log.debug("|{0}| >> sz: '{1}' ".format(_str_func, _sizeZ))

    if mode == 'max':
        return max(max(_sizeX), max(_sizeY), max(_sizeZ))
    elif mode == 'bb':
        return [max(_sizeX), max(_sizeY), max(_sizeZ)]
    else:
        raise ValueError, "|{0}| >> unknown mode: {1}".format(_str_func, mode)
Пример #4
0
def get_nonintermediate(shape):
    """
    Get the nonintermediate shape on a transform
    
    :parameters:
        shape(str): Shape to check

    :returns
        non intermediate shape(string)
    """
    _str_func = "get_nonintermediate"
    try:
        if not VALID.is_shape(shape):
            _shapes = mc.listRelatives(shape, fullPath=True)
            _l_matches = []
            for s in _shapes:
                if not ATTR.get(s, 'intermediateObject'):
                    _l_matches.append(s)
            if len(_l_matches) == 1:
                return _l_matches[0]
            else:
                raise ValueError, "Not sure what to do with this many intermediate shapes: {0}".format(
                    _l_matches)
        elif ATTR.get(shape, 'intermediateObject'):
            _type = VALID.get_mayaType(shape)
            _trans = SEARCH.get_transform(shape)
            _shapes = mc.listRelatives(_trans,
                                       s=True,
                                       type=_type,
                                       fullPath=True)
            _l_matches = []
            for s in _shapes:
                if not ATTR.get(s, 'intermediateObject'):
                    _l_matches.append(s)
            if len(_l_matches) == 1:
                return _l_matches[0]
            else:
                raise ValueError, "Not sure what to do with this many intermediate shapes: {0}".format(
                    _l_matches)
        else:
            return shape
    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err)
Пример #5
0
def siblings_get(node=None, fullPath=True):
    """
    Get all the parents of a given node where the last parent is the top of the heirarchy
    
    :parameters:
        node(str): Object to check
        fullPath(bool): Whether you want long names or not

    :returns
        siblings(list)
    """
    _str_func = 'siblings_get'
    _node = VALID.mNodeString(node)

    _l_res = []
    _type = VALID.get_mayaType(_node)

    log.debug("|{0}| >> node: [{1}] | type: {2}".format(
        _str_func, _node, _type))

    if VALID.is_shape(_node):
        log.debug("|{0}| >> shape...".format(_str_func))
        _long = NAME.long(_node)
        for s in shapes_get(_node, True):
            if s != _long:
                _l_res.append(s)

    elif not VALID.is_transform(_node):
        log.debug("|{0}| >> not a transform...".format(_str_func))
        if VALID.is_component(_node):
            log.debug("|{0}| >> component...".format(_str_func))
            _comp = VALID.get_component(_node)
            log.debug("|{0}| >> component: {1}".format(_str_func, _comp))
            _comb = "{0}.{1}".format(_comp[1], _comp[0])
            for c in mc.ls("{0}.{1}[*]".format(_comp[1], _comp[2]),
                           flatten=True):
                if str(c) != _comb:
                    _l_res.append(c)
        else:
            _long = NAME.long(_node)
            log.debug("|{0}| >> something else...".format(_str_func))
            _l = mc.ls(type=_type)
            for o in _l:
                if NAME.long(o) != _long:
                    _l_res.append(o)
            #raise ValueError,"Shouldn't have arrived. node: [{0}] | type: {1}".format(_node,_type)
    elif parents_get(_node):
        log.debug("|{0}| >> parented...".format(_str_func))
        _long = NAME.long(_node)
        for c in children_get(parent_get(node), True):
            if c != _long:
                _l_res.append(c)
    else:
        log.debug("|{0}| >> root transform...".format(_str_func))
        l_rootTransforms = get_rootList()
        _short = NAME.short(_node)
        for o in l_rootTransforms:
            if o != _short and VALID.get_mayaType(o) == _type:
                _l_res.append(o)

    if not fullPath:
        return [NAME.short(o) for o in _l_res]
    return _l_res
Пример #6
0
def create_axisProxy(obj=None):
    """
    Make a local axis box around a given object so that you can then 
    
    """
    try:
        _str_func = 'create_axisProxy'
        _dag = VALID.getTransform(obj)
        if not _dag:
            raise ValueError, "Must have a dag node. Obj: {0}".format(obj)
        if VALID.is_shape(obj):
            l_shapes = [obj]
        else:
            l_shapes = TRANS.shapes_get(_dag, True)

        _parent = TRANS.parent_get(_dag)
        _dup = mc.duplicate(l_shapes, po=False, rc=True)[0]
        #TRANS.pivots_recenter(_dup)
        _dup = TRANS.parent_set(_dup, False)
        ATTR.set_standardFlags(_dup, lock=False, keyable=True)
        #Get some values...
        l_reset = ['t', 'r', 's', 'shear', 'rotateAxis']
        t = ATTR.get(_dup, 'translate')
        r = ATTR.get(_dup, 'rotate')
        s = ATTR.get(_dup, 'scale')
        ra = ATTR.get(_dup, 'rotateAxis')
        if ATTR.has_attr(_dup, 'jointOrient'):
            l_reset.append('jointOrient')
            jo = ATTR.get(_dup, 'jointOrient')
        o = TRANS.orient_get(_dup)
        shear = ATTR.get(_dup, 'shear')
        _scaleLossy = TRANS.scaleLossy_get(_dag)

        #Reset our stuff before we make our bb...
        ATTR.reset(_dup, l_reset)
        _size = POS.get_bb_size(_dup, True)

        #_proxy = create_proxyGeo('cube',COREMATH.list_div(_scaleLossy,_size))
        _proxy = create_proxyGeo('cube', _size)
        mc.makeIdentity(_proxy, apply=True, scale=True)

        #Now Put it back
        _dup = TRANS.parent_set(_dup, TRANS.parent_get(_dag))
        _proxy = TRANS.parent_set(_proxy, _dup)

        #_dup = TRANS.parent_set(_dup, TRANS.parents_get(_dag))
        SNAP.go(_dup, _dag)
        #ATTR.set(_dup,'s',(0,0,0))
        ATTR.reset(_dup, ['s', 'shear'])

        ATTR.reset(_proxy, ['t', 'r', 's', 'shear', 'rotateAxis'])
        _proxy = TRANS.parent_set(_proxy, _dag)
        ATTR.reset(_proxy, ['t', 'r', 's', 'shear', 'rotateAxis'])
        #match_transform(_proxy,_dag)

        #SNAP.go(_proxy,_dag,pivot='bb')

        #cgmGEN.func_snapShot(vars())

        _proxy = TRANS.parent_set(_proxy, False)
        mc.delete(_dup)
        #match_transform(_proxy,_dag)
        return mc.rename(_proxy,
                         "{0}_localAxisProxy".format(NAMES.get_base(_dag)))
    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, msg=vars())
Пример #7
0
def get(obj=None,
        pivot='rp',
        space='ws',
        targets=None,
        mode='xform',
        asEuclid=False):
    """
    General call for querying position data in maya.
    Note -- pivot and space are ingored in boundingBox mode which returns the center pivot in worldSpace
    
    :parameters:
        obj(str): Object to check
            Transform, components supported
        pivot(str): Which pivot to use. (rotate,scale,boundingBox)
            rotatePivot
            scalePivot
            boundingBox -- Returns the calculated center pivot position based on bounding box
        space(str): World,Object,Local
        mode(str):
            xform -- Utilizes tranditional checking with xForm or pointPosition for components
        asEuclid(bool) - whether to return as Vector or not
    :returns
        success(bool)
    """
    try:
        _str_func = 'get_pos'
        _obj = VALID.mNodeString(obj)
        _pivot = VALID.kw_fromDict(pivot,
                                   SHARED._d_pivotArgs,
                                   noneValid=False,
                                   calledFrom=_str_func)
        _targets = VALID.stringListArg(targets,
                                       noneValid=True,
                                       calledFrom=_str_func)
        _space = VALID.kw_fromDict(space,
                                   SHARED._d_spaceArgs,
                                   noneValid=False,
                                   calledFrom=_str_func)
        _mode = VALID.kw_fromDict(mode,
                                  _d_pos_modes,
                                  noneValid=False,
                                  calledFrom=_str_func)
        _res = False

        if _pivot == 'boundingBox':
            log.debug("|{0}|...boundingBox pivot...".format(_str_func))
            _res = get_bb_center(_obj)
            if MATH.is_vector_equivalent(
                    _res, [0, 0, 0]) and not mc.listRelatives(_obj, s=True):
                _pivot = 'rp'
                log.warning(
                    "|{0}|...boundingBox pivot is zero, using rp....".format(
                        _str_func))

        if '[' in _obj:
            log.debug("|{0}| >> component mode...".format(_str_func))
            if ":" in _obj.split('[')[-1]:
                raise ValueError, "|{0}| >>Please specify one obj. Component list found: {1}".format(
                    _str_func, _obj)
            #_cType = VALID.get_mayaType(_obj)
            _l_comp = VALID.get_component(_obj)
            _root = _l_comp[1]
            _cType = _l_comp[3]
            if not VALID.is_shape(_root):
                _shapes = mc.listRelatives(_root, s=True, fullPath=True) or []
                if len(_shapes) > 1:
                    log.warning(
                        "|{0}| >>More than one shape found. To be more accurate, specify: {1} | shapes: {2}"
                        .format(_str_func, _obj, _shapes))
                _root = _shapes[0]

            _OBJ = '.'.join([_root, _l_comp[0]])

            log.debug(
                "|{0}| >> obj: {1}({6}) | type: {2} | pivot: {3} | space: {4} | mode: {5}"
                .format(_str_func, _OBJ, _cType, _pivot, _space, _mode, _obj))

            kws_pp = {'world': False, 'local': False}
            if _space == 'world': kws_pp['world'] = True
            else: kws_pp['local'] = True

            if _cType == 'polyVertex':
                _res = mc.pointPosition(_OBJ, **kws_pp)
            elif _cType == 'polyEdge':
                mc.select(cl=True)
                mc.select(_OBJ)
                mel.eval("PolySelectConvert 3")
                edgeVerts = mc.ls(sl=True, fl=True)
                posList = []
                for vert in edgeVerts:
                    posList.append(mc.pointPosition(vert, **kws_pp))
                _res = MATH.get_average_pos(posList)
            elif _cType == 'polyFace':
                mc.select(cl=True)
                mc.select(_OBJ)
                mel.eval("PolySelectConvert 3")
                edgeVerts = mc.ls(sl=True, fl=True)
                posList = []
                for vert in edgeVerts:
                    posList.append(mc.pointPosition(vert, **kws_pp))
                _res = MATH.get_average_pos(posList)
            elif _cType in [
                    'surfaceCV', 'curveCV', 'editPoint', 'surfacePoint',
                    'curvePoint', 'cv', 'bezierCurve'
            ]:
                _res = mc.pointPosition(_OBJ, **kws_pp)
                #_res =  mc.pointPosition(_OBJ)
            else:
                raise RuntimeError, "|{0}| >> Shouldn't have gotten here. Need another check for component type. '{1}'".format(
                    _str_func, _cType)

        else:
            log.debug(
                "|{0}| >> obj: {1} | pivot: {2} | space: {3} | mode: {4} | asEuclid: {5}"
                .format(_str_func, _obj, _pivot, _space, _mode, asEuclid))
            if _space == 'local' or _pivot == 'local':
                _res = ATTR.get(_obj, 'translate')
            #elif _pivot == 'local':
            #if _space == 'world':
            #    _res = mc.xform(_obj, q=True, rp = True, ws=True )
            #else:
            #    _res = ATTR.get(_obj,'translate')
            else:
                kws = {
                    'q': True,
                    'rp': False,
                    'sp': False,
                    'os': False,
                    'ws': False
                }
                if _pivot == 'rp': kws['rp'] = True
                else: kws['sp'] = True

                if _space == 'object': kws['os'] = True
                else: kws['ws'] = True

                log.debug("|{0}| >> xform kws: {1}".format(_str_func, kws))

                _res = mc.xform(_obj, **kws)

        if _res is not None:
            if asEuclid:
                log.debug("|{0}| >> asEuclid...".format(_str_func))
                return EUCLID.Vector3(_res[0], _res[1], _res[2])
            return _res
        raise RuntimeError, "|{0}| >> Shouldn't have gotten here: obj: {1}".format(
            _str_func, _obj)
    except Exception, err:
        cgmGen.cgmExceptCB(Exception, err)
Пример #8
0
def get_axisBox_size(arg=None, children=False, mode=None, asEuclid=False):
    """
    Get the bb size of a given arg
    
    :parameters:
        arg(str/list): Object(s) to check
        shapes(bool): Only check dag node shapes
        mode(varied): 
            True/'max': Only return max value
            'min': Only min

    :returns
        boundingBox size(list)
    """
    _str_func = 'get_axisBox_size'
    #_arg = VALID.stringListArg(arg,False,_str_func)
    try:
        log.debug("|{0}| >> shapes mode ".format(_str_func))
        arg = VALID.listArg(arg)

        _dag = VALID.getTransform(arg[0])
        if not _dag:
            raise ValueError, "Must have a dag node. Obj: {0}".format(_dag)
        if VALID.is_shape(_dag):
            l_shapes = [_dag]
        else:
            l_shapes = mc.listRelatives(_dag, s=True, fullPath=True) or []

        _dup = mc.duplicate(l_shapes, po=False, rc=True)[0]
        if not children:
            for o in mc.listRelatives(
                    _dup, children=True, type='transform',
                    fullPath=True) or []:
                mc.delete(o)
        try:
            _dup = mc.parent(_dup, world=True)[0]
        except:
            pass

        #Reset our stuff before we make our bb...
        ATTR.reset(_dup, ['t', 'r', 'shear'])
        _size = get_bb_size(_dup, True)

        mc.delete(_dup)

        _res = _size

        if mode is None:
            if asEuclid:
                log.debug("|{0}| >> asEuclid...".format(_str_func))
                return EUCLID.Vector3(_res[0], _res[1], _res[2])
            return _res
        elif mode in [True, 'max']:
            return max(_res)
        elif mode in ['min']:
            return min(_res)
        else:
            log.error("|{0}| >> Unknown mode. Returning default. {1} ".format(
                _str_func, mode))
        return _res
    except Exception, err:
        cgmGen.cgmExceptCB(Exception, err, msg=vars())