BlenderProc icon indicating copy to clipboard operation
BlenderProc copied to clipboard

Convex decomposition physics cannot be disabled

Open simon-lgb opened this issue 1 year ago • 3 comments
trafficstars

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 avatar Jun 07 '24 15:06 simon-lgb

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")

cornerfarmer avatar Jun 17 '24 08:06 cornerfarmer

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?

simon-lgb avatar Jun 17 '24 09:06 simon-lgb

Hey @simon-lgb,

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

cornerfarmer avatar Jun 18 '24 08:06 cornerfarmer