Exemplo n.º 1
0
def uiFunc_createLoc(self,selfMode = False):
    try:
        _d = uiQuery_advancedSnap(self)
        _sel = _d.pop('sl')
        if not _sel:
            return log.error("Nothing selected")
        
        if len(_sel) == 1:
            targets = None
        else:
            targets = _sel[1:]
            
        obj = _sel[0]
        _d['queryMode'] = True
        
        if selfMode:
            _d['objLoc'] = True
        else:
            _d['targetLoc'] = True
            
        #cgmGEN.func_snapShot(vars())
        SNAPCALLS.snap( obj,targets, **_d)
        
    except Exception,err:
        cgmGEN.cgmExceptCB(Exception,err)
Exemplo n.º 2
0
def uiFunc_snap(self):
    try:
        _d = uiQuery_advancedSnap(self)
        _sel = _d.pop('sl')
        if not _sel:
            return log.error("Nothing selected")
        
        if len(_sel) == 1:
            targets = None
        else:
            targets = _sel[1:]
        obj = _sel[0]
        SNAPCALLS.snap( obj,targets, **_d)
        
    except Exception,err:
        cgmGEN.cgmExceptCB(Exception,err)
Exemplo n.º 3
0
def resize_masterShape(self, sizeBy=None, resize=False):
    try:

        _short = self.p_nameShort
        _str_func = '[{0}] resize_masterShape'.format(_short)
        log.debug("|{0}| >> ".format(_str_func) + '-' * 80)
        _sel = mc.ls(sl=True)
        _bb = False
        _bb = self.baseSize

        if resize:
            if _sel:
                _bb = TRANS.bbSize_get(_sel, False)
            #elif self.getBlockChildren():
            #    sizeBy = mc.ls(self.getBlockChildren(asMeta=False))
            #    _bb = TRANS.bbSize_get(sizeBy,False)
            self.baseSize = _bb

        log.debug("|{0}| >> _bb: {1}".format(_str_func, _bb))

        mHandleFactory = self.asHandleFactory(_short)
        mc.delete(self.getShapes())

        _average = MATH.average([_bb[0], _bb[2]])
        _size = _average * 1.5
        _offsetSize = _average * .01
        _blockScale = self.blockScale
        mFormNull = self.atUtils('stateNull_verify', 'form')
        mNoTransformNull = self.atUtils('noTransformNull_verify', 'form')

        if resize or self.controlOffset == .9999:
            self.controlOffset = _offsetSize

        #Main curve ===========================================================================
        _crv = CURVES.create_fromName(name='circle', direction='y+', size=1)
        mCrv = cgmMeta.asMeta(_crv)
        SNAP.go(mCrv.mNode, self.mNode, rotation=False)
        TRANS.scale_to_boundingBox(mCrv.mNode, [_bb[0], None, _bb[2]])

        #mDup = mCrv.doDuplicate(po=False)
        #mDup.p_position = MATH.list_add(mDup.p_position, [0,_offsetSize,0])

        RIG.shapeParent_in_place(self.mNode, _crv, False)
        #RIG.shapeParent_in_place(self.mNode,mDup.mNode,False)

        mHandleFactory.color(self.mNode, 'center', 'main', transparent=False)

        #Bounding box ==================================================================
        if self.getMessage('bbHelper'):
            self.bbHelper.delete()

        _bb_shape = CURVES.create_controlCurve(self.mNode,
                                               'cubeOpen',
                                               size=1,
                                               sizeMode='fixed')
        _bb_newSize = MATH.list_mult(self.baseSize,
                                     [_blockScale, _blockScale, _blockScale])
        TRANS.scale_to_boundingBox(_bb_shape, _bb_newSize)
        mBBShape = cgmMeta.validateObjArg(_bb_shape,
                                          'cgmObject',
                                          setClass=True)
        mBBShape.p_parent = mFormNull

        mBBShape.inheritsTransform = False
        mc.parentConstraint(self.mNode, mBBShape.mNode, maintainOffset=False)

        SNAPCALLS.snap(mBBShape.mNode,
                       self.mNode,
                       objPivot='axisBox',
                       objMode='y-')

        CORERIG.copy_pivot(mBBShape.mNode, self.mNode)
        self.doConnectOut('baseSize', "{0}.scale".format(mBBShape.mNode))
        #mHandleFactory.color(mBBShape.mNode,controlType='sub')
        mBBShape.setAttrFlags()

        mBBShape.doStore('cgmName', self)
        mBBShape.doStore('cgmType', 'bbVisualize')
        mBBShape.doName()
        mBBShape.template = True
        self.connectChildNode(mBBShape.mNode, 'bbHelper')

        #Offset visualize ==================================================================
        if self.getMessage('offsetHelper'):
            self.offsetHelper.delete()

        #Need to guess our offset size based on bounding box volume

        mShape = self.getShapes(asMeta=True)[0]
        l_return = mc.offsetCurve(mShape.mNode, distance=1, ch=True)
        #pprint.pprint(l_return)
        mHandleFactory.color(l_return[0], 'center', 'sub', transparent=False)

        mOffsetShape = cgmMeta.validateObjArg(l_return[0],
                                              'cgmObject',
                                              setClass=True)
        mOffsetShape.p_parent = mNoTransformNull
        #mOffsetShape.doSnapTo(self)
        #mc.pointConstraint(self.mNode,mOffsetShape.mNode,maintainOffset=True)
        #mc.orientConstraint(self.mNode,mOffsetShape.mNode,maintainOffset=True)
        mOffsetShape.inheritsTransform = False

        mOffsetShape.dagLock()

        _arg = '{0}.distance = -{1}.controlOffset'.format(
            l_return[1], self.mNode)
        NODEFACTORY.argsToNodes(_arg).doBuild()
        #self.doConnectOut('controlOffset',"{0}.distance".format(l_return[1]))

        mOffsetShape.doStore('cgmName', self)
        mOffsetShape.doStore('cgmType', 'offsetVisualize')
        mOffsetShape.doName()

        self.connectChildNode(mOffsetShape.mNode, 'offsetHelper')

        return
        #Offset visualize ==================================================================
        if self.getMessage('offsetHelper'):
            self.offsetHelper.delete()

        mShape = self.getShapes(asMeta=True)[0]
        l_return = mc.offsetCurve(mShape.mNode, distance=1, ch=True)
        #pprint.pprint(l_return)
        mHandleFactory.color(l_return[0], 'center', 'sub', transparent=False)

        mOffsetShape = cgmMeta.validateObjArg(l_return[0],
                                              'cgmObject',
                                              setClass=True)
        mOffsetShape.p_parent = mFormNull

        mOffsetShape.inheritsTransform = False
        mc.parentConstraint(self.mNode,
                            mOffsetShape.mNode,
                            maintainOffset=False)

        #mOffsetShape.setAttrFlags()

        _arg = '{0}.distance = -{1}.controlOffset * {1}.blockScale'.format(
            l_return[1], self.mNode)
        NODEFACTORY.argsToNodes(_arg).doBuild()
        #self.doConnectOut('controlOffset',"{0}.distance".format(l_return[1]))

        mOffsetShape.doStore('cgmName', self)
        mOffsetShape.doStore('cgmType', 'offsetVisualize')
        mOffsetShape.doName()

        self.connectChildNode(mOffsetShape.mNode, 'offsetHelper')

        return

        _crv = CURVES.create_fromName(name='squareOpen',
                                      direction='y+',
                                      size=1)
        TRANS.scale_to_boundingBox(_crv, [_bb[0], None, _bb[2]])

        mHandleFactory.color(_crv, 'center', 'sub', transparent=False)

        mCrv = cgmMeta.validateObjArg(_crv, 'cgmObject')
        l_offsetCrvs = []
        for shape in mCrv.getShapes():
            offsetShape = mc.offsetCurve(shape, distance=-_offsetSize,
                                         ch=True)[0]
            mHandleFactory.color(offsetShape,
                                 'center',
                                 'main',
                                 transparent=False)
            l_offsetCrvs.append(offsetShape)

        RIG.combineShapes(l_offsetCrvs + [_crv], True)
        SNAP.go(_crv, self.mNode)

        RIG.shapeParent_in_place(self.mNode, _crv, True)

        self.baseSize = _bb

        #Bounding box ==================================================================
        if self.getMessage('offsetVisualize'):
            self.bbVisualize.delete()

        _bb_shape = CURVES.create_controlCurve(self.mNode,
                                               'cubeOpen',
                                               size=1.0,
                                               sizeMode='fixed')
        mBBShape = cgmMeta.validateObjArg(_bb_shape,
                                          'cgmObject',
                                          setClass=True)
        mBBShape.p_parent = mFormNull

        SNAPCALLS.snap(mBBShape.mNode,
                       self.mNode,
                       objPivot='axisBox',
                       objMode='y-')

        CORERIG.copy_pivot(mBBShape.mNode, self.mNode)
        self.doConnectOut('baseSize', "{0}.scale".format(mBBShape.mNode))
        mHandleFactory.color(mBBShape.mNode, controlType='sub')
        mBBShape.setAttrFlags()

        mBBShape.doStore('cgmName', self)
        mBBShape.doStore('cgmType', 'bbVisualize')
        mBBShape.doName()

        self.connectChildNode(mBBShape.mNode, 'bbHelper')

        return True

    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, localDat=vars())