Mercurial > MadButterfly
annotate pyink/tween.py @ 1170:e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
author | wycc |
---|---|
date | Thu, 30 Dec 2010 11:30:16 +0800 |
parents | 6160e6282252 |
children | 178b126edd2c |
rev | line source |
---|---|
1140 | 1 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*- |
2 # vim: sw=4:ts=8:sts=4 | |
3 import traceback | |
4 import math | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
5 |
1140 | 6 class TweenObject: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
7 TWEEN_TYPE_NORMAL = 0 |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
8 #TWEEN_TYPE_RELOCATE = 1 |
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
9 TWEEN_TYPE_SCALE = 1 |
1156
ad9c44a08645
If an object does not exist in the destination group, we should duplicate it.
wycc
parents:
1151
diff
changeset
|
10 |
1140 | 11 def __init__(self,doc,dom): |
12 self.document = doc | |
13 self.dom = dom | |
1141 | 14 try: |
15 self.width = float(dom.getAttribute("width")) | |
16 self.height = float(dom.getAttribute("height")) | |
17 except: | |
18 self.width = 640 | |
19 self.height = 480 | |
1140 | 20 |
21 def updateMapping(self): | |
22 self.nodeToItem={} | |
23 root = self.dom | |
24 self.updateMappingNode(root) | |
25 def updateMappingNode(self,node): | |
26 for c in node.childList(): | |
27 self.updateMappingNode(c) | |
1141 | 28 try: |
29 self.nodeToItem[c.getAttribute("id")] = c | |
30 except: | |
31 pass | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
32 def updateTweenContent(self, duplicate_group, tween_type, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
33 start_scene_group, stop_scene_group, percent): |
1140 | 34 """ |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
35 Update the content of the duplicate scene group. We will |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
36 use precent, start_scene_group, stop_scene_group to |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
37 compute transform matrix and update duplicate scene group |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
38 specified. |
1140 | 39 """ |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
40 # Collect ref from the obj |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
41 node = duplicate_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
42 dup_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
43 while node: |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
44 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
45 ref = node.getAttribute("ref") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
46 dup_nodes[ref] = node |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
47 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
48 ref = None |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
49 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
50 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
51 pass |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
52 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
53 # Collect all nodes in stop scene |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
54 stop_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
55 node = stop_scene_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
56 while node: |
1140 | 57 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
58 node_label = node.getAttribute("ns0:duplicate-src") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
59 stop_nodes[node_label] = node |
1140 | 60 except: |
61 pass | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
62 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
63 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
64 |
1160
1a699dc00fa3
Fix the issue of not removing node in old scene when switching scenes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1157
diff
changeset
|
65 # Remove duplicate nodes that is not in the set of stop nodes |
1170
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
66 #for node_ref in dup_nodes: |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
67 # if node_ref not in stop_nodes: |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
68 # node = dup_nodes[node_ref] |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
69 # duplicate_group.removeChild(node) |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
70 # pass |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
71 # pass |
1160
1a699dc00fa3
Fix the issue of not removing node in old scene when switching scenes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1157
diff
changeset
|
72 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
73 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
74 # Node ID of a node of start scene must be mapped to |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
75 # 'ns0:duplicate-src' attribute of a node of stop scene. The |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
76 # nodes which can not be mapped to a node of stop scene are |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
77 # not manipulated by the tween. |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
78 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
79 # When a scene is duplicated, 'ns0:duplicate-src' attribute of |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
80 # nodes, in the new scene, must be setted to ID of respective |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
81 # one in the duplicated scene. |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
82 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
83 start_node = start_scene_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
84 while start_node: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
85 start_node_id = start_node.getAttribute('id') |
1163 | 86 dup_node = dup_nodes.setdefault(start_node_id, None) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
87 try: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
88 stop_node = stop_nodes[start_node_id] |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
89 except KeyError: |
1170
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
90 self.updateTweenObject(duplicate_group, tween_type, |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
91 start_node, start_node, |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
92 percent, dup_node) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
93 start_node = start_node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
94 continue |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
95 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
96 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
97 self.updateTweenObject(duplicate_group, tween_type, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
98 start_node, stop_node, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
99 percent, dup_node) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
100 start_node = start_node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
101 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
102 pass |
1140 | 103 |
104 def parseTransform(self,obj): | |
105 """ | |
106 Return the transform matrix of an object | |
107 """ | |
108 try: | |
1141 | 109 t = obj.getAttribute("transform") |
1140 | 110 print t |
111 if t[0:9] == 'translate': | |
112 print "translate" | |
113 fields = t[10:].split(',') | |
114 x = float(fields[0]) | |
115 fields = fields[1].split(')') | |
116 y = float(fields[0]) | |
117 return [1,0,0,1,x,y] | |
118 elif t[0:6] == 'matrix': | |
119 print "matrix" | |
120 fields=t[7:].split(')') | |
121 fields = fields[0].split(',') | |
122 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])] | |
123 except: | |
124 #traceback.print_exc() | |
125 return [1,0,0,1,0,0] | |
126 | |
127 def invA(self,m): | |
128 d = m[0]*m[3]-m[2]*m[1] | |
129 return [m[3]/d, -m[1]/d, -m[2]/d, m[0]/d, (m[1]*m[5]-m[4]*m[3])/d, (m[4]*m[2]-m[0]*m[5])/d] | |
130 | |
131 def mulA(self,a,b): | |
132 return [a[0]*b[0]+a[1]*b[2], | |
133 a[0]*b[1]+a[1]*b[3], | |
134 a[2]*b[0]+a[3]*b[2], | |
135 a[2]*b[1]+a[3]*b[3], | |
136 a[0]*b[4]+a[1]*b[5]+a[4], | |
137 a[2]*b[4]+a[3]*b[5]+a[5]] | |
138 | |
139 def decomposition(self,m): | |
140 """ | |
141 Decompose the affine matrix into production of translation,rotation,shear and scale. | |
142 The algorithm is documented at http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
143 """ | |
144 if m[0]*m[3] == m[1]*m[2]: | |
145 print "The affine matrix is singular" | |
146 return [1,0,0,1,0,0] | |
147 A=m[0] | |
148 B=m[2] | |
149 C=m[1] | |
150 D=m[3] | |
151 E=m[4] | |
152 F=m[5] | |
153 sx = math.sqrt(A*A+B*B) | |
154 A = A/sx | |
155 B = B/sx | |
156 shear = m[0]*m[1]+m[2]*m[3] | |
157 C = C - A*shear | |
158 D = D - B*shear | |
159 sy = math.sqrt(C*C+D*D) | |
160 C = C/sy | |
161 D = D/sy | |
162 r = A*D-B*C | |
163 if r == -1: | |
164 shear = -shear | |
165 sy = -sy | |
166 R = math.atan2(B,A) | |
167 return [sx,sy, R, E,F] | |
168 | |
169 | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
170 def updateTweenObject(self,obj,typ,s,d,p,newobj): |
1140 | 171 """ |
172 Generate tweened object in the @obj by using s and d in the @p percent | |
173 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
174 """ | |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
175 if typ == self.TWEEN_TYPE_SCALE: |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
176 self.updateTweenObjectScale(obj,s,d,p,newobj) |
1140 | 177 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
178 elif typ == self.TWEEN_TYPE_NORMAL: |
1170
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
179 if newobj == None: |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
180 newobj = s.duplicate(self.document) |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
181 newobj.setAttribute("ref", s.getAttribute("id")) |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
182 obj.appendChild(newobj) |
1140 | 183 pass |
184 | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
185 def updateTweenObjectScale(self,obj,s,d,p,newobj): |
1140 | 186 """ |
187 Generate a new group which contains the original group and then | |
188 add the transform matrix to generate a tween frame between the | |
189 origin and destination scene group. | |
190 | |
191 We will parse the transform matrix of the @s and @d and then | |
192 generate the matrix which is (1-p) of @s and p percent of @d. | |
193 """ | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
194 if newobj == None: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
195 newobj = s.duplicate(self.document) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
196 top = self.document.createElement("svg:g") |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
197 top.setAttribute("ref",s.getAttribute("id")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
198 top.appendChild(newobj) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
199 obj.appendChild(top) |
1170
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
200 print "aaa" |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
201 else: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
202 top = newobj |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
203 newobj = top.firstChild() |
1140 | 204 |
205 if s.name() == 'svg:g': | |
206 # Parse the translate or matrix | |
207 # | |
208 # D = B inv(A) | |
209 try: | |
1141 | 210 item = self.nodeToItem[s.getAttribute("id")] |
1140 | 211 (ox,oy) = item.getCenter() |
212 except: | |
213 ox = 0 | |
214 oy = 0 | |
215 try: | |
1141 | 216 item = self.nodeToItem[d.getAttribute("id")] |
1140 | 217 (dx,dy) = item.getCenter() |
218 except: | |
219 dx = 0 | |
220 dy = 0 | |
221 | |
222 sm = self.parseTransform(s) | |
223 ss = self.decomposition(sm) | |
224 dm = self.parseTransform(d) | |
225 dd = self.decomposition(dm) | |
226 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] | |
227 sy = (ss[1]*(1-p)+dd[1]*p)/ss[0] | |
228 a = ss[2]*(1-p)+dd[2]*p-ss[2] | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
229 tx = ox*(1-p)+dx*p |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
230 ty = oy*(1-p)+dy*p |
1140 | 231 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] |
232 m = self.mulA([sx,0,0,sy,0,0],m) | |
233 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
234 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
235 | |
236 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
237 else: | |
238 try: | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
239 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
240 sw = float(s.getAttribute("width")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
241 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
242 sw = 1 |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
243 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
244 sh = float(s.getAttribute("height")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
245 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
246 sh = 1 |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
247 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
248 dw = float(d.getAttribute("width")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
249 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
250 dw = 1 |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
251 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
252 dh = float(d.getAttribute("height")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
253 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
254 dh = 1 |
1140 | 255 try: |
1141 | 256 item = self.nodeToItem[s.getAttribute("id")] |
1140 | 257 (ox,oy) = item.getCenter() |
258 except: | |
259 ox = 0 | |
260 oy = 0 | |
261 try: | |
1141 | 262 item = self.nodeToItem[d.getAttribute("id")] |
1140 | 263 (dx,dy) = item.getCenter() |
264 except: | |
265 dx = 0 | |
266 dy = 0 | |
267 try: | |
268 sm = self.parseTransform(s) | |
269 ss = self.decomposition(sm) | |
270 except: | |
271 ss = [1,1,0,0,0] | |
272 pass | |
273 try: | |
274 dm = self.parseTransform(d) | |
275 dd = self.decomposition(dm) | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
276 print "dd=",dd |
1140 | 277 except: |
278 dd = [1,1,0,0,0] | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
279 dd[0] = dd[0]*dw/sw |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
280 dd[1] = dd[1]*dh/sh |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
281 print "ss[0]=",ss[0],"dd[0]=",dd[0] |
1140 | 282 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] |
283 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
284 print "sx=",sx,"sy=",sy |
1140 | 285 a = ss[2]*(1-p)+dd[2]*p-ss[2] |
286 tx = ox*(1-p)+dx*p | |
287 ty = oy*(1-p)+dy*p | |
288 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] | |
289 m = self.mulA([sx,0,0,sy,0,0],m) | |
290 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
291 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
292 | |
293 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
294 except: | |
295 traceback.print_exc() |