]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/armature.py
Return back to first stage after some optimization happens
[libs/gl.git] / blender / io_mspgl / armature.py
1 class Link:
2         def __init__(self, bone):
3                 self._bone = bone
4                 self.name = self._bone.name
5                 self.index = None
6                 self.parent_name = None
7                 if self._bone.parent:
8                         self.parent_name = self._bone.parent.name
9                 self.parent = None
10                 self.base = self._bone.head_local
11
12 class Armature:
13         def __init__(self, arm):
14                 self._armature = arm
15
16                 self.links = [Link(b) for b in self._armature.bones]
17                 for i, l in enumerate(self.links):
18                         l.index = i
19
20                 links_by_name = dict((l.name, l) for l in self.links)
21                 for l in self.links:
22                         if l.parent_name:
23                                 l.parent = links_by_name[l.parent_name]
24
25         def sort_links(self):
26                 sorted_links = []
27                 for l in self.links:
28                         if l in sorted_links:
29                                 continue
30                         if not l.parent:
31                                 sorted_links.append(l)
32                         else:
33                                 chain = [l]
34                                 p = l.parent
35                                 while p and p not in sorted_links:
36                                         chain.append(p)
37                                         p = p.parent
38                                 sorted_links += reversed(chain)
39                 self.links = sorted_links