def to_ground(obj=None): _str_func = 'snap_to_ground' _obj = VALID.mNodeString(obj) p_bottom = POS.get_bb_pos(_obj,True,'bottom') p_pivot = POS.get(_obj) p_pivot[1] = p_pivot[1] - p_bottom[1] POS.set(_obj,p_pivot)
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)