<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Skeletal Animation Editor</title>
		<link>http://www.allegro.cc/forums/view/609877</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 05 Apr 2012 08:17:19 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey everyone,</p><p>I decided to release my skeletal animation editor. The program supports only SVGs for the image format (I may add support for a folder of images if anyone cares enough :p), but it&#39;s pretty nice. I haven&#39;t released the source code, as it&#39;s a terrible mess right now (I redeveloped it over the course of a day...).</p><p>Here is a screenshot of it in action:</p><p><span class="remote-thumbnail"><span class="json">{"name":"605813","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/a\/4a40dc6e2724fbb8b11b6d8b1d10d5fa.png","w":640,"h":480,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/a\/4a40dc6e2724fbb8b11b6d8b1d10d5fa"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/4/a/4a40dc6e2724fbb8b11b6d8b1d10d5fa-240.jpg" alt="605813" width="240" height="180" /></span></p><p>Download link is here: <a href="http://commaexcess.com/articles/9/skeletal-animation-editor">http://commaexcess.com/articles/9/skeletal-animation-editor</a></p><p>(There is an example skeleton in the download, as well. Left click moves a bone, right click rotates. The rest is easy to figure out.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Fri, 30 Mar 2012 12:09:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I thought about doing something like this a few years ago, but never found the time. This looks awesome, I&#39;ll try it out as soon as I get time - downloading now...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 01 Apr 2012 23:01:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />! I have another animation that is considerably better than the included (check the attachment). Since I don&#39;t have smart skin loading, you may have to edit Soldier.xml, scroll to the bottom, and change this:</p><div class="source-code snippet"><div class="inner"><pre>  <span class="k3">&lt;</span>editor background<span class="k3">=</span><span class="s">"CornflowerBlue"</span> skin<span class="k3">=</span><span class="s">"Soldier.svg"</span> <span class="k3">/</span><span class="k3">&gt;</span>
</pre></div></div><p>

To...</p><div class="source-code snippet"><div class="inner"><pre>  <span class="k3">&lt;</span>editor background<span class="k3">=</span><span class="s">"CornflowerBlue"</span> skin<span class="k3">=</span><span class="s">"X:\Path\To\File\Soldier.svg"</span> <span class="k3">/</span><span class="k3">&gt;</span>
</pre></div></div><p>

Else you&#39;ll get an error upon loading the file.</p><p>Here is a screenie of the soldier using a crush attack:</p><p><span class="remote-thumbnail"><span class="json">{"name":"605820","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d6c4c498f3bfa1592d9bced1c6b94394.png","w":640,"h":480,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/6\/d6c4c498f3bfa1592d9bced1c6b94394"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/d/6/d6c4c498f3bfa1592d9bced1c6b94394-240.jpg" alt="605820" width="240" height="180" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Sun, 01 Apr 2012 23:15:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609877/951179#target">Aaron Bolyard</a> said:</div><div class="quote"><p>I may add support for a folder of images if anyone cares enough :p</p></div></div><p>

Me, me cares enough! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I have a project that needs this kind of animation. But SVG is too complex format (at SVG files created by Inkscape are <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />). Bitmaps are better for me. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Wed, 04 Apr 2012 02:45:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Would you mind to explain how the SVG data is rendered to screen? I mean the whole process? sorry if I asking too much <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /></p><p>Thanks in advance.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Wed, 04 Apr 2012 08:16:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Anyone with too much free time could make an SVG addon for Allegro 5.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trezker)</author>
		<pubDate>Wed, 04 Apr 2012 17:20:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609877/951634#target">Paul whoknows</a> said:</div><div class="quote"><p>Would you mind to explain how the SVG data is rendered to screen? I mean the whole process? sorry if I asking too much</p></div></div><p>

It&#39;s no problem! The skeletal animation editor uses a bridge between SVG and GDI+ and it&#39;s not something I made. On the other hand, my actual game uses a custom SVG loader that basically ignores everything but groups and path data.</p><p>Once the SVG is loaded, I have to perform a rudimentary triangulation of the points. Since I use a programmable pipeline, I am able to transform the points (better put, the resulting fragments; I&#39;ll explain this later) on the GPU, which allows me to generate the &quot;infinite resolution&quot; curves.</p><p>In order to triangulate the points, I perform a rather simple triangulation method that leverages the stencil buffer. I basically create a list of triangles out of points. Say I start off with four points:</p><p><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/6/36e3c7631a9f9842e718b841172f5a78.png" alt="605827" width="81" height="58" /></p><p>Normally, triangulation would look like this:</p><p><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/9/f/9fd722d11f26e0fb174d2d10608fdeb0.png" alt="605828" width="81" height="58" /></p><p>However, if you have the stencil buffer available, you can triangulate them as so:</p><p><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/2/22e1bf7171214c46739a61c69751074f.png" alt="605829" width="81" height="58" /></p><p>Notice the extra point (in red). This is the &quot;dangling point&quot; as I call it; it&#39;s used in the same manner as a triangle fan. Each point is connected to the dangling point. The stencil buffer allows us to skip a heavier triangulation method (e.g., Delauney), as outlined below, by using this method.</p><p>Now, when you go to draw the shape, you set the stencil buffer to always invert when a fragment is drawn and disable color writing. This will produce the following output in the stencil buffer:</p><p><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/b/d/bd41e71b636040c500a063c321f3a432.png" alt="605830" width="81" height="58" /></p><p>Notice it&#39;s the triangulated shape? Simply draw the shape (in my case, I draw a special rectangle that is scaled and translated to fill the shape, which allows me to use gradients, etc with ease), this time with color writing enabled and the stencil test to only draw if the stencil value is odd (basically, not equal to 0). Basically, I am employing the common &quot;even-odd&quot; rule used by most SVG paths.</p><p>With that in mind, here is a Bezier curve that needs to be triangulated (note, this is a quick sketch and is not a quadratic curve, but let&#39;s pretend it is!):</p><p><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/3/e/3ee11ee277542158b4c1bd9ec45a3c93.png" alt="605831" width="175" height="90" /></p><p>First we need to assign to the points a curve value for the fragment shader (as explained later on) that defines the curve. Luckily, for quadratic curves, these values are simple: point 1 gets the curve value (0.0, 0.0); point 2 (the control point) gets the curve value (0.5, 0.0); and point 3 gets the curve value (1.0, 1.0).</p><p>Now, triangulating the curve is easy. First, create a triangle out of points 1, 2, and 3 (in that order). Next, connect points 1 and 3 to the dangling point in order to fill the shape in. For the curve I presented just above, this would have no effect. However, when adding more curves, it will fill in the shape.</p><p>Now, when drawing the path, you have to use a fragment shader. The fragment shader is extremely simple; you subtract the second component of the curve value from the first component of the curve value squared, as seen in the following fragment shader:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="p">#version 150</span>
<span class="number">  2</span>
<span class="number">  3</span>smooth in vec2 frag_ControlPoint<span class="k2">;</span> <span class="c">// UV value pair</span>
<span class="number">  4</span>
<span class="number">  5</span>out vec4 game_FragColor<span class="k2">;</span> <span class="c">// Output color</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="k1">void</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number">  8</span><span class="k2">{</span>
<span class="number">  9</span>  <span class="k1">float</span> u <span class="k3">=</span> frag_ControlPoint.s<span class="k2">;</span>
<span class="number"> 10</span>  <span class="k1">float</span> v <span class="k3">=</span> frag_ControlPoint.t<span class="k2">;</span>
<span class="number"> 11</span>  
<span class="number"> 12</span>  <span class="c">// If the inequality evaluates to false, then this fragment </span>
<span class="number"> 13</span>  <span class="c">// is within the curve. Otherwise, the fragment is outside </span>
<span class="number"> 14</span>  <span class="c">// the curve, so discard it.</span>
<span class="number"> 15</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k2">(</span>u <span class="k3">*</span> u<span class="k2">)</span> <span class="k3">-</span> v <span class="k3">&gt;</span> <span class="n">0</span><span class="k2">)</span>
<span class="number"> 16</span>    discard<span class="k2">;</span>
<span class="number"> 17</span>  
<span class="number"> 18</span>  game_FragColor <span class="k3">=</span> vec4<span class="k2">(</span><span class="n">1</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span><span class="k2">}</span>
</div></div><p>

And then you&#39;re done. You need to understand that this method is much heavier than drawing a bitmap or even multiple bitmaps; however, even with many thousands of shapes, it&#39;s still not nearly as taxing as Crysis <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />.</p><p>Also, keep in mind that I subdivide cubic curves into four quadratic curves that emulate the cubic curve nearly perfectly. This is because drawing a cubic curve on the GPU gives me too much of a headache <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />. SVG paths primarily use cubic curves, so other than subdividing them, you&#39;d have to calculate four special values as outlined in <a href="http://research.microsoft.com/en-us/um/people/cloop/loopblinn05.pdf">Loop and Blinn&#39;s excellent paper</a>.</p><p>I have source code for the curve drawing available in Algae, a game library I programmed. You can get it <a>here</a>. The appropriate code is in <span class="source-code">Algae<span class="k3">/</span>Graphics<span class="k3">/</span>QuadraticPathBuilder.cs</span>. Sadly, it&#39;s in C#, but the principle remains the same.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Wed, 04 Apr 2012 20:39:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Aaron, thank you very much! <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> your explanation is great, thanks!</p><p>Implementing a real-time vector graphics engine seems to be a tremendous amount of work! I was thinking in implement a real-time vector graphics game using plain Opengl, but now I&#39;m a little scared <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /> perhaps I should start using some SVG-to-GPU library?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Thu, 05 Apr 2012 08:17:19 +0000</pubDate>
	</item>
</rss>
