diff --git a/.github/workflows/blenderprochelper.yml b/.github/workflows/blenderprochelper.yml index 6b7e91358..8cb45d47e 100644 --- a/.github/workflows/blenderprochelper.yml +++ b/.github/workflows/blenderprochelper.yml @@ -12,7 +12,7 @@ jobs: - name: Run BlenderProcHelper run: python /home/$USER/workspace/BlenderProcHelper/github_action.py - name: Archive logs - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: logs - path: artifacts \ No newline at end of file + path: artifacts diff --git a/blenderproc/__init__.py b/blenderproc/__init__.py index cf20a8174..a7d1d8812 100644 --- a/blenderproc/__init__.py +++ b/blenderproc/__init__.py @@ -9,14 +9,14 @@ if is_using_external_bpy_module(): try: import bpy - if bpy.app.version[0] != 4 and bpy.app.version[1] != 2: - raise RuntimeError("\n###############\nUSE_EXTERNAL_BPY_MODULE is set, but bpy module is not from Blender 4.2.\n\tpip install bpy==4.2.0\n###############\n") + if bpy.app.version[0] != 4 and bpy.app.version[1] != 4: + raise RuntimeError("\n###############\nUSE_EXTERNAL_BPY_MODULE is set, but bpy module is not from Blender 4.4.\n\tpip install bpy==4.4.0\n###############\n") print(f"BlenderProc is using external 'bpy' ({bpy.app.version_string}) module found in the environment.") # If we successfully imported bpy of correct version, we can signal that we are in the internal blender python environment os.environ.setdefault("INSIDE_OF_THE_INTERNAL_BLENDER_PYTHON_ENVIRONMENT", "1") except ImportError: - raise RuntimeError("\n###############\nUSE_EXTERNAL_BPY_MODULE is set, but bpy module could not be imported. Make sure bpy module is present in your python environment.\n\tpip install bpy==4.2.0\n###############\n") + raise RuntimeError("\n###############\nUSE_EXTERNAL_BPY_MODULE is set, but bpy module could not be imported. Make sure bpy module is present in your python environment.\n\tpip install bpy==4.4.0\n###############\n") # check the python version, only python 3.X is allowed: diff --git a/blenderproc/python/loader/BlendLoader.py b/blenderproc/python/loader/BlendLoader.py index f24aed88b..2dbb566f2 100644 --- a/blenderproc/python/loader/BlendLoader.py +++ b/blenderproc/python/loader/BlendLoader.py @@ -79,14 +79,15 @@ def load_blend(path: str, obj_types: Optional[Union[List[str], str]] = None, nam # Find the maximum frame number of its key frames max_keyframe = -1 if obj.animation_data is not None: - fcurves = obj.animation_data.action.fcurves - for curve in fcurves: + strip = obj.animation_data.action.layers[0].strips[0] + channelbag = strip.channelbag(obj.animation_data.action_slot, ensure=True) + for curve in channelbag.fcurves: keyframe_points = curve.keyframe_points for keyframe in keyframe_points: max_keyframe = max(max_keyframe, keyframe.co[0]) # Set frame_end to the next free keyframe - bpy.context.scene.frame_end = max_keyframe + 1 + bpy.context.scene.frame_end = int(max_keyframe + 1) else: # Remove object again if its type is not desired bpy.data.objects.remove(obj, do_unlink=True) diff --git a/blenderproc/python/utility/InstallUtility.py b/blenderproc/python/utility/InstallUtility.py index a25450698..694723c29 100644 --- a/blenderproc/python/utility/InstallUtility.py +++ b/blenderproc/python/utility/InstallUtility.py @@ -85,9 +85,9 @@ def make_sure_blender_is_installed(custom_blender_path: Optional[str], blender_i blender_install_path = "blender" # Determine configured version - # right now only support blender-4.2.1 - major_version = "4.2" - minor_version = "1" + # right now only support blender-4.4.3 + major_version = "4.4" + minor_version = "3" blender_version = f"blender-{major_version}.{minor_version}" if platform in ["linux", "linux2"]: blender_version += "-linux-x64" diff --git a/blenderproc/python/utility/Utility.py b/blenderproc/python/utility/Utility.py index d71fe3435..f8fab4a21 100644 --- a/blenderproc/python/utility/Utility.py +++ b/blenderproc/python/utility/Utility.py @@ -63,7 +63,7 @@ def reset_keyframes() -> None: """ Removes registered keyframes from all objects and resets frame_start and frame_end """ bpy.context.scene.frame_start = 0 bpy.context.scene.frame_end = 0 - for a in bpy.data.actions: + for a in list(bpy.data.actions): bpy.data.actions.remove(a) diff --git a/docs/tutorials/bpy_module.md b/docs/tutorials/bpy_module.md index e22a0d54c..97aabb19a 100644 --- a/docs/tutorials/bpy_module.md +++ b/docs/tutorials/bpy_module.md @@ -5,7 +5,7 @@ BlenderProc supports using `bpy` module installed from pip. This behavior is con ## Setup 1. Set `USE_EXTERNAL_BPY_MODULE=1` in your environment -2. `pip install bpy==4.2.0` +2. `pip install bpy==4.4.0` 3. Install [required packages](#required-dependencies) 4. After `import blenderproc` call `blenderproc.init()` 5. Run your script using `python my_script.py` or `blenderproc run my_script.py` @@ -21,7 +21,7 @@ BlenderProc supports using `bpy` module installed from pip. This behavior is con Following dependencies have to be installed in your environment to allow using BlenderProc with Python `bpy` module. ``` -pip install wheel bpy==4.2.0 pyyaml==6.0.1 imageio==2.34.1 gitpython==3.1.43 scikit-image==0.23.2 pypng==0.20220715.0 scipy==1.13.1 matplotlib==3.9.0 pytz==2024.1 h5py==3.11.0 Pillow==10.3.0 opencv-contrib-python==4.10.* scikit-learn==1.5.0 python-dateutil==2.9.0.post0 rich==13.7.1 trimesh==4.4.0 pyrender==0.1.45 PyQT5 +pip install wheel bpy==4.4.0 pyyaml==6.0.1 imageio==2.34.1 gitpython==3.1.43 scikit-image==0.23.2 pypng==0.20220715.0 scipy==1.13.1 matplotlib==3.9.0 pytz==2024.1 h5py==3.11.0 Pillow==10.3.0 opencv-contrib-python==4.10.* scikit-learn==1.5.0 python-dateutil==2.9.0.post0 rich==13.7.1 trimesh==4.4.0 pyrender==0.1.45 PyQT5 ``` This is because BlenderProc does not require these dependencies directly, but the Blender it uses does. When using `bpy` package there is no Blender being installed and these dependencies become dependencies of the BlenderProc. @@ -31,11 +31,11 @@ This is because BlenderProc does not require these dependencies directly, but th ### Python version mismatch ``` -pip install bpy==4.2.0 +pip install bpy==4.4.0 Defaulting to user installation because normal site-packages is not writeable ERROR: Ignored the following versions that require a different python version: 2.82.1 Requires-Python >=3.7, <3.8 -ERROR: Could not find a version that satisfies the requirement bpy==4.2.0 (from versions: none) -ERROR: No matching distribution found for bpy==4.2.0 +ERROR: Could not find a version that satisfies the requirement bpy==4.4.0 (from versions: none) +ERROR: No matching distribution found for bpy==4.4.0 ``` Using BlenderProc with `bpy` module from pip strictly requires Python3.11, see [Limitations](#limitations). Suggested workflow is to work with virtual environment using Python3.11. diff --git a/examples/resources/keyframed_camera.blend b/examples/resources/keyframed_camera.blend new file mode 100644 index 000000000..d38000d48 Binary files /dev/null and b/examples/resources/keyframed_camera.blend differ diff --git a/tests/testLoader.py b/tests/testLoader.py index d9971ccf0..1e4147272 100644 --- a/tests/testLoader.py +++ b/tests/testLoader.py @@ -69,3 +69,17 @@ def perform_material_checks(used_material: bproc.types.Material, used_path: Path texture = bpy.data.images.load(str(texture_path), check_existing=True) material = bproc.material.create_material_from_texture(texture, material_name="new_mat") perform_material_checks(material, texture_path) + + def test_load_camera(self): + bproc.clean_up(True) + resource_folder = os.path.join(os.path.dirname(__file__), "..", "examples", "resources") + cameras = bproc.loader.load_blend( + os.path.join(resource_folder, "keyframed_camera.blend"), + data_blocks=["objects"], + name_regrex="Camera", + obj_types=["CAMERA"] + ) + + self.assertEqual(len(cameras), 1) + self.assertEqual(bpy.context.scene.frame_end, 101) + self.assertEqual(bpy.context.scene.camera, cameras[0].blender_obj) \ No newline at end of file