コード例 #1
0
    def replaceCollisionPolysWithPlanes(self, model):
        newCollisionNode = PM.CollisionNode('collisions')
        newCollideMask = PM.BitMask32(0)
        planes = []
        collList = model.findAllMatches('**/+CollisionNode')
        if not collList:
            collList = [model]
        for cnp in collList:
            cn = cnp.node()
            if not isinstance(cn, PM.CollisionNode):
                self.notify.warning('Not a collision node: %s' % repr(cnp))
                break
            newCollideMask = newCollideMask | cn.getIntoCollideMask()
            for i in range(cn.getNumSolids()):
                solid = cn.getSolid(i)
                if isinstance(solid, PM.CollisionPolygon):
                    plane = PM.Plane(solid.getPlane())
                    planes.append(plane)
                else:
                    self.notify.warning('Unexpected collision solid: %s' %
                                        repr(solid))
                    newCollisionNode.addSolid(plane)

        newCollisionNode.setIntoCollideMask(newCollideMask)
        threshold = 0.1
        planes.sort(lambda p1, p2: p1.compareTo(p2, threshold))
        lastPlane = None
        for plane in planes:
            if lastPlane == None or plane.compareTo(lastPlane, threshold) != 0:
                cp = PM.CollisionPlane(plane)
                newCollisionNode.addSolid(cp)
                lastPlane = plane

        return PM.NodePath(newCollisionNode)
コード例 #2
0
 def privGotSpec(self, levelSpec):
     DistCogdoLevelGame.privGotSpec(self, levelSpec)
     levelMgr = self.getEntity(LevelConstants.LevelMgrEntId)
     self.endVault = levelMgr.geom
     self.endVault.reparentTo(self.geomRoot)
     self.endVault.findAllMatches('**/MagnetArms').detach()
     self.endVault.findAllMatches('**/Safes').detach()
     self.endVault.findAllMatches('**/MagnetControlsAll').detach()
     cn = self.endVault.find('**/wallsCollision').node()
     cn.setIntoCollideMask(OTPGlobals.WallBitmask
                           | ToontownGlobals.PieBitmask
                           | PM.BitMask32.lowerOn(3) << 21)
     walls = self.endVault.find('**/RollUpFrameCillison')
     walls.detachNode()
     self.evWalls = self.replaceCollisionPolysWithPlanes(walls)
     self.evWalls.reparentTo(self.endVault)
     self.evWalls.stash()
     floor = self.endVault.find('**/EndVaultFloorCollision')
     floor.detachNode()
     self.evFloor = self.replaceCollisionPolysWithPlanes(floor)
     self.evFloor.reparentTo(self.endVault)
     self.evFloor.setName('floor')
     plane = PM.CollisionPlane(
         PM.Plane(PM.Vec3(0, 0, 1), PM.Point3(0, 0, -50)))
     planeNode = PM.CollisionNode('dropPlane')
     planeNode.addSolid(plane)
     planeNode.setCollideMask(ToontownGlobals.PieBitmask)
     self.geomRoot.attachNewNode(planeNode)
コード例 #3
0
    def privGotSpec(self, levelSpec):
        DistCogdoLevelGame.privGotSpec(self, levelSpec)

        levelMgr = self.getEntity(LevelConstants.LevelMgrEntId)
        self.endVault = levelMgr.geom
        self.endVault.reparentTo(self.geomRoot)

        # Clear out unneeded backstage models from the EndVault, if
        # they're in the file.
        self.endVault.findAllMatches('**/MagnetArms').detach()
        self.endVault.findAllMatches('**/Safes').detach()
        self.endVault.findAllMatches('**/MagnetControlsAll').detach()

        # Flag the collisions in the end vault so safes and magnets
        # don't try to go through the wall.
        cn = self.endVault.find('**/wallsCollision').node()
        cn.setIntoCollideMask(OTPGlobals.WallBitmask
                              | ToontownGlobals.PieBitmask
                              | (PM.BitMask32.lowerOn(3) << 21))

        # Find all the wall polygons and replace them with planes,
        # which are solid, so there will be zero chance of safes or
        # toons slipping through a wall.
        walls = self.endVault.find('**/RollUpFrameCillison')
        walls.detachNode()
        self.evWalls = self.replaceCollisionPolysWithPlanes(walls)
        self.evWalls.reparentTo(self.endVault)

        # Initially, these new planar walls are stashed, so they don't
        # cause us trouble in the intro movie or in battle one.  We
        # will unstash them when we move to battle three.
        self.evWalls.stash()

        # Also replace the floor polygon with a plane, and rename it
        # so we can detect a collision with it.
        floor = self.endVault.find('**/EndVaultFloorCollision')
        floor.detachNode()
        self.evFloor = self.replaceCollisionPolysWithPlanes(floor)
        self.evFloor.reparentTo(self.endVault)
        self.evFloor.setName('floor')

        # Also, put a big plane across the universe a few feet below
        # the floor, to catch things that fall out of the world.
        plane = PM.CollisionPlane(
            PM.Plane(PM.Vec3(0, 0, 1), PM.Point3(0, 0, -50)))
        planeNode = PM.CollisionNode('dropPlane')
        planeNode.addSolid(plane)
        planeNode.setCollideMask(ToontownGlobals.PieBitmask)
        self.geomRoot.attachNewNode(planeNode)
コード例 #4
0
    def replaceCollisionPolysWithPlanes(self, model):
        newCollisionNode = PM.CollisionNode('collisions')
        newCollideMask = PM.BitMask32(0)
        planes = []

        collList = model.findAllMatches('**/+CollisionNode')
        if not collList:
            collList = [model]

        for cnp in collList:
            cn = cnp.node()
            if not isinstance(cn, PM.CollisionNode):
                self.notify.warning("Not a collision node: %s" % (repr(cnp)))
                break

            newCollideMask = newCollideMask | cn.getIntoCollideMask()
            for i in range(cn.getNumSolids()):
                solid = cn.getSolid(i)
                if isinstance(solid, PM.CollisionPolygon):
                    # Save the plane defined by this polygon
                    plane = PM.Plane(solid.getPlane())
                    planes.append(plane)
                else:
                    self.notify.warning("Unexpected collision solid: %s" %
                                        (repr(solid)))
                    newCollisionNode.addSolid(plane)

        newCollisionNode.setIntoCollideMask(newCollideMask)

        # Now sort all of the planes and remove the nonunique ones.
        # We can't use traditional dictionary-based tricks, because we
        # want to use Plane.compareTo(), not Plane.__hash__(), to make
        # the comparison.
        threshold = 0.1
        planes.sort(lambda p1, p2: p1.compareTo(p2, threshold))
        lastPlane = None
        for plane in planes:
            if lastPlane == None or plane.compareTo(lastPlane, threshold) != 0:
                cp = PM.CollisionPlane(plane)
                newCollisionNode.addSolid(cp)
                lastPlane = plane

        return PM.NodePath(newCollisionNode)
コード例 #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