def locMeCVOnCurve(curveCV): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if search.returnObjectType(curveCV) == 'curveCV': cvPos = mc.pointPosition (curveCV,w=True) wantedName = (curveCV + '_loc') actualName = mc.spaceLocator (n= wantedName) mc.move (cvPos[0],cvPos[1],cvPos[2], [actualName[0]]) splitBuffer = curveCV.split('.') uPos = distance.returnClosestUPosition (actualName[0],splitBuffer[0]) mc.move (uPos[0],uPos[1],uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning ('Not a curveCV') return False
def locMeCvFromCvIndex(shape,cvIndex): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ cv = ('%s%s%i%s'%(shape,'.cv[',cvIndex,']')) if mc.objExists(cv): cvPos = mc.pointPosition (cv,w=True) wantedName = (cv + 'loc') actualName = mc.spaceLocator (n= wantedName) mc.move (cvPos[0],cvPos[1],cvPos[2], [actualName[0]]) uPos = distance.returnClosestUPosition (actualName[0],shape) mc.move (uPos[0],uPos[1],uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning ('Shape does not exist') return False
def __func__(self): """ """ self.mi_baseCurve = cgmMeta.validateObjArg(self.d_kws['baseCurve'],mayaType='nurbsCurve',noneValid=False) self._str_funcCombined = self._str_funcCombined + "(%s)"%self.mi_baseCurve.p_nameShort self.str_arg = cgmValid.stringArg(self.d_kws['arg'],noneValid=True) self.b_keepOriginal = cgmValid.boolArg(self.d_kws['keepOriginal'], calledFrom=self._str_funcCombined) if isEP(self.mi_baseCurve): log.warning("%s %s already an ep curve"%(self._str_reportStart,self.mi_baseCurve.p_nameShort)) return False mi_crv = self.mi_baseCurve if self.str_arg.lower() == 'ep': l_pos = [] for cv in mi_crv.getComponents('cv'): locatorName = locators.locMeObject(cv) pos = distance.returnClosestUPosition(locatorName,mi_crv.mNode) mc.delete(locatorName) l_pos.append( pos ) if not self.b_keepOriginal:mi_crv.delete() return mc.curve(d = 2,ep = l_pos, os = True) #return curves.curveFromPosList(l_pos) raise NotImplementedError,"arg: %s"%self.str_arg
def locMeCvFromCvIndex(shape, cvIndex): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ cv = ('%s%s%i%s' % (shape, '.cv[', cvIndex, ']')) if mc.objExists(cv): cvPos = mc.pointPosition(cv, w=True) wantedName = (cv + 'loc') actualName = mc.spaceLocator(n=wantedName) mc.move(cvPos[0], cvPos[1], cvPos[2], [actualName[0]]) uPos = distance.returnClosestUPosition(actualName[0], shape) mc.move(uPos[0], uPos[1], uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning('Shape does not exist') return False
def locMeCVOnCurve(curveCV): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places locators on the cv's closest position on a curve ARGUMENTS: curve(string) RETURNS: locList(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ if search.returnObjectType(curveCV) == 'curveCV': cvPos = mc.pointPosition(curveCV, w=True) wantedName = (curveCV + '_loc') actualName = mc.spaceLocator(n=wantedName) mc.move(cvPos[0], cvPos[1], cvPos[2], [actualName[0]]) splitBuffer = curveCV.split('.') uPos = distance.returnClosestUPosition(actualName[0], splitBuffer[0]) mc.move(uPos[0], uPos[1], uPos[2], [actualName[0]]) return actualName[0] else: guiFactory.warning('Not a curveCV') return False
def locMeClosestPointOnCurve(obj, curve): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places a locator on the closest point on a curve to the target object ARGUMENTS: obj(string) curve(string) RETURNS: locatorName(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ locatorName = locMeObject(obj) objTrans = distance.returnClosestUPosition(obj,curve) mc.move (objTrans[0],objTrans[1],objTrans[2], locatorName) return locatorName
def locMeClosestPointOnCurve(obj, curve): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Places a locator on the closest point on a curve to the target object ARGUMENTS: obj(string) curve(string) RETURNS: locatorName(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ locatorName = locMeObject(obj) objTrans = distance.returnClosestUPosition(obj, curve) mc.move(objTrans[0], objTrans[1], objTrans[2], locatorName) return locatorName
def skeletonize(moduleNull, stiffIndex=0): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Basic limb skeletonizer ARGUMENTS: moduleNull(string) stiffIndex(int) - the index of the template objects you want to not have roll joints For example, a value of -1 will let the chest portion of a spine segment be solid instead of having a roll segment. Default is '0' which will put roll joints in every segment RETURNS: limbJoints(list) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>>Get our info #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> partName = NameFactory.returnUniqueGeneratedName(moduleNull, ignore='cgmType') """ template null """ templateNull = modules.returnTemplateNull(moduleNull) templateNullData = attributes.returnUserAttrsToDict(templateNull) """ template object nulls """ templatePosObjectsInfoNull = modules.returnInfoTypeNull( moduleNull, 'templatePosObjects') templateControlObjectsNull = modules.returnInfoTypeNull( moduleNull, 'templateControlObjects') templatePosObjectsInfoData = attributes.returnUserAttrsToDict( templatePosObjectsInfoNull) templateControlObjectsData = attributes.returnUserAttrsToDict( templateControlObjectsNull) jointOrientation = modules.returnSettingsData('jointOrientation') moduleRootBuffer = modules.returnInfoNullObjects(moduleNull, 'templatePosObjects', types='templateRoot') moduleRoot = moduleRootBuffer[0] stiffIndex = templateNullData.get('stiffIndex') rollJoints = templateNullData.get('rollJoints') """ AutonameStuff """ divider = NameFactory.returnCGMDivider() skinJointsNull = modules.returnInfoTypeNull(moduleNull, 'skinJoints') templateObjects = [] coreNamesArray = [] #>>>TemplateInfo for key in templatePosObjectsInfoData.keys(): if (mc.attributeQuery(key, node=templatePosObjectsInfoNull, msg=True)) == True: templateObjects.append(templatePosObjectsInfoData[key]) coreNamesArray.append(key) posTemplateObjects = [] """ Get the positional template objects""" for obj in templateObjects: bufferList = obj.split(divider) if (typesDictionary.get('templateObject')) in bufferList: posTemplateObjects.append(obj + divider + typesDictionary.get('locator')) """put objects in order of closeness to root""" posTemplateObjects = distance.returnDistanceSortedList( moduleRoot, posTemplateObjects) curve = (templatePosObjectsInfoData['curve']) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Actually making the skeleton with consideration for roll joints and the stiffIndex! #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if stiffIndex == 0: """ If no roll joints """ limbJoints = joints.createJointsFromCurve(curve, partName, rollJoints) else: rolledJoints = joints.createJointsFromCurve(curve, partName, rollJoints) if rollJoints == 0: limbJoints = rolledJoints else: if stiffIndex < 0: """ Get our to delete number in a rolledJoints[-4:] format""" #searchIndex = (int('%s%s' %('-',(rollJoints+1)))*abs(stiffIndex)-1) searchIndex = (int('%s%s' % ('-', (rollJoints + 1))) * abs(stiffIndex)) toDelete = rolledJoints[searchIndex:] """ delete out the roll joints we don't want""" mc.delete(toDelete[0]) for name in toDelete: rolledJoints.remove(name) """ make our stiff joints """ jointPositions = [] if abs(stiffIndex) == 1: jointPositions.append( distance.returnClosestUPosition( posTemplateObjects[stiffIndex], curve)) else: for obj in posTemplateObjects[stiffIndex:]: jointPositions.append( distance.returnClosestUPosition(obj, curve)) stiffJoints = joints.createJointsFromPosListName( jointPositions, 'partName') """ connect em up """ mc.parent(stiffJoints[0], rolledJoints[-1]) limbJoints = [] for joint in rolledJoints: limbJoints.append(joint) for joint in stiffJoints: limbJoints.append(joint) else: """ if it's not negative, it's positive....""" searchIndex = ((rollJoints + 1) * abs(stiffIndex)) toDelete = rolledJoints[:searchIndex] toKeep = rolledJoints[searchIndex:] """ delete out the roll joints we don't want""" mc.parent(toKeep[0], world=True) mc.delete(toDelete[0]) for name in toDelete: rolledJoints.remove(name) """ make our stiff joints """ jointPositions = [] if abs(stiffIndex) == 1: jointPositions.append( distance.returnClosestUPosition( posTemplateObjects[stiffIndex - 1], curve)) else: for obj in posTemplateObjects[:stiffIndex]: jointPositions.append( distance.returnClosestUPosition(obj, curve)) stiffJoints = joints.createJointsFromPosListName( jointPositions, 'partName') """ connect em up """ mc.parent(rolledJoints[0], stiffJoints[-1]) limbJoints = [] for joint in stiffJoints: limbJoints.append(joint) for joint in rolledJoints: limbJoints.append(joint) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Naming #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ Copy naming information from template objects to the joints closest to them copy over a cgmNameModifier tag from the module first """ attributes.copyUserAttrs(moduleNull, limbJoints[0], attrsToCopy=['cgmNameModifier']) """ First we need to find our matches """ for obj in posTemplateObjects: closestJoint = distance.returnClosestObject(obj, limbJoints) transferObj = attributes.returnMessageObject(obj, 'cgmName') """Then we copy it""" attributes.copyUserAttrs( transferObj, closestJoint, attrsToCopy=['cgmNameModifier', 'cgmDirection', 'cgmName']) limbJointsBuffer = NameFactory.doRenameHeir(limbJoints[0]) limbJoints = [] limbJoints.append(limbJointsBuffer[0]) for joint in limbJointsBuffer[1]: limbJoints.append(joint) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Orientation #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> limbJoints = orientSegment(limbJoints, posTemplateObjects, jointOrientation) #>>> Set its radius and toggle axis visbility on #averageDistance = distance.returnAverageDistanceBetweenObjects (limbJoints) jointSize = ( distance.returnDistanceBetweenObjects(limbJoints[0], limbJoints[-1]) / 6) for jnt in limbJoints: mc.setAttr((jnt + '.radi'), jointSize * .2) #>>>>>>> TEMP joints.toggleJntLocalAxisDisplay(jnt) print 'to orientation' #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #>>> Storing data #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> skinJointsNull = modules.returnInfoTypeNull(moduleNull, 'skinJoints') skinJointsNullData = attributes.returnUserAttrsToList(skinJointsNull) existingSkinJoints = lists.removeMatchedIndexEntries( skinJointsNullData, 'cgm') print existingSkinJoints if len(existingSkinJoints) > 0: for entry in existingSkinJoints: attrBuffer = (skinJointsNull + '.' + entry[0]) print attrBuffer attributes.doDeleteAttr(skinJointsNull, entry[0]) for i in range(len(limbJoints)): buffer = ('%s%s' % ('joint_', i)) attributes.storeInfo(skinJointsNull, buffer, limbJoints[i]) return limbJoints
def createWrapControlShape( targetObjects, targetGeo=None, latheAxis='z', aimAxis='y+', objectUp='y+', points=8, curveDegree=1, insetMult=None, #Inset multiplier minRotate=None, maxRotate=None, posOffset=[], rootOffset=[], #offset root before cast rootRotate=None, joinMode=False, extendMode=None, closedCurve=True, l_specifiedRotates=None, maxDistance=1000, closestInRange=True, vectorOffset=None, midMeshCast=False, subSize=None, #For ball on loli for example rotateBank=None, joinHits=None, #keys to processed hits to see what to join axisToCheck=['x', 'y'], **kws): #'segment,radial,disc' """ This function lathes an axis of an object, shoot rays out the aim axis at the provided mesh and returning hits. it then uses this information to build a curve shape. :parameters: mesh(string) | Surface to cast at mi_obj(string/mObj) | our casting object latheAxis(str) | axis of the objec to lathe TODO: add validation aimAxis(str) | axis to shoot out of points(int) | how many points you want in the curve curveDegree(int) | specified degree minRotate(float) | let's you specify a valid range to shoot maxRotate(float) | let's you specify a valid range to shoot posOffset(vector) | transformational offset for the hit from a normalized locator at the hit. Oriented to the surface markHits(bool) | whether to keep the hit markers returnDict(bool) | whether you want all the infomation from the process. rotateBank (float) | let's you add a bank to the rotation object l_specifiedRotates(list of values) | specify where to shoot relative to an object. Ignores some other settings maxDistance(float) | max distance to cast rays closestInRange(bool) | True by default. If True, takes first hit. Else take the furthest away hit in range. :returns: Dict ------------------------------------------------------------------ 'source'(double3) | point from which we cast 'hit'(double3) | world space points | active during single return 'hits'(list) | world space points | active during multi return 'uv'(double2) | uv on surface of hit | only works for mesh surfaces :raises: Exception | if reached """ _str_func = "createWrapControlShape" log.debug(">> %s >> " % (_str_func) + "=" * 75) _joinModes = [] _extendMode = [] if type(targetObjects) not in [list, tuple]: targetObjects = [targetObjects] targetGeo = VALID.objStringList(targetGeo, calledFrom=_str_func) assert type(points) is int, "Points must be int: %s" % points assert type(curveDegree) is int, "Points must be int: %s" % points assert curveDegree > 0, "Curve degree must be greater than 1: %s" % curveDegree if posOffset is not None and len(posOffset) and len(posOffset) != 3: raise StandardError, "posOffset must be len(3): %s | len: %s" % ( posOffset, len(posOffset)) if rootOffset is not None and len(rootOffset) and len(rootOffset) != 3: raise StandardError, "rootOffset must be len(3): %s | len: %s" % ( rootOffset, len(rootOffset)) if rootRotate is not None and len(rootRotate) and len(rootRotate) != 3: raise StandardError, "rootRotate must be len(3): %s | len: %s" % ( rootRotate, len(rootRotate)) if extendMode in ['loliwrap', 'cylinder', 'disc'] and insetMult is None: insetMult = 1 for axis in ['x', 'y', 'z']: if axis in latheAxis.lower(): latheAxis = axis log.debug("targetObjects: %s" % targetObjects) if len(aimAxis) == 2: single_aimAxis = aimAxis[0] else: single_aimAxis = aimAxis mAxis_aim = VALID.simpleAxis(aimAxis) log.debug("Single aim: %s" % single_aimAxis) log.debug("createWrapControlShape>> midMeshCast: %s" % midMeshCast) log.debug("|{0}| >> extendMode: {1}".format(_str_func, extendMode)) #>> Info l_groupsBuffer = [] il_curvesToCombine = [] l_sliceReturns = [] #Need to do more to get a better size #>> Build curves #================================================================= #> Root curve # log.debug("RootRotate: %s" % rootRotate) mi_rootLoc = cgmMeta.cgmNode(targetObjects[0]).doLoc() if rootOffset: log.debug("rootOffset: %s" % rootOffset) mc.move(rootOffset[0], rootOffset[1], rootOffset[2], [mi_rootLoc.mNode], r=True, rpr=True, os=True, wd=True) if rootRotate is not None and len(rootRotate): log.debug("rootRotate: %s" % rootRotate) mc.rotate(rootRotate[0], rootRotate[1], rootRotate[2], [mi_rootLoc.mNode], os=True, r=True) #>> Root mi_rootLoc.doGroup() #Group to zero if extendMode == 'segment': log.debug("segment mode. Target len: %s" % len(targetObjects[1:])) if len(targetObjects) < 2: log.warning( "Segment build mode only works with two objects or more") else: if insetMult is not None: rootDistanceToMove = distance.returnDistanceBetweenObjects( targetObjects[0], targetObjects[1]) log.debug("rootDistanceToMove: %s" % rootDistanceToMove) mi_rootLoc.__setattr__('t%s' % latheAxis, rootDistanceToMove * insetMult) #mi_rootLoc.tz = (rootDistanceToMove*insetMult)#Offset it #Notes -- may need to play with up object for aim snapping #mi_upLoc = cgmMeta.cgmNode(targetObjects[0]).doLoc() #mi_upLoc.doGroup()#To zero objectUpVector = dictionary.returnStringToVectors(objectUp) log.debug("objectUpVector: %s" % objectUpVector) #mi_uploc for i, obj in enumerate(targetObjects[1:]): log.debug("i: %s" % i) #> End Curve mi_endLoc = cgmMeta.cgmNode(obj).doLoc() aimVector = dictionary.returnStringToVectors(latheAxis + '-') log.debug("segment aimback: %s" % aimVector) #Snap.go(mi_endLoc.mNode,mi_rootLoc.mNode,move=False,aim=True,aimVector=aimVector,upVector=objectUpVector) #Snap.go(mi_endLoc.mNode,mi_rootLoc.mNode,move=False,orient=True) SNAP.go(mi_endLoc.mNode, mi_rootLoc.mNode, position=False, rotation=True) mi_endLoc.doGroup() if i == len(targetObjects[1:]) - 1: if insetMult is not None: log.debug("segment insetMult: %s" % insetMult) distanceToMove = distance.returnDistanceBetweenObjects( targetObjects[-1], targetObjects[0]) log.debug("distanceToMove: %s" % distanceToMove) #mi_endLoc.tz = -(distanceToMove*insetMult)#Offset it mi_endLoc.__setattr__('t%s' % latheAxis, -(distanceToMove * insetMult)) log.debug("segment lathe: %s" % latheAxis) log.debug("segment aim: %s" % aimAxis) log.debug("segment rotateBank: %s" % rotateBank) d_endCastInfo = createMeshSliceCurve( targetGeo, mi_endLoc, midMeshCast=midMeshCast, curveDegree=curveDegree, latheAxis=latheAxis, aimAxis=aimAxis, posOffset=posOffset, points=points, returnDict=True, closedCurve=closedCurve, maxDistance=maxDistance, closestInRange=closestInRange, rotateBank=rotateBank, l_specifiedRotates=l_specifiedRotates, axisToCheck=axisToCheck) l_sliceReturns.append(d_endCastInfo) mi_end = cgmMeta.cgmObject(d_endCastInfo['curve']) il_curvesToCombine.append(mi_end) mc.delete(mi_endLoc.parent) #delete the loc elif extendMode == 'radial': log.debug("|{0}| >> radial...".format(_str_func)) d_handleInner = createMeshSliceCurve( targetGeo, mi_rootLoc, midMeshCast=midMeshCast, curveDegree=curveDegree, latheAxis=latheAxis, aimAxis=aimAxis, posOffset=0, points=points, returnDict=True, closedCurve=closedCurve, maxDistance=maxDistance, closestInRange=closestInRange, rotateBank=rotateBank, l_specifiedRotates=l_specifiedRotates, axisToCheck=axisToCheck) mi_buffer = cgmMeta.cgmObject(d_handleInner['curve']) #instance curve l_sliceReturns.append(d_handleInner) il_curvesToCombine.append(mi_buffer) elif extendMode == 'disc': log.debug("|{0}| >> disc...".format(_str_func)) d_size = returnBaseControlSize(mi_rootLoc, targetGeo, axis=[aimAxis]) #Get size #discOffset = d_size[ d_size.keys()[0]]*insetMult size = False l_absSize = [abs(i) for i in posOffset] if l_absSize: size = max(l_absSize) if not size: d_size = returnBaseControlSize(mi_rootLoc, targetGeo, axis=[aimAxis]) #Get size log.debug("d_size: %s" % d_size) size = d_size[d_size.keys()[0]] * insetMult discOffset = size log.debug("d_size: %s" % d_size) log.debug("discOffset is: %s" % discOffset) mi_rootLoc.__setattr__('t%s' % latheAxis, discOffset) if posOffset: tmp_posOffset = [ posOffset[0] * .5, posOffset[1] * .5, posOffset[2] * .5 ] d_handleInnerUp = createMeshSliceCurve( targetGeo, mi_rootLoc, curveDegree=curveDegree, midMeshCast=midMeshCast, latheAxis=latheAxis, aimAxis=aimAxis, posOffset=tmp_posOffset, points=points, returnDict=True, closedCurve=closedCurve, maxDistance=maxDistance, closestInRange=closestInRange, rotateBank=rotateBank, l_specifiedRotates=l_specifiedRotates, axisToCheck=axisToCheck) mi_buffer = cgmMeta.cgmObject( d_handleInnerUp['curve']) #instance curve l_sliceReturns.append(d_handleInnerUp) il_curvesToCombine.append(mi_buffer) mi_rootLoc.__setattr__('t%s' % latheAxis, -discOffset) d_handleInnerDown = createMeshSliceCurve( targetGeo, mi_rootLoc, curveDegree=curveDegree, midMeshCast=midMeshCast, latheAxis=latheAxis, aimAxis=aimAxis, posOffset=tmp_posOffset, points=points, returnDict=True, closedCurve=closedCurve, maxDistance=maxDistance, closestInRange=closestInRange, rotateBank=rotateBank, l_specifiedRotates=l_specifiedRotates, axisToCheck=axisToCheck) mi_buffer = cgmMeta.cgmObject( d_handleInnerDown['curve']) #instance curve l_sliceReturns.append(d_handleInnerDown) il_curvesToCombine.append(mi_buffer) mi_rootLoc.tz = 0 elif extendMode == 'cylinder': log.debug("|{0}| >> cylinder...".format(_str_func)) d_size = returnBaseControlSize(mi_rootLoc, targetGeo, axis=[aimAxis]) #Get size discOffset = d_size[d_size.keys()[0]] * insetMult log.debug("d_size: %s" % d_size) log.debug("discOffset is: %s" % discOffset) mi_rootLoc.__setattr__('t%s' % latheAxis, discOffset) d_handleInnerUp = createMeshSliceCurve( targetGeo, mi_rootLoc, curveDegree=curveDegree, midMeshCast=midMeshCast, latheAxis=latheAxis, aimAxis=aimAxis, posOffset=posOffset, points=points, returnDict=True, closedCurve=closedCurve, maxDistance=maxDistance, closestInRange=closestInRange, rotateBank=rotateBank, l_specifiedRotates=l_specifiedRotates, axisToCheck=axisToCheck) mi_buffer = cgmMeta.cgmObject( d_handleInnerUp['curve']) #instance curve l_sliceReturns.append(d_handleInnerUp) il_curvesToCombine.append(mi_buffer) mi_rootLoc.__setattr__('t%s' % latheAxis, 0) elif extendMode == 'loliwrap': log.debug("|{0}| >> lolipop...".format(_str_func)) #l_absSize = [abs(i) for i in posOffset] size = False #if l_absSize: #log.debug("l_absSize: %s"%l_absSize) #size = max(l_absSize)*1.25 if subSize is not None: size = subSize if not size: d_size = returnBaseControlSize(mi_rootLoc, targetGeo, axis=[aimAxis]) #Get size log.info("d_size: %s" % d_size) l_size = d_size[single_aimAxis] size = l_size / 3 log.info("loli size: %s" % size) i_ball = cgmMeta.cgmObject( curves.createControlCurve('sphere', size=size)) elif extendMode == 'endCap': log.debug("|{0}| >> endCap...".format(_str_func)) returnBuffer1 = createMeshSliceCurve( targetGeo, mi_rootLoc.mNode, aimAxis='{0}+'.format(latheAxis), latheAxis=objectUp[0], curveDegree=curveDegree, maxDistance=maxDistance, closestInRange=closestInRange, closedCurve=False, l_specifiedRotates=[-90, -60, -30, 0, 30, 60, 90], posOffset=posOffset) mi_rootLoc.rotate = [0, 0, 0] mi_rootLoc.__setattr__('r%s' % latheAxis, 90) returnBuffer2 = createMeshSliceCurve( targetGeo, mi_rootLoc.mNode, aimAxis='{0}+'.format(latheAxis), latheAxis=objectUp[0], curveDegree=curveDegree, maxDistance=maxDistance, closedCurve=False, closestInRange=closestInRange, l_specifiedRotates=[-90, -60, -30, 0, 30, 60, 90], posOffset=posOffset) l_sliceReturns.extend([returnBuffer1, returnBuffer2]) il_curvesToCombine.append(cgmMeta.cgmObject(returnBuffer1)) il_curvesToCombine.append(cgmMeta.cgmObject(returnBuffer2)) mi_rootLoc.rotate = [0, 0, 0] #Now cast our root since we needed to move it with segment mode before casting if extendMode == 'cylinder': log.debug("|{0}| >> cylinder move...".format(_str_func)) mi_rootLoc.__setattr__('t%s' % latheAxis, -discOffset) log.debug("|{0}| >> Rootcast...".format(_str_func)) d_rootCastInfo = createMeshSliceCurve( targetGeo, mi_rootLoc, curveDegree=curveDegree, minRotate=minRotate, maxRotate=maxRotate, latheAxis=latheAxis, midMeshCast=midMeshCast, aimAxis=aimAxis, posOffset=posOffset, points=points, vectorOffset=vectorOffset, returnDict=True, closedCurve=closedCurve, maxDistance=maxDistance, closestInRange=closestInRange, rotateBank=rotateBank, l_specifiedRotates=l_specifiedRotates, axisToCheck=axisToCheck) #d_rootCastInfo = createMeshSliceCurve(targetGeo,mi_rootLoc,**kws) log.debug("|{0}| >> Rootcast done".format(_str_func) + cgmGEN._str_subLine) if extendMode == 'disc': l_sliceReturns.insert(1, d_rootCastInfo) else: l_sliceReturns.insert(0, d_rootCastInfo) #Special loli stuff if extendMode == 'loliwrap': SNAP.go(i_ball.mNode, mi_rootLoc.mNode, True, True) #Snap to main object #log.debug("hitReturns: %s"%d_rootCastInfo['hitReturns']) #cgmGEN.walk_dat(d_rootCastInfo['hitReturns'],'hitReturns') mi_crv = cgmMeta.cgmObject(d_rootCastInfo['curve']) """ d_return = RayCast.findMeshIntersectionFromObjectAxis(targetGeo,mi_rootLoc.mNode,mAxis_aim.p_string) or {} if not d_return.get('hit'): log.info(d_return) raise ValueError,"No hit on loli check" pos = d_return.get('hit') dist = distance.returnDistanceBetweenPoints(i_ball.getPosition(),pos) * 2""" if vectorOffset is not None: dist = vectorOffset + subSize * 4 else: dist = max(posOffset) + subSize * 4 if '-' in aimAxis: distM = -dist else: distM = dist log.debug("distM: %s" % distM) #Move the ball pBuffer = i_ball.doGroup() i_ball.__setattr__('t%s' % single_aimAxis, distM) i_ball.parent = False mc.delete(pBuffer) uPos = distance.returnClosestUPosition(i_ball.mNode, mi_crv.mNode) SNAP.aim(i_ball.mNode, mi_rootLoc.mNode, aimAxis='z-') #if posOffset: #mc.move(posOffset[0]*3,posOffset[1]*3,posOffset[2]*3, [i_ball.mNode], r = True, rpr = True, os = True, wd = True) #Make the curve between the two mi_traceCrv = cgmMeta.cgmObject( mc.curve(degree=1, ep=[uPos, i_ball.getPosition()])) #Combine il_curvesToCombine.extend([i_ball, mi_traceCrv]) mi_root = cgmMeta.cgmObject(d_rootCastInfo['curve']) #instance curve il_curvesToCombine.append(mi_root) mc.delete(mi_rootLoc.parent) #delete the loc l_curvesToCombine = [mi_obj.mNode for mi_obj in il_curvesToCombine ] #Build our combine list before adding connectors log.debug("|{0}| >> processed: {1}".format( _str_func, d_rootCastInfo['processedHits'])) if joinMode and extendMode not in ['loliwrap', 'endCap' ] and len(l_sliceReturns) > 1: if joinHits: keys = d_rootCastInfo['processedHits'].keys() keys.sort() #goodDegrees = [] #for i,key in enumerate(keys): #if i in joinHits: #goodDegrees.append(key) goodDegrees = [key for i, key in enumerate(keys) if i in joinHits] log.debug("joinHits: %s" % joinHits) log.debug("goodDegrees: %s" % goodDegrees) else: goodDegrees = [ key for key in d_rootCastInfo['processedHits'].keys() ] #> Side Curves for degree in goodDegrees: l_pos = [] for d in l_sliceReturns: l_pos.append(d['processedHits'].get(degree) or False) while False in l_pos: l_pos.remove(False) log.debug("l_pos: %s" % l_pos) if len(l_pos) >= 2: try: l_curvesToCombine.append( mc.curve(d=curveDegree, ep=l_pos, os=True)) #Make the curve except: log.debug( "createWrapControlShape>>> skipping curve fail: %s" % (degree)) #>>Combine the curves newCurve = curves.combineCurves(l_curvesToCombine) mi_crv = cgmMeta.cgmObject(rigging.groupMeObject(targetObjects[0], False)) curves.parentShapeInPlace(mi_crv.mNode, newCurve) #Parent shape mc.delete(newCurve) #>>Copy tags and name mi_crv.doCopyNameTagsFromObject(targetObjects[0], ignore=['cgmType', 'cgmTypeModifier']) mi_crv.addAttr('cgmType', attrType='string', value='controlCurve', lock=True) mi_crv.doName() #Store for return return {'curve': mi_crv.mNode, 'instance': mi_crv}
#Pos data pos = distance.returnWorldSpacePosition("%s"%distance.returnMidU(mi_crv.mNode)) dist = distance.returnDistanceBetweenPoints(i_ball.getPosition(),pos) if '-' in aimAxis: distM = -dist else: distM = dist log.debug("distM: %s"%distM) #Move the ball pBuffer = i_ball.doGroup() i_ball.__setattr__('t%s'%single_aimAxis,distM) i_ball.parent = False mc.delete(pBuffer) uPos = distance.returnClosestUPosition(i_ball.mNode,mi_crv.mNode) Snap.go(i_ball.mNode,mi_rootLoc.mNode,move = False, orient = False, aim=True, aimVector=[0,0,-1]) if posOffset: mc.move(posOffset[0]*3,posOffset[1]*3,posOffset[2]*3, [i_ball.mNode], r = True, rpr = True, os = True, wd = True) #Make the curve between the two mi_traceCrv = cgmMeta.cgmObject( mc.curve(degree = 1, ep = [uPos,i_ball.getPosition()]) ) #Combine il_curvesToCombine.extend([i_ball,mi_traceCrv]) mi_root = cgmMeta.cgmObject(d_rootCastInfo['curve'])#instance curve il_curvesToCombine.append(mi_root) mc.delete(mi_rootLoc.parent)#delete the loc
def getCurveMirrorData(self,mi_crv): d_return = {} d_return['f_bbMin'] = mi_crv.boundingBoxMin[self.int_across] d_return['f_bbMax'] = mi_crv.boundingBoxMax[self.int_across] d_return['b_oneSided'] = False d_return['b_balanced'] = False d_return['b_weighted'] = None #> First see our push direction ---------------------------------------------------------- try: if cgmMath.isFloatEquivalent( d_return['f_bbMax'], d_return['f_bbMin']): d_return['b_balanced'] = 1 if d_return['f_bbMax'] > d_return['f_bbMin']: d_return['b_weighted'] = 1 elif d_return['f_bbMax'] < d_return['f_bbMin']: d_return['b_weighted'] = -1 except Exception,error:raise StandardError,"Push direction check | %s"%error #> Check thresholds ---------------------------------------------------------------------- try: if -d_return['f_bbMin'] <= self.f_threshold and d_return['f_bbMax'] >= self.f_threshold or d_return['f_bbMin'] <= -self.f_threshold and d_return['f_bbMax'] <= -self.f_threshold: d_return['b_oneSided'] = True """if abs(d_return['f_bbMin']) <= self.f_threshold or abs(d_return['f_bbMax']) <= self.f_threshold: d_return['b_oneSided'] = True""" except Exception,error:raise StandardError,"Threshholds check | %s"%error #> Is ep -------------------------------------------------------------------- try: d_return['b_epState'] = isEP(mi_crv) except Exception,error:raise StandardError,"ep check | %s"%error #> Get positions ------------------------------------------------------------------------- try: l_cvs = mi_crv.getComponents('cv') l_cvPos = [] l_epPos = [] if d_return['b_epState']: for ep in mi_crv.getComponents('ep'): pos = mc.pointPosition(ep,w=True) l_epPos.append( pos ) for cv in l_cvs: l_cvPos.append( mc.pointPosition(cv,w=True) ) else: for cv in l_cvs: l_cvPos.append( mc.pointPosition(cv,w=True) ) #Get an ep value locatorName = locators.locMeObject(cv) pos = distance.returnClosestUPosition(locatorName,mi_crv.mNode) mc.delete(locatorName) l_epPos.append( pos ) d_return['l_cvPos'] = l_cvPos d_return['l_epPos'] = l_epPos d_return['l_cvs'] = l_cvs except Exception,error:raise StandardError,"Get positions | %s"%error #> Is even -------------------------------------------------------------------- try: if len(l_cvs)%2==0:#even d_return['b_even'] = True else: d_return['b_even'] = False except Exception,error:"Even check | %s"%error #> Which end is bigger try: if abs(l_cvPos[0][self.int_across]) <= self.f_threshold: d_return['b_startInThreshold'] = True else:d_return['b_startInThreshold'] = False if abs(l_cvPos[-1][self.int_across]) <= self.f_threshold: d_return['b_endInThreshold'] = True else:d_return['b_endInThreshold'] = False except Exception,error:raise StandardError,"End check | %s"%error return d_return