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

Need to expose btHeightfieldTerrainShape as Godot shape for easy terrains #24548

Closed
slapin opened this issue Dec 22, 2018 · 12 comments
Closed

Need to expose btHeightfieldTerrainShape as Godot shape for easy terrains #24548

slapin opened this issue Dec 22, 2018 · 12 comments

Comments

@slapin
Copy link
Contributor

slapin commented Dec 22, 2018

@AndreaCatania how would you suggest exposing btHeightfieldTerrainShape? If that is not accepted politically I will be more than happy to keep the change local, but how do you think this could be done properly for Godot effective use? Thanks!

To others:

btHeightfieldTerrainShape is Bullet primitive shape which is built from heightmap. You can have shader-based terrain (i.e. splatmapping-based) and use this shape as collision, so characters do walk on it. So you do not need to create mesh specially for collision or manually check it every time to not fall through.
Works the same as other Bullet collision shapes. I used it in other engines and it is fast and useful even created at run time.

@Toshiwoz
Copy link
Contributor

Then I'll have to rewrite my code 😩...
But it sounds as a good improvement.
I think this can be related to @Zylann's latest commits..

@Zylann
Copy link
Contributor

Zylann commented Dec 23, 2018

It is exposed in PhysicsServer (example of usage in my plugin) but a node surely would be more user-friendly. Could be exposed with an Image property? I use 16-bit half-float for rendering but Bullet doesn't has this type so currently it is converted to either float or 8bit internally.
@Toshiwoz which commit?

See also #24390 about an issue with that shape currently

@Toshiwoz
Copy link
Contributor

@Zylann I was referrring to the following PRs:

I think you already set the premises in order to have such kind of node.

@Zylann
Copy link
Contributor

Zylann commented Dec 23, 2018

Yeah I'm just not sure how the image format should be dealt with. The only commonly supported format between Godot and Bullet that works in most cases is float, so people have to import an .exr as such as an ImageTexture just so they can both use it as image on CPU and heightmap on GPU (assuming that you want to spend the weight of that format on GPU), but there is no node supporting visualization so far so that part still needs manual work. At the same time I would find it strange to ask for a Texture while all this shape needs is an Image (or more precisely, a PoolRealArray, the image is not referenced, it is actually copied), so I don't know. Perhaps it would be that way on the node API while the PhysicsServer API offers more details.

In my plugin I included both in a single node handling those details internally anyways because so far I think it's easier to use than building the classic staticsbody/collisionshape/visualinstance by hand and linking the same image in between somehow (especially because it is editable and probably won't stay a single image in my case). In Unity they also hide this away by asking for the same TerrainData resource required by their renderer component.

That could be worth discussing too when such kind of terrain is considered for addition in the engine.

@slapin
Copy link
Contributor Author

slapin commented Dec 24, 2018 via email

@slapin
Copy link
Contributor Author

slapin commented Dec 24, 2018 via email

@slapin
Copy link
Contributor Author

slapin commented Dec 24, 2018 via email

@Toshiwoz
Copy link
Contributor

At the same time I would find it strange to ask for a Texture while all this shape needs is an Image (or more precisely, a PoolRealArray, the image is not referenced, it is actually copied), so I don't know.

@Zylann Somehow I do use a PoolRealArray as parameter instead of image or texture, I do decode that from an image first.
The reason is because heightmaps can be encoded/decoded with different tecniques, for example Mapbox uses this formula:
height= -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1)
While it seems you use only one channel
in another case (heightmap generated from NoiseTexture) I used the sum of the 3 channels, and I'm quite sure out there there are several other ways to encode/decode height data.

So it actually does make sense to use something more specific than a texture, and maybe by adding another layer that actually decodes images into a PoolRealArray. For example add a string parameter with the decoding formula, and then have it evaluated internally.

Hope this makes sense to you.

BTW, in the latest patreon vote PCG have taken some attention:
https://www.patreon.com/posts/november-2018-23510558

@Zylann
Copy link
Contributor

Zylann commented Dec 24, 2018

@slapin after investigating the issue I linked earlier, I also found that processAllTriangles function, so I could also work on supporting holes because my plugin also supports that by packing the last bit of the alpha channel in the color map (the rest of alpha being used for AO), and can be stored in RAM as a bitmap for physics.
I would also need to expose the triangle layout setting because I use diamond tiles instead of zigzag tiles (because less orientation artifacts).

@OBKF
Copy link
Contributor

OBKF commented Dec 25, 2018

This looks interesting, I am following this.
By the way @Zylann your terrain plugin is amazing :D .

@bojidar-bg
Copy link
Contributor

I think the Heightmap shape is now implemented when using Bullet, correct?

@clayjohn
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants