# HG changeset patch # User wycc # Date 1293173047 -28800 # Node ID e14ec6d1a66170e92b9614866042222bf6eeb367 # Parent 8f0ee167c5b2f04186ef1f6b4cd76768deac0bf3 CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape. diff -r 8f0ee167c5b2 -r e14ec6d1a661 pyink/MBScene.py --- a/pyink/MBScene.py Thu Dec 23 00:00:46 2010 +0800 +++ b/pyink/MBScene.py Fri Dec 24 14:44:07 2010 +0800 @@ -512,13 +512,17 @@ # Check the duplicated scene group and create it if it is not available try: if layer.duplicateGroup: - layer.duplicateGroup.parent().removeChild(layer.duplicateGroup) - layer.duplicateGroup = None + layer.duplicateGroup.setAttribute("style","display:none") except: - traceback.print_exc() + print "*"*40 + layer.duplicateGroup = self.document.createElement("svg:g") + layer.duplicateGroup.setAttribute("inkscape:label","dup") + layer.duplicateGroup.setAttribute("sodipodi:insensitive","1") + layer.duplicateGroup.setAttribute("style","") + layer.layer.node.appendChild(layer.duplicateGroup) pass # Create a new group - layer.duplicateGroup = None + #layer.duplicateGroup = None while i < len(layer._keys): @@ -536,19 +540,19 @@ else: if nth > (s.idx+1) and nth <= (layer._keys[i+1].idx+1): if i+2 < len(layer._keys): - layer.duplicateGroup = self.document.createElement("svg:g") - layer.duplicateGroup.setAttribute("inkscape:label","dup") - layer.duplicateGroup.setAttribute("sodipodi:insensitive","1") + #s.ref.parent().appendChild(layer.duplicateGroup) s.ref.setAttribute("style","display:none") - s.ref.parent().appendChild(layer.duplicateGroup) + layer.duplicateGroup.setAttribute("style","") self.tween.updateTweenContent(layer.duplicateGroup, layer.get_tween_type(s.idx),s, layer._keys[i+2], nth) else: - layer.duplicateGroup = s.ref.duplicate(self.document) - layer.duplicateGroup.setAttribute("style","") - layer.duplicateGroup.setAttribute("inkscape:label","dup") - layer.duplicateGroup.setAttribute("sodipodi:insensitive","1") + layer.duplicateGroup.setAttribute("style","") + #layer.duplicateGroup = s.ref.duplicate(self.document) + #layer.duplicateGroup.setAttribute("style","") + #layer.duplicateGroup.setAttribute("inkscape:label","dup") + #layer.duplicateGroup.setAttribute("sodipodi:insensitive","1") s.ref.setAttribute("style","display:none") - s.ref.parent().appendChild(layer.duplicateGroup) + #s.ref.parent().appendChild(layer.duplicateGroup) + pass else: s.ref.setAttribute("style","display:none") i = i + 2 @@ -744,7 +748,7 @@ if orig == None: return None ns = orig.duplicate(rdoc) - gid = self.last_line.node.label()+self.newID() + gid = self.last_line.node.getAttribute('id')+self.newID() self.ID[gid]=1 ns.setAttribute("id",gid) ns.setAttribute("inkscape:groupmode","layer") @@ -780,15 +784,23 @@ self.lockui = False #self.grid.show_all() pass + def changeObjectLabel(self,w): o = self.desktop.selection.list()[0] o.setAttribute("inkscape:label", self.nameEditor.get_text()) + def addNameEditor(self,hbox): self.nameEditor = gtk.Entry(max=40) hbox.pack_start(self.nameEditor,expand=False,fill=False) self.editDone = gtk.Button('Set') hbox.pack_start(self.editDone,expand=False,fill=False) self.editDone.connect('clicked', self.changeObjectLabel) + + def doRun(self): + """ + Execute the current animation till the last frame. + """ + def addButtons(self,hbox): #btn = gtk.Button('Edit') @@ -806,8 +818,12 @@ btn=gtk.Button('Duplicate Key') btn.connect('clicked', self.doDuplicateKeyScene) hbox.pack_start(btn,expand=False,fill=False) + btn=gtk.Button('Run') + btn.connect('clicked', self.doRun) + hbox.pack_start(btn,expand=False,fill=False) self.addNameEditor(hbox) self.addTweenTypeSelector(hbox) + pass def onTweenTypeChange(self,w): n = self.tweenTypeSelector.get_active() diff -r 8f0ee167c5b2 -r e14ec6d1a661 pyink/primitive_test.svg --- a/pyink/primitive_test.svg Thu Dec 23 00:00:46 2010 +0800 +++ b/pyink/primitive_test.svg Fri Dec 24 14:44:07 2010 +0800 @@ -10,12 +10,13 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="744.09448819" - height="1052.3622047" + width="744.09448" + height="1052.3622" id="svg2" version="1.1" - inkscape:version="0.48+devel r9774 custom" - sodipodi:docname="primitive_test.svg"> + inkscape:version="0.48+devel r9776" + sodipodi:docname="primitive_test.svg" + style="display:inline"> @@ -51,42 +52,118 @@ + id="layer1" + style="display:inline"> - + id="layer1s4140"> + + + + + + + + + + + + + + + + + + diff -r 8f0ee167c5b2 -r e14ec6d1a661 pyink/tween.py --- a/pyink/tween.py Thu Dec 23 00:00:46 2010 +0800 +++ b/pyink/tween.py Fri Dec 24 14:44:07 2010 +0800 @@ -39,7 +39,20 @@ d = dest.ref.firstChild() sources={} dests={} - + # Collect ref from the obj + o = obj.firstChild() + maps={} + while o: + print "--->",o + try: + ref = o.getAttribute("ref") + except: + print o + ref = None + + if ref: + maps[ref] = o + o = o.next() # Collect all objects while d: try: @@ -54,12 +67,17 @@ d = dest.ref.firstChild() while s: print s,d + sid = s.getAttribute("id") + if maps.has_key(sid): + o = maps[sid] + else: + o = None try: label = s.getAttribute("inkscape:label") # Use i8nkscape:label to identidy the equipvalent objects if label: if dests.hasattr(label.value()): - self.updateTweenObject(obj,typ,s,dests[label.value()],percent) + self.updateTweenObject(obj,typ,s,dests[label.value()],percent,o) s = s.next() continue except: @@ -73,7 +91,7 @@ except: pass if s.name() == d.name(): - self.updateTweenObject(obj,typ,s,d,percent) + self.updateTweenObject(obj,typ,s,d,percent,o) d = d.next() break d = d.next() @@ -145,15 +163,15 @@ return [sx,sy, R, E,F] - def updateTweenObject(self,obj,typ,s,d,p): + def updateTweenObject(self,obj,typ,s,d,p,newobj): """ Generate tweened object in the @obj by using s and d in the @p percent http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html """ if typ == 'relocate': newobj = s.duplicate(self.document) - newobj.setAttribute("ref", s.getAttribute("id")) top = self.document.createElement("svg:g") + top.setAttribute("ref", s.getAttribute("id")) top.appendChild(newobj) obj.appendChild(top) if s.name() == 'svg:g': @@ -176,7 +194,7 @@ pass pass elif typ == 'scale': - self.updateTweenObjectScale(obj,s,d,p) + self.updateTweenObjectScale(obj,s,d,p,newobj) pass elif typ == 'normal': newobj = s.duplicate(self.document) @@ -186,7 +204,7 @@ obj.appendChild(top) pass - def updateTweenObjectScale(self,obj,s,d,p): + def updateTweenObjectScale(self,obj,s,d,p,newobj): """ Generate a new group which contains the original group and then add the transform matrix to generate a tween frame between the @@ -195,10 +213,15 @@ We will parse the transform matrix of the @s and @d and then generate the matrix which is (1-p) of @s and p percent of @d. """ - newobj = s.duplicate(self.document) - top = self.document.createElement("svg:g") - top.appendChild(newobj) - obj.appendChild(top) + if newobj == None: + newobj = s.duplicate(self.document) + top = self.document.createElement("svg:g") + top.setAttribute("ref",s.getAttribute("id")) + top.appendChild(newobj) + obj.appendChild(top) + else: + top = newobj + newobj = top.firstChild() if s.name() == 'svg:g': # Parse the translate or matrix @@ -224,8 +247,8 @@ sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] sy = (ss[1]*(1-p)+dd[1]*p)/ss[0] a = ss[2]*(1-p)+dd[2]*p-ss[2] - tx = ox*(1-p)+dx*p-ox - ty = oy*(1-p)+dy*p-oy + tx = ox*(1-p)+dx*p + ty = oy*(1-p)+dy*p m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] m = self.mulA([sx,0,0,sy,0,0],m) m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) @@ -234,10 +257,22 @@ top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) else: try: - sw = float(s.getAttribute("width")) - sh = float(s.getAttribute("height")) - dw = float(d.getAttribute("width")) - dh = float(d.getAttribute("height")) + try: + sw = float(s.getAttribute("width")) + except: + sw = 1 + try: + sh = float(s.getAttribute("height")) + except: + sh = 1 + try: + dw = float(d.getAttribute("width")) + except: + dw = 1 + try: + dh = float(d.getAttribute("height")) + except: + dh = 1 try: item = self.nodeToItem[s.getAttribute("id")] (ox,oy) = item.getCenter() @@ -259,12 +294,15 @@ try: dm = self.parseTransform(d) dd = self.decomposition(dm) + print "dd=",dd except: dd = [1,1,0,0,0] - dd[0] = ss[0]*dw/sw - dd[1] = ss[1]*dh/sh + dd[0] = dd[0]*dw/sw + dd[1] = dd[1]*dh/sh + print "ss[0]=",ss[0],"dd[0]=",dd[0] sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] + print "sx=",sx,"sy=",sy a = ss[2]*(1-p)+dd[2]*p-ss[2] tx = ox*(1-p)+dx*p ty = oy*(1-p)+dy*p