DLR-RM / BlenderProc

A procedural Blender pipeline for photorealistic training image generation
GNU General Public License v3.0
2.64k stars 437 forks source link

Convex decomposition physics cannot be disabled #1111

Open simon-lgb opened 3 weeks ago

simon-lgb commented 3 weeks ago

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

cornerfarmer commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

Hey @simon-lgb,

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