TokisanGames / Terrain3D

A high performance, editable terrain system for Godot 4.
MIT License
2.14k stars 127 forks source link

Generate Collision Dynamically #161

Open TokisanGames opened 1 year ago

TokisanGames commented 1 year ago

Collision for all regions currently builds when a scene runs using the physics server.

There is a debug/show_collision option that builds collision for all regions right then, in the editor and it also works in game. This creates a static body rather than the physics server. If view gizmos is on, you can see it in the editor. You also need this if you want to enable view collision shapes in game.

Collision takes up a lot of memory and is a bit slow to generate. Each region takes 145ms to generate on my system. And running 16k x 8k collision takes about 6gb, or about 48mb per region.

What I'd like is keep the two options of build all collision at runtime, build all collision in the editor, and add dynamic options that will build a much smaller collision mesh around the camera.

The code is already structured into Terrain3D::_build_collision, _update_collision, _destroy_collision, but it's not fully setup to be dynamic yet. So most of the work will be in the middle one. It currently builds a 1025x1025 collision mesh. 1025 because we need one more vertex to get 1024 squares.

TokisanGames commented 11 months ago

I updated the plan for collision options above. set_collision_enabled should be something toggleable, which means it can just talk to the physics server in realtime. Currently it is used only to determine if collision gets built.

TokisanGames commented 2 months ago

In 4.3, HeightMapShape3D accepts inputs from a normalized image

https://github.com/godotengine/godot/pull/87881 https://github.com/godotengine/godot/pull/87889