Only collides with visible geometry

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?

Nothing’s obviously wrong in your code snippet, but there’s not enough there to diagnose whether your polygon is actually in front of the ray, or any of the usual things that might go wrong with collisions.

David

Well, as far as I can tell, the problem involves the way i attached the collision solid or the bitmasks. the ray collided with the visible geometry just fine, but it will not collide with the collision solids, and that is all that I changed. I checked the position and scale, and the collision solid should be colliding with the ray.

Hmm, looking closer, one problem I see is the way you define your CollisionPolygon:

CollisionPolygon(*[Point3(x,y,0) for x in (.5,-.5) for y in (-.5,.5)])

This defines the points in an invalid order. You’re making a bow-tie pattern, instead of ordering the points counter-clockwise, so you have an invalid polygon.

David

Thank you so much! It works perfectly now!