Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terrain System #8

Open
jrenner opened this issue Aug 30, 2014 · 9 comments
Open

Terrain System #8

jrenner opened this issue Aug 30, 2014 · 9 comments

Comments

@jrenner
Copy link
Owner

jrenner commented Aug 30, 2014

Here's some code I used in a previous project for creating heightmapped terrain from reading a PNG file:

HeightMap reads the PNG file and creates a 2d array of vertices

HeightMapModel creates a 3d model based on the HeightMap

it doesn't have LOD or anything like that. At the time I tried to create a Bullet btHeightfieldTerrain body based on the data but could never get it to work.

HeightMap.java
HeightMapModel.java

@Caresilabs
Copy link
Contributor

Awesome! I try to bake it in my terrain manager.

I googled libgdx heighmap and there are a height map test that might be useful. However we need to get it working with bullet of course.

@Caresilabs
Copy link
Contributor

I forgot to ask, how does this render? Isn't it easier to build a model class from the vertices and them just create a model instance? :)

@jrenner
Copy link
Owner Author

jrenner commented Aug 30, 2014

I forgot to add the GroundChunk class, you can see it is used inside HeightMapModel:
https://gist.github.com/jrenner/169438e75773d0dbe861

The ground chunks are just added to a list, and then rendered like this:

    private void renderGroundChunks() {
        Lists.visibleGroundChunks.clear();
        for (GroundChunk ground : Lists.groundChunks) {
            if (ground.isVisible(cam)) {
                modelBatch.render(ground, environment);
                Lists.visibleGroundChunks.add(ground);
            }
        }
    }

visibleGroundChunks was just for debugging to see how many were visible in that project, it's not necessary

@jrenner
Copy link
Owner Author

jrenner commented Aug 30, 2014

You might also want these files for testings:
Here is the height map data file: http://www.superior-tactics.com:12080/hm1.png

Here is the texture you can use for it: http://www.superior-tactics.com:12080/hm1_paint.png

It should look something like this: https://www.youtube.com/watch?v=xNbi63i8aT4

@Caresilabs
Copy link
Contributor

This looks great!

Im home from work in about 2/3h and have a lot of time to fix this. cant wait hehe.

Have you used BtHeightFieldTerrainShape and know how it works?

@jrenner
Copy link
Owner Author

jrenner commented Aug 30, 2014

a while back when I was working on that terrain stuff I tried to create a btHeightFieldTerrainShape but the shape always came out corrupted/distorted, and I never got it working correctly. I ended up just writing a function that checks the height (y) of the ground at the 2d point (x,z) to do simple ground collisions. That worked fine, but it won't for GDX-proto, because we need the bullet shape to get the ground terrain working properly with ray casting.

@Caresilabs
Copy link
Contributor

What I see there are two options:

  1. get heightmapshape working
  2. Use the generetaed Model and creating a mesh collision on it

Im going to go with #2 first but when we find a soloution it will be easy as a pie to change it.

@jrenner
Copy link
Owner Author

jrenner commented Aug 30, 2014

Yeah, model-based object should be easy to get working, it's already used for the static geometry

@Caresilabs
Copy link
Contributor

Alright!

So Im thinking That you have a Terrain manager that is responsible for all terrain related stuff.

Terrain Manager can created TerrainChunks/GroundChunks (depending on the name) for you by example writing Terrain.createMeshTerrain(parameters) and there should be a a couple of methods to do that. At the moment I have:

  1. CreateMeshTerrain
  2. CreateHeightMapTerrain
  3. ???

And when you have the returned Chunk you can modify it by:

  1. Adding normal and specular maps
  2. Adding static objects such as trees, rocks and more scene object that the user like to add.

Then you want to add the chunk to the game and here is what I need some help.

Because there are multiple ways of dealing with terrains. One way is to have one large chunk that is your world however in most cases that will not work. Lets say you want to create a Open World game. Well good luck on that. With some research I found that a common method is to scroll the terrain chunks with you.

000
010
000

By using 9 chunks where the 0 represent a distant chunk and the 1 is the chunk the player is on.

When the player steps over to a 0 new terrain are created and some terrain are destroyed to keep the player at the middle chunk.

Do you have any suggestions on how I should set up the terrain?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants