Exemplo n.º 1
0
 def _shapeParent(self):
     shapeParentTo = self.d_kws['shapeParentTo']
     if shapeParentTo:
         try:
             i_target = cgmMeta.validateObjArg(shapeParentTo,
                                               cgmMeta.cgmObject)
             curves.parentShapeInPlace(i_target.mNode,
                                       self.mi_control.mNode)
             i_target = cgmMeta.asMeta(i_target,
                                       'cgmControl',
                                       setClass=True)
             #self.mi_control.delete()
             self.mi_control = i_target  #replace the control with the joint
         except Exception, error:
             raise StandardError, "shapeParentTo | %s" % error
Exemplo n.º 2
0
        def _shapeParent(self):		    
            shapeParentTo = self.d_kws['shapeParentTo']
            if shapeParentTo:
                try:
                    i_target = cgmMeta.validateObjArg(shapeParentTo,cgmMeta.cgmObject)
                    curves.parentShapeInPlace(i_target.mNode,self.mi_control.mNode)
                    i_target = cgmMeta.asMeta(i_target,'cgmControl',setClass = True)
                    #self.mi_control.delete()
                    self.mi_control = i_target#replace the control with the joint    
                except Exception,error:raise StandardError,"shapeParentTo | %s"%error

            useShape = self.d_kws['useShape']
            if useShape is not None:
                try:
                    i_shape = cgmMeta.validateObjArg(useShape,cgmMeta.cgmObject,mayaType='nurbsCurve')
                    curves.parentShapeInPlace(self.mi_control.mNode,i_shape.mNode)
                except Exception,error:raise StandardError,"useShape | %s"%error
Exemplo n.º 3
0
        def _copyTransform(self):		    
            copyTransform = self.d_kws['copyTransform']
            if copyTransform is not None:
                if issubclass(type(copyTransform),cgmMeta.cgmNode):
                    i_target = copyTransform
                elif mc.objExists(copyTransform):
                    i_target = cgmMeta.cgmObject(copyTransform)
                else:
                    raise StandardError,"Failed to find suitable copyTransform object: '%s"%copyTransform

                #Need to move this to default cgmNode stuff
                mBuffer = self.mi_control
                i_newTransform = cgmMeta.cgmObject( rigging.groupMeObject(i_target.mNode,False) )
                for a in mc.listAttr(self.mi_control.mNode, userDefined = True):
                    attributes.doCopyAttr(self.mi_control.mNode,a,i_newTransform.mNode)
                curves.parentShapeInPlace(i_newTransform.mNode,self.mi_control.mNode)#Parent shape
                i_newTransform.parent = self.mi_control.parent#Copy parent
                self.mi_control = cgmMeta.asMeta(i_newTransform,'cgmControl', setClass=True)
                mc.delete(mBuffer.mNode)
Exemplo n.º 4
0
        def _copyTransform(self):		    
            copyTransform = self.d_kws['copyTransform']
            if copyTransform is not None:
                if issubclass(type(copyTransform),cgmMeta.cgmNode):
                    i_target = copyTransform
                elif mc.objExists(copyTransform):
                    i_target = cgmMeta.cgmObject(copyTransform)
                else:
                    raise StandardError,"Failed to find suitable copyTransform object: '%s"%copyTransform

                #Need to move this to default cgmNode stuff
                mBuffer = self.mi_control
                i_newTransform = cgmMeta.cgmObject( rigging.groupMeObject(i_target.mNode,False) )
                for a in mc.listAttr(self.mi_control.mNode, userDefined = True):
                    attributes.doCopyAttr(self.mi_control.mNode,a,i_newTransform.mNode)
                curves.parentShapeInPlace(i_newTransform.mNode,self.mi_control.mNode)#Parent shape
                i_newTransform.parent = self.mi_control.parent#Copy parent
                self.mi_control = cgmMeta.asMeta(i_newTransform,'cgmControl', setClass=True)
                mc.delete(mBuffer.mNode)
def create(obj,parentTo = False):
    """   
    Create a spacePivot from a given object

    :parameters:
        *a(varied): - Uses validate_arg 

    :returns
        mSpacePivot(metaList)
    """ 
    _str_func = 'create'
    
    #....inital...
    i_obj = cgmMeta.validateObjArg(obj,cgmMeta.cgmObject,noneValid=False)    
    i_parent = cgmMeta.validateObjArg(parentTo,cgmMeta.cgmObject,noneValid=True)    
    bbSize = DIST.get_bb_size(i_obj.mNode)
    size = max(bbSize)

    #>>>Create #====================================================
    #CURVES.create_controlCurve(i_obj.mNode,'jack')
    i_control = cgmMeta.asMeta(CURVES.create_controlCurve(i_obj.mNode,'jack',sizeMode='guess')[0],'cgmObject',setClass=True)
    log.debug(i_control)
    try:l_color = curves.returnColorsFromCurve(i_obj.mNode)
    except Exception,error:raise Exception,"color | %s"%(error)          
    log.debug("l_color: %s"%l_color)
    curves.setColorByIndex(i_control.mNode,l_color[0])
    
    #>>>Snap and Lock
    #====================================================	
    #Snap.go(i_control,i_obj.mNode,move=True, orient = True)

    #>>>Copy Transform
    #====================================================   
    i_newTransform = i_obj.doCreateAt()

    #Need to move this to default cgmNode stuff
    mBuffer = i_control
    i_newTransform.doCopyNameTagsFromObject(i_control.mNode)
    curves.parentShapeInPlace(i_newTransform.mNode,i_control.mNode)#Parent shape
    i_newTransform.parent = mBuffer.parent#Copy parent
    i_control = i_newTransform
    mc.delete(mBuffer.mNode)
    
    #>>>Register
    #====================================================    
    #Attr
    i = ATTR.get_nextAvailableSequentialAttrIndex(i_obj.mNode,"pivot")
    str_pivotAttr = str("pivot_%s"%i)
    str_objName = str(i_obj.getShortName())
    str_pivotName = str(i_control.getShortName())
    
    #Build the network
    i_obj.addAttr(str_pivotAttr,enumName = 'off:lock:on', defaultValue = 2, value = 0, attrType = 'enum',keyable = False, hidden = False)
    i_control.overrideEnabled = 1
    d_ret = NodeF.argsToNodes("%s.overrideVisibility = if %s.%s > 0"%(str_pivotName,str_objName,str_pivotAttr)).doBuild()
    log.debug(d_ret)
    d_ret = NodeF.argsToNodes("%s.overrideDisplayType = if %s.%s == 2:0 else 2"%(str_pivotName,str_objName,str_pivotAttr)).doBuild()
    
    for shape in mc.listRelatives(i_control.mNode,shapes=True,fullPath=True):
        log.debug(shape)
        mc.connectAttr("%s.overrideVisibility"%i_control.mNode,"%s.overrideVisibility"%shape,force=True)
        mc.connectAttr("%s.overrideDisplayType"%i_control.mNode,"%s.overrideDisplayType"%shape,force=True)
    
    #Vis 
    #>>>Name stuff
    #====================================================
    cgmMeta.cgmAttr(i_control,'visibility',lock=True,hidden=True)   
    i_control = cgmMeta.validateObjArg(i_control,'cgmControl',setClass = True)
    i_control.doStore('cgmName',i_obj)
    i_control.addAttr('cgmType','controlAnim',lock=True)    
    i_control.addAttr('cgmIterator',"%s"%i,lock=True)        
    i_control.addAttr('cgmTypeModifier','spacePivot',lock=True)

    i_control.doName(nameShapes=True)

    i_control.addAttr('cgmAlias',(i_obj.getNameAlias()+'_pivot_%s'%i),lock=False)
    
    #Store on object
    #====================================================    
    i_obj.addAttr("spacePivots", attrType = 'message',lock=True)
    _l_spacePivots = i_obj.getMessage('spacePivots',True) or []
    if i_control.getLongName() not in _l_spacePivots:
        #_l_spacePivots = i_obj.getMessage('spacePivots',True)
        #_l_spacePivots.append(i_control.mNode)
        i_obj.msgList_append('spacePivots',i_control,'controlTarget')
    log.debug("spacePivots: %s"%i_obj.msgList_get('spacePivots',asMeta = True))

    #parent
    if i_parent:
        i_control.parent = i_parent.mNode
        i_constraintGroup = (cgmMeta.asMeta(i_control.doGroup(True),'cgmObject',setClass=True))
        i_constraintGroup.addAttr('cgmTypeModifier','constraint',lock=True)
        i_constraintGroup.doName()
        i_control.connectChildNode(i_constraintGroup,'constraintGroup','groupChild')	

        log.debug("constraintGroup: '%s'"%i_constraintGroup.getShortName())		

    #change to cgmControl
    i_control = cgmMeta.asMeta(i_control.mNode,'cgmControl', setClass=1)

    return i_control
Exemplo n.º 6
0
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}
Exemplo n.º 7
0
    class fncWrap(cgmGeneral.cgmFuncCls):
        def __init__(self, *args, **kws):
            """
            """
            super(fncWrap, self).__init__(*args, **kws)
            if args:
                self.mi_control = cgmMeta.validateObjArg(args[0],
                                                         cgmMeta.cgmObject,
                                                         noneValid=False)
            try:
                self._str_funcName = "registerControl(%s)" % self.mi_control.p_nameShort
            except:
                self._str_funcName = "registerControl"
            self._l_ARGS_KWS_DEFAULTS = [
                {
                    'kw': 'controlObject',
                    "default": None,
                    'help': "The object to use as a control",
                    "argType": "mObject"
                },
                {
                    'kw': 'copyTransform',
                    "default": None,
                    'help':
                    "Object to copy the transform of for our control object",
                    "argType": "mObject"
                },
                {
                    'kw': 'copyPivot',
                    "default": None,
                    'help':
                    "Object to copy the pivot of for our control object",
                    "argType": "mObject"
                },
                {
                    'kw': 'shapeParentTo',
                    "default": None,
                    'help':
                    "Object to shape parent our control curve to to use that transform",
                    "argType": "mObject"
                },
                {
                    'kw': 'useShape',
                    "default": None,
                    'help': "Object to use the curve shape of for our control",
                    "argType": "mObject"
                },
                {
                    'kw': 'setRotateOrder',
                    "default": None,
                    'help': "Argument for a rotate order to set",
                    "argType": "rotateOrder"
                },
                {
                    'kw': 'autoLockNHide',
                    "default": None,
                    'help': "Try to set lock and hide",
                    "argType": "bool"
                },
                {
                    'kw': 'mirrorAxis',
                    "default": None,
                    'help': "Mirror axis to set - using red9's setup terms",
                    "argType": "string"
                },
                {
                    'kw': 'mirrorSide',
                    "default": None,
                    'help': "Mirror side - using red9's setup terms",
                    "argType": "string/int"
                },
                {
                    'kw': 'makeMirrorable',
                    "default": True,
                    'help':
                    "Setup for mirrorability (using red9) -- implied by other mirror args",
                    "argType": "bool"
                },
                {
                    'kw': 'addDynParentGroup',
                    "default": False,
                    'help': "Add a dynParent group setup"
                },
                {
                    'kw': 'addExtraGroups',
                    "default": False,
                    'help': "Number of nested extra groups desired",
                    "argType": "int"
                },
                {
                    'kw': 'addConstraintGroup',
                    "default": False,
                    'help':
                    "If a group just above the control is desired for consraining",
                    "argType": "bool"
                },
                {
                    'kw': 'freezeAll',
                    "default": False,
                    'help': "Freeze all transforms on the control object",
                    "argType": "bool"
                },
                {
                    'kw': 'addSpacePivots',
                    "default": False,
                    'help': "Number of space pivots to generate and connect",
                    "argType": "int"
                },
                {
                    'kw': 'controlType',
                    "default": None,
                    'help': "Tag for cgmType",
                    "argType": "string"
                },
                {
                    'kw': 'typeModifier',
                    "default": None,
                    'help': "Tag for cgmTypeModifier for naming",
                    "argType": "string"
                },
                {
                    'kw': 'addForwardBack',
                    "default": None,
                    'help':
                    "Forward Back driver setup. Looking for an attribute to drive",
                    "argType": "mAttr"
                },
                {
                    'kw': 'addMirrorAttributeBridges',
                    "default": None,
                    'help':
                    "Attribute to drive the same channel on mirrored objects. Looking for an nested list [[attrName,attr],...]",
                    "argType": "nested list"
                },
                {
                    'kw': 'aim',
                    "default": None,
                    'help': "aim axis to use",
                    "argType": "string/int"
                },
                {
                    'kw': 'up',
                    "default": None,
                    'help': "up axis to use",
                    "argType": "string/int"
                },
                {
                    'kw': 'out',
                    "default": None,
                    'help': "out axis to use",
                    "argType": "string/int"
                },
                {
                    'kw': 'makeAimable',
                    "default": False,
                    'help': "Make object aimable -- implied by aim/up/out",
                    "argType": "mObject"
                },
            ]

            self.__dataBind__(*args, **kws)
            #=================================================================
            self.l_funcSteps = [{
                'step': 'validate',
                'call': self._validate
            }, {
                'step': 'Copy Transform',
                'call': self._copyTransform
            }, {
                'step': 'Shape Parent',
                'call': self._shapeParent
            }, {
                'step': 'Copy Pivot',
                'call': self._copyPivot
            }, {
                'step': 'Naming',
                'call': self._naming
            }, {
                'step': 'Aim Setup',
                'call': self._aimSetup
            }, {
                'step': 'Rotate Order',
                'call': self._rotateOrder
            }, {
                'step': 'Initial Freeze',
                'call': self._initialFreeze
            }, {
                'step': 'Groups Setup',
                'call': self._groupsSetup
            }, {
                'step': 'Space Pivot',
                'call': self._spacePivots
            }, {
                'step': 'Mirror Setup',
                'call': self._mirrorSetup
            }, {
                'step': 'Freeze',
                'call': self._freeze
            }, {
                'step': 'Mirror Attribute Bridges',
                'call': self._mirrorAttributeBridges_
            }, {
                'step': 'lock N Hide',
                'call': self._lockNHide
            }, {
                'step': 'Return build',
                'call': self._returnBuild
            }]

        def _validate(self):
            assert type(self.d_kws['addExtraGroups']) in [int, bool]
            assert type(self.d_kws['addSpacePivots']) in [int, bool]

            i_obj = self.mi_control
            self.mi_control = cgmMeta.asMeta(i_obj,
                                             'cgmControl',
                                             setClass=True)

            self.str_mirrorAxis = VALID.stringArg(
                self.d_kws['mirrorAxis'], calledFrom=self._str_funcCombined)
            self.str_mirrorSide = VALID.stringArg(
                self.d_kws['mirrorSide'], calledFrom=self._str_funcCombined)
            self.b_makeMirrorable = VALID.boolArg(
                self.d_kws['makeMirrorable'],
                calledFrom=self._str_funcCombined)

            self._addMirrorAttributeBridges = self.d_kws.get(
                'addMirrorAttributeBridges') or False
            if self._addMirrorAttributeBridges:
                if type(self._addMirrorAttributeBridges) not in [list, tuple]:
                    raise StandardError, "[Bad addMirrorAttributeBridge arg]{arg: %s}" % self._addMirrorAttributeBridge
                for i, l in enumerate(self._addMirrorAttributeBridges):
                    if type(l) not in [list, tuple]:
                        raise StandardError, "[Bad addMirrorAttributeBridge arg: %s]{arg: %s}" % (
                            i, l)
            # Running lists ------------------------------------------------------------------------------------------
            self.ml_groups = []  #Holder for groups
            self.ml_constraintGroups = []
            self.ml_spacePivots = []

        def _copyTransform(self):
            copyTransform = self.d_kws['copyTransform']
            if copyTransform is not None:
                if issubclass(type(copyTransform), cgmMeta.cgmNode):
                    i_target = copyTransform
                elif mc.objExists(copyTransform):
                    i_target = cgmMeta.cgmObject(copyTransform)
                else:
                    raise StandardError, "Failed to find suitable copyTransform object: '%s" % copyTransform

                #Need to move this to default cgmNode stuff
                mBuffer = self.mi_control
                i_newTransform = cgmMeta.cgmObject(
                    rigging.groupMeObject(i_target.mNode, False))
                for a in mc.listAttr(self.mi_control.mNode, userDefined=True):
                    attributes.doCopyAttr(self.mi_control.mNode, a,
                                          i_newTransform.mNode)
                curves.parentShapeInPlace(i_newTransform.mNode,
                                          self.mi_control.mNode)  #Parent shape
                i_newTransform.parent = self.mi_control.parent  #Copy parent
                self.mi_control = cgmMeta.asMeta(i_newTransform,
                                                 'cgmControl',
                                                 setClass=True)
                mc.delete(mBuffer.mNode)

        def _shapeParent(self):
            shapeParentTo = self.d_kws['shapeParentTo']
            if shapeParentTo:
                try:
                    i_target = cgmMeta.validateObjArg(shapeParentTo,
                                                      cgmMeta.cgmObject)
                    curves.parentShapeInPlace(i_target.mNode,
                                              self.mi_control.mNode)
                    i_target = cgmMeta.asMeta(i_target,
                                              'cgmControl',
                                              setClass=True)
                    #self.mi_control.delete()
                    self.mi_control = i_target  #replace the control with the joint
                except Exception, error:
                    raise StandardError, "shapeParentTo | %s" % error

            useShape = self.d_kws['useShape']
            if useShape is not None:
                try:
                    i_shape = cgmMeta.validateObjArg(useShape,
                                                     cgmMeta.cgmObject,
                                                     mayaType='nurbsCurve')
                    curves.parentShapeInPlace(self.mi_control.mNode,
                                              i_shape.mNode)
                except Exception, error:
                    raise StandardError, "useShape | %s" % error
Exemplo n.º 8
0
	    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}  
 
def createMeshSliceCurve(mesh, mi_obj,latheAxis = 'z',aimAxis = 'y+',
                         points = 12, curveDegree = 3, minRotate = None, maxRotate = None, rotateRange = None,
                         posOffset = 0, markHits = False,rotateBank = None, closedCurve = True, maxDistance = 1000,
                         initialRotate = 0, offsetMode = 'vector', midMeshCast = False,
                         l_specifiedRotates = None, closestInRange = True,