Open slapin opened 3 years ago
VoxelInstancer automatically removes instances when the chunks corresponding to their associated LOD are unloaded.
That said, as I mentionned in an earlier issue, you don't have to use VoxelInstancer to spawn road segments. You are free to use your own chunking system layering on top of the terrain, especially if you know the line database in advance. Systems don't have to be intertwined (depends how you do yours tho). Mixing them together can be harder because the use cases are significantly different. Roads are not instances at all, they are unique geometry. The only part that needs interaction with the terrain is flattening/riverbeds, which relates to voxels, not instances, and can be integrated to a custom voxel generator I think.
Well, I need VoxelInstancer to place things properly though, I mostly want to know LOD level from it and when to spawn/despawn things. So basically It seems like I need to use custom VoxelInstancer for life cycling I guess...
Road elements are not too unique except for intersections because re-generation all the time seems to be waste of CPU power... Also Godot's way with vertex buffers is not too friendly to be heavy with procedural generation. Anyway, I tried generating the whole thing, it is fast but Godot can't cull it, so still need to build from chunks. Basically I thought about making road segments correspond to terrain chunks they are on and when all the chunks are gone, the segment will go to, the problem is placement of such segment requires knowledge of nonexistent geometry so for now I got to have only segments which can belong to only one chunk most of time, but sometimes in corner cases it belongs to two.
Was also thinking that I could update road map using data from voxel generators but place only complete roads (where both of segment's vertices are complete) but that leaves too many incomplete segments... also there are corner cases of terrain rising too much between the segment ends which leads to unrealistic road... So I found with current system the shorter the better, so I split segments.
Well, I need VoxelInstancer to place things properly though, I mostly want to know LOD level from it and when to spawn/despawn things.
Yes, and what I said was, you can do all this yourself with a different chunk system. Just because a part of VoxelInstancer does this does not mean you have to fit something that also uses it but for a totally different use case (I was even wondering myself if I could separate VoxelInstancer completely at some point). You can continue doing it, I'm just telling you it's not the only way to do what you want. "divide and conquer" approach: it's the theory that it's easier to reason with two independent systems with a bit of redundancy but less complexity, than with one complex system. Also this module deals with 3D chunks. It doesnt seem like a fitting structure for a road system, so you have to deal with that extra complexity to decide which ones correspond to the road chunks.
the problem is placement of such segment requires knowledge of nonexistent geometry
That's exactly where I said "you may know road segments in advance" is important. Sounds like you don't know it all in advance then?
for now I got to have only segments which can belong to only one chunk most of time, but sometimes in corner cases it belongs to two.
My idea on this is to transform road data before it can be spawned. Divide roads into segments and fit them into chunks. It's ok if not all of it fits exactly within a chunk, but in any case it is much easier to associate with one chunk only. The less you need to access neighbors, the better.
also there are corner cases of terrain rising too much between the segment ends which leads to unrealistic road...
That's where custom generator with flattening comes in place. The generator must access road data to flatten ground or make tunnels where segments are passing through. So basically I think of roads as a two-part problem: 1) modify voxel generation to make room for them, 2) place their meshes with either instancer or a chunking system of your own. Both will then line up without interacting with each other because they may use the same database of road data.
As for this issues's topic, it seems we are talking about the same things over and over, not just about despawning chunks. You have now 3 issues open discussing the same topics with varying titles, I think this needs cleanup xD
But these talks are of astonishing use to me, thanks a lot for the ideas and support! Now I have a plan!
Is it possible for VoxelInstancer to know when the chunk is removed/despawned? The problem is the following:
I have a line segment database which I use to build road map on terrain. Some segments might correspond to several chunks (because life is not perfect) and I mark them as already spawned to be not spawned again by incrementing use counter. But when chunks go I want to decrement use counters for them and despawn on 0. How can I do this?