Skip to content

Commit

Permalink
Merge pull request #32 from pehala/change_armature
Browse files Browse the repository at this point in the history
Create empty armature instead of a skeleton
  • Loading branch information
pehala authored Feb 25, 2023
2 parents 11c3c10 + ec1d221 commit b5505e4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 247 deletions.
7 changes: 3 additions & 4 deletions animationCombiner/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ def create_bones(armature: Armature, skeleton: Skeleton, pose: Pose, root: EditB
create_bone(armature, child, root, pose, skeleton)


def create_armature(pose: Pose, skeleton: Skeleton, name: str = "Armature"):
def create_armature(name: str = "Armature"):
"""Create the entire Armature"""
bpy.ops.object.armature_add(enter_editmode=True)
armature = bpy.data.armatures[bpy.context.view_layer.objects.active.name]
armature.name = name
armature.edit_bones.remove(armature.edit_bones.get("Bone"))
armature_object = bpy.context.view_layer.objects.active

create_bones(armature, skeleton, pose)
armature_object = bpy.context.view_layer.objects.active
armature_object.name = name

# Exit Armature editing
bpy.ops.object.mode_set(mode="OBJECT", toggle=False)
Expand Down
2 changes: 1 addition & 1 deletion animationCombiner/api/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def on_actions_update(self=None, context=None):
"""Recalculates length of final animation after the actions were updated"""
armature = bpy.data.armatures[bpy.context.view_layer.objects.active.name]
armature = bpy.context.view_layer.objects.active.data
length = 0
for action in armature.actions:
length += action.length_group.length
Expand Down
7 changes: 2 additions & 5 deletions animationCombiner/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class CreateExampleOperator(bpy.types.Operator):
"""Creates HBM skeleton as a base"""
bl_idname = "ac.create_example"
bl_label = "Create HBM skeleton"
bl_label = "Create empty armature"

@staticmethod
def run(self, context):
Expand All @@ -27,10 +27,7 @@ def unregister(cls):
bpy.types.VIEW3D_MT_add.remove(cls.run)

def execute(self, context):
with resources.files("animationCombiner.resources").joinpath("test.data").open("r") as file:
loader = HDM05MessifLoader(file, "test")
animation = loader.load_animation()
create_armature(animation.poses[0], animation.skeleton)
create_armature(context.scene.armature_name_preset)
return {"FINISHED"}


Expand Down
6 changes: 4 additions & 2 deletions animationCombiner/operators/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def execute(self, context):
# Recreate all Bones
order = skeleton.order()
bpy.ops.object.mode_set(mode="EDIT", toggle=False)
for bone in order:
armature_data.edit_bones.remove(armature_data.edit_bones.get(bone))
for name in order:
bone = armature_data.edit_bones.get(name)
if bone is not None:
armature_data.edit_bones.remove(armature_data.edit_bones.get(bone))

pose = Pose({
name: coords.coords for name, coords in zip(order, base_skeleton)
Expand Down
Loading

0 comments on commit b5505e4

Please sign in to comment.