Godot 3.0 Map Loader is (almost) ready!

I’ve been working on some refinements in order to have this plugin work as best as it could (I even tried to customize the upcoming Godot 3.1!).
So let’s get started.

Adding Collision Shape

That was quite easy actually, even if, I have to say, as I am testing it with a vehicleI find sometimes an ‘invisible’ obstacle that makes the vehicle stop, or sometimes flip (it feels more or less like an invisible rock placed on the ground).

Anyways, in order to do that I had to use this code:

To explain it a little bit:

  • $TerrainMesh is the mesh generated from heightmap
  • $TerrainCollision is the collision shape that we want to generate from the mesh

So it’s very simple, the only thing I’m not sure is if ConcavePolygonShape is actually the type of shape I should use, as some areas are actually convex.

Mesh rendering improvements

Since the first article about this addon I was able to improve the rendering of the tile mesh when I finally realized how to use add_smooth_group function.

I also modified the mesh generation using a triangle fan, overall performance allow to generate much faster, around 2.5 seconds per tile on my old laptop.

Drawing a regular and a “compressed” triangle fan

The cool thing is that would also allow me to save some vertices when height change is linear. What I mean by that is that the triangle fan is drawn as in the pucture here, starting from the center you draw 8 triangles each one shares the center vertex, now each vertex has a different height, but the top, bottom, left and right vertex (numbered 3, 7, 9, 5) can even be skipped if height changes linearly, for example:


Vertex 2
Vertex 3
Vertex 4
Example 1
20m
30m40m
Example 2
0m
0m0m
Example 3
20m
25m
15m

In the table above, example 1 and example 2 can skip vertex 3, as the change is linear, so it does not affect the representation of the mesh.

Skipping a triangle can make the mesh smaller and likely reduce rendering time and memory usage.

Threads

One annoying thing I was experiencing while developing was Godot freezing while generating the mesh. I use threads when I develop in C# but not in Godot, so I wanted to try it and found out a couple of things..

First attempt was a failure, the process launched.. but nothing happened, not even an error or warning message, so I googled, better, I checked on the Q&A section of Godot (a quite useful source of information), and found out that is yet under discussion if is a bug or not(here): you have always to declare a parameter to the function you call in a separate thread, also, you have to use only one parameter (being empty or an array of sub-parameters).

Well, apart from that, it worked! And I like the fact that now I can still use the editor while downloading the tile, the only thing is that on threads the process seems to be slower.

Todos and limitations

Texture painting, height map editable and normal maps

As I got a better machine (still, not a high end pc, but good enought for now), I decided to test also other’s addons that are similar, like Zylann’s HTerrain, a cool feature it has is that you can edit the terrain, paint it, and probably other features I havent seein yet. Well, I believe my module would benefit by having such a series of features, who knows, one day I’ll take my time to do something similar.

Lod, alignment of different zoom level tiles

Also I can’t yet position tiles of different zoom levels, neither I have LOD implemented. But as Godot will become more mature, and get new features that would become easier to implement.

Smooth betweel tiles

If you test my addon you may realize that there is a line that clearly separates the meshes, that is undesirable side effect due to the fact that smooting would work only on a single mesh, maybe normal maps may solve that?

World is not flat

On high zoom levels it’s ok to have flat tiles, but when zooming out world should not, as we know world is spherical (not quite, but almost).

I tried to implement that, but I had problems with precision and speed. So for now the code is there but not used (and needs a lot of cleanup).

Testing with an (almost) real life example

Well, I wanted to test it, and it came to my mind to use a vehicle, so I spent quite a while importing the blender model into Godot, and then tweak the vehicle parameters.

That was the hard part, and well, I also took the occasion to test it on Godot 3.1 (a custom build I made), but, well, it has some problems, so I switched back to 3.0 and finally some acceptable result here.

The bad thing I discovered is that just by adding 9 tiles (resized almost to a realistic size compared to the car), it took more than a minute to load the “level”. By creating the mesh dynamically (instead of storing it as a file) it would have taken about 20-30 seconds to render the 9 tiles, it may be worth to test that for an eventual new version of the addon.

Here you can see how a vehicle interacts with the terrain generated.

Credits:

Thanks to 3DHaup for the free 3D mode he made available to anyone wanting to use it. And of course to SketchFab.

You can test the addon yourself by downloading the addon from the Github repo (instructions in the readme).

Posted in 3D, Game Development and tagged , , , .

2 Comments

  1. Hi,
    I am working on a similar project in order to get used with godot, and I encountered the same behavior with car colliding against invisible obstacles. Even with a totally flat map

    Did you find a solution since you post this ?

    Thanks

  2. Hi, actually no, I still haven’t done anything about it.
    If I’m not wrong I also remember someone say that it doesn’t work with triangle fan.
    You can try using trimesh for collision shape, eventually.
    I’m working on a new version that does not use triangle fans and once done I’ll test collisions again. It might also be that after that I’ll migrate to Godot 3.1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.