Beispiel #1
0
    def getlimiteTranslateValue( self , axeDir , limiteRotValues , origTrsWorld , targetTrs ):

        # axe dir 
        signDir = 1
        if( 2 < axeDir ):
            signDir = -1
            axeDir -= 3         
        
        # axe dir       
        
        trsObj   = trsClass.trsClass()        
        distance = trsObj.toDistance( targetTrs , inTrsValue = origTrsWorld ) 
        
        # CONVERT TO ROT LIMIT
        limitRot = []      
        for i in range(0,3):
            rotationValue    = [0,0,0]
            rotationValue[i] = limiteRotValues[i]
            limitRot.append( rotationValue )       
        
        # CONVERT ROT TO TRANSLATE LIMIT        
        axeLimites = [ 0 , 2 , 1 ]
        
        limitCoords = [0,0,0]
        offsetTrsRotate    = [0,0,0,0,0,0,1,1,1]
        offsetTrsTranslate = [0,0,0,0,0,0,1,1,1]
        offsetTrsTranslate[axeDir] = distance * signDir
        
        for i in range( 0 , 3 ):
            offsetTrsRotate[3:6] = limitRot[i]
            trsObj.offsetItself( offsetTrsRotate , inTrsValue = origTrsWorld )
            trsObj.offsetItself( offsetTrsTranslate )            
            limitCoords[i] = ( trsObj.value[0:3] )   

        return limitCoords
Beispiel #2
0
    def getReflectVector( self , vector , planeCoords , collisionWeight ):
        
        vectorReset = [ planeCoords[0][0] * -1 , planeCoords[0][1] * -1 , planeCoords[0][2] * -1 ]
        
        for i in range( 0 , 3 ):
            for j in range( 0 , 3 ):
                planeCoords[i][j] += vectorReset[j]
        
        
        
        trsObj  = trsClass.trsClass()
        trsObj.value = vector + [0,0,0,1,1,1]
        trsObj.mirror( planeCoords )
        
        trsObj * collisionWeight
        
        reflectVector = trsObj.value[0:3]

        
        return reflectVector
Beispiel #3
0
    def compute( self, plug , dataBlock ):
      
    	outsAttr = [ self.outputXAttr , self.outputYAttr , self.outputZAttr  ]                    
        if not ( plug in outsAttr ):
            return om.kUnknownParameter                    
        #_____________________________________________________________________________________ IN   


        dataHandle     = dataBlock.inputValue( self.inputTimeAttr )
        intime         = dataHandle.asFloat()           

        dataHandle     = dataBlock.inputValue( self.input1Attr )
        activate       = dataHandle.asFloat()         
        
        dataHandle       = dataBlock.inputValue( self.input2Attr )
        leadMFloatMatrix = dataHandle.asFloatMatrix()
        leadMatrix       = MMatrixToNum(leadMFloatMatrix) 

        dataHandle       = dataBlock.inputValue( self.input3Attr )
        worldMFloatMatrix = dataHandle.asFloatMatrix()
        worldMatrix       = MMatrixToNum(worldMFloatMatrix) 
        
        dataHandle     = dataBlock.inputValue( self.input4Attr )
        mass           = dataHandle.asFloat()           
                         
        dataHandle     = dataBlock.inputValue( self.input5Attr )
        elasticity     = dataHandle.asFloat()
                        
        dataHandle     = dataBlock.inputValue( self.input6Attr )
        damping        = dataHandle.asFloat()   
        
        dataHandle     = dataBlock.inputValue( self.input7Attr )
        collision      = dataHandle.asFloat()     

        dataHandle        = dataBlock.inputValue( self.input8Attr )
        self.minRotValues = dataHandle.asFloat3()           
        self.minRotValues = [ self.minRotValues[0] , self.minRotValues[1] , self.minRotValues[2] ]          
        
        dataHandle        = dataBlock.inputValue( self.input9Attr )
        self.maxRotValues = dataHandle.asFloat3() 
        self.maxRotValues = [ self.maxRotValues[0] , self.maxRotValues[1] , self.maxRotValues[2] ]  
        
        dataHandle     = dataBlock.inputValue( self.input10Attr )           
        distance       = dataHandle.asFloat()           
                
        dataHandle     = dataBlock.inputValue( self.input11Attr )
        self.nbrEval   = dataHandle.asFloat()
        
        dataHandle     = dataBlock.inputValue( self.input12Attr ) 
        self.lastTime  = dataHandle.asFloat()                    
  
        dataHandle     = dataBlock.inputValue( self.input13Attr )
        self.lastSpeed = dataHandle.asFloat3()
        self.lastSpeed = [ self.lastSpeed[0] , self.lastSpeed[1] , self.lastSpeed[2] ]      
        
        dataHandle     = dataBlock.inputValue( self.input14Attr )           
        self.slaveValue= dataHandle.asFloat3()          
        self.slaveValue= [ self.slaveValue[0] , self.slaveValue[1] , self.slaveValue[2] ]             
        
        dataHandle     = dataBlock.inputValue( self.input15Attr )           
        axeDirWay      = dataHandle.asInt()  
        
        dataHandle     = dataBlock.inputValue( self.input16Attr )
        ctrlTranslate  = dataHandle.asFloat3()           
        
        dataHandle     = dataBlock.inputValue( self.input17Attr )
        ctrlRotate     = dataHandle.asFloat3()  

        dataHandle     = dataBlock.inputValue( self.input18Attr )
        ctrlScale      = dataHandle.asFloat3()  
        
        dataHandle     = dataBlock.inputValue( self.input19Attr )
        follow         = dataHandle.asFloat()             
        
        #_____________________________________________________________________________________COMPUTE
        trsObj = trsClass.trsClass() 
        
        #_______________ SIGN AXE         
        signDir = 1
        axeDir  = axeDirWay
        if( 2 < axeDir ):
            signDir = -1
            axeDir -= 3 
            
        #_______________ DELTA TIME        
        incrEval      = 0.04
        self.nbrEval += incrEval
        
        curTime       = self.nbrEval       
        deltaTime     = curTime - self.lastTime         
        self.lastTime = curTime 
        
        #_______________ TRS       
        origTrsWorld  = trsObj.createFromFloatMatrix( worldMatrix ) 
        
        ctrlTrsLocal  = [ ctrlTranslate[0] , ctrlTranslate[1] , ctrlTranslate[2] , ctrlRotate[0] , ctrlRotate[1] , ctrlRotate[2] , ctrlScale[0] , ctrlScale[1] , ctrlScale[2] ]
        ctrlTrsWorld  = trsObj.unParent( origTrsWorld , inTrsValue = ctrlTrsLocal  ) 
        
        ctrlTrsLocalClamped = ctrlTrsLocal[:]
        if not( collision == 0 ):
            for i in range(0,3):
                if not( i == axeDir ):
                    ctrlTrsLocalClamped[i+3] = max( min( ctrlTrsLocal[i+3] , self.maxRotValues[i] ), self.minRotValues[i] )        
                    
        ctrlTrsWorldClamped = trsObj.unParent( origTrsWorld , inTrsValue = ctrlTrsLocalClamped )

        offsetTrsBase         = [0,0,0,0,0,0,1,1,1]
        offsetTrsBase[axeDir] = distance * signDir           
        ctrlOffsetTrs         = trsObj.offsetItself( offsetTrsBase , inTrsValue = ctrlTrsWorldClamped  )  
        
        #_______________ DYNAMIC       
        curentFrame   = mc.currentTime( query = True )
        startFrame    = mc.playbackOptions( query = True , minTime = True )

        if( activate == 0 ) or ( curentFrame == startFrame ):
            
            self.nbrEval        = 0
            self.lastTime       = 0
            self.lastSpeed      = [ 0 , 0 , 0 ]       
            self.slaveValue     = ctrlOffsetTrs[0:3]
            self.leadCollision  = None 
            angleOut = self.angleCompute( axeDirWay , ctrlTrsWorld , ctrlOffsetTrs , self.slaveValue )
            
        else: 
                        
            # DYNAMIC
            for i in range( 0 , 3 ):
                self.slaveValue[i] , self.lastSpeed[i] = self.computeDynamic( ctrlOffsetTrs[i] , self.slaveValue[i] , self.lastSpeed[i] , mass , elasticity , damping , deltaTime )         

            # FOLLOW SYS                       
            if not( follow == 0 ):
                vToTarget       = ompy.MVector( self.slaveValue[0] - ctrlTrsWorldClamped[0] , self.slaveValue[1] - ctrlTrsWorldClamped[1] , self.slaveValue[2] - ctrlTrsWorldClamped[2] )               
                vFollow         = vToTarget * ( distance / vToTarget.length() )
                self.slaveValue = [ ctrlTrsWorldClamped[0] + vFollow.x , ctrlTrsWorldClamped[1] + vFollow.y , ctrlTrsWorldClamped[2] + vFollow.z ]
                
            # COLLISION           
            allAxesLimites    = [ [ 0 ,  2 , 1 ] , [ 2 , 1 ,  0 ] , [  1 , 0 , 2 ] ] 
            axeLimites        = allAxesLimites[axeDir]           
           
            if not( collision == 0 ):
                                    
                ctrlTrsWorldOrigOrient = ctrlTrsWorld[0:3] + origTrsWorld[3:6] + ctrlTrsWorld[6:9]              
                origOffsetTrs          = trsObj.offsetItself( offsetTrsBase , inTrsValue = ctrlTrsWorldOrigOrient   )               
                angleOutCollision      = self.angleCompute( axeDirWay , ctrlTrsWorldOrigOrient , origOffsetTrs , self.slaveValue+[0,0,0,1,1,1] )
                                
                # RECOMPUTE NEXT DYN:   slaveValue   lastSpeed 
                                        
                for i in range(0,3):
                    
                    if( i == axeDir ):
                        continue
                    
                    if( self.minRotValues[i] == 0 ) and ( self.maxRotValues[i] == 0 ):
                        planeCoords     = trsObj.toPlaneCoords( axeNormal = axeLimites[i] , inTrsValue = ctrlTrsWorldOrigOrient )
                        self.slaveValue = trsObj.snapOnPlane( planeCoords , inTrsValue = self.slaveValue+[0,0,0,1,1,1] )   
                        continue
                        
                    if( angleOutCollision[i] < self.minRotValues[i] ) or ( self.maxRotValues[i] < angleOutCollision[i] ):
                                         
                        if( angleOutCollision[i] < self.minRotValues[i] ):
                            limitRotValue = self.minRotValues 
                        elif( self.maxRotValues[i] < angleOutCollision[i] ):
                            limitRotValue = self.maxRotValues         
                                                
                        # plane coord corresponding to the limit
                
                        offsetTrsBase      = [0,0,0,0,0,0,1,1,1]
                        offsetTrsBase[i+3] = limitRotValue[i]                      
                        trsObj.offsetItself( offsetTrsBase , inTrsValue = ctrlTrsWorldOrigOrient  ) 
                        planeCoords      = trsObj.toPlaneCoords( axeNormal = axeLimites[i] )
                       
                        #slaveValue                               
                        self.slaveValue   = trsObj.snapOnPlane( planeCoords , inTrsValue = self.slaveValue+[0,0,0,1,1,1] )   
                        
                        #lastSpeed                       
                        mVectorA      = ompy.MVector( planeCoords[1][0] - planeCoords[0][0]  , planeCoords[1][1] - planeCoords[0][1]  , planeCoords[1][2] - planeCoords[0][2]  )
                        mVectorB      = ompy.MVector( planeCoords[2][0] - planeCoords[0][0]  , planeCoords[2][1] - planeCoords[0][1]  , planeCoords[2][2] - planeCoords[0][2]  )
                        mVectorMoyen  = ompy.MVector( origOffsetTrs[0]  - self.slaveValue[0] , origOffsetTrs[1]  - self.slaveValue[1] , origOffsetTrs[2]  - self.slaveValue[2] )
                        mVectorNormal = utilsMayaApi.get2VectorsNormal( mVectorA , mVectorB , mVectorMoyen )
                        
                        mlastSpeed    = ompy.MVector( self.lastSpeed[0] , self.lastSpeed[1] , self.lastSpeed[2] )                          
                                               
                        if( mVectorNormal * mlastSpeed < 0 ):
                            self.lastSpeed = self.getReflectVector( self.lastSpeed , planeCoords , collision )
                                          
               

            # OUT ANGLE  
            angleOut = self.angleCompute( axeDirWay , ctrlTrsWorld , ctrlOffsetTrs , self.slaveValue ) 
            
            angleOut = [ activate * angleOut[0] , activate * angleOut[1] , activate * angleOut[2] ]
            

        
        #_____________________________________________________________________________________ OUT

        
        
        nodeName = self.name()  
        mc.undoInfo( swf = 0 )
        mc.setAttr( nodeName +'.nbrEval'    , self.nbrEval    )
        mc.setAttr( nodeName +'.lastTime'   , self.lastTime   )       
        mc.setAttr( nodeName +'.lastSpeed'  ,  self.lastSpeed[0] ,  self.lastSpeed[1] ,  self.lastSpeed[2] , type = 'double3')            
        mc.setAttr( nodeName +'.slaveValue' , self.slaveValue[0] , self.slaveValue[1] , self.slaveValue[2] , type = 'double3')                        
        mc.undoInfo( swf = 1 )
    
        output     = angleOut[0]               
        dataHandle = dataBlock.outputValue( self.outputXAttr )       
        dataHandle.setFloat( output )
        
        output     = angleOut[1]               
        dataHandle = dataBlock.outputValue( self.outputYAttr )       
        dataHandle.setFloat( output )

        output     = angleOut[2]           
        dataHandle = dataBlock.outputValue( self.outputZAttr )      
        dataHandle.setFloat( output )

        
        dataBlock.setClean( plug ) 
Beispiel #4
0
    def compute( self, plug , dataBlock ):  
            
    	outsAttr = [ self.outputTXAttr , self.outputTYAttr , self.outputTZAttr , self.outputRXAttr , self.outputRYAttr , self.outputRZAttr , self.outputSXAttr , self.outputSYAttr , self.outputSZAttr ]                    
        if not ( plug in outsAttr ):
            return om.kUnknownParameter                        
        #_____________________________________________________________________________________ IN   
        intime           = utils.nodeAttrToFloat(           dataBlock , self.attrInTime  )          
        activate         = utils.nodeAttrToFloat(           dataBlock , self.attrInActivate  )                 
        worldMatrix      = utils.nodeAttrToMatrixFloatList( dataBlock , self.attrInMatrix  )   
        mass             = utils.nodeAttrToFloat(           dataBlock , self.attrInMass  )            
        elasticity       = utils.nodeAttrToFloat(           dataBlock , self.attrInElasticity  ) 
        damping          = utils.nodeAttrToFloat(           dataBlock , self.attrInDamping  ) 
        collision        = utils.nodeAttrToFloat(           dataBlock , self.attrInCollision  ) 
        collisionMatrix  = utils.nodeAttrToMatrixFloatList( dataBlock , self.attrInCollisionMatrix  )        
        hitSphereSize    = utils.nodeAttrToFloat(           dataBlock , self.attrInCollisionSphereSize  )         
        fatherMatrix     = utils.nodeAttrToMatrixFloatList( dataBlock , self.attrInMatrixFather  )  
        self.nbrEval     = utils.nodeAttrToFloat(           dataBlock , self.attrInNbrEval  )         
        self.lastTime    = utils.nodeAttrToFloat(           dataBlock , self.attrInLastTime  )               
        self.lastSpeedT  = utils.nodeAttrToFloat3(          dataBlock , self.attrInLastSpeedT  )                                            
        self.lastSpeedR  = utils.nodeAttrToFloat3(          dataBlock , self.attrInLastSpeedR  )      
        self.lastSpeedS  = utils.nodeAttrToFloat3(          dataBlock , self.attrInLastSpeedS  )      
        self.slaveTValue = utils.nodeAttrToFloat3(          dataBlock , self.attrInSlaveT  )   
        self.slaveRValue = utils.nodeAttrToFloat3(          dataBlock , self.attrInSlaveR  )          
        self.slaveSValue = utils.nodeAttrToFloat3(          dataBlock , self.attrInSlaveS  )                 
        axeDirWay        = utils.nodeAttrToInt(             dataBlock , self.attrInAxeDir  )        
        
        #_____________________________________________________________________________________COMPUTE
        #_______________ DELTA TIME        
        incrEval      = 0.04
        self.nbrEval += incrEval
        
        curTime       = self.nbrEval       
        deltaTime     = curTime - self.lastTime         
        self.lastTime = curTime 
        
        #_______________ TRS  
        trsObj = trsClass.trsClass()              
        initTrsWorld  = trsObj.createFromFloatMatrix( worldMatrix ) 
        
        # COLLISION INIT       
        leadTrsWorld = initTrsWorld 
        
        if not( collision == 0 ):
                        
            # get vector normal + plane coords
            axeNormal = 0
            trsObj.createFromFloatMatrix( collisionMatrix )
        
            vectorNormal  = trsObj.toTripleVectors()[axeNormal]
            mVectorNormal = ompy.MVector( vectorNormal[0] , vectorNormal[1] , vectorNormal[2] ) 
            mVectorNormal.normalize()
            vContact = mVectorNormal * hitSphereSize            
            
            planeCoords   = trsObj.toPlaneCoords( axeNormal )             
                                
            # RECOMPUTE LEAD : leadTrsWorld
            snapOnPlane    = trsObj.snapOnPlane( planeCoords , inTrsValue = initTrsWorld )               
            vSnapInit      = ompy.MVector( initTrsWorld[0]   - snapOnPlane[0] , initTrsWorld[1]   - snapOnPlane[1] , initTrsWorld[2]   - snapOnPlane[2] )
            
            if( vSnapInit.length() <= hitSphereSize ) or ( mVectorNormal * vSnapInit <= 0 ):
                leadTrsWorld = [ snapOnPlane[0] + vContact.x , snapOnPlane[1] + vContact.y , snapOnPlane[2] + vContact.z ] + leadTrsWorld[3:9]        

        
        #_______________ DYNAMIC       
        curentFrame   = mc.currentTime( query = True )
        startFrame    = mc.playbackOptions( query = True , minTime = True )

        if( activate == 0 ) or ( curentFrame == startFrame ):
            
            self.nbrEval        = 0
            self.lastTime       = 0  
            
            self.slaveTValue    = leadTrsWorld[0:3]                  
            self.slaveRValue    = leadTrsWorld[3:6]    
            self.slaveSValue    = leadTrsWorld[6:9] 
            
            self.lastSpeedT = [0,0,0]
            self.lastSpeedR = [0,0,0]
            self.lastSpeedS = [0,0,0]
            
            self.slaveValue = self.slaveTValue + self.slaveRValue + self.slaveSValue
            self.lastSpeed  = self.lastSpeedT + self.lastSpeedR + self.lastSpeedS            
            trsOut          = leadTrsWorld
            
        else: 
                        
            # DYNAMIC
            self.slaveValue = self.slaveTValue + self.slaveRValue + self.slaveSValue
            self.lastSpeed  = self.lastSpeedT + self.lastSpeedR + self.lastSpeedS
            
            for i in range( 0 , 9 ):
                self.slaveValue[i] , self.lastSpeed[i] = self.computeDynamic( leadTrsWorld[i] , self.slaveValue[i] , self.lastSpeed[i] , mass , elasticity , damping , deltaTime )   
                           
                        
            # activate modulation
            for i in range( 0 , 9 ):            	
            	self.slaveValue[i] =  self.slaveValue[i] * activate + leadTrsWorld[i] * ( 1 - activate )
            	
            # out
            
            self.slaveTValue = self.slaveValue[0:3]                  
            self.slaveRValue = self.slaveValue[3:6]    
            self.slaveSValue = self.slaveValue[6:9]
            
            self.lastSpeedT = self.lastSpeed[0:3]
            self.lastSpeedR = self.lastSpeed[3:6]
            self.lastSpeedS = self.lastSpeed[6:9]
            
            # COLLISION                   
           
            if not( collision == 0 ):
                                              
                # RECOMPUTE NEXT DYN:   slaveValue   lastSpeed  
                snapOnPlane    = trsObj.snapOnPlane( planeCoords , inTrsValue = self.slaveValue )
                vSnapSlave     = ompy.MVector( self.slaveValue[0] - snapOnPlane[0] , self.slaveValue[1] - snapOnPlane[1] , self.slaveValue[2] - snapOnPlane[2] ) 
                
                if( vSnapSlave.length() <= hitSphereSize ) or ( mVectorNormal * vSnapSlave <= 0 ): 
                    self.slaveValue = [ snapOnPlane[0] + vContact.x , snapOnPlane[1] + vContact.y , snapOnPlane[2] + vContact.z ] + self.slaveValue[6:9]                    
                    #self.slaveValue = snapOnPlane 
                    
                    mLastSpeed    = ompy.MVector( self.lastSpeed[0] , self.lastSpeed[1] , self.lastSpeed[2] )                     
                    if( mVectorNormal * mLastSpeed < 0 ):                 
                        self.lastSpeed = self.getReflectVector( self.lastSpeed , planeCoords , collision )                
            
            self.slaveTValue = self.slaveValue[0:3]                     
            self.lastSpeedT  = self.lastSpeed[0:3]
            
            trsOut = self.slaveTValue + self.slaveRValue + self.slaveSValue                                          
        
        #_____________________________________________________________________________________ OUT NEXT EXAL       
        
        nodeName = self.name()  
        mc.undoInfo( swf = 0 )
        mc.setAttr( nodeName +'.nbrEval'  , self.nbrEval    )
        mc.setAttr( nodeName +'.lastTime' , self.lastTime   )  
        
        mc.setAttr( nodeName +'.lastSpeedT' ,  self.lastSpeedT[0] ,  self.lastSpeedT[1] ,  self.lastSpeedT[2] , type = 'double3')   
        mc.setAttr( nodeName +'.lastSpeedR' ,  self.lastSpeedR[0] ,  self.lastSpeedR[1] ,  self.lastSpeedR[2] , type = 'double3') 
        mc.setAttr( nodeName +'.lastSpeedS' ,  self.lastSpeedS[0] ,  self.lastSpeedS[1] ,  self.lastSpeedS[2] , type = 'double3') 
        
        mc.setAttr( nodeName +'.slaveTValue' , self.slaveTValue[0] , self.slaveTValue[1] , self.slaveTValue[2] , type = 'double3')  
        mc.setAttr( nodeName +'.slaveRValue' , self.slaveRValue[0] , self.slaveRValue[1] , self.slaveRValue[2] , type = 'double3')  
        mc.setAttr( nodeName +'.slaveSValue' , self.slaveSValue[0] , self.slaveSValue[1] , self.slaveSValue[2] , type = 'double3')          
        mc.undoInfo( swf = 1 )
    
        #_____________________________________________________________________________________ OUT NODE                

        fatherTrs   = trsObj.createFromFloatMatrix( fatherMatrix )         
        trsOutUnder = trsObj.parent( fatherTrs , inTrsValue = trsOut )

        
        dataHandle = dataBlock.outputValue( self.outputTXAttr )       
        dataHandle.setFloat( trsOutUnder[0] )
             
        dataHandle = dataBlock.outputValue( self.outputTYAttr )       
        dataHandle.setFloat( trsOutUnder[1] )
        
        dataHandle = dataBlock.outputValue( self.outputTZAttr )      
        dataHandle.setFloat( trsOutUnder[2] )

        dataHandle = dataBlock.outputValue( self.outputRXAttr )      
        dataHandle.setFloat( trsOutUnder[3] )
        
        dataHandle = dataBlock.outputValue( self.outputRYAttr )      
        dataHandle.setFloat( trsOutUnder[4] )
        
        dataHandle = dataBlock.outputValue( self.outputRZAttr )      
        dataHandle.setFloat( trsOutUnder[5] )

        dataHandle = dataBlock.outputValue( self.outputSXAttr )      
        dataHandle.setFloat( trsOutUnder[6] )

        dataHandle = dataBlock.outputValue( self.outputSYAttr )      
        dataHandle.setFloat( trsOutUnder[7] )

        dataHandle = dataBlock.outputValue( self.outputSZAttr )      
        dataHandle.setFloat( trsOutUnder[8] )
        
        dataBlock.setClean( plug )