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)
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)
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)
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)