I have been noticing my code being very slow. I managed to trace it to the collisions, and found out that everything had been colliding with visible geometry. my attempt to make it use the collision nodes caused it to not register any collisions at all. here is my code:
class MyApp(ShowBase):
def __init__(self):
#...
self.myHandler = CollisionHandlerQueue()
base.cTrav1 = CollisionTraverser()
self.pickerRay1 = CollisionRay()
pickerNP1 = camera.attachNewNode(CollisionNode('mouseRay1'))
pickerNP1.node().addSolid(self.pickerRay1)
pickerNP1.node().setIntoCollideMask(BitMask32.allOff())
pickerNP1.node().setFromCollideMask(BitMask32(0x1))
base.cTrav1.addCollider(pickerNP1, self.myHandler)
#...
self.accept("mouse1",self.pickobject)
self.col = CollisionPolygon(*[Point3(x,y,0) for x in (.5,-.5) for y in (-.5,.5)])
#...
def addobject(self):
#...
#procedurally create nodePath, parent it to render
colNodePath = nodePath.attachNewNode(CollisionNode("cnode"))
colNodePath.addSolid(self.col) #self.col was defined in init.
nodePath.setCollideMask(BitMask32.allOff())# \
colNodePath.setCollideMask(BitMask32(0x1)) # / this is what i changed. before it was:
#nodePath.setCollideMask(BitMask32(0x1))
#...
def pickobject(self):
if base.mouseWatcherNode.hasMouse():
x = base.mouseWatcherNode.getMouseX()
y = base.mouseWatcherNode.getMouseY()
self.pickerRay1.setFromLens(base.camNode,x,y)
base.cTrav1.traverse(render)
self.myHandler.sortEntries()
if self.myHandler.getNumEntries() > 0:
pickedObj = self.myHandler.getEntry(0).getIntoNodePath()
print pickedObj
#...
This code was simplified greatly. I do not know what could have gone wrong, as i didn’t change much. why would it only collide with visible geometry and not collision nodes?