コード例 #1
0
def GetInvertedMatrix(mat):
    """
    Invert the indicated matrix, sending back a new matrix.
    """
    invMat = pm.Mat4()
    invMat.invertFrom(mat)
    return invMat
コード例 #2
0
def ScalePoint(pnt, scl, invert=False):
    """
    Return a new point based on the indicated point xformed by a matrix 
    constructed by the indicated scale. Invert the scale matrix if required.
    """
    sclMat = pm.Mat4().scaleMat(scl)
    if invert:
        sclMat.invertInPlace()
    return sclMat.xformPoint(pnt)
コード例 #3
0
def GetTrsMatrices(xform):
    """
    Return translation, rotation and scale matrices back for the specified
    transform.
    """
    # Get translation and rotation matrices
    rotMat = pm.Mat4()
    xform.getQuat().extractToMatrix(rotMat)
    transMat = pm.Mat4().translateMat(xform.getPos())

    # More care must be taken to get the scale matrix as simply calling
    # Mat4().scaleMat( xform.getScale() ) won't account for shearing or other
    # weird scaling. To get this matrix simply remove the translation and
    # rotation components from the xform.
    invRotMat = pm.Mat4()
    invRotMat.invertFrom(rotMat)
    invTransMat = pm.Mat4()
    invTransMat.invertFrom(transMat)
    scaleMat = xform.getMat() * invTransMat * invRotMat

    return transMat, rotMat, scaleMat
コード例 #4
0
ファイル: functions.py プロジェクト: Derfies/p3d
def Str2Mat4(string):
    mat = pm.Mat4()
    mat.set(*Str2FloatTuple(string))
    return mat
コード例 #5
0
ファイル: translation.py プロジェクト: vheuken/panda3d-editor
 def Transform( self ):
     axis = self.GetSelectedAxis()
     axisPoint = self.GetAxisPoint( axis )
     
     # Calculate delta and snapping.
     d = axisPoint - self.lastAxisPoint
     lastSnap = self._Snap( self._s )
     self._s += d
     thisSnap = self._Snap( self._s )
     
     if self._snp:
         
         # If snapping in planar mode or using the camera axis, snap to a
         # point on the ground plane.
         if axis.vector == CAMERA_VECTOR or self.planar:
             pnt = self.GetMousePlaneCollisionPoint( pm.Point3( 0 ), 
                                                     pm.Vec3( 0, 0, 1 ) )
             pnt = utils.SnapPoint( pnt, self._snpAmt )
             
             self.setPos( render, pnt )
             for np in self.attachedNps:
                 np.setPos( render, pnt )
                 
             return
             
         # If snapping in world space, construct a plane where the mouse
         # clicked the axis and move all NodePaths so they intersect it.
         elif not self.local:
             pnt = utils.SnapPoint( self.startAxisPoint + d, self._snpAmt )
             pl = pm.Plane( axis.vector, pm.Point3( pnt ) )
             
             self.setPos( render, pl.project( self.getPos( render ) ) )
             for np in self.attachedNps:
                 np.setPos( render, pl.project( np.getPos( render ) ) )
                 
             return
         
         # Gone over the snap threshold - set the delta to the snap amount.
         elif thisSnap.compareTo( lastSnap, TOL ):
             d.normalize()
             d *= self._snpAmt
             
             # BUG - need to resize to compensate for cam dist?
             
         # In snapping mode but haven't gone past the snap threshold.
         else:
             d = pm.Vec3( 0 )
         
     d = self.getRelativeVector( self.rootNp, d )
     self.setMat( pm.Mat4().translateMat( d ) * self.getMat() )
     
     # Adjust the size of delta by the gizmo size to get real world units.
     d = utils.ScalePoint( d, self.getScale() )
     
     # Hack for fixing camera vector xforming in local mode.
     if self.local and axis.vector == CAMERA_VECTOR:
         d = self.rootNp.getRelativeVector( self, d )
         d = utils.ScalePoint( d, self.getScale(), True )
     
     # Xform attached NodePaths.
     for np in ( self.attachedNps ):
         if self.local and axis.vector != CAMERA_VECTOR:
             sclD = utils.ScalePoint( d, np.getScale( self.rootNp ), True )
             np.setMat( pm.Mat4().translateMat( sclD ) * np.getMat() )
         else:
             np.setMat( self.rootNp, np.getMat( self.rootNp ) * 
                        pm.Mat4().translateMat( d ) )
     
     self.lastAxisPoint = axisPoint