Mercurial > MadButterfly
changeset 1146:e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
author | wycc |
---|---|
date | Fri, 24 Dec 2010 14:44:07 +0800 |
parents | 8f0ee167c5b2 |
children | 5cfa73d7e80f |
files | pyink/MBScene.py pyink/primitive_test.svg pyink/tween.py |
diffstat | 3 files changed, 193 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- 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()
--- 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"> <defs id="defs4" /> <sodipodi:namedview @@ -29,12 +30,12 @@ inkscape:cx="375" inkscape:cy="862.85714" inkscape:document-units="px" - inkscape:current-layer="Layer 1s8009" + inkscape:current-layer="Layer 1s1983" showgrid="false" - inkscape:window-width="741" + inkscape:window-width="778" inkscape:window-height="639" - inkscape:window-x="614" - inkscape:window-y="288" + inkscape:window-x="512" + inkscape:window-y="118" inkscape:window-maximized="0" /> <metadata id="metadata7"> @@ -51,42 +52,118 @@ <ns0:scene start="1" ref="Layer 1s1983" - end="20" + end="19" type="scale" /> <ns0:scene - start="21" - ref="Layer 1s8009" - end="24" + start="20" + ref="layer1s4140" type="normal" /> </ns0:scenes> </metadata> <g inkscape:label="Layer 1" inkscape:groupmode="layer" - id="layer1"> + id="layer1" + style="display:inline"> <g id="Layer 1s1983" inkscape:groupmode="layer" style="display:none"> - <rect - x="31.90139" - y="-22.552591" - width="23.144594" - height="99.921394" - id="rect3070" - transform="matrix(0.97036454,0.24164574,-0.39246616,0.91976645,0,0)" /> + <g + id="g3077"> + <path + transform="translate(-48.571429,-100)" + d="m 145.71428,168.07646 a 42.857143,47.142857 0 1 1 -85.714284,0 42.857143,47.142857 0 1 1 85.714284,0 z" + sodipodi:ry="47.142857" + sodipodi:rx="42.857143" + sodipodi:cy="168.07646" + sodipodi:cx="102.85714" + id="path3237" + style="fill:#ff0000;fill-opacity:1" + sodipodi:type="arc" /> + </g> + <g + id="g3072"> + <rect + transform="matrix(0.8189798,0.57382236,-0.57382236,0.8189798,0,0)" + y="-68.432068" + x="171.42537" + height="160" + width="25.714285" + id="rect3229" + style="fill:#ff0000;fill-opacity:1" /> + </g> </g> <g - style="" + style="display:none" inkscape:groupmode="layer" - id="Layer 1s8009"> - <rect - transform="matrix(0.80629826,-0.59150919,0.67689515,0.73607945,0,0)" - id="rect3431" - height="432.13434" - width="64.699173" - y="220.30684" - x="3.5009925" /> + id="layer1s4140"> + <g + id="g3083" + transform="translate(360,334.28571)"> + <path + sodipodi:type="arc" + style="fill:#ff0000;fill-opacity:1" + id="path3085" + sodipodi:cx="102.85714" + sodipodi:cy="168.07646" + sodipodi:rx="42.857143" + sodipodi:ry="47.142857" + d="m 145.71428,168.07646 c 0,26.03628 -19.18779,47.14286 -42.85714,47.14286 -23.669347,0 -42.857144,-21.10658 -42.857144,-47.14286 0,-26.03628 19.187797,-47.14285 42.857144,-47.14285 23.66935,0 42.85714,21.10657 42.85714,47.14285 z" + transform="translate(-48.571429,-100)" /> + </g> + <g + id="g3087" + transform="translate(151.42857,191.42857)"> + <rect + style="fill:#ff0000;fill-opacity:1" + id="rect3089" + width="25.714285" + height="160" + x="171.42537" + y="-68.432068" + transform="matrix(0.8189798,0.57382236,-0.57382236,0.8189798,0,0)" /> + </g> + </g> + <g + inkscape:label="dup" + sodipodi:insensitive="1" + style="" + id="g3084"> + <g + ref="g3077" + id="g3086" + transform="matrix(1,0,0,1,360,334.286)"> + <g + id="g3088"> + <path + sodipodi:type="arc" + style="fill:#ff0000;fill-opacity:1" + id="path3090" + sodipodi:cx="102.85714" + sodipodi:cy="168.07646" + sodipodi:rx="42.857143" + sodipodi:ry="47.142857" + d="m 145.71428,168.07646 c 0,26.03628 -19.18779,47.14286 -42.85714,47.14286 -23.669347,0 -42.857144,-21.10658 -42.857144,-47.14286 0,-26.03628 19.187797,-47.14285 42.857144,-47.14285 23.66935,0 42.85714,21.10657 42.85714,47.14285 z" + transform="translate(-48.571429,-100)" /> + </g> + </g> + <g + ref="g3072" + id="g3092" + transform="matrix(1,0,0,1,151.429,191.429)"> + <g + id="g3094"> + <rect + style="fill:#ff0000;fill-opacity:1" + id="rect3096" + width="25.714285" + height="160" + x="171.42537" + y="-68.432068" + transform="matrix(0.8189798,0.57382236,-0.57382236,0.8189798,0,0)" /> + </g> + </g> </g> </g> </svg>
--- 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