-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 ability to get face index and barycentric coordinates from raycast #71233
Add ability to get face index and barycentric coordinates from raycast #71233
Conversation
4770b7a
to
7c0688a
Compare
0c9ce98
to
a8cf52e
Compare
Is this implemented in Godot 4 RC1? Calls to 'get_triangle_barycentric_coords' stills don't appear to work. |
Darn, I just noticed that it is still pending review before merging. Sure hope it gets merged soon. But I guess it's going to have to wait for Godot 4.1 now? |
@thismarty I can't find a related/similar feature in the RC1 release notes. The barycentric coordinate function still works for me. |
Unfortunately so, I guess. Kind of a shame, though. This has been open and ready to merge for a while now. But I did open this after the feature freeze. |
Dangit. Oh well, thanks a bunch for implementing it - it will be very useful once merged! |
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.
This looks fine to me. Can you rebase and test just to make sure it works with the latest code?
a26e541
to
af7f787
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.
LGTM, haven't tested so TIWAGOS but looks correct
<method name="get_triangle_barycentric_coords"> | ||
<return type="Vector3" /> | ||
<param index="0" name="point" type="Vector3" /> | ||
<param index="1" name="a" type="Vector3" /> | ||
<param index="2" name="b" type="Vector3" /> | ||
<param index="3" name="c" type="Vector3" /> | ||
<description> | ||
Returns a [Vector3] containing weights based on how close a 3D position ([param point]) is to a triangle's different vertices ([param a], [param b] and [param c]). This is useful for interpolating between the data of different vertices in a triangle. One example use case is using this to smoothly rotate over a mesh instead of relying solely on face normals. | ||
[url=https://en.wikipedia.org/wiki/Barycentric_coordinate_system]Here is a more detailed explanation of barycentric coordinates.[/url] | ||
</description> | ||
</method> |
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.
This should likely mention:
- what's a valid input (
a
,b
,c
forming a triangle andpoint
being coplanar with theabc
triangle), - what's the behavior for an invalid input (
a
,b
,c
not forming a valid triangle, orpoint
being not coplanar with theabc
triangle).
(But it's a non-blocker, can be improved later, separately)
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.
Let's delegate this to a follow-up. This has been cooking long enough :)
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 can open a new PR for this. Does an issue need to be created?
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.
@PrecisionRender No, just link back to this comment discussion and the PR
Thanks a lot! |
Yay I can already see uses for this <3 |
AWESOME! Can't wait so see this feature implemented in Godot. Now it's just a matter of time before someone recreates an F-Zero style game in Godot. |
I am rather thinking of doing shadow detection this way (instead of raycasting towards the sun) :) |
@Corruptinator Already implemented. It should be fully ready for the 4.2 release. 😁 |
Oh, that is a good point @Zireael07. You're right. So many uses for Barycentric Coordinates. |
This PR seems to have introduced a breaking change to GDExtension without anyone realizing. Any changes to godot/servers/physics_server_3d.h Lines 151 to 159 in f7bc653
godot/servers/register_server_types.cpp Line 160 in f7bc653
... which would likely trigger a I'm not sure there's a perfect way to solve this, since you're changing the format/size of the struct no matter which way you turn it, which will likely upset |
@mihe Are you saying that GDExtension API is sensitive to the order of elements we return in |
There is no As of right now, the
It is, but only if you actually make the corresponding change to the
This should obviously/ideally be dealt with in a less brittle and error-prone way, maybe using some macro magic, as opposed to typing in the layout into a string somewhere. It's not the first time this has happened, and probably won't be the last, unless this is changed. |
@mihe Could you create an issue for this so we don't lose track of it? |
Issue created, with MRP: #80444 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Understood. Sorry for the non-related message. |
Implements godotengine/godot-proposals#4663, #684, #1903, portion of #17665
Closes godotengine/godot-proposals#4663
This PR implements a way to get the barycentric coordinates of a collision object from a ray. To do this, we return the intersected face index from a
ConcaveCollisionShape3D
and expose a barycentric coordinate function. This allows for the user to get much more detail from a ray than simply the collision point and normal. Check the surface alignment example below.Alignment using
RayCast
normal:wo_bary_coords.mp4
Alignment using barycentric coordinate interpolation:
w_bary_coords.mp4
Test project: Barycentric Coords Test.zip