2020-10-11 16:11:15 +00:00
|
|
|
""" Gathers the Blender objects from the current scene and returns them as a list of
|
|
|
|
Model objects. """
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
import math
|
|
|
|
from enum import Enum
|
|
|
|
from typing import List, Set, Dict, Tuple
|
|
|
|
from itertools import zip_longest
|
|
|
|
from .msh_model import *
|
|
|
|
from .msh_model_utilities import *
|
|
|
|
from .msh_utilities import *
|
|
|
|
from .msh_model_gather import *
|
|
|
|
|
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
def extract_anim(armature: bpy.types.Armature) -> Animation:
|
2020-10-11 16:11:15 +00:00
|
|
|
|
|
|
|
action = armature.animation_data.action
|
2020-10-20 03:18:08 +00:00
|
|
|
anim = Animation();
|
|
|
|
|
|
|
|
if not action:
|
|
|
|
framerange = Vector((0.0,1.0))
|
|
|
|
else:
|
|
|
|
framerange = action.frame_range
|
2020-10-11 16:11:15 +00:00
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
num_frames = math.floor(framerange.y - framerange.x) + 1
|
|
|
|
increment = (framerange.y - framerange.x) / (num_frames - 1)
|
2020-10-11 16:11:15 +00:00
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
anim.end_index = num_frames - 1
|
|
|
|
|
2020-11-23 15:15:22 +00:00
|
|
|
anim.bone_transforms["DummyRoot"] = []
|
2020-10-11 16:11:15 +00:00
|
|
|
for bone in armature.data.bones:
|
2020-10-20 03:18:08 +00:00
|
|
|
anim.bone_transforms[bone.name] = []
|
2020-10-11 16:11:15 +00:00
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
for frame in range(num_frames):
|
|
|
|
|
|
|
|
frame_time = framerange.x + frame * increment
|
2020-10-11 16:11:15 +00:00
|
|
|
bpy.context.scene.frame_set(frame_time)
|
|
|
|
|
2020-11-23 15:15:22 +00:00
|
|
|
anim.bone_transforms["DummyRoot"].append(ModelTransform())
|
2020-10-11 16:11:15 +00:00
|
|
|
for bone in armature.pose.bones:
|
2020-10-12 00:52:34 +00:00
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
transform = bone.matrix
|
2020-10-11 16:11:15 +00:00
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
if bone.parent:
|
|
|
|
transform = bone.parent.matrix.inverted() @ transform
|
|
|
|
|
|
|
|
loc, rot, _ = transform.decompose()
|
2020-10-16 18:56:03 +00:00
|
|
|
|
|
|
|
xform = ModelTransform()
|
2020-10-20 03:18:08 +00:00
|
|
|
xform.rotation = convert_rotation_space(rot)
|
|
|
|
xform.translation = convert_vector_space(loc)
|
2020-10-11 16:11:15 +00:00
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
anim.bone_transforms[bone.name].append(xform)
|
2020-10-11 16:11:15 +00:00
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
return anim
|