Visible geometry Collisions

im Trying to make a .egg collide with collisionSpheres.

from direct.showbase.ShowBase import ShowBase
from direct.interval.IntervalGlobal import Sequence, Func, Wait
from pandac.PandaModules import CollisionTraverser, CollisionHandlerEvent
from pandac.PandaModules import CollisionNode, CollisionSphere
from pandac.PandaModules import VBase4
from pandac.PandaModules import Point3
from panda3d.core import BitMask32

class Voxelize(ShowBase):
    
    def __init__(self):
        ShowBase.__init__(self)
        
        base.cTrav = CollisionTraverser()
        self.collHandEvent = CollisionHandlerEvent()
        self.collHandEvent.addInPattern('%fn-into-%in')
        
        self.createVoxelField(2, .5)
        self.loadModel('models/ship.egg')
        
    def createVoxelField(self, CubeSize, VoxelSize):
        for i in range(CubeSize):
            for k in range(CubeSize):
                for j in range(CubeSize):
                    self.makeVoxel(i,k,j,VoxelSize)
                    
    def loadModel(self, modelPath):
        model = loader.loadModel(str(modelPath))
        model.reparentTo(render)
        geomnode = model.find('**/-GeomNode').node() 
        geomnode.setIntoCollideMask(BitMask32.bit(1))
        
        base.cTrav.addCollider(model, self.collHandEvent)
        
    def makeVoxel(self, x, y, z, size):
        center = Point3(0,0,0)
        Cnode = CollisionNode('VoxelCollisionNode')
        node = render.attachNewNode(Cnode)
        sphere = CollisionSphere(center,size)
        Cnode.addSolid(sphere)
        node.setPos(x,y,z)
        node.show()
        base.cTrav.addCollider(node, self.collHandEvent)

thats what i got but i get errors on base.cTrav.addCollider(model, self.collHandEvent) any ideas?

EDIT: well i seem to have gotten them to collide with the visible geometry. My problem now is removing the Nodes containing the collisionSolids that AREN’T collidibg with the visible geometry. new Code

from direct.showbase.ShowBase import ShowBase
from direct.interval.IntervalGlobal import Sequence, Func, Wait
from pandac.PandaModules import CollisionTraverser, CollisionHandlerQueue
from pandac.PandaModules import CollisionNode, CollisionSphere
from pandac.PandaModules import VBase4
from pandac.PandaModules import Point3
from panda3d.core import BitMask32

class Voxelize(ShowBase):
    
    def __init__(self):
        ShowBase.__init__(self)
        
        self.CubeSize = 5
        
        base.cTrav = CollisionTraverser()
        self.collHandEvent = CollisionHandlerQueue()
        
        self.createVoxelField(self.CubeSize, .5)
        self.loadModel('models/ship.egg')
        
        base.cTrav.traverse(render)
        for i in range(self.collHandEvent.getNumEntries()):
            entry = self.collHandEvent.getEntry(i)
            if entry.hasInto() == True:
                this = entry.getFromNodePath()
                this.hide()
                print(this)
        
    def createVoxelField(self, CubeSize, VoxelSize):
        for i in range(CubeSize):
            for k in range(CubeSize):
                for j in range(CubeSize):
                    self.makeVoxel(i,k,j,VoxelSize)
                    
    def loadModel(self, modelPath):
        model = loader.loadModel(str(modelPath))
        model.reparentTo(render)
        model.setPos(self.CubeSize/2, self.CubeSize/2, self.CubeSize/2)
        geomnode = model.find('**/-GeomNode').node() 
        geomnode.setIntoCollideMask(BitMask32.bit(1))
        
    def makeVoxel(self, x, y, z, size):
        center = Point3(0,0,0)
        Cnode = CollisionNode('VoxelCollisionNode')
        node = render.attachNewNode(Cnode)
        sphere = CollisionSphere(center,size)
        Cnode.addSolid(sphere)
        node.setPos(x,y,z)
        node.show()
        base.cTrav.addCollider(node, self.collHandEvent)
        
    def collide(self, collEntry):
        print(collEntry)
        
        
app = Voxelize()
app.run()

Sorry, I’m not sure what you’re asking.

David

Basically I’m creating a model to voxel loader, I have a model that is thrown inside a cube made of voxels, I then remove any voxels that aren’t colliding with the model, that’s why I need visible geom collisions.

Yes, but what specific question about Panda are you asking right now?

how to properly set up visible geom collisions, and how to filter out the collisions that only happened with visible geometry

That’s not a very specific question. :slight_smile:

The general answer is, there’s nothing special about collisions with visible geometry as opposed to collisions with collision geometry (other than the fact that it’s about 10x slower). You control them both the same way, with the use of bitmasks. If your “from” mask on your from CollisionNode has any bits in common with the “into” mask on your GeomNode, then it will be tested for collisions; otherwise, it won’t.

David