Hi, everyone! I’m new to Panda3D, I was trying to solve this myself, there are many similar topics on this in the forums, but after spending 5 hours with no result, I decided to create this thread.
I need to do simple task. I have level with static geometry, and camera moving around this level. I need to ‘map’ the level, i.e. sent raycast in all directions from the camera, and get collision distances from camera to the surface, though mapping level this way.
I thought that most effcicient way to do this is to use Bullet World physics, though I’ll have so sent lots of rays in all directions, I think there is no ‘SphereOverlap’ or something like that in Panda3D.
So I created test scene inside 3Ds Max, and exported it, keeping this inside egg file:
<Collide> Floor_Big_004 { Polyset keep descend }
Then coded this:
from direct.showbase.ShowBase import ShowBase
from FirstPersonCamera import FirstPersonCamera
from panda3d.core import *
#loadPrcFileData("", "want-directtools #t")
#loadPrcFileData("", "want-tk #t")
from panda3d.bullet import BulletWorld
class Application(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.setupCD()
base.setBackgroundColor(1, 1, 1)
base.disableMouse()
self.floor = loader.loadModel("Floor_Big_02.egg")
self.floor.reparentTo(render)
self.floor.setPos(0, 0, 0)
self.floor.setScale(0.1, 0.1, 0.1)
self.geomnodes = self.floor.findAllMatches('**/+GeomNode')
self.gn = self.geomnodes.getPath(0).node
self.geom = self.gn.getGeom(0)
self.mesh = BulletTriangleMesh()
self.mesh.addGeom(self.geom)
self.shape = BulletTriangleMeshShape(self.mesh, dynamic=False)
self.cam.setPos(10, -10, 5)
self.mouseLook = FirstPersonCamera(self, self.cam, self.render)
def setupCD(self):
taskMgr.add(self.update, 'update')
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt)
pFrom = self.cam.getPos()
pTo = pFrom + Vec3(1, 0, 0) * 99999
result = self.world.rayTestAll(pFrom, pTo)
if result.hasHits():
print result.hasHits()
return task.cont
“GeomNode” is not found no matter what. From what I learned, Panda3D should have created it automatically; On second thought, when I look at the egg file, it has not GeomNode tags either
<Group> character {
<Dart> { 1 }
<Group> Floor_Big_004 {
<Collide> Floor_Big_004 { Polyset keep descend }
<VertexPool> Floor_Big_004.verts {
<Vertex> 0 {
139.996 -400.004 2.28882e-005
<UV> {
0.000207861 0.499871
<Tangent> { 1 8.92681e-007 0 }
<Binormal> { -8.92681e-007 1 2.72486e-007 }
}
<Normal> { 0 -2.72486e-007 1 }
}
<Vertex> 1 {
....
139.996 -540 -1.52588e-005
<UV> {
Any advice, what might be wrong? And is my approach for mapping is, in general, efficient?
If I remove that ‘self.floor.findAllMatches(’**/+GeomNode’)’ part which always fails, raycast will simply return ‘false’ all the time.