-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add HeightMapShape3D update with Image data #87889
Conversation
Great feature, it would be even better if the HeightMapShape3D could be updated partially from the height map image. |
57f077c
to
04858d4
Compare
04858d4
to
d454912
Compare
dfbc6d6
to
90ee092
Compare
Added error msgs and support for the lower precision formats @Redwarx008 Partial updates (and reads) should be also made available, not only for the image but also for the normal byte array. I will see what I can do but that deserves its own pr. |
5588463
to
d2722cc
Compare
8ed22fc
to
c207190
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally (rebased on top of master
29b3d9e), it works as expected.
Testing project: test_pr_87889.zip
DEV_ASSERT(pixel_value >= 0.0 && pixel_value <= 1.0); | ||
|
||
real_t height_value = Math::remap(pixel_value, 0.0f, 1.0f, remap_height_min, remap_height_max); | ||
|
||
if (height_value < new_min_height) { | ||
new_min_height = height_value; | ||
} | ||
if (height_value > new_max_height) { | ||
new_max_height = height_value; | ||
} | ||
|
||
map_data_ptrw[i] = height_value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this code can be moved below the switch
statement, and have the default
branch use return
instead. This way, we can avoid repetition in the 2 branches below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not easily, the way pixel_value
is calculated depends on the data type, and it needs to be calculate in the for
loop for each index.
Adds HeightMapShape3D update with Image data.
Thanks! |
Adds
HeightMapShape3D
update withImage
data.Populating height values in a heightmap collision from an image file is a common use.
It shouldnt be required that users need to read large image data arrays with slow scripts to achieve this basic thing.
So what this pr does is add
update_map_data_from_image()
as a new function toHeightMapShape3D
.The function allows a single component black&white Image in format
FORMAT_RF
(32 bit) orFORMAT_RH
(16 bit) orFORMAT_R8
(8 bit) as input and to define a minimum and maximum height range. The image pixel values read in0.0
to1.0
range are then remapped to those values.The code for this was actually found in part on the PhysicsServer3D as more or less dead-code not reachable by users. It also makes far more sense to have this functionality on the collision shape directly to update the
map_data
. This data array is commonly used for other related stuff, like creating procedual meshes from the heightmap data.Full usage example to create heightmap collision from an image file: