Large terrain file

A simple mechanism might be something like this:

#The exact placement may depend on your
# purposes and project; what I believe that
# mean to convey by putting this line here
# is simply "not in the task".
lastPos = base.cam.getPos()
updateDistanceSquared = 64*64

#I'm squaring the distance above so that
# I can use the "lengthSquared" method
# below, which I imagine to be slightly
# cheaper than "length".  The number "64"
# is arbitrary, and may vary according to
# your desires.

def updateTask(task):
    pos = base.cam.getPos()
    distSq = (pos - lastPos).lengthSquared()
    if distSq > updateDistanceSquared:
        lastPos = pos
        terrain.update()
    return task.cont

Add “self.”/“objectName.” and/or rename as appropriate to the structure of your program.

Thank you that looks exactly what I was looking for.

I added the line:

terrain.setAutoFlatten(GeoMipTerrain.AFMStrong)

and it increased the framerate from about 70 to 450 :laughing:

With the updating, I think I may be doing it wrong :confused: I can’t see any sign of it updating. I put:

lastPos = base.cam.getPos()
updateDistanceSquared = 64*64

at the beginning outside my class but was it mean to go elsewhere? :confused: Sorry if that’s a dumb question.

Perhaps try reducing the size from 64 to some smaller value; depending on your game, you might find that 64 units is rather far.

I think it isn’t updating at all. It seems to just stay low quality. When I remove the update task completely I see no difference :confused:

Hi

Did you make any of these calls that influence the LOD changes of the terrain after creating the GeoMipTerrain ? (only need to be done once)

GeoMipTerrain functions:
setBlockSize, setNear, setFar, setFocalPoint, setMinLevel

You need to put the camera node into the setFocalPoint, and in my case using 1025x1025 terrain I set near=256 and far=512, min_level=2,block_size=64

Also you don’t really need a task to call the terrain update in, you can call it from within your task that handles the camera movements for forward,backward,and side to side movements. That way you only do the distance checking when you need to, when the camera actually moves. My distance calculation is a little different, I only use the xy value, not z.

      LPoint2f pos = mCameraNode.get_pos().get_xy();
      float dist = (mPrevCameraPos - pos).length();

you can still use the squared function instead as it wouldn’t have to take the square root.

In my code I haven’t tried using the auto flatten, so not sure what to say about it, if it messes up using the LOD stuff or not…

Thanks for the help, I tried playing around with it a bit more but couldn’t have any success in making it update properly. However I decided to go for the blocky minecraft sort of look :slight_smile: so I’m not using L3DT now but have a python implementation of Perlin Noise and coloured tiles. But I’m running into a bit of a problem :confused: My actor sometimes goes through the ground if I run directly at a steep slope. I think it may be something to do with the edges of the triangles. Any idea how I would fix this? :frowning:

Fixed it by lowering my speed :smiley:

I’m glad that you fixed it. :slight_smile:

As an alternative, against it becoming a problem again, I see that GeomMipTerrain has a method called “getElevation” - if you’re using the ray-collision method of keeping your character on the ground, you could perhaps switch to getElevation(x, y) where x and y are the respective x- and y- coordinates of your character as of that update.

Thanks I’ll look into that if I need the player to move fast (like in a car or something)