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

modify terrain data in real-time with code,like:gdscript、c# #526

Closed
whutwxn opened this issue Oct 16, 2024 · 6 comments
Closed

modify terrain data in real-time with code,like:gdscript、c# #526

whutwxn opened this issue Oct 16, 2024 · 6 comments

Comments

@whutwxn
Copy link

whutwxn commented Oct 16, 2024

Description

How can we create 3D terrain, modify terrain data in real-time, and modify textures through code? Do you have any example code

@whutwxn
Copy link
Author

whutwxn commented Oct 16, 2024

The file(CodeGenerated.gd) code writing is too simple

@TokisanGames
Copy link
Owner

The API is full of documentation on how to do this. Please spend more time reading through it. e.g.

Ask on discord for specific help.

@TokisanGames
Copy link
Owner

Let us know if you have specific questions and join us on discord.

@TokisanGames TokisanGames closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2024
@whutwxn
Copy link
Author

whutwxn commented Oct 18, 2024

When I update the height map and control map in real-time in the game to ensure real-time map drawing, the FPS of the game drops directly to around 10, but the CPU, GPU, and memory usage are not very high. What is the reason for this?

@whutwxn
Copy link
Author

whutwxn commented Oct 18, 2024

image
this is the code

@TokisanGames
Copy link
Owner

  • If you have collision enabled, updating the heightmap is rebuilding the collision for every region, which is slow. Disable collision generation for testing at least. Dynamic collision WIP: Make collision generation dynamic #278 will alleviate this.
  • You don't need to set_pixels and most definitely should not be force_updating_maps hundreds of times per second. Switch to physics_process for pixel updates at 60fps. And update maps no more than 6-10x/second which can be achieved with a basic timer at 0.1 seconds.
  • It's faster to access and write to the image maps directly rather than using set_pixel. This should be done when accessing a large number of pixels, and certainly if you're doing it hundreds of times per second. https://terrain3d.readthedocs.io/en/latest/docs/collision.html#query-many-heights
  • It's clear you're using _process as your main driver, but you should rarely use _process. Your structure needs a redesign. Updates on timer like I mentioned, stop doing redundant things like checking variables and using set_pixel for the same values hundreds of times per second. Verify things only at the start of an operation, then only perform data writes in the loop. Then batch map updates periodically. _process is a loop and you're using it poorly which gives you terrible performance.

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