setGroupCollisionFlag() is not activate ?

Hi everybody

I am a user of Bullet with Panda3D.
I’d like to ask how to use “Group Masks” described in
panda3d.org/manual/index.ph … nguage=cxx

According to the instruction in “Group Masks”,
I set setGroupCollisionFlag() in line 150-155 described below
such as
self.world.setGroupCollisionFlag(mask0, mask0, True)

However, the warning message
":bullet(warning): filter algorithm is not ‘groups-mask’ "
appeared at excection.

So, I guess that setGroupCollisionFlag() is not activate, is it right ?

# -*- coding: utf-8 -*-
#from pandac.PandaModules import loadPrcFileData
#loadPrcFileData('', 'load-display tinydisplay')
#
# This code is from
#  Panda3d -> manual -> 36. Physics -> 3 Using Bullet with Panda3d
# -> 19. Bullet sample -> 04_Filterling.py
# https://www.panda3d.org/manual/index.php/Bullet_Samples

import sys
import direct.directbase.DirectStart

from direct.showbase.DirectObject import DirectObject
from direct.showbase.InputStateGlobal import inputState

from panda3d.core import AmbientLight
from panda3d.core import DirectionalLight
from panda3d.core import Vec3
from panda3d.core import Vec4
from panda3d.core import Point3
from panda3d.core import TransformState
from panda3d.core import BitMask32

from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletPlaneShape
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletRigidBodyNode
from panda3d.bullet import BulletDebugNode

class Game(DirectObject):

  def __init__(self):
    base.setBackgroundColor(0.1, 0.1, 0.8, 1)
    base.setFrameRateMeter(True)

    base.cam.setPos(0, -20, 4)
    base.cam.lookAt(0, 0, 0)

    # Light
    alight = AmbientLight('ambientLight')
    alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
    alightNP = render.attachNewNode(alight)

    dlight = DirectionalLight('directionalLight')
    dlight.setDirection(Vec3(1, 1, -1))
    dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
    dlightNP = render.attachNewNode(dlight)

    render.clearLight()
    render.setLight(alightNP)
    render.setLight(dlightNP)

    # Input
    self.accept('escape', self.doExit)
    self.accept('r', self.doReset)
    self.accept('f1', self.toggleWireframe)
    self.accept('f2', self.toggleTexture)
    self.accept('f3', self.toggleDebug)
    self.accept('f5', self.doScreenshot)

    inputState.watchWithModifiers('forward', 'w')
    inputState.watchWithModifiers('left', 'a')
    inputState.watchWithModifiers('reverse', 's')
    inputState.watchWithModifiers('right', 'd')
    inputState.watchWithModifiers('turnLeft', 'q')
    inputState.watchWithModifiers('turnRight', 'e')

    # Task
    taskMgr.add(self.update, 'updateWorld')

    # Physics
    self.setup()



  # _____HANDLER_____

  def doExit(self):
    self.cleanup()
    sys.exit(1)

  def doReset(self):
    self.cleanup()
    self.setup()

  def toggleWireframe(self):
    base.toggleWireframe()

  def toggleTexture(self):
    base.toggleTexture()

  def toggleDebug(self):
    if self.debugNP.isHidden():
      self.debugNP.show()
    else:
      self.debugNP.hide()

  def doScreenshot(self):
    base.screenshot('Bullet')

  # ____TASK___

  def processInput(self, dt):
    force = Vec3(0, 0, 0)
    torque = Vec3(0, 0, 0)

    if inputState.isSet('forward'): force.setY( 1.0)
    if inputState.isSet('reverse'): force.setY(-1.0)
    if inputState.isSet('left'):    force.setX(-1.0)
    if inputState.isSet('right'):   force.setX( 1.0)
    if inputState.isSet('turnLeft'):  torque.setZ( 1.0)
    if inputState.isSet('turnRight'): torque.setZ(-1.0)

    force *= 30.0
    torque *= 10.0

    self.boxNP.node().setActive(True)
    self.boxNP.node().applyCentralForce(force)
    self.boxNP.node().applyTorque(torque)

  def update(self, task):
    dt = globalClock.getDt()

    self.processInput(dt)
    self.world.doPhysics(dt)

    return task.cont

  def cleanup(self):
    self.world = None
    self.worldNP.removeNode()


  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
    self.debugNP.show()

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

    # Group Collision Flag
    mask0 = 0
    mask1 = 1
    mask2 = 2

    self.world.setGroupCollisionFlag(mask0, mask0, True) 
    self.world.setGroupCollisionFlag(mask0, mask1, True)
    self.world.setGroupCollisionFlag(mask0, mask2, True)
    self.world.setGroupCollisionFlag(mask1, mask1, True) 
    self.world.setGroupCollisionFlag(mask1, mask2, True) 
    self.world.setGroupCollisionFlag(mask2, mask2, True) 

    # Ground
    shape = BulletPlaneShape(Vec3(0, 0, 1), -1)

    mask = BitMask32(0x0f)
    print 'ground: ', mask

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
    np.node().addShape(shape)
    np.setPos(0, 0, -1)
#    np.setCollideMask(mask)
    np.setCollideMask(mask0)


    self.world.attachRigidBody(np.node())

    # Box 1
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    mask = BitMask32(0x3)
    print 'box-1:  ', mask

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-1'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(-6, 0, 4)
#    np.setCollideMask(mask)
    np.setCollideMask(mask1)

    self.world.attachRigidBody(np.node())

    # Box 2
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    mask = BitMask32.bit(0)
    print 'box-2:  ', mask

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-2'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(-2, 0, 4)
#    np.setCollideMask(mask)
    np.setCollideMask(mask2)

    self.world.attachRigidBody(np.node())

    # Box 3
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    mask = BitMask32.bit(2)
    print 'box-3:  ', mask

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-3'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(2, 0, 4)
#    np.setCollideMask(mask)
    np.setCollideMask(mask1)

    self.world.attachRigidBody(np.node())

    # Box 4
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    mask = BitMask32(0x3)
    print 'box-4:  ', mask

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-4'))
    np.node().setMass(1.0)
    np.node().addShape(shape)
    np.setPos(6, 0, 4)
    np.setCollideMask(mask2)

    self.world.attachRigidBody(np.node())

    self.boxNP = np

    visualNP = loader.loadModel('models/box.egg')
    visualNP.reparentTo(self.boxNP)

game = Game()
run()

Regards

Looking at the page to which you link, my understanding is that you’re required to set a configuration variable (your “config.prc” file is the obvious place, but it might be feasible to set it at run-time) in order to make this work. Specifically, it indicates that you should have (whether already there or created by you) a variable named “bullet-filter-algorithm”, with the value “groups-mask”.

From the page:

Thanks for your reply, but I can not understand what you said.
Because, Mr/Ms enn0x (Sun Nov 13, 2011 5:18 am) answered as following
panda3d.org/forums/viewtopic … &start=450

My code just followed the code in the URL.
And more, from the source code;
panda3d.org/reference/1.8.0 … source.php
line 78-81
I can not find the wrong in my code ?

I’m suggesting that the problem isn’t in your code, but in your “config.prc” file. If you’re not familiar with the file, it’s a configuration file that you should have received with Panda–although you can make your own if you want, and even set configuration values while the program is running.

There’s more information in the manual, starting here, I believe.

As to the post that you mention, take a look at the post just above it–enn0x mentions a “config variable”–that is, a variable in “config.prc”, named “bullet-filter-algorithm”.

Put another way, look for the file “config.prc” in your Panda installation, and look within that file for a variable named “bullet-filter-algorithm”. If it’s there, change it to “group-mask” (presuming that it’s not already set to that); if it’s not there, add it, with the same value.

(By the way, in order to link to a specific post on this forum, look for a small icon at the top-left of the post to which you want to link–it should look like a tiny page. That should link to the post, and copying that link should allow you to link others to it.)

Dear Thaumaturge

Thank you a lot for very kind instructions !

I am a user of Bullet, so just have focused only on the Bullet terms in
panda3d.org/manual/index.php/Main_Page

So, I missed the usage of “Config.src” until getting your pointing out.
I got it by adding the following sentence into “Config.src” ;

bullet-filter-algorithm groups-mask

But, I have found the good example for it in the bullet-sample
panda3d.org/manual/index.php/Bullet_Samples

It is “05_FilteringExtended.py” which is coded as following

from pandac.PandaModules import loadPrcFileData
loadPrcFileData('', 'bullet-filter-algorithm groups-mask')

Anyway, your instruction leads me to the successful programming.

Regards !