Hello,
I have another problem with GeoMipTerrain and Collision detection.After the game start, collision detection won’t work on my GeoMipTerrain.Here is the error and code parts:
Error:
:grutil(error): GeoMipTerrain: root node unexpectedly mangled 256 vs 257
Code (Code is really similiar: https://discourse.panda3d.org/viewtopic.php?t=4536 , but with a few changes):
Terrain:
self.terrain = GeoMipTerrain("Otok-1")
self.terrain.setHeightfield(Filename("data/default.png"))
self.terrain.getRoot().setSz(400)
self.terrain.setBlockSize(32)
self.terrain.setFactor(400)
self.terrain.setMinLevel(3)
self.terrain.getRoot().reparentTo(render)
self.terrain.getRoot().setPos(0, 0, -180)
self.terrain.generate()
tex0 = loader.loadTexture("data/default_d.png")
tex0.setMinfilter(Texture.FTLinearMipmapLinear)
tex1 = loader.loadTexture("data/grayRock.png")
tex1.setMinfilter(Texture.FTLinearMipmapLinear)
tex2 = loader.loadTexture("data/hardDirt.png")
tex2.setMinfilter(Texture.FTLinearMipmapLinear)
tex3 = loader.loadTexture("data/bigRockFace.png")
tex3.setMinfilter(Texture.FTLinearMipmapLinear)
tex4 = loader.loadTexture("data/shortGrass.png")
tex4.setMinfilter(Texture.FTLinearMipmapLinear)
tex5 = loader.loadTexture("data/default_c.png")
tex5.setMinfilter(Texture.FTLinearMipmapLinear)
tex6 = loader.loadTexture("data/default_l.png")
tex6.setMinfilter(Texture.FTLinearMipmapLinear)
self.terrain.getRoot().setTexture( TextureStage('tex0'),tex0 )
self.terrain.getRoot().setTexture( TextureStage('tex1'),tex1 )
self.terrain.getRoot().setTexture( TextureStage('tex2'),tex2 )
self.terrain.getRoot().setTexture( TextureStage('tex3'),tex3 )
self.terrain.getRoot().setTexture( TextureStage('tex4'),tex4 )
self.terrain.getRoot().setTexture( TextureStage('tex5'),tex5 )
self.terrain.getRoot().setTexture( TextureStage('tex6'),tex6 )
self.terrain.getRoot().setShader(loader.loadShader('terraintexture.sha'))
self.islandToRen=self.terrain.getRoot()
self.islandToRen.reparentTo(render)
self.islandToRen.setPos(0, 0, -180)
Collision detection:
mColl=self.initCollisionSphere(self.islandToRen, False)
mColl[0].node().setIntoCollideMask( BitMask32.bit( 1 ))
mColl[0].node().setFromCollideMask( BitMask32.allOff())
base.cTrav .addCollider(mColl[0], self.collHandEvent)
self.accept( 'into-' + mColl[1], self.collide)
self.accept( 'outof-' + mColl[1], self.collide2)
def initCollisionSphere( self, obj, show=False):
bounds = obj.getChild(0).getBounds()
center = bounds.getCenter()
radius = bounds.getRadius()*0.9
collSphereStr = 'CollisionHull' +obj.getName()
cNode=CollisionNode(collSphereStr)
cNode.addSolid(CollisionSphere(center, radius ) )
cNodepath=obj.attachNewNode(cNode)
if show:
cNodepath.show()
return (cNodepath,collSphereStr )
I’m running this on Windows XP.
sorry for my bad english!
Regards,
Veki