greetings,
Was trying to set up a scene where a box falls down against a heightfield terrain generated by a GeoMipTerrain. This using solely ODE physics. I’ve been unable, so far, to get a collision between the box and the trimesh generated for the terrain. Searched around for quite a while and couldn’t find something to solve it so far. Any ideas bout what i’m doing wrong or what could be the issue? My suspicions are on the generated trimesh although it does print out to have 30k + triangles.
the code is based on the boxes manual example.
import math, os, sys
from direct.directbase import DirectStart
from pandac.PandaModules import Filename
# finds what path we're in
PATH = os.path.abspath(sys.path[0])
PATH = Filename.fromOsSpecific(PATH).getFullpath()
from pandac.PandaModules import OdeWorld, OdeSimpleSpace, OdeJointGroup
from pandac.PandaModules import OdeBody, OdeMass, Quat, CardMaker, Vec4
from pandac.PandaModules import OdePlaneGeom, BitMask32, OdeBoxGeom, GeoMipTerrain,OdeTriMeshData,OdeTriMeshGeom
myworld = OdeWorld()
myworld.setGravity(0, 0, -9.81)
#Cube Construction and placing in scene graph
#cube is 1 unit size
cube = loader.loadModel("box.egg")
cube.reparentTo(render)
cube.setColor(0.2, 0.5, 0)
cube.setPos(70, 60 , 70)
cube.setScale(2)
bbody = OdeBody(myworld)
bbodyMass = OdeMass()
bbodyMass.setBox(11340, 2, 2, 2)
bbody.setMass(bbodyMass)
bbody.setPosition(cube.getPos(render))
bbody.setQuaternion(cube.getQuat(render))
#creates terrain
terrain = GeoMipTerrain("terrain")
terrain.setHeightfield(Filename(PATH + "/resources/terrains/height2.png"))
terrain.getRoot().reparentTo(render)
terrain.getRoot().setSz(30)
terrain.setColorMap(Filename(PATH + "/resources/models/ground.jpg"))
terrain.generate()
#collisions setup
space = OdeSimpleSpace()
space.setAutoCollideWorld(myworld)
contactGroup = OdeJointGroup()
space.setAutoCollideJointGroup(contactGroup)
#colisionGeoms
modelTrimesh = OdeTriMeshData(terrain.getRoot(), True)
modelGeom = OdeTriMeshGeom(space, modelTrimesh)
modelGeom.setCollideBits(BitMask32(0x00000001))
modelGeom.setCategoryBits(BitMask32(0x00000002))
boxGeom = OdeBoxGeom(space,0.5, 0.5, 0.5)
boxGeom.setCollideBits(BitMask32(0x00000002))
boxGeom.setCategoryBits(BitMask32(0x00000001))
boxGeom.setBody(bbody)
#only 1 material type for now
myworld.initSurfaceTable(1)
#surfaceId1 collides with surfaceId2 (physical properties of that collision)
#setSurfaceEntry(surface Id1, surfaceId2, mu, bounce, bounce_vel, soft_erp, soft_cfm, slip, dampen)
myworld.setSurfaceEntry(0, 0, 0.0, 1.0, 9.1, 0.9, 0.00001, 0.0, 0.002)
#camera placing
base.cam.setPos(50, -30 , 70)
base.cam.lookAt(50, -30 , 70)
stepSize = 1.0/90.0
#task for running the simulation
def simTask(task):
contactGroup.empty()
print "contacts number: %d" %space.autoCollide() #setup the contact joints
#updates positions
cube.setPosQuat(render, bbody.getPosition(), Quat(bbody.getQuaternion()))
#runs a physic simulation step
myworld.quickStep(stepSize)
return task.cont
#task for physical simulation test added to taskManager
taskMgr.doMethodLater(1.0, simTask,"simulation")
run()