示例#1
0
def get_axisBox_size(targets=None, maxDistance=10000000, mark=False):
    try:
        _str_func = 'get_axisBox_size'
        log.debug("|{0}| >> ".format(_str_func) + '-' * 80)

        targets = VALID.listArg(targets)
        _targets = VALID.mNodeStringList(targets)

        if not _targets:
            raise ValueError, "Must have targets!"

        d_res = {'x': [], 'y': [], 'z': []}

        for t in _targets:
            log.debug("|{0}| >> On t: {1}".format(_str_func, t))
            _proxy = CORERIG.create_axisProxy(t)
            _startPoint = POS.get(_proxy, 'bb')
            for k in d_res.keys():
                log.debug("|{0}| >> On t: {1} | {2}".format(_str_func, t, k))

                pos_positive = RAYS.get_cast_pos(t,
                                                 k + '+',
                                                 'near',
                                                 _proxy,
                                                 startPoint=_startPoint,
                                                 mark=False,
                                                 maxDistance=maxDistance)
                pos_neg = RAYS.get_cast_pos(t,
                                            k + '-',
                                            'near',
                                            _proxy,
                                            startPoint=_startPoint,
                                            mark=False,
                                            maxDistance=maxDistance)

                if mark:
                    LOCINATOR.LOC.create(position=pos_positive,
                                         name="{0}_{1}Pos_loc".format(t, k))
                    LOCINATOR.LOC.create(position=pos_neg,
                                         name="{0}_{1}Neg_loc".format(t, k))

                dist = DIST.get_distance_between_points(pos_positive, pos_neg)
                d_res[k].append(dist)
            mc.delete(_proxy)

        for k, v in d_res.iteritems():
            d_res[k] = COREMATH.average(v)

        return d_res['x'], d_res['y'], d_res['z']

    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err)
示例#2
0
def get_special_pos(targets=None, arg='rp', mode=None, mark=False):
    """
    This had to move here for import loop considerations

    :parameters:
        obj(str): Object to modify
        target(str): Object to snap to
        sourceObject(str): object to copy from
        arg
            rp
            sp
            boundingBoxEach
            boundingBoxAll - all targets bounding box cumulative
            axisBox
            castFar
            castNear
            groundPos
        mode - Relative to 
            center
            front
            x

    :returns
        success(bool)
    """
    try:
        _str_func = 'get_special_pos'
        _sel = mc.ls(sl=True) or []

        targets = VALID.listArg(targets)
        _targets = VALID.mNodeStringList(targets)

        if not _targets:
            raise ValueError, "Must have targets!"

        _arg = VALID.kw_fromDict(arg,
                                 SHARED._d_pivotArgs,
                                 noneValid=True,
                                 calledFrom=__name__ + _str_func +
                                 ">> validate pivot")
        if _arg is None:
            _arg = arg

        if _arg == 'cast':
            _arg = 'castNear'

        if mode is None:
            if _arg in ['boundingBox']:
                mode = 'center'
            else:
                mode = 'z+'

        l_nameBuild = ['_'.join([NAMES.get_base(o) for o in _targets]), _arg]
        if mode:
            l_nameBuild.append(mode)
        l_res = []
        if _arg in ['rp', 'sp']:
            for t in _targets:
                l_res.append(POS.get(t, _arg, 'world'))
        elif _arg == 'boundingBox':
            l_res.append(POS.get_bb_pos(_targets, False, mode))
        elif _arg == 'boundingBoxShapes':
            l_res.append(POS.get_bb_pos(_targets, True, mode))
        elif _arg == 'boundingBoxEach':
            for t in _targets:
                l_res.append(POS.get_bb_pos(t, False, mode))
        elif _arg == 'boundingBoxEachShapes':
            for t in _targets:
                l_res.append(POS.get_bb_pos(t, True, mode))
        elif _arg == 'groundPos':
            for t in targets:
                pos = TRANS.position_get(t)
                l_res.append([pos[0], 0.0, pos[2]])
        elif _arg.startswith('castAll'):
            _type = _arg.split('castAll')[-1].lower()
            log.debug("|{0}| >> castAll mode: {1} | {2}".format(
                _str_func, mode, _type))
            pos = RAYS.get_cast_pos(_targets[0],
                                    mode,
                                    _type,
                                    None,
                                    mark=False,
                                    maxDistance=100000)
            l_res.append(pos)
        elif _arg.startswith('cast'):
            _type = _arg.split('cast')[-1].lower()
            log.debug("|{0}| >> cast mode: {1} | {2}".format(
                _str_func, mode, _type))
            if len(_targets) > 1:
                log.debug("|{0}| >> more than one target...".format(_str_func))
                pos = RAYS.get_cast_pos(_targets[0],
                                        mode,
                                        _type,
                                        _targets[1:],
                                        mark=False,
                                        maxDistance=100000)
            else:
                pos = RAYS.get_cast_pos(_targets[0],
                                        mode,
                                        _type,
                                        _targets,
                                        mark=False,
                                        maxDistance=100000)
            if not pos:
                return False
            l_res.append(pos)
        elif _arg == 'axisBox':
            log.warning("|{0}| >> axisBox mode is still wip".format(_str_func))
            if not targets:
                raise ValueError, "No targets in axisBox cast!"
            for t in targets:
                log.debug("|{0}| >> AxisBox cast: {1} ".format(_str_func, t))
                _proxy = CORERIG.create_axisProxy(t)
                #Start point is bb center because rp can sometimes be in odd places and we care about the axisBox
                pos = RAYS.get_cast_pos(t,
                                        mode,
                                        'near',
                                        _proxy,
                                        startPoint=POS.get(_proxy, 'bb'),
                                        mark=False,
                                        maxDistance=100000)

                log.debug("|{0}| >> AxisBox dat: {1}".format(_str_func, pos))
                #if not pos:
                #    pprint.pprint(vars())
                l_res.append(pos)
                mc.delete(_proxy)
        else:
            raise ValueError, "|{0}| >> Unknown mode: {1}".format(
                _str_func, _arg)

        #cgmGEN.func_snapShot(vars())

        if len(l_res) > 1:
            _res = DIST.get_average_position(l_res)
        else:
            _res = l_res[0]

        if mark:
            _loc = mc.spaceLocator()[0]
            mc.move(_res[0], _res[1], _res[2], _loc, ws=True)
            mc.rename(_loc, '{0}_loc'.format('_'.join(l_nameBuild)))
        if _sel and not mark:
            mc.select(_sel)
        return _res
    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err)