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

Fix collision reposition with CSGShape3D #102286

Conversation

ryevdokimov
Copy link
Contributor

Fixes: #102274

2025-02-01.18-11-56.mp4

@ryevdokimov ryevdokimov requested review from a team as code owners February 1, 2025 14:15
@AThousandShips AThousandShips added this to the 4.4 milestone Feb 1, 2025
@akien-mga akien-mga requested review from fire and KoBeWi February 6, 2025 00:38
@ryevdokimov ryevdokimov force-pushed the fix-collision-reposition-csgshape branch from 6bd9d28 to 468cbf7 Compare February 6, 2025 17:19
@ryevdokimov ryevdokimov requested a review from a team as a code owner February 6, 2025 17:19
@ryevdokimov ryevdokimov force-pushed the fix-collision-reposition-csgshape branch 2 times, most recently from 2cf3f05 to 054b6eb Compare February 6, 2025 17:47
Comment on lines 4388 to 4390
if (node->is_class("CSGShape3D")) {
rids.insert(node->call("get_root_collision_instance"));
}

Copy link
Member

@fire fire Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still breaking encapsulation. I remember we may have added call back functions to override, but I don't remember.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No such function is used here, so probably it does not exist, or is for something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSG collision shapes from what I can tell are unique in how they're generated by having the parent hold the identity of the collision resource. Somehow which behavior is being used needs to be identified and the RIDs retrieved that way. Currently not seeing any obvious way to do that, but I'll keep thinking about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no expert in the matter but I faced a similar problem in #101368. Maybe one idea could be to add some kind of get_collision_rid method in VisualInstance3D that returns an empty RID and overload it in CsgShape?

Copy link
Contributor Author

@ryevdokimov ryevdokimov Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe one idea could be to add some kind of get_collision_rid method in VisualInstance3D

Adding a method for getting collision related data in a class meant only for visual things seems strange to me, and I'm not sure much better than breaking encapsulation in this scenario. I'm opened to second opinions though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would likely go in GeometryInstance3D I think, and not VisualInstance3D? (The former inherits the latter.)

Collision data in geometry is slightly more related I suppose.

But yeah I don't see an easy/clean solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that would be marginally better, but still is it worth muddying up the classes to handle niche cases like this? I just don't want a precedent to be set that might end up making things confusing down the future. I feel like the real solution to this is something more fundamental that I can't pin down quite yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's go with the local hack for now and see if we find a better architecture later.

Copy link
Contributor Author

@ryevdokimov ryevdokimov Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment in the code to point out this is a hack. I do plan on developing this snapping idea further, see: #100415 for example, so maybe something will hit me in the head during the process.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

Testing project: test_pr_102286.zip

Note that it won't work if the CSGBox you're moving is a child of the CSGCombiner3D with the collision on it. It will just pass through instead:

test_csg_reposition.mp4

This may be difficult to resolve though, given the collision shape is regenerating itself in real-time when you're moving the object (and you don't want the object to collide with itself as you're repositioning it).

PS: I noticed that we can pan, zoom and orbit while using physics-based repositioning, but not when using the translate/rotate/style Blender-style manipulation shortcuts. It would be good to look into unlocking those options if they don't conflict with anything else (in a separate PR).

@ryevdokimov ryevdokimov force-pushed the fix-collision-reposition-csgshape branch from 054b6eb to 708e2c8 Compare February 13, 2025 04:57
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't test, but the code looks ok.

@ryevdokimov ryevdokimov force-pushed the fix-collision-reposition-csgshape branch from 708e2c8 to 6f0a0ba Compare February 13, 2025 15:32
@Repiteo Repiteo merged commit b853ace into godotengine:master Feb 13, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Feb 13, 2025

Thanks!

@ryevdokimov ryevdokimov deleted the fix-collision-reposition-csgshape branch February 13, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reposition Using Collisions bug Godot v4.4
8 participants