How to modify dynamically a mesh ?

Hello everyone,

I generate meshes for my terrain, which combine two textures: one for the terrain type and one for the road network (when there is a road). The road network will evolve during the game (not each frame obviously, but from time to time) and I was thinking of the best way to implement that.

Here is what I plan to do : I could subdivide my tile map in areas of 10 x 10 or 20 x 20 tiles and generate a mesh for each area. Then, when I change the road network, I have to check which areas are concerned, get the corrisponding UVs arrays, modify the UVs values of the specific tiles and then reset the concerned mesh(es) UVs. With the tile coordinate, I should be able to get the correct index in the UVs array, so it shouldn’t be so long. Thanks to the subdivisions, I don’t have to reset the UVs of the whole terrain (the map is 200 * 200 tiles and could be bigger in the end, around 256 * 256).

If I go that way, what do you think would be the optimal size of the areas ? At the start, road network is around 10 % of the total of tiles ; at the end, probably around 20%.

Is there a better way to do that ?

Thans for your help !

Hello @Gian1983 ,

The optimal size for the areas depends on the amount of geometry, textures, and other assets that you have in each area.

Also depends on the target platform that you want your project to build and run.

The best thing that you can do is to create placeholder test areas with more or less the amount of geometry, textures, and other assets that your project will more likely have in his final version. Then you can test, using the Unity Profiler to change the size of your areas accordingly.

Depending on the complexity of your project you can also use different LOD (levels of detail) for each area, depending on the distance of such areas with the camera.

On the other hand, probably the best solution for a system like yours, where you have to change dynamically some of the areas, is by creating in advance all the possible variations of such areas to just switch between them in runtime.

This approach is not the best one if you can’t have your variations ahead of time or if the number of variations is too high.

Good luck with your project!

Thanks for your advice !

1 Like