def lever(self, ball=False): try: _str_func = 'lever_digit' log_start(_str_func) mBlock = self.mBlock mRigNull = self.mRigNull _offset = self.v_offset _jointOrientation = self.d_orientation['str'] ml_formHandles = self.ml_formHandles ml_prerigHandles = self.ml_prerigHandles mHandleFactory = self.mHandleFactory #Mesh shapes ---------------------------------------------------------- mMesh_tmp = self.mBlock.atUtils('get_castMesh') str_meshShape = mMesh_tmp.getShapes()[0] #Figure out our knots ---------------------------------------------------- mMain = self.ml_formHandlesUse[0] mMainLoft = mMain.loftCurve idxMain = self.ml_shapers.index(mMainLoft) minU = ATTR.get(str_meshShape, 'minValueU') maxU = ATTR.get(str_meshShape, 'maxValueU') f_factor = (maxU - minU) / (20) pprint.pprint(vars()) #reload(SURF) #Meat ============================================================== mLeverDirect = mRigNull.getMessageAsMeta('leverDirect') mLeverFK = mRigNull.getMessageAsMeta('leverFK') mLeverControlCast = mLeverDirect if not mLeverControlCast: mLeverControlCast = mLeverFK log.debug("|{0}| >> mLeverControlCast: {1}".format( _str_func, mLeverControlCast)) dist_lever = DIST.get_distance_between_points( ml_prerigHandles[0].p_position, ml_prerigHandles[1].p_position) log.debug("|{0}| >> Lever dist: {1}".format(_str_func, dist_lever)) #Dup our rig joint and move it mDup = mLeverControlCast.doDuplicate(po=True) mDup.p_parent = mLeverControlCast mDup.resetAttrs() ATTR.set(mDup.mNode, 't{0}'.format(_jointOrientation[0]), dist_lever * .5) l_lolis = [] l_starts = [] _mTar = mDup if ball: #Loli =============================================================== mDefineLeverObj = mBlock.defineLeverHelper _mVectorLeverUp = MATH.get_obj_vector(mDefineLeverObj.mNode, 'y+', asEuclid=True) #mOrientHelper = mBlock.orientHelper #_mVectorLeverUp = MATH.get_obj_vector(mOrientHelper.mNode,'y+',asEuclid=True) mBall_tmp = mBlock.atUtils('get_castMesh') str_ballShape = mBall_tmp.getShapes()[0] pos = RAYS.cast(str_ballShape, startPoint=_mTar.p_position, vector=_mVectorLeverUp).get('near') #pos = RAYS.get_cast_pos(_mTar.mNode,_mVectorLeverUp,shapes = str_ballShape) #SNAPCALLS.get_special_pos([_mTar,str_ballShape],'castNear',str_settingsDirections,False) vec = MATH.get_vector_of_two_points(_mTar.p_position, pos) newPos = DIST.get_pos_by_vec_dist(pos, vec, _offset * 4) ball = CURVES.create_fromName('sphere', _offset * 2) mBall = cgmMeta.cgmObject(ball) mBall.p_position = newPos SNAP.aim_atPoint( mBall.mNode, _mTar.p_position, aimAxis=_jointOrientation[0] + '+', mode='vector', vectorUp=_mTar.getAxisVector(_jointOrientation[0] + '-')) line = mc.curve(d=1, ep=[pos, newPos], os=True) l_lolis.extend([ball, line]) ATTR.set(mDup.mNode, 't{0}'.format(_jointOrientation[0]), dist_lever * .8) CORERIG.shapeParent_in_place(mLeverFK.mNode, l_lolis, False) mBall_tmp.delete() #Main clav section ======================================== """ ml_clavShapes = BUILDUTILS.shapes_fromCast(self, targets= [mLeverControlCast.mNode, mDup.mNode], aimVector= self.d_orientation['vectorOut'], connectionPoints = 5, f_factor=0, offset=_offset, mode = 'frameHandle')""" l_curves = SURF.get_splitValues(str_meshShape, knotIndices=[0, idxMain], mode='u', insertMax=False, preInset=f_factor * .5, postInset=-f_factor * .5, curvesCreate=True, curvesConnect=True, connectionPoints=6, offset=self.v_offset) ml_shapes = cgmMeta.validateObjListArg(l_curves) mHandleFactory.color(mLeverFK.mNode, controlType='sub') CORERIG.shapeParent_in_place(mLeverFK.mNode, ml_shapes[0].mNode, False, replaceShapes=False) mDup.delete() for mShape in ml_shapes: try: mShape.delete() except: pass mMesh_tmp.delete() except Exception, err: cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
def specialSnap(obj=None, targets=None, arg='axisBox', mode='center', castOffset=False): """ Special snap functionality :parameters: obj(str): Object to modify target(str): Object to snap to sourceObject(str): object to copy from :returns success(bool) """ try: _str_func = 'specialSnap' _obj = VALID.mNodeString(obj) _targets = VALID.listArg(targets) if not _targets: _targets = [_obj] if arg not in ['axisBox']: _targets.insert(0, _obj) p = get_special_pos(_targets, arg, mode, False) if castOffset: p_start = TRANS.position_get(_obj) _vector_to_hit = COREMATH.get_vector_of_two_points(p_start, p) _vector_to_start = COREMATH.get_vector_of_two_points(p, p_start) _cast = RAYS.cast(startPoint=p_start, vector=_vector_to_hit) _hit = _cast.get('near') _dist_base = DIST.get_distance_between_points( p_start, p) #...get our base distance _dist_to_hit = DIST.get_distance_between_points( p_start, _hit) #...get our base distance p_result = DIST.get_pos_by_vec_dist(p_start, _vector_to_hit, (_dist_base + _dist_to_hit)) #_cast = RayCast.cast(self.l_mesh, startPoint=_pos_obj,vector=_vec_obj) #_nearHit = _cast['near'] #_dist_firstHit = DIST.get_distance_between_points(_pos_obj,_nearHit) #log.debug("baseDist: {0}".format(_dist_base)) #log.debug("firstHit: {0}".format(_dist_firstHit)) """ if not _m_normal: if self.mode == 'far': _dist_new = _dist_base + _dist_firstHit else: _dist_new = _dist_base - _dist_firstHit _offsetPos = DIST.get_pos_by_vec_dist(_pos_obj,_vec_obj,(_dist_new)) else: log.debug("|{0}| >> mesh normal offset!".format(_str_funcName)) _offsetPos = DIST.get_pos_by_vec_dist(_pos_base,_m_normal,(_dist_firstHit))""" #cgmGEN.func_snapShot(vars()) POS.set(_obj, p_result) return POS.set(_obj, p) except Exception, err: cgmGEN.cgmExceptCB(Exception, err, msg=vars())
rotateValue) log.debug( mc.getAttr("%s.rotate%s" % (mi_rotObj.mNode, latheAxis.capitalize()))) #mi_rotObj.__setattr__('rotate%s'%latheAxis.capitalize(),rotateValue) try: log.debug("mesh: %s" % mesh) log.debug("mi_loc.mNode: %s" % mi_loc.mNode) log.debug("aimAxis: %s" % aimAxis) log.debug("latheAxis: %s" % latheAxis) log.debug("maxDistance: %s" % maxDistance) hit = RayCast.cast(mesh, mi_loc.mNode, aimAxis, offsetMode='vector', offsetDistance=vectorOffset, maxDistance=maxDistance).get('hit') if not hit: log.debug( cgmGEN.logString_msg( _str_func, "No hit, alternate method | {0}".format( rotateValue))) hit = DIST.get_pos_by_axis_dist(mi_loc.mNode, aimAxis, maxDistance) if hit: if DIST.get_distance_between_points(pos_base, hit) > maxDistance: log.debug("Max distance exceeded. Using alternative") hit = DIST.get_pos_by_axis_dist(