zju3dv / EasyMocap

Make human motion capture easier.
Other
3.43k stars 439 forks source link

uptade the file convert2bvh.py for the for change of Blender API #403

Closed Lilien86 closed 1 month ago

Lilien86 commented 3 months ago

Blender Script API Changes Documentation

This message outlines the specific updates made to a Blender script, highlighting the adaptations to the latest recommended practices by Blender's API. The changes are detailed line by line, reflecting the modifications from the previous version to the newer one.

Object Selection and Deletion

Before:

bpy.data.objects['Cube'].select = True

After:

bpy.data.objects['Cube'].select_set(True)

This change updates the method for selecting objects to select_set(True), replacing the deprecated .select property. It ensures compatibility with newer versions of Blender.

Active Object Setting

Before:

scn.objects.active = cam_ob

After:

bpy.context.view_layer.objects.active = cam_ob

The method for setting the active object has been updated to use bpy.context.view_layer.objects.active, aligning the script with changes in Blender's API for better compatibility.

Render Passes Update

Before:

scn.render.layers["RenderLayer"].use_pass_vector = True
scn.render.layers["RenderLayer"].use_pass_normal = True

After:

bpy.context.view_layer.use_pass_vector = True
bpy.context.view_layer.use_pass_normal = True

Render passes are now directly set on bpy.context.view_layer instead of using scn.render.layers["RenderLayer"]. This aligns the script with Blender API changes regarding render layer and pass management.

Global Object Selection and Active Object Reset

Before:

for ob in bpy.data.objects.values():
    ob.select = False
bpy.context.scene.objects.active = None

After:

for ob in bpy.data.objects.values():
   ob.select_set(False)
bpy.context.view_layer.objects.active = None

These modifications also reflect the updated methods select_set(False) for global object selection and resetting the active object using the current view_layer. This ensures better integration with Blender's layering system and avoids deprecated methods.

Scene Update

Implicit Before:

scene.update()

After:

bpy.context.view_layer.update()

Although not explicitly shown in the provided snippets, the implicit replacement by bpy.context.view_layer.update() in the new version complies with recommended practices for refreshing the scene and state after programmatic changes in Blender.

These updates make the script compatible with recent versions of Blender, aligning it with current recommended practices for interacting with the Blender API.