Skip to content

Commit

Permalink
feat: upgrade to Blender 4.1 bone collections
Browse files Browse the repository at this point in the history
  • Loading branch information
anasrar committed Mar 27, 2024
1 parent ca9560a commit ce2a1c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ReNimNode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"name": "ReNim Node",
"author": "Anas Rin",
"description": "Node-Based Retarget Animation",
"blender": (3, 6, 0),
"version": (0, 1, 3),
"blender": (4, 1, 0),
"version": (0, 1, 4),
"location": "Editor Type > Retarget Animation Node",
"warning": "",
"wiki_url": "https://github.com/anasrar/ReNim", # 2.82 below
Expand Down
10 changes: 5 additions & 5 deletions ReNimNode/production/node_mapping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import bpy
from bpy.types import Node
from bpy.types import BoneCollection, Node
from bpy import props
from nodeitems_utils import NodeItem, register_node_categories, unregister_node_categories
from bpy.utils import register_class, unregister_class
Expand Down Expand Up @@ -101,7 +101,7 @@ class ReNimNodeMappingBone(ReNimNode, Node):

old_update: props.BoolProperty(default=False) # type: ignore

def add_bone(self):
def add_bone(self, bone_collection: BoneCollection):
# get object socket
socket = self.inputs[0].links[0].from_socket

Expand Down Expand Up @@ -147,9 +147,9 @@ def add_bone(self):
mimic_target_bone.hide_select = True
mimic_source_bone.hide_select = True

# set layer bone
mimic_target_bone.layers = [(index == 31) for index in range(32)]
mimic_source_bone.layers = [(index == 31) for index in range(32)]
# add to bone collection
bone_collection.assign(mimic_target_bone)
bone_collection.assign(mimic_source_bone)

# get target and source rotation (quaternion)
rotation_target_bone = target_bone.matrix.to_quaternion()
Expand Down
11 changes: 10 additions & 1 deletion ReNimNode/production/node_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ def bind(self, context: Context, operator: Operator):
# disbale mirror for preventing symmetrize bone
bpy.context.active_object.data.use_mirror_x = False # type: ignore

# create new bone collections
bone_collection = bpy.context.active_object.data.collections.new( # type: ignore
"ReNimHelperBones")
bone_collection.is_visible = False

for node in bone_nodes:
node.add_bone()
node.add_bone(bone_collection)

# change mode to pose to add constraint and driver only on valid bone
# commented becuse we don't really need to switch mode to pose
Expand Down Expand Up @@ -175,6 +180,10 @@ def unbind(self, context: Context, operator: Operator):
node.use_custom_color = False
node.is_bind = False

# remove bone collections
collections = bpy.context.active_object.data.collections # type: ignore
collections.remove(collections.get("ReNimHelperBones"))

# change mode back to object
bpy.ops.object.mode_set(mode="OBJECT")

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
autopep8==2.1.0
fake-bpy-module-3.6==20231118
fake-bpy-module-4.0==20231118
nodeenv==1.8.0
pycodestyle==2.11.1
pydocstyle==6.3.0
Expand Down

0 comments on commit ce2a1c2

Please sign in to comment.