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

Expose set_pixel and variants #258

Closed
CsloudX opened this issue Nov 28, 2023 · 4 comments
Closed

Expose set_pixel and variants #258

CsloudX opened this issue Nov 28, 2023 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@CsloudX
Copy link

CsloudX commented Nov 28, 2023

Description

I want modify terrain when game runtime. but there was no a function for get the Image's pixel position with global_position.
Now I'm solved this problem by look at the Terrain3DEditor C++ code, but I wish can has api for GDScript.
image

Are you willing to help create this feature?

No

@TokisanGames
Copy link
Owner

There is an API. All of the get pixel variants take a global position. Why can't you use this?

ClassDB::bind_method(D_METHOD("get_pixel", "map_type", "global_position"), &Terrain3DStorage::get_pixel);
ClassDB::bind_method(D_METHOD("get_height", "global_position"), &Terrain3DStorage::get_height);
ClassDB::bind_method(D_METHOD("get_color", "global_position"), &Terrain3DStorage::get_color);
ClassDB::bind_method(D_METHOD("get_control", "global_position"), &Terrain3DStorage::get_control);
ClassDB::bind_method(D_METHOD("get_roughness", "global_position"), &Terrain3DStorage::get_roughness);

You just want a function that does the math of get_pixel without returning the pixel? But you can already write your own function for that as you have. Vec3 to vec2 image position is not useful without the region Id as well. Most people should use get_pixel. The reason you'd use the maps directly is if you want to use image.blit or fill. And in those cases you aren't recalculating the image position every pixel.

Now I'm solved this problem by look at the Terrain3DEditor C++ code

That's great, and exactly what you should be doing in both Terrain3D and Godot source when doing advanced gamedev projects.

@CsloudX
Copy link
Author

CsloudX commented Nov 28, 2023

There is an API. All of the get pixel variants take a global position. Why can't you use this?

I'm not only want get_pixel, but also want set_pixel, so I need the true pixel of image.
OR, there was get_height(global_position), can implement set_height(global_position, height)?

@TokisanGames
Copy link
Owner

I can add set_pixel easily and see it as useful.

@TokisanGames TokisanGames added the enhancement New feature or request label Nov 28, 2023
@TokisanGames TokisanGames added this to the Beta milestone Nov 28, 2023
@TokisanGames
Copy link
Owner

TokisanGames commented Nov 28, 2023

Per pixel setters have been added in 6ec4f7b.

After writing to the maps, you'll need to use force_update_maps to see changes. That won't update collision. You can disable and reenable collision, but that is slow. Dynamic collision is being worked on in #161.

image

@TokisanGames TokisanGames changed the title implement TerrainStorage.get_region_pixel_pos(global_position:Vector2)->Vector2i Expose set_pixel and variants Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants