Esempio n. 1
0
def get_midPointDict(sourceList, forceBBCenter=False):
    _l_info = []
    _l_pos = []
    _l_rot = []
    for s in sourceList:
        _d = POS.get_info(s, boundingBox=forceBBCenter)
        _l_pos.append(_d['position'])
        _l_rot.append(_d['rotation'])
        _l_info.append(_d)
    _d = _l_info[0]
    _d['position'] = MATH.get_average_pos(_l_pos)
    _d['rotation'] = MATH.get_average_pos(_l_rot)
    #position(_target,_d)
    return _d
Esempio n. 2
0
def matchTarget_snap(obj=None,
                     move=True,
                     rotate=True,
                     boundingBox=False,
                     pivot='rp'):
    """
    Snap an object to it's match target
    
    :parameters:
        obj(str): Object to modify
        target(str): Target to match

    :returns
        success(bool)
    """
    _str_func = 'matchTarget_snap'

    _obj = VALID.objString(obj,
                           noneValid=False,
                           calledFrom=__name__ + _str_func + ">> validate obj")

    _target = ATTR.get_message(_obj, 'cgmMatchTarget', 'cgmMatchDat', 0)

    if not _target:
        raise ValueError, "|{0}| >> {1} has no cgmMatchTarget.".format(
            _str_func, NAMES.get_short(_obj))

    log.debug("|{0}| >> {1} snapping to: {2}.".format(_str_func,
                                                      NAMES.get_short(_obj),
                                                      _target[0]))

    go(obj, _target[0], move, rotate, pivot=pivot)
    return True

    _dict = POS.get_info(_target[0])

    #cgmGEN.log_info_dict(_dict)

    pos = _dict['position']

    if move:
        mc.move(pos[0], pos[1], pos[2], _obj, ws=True, rpr=True)
    if rotate:
        #if _dict.get('rotateOrder'):mc.xform(_obj, roo=_dict['rotateOrder'],p=True)
        if _dict.get('rotation'): mc.xform(_obj, ro=_dict['rotation'], ws=True)
        #if _dict.get('rotateAxis'):mc.xform(_obj, ra=_dict['rotateAxis'],p=True)

    return True
Esempio n. 3
0
def uiFunc_updateFields(self):
    _str_func = 'uiFunc_updateFields'
    #_type = VALID.get_mayaType(_short)

    if not self._mTransformTarget:
        return False
    _short = self._mTransformTarget.mNode

    #_space = self.var_sourceTransSpaceMode.value
    #log.info("|{0}| >> Getting data. Space: {1} ".format(_str_func, _space))

    #_pos = POS.get(_short,'rp',_space)
    _info = POS.get_info(_short)

    pprint.pprint(_info)
    #pprint.pprint(self._d_transformAttrFields)
    _d_sectionToDatKey = {'rotate': 'rotateLocal', 'orient': 'rotation'}

    for section in self._d_transformAttrFields.keys():
        log.info("|{0}| >> On {1}".format(_str_func, section))
        _s = section
        if _s in [
                'translate', 'rotate', 'position', 'rotateAxis', 'scalePivot',
                'orient'
        ]:
            _k = _d_sectionToDatKey.get(_s, _s)
            for i, v in enumerate(_info[_k]):
                self._d_transformAttrFields[_s]['XYZ'[i]].setValue(v)

        elif _s == 'jointOrient':
            if ATTR.has_attr(_short, 'jointOrient'):
                self._d_transformRows[_s](edit=True, vis=True)
                _v = ATTR.get(_short, 'jointOrient')
                log.info("|{0}| >> jointOrient: {1}".format(_str_func, _v))
                for i, v in enumerate(_v):
                    self._d_transformAttrFields[_s]['XYZ'[i]].setValue(v)
            else:
                self._d_transformRows[_s](edit=True, vis=False)
        elif _s == 'scale':
            for i, v in enumerate(ATTR.get(_short, 'scale')):
                self._d_transformAttrFields[_s]['XYZ'[i]].setValue(v)
        elif _s == 'scaleLossy':
            for i, v in enumerate(TRANS.scaleLossy_get(_short)):
                self._d_transformAttrFields[_s]['XYZ'[i]].setValue(v)
        else:
            log.info("|{0}| >> Missing query for {1}".format(
                _str_func, section))
Esempio n. 4
0
    def getAndMove(loc, targets=None, mode=None, forceBBCenter=False):

        log.debug("|{0}| >> mode: {1} | targets: {2}".format(
            _str_func, mode, targets))
        if not targets:
            raise ValueError, "Must have targets"

        _kws = {'target': loc, 'move': True, 'rotate': True}

        if mode == 'fromTarget':
            _d = POS.get_info(targets[0])
            _kws['infoDict'] = _d

        elif mode == 'midPoint':
            if len(targets) == 1:
                _d = POS.get_info(targets[0], boundingBox=True)
                _kws['infoDict'] = _d

            elif not len(targets) >= 2:
                raise ValueError, "midPoint mode must have at least two targets"
            else:
                _d = get_midPointDict(targets, forceBBCenter)
                _kws['infoDict'] = _d

        elif mode == 'closestPoint':
            if not len(targets) >= 2:
                raise ValueError, "midPoint mode must have at least two targets"

            _d = {
                'position':
                DIST.get_by_dist(targets[0],
                                 targets[1:],
                                 resMode='pointOnSurface')
            }
            _kws['infoDict'] = _d
            _kws['rotate'] = False

        elif mode == 'closestTarget':
            if not len(targets) >= 3:
                raise ValueError, "midPoint mode must have at least three targets"

            _d = POS.get_info(
                DIST.get_by_dist(targets[0], targets[1:], resMode='object'))
            _d['rotateOrder'] = False
            _d['rotateAxis'] = False

            _kws['infoDict'] = _d

        elif mode == 'rayCast':
            _dbuffer = r9Meta.MetaClass(_loc).cgmLocDat
            _d = {}
            _p = POS.get_uv_position(_target[0], _dbuffer['uv'])
            if _dbuffer.get('offsetDist'):
                _v = POS.get_uv_normal(_target[0], _dbuffer['uv'])
                _dist = _dbuffer.get('offsetDist')
                _p = DIST.get_pos_by_vec_dist(_p, _v, _dist)
            _d['position'] = _p
            _kws['infoDict'] = _d
            _kws['rotate'] = False
        else:
            log.error("|{0}| >> unknown mode: {1}".format(_str_func, _mode))
            return False

        try:
            return position(**_kws)
        except Exception, err:
            log.error("|{0}| >> loc: {1}".format(_str_func, loc))
            cgmGeneral.log_info_dict(_kws['infoDict'],
                                     "{0} >> {1}".format(_str_func, mode))
            log.error("|{0}| >> err: {1}".format(_str_func, _err))
            return False
Esempio n. 5
0
    _targets = VALID.listArg(targets)

    if _type == 'locator':
        if mode and _targets:
            log.debug("|{0}| >> mode override...".format(_str_func))

            return getAndMove(_loc, _targets, mode, forceBBCenter)

        elif _targets:
            log.debug("|{0}| >> source mode...".format(_str_func))
            if len(_targets) > 1:
                log.debug("|{0}| >> assuming midPoint...".format(_str_func))
                return getAndMove(_loc, _targets, 'midPoint', forceBBCenter)
            else:
                log.debug("|{0}| >> singleTarget...".format(_str_func))
                _d = POS.get_info(_targets, boundingBox=forceBBCenter)
                position(_loc, _d)
                return True
        else:
            log.debug("|{0}| >> tagged...".format(_str_func))
            _mode = SEARCH.get_nodeTagInfo(_loc, 'cgmLocMode')
            if _mode == 'fromTarget':
                _targets = ATTR.get_message(_loc, 'cgmLocSource', 'cgmLocDat')
                return getAndMove(_loc, _targets, _mode, forceBBCenter)

            elif _mode == 'midPoint':
                _targets = ATTR.msgList_get(_loc, 'cgmLocSource', 'cgmLocDat')
                return getAndMove(_loc, _targets, _mode, forceBBCenter)

            elif _mode == 'closestPoint':
                _targets = ATTR.msgList_get(_loc, 'cgmLocSource', 'cgmLocDat')