-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasf_skeleton.py
72 lines (54 loc) · 2.39 KB
/
asf_skeleton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from joint import Joint
from cgkit.asfamc import ASFReader
from transformations import compose_matrix
import numpy as np
class ASF_Skeleton:
def __init__(self, filename):
self.name = None
self.joints = None
self.root = None
self.units = None
self.name2joint = {}
self.root = Joint(-1, "root", [0,0,0], [0,0,0], 1, "rx ry rz")
self.name2joint["root"] = self.root
def __init_name(name):
self.name = name
def __init_units(units):
self.units = units
def __init_joints(joint_data):
self.joints = [Joint.from_dict(entry) for entry in joint_data]
for joint in self.joints:
self.name2joint[joint.name] = joint
def __init_root(root_data):
self.root.direction = np.array([float(i)
for i in root_data["position"]])
self.root.theta_degrees = np.array([float(i)
for i in
root_data["orientation"]])
def __init_hierarchy(hierarchy):
for h in hierarchy:
parent_name, dep_names = h
for dep_name in dep_names:
self.name2joint[dep_name].parent = self.name2joint[parent_name]
reader = ASFReader(filename)
reader.onName = __init_name
reader.onUnits = __init_units
reader.onRoot = __init_root
reader.onBonedata = __init_joints
reader.read()
reader = ASFReader(filename)
reader.onHierarchy = __init_hierarchy
reader.read()
def update_joint_positions(self):
self.root.sum_transform = compose_matrix(angles=self.root.theta_radians,
translate=self.root.direction)
self.root.base_pos = self.root.offset
self.root.end_pos = self.root.offset
self.root.sum_ctrans = self.root.ctrans
for joint in self.joints:
joint.sum_transform = np.matmul(joint.parent.sum_transform,
joint.local_transform)
joint.base_pos = np.matmul(joint.sum_transform,
np.array([0,0,0,1]))[:-1]
joint.end_pos = np.matmul(joint.sum_transform,
np.append(joint.offset, 1))[:-1]