Skip to content

Convex decomposition physics cannot be disabled #1111

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

Open
simon-lgb opened this issue Jun 7, 2024 · 3 comments
Open

Convex decomposition physics cannot be disabled #1111

simon-lgb opened this issue Jun 7, 2024 · 3 comments
Labels
first answer provided question Question, not yet a bug ;)

Comments

@simon-lgb
Copy link

simon-lgb commented Jun 7, 2024

Describe the issue

When convex decomposition parts are built for an object, disabling the rigid body does not properly work anymore. This appears to be due to the created parts objects not being removed or their rigid bodies being disabled.
This prevents the physics simulation from terminating once objects stop moving and can significantly impact performance.

Minimal code example

import blenderproc as bproc

bproc.init()

obj = bproc.object.create_primitive('MONKEY')

print("=== Testing convex hull rigid body ===")

obj.enable_rigidbody(active=True)
obj.disable_rigidbody()

bproc.object.simulate_physics_and_fix_final_poses()

print("=== Testing compound rigid body ===")

obj.enable_rigidbody(active=True, collision_shape='COMPOUND')
obj.build_convex_decomposition_collision_shape(".blenderproc")
obj.disable_rigidbody()

bproc.object.simulate_physics_and_fix_final_poses()

Files required to run the code

No response

Expected behavior

The rigid body parts should either be completely removed (would require rebuilding them if needed again later) or their rigid bodies should be disabled and potentially reenabled later.

BlenderProc version

2.7.1

@simon-lgb simon-lgb added the question Question, not yet a bug ;) label Jun 7, 2024
@cornerfarmer
Copy link
Member

Hey @simon-lgb,

thanks for the issue. You are right, disabling the object's rigidbody does not disable the rigid bodys of the components.
I am not sure there is an easy way to do this automatically.

However, disabling the childrens' rigidbodies manually definitely works:

obj.disable_rigidbody()
for child in obj.get_children():
    child.disable_rigidbody()

And for reactivating them again, do:

obj.enable_rigidbody(active=True, collision_shape='COMPOUND')
for child in obj.get_children():
    child.enable_rigidbody(True, "CONVEX_HULL")

@simon-lgb
Copy link
Author

simon-lgb commented Jun 17, 2024

Thank you for you reply, I ended up settling for a similar solution in my code.

My approach would be to set a custom property on the parts and handle your suggestions above in the method of the parent object. I would also include deleting any previous objects when a new shape is built.

Unless you consider it as too complex for the library, I could create a PR for this. In the former case, may I suggest to add a note about this behavior to the relevant method documentations?

@cornerfarmer
Copy link
Member

Hey @simon-lgb,

your approach seems good! It would be great if you could create a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first answer provided question Question, not yet a bug ;)
Projects
None yet
Development

No branches or pull requests

2 participants