For a good while I was having trouble whenever I needed to set a collision bitmask in my game because there were just so many different fields manually typing out the bits became tedious.
Fortunately, I was able to come up with this solution where you define a list of possible tags in bitmask_types, and then import and call generate_bitmask with whatever tags you want whenever you need to make a bitmask.
from panda3d.core import BitMask32
bitmask_types = ("world", "water",
"red team", "red bones", "blue team", "blue bones",
"vr grabable", "point and select"
)
assert len(bitmask_types) <= 32
def generate_bitmask(*params):
newBM = BitMask32()
assert newBM.is_zero()#Since I'm showing this, a question. Do I need this?
for param in params:
if not param in bitmask_types:
continue
index = bitmask_types.index(param)
assert index < 32
newBM.set_bit(index)
return newBM