Panda PhysX

Hello! I’m having troubles with groups and groups masks.

import direct.ffi.panda3d

import direct.directbase.DirectStart

from panda3d.core import Vec3
from panda3d.core import Point3

from panda3d.physx import PhysxManager
from panda3d.physx import PhysxScene
from panda3d.physx import PhysxSceneDesc
from panda3d.physx import PhysxBodyDesc
from panda3d.physx import PhysxActorDesc
from panda3d.physx import PhysxBoxShapeDesc
from panda3d.physx import PhysxPlaneShapeDesc
from panda3d.physx import PhysxRay
from panda3d.physx import PhysxMask
from panda3d.physx import PhysxGroupsMask

from base import BaseWorld


class World(BaseWorld):

  def __init__(self):
    BaseWorld.__init__(self)

  def setup(self):
      
    # Scene
    sceneDesc = PhysxSceneDesc()
    sceneDesc.setGravity(Vec3(0, 0, -9.81))

    self.scene = PhysxManager.getGlobalPtr().createScene(sceneDesc)

    # Plane
    shapeDesc = PhysxPlaneShapeDesc()
    shapeDesc.setPlane(Vec3(0, 0, 1), -2)

    actorDesc = PhysxActorDesc()
    actorDesc.addShape(shapeDesc)

    self.planeActor = self.scene.createActor(actorDesc)

    # Box
    self.boxNP = loader.loadModel('models/box.egg')
    self.boxNP.reparentTo(render)

    shapeDesc = PhysxBoxShapeDesc()
    shapeDesc.setDimensions(Vec3(0.5, 0.5, 0.5))

    bodyDesc = PhysxBodyDesc()
    bodyDesc.setMass(10.0)

    actorDesc = PhysxActorDesc()
    actorDesc.setBody(bodyDesc)
    actorDesc.setName('Box')
    actorDesc.addShape(shapeDesc)
    actorDesc.setGlobalPos(Point3(0, 0, -1.5))

    self.boxActor = self.scene.createActor(actorDesc)
    self.boxActor.attachNodePath(self.boxNP)
    
    # Scene collision filtering expression: (G0 & G1) == True.
    self.scene.setFilterConstant0(PhysxGroupsMask.allOff())
    self.scene.setFilterConstant1(PhysxGroupsMask.allOff()
    self.scene.setFilterOps(op0 = self.scene.FOOr
                           ,op1 = self.scene.FOOr
                           ,op2 = self.scene.FOAnd)
    self.scene.setFilterBool(True)

    # Main groups mask.
    GROUPSMASK1 = PhysxGroupsMask().allOff()
    GROUPSMASK1.setBits0(1)
    
    # Another groups mask.
    GROUPSMASK2 = PhysxGroupsMask().allOff()
    GROUPSMASK2.setBits0(2)
    
    # Box in group 0.
    self.boxActor.setGroup(0)
        
    # Box and plane in groups mask 1.
    self.boxActor.getShape(0).setGroupsMask(GROUPSMASK1)
    self.planeActor.getShape(0).setGroupsMask(GROUPSMASK1)
    
    # Ray
    ray = PhysxRay()
    ray.setOrigin(Point3(0, -1, -1.5))
    ray.setDirection(Vec3(0, 1, 0))
    ray.setLength(5.0)
    
    # Raycast 1.
    group0 = PhysxMask.allOff()
    rayhit = self.scene.raycastClosestShape(ray
                                           ,shapesType=PhysxScene.STAll
                                           ,mask=group0
                                           ,groups=GROUPSMASK1)
    
    print "raycast 1 hit? ", not rayhit.isEmpty()
    
    # Raycast 2.
    group0 = PhysxMask.allOff()
    group0.setBit(0)
    rayhit = self.scene.raycastClosestShape(ray
                                           ,shapesType=PhysxScene.STAll
                                           ,mask=group0
                                           ,groups=GROUPSMASK1)
    print "raycast 2 hit? ", not rayhit.isEmpty()
    
    # Raycast 3.
    group0 = PhysxMask.allOff()
    group0.setBit(0)
    rayhit = self.scene.raycastClosestShape(ray
                                           ,shapesType=PhysxScene.STAll
                                           ,mask=group0
                                           ,groups=GROUPSMASK2)
    print "raycast 2 hit? ", not rayhit.isEmpty()

  def update(self, task):
    dt = globalClock.getDt()
    self.scene.simulate(dt)
    self.scene.fetchResults()
    return task.cont

  def cleanup(self):
    self.boxNP.removeNode()
    self.scene.release()
    render.ls()

if __name__ == '__main__':
  world = World()
  run()

I was expecting an opposite outcome for any of the three ray casts. What am I doing wrong? Thanks!