DLR-RM / BlenderProc

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

[BUG]: physics simulation changes type of blender object #331

Closed domef closed 2 years ago

domef commented 2 years ago

Describe the bug After the physics simulation, the property blender_obj of blenderproc.python.types.LightUtility.Light object changes type from bpy_types.Object to bpy.types.PointLight.

General Information

  1. Which BlenderProc verison are you using? 2.0.0a6.

  2. On which operating system are you? Ubuntu 18.04.

  3. Have you checked the issue tracker to see if a similar issue has been opened? Yes.

  4. Have you changed BlenderProc in anyway besides the config file? If yes, are you sure that this change does not affect the problem you are having? No.

To Reproduce This is a minimal code example:

import blenderproc as bproc

bproc.init()

plane = bproc.object.create_primitive("PLANE")
plane.enable_rigidbody(active=True, collision_shape="CONVEX_HULL")
cube = bproc.object.create_primitive("CUBE", location=[0, 0, 2])
cube.enable_rigidbody(active=True, collision_shape="CONVEX_HULL")

light = bproc.types.Light(name='Light')

print(type(light.blender_obj))

bproc.object.simulate_physics_and_fix_final_poses(min_simulation_time=1, max_simulation_time=4, check_object_interval=1)

print(type(light.blender_obj))

This is the the output:

Warning: Changed install path from /home_local/federico... to /home/federico..., there is no /home_local/ on this machine.
Using blender in /home/federico/blender/blender-2.93.0-linux-x64
Using temporary directory: /dev/shm/blender_proc_46cdfaa74fcc4108930c8fef7ff279b5
Blender 2.93.0 (hash 84da05a8b806 built 2021-06-02 11:29:24)
Read prefs: /home/federico/.config/blender/2.93/config/userpref.blend
Looking in links: /tmp/tmpv87gmb70
Requirement already satisfied: setuptools in /home/federico/blender/blender-2.93.0-linux-x64/2.93/python/lib/python3.9/site-packages (49.2.1)
Requirement already satisfied: pip in /home/federico/blender/blender-2.93.0-linux-x64/2.93/python/lib/python3.9/site-packages (21.3.1)
Requirement already satisfied: pip in /home/federico/blender/blender-2.93.0-linux-x64/2.93/python/lib/python3.9/site-packages (21.3.1)
Device NVIDIA GeForce RTX 2080 Ti of type OPTIX found and used.
<class 'bpy_types.Object'>
Running simulation up to 1 seconds (24 frames)
bake: frame 1 :: 24
...
...
...
bake: frame 48 :: 48
Objects have stopped moving after 2  seconds (48 frames)
<class 'bpy.types.PointLight'>

Blender quit
Cleaning temporary directory

Since after the simulation the blender_obj is a different type I cannot access to the same functions and properties.

themasterlink commented 2 years ago

Hey,

before I check this out, amazing bug report!

Best, Max

cornerfarmer commented 2 years ago

Hey @domef,

thanks for reporting this bug. It should be easily solvable by removing this function: https://github.com/DLR-RM/BlenderProc/blob/main/blenderproc/python/types/LightUtility.py#L29-L34

This function is called, each time an undo operation is executed (e.q. in the physics simulator). As after an undo, all blender references become invalid, we have to reassign them. Apparently for Lights that reassignment did not work properly. By removing the function, the parent function from the Entity class should now be used which is also correct for light objects.

Let me know if you experience any further problems.

themasterlink commented 2 years ago

This is fixed with 2.1.0