-
Notifications
You must be signed in to change notification settings - Fork 86
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
Ray-casts do not support face_index
#702
Comments
I'm wondering if this feature is still not planned to be supported, since this is an important feature to have especially if you have a surface property index per mesh triangle.
Assuming that the actual vertex count/positions remain the same, would it not be possible to create a mapping between the original vertices and the indexed vertices? I don't really see how the input mesh could differ from the (optimised?) mesh apart from re-indexed vertices. The triangle index of a godot physics mesh is (roughly, this function probably has issues) int(index/3), since the whole mesh is just a 1D buffer of vertices. Actually that probably wouldnt work since the vertex buffer could be any size. Wouldn't the offset value of the current index correspond to the original index though? As far as I understand, if a mesh has n vertices (before indexing), there has to be n indices after it gets indexified. Even though the value stored at Index[i] corresponds to a position from a shrunken vertex buffer, the actual position [i] should match the original vertex's index so long as no weird swapping/reordering etc occurs? |
While I believe Jolt's indexing currently preserves the same order as the input list of triangles (which is an assumption I would be hesitant about relying on since it could presumably change at any time) the thing that does throw a wrench into this is the fact that Jolt culls degenerate faces, which will obviously offset all subsequent indices. It might be that I could do the culling of degenerate faces on my end, and hang on to their indices in order to undo any such offset, but that's frankly making a lot of assumptions about Jolt's indexing, which again could presumably change at any point. In any case, this is moot so long as Jolt doesn't hang on to the actual triangle index in its The only fix I can see, without changing how this works on the Godot side of things, would be to fork/change Jolt and either repurpose/extend its existing 5-bit The change I've had in mind is to instead make a PR to Godot to add the face vertices as part of its ray-cast results. While this would largely make |
Would it make sense or be possible to have custom data channels within the physics mesh that get baked alongside the indexing process, similar to how ArrayMeshes have various buffers like position, color, custom0/1/2 etc? This might be more of a general Godot PR type deal rather than jolt specifically. Are face normals for physics meshes baked into a buffer or are they calculated at runtime?
Do you mean only returning the position values of the vertices, or the actual indices themselves which could be used to index into various buffers? There's a bit of a gap here because as far as I know Godot physics meshes aren't indexed and don't really store any data besides position data. Maybe behind the scenes Godot bakes some data like face normals etc but I'm not sure. I think what this problem is bringing up however is a solid reason to be able to store different channels in physics meshes just as you would in a render mesh. If returning a face index which corresponds to the input mesh isn't possible, I think that's okay as long as there is a way to add in more data, which is something that Godot itself will have to support. |
It doesn't really matter what you add on the Godot side of things. The only per-face properties I can provide as part of the ray-cast results is the normal, vertex positions and material index (which again is not used by this extension). Anything else I will have no choice but to leave at its default value.
They're calculated at runtime. (
Only the position values, yes.
They do calculate it behind the scenes, yes. |
Thanks for your replies. I guess it's probably much more effort than it's worth at this stage to support getting (godot) face indices. For now I've decided to just split up my multi-material physics meshes into separate meshes by collecting all tris with the same surface property index and building a new mesh shape out of them. It seems to work well, and might even improve performance a little by cutting up very large map meshes into smaller ones. |
@mihe Since we're working through the list of differences between godot physics and godot jolt now, I think there's something we can do about this:
What do you say? |
I guess that would all largely become opt-in then, even from a memory standpoint, meaning it could potentially be put behind a setting for anyone not wanting to pay the cost of this? |
Yes, it would be opt-in. The resulting MeshShape won't change. |
I think that sounds pretty reasonable. |
I changed my mind a little: https://github.com/jrouwe/JoltPhysics/tree/feature/per_triangle_user_data This simply provides a What do you think? (note code untested) |
I would say that looks much nicer from an API perspective, and obviously lines up better with the existing methods, like I'm surprised/happy to see you were able to still make it opt-in without too much hassle. |
I think this should be it: Beware that it costs up to 25% extra memory per mesh, so you may want to put this behind another project flag. |
Awesome. I'm working on it as we speak.
Yes, most definitely. |
Looks to be working well enough (#955) but I've only done some very basic testing so far. The whole Would it be too out-of-place to have some It's not a big deal or anything, but I figured you might appreciate the feedback. |
Thanks for the feedback! I think having a |
Fair enough! That all sounds reasonable to me. |
To anyone who might still be subscribing to this issue, support for Note that the release on Godot Asset Library is still pending approval, so you might need to download it from GitHub for the time being. Also note that you have to explicitly enable support for it, by enabling the |
This extension does not currently support the
face_index
field found in the result dictionary ofintersect_ray
, as seen in its documentation.This was something introduced in Godot 4.2 (godotengine/godot#71233) which lets you get the index of any face/triangle of a
ConcavePolygonShape3D
that the ray-cast hit.While Jolt does have support for getting the vertices of a particular face, there's no public interface for getting the actual triangle index of it. Even if there was, the process of "indexifying" the triangles that happens as part of creating Jolt's
JPH::MeshShape
means that any index you return from Jolt won't map to the actual list of faces originally set on theConcavePolygonShape3D
anyway, which thisface_index
thing relies entirely upon.This is unlikely to ever be supported by this extension in its current form.
The text was updated successfully, but these errors were encountered: