<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Smart-Page.net &#187; General</title>
	<atom:link href="http://www.smart-page.net/blog/category/general/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.smart-page.net/blog</link>
	<description>C++ / C# / Py / Actionscript ... &#039;My God. It&#039;s full of stars!&#039;</description>
	<lastBuildDate>Thu, 23 Jun 2011 00:14:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Advanced Python plugin coding for Cinema 4D</title>
		<link>http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/</link>
		<comments>http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/#comments</comments>
		<pubDate>Sun, 08 May 2011 22:31:06 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[cinema 4D]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Plugin development]]></category>
		<category><![CDATA[Pydev]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=1215</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/" title="Advanced Python plugin coding for Cinema 4D"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/title2.32lgm6px71s0w08c8gkk8cwsw.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Advanced Python plugin coding for Cinema 4D" style="float:left;padding:0 10px 10px 0;" ></a>It&#8217;s been a long time&#8230; how have you been? This is going to be another Python/Cinema 4D related post. While python is great for quickly scripting workflow optimizing tools, prototype stuff or write generators and tags, is it suited for big, complex plugin development? It is! You get &#8216;nearly&#8217; full access to the C++ API [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/" title="Advanced Python plugin coding for Cinema 4D"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/title2.32lgm6px71s0w08c8gkk8cwsw.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Advanced Python plugin coding for Cinema 4D" style="float:left;padding:0 10px 10px 0;" ></a><p>It&#8217;s been a long time&#8230; how have you been?</p>
<p>This is going to be another Python/Cinema 4D related post.</p>
<p>While python is great for quickly scripting workflow optimizing tools, prototype stuff or write generators and tags, is it suited for big, complex plugin development?</p>
<p><span id="more-1215"></span>It is!</p>
<p>You get &#8216;nearly&#8217; full access to the C++ API of Cinema 4D, don&#8217;t have to compile or worry much about platform dependencies, can easily find a ton of neat recipes and libraries out there&#8230;</p>
<p>So it’s not only possible to code full-fledged python plugins but it even has its advantages over classical C++ development.</p>
<p>Imagine you wrote a nifty script, decided to make it a simple plugin, and now want to take it a step further &#8211; add more features, a complex GUI with some dialogs etc&#8230;</p>
<p>If you are still working with the script editor by now, things will most likely start to get out of hand as you introduce more modules and classes, deal with more code and more functionality.</p>
<p>This is the point where you might want to look out for a little help.</p>
<p>We are going to set up an IDE (Integrated Development Environment), talk a bit about modules/packages and finally I will try to give some general hints and tips.<br />
<br/></p>
<h1>Coding Environment/IDE:</h1>
<h2>Prepare Cinema 4D:</h2>
<p>You may skip this part, but I highly recommend it:</p>
<ul>
<li>Make a copy of your Cinema 4D installation &#8211; name it <em>&#8220;Cinema 4D R12 Dev&#8221;</em> for example.</li>
<li>Get rid of all Cinema 4D plugins you don&#8217;t need for your development</li>
<li>Place an empty text file named <em>&#8220;c4d_debug.txt&#8221;</em> into the root folder of your Cinema 4D copy.</li>
</ul>
<p>This will slow Cinema 4D down a bit, but enables you to monitor memory leaks.</p>
<p>We will add some useful things on Cinema 4D-side later &#8211; for now let&#8217;s continue with the Eclipse setup&#8230;<br />
<br/></p>
<h2>Eclipse:</h2>
<p><img class="alignnone size-full wp-image-1217" title="eclipse" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/eclipse.jpg" alt="" width="683" height="101" /></p>
<p>If you never used one, think of an IDE as your workshop, it’s a collection of tools as well as the place where you do and organize your coding work.</p>
<p>Eclipse is one of the most popular &#8211; its Java based, open source, free to use and most importantly has excellent support for python.</p>
<p>So let&#8217;s start by downloading and installing Eclipse Classic from <a href="http://www.eclipse.org/downloads/" target="_blank">http://www.eclipse.org/downloads/</a><br />
If you don&#8217;t have the <a href="http://www.java.com/de/download/"  target="_blank">Java Runtime Environment</a> installed jet, you need to do this first.<br />
<br/></p>
<h2>PyDev:</h2>
<p>As said before, Eclipse has excellent python support &#8211; but not out of the box, so we are going to install <a href="http://www.pydev.org" target="_blank">PyDev</a>.</p>
<p>PyDev will help you coding by adding syntax highlighting, code completion and much more.<br />
Should you encounter any trouble with the following steps, please refer to the PyDev <a href="http://pydev.org/manual_101_install.html" target="_blank">installation manual</a>.</p>
<ul>
<li>After installation, startup Eclipse, click <em>&#8220;Help&#8221;, </em>and chose <em>&#8220;Install New Software&#8230;&#8221;.</em></li>
<li>Next click the <em>&#8220;Add&#8230;&#8221;</em> button, type in <em>&#8220;PyDev&#8221;</em> as name and <em>&#8220;http://pydev.org/updates&#8221; </em>as location &#8211; then confirm.</li>
<li>Now enter <em>&#8220;PyDev&#8221;</em> in the <em>&#8220;Work with:&#8221;</em> field, you should see an entry<em> &#8220;PyDev for Eclipse&#8221; </em>- check it and click <em>&#8220;Next&#8221;.</em></li>
</ul>
<p>After confirming again and accepting the terms, it will download and install.</p>
<ul>
<li>Click <em>&#8220;Windows&#8221;</em> and open the <em>&#8220;Preferences&#8221;</em> dialog.</li>
<li>Select PyDev and the child <em>&#8220;Interpreter &#8211; Python&#8221;</em></li>
<li>Click <em>&#8220;New&#8230;&#8221;</em>, input <em>&#8220;Python Cinema 4D&#8221;</em> as name and browse to your Cinema 4D installation.</li>
<li>In <em>&#8220;/resource/modules/python/res/Python.win64.framework/&#8221;</em> select the <em>python.exe</em>.</li>
<li>Confirm your selection and the paths PyDev wants to add to your syspath.</li>
</ul>
<p>So much for the PyDev installation itself, now we have to associate the Cinema 4D Python plugin extension *.pyp with PyDev to enable syntax highlighting and code completion for those files as well:</p>
<ul>
<li>Open <em>&#8216;Window&#8217;</em> within the file-menu and click <em>&#8216;Preferences&#8217;</em></li>
<li>Select <em>&#8216;General&#8217; -> &#8216;Content Types&#8217;</em> from the list on the left.</li>
<li>In the <em>&#8216;Content types:&#8217;</em> view on the right, unfold <em>&#8216;Text&#8217;</em> and click <em>&#8216;Python File&#8217;</em></li>
<li>Hit the <em>&#8216;Add&#8230;&#8217;</em> button of the <em>&#8216;File associations:&#8217;</em> list on the lower right, type <em>&#8220;*.pyp&#8221;</em> into the popup and confirm.</li>
</ul>
<p>Its helpful to add a file containing all symbols of the Cinema 4D Python API’s “c4d” package to the ‘site-packages folder to spice up the auto-completion – <a href="http://www.smart-page.net/py4d/c4d.zip">grab it here</a>.</p>
<p>Place the file within <em>&#8220;/resource/modules/python/res/Python.win64.framework/Lib/site-packages</em><em>&#8220;</em><br />
<br/></p>
<h4>Note:</h4>
<p>You will have to update this file if you want to keep up to date with future versions of Cinema4D, it can be easily printed to the console by executing:</p>
<pre>for itm in dir(c4d):
    s = getattr(c4d, itm)
    print "%s = %s" % (itm, s)</pre>
<p><br/></p>
<h2>Project setup</h2>
<p><img class="alignnone size-full wp-image-1218" title="construction" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/construction.jpg" alt="" width="683" height="134" /></p>
<p>We take your IDE for a spin and create the first project:</p>
<ul>
<li>Click <em>&#8220;File&#8221; &#8211; &#8220;New&#8221;</em> and chose <em>&#8220;PyDev Project&#8221;</em></li>
<li>Input a Name for your Project and uncheck the <em>&#8220;Use default&#8221; </em>box below.</li>
<li>Browse to your Cinema 4D installations plugin folder, create a new directory with your plugins name and select it.</li>
<li>Select<em> &#8220;2.6&#8243; </em>from the <em>&#8220;Grammar Version&#8221;- </em>dropdown and leave the Interpreter set to default.</li>
<li>Last but not least uncheck the <em>&#8220;Create default &#8216;src&#8217; folder&#8230;&#8221; checkbox and hit &#8220;Finish&#8221;.</em></li>
</ul>
<p>To setup the needed folder structure, header- resource- and string files for your plugin, please read the Cinema 4D Python documentation <em>“Plugin structure”</em> &#8211;  especially <em>“Directory structure”</em> &#8211; and take a look at the Python plugin examples within the documentation &#8211; or the experimental plugin from <a href="http://www.smart-page.net/blog/2010/09/10/a-raytracer-in-python-for-cinema-4d" target="_blank">this post</a>:</p>
<p>Just remember this part is vital, so do not rush through it &#8211; at least read the section mentioned above and take a good look at the SDK examples.</p>
<p>Only if you have built C++ plugins before and are already familiar with the structure, you may&#8230;<br />
<br/></p>
<h4>Hint:</h4>
<p>You can also add your existing project files by just placing them within the plugin-directory we just created, or dragging them into the project-folder within Eclipse.</p>
<p>When organizing the file structure within your project, you are working with your file system &#8211; changes you do here are reflected on your harddisk.<br />
This also works the other way round, move something on the file system and Eclipse will update those changes to your project &#8211; while not always instantly.</p>
<p>You can press F5 within Eclipse to update a folder and its subfolders or the contents of a file.</p>
<p>Don&#8217;t worry, if the project-view is out of sync with the file system &#8211; Eclipse will tell you.<br />
<br/></p>
<h2>A coders Cinema 4D:</h2>
<p><img class="alignnone size-full wp-image-1219" title="c4d" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/c4d.jpg" alt="" width="683" height="112" /></p>
<p>We are all set with the IDE part &#8211; let&#8217;s tune the Cinema 4D installation a bit more to improve the workflow and finalize your coding environment.</p>
<p>If you didn&#8217;t add/import your existing code to the project we just created, write a simple hello world and fire up Cinema.</p>
<p>It&#8217;s a good idea to setup a developer friendly layout, I like adding the console window to the tabs on the right, next to the object manager &#8211; or even better to a side monitor.<br />
Should you be writing a CommandData Plugin, consider opening the Command Manager and dragging its icon into the layout, so you can quickly re-open it.</p>
<p>You will be launching and closing Cinema 4D a lot during development &#8211; it&#8217;s helpful to have a strategy to quickly start and close it.<br />
Place a link to Cinema 4D on your taskbar/dock, close it using <em>ALT+F4/Command+Q</em> or create a little python script containing <em>&#8220;exit()&#8221; </em>and add it to the layout/create a shortcut.</p>
<p>Finally, open your Plugin as well as everything you need to test its functionality and save the layout as startup layout.</p>
<p>If you have a test document that you need to check your plugin, press <em>CTRL+E</em>, click the &#8220;Open Preferences Folder&#8230;&#8221; button and place it as &#8220;default.c4d&#8221; within that folder so it will load on startup.</p>
<p>You long got the idea &#8211; try to prepare everything so you don&#8217;t have to spend time doing recurring tasks on every unit-test you are going to make during development.<br />
<br/></p>
<h2>Some additional tools:</h2>
<p>It&#8217;s often helpful to keep an eye on memory consumption and or active threads so I always have the task manager/activity monitor in reach when coding.</p>
<p>And while not really necessary, it&#8217;s convenient to have a good, fast text editor with Python syntax highlighting so you are able to read a file or snippet without having to launch the IDE first.<br />
I can recommend <a href="http://notepad-plus-plus.org/" target="_blank">Notepad++</a> and <a href="http://macromates.com/" target="_blank">TextMate </a>or <a href="http://www.gnu.org/software/emacs/" target="_blank">Emacs </a>for this job.<br />
<br/></p>
<h1>Working with eclipse:</h1>
<p><img class="alignnone size-full wp-image-1220" title="prototype" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/prototype.jpg" alt="" width="683" height="134" /></p>
<p>Eclipse in combination with PyDev is a mighty! tool &#8211; Aside from the obvious killer features &#8211; syntax highlighting and code completion, there is a ton of others.</p>
<p>Often you will discover some that will make you feel bad for not having used them right from the start, so I&#8217;ll try to point out the most useful, while I encourage you to read up on Eclipse and PyDev.<br />
<br/></p>
<h3>The Find/Replace Dialog</h3>
<p>Press CTRL+F for all your search and replace needs – just listing it to make you aware of the direction-, selection- and regex support.<br />
If you haven&#8217;t used regular expressions jet, you should directly head over to <a href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank">Wikipedia </a>- you won&#8217;t regret it.</p>
<p>Even more powerful is the&#8230;<br />
<br/></p>
<h3>Search Dialog</h3>
<p>CTRL+H opens the global or project wide search – here you can also replace over all files.</p>
<p>Just keep in mind that the &#8220;PyDev Search&#8221; tab does only look within *.py files while the &#8220;File Search&#8221; tab by default searches over a *.* pattern.<br />
<br/></p>
<h3>Compare feature and history</h3>
<p>Just select two files, right click and chose <em>&#8220;Compare with&#8221; -&gt; &#8220;Each other&#8221;.</em></p>
<p>You can also compare a file with an earlier state of itself by choosing <em>&#8220;Local history&#8221;.</em></p>
<p>This is another huge plus of using an Eclipse &#8211; don&#8217;t worry anymore about changing huge sections of code or commenting it &#8211; just go ahead and delete it &#8211; you can always return to an earlier state using the &#8220;History&#8221;- tab.</p>
<p>But use this with care, as it’s possible to lose the history by moving or re-creating a project and it’s not infinite.<br />
<br/></p>
<h3>Tabbed views</h3>
<p>You can drag a tab to one side of the code view until a small arrow appears &#8211; the tab will then snap to that side, splitting your view so you can work with multiple source files at the same time.</p>
<p>This is very useful when working with the header-, resource- or string files of your project as you can code on the left and copy &#8216;n paste ID&#8217;s from the right for example.<br />
<br/></p>
<h1>Coding python for Cinema 4D:</h1>
<p><img class="alignnone size-full wp-image-1221" title="python" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/python.jpg" alt="" width="683" height="126" /></p>
<p>We have setup the coding environment &#8211; how about doing some programming now?</p>
<p>This will be a loose collection of tips that are all more or less Cinema 4D related, but mostly  good practice in general.<br />
<br/></p>
<h3>Modules and namespace:</h3>
<p>First &#8211; this is <a href="http://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank">OOP </a>(Object Oriented Programming) and your project&#8217;s structure should reflect that.</p>
<p>In general, classes and modules are a good thing, it&#8217;s a far more common fault to have less abstraction than too much.</p>
<p>Packages/Modules are also the key to keep your code organized, manageable &#8211; AND reusable.</p>
<p>So if you are going to write something that you might want to use again later, consider spending the extra time to make it a bit more user/coder-friendly and build a class or module.</p>
<p>When working with python and modules you have to keep a close eye on naming and namespace, especially in context with the Cinema 4D SDK.</p>
<p>Be creative and use unique module names &#8211; this will keep things easier when you are using other modules &#8211; and you will &#8211; at least the ones from the Cinema 4D API.<br />
Also be careful when importing from modules &#8211; it&#8217;s rarely a good idea to just import everything (<em>from foo import *</em>) &#8211; instead carefully select the members you really need and give everyone its own import line rather than stacking them with commas in one.</p>
<p>It&#8217;s often better to just import the module into your namespace and reference the members via <em>module.foo</em> – you don’t pollute your namespace and it’s more readable.</p>
<p>In any case you should avoid the API&#8217;s module AND member names like the plaque.</p>
<p>For example if you extend the GeDialog Class and have a method <em>&#8220;def close(self):&#8221;</em> &#8211; but make the slight mistake to call it as <em>&#8220;Close()&#8221;</em>, you might end up with a similar behavior but wonder for minutes while your dialog just closes without saving it&#8217;s settings first (or whatever “<em>close()“</em> should have done).</p>
<p>I know for some this is basic stuff &#8211; many have their own patterns for this and that’s ok!</p>
<p>Whatever you do &#8211; be consistent and aware of your namespace.<br />
<br/></p>
<h3>Symbols:</h3>
<p><img class="alignnone size-full wp-image-1223" title="symbols" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/symbols1.jpg" alt="" width="683" height="112" /></p>
<p>As you need to keep track of the enums within the c4d_symbols.h, it is best to define every integer by yourself and not auto-enumerate them.</p>
<p>Then mirror those symbols to a *.py file called <em>&#8220;ids.py&#8221;</em> and be careful to update both should you change them or introduce new ones.</p>
<p>Instead of hardcoding ID&#8217;s, you should always use the symbol within the c4d-package.<br />
Should you ever need to identify a symbol by it&#8217;s integer value (for example if you want to check for a certain flag that is returned) &#8211; this little script will help you out:</p>
<pre>import c4d;
from c4d import gui; 

def main():
    wanted = gui.RenameDialog("ID to search for...")
    outp = ""

    for itm in dir(c4d):
        s = getattr(c4d, itm)
        if s == int(wanted):
            outp += "%s = %s\n" % (itm, s)

    gui.MessageDialog("Sorry - none found..." if outp == "" else outp)

if __name__=='__main__':
    main()</pre>
<p><br/></p>
<h3>API calls / performance:</h3>
<p>Don&#8217;t get me wrong &#8211; the Python API is blazing fast &#8211; so fast you often can&#8217;t tell the difference to C++ &#8211; but still, API calls take time.<br />
When working with thousands of objects, this quickly adds up no matter how fast each individual call is.</p>
<p>Try to limit those calls in sections of your code, where you really need performance &#8211; look for ways to keep states within your own plugin logic rather than querying them form Cinema 4D whenever possible.</p>
<p>If you are looking for bottlenecks, be sure to check out <a href="http://docs.python.org/library/profile.html" target="_blank">cProfile </a>– it’s great.<br />
<br/></p>
<h3>Prototyping:</h3>
<p>Using an IDE doesn&#8217;t forbid you to use Cinema 4D&#8217;s script editor and console to quickly whip up and test something &#8211; you can even write and directly execute a simple test script within eclipse if you are working on parts of your plugin that don&#8217;t need the Cinema SDK (some kind of parser for example) and take advantage of the PyDev debugger.<br />
<br/></p>
<h3>Debugging:</h3>
<p>The lack of a real debugger can be compensated by using the <a href='http://www.smart-page.net/blog/2011/05/29/debugging-cinema-4d-python-plugins-with-pydev/' target='_blank'>PyDev remote debugger</a>, pythons inspect module and the logging package.</p>
<p>Remember that there is a limit to the amount of characters the Cinema 4D console can output for a single print command.</p>
<p>Also take a look at <a href="http://docs.python.org/library/sys.html" target="_blank"><em>sys.exc_info()</em></a><br />
<br/></p>
<h3>Garbage Collection:</h3>
<p>When introducing <a href="http://en.wikipedia.org/wiki/Circular_reference" target="_blank">circular references</a> you should use <a href="http://docs.python.org/library/weakref.html" target="_blank">weak references</a> to give the garbage collector a hand.<br />
<br/></p>
<h3>Compilation:</h3>
<p><a href="http://www.smart-page.net/blog/wp-content/uploads/2011/05/stuff.jpg" rel="lightbox[1215]"><img class="alignnone size-full wp-image-1226" title="stuff" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/stuff.jpg" alt="" width="683" height="112" /></a></p>
<p>How about shipping your plugin as precompiled byte code?</p>
<p>This will make Cinema 4D start up faster &#8211; as the compilation of your plugin can be skipped, obfuse your source and still be platform interoperable.</p>
<p>Just copy your plugin, open the console/terminal and execute <em>&#8220;python.exe -<a href="http://docs.python.org/library/compileall.html" target="_blank">mcompileall </a>C:\PathToMyPlugin&#8221;</em> and delete all *.py files afterwards.</p>
<p>Note that this might not work in some cases, so be sure to test your plugins functionality again.<br />
<br/></p>
<h3>Platform dependency:</h3>
<p>While Python is platform-independent, there are still some things to keep in mind.</p>
<p>Don&#8217;t use backslashes in paths but slashes &#8211; they are understood by windows AND mac OS.</p>
<p>You can also use <a href="http://docs.python.org/library/platform.html" target="_blank"><em>platform.system()</em></a> to determine on what OS your plugin runs on and import modules after a conditional check &#8211; for example:</p>
<pre>if platform.system().lower() == "windows":</pre>
<pre>    import winsound
    winsound.PlaySound(os.path.join(os.path.dirname(__file__), "../res/snd", "DingSound.wav"),
winsound.SND_FILENAME)</pre>
<p><br/></p>
<h3>GUI &#8211; Threading:</h3>
<p>It&#8217;s the old story, if the GUI thread has to wait for your plugin, you lock up Cinema 4D &#8211; unacceptable for the user.</p>
<p>Doing time intensive stuff within your own threads is the simple solution to this, but keep in mind that you can&#8217;t have them call the GUI thread &#8211; instead use messages and the GeDialog&#8217;s <em>SetTimer().</em><br />
<br/></p>
<h3>Resource reference:</h3>
<p>Classes that use the &#8220;plugins&#8221; module need a reference to the plugins resource pointer.</p>
<p>This can be handled by importing those classes within the plugins *.pyp file and setting the class variable <em>&#8220;__res__&#8221;</em> or using a <a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank">singleton </a>(see below).<br />
<br/></p>
<h3>Singletons and invading Borgs:</h3>
<p><img class="alignnone size-full wp-image-1224" title="borg" src="http://www.smart-page.net/blog/wp-content/uploads/2011/05/borg.jpg" alt="" width="683" height="107" /></p>
<p>This is something for the advanced developer &#8211; and kind of a hot topic too.</p>
<p>The use of globally accessible objects or ‘globals’ is often considered bad practice but also unavoidable in some cases (logger) and python even somewhat encourages it.</p>
<p>So if you know what you are doing and think about using a singleton, you might want to take a look at the &#8220;borg&#8221;-(anti)pattern &#8211; a monostate proxy with a twist.</p>
<pre>class Borg:</pre>
<pre>__we_are_one = {}</pre>
<pre>    def __init__(self):       
    self.__dict__ = self.__we_are_one</pre>
<p><br/></p>
<h1>Still alive</h1>
<p>This was a lot of compressed stuff to digest, I know, but please do me the favor and don’t let any of this scare you off, it’s easier and more fun than you would expect.</p>
<p>I am sorry some topics where not covered in the depth they deserve -  it wasn’t easy to keep this a readable post rather than a book…</p>
<p>I hope this still was helpful to someone, if you have any questions, thoughts or would like me to write a more detailed post on a certain topic &#8211; let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2011/05/09/advanced-python-plugin-coding-for-cinema-4d/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The Kopernikus Orrery &#8211; our solar system in Unity</title>
		<link>http://www.smart-page.net/blog/2010/07/27/the-kopernikus-orrery-our-solar-system-in-unity/</link>
		<comments>http://www.smart-page.net/blog/2010/07/27/the-kopernikus-orrery-our-solar-system-in-unity/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 21:28:57 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Unity 3D]]></category>
		<category><![CDATA[Kopernikus]]></category>
		<category><![CDATA[Orrery]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=1144</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/07/27/the-kopernikus-orrery-our-solar-system-in-unity/" title="The Kopernikus Orrery &#8211; our solar system in Unity"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/orrery.4bkgzqqwbyr5a88kw4ocook8.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The Kopernikus Orrery &#8211; our solar system in Unity" style="float:left;padding:0 10px 10px 0;" ></a>Humanity has presumably gazed at the stars long before the invention of speech and the concept of numbers&#8230; But it took until the middle of the last millennia till we really understood our own place within the cosmic clockwork. Checkout the Kopernikus Planetarium! In 1704, George Graham and Thomas Tompion build a mechanical, heliocentric illustration [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/07/27/the-kopernikus-orrery-our-solar-system-in-unity/" title="The Kopernikus Orrery &#8211; our solar system in Unity"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/orrery.4bkgzqqwbyr5a88kw4ocook8.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The Kopernikus Orrery &#8211; our solar system in Unity" style="float:left;padding:0 10px 10px 0;" ></a><p>Humanity has presumably gazed at the stars long before the invention of speech and the concept of numbers&#8230;</p>
<p>But it took until the middle of the last millennia till we really understood our own place within the cosmic clockwork.</p>
<p><strong>Checkout the <a href="http://www.smart-page.net/unity/sp_orrery/" target="_blank">Kopernikus Planetarium!</a></strong></p>
<p><strong><span id="more-1144"></span><br />
</strong></p>
<p>In 1704, <a href="http://en.wikipedia.org/wiki/George_Graham_%28clockmaker%29" target="_blank">George Graham</a> and <a href="http://en.wikipedia.org/wiki/Thomas_Tompion" target="_blank">Thomas Tompion</a> build a mechanical, heliocentric illustration of the solar system &#8211; a copy was made for the Earl of Orrery &#8211; hence the name &#8220;<a href="http://en.wikipedia.org/wiki/Orrery" target="_blank">Orrery</a>&#8220;.</p>
<p>Recently my fellow worker <a href="http://www.pa3d.de" target="_blank">Philipp Althoff</a> introduced me to those fascinating devices and we decided to build one.</p>
<p><img class="alignnone size-full wp-image-1147" title="orrery1" src="http://www.smart-page.net/blog/wp-content/uploads/2010/07/orrery1.jpg" alt="" width="683" height="169" /><br />
<br/></p>
<p>As orrerys naturally show a scaled version of the solar system, high precision is vital for the device will quickly start to become inaccurate.</p>
<p>Philipp did an outstanding job measuring, modeling and texturing a model that also is completely parametric, so we could freely scale its polygon count for use in Unity 3D.</p>
<p>Klaus Hünig from <a href="http://www.Astromedia.de" target="_blank">Astromedia.de</a> was so kind to support us with plans and data of his &#8220;<a href="http://astromedia.de/" target="_blank">Kopernikus-Planetarium</a>&#8220;, a beautiful orrery construction kit.</p>
<p>While I did my best to research and calculate the exact orbits, directions and pivots, Mr. Hünig pointed out my errors and helped to refine the model.<br />
<br/></p>
<h2>Conclusion</h2>
<p>The result is a 5MB heavy, animated Unity 3D version of the Kopernikus orrery by Astromedia.de.<br />
Orbits and scales are accurate, the time scale able.</p>
<p><img class="alignnone size-full wp-image-1148" title="orrery2" src="http://www.smart-page.net/blog/wp-content/uploads/2010/07/orrery2.jpg" alt="" width="683" height="169" /><br />
<br/></p>
<p>Finally we also produced <a href="http://www.smart-page.net/unity/sp_orrery/setup.exe">a screensaver installer</a> (WIN) and Philipp did the finishing touch on the browser version by composing the celestial background music.</p>
<p><br/><br />
Hope you find it relaxing.</p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/07/27/the-kopernikus-orrery-our-solar-system-in-unity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Binary Kite &#8211; even more cubes with Py4D</title>
		<link>http://www.smart-page.net/blog/2010/06/25/the-binary-kite-even-more-cubes-with-py4d/</link>
		<comments>http://www.smart-page.net/blog/2010/06/25/the-binary-kite-even-more-cubes-with-py4d/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 12:47:17 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Binary kite]]></category>
		<category><![CDATA[C4D]]></category>
		<category><![CDATA[Cinema4D]]></category>
		<category><![CDATA[Generative geometry]]></category>
		<category><![CDATA[py4d]]></category>
		<category><![CDATA[Structure Synth]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=1096</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/06/25/the-binary-kite-even-more-cubes-with-py4d/" title="The Binary Kite &#8211; even more cubes with Py4D"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/binary_kite1.7nj4lk5ebzdm68sw00cg8soso.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The Binary Kite &#8211; even more cubes with Py4D" style="float:left;padding:0 10px 10px 0;" ></a>There are those popular structures we all know and love because they simply look fascinating from every angle &#8211; like the Sierpinski triangle, the Pythagoras tree or the Menger sponge. Generative geometry is one more proof that math is beautiful no matter how basic. Recently I stumbled upon a new pattern that is also phenomenally [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/06/25/the-binary-kite-even-more-cubes-with-py4d/" title="The Binary Kite &#8211; even more cubes with Py4D"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/binary_kite1.7nj4lk5ebzdm68sw00cg8soso.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The Binary Kite &#8211; even more cubes with Py4D" style="float:left;padding:0 10px 10px 0;" ></a><p>There are those popular structures we all know and love because they simply look fascinating from every angle &#8211; like the <a href="http://en.wikipedia.org/wiki/Sierpinski_triangle" target="_blank">Sierpinski triangle</a>, the <a href="http://en.wikipedia.org/wiki/Pythagoras_tree" target="_blank">Pythagoras tree</a> or the <a href="http://en.wikipedia.org/wiki/Menger_sponge" target="_blank">Menger sponge</a>.<br />
Generative geometry is one more proof that math is beautiful no matter how basic.</p>
<p>Recently I stumbled upon a new pattern that is also phenomenally simple but produces rather complex shapes &#8211; the &#8220;Binary Kite&#8221;.</p>
<p><span id="more-1096"></span></p>
<p>I first saw it in Mikael Hvidtfeldt Christensen&#8217;s &#8216;<a href="http://structuresynth.sourceforge.net/" target="_blank">Structure Synth</a>&#8216; &#8211; an ingenious tool for exploration of generative 3D structures.</p>
<p>Basically it&#8217;s a 3D array of randomly black/white colored cubes that slightly scale(linear) and rotate(noise) per iteration on one axis.<br />
What makes it look so interesting is that each items transformation matrix is subordinated to its predecessor on that axis.</p>
<p>Initially, I played around with the kite in Unity 3D but quickly discovered that it can´t be animated at high iterations.<br />
<br/><br />
So I fired up C4D and wrote a simple Py4D generator.<br />
<br/></p>
<h2>The results</h2>
<p>I did end up with this gorgeous picture of a 30*30*500 cubes kite (5400000 polygons) (<a href="http://www.smart-page.net/py4d/sp_kite/binary_kite.jpg" target="_blank" rel="lightbox[1096]">fullsize</a>):</p>
<p><a href="http://www.smart-page.net/py4d/sp_kite/binary_kite_small.jpg" target="_blank" rel="lightbox[1096]"><img class="alignnone size-full wp-image-1097" title="binary_kite_01" src="http://www.smart-page.net/blog/wp-content/uploads/2010/06/binary_kite_01.jpg" alt="" width="683" height="169" rel="" /></a></p>
<p>Here is a closeup from the same viewpoint (<a href="http://www.smart-page.net/py4d/sp_kite/binary_kite_close.jpg" target="_blank" rel="lightbox[1096]">fullsize</a>):</p>
<p><a href="http://www.smart-page.net/py4d/sp_kite/binary_kite_close_small.jpg" target="_blank" rel="lightbox[1096]"><img class="alignnone size-full wp-image-1098" title="binary_kite_02" src="http://www.smart-page.net/blog/wp-content/uploads/2010/06/binary_kite_02.jpg" alt="" width="683" height="169" /></a></p>
<p>Last but not least I rendered this short animation of a <a href="http://www.vconverter.de/?file=binary_kite" target="_blank">5*5*150 kite growing</a>:</p>
<p><a href="http://www.vconverter.de/?file=binary_kite" target="_blank"><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/06/binary_kite_03.jpg" alt="" title="binary_kite_03" width="683" height="169" class="alignnone size-full wp-image-1118" /></a></p>
<p>Want to render your own kite with even more cubes? Grab the <a href="http://www.smart-page.net/python/BinaryKite4Py.c4d">scene file here</a>.</p>
<p><strong><span style="color: #ff9900;">Update:</span></strong> <em>The file has been updated to work with the R12 version of Cinema 4D.</em></p>
<p><strong><span style="color: rgb(255, 102, 0);">Hint:</span></strong><br />
<em>Remember to uncheck &#8220;Optimize cache&#8221; in the Python Generator´s properties if you want to animate the parameters.</em><br />
<br/></p>
<h2>Conclusion</h2>
<p>While Structure Synth is awesome, Cinema 4D and Py4D are a great way to visualize generated geometry too as Cinema&#8217;s render instances enable you to work with millions of objects.<br />
<br/><br />
Cheers<br />
<br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/06/25/the-binary-kite-even-more-cubes-with-py4d/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Conway&#8217;s Game of Life 3D &#8211; huge amount of objects in Unity</title>
		<link>http://www.smart-page.net/blog/2010/06/10/conway%c2%b4s-game-of-life-3d-huge-amount-of-objects-in-unity/</link>
		<comments>http://www.smart-page.net/blog/2010/06/10/conway%c2%b4s-game-of-life-3d-huge-amount-of-objects-in-unity/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 13:24:49 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Unity 3D]]></category>
		<category><![CDATA[CombineMeshes]]></category>
		<category><![CDATA[Conway]]></category>
		<category><![CDATA[Game of Life]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=1032</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/06/10/conway%c2%b4s-game-of-life-3d-huge-amount-of-objects-in-unity/" title="Conway&#8217;s Game of Life 3D &#8211; huge amount of objects in Unity"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/gol.3k7231q2u7h2qskk884ws0gk0.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Conway&#8217;s Game of Life 3D &#8211; huge amount of objects in Unity" style="float:left;padding:0 10px 10px 0;" ></a>Surely you have already heard of Conway&#8216;s cellular automaton &#8211; the Game of Life. For those who haven&#8217;t, it&#8217;s a simulation of cells interacting with their neighbors by following a simple rule set on an infinite, two dimensional grid. So let&#8217;s add a dimension -> view the game of life in 3D! The Game of [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/06/10/conway%c2%b4s-game-of-life-3d-huge-amount-of-objects-in-unity/" title="Conway&#8217;s Game of Life 3D &#8211; huge amount of objects in Unity"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/gol.3k7231q2u7h2qskk884ws0gk0.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Conway&#8217;s Game of Life 3D &#8211; huge amount of objects in Unity" style="float:left;padding:0 10px 10px 0;" ></a><p>Surely you have already heard of <a href="http://en.wikipedia.org/wiki/John_Horton_Conway" target="_blank">Conway</a>&#8216;s <a href="http://en.wikipedia.org/wiki/Cellular_automaton" target="_blank">cellular automaton</a> &#8211; the <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Game of Life</a>.</p>
<p>For those who haven&#8217;t, it&#8217;s a simulation of cells interacting with their neighbors by following a <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Rules" target="_blank">simple rule set</a> on an infinite, two dimensional grid.</p>
<p><strong>So let&#8217;s add a dimension -> <a href="http://www.smart-page.net/unity/sp_gol/" target="_blank">view the game of life in 3D</a>!</strong></p>
<p><span id="more-1032"></span><br />
The Game of Life has become famous not only in theoretical computer science, for it is <a href="http://en.wikipedia.org/wiki/Turing_complete" target="_blank">Turing Complete</a>, generates the most interesting <a href="http://conwaylife.com/wiki/index.php?title=Category:Patterns" target="_blank">patterns</a> and is easy to implement.<br />
In flash it can be <a href="http://www.smart-page.net/as3/sp_life" target="_blank">done</a> in &#8216;one line&#8217; of code by means of a convolution filter.</p>
<p>So since 1970 the Game of Life has been explored by almost every programmer, it&#8217;s no surprise its &#8220;Glider&#8221; pattern became the official &#8220;<a href="http://en.wikipedia.org/wiki/Hacker_emblem" target="_blank">Hacker Emblem</a>&#8221; in 2003.</p>
<p>Customarily it&#8217;s visualized by a 2D representation of the board/grid &#8211; however, it can be applied to 1D and 3D space as well.</p>
<p>While I find 3D versions/rule sets to be interesting too, there is a much simpler way to lift the game into three dimensions that also generates more beautiful patterns:<br />
Simply plotting the (visible) game grid´s state over time on the third axis perfectly visualizes the process and generates amazing shapes&#8230; or at least very interesting greebles <img src='http://www.smart-page.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<br/><br />
<h2>Why Unity?</h2>
<p>The only issue is the amount of cells to draw &#8211; visualizing a small 10*10 field over 100 generations already means handling up to 10k cubes or sprites.</p>
<p>And I had an even higher amount in mind, so flash wouldn&#8217;t get me anywhere this time.</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/06/gol3.jpg" alt="" title="gol3" width="683" height="169" class="alignnone size-full wp-image-1084" /></p>
<p>First I thought about building a standalone app, then using <a href="http://processing.org/" target="_blank">Processing</a> or <a href="http://www.py4d.com/" target="_blank">Py4D</a>&#8230;</p>
<p>There it hit me &#8211; Unity! As long as OpenGL isn&#8217;t native to the web, <a href="http://unity3d.com/" target="_blank">Unity 3D</a> is definitely the best way to deliver intensive 3D games/apps via the browser.</p>
<p>As Unity offers C# as scripting language I immediately feel at home. Unity 3D reviewed in one word: Awesome!<br />
<br/><br />
<h2>The draw call issue</h2>
<p>But there is always a stumbling block hidden somewhere.</p>
<p>Since I am generating a lot of cubes (cells) on every frame, unity has to do a huge amount of draw calls &#8211; one for each object.<br />
The frame rate on my machine (Q6600, GF8600) dropped right into the basement.</p>
<p>The simple solution to this issue was to generate the complete generation of cubes and to fuse them to one single mesh using <a href="http://unity3d.com/support/documentation/ScriptReference/Mesh.CombineMeshes.html" target="_blank"><em>Mesh.CombineMeshes</em></a>.<br />
Normally this is done on startup  &#8211;  for the exact purpose of reducing draw calls &#8211; and I thought it could also be used at runtime for this scenario.</p>
<p>As objects are limited to 65k vertices, it wasn&#8217;t possible to merge the complete scene into one mesh, but that might have quickly become too time intensive as well.</p>
<p>So finally I was able to animate/display more than a million vertices.</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/06/gol12.jpg" alt="" title="gol1" width="683" height="169" class="alignnone size-full wp-image-1081" /><br />
<br/><br />
<h2>Conclusion</h2>
<p>The app now draws a 50*50 grid over a time of 200 generations &#8211; press space to reset the game and seed a new field of life cells.</p>
<p>Admittedly, it takes a lot of resources &#8211; a graphic adapter with at least 128MB is essential as the simulation might end up with 1.5 million vertices.</p>
<p><br/><br />
Hope you get to see some interesting patterns &#8211; have fun!<br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/06/10/conway%c2%b4s-game-of-life-3d-huge-amount-of-objects-in-unity/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Py4D Examples &#8211; particle party</title>
		<link>http://www.smart-page.net/blog/2010/04/10/py4d-examples-particle-party/</link>
		<comments>http://www.smart-page.net/blog/2010/04/10/py4d-examples-particle-party/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 15:33:42 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[boids]]></category>
		<category><![CDATA[Particles]]></category>
		<category><![CDATA[Physics]]></category>
		<category><![CDATA[py4d]]></category>
		<category><![CDATA[Stars]]></category>
		<category><![CDATA[Strange Attractor]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=964</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/04/10/py4d-examples-particle-party/" title="Py4D Examples &#8211; particle party"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/py4d_title1.3t0udbr1iklkrowok0g4owsgc.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Py4D Examples &#8211; particle party" style="float:left;padding:0 10px 10px 0;" ></a>I haven´t written about Py4D for quite a while now&#8230; In the meantime, Maxon has first announced a cooperation with &#8211; and now the acquisition of Sebastian Rath´s praised python implementation for Cinema4D. So finally &#8211; Cinema4D meets Python! Let´s celebrate with some cool experiments! If you are new to this blog or Py4D &#8211; [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/04/10/py4d-examples-particle-party/" title="Py4D Examples &#8211; particle party"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/py4d_title1.3t0udbr1iklkrowok0g4owsgc.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Py4D Examples &#8211; particle party" style="float:left;padding:0 10px 10px 0;" ></a><p>I haven´t written about <a href="http://www.py4d.com/" target="_blank">Py4D</a> for quite a while now&#8230;</p>
<p>In the meantime, <a href="http://www.maxon.net" target="_blank">Maxon</a> has first announced a cooperation with &#8211; and now the acquisition of Sebastian Rath´s praised python implementation for Cinema4D.</p>
<p>So finally &#8211; Cinema4D meets Python!</p>
<p><strong>Let´s celebrate with some cool experiments!</strong></p>
<p><strong><span id="more-964"></span><br />
</strong></p>
<p>If you are new to this blog or Py4D &#8211; a short introduction:</p>
<p>Py4D enhances C4D with a standard Python interpreter that provides access to the C4D SDK and allows to easily code platform indepentent scripts and plugins that control or extend C4D.</p>
<p>Basicly the same as COFFEE, C4D´s own scripting language, but Py4D has two major advantages:</p>
<ul>
<li> It follows the C++ SDK more closely and implements it further than COFFEE does.</li>
<li>It is a easy to pickup, widely known language with a huge community and tons of existing code and librarys.</li>
</ul>
<p><br/><br />
While C4D is a mighty tool in itself, this powerful scripting interface enables the user to work with external data, automate processes or build his own tools.</p>
<p>Being more the C++ type when it comes to plugin development and C4D, I enjoy being able to solve small problems just by hacking a few lines of code into the script manager.<br />
I also prototype most of my plugins in Py4D before I start developing in C++ &#8211; it´s just more convenient.<br />
The step of compiling for every test takes much more time in the long run.</p>
<p><br/></p>
<h3>So here´s the meat:</h3>
<p>Four simple examples how to have a good time with Py4D and some particles&#8230;</p>
<p><del datetime="2010-09-09T18:26:28+00:00">Everyone requires C4D R11.5, the Thinking Particles module and the actual version of Py4D.</del></p>
<p><strong><span style="color: #ff9900;">Update:</span></strong> <em>All files have been updated to work with the R12 version of Cinema 4D.</em></p>
<p>Py4D has been through some changes since the open beta started, so I took the time to update the scripts I published in the <a href="http://www.smart-page.net/blog/2009/08/07/py4d-boids/" target="_blank">boids</a>, and <a href="http://www.smart-page.net/blog/2009/09/15/strange-attractor-c4dpy4d-particle-bench/" target="_blank">strange attractor</a> posts and included them here.</p>
<p><em>Click the images for a preview.</em><br />
<br/></p>
<h3>1. Stars4Py4D</h3>
<p><a href="http://www.smart-page.net/as3d/sp_stars" target="_blank"><img class="size-full wp-image-965 alignnone" title="py4" src="http://www.smart-page.net/blog/wp-content/uploads/2010/04/py4.jpg" alt="" width="680" height="100" /></a></p>
<p>This is a Py4D port of the <a href="http://www.smart-page.net/blog/2010/04/03/cruising-the-cosmos-sagan-style-flash-in-outer-space/" target="_blank">Sagan experiment</a> I did in flash <- check out this link, it´s fun <img src='http://www.smart-page.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>A good and simple first step with particles - position vectors get parsed from a CVS <a href="http://www.astronexus.com/node/34" target="_blank">database</a> and from a galaxy of suns&#8230; “My God. It’s full of stars!”</p>
<p>Hint: <em>this example might be the best to start with, as it includes comments &#8211; the others don´t, because they use pretty much the same pattern. </em> </p>
<p>Just <a href="http://www.smart-page.net/python/Stars4Py.zip" target="_blank">download the package</a>, load the scene and change the path to the CSV file within the &#8220;file&#8221; user data field of the Py4D Tag.</p>
<p><br/></p>
<h3>2. Phy4D</h3>
<p><a href="http://www.vconverter.de/?file=py4d_simple_phy" target="_blank"><img class="alignnonesize-full wp-image-968" title="py2" src="http://www.smart-page.net/blog/wp-content/uploads/2010/04/py2.jpg" alt="" width="680" height="100" /></a></p>
<p>A very simple adaptation of a 2D &#8220;physic engine&#8221; &#8211; works only with spheres.<br />
The direction of gravitation is animated to make this a little more interesting.</p>
<p>Have a look at the <a href="http://www.vconverter.de/?file=py4d_simple_phy" target="_blank">preview video</a> and <a href="http://www.smart-page.net/python/Phy4Py.c4d">scene file</a>.</p>
<p><br/></p>
<h3>3. Boids</h3>
<p><a href="http://www.vconverter.de/?file=sp_boids" target="_blank"><img class="alignnonesize-full wp-image-970" title="py1" src="http://www.smart-page.net/blog/wp-content/uploads/2010/04/py1.jpg" alt="" width="680" height="100" /></a></p>
<p>This is simply a revival of the <a href="http://www.smart-page.net/blog/2009/08/07/py4d-boids/" target="_blank">Py4D Boids post</a> &#8211; same beast, but updated to the Py4D release version.<br />
The script creates a flocking boids swarm, that behaves according to the <a href="http://en.wikipedia.org/wiki/Boids" target="_blank">rules</a> outlined by Craig Reynolds.</p>
<p>Checkout <a href="http://www.vconverter.de/?file=sp_boids" target="_blank">this video</a> from Sebastian and get the <a href="http://www.smart-page.net/python/Boids4Py.c4d">scenefile</a>.</p>
<p><br/></p>
<h3>4. Strange Attractor</h3>
<p><a href="http://www.vconverter.de/?file=strangeattractor" target="_blank"><img class="alignnonesize-full wp-image-969" title="py3" src="http://www.smart-page.net/blog/wp-content/uploads/2010/04/py3.jpg" alt="" width="680" height="100" /></a></p>
<p>Again just the script from the original strange attractor post, but ported to the final SDK.<br />
View the <a href="http://www.vconverter.de/?file=strangeattractor" target="_blank">final rendering</a> and the <a href="http://www.smart-page.net/blog/2009/09/15/strange-attractor-c4dpy4d-particle-bench/" target="_blank">original post</a> &#8211; you can use the <a href="http://www.smart-page.net/as3/sp_safinder/" target="_blank">Strange Attractor Finder</a> to locate your very own, chaotic attractor!</p>
<p>Here´s the <a href="http://www.smart-page.net/py4d/SA4Py4D.c4d">scene file</a>.</p>
<p><br/></p>
<h3>Conclusion</h3>
<p>Python and Cinema4D are a great team and Py4D is THE alternative to COFFEE.</p>
<p>I hope this gives everybody who is interested in Py4D and controlling particles, a small head start, some inspiration or at least something fun to play with <img src='http://www.smart-page.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<br/><br />
Thanks to Sebastian for suggestions, support &#8211; and of course Py4D.</p>
<p><br/><br />
Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/04/10/py4d-examples-particle-party/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Cruising the cosmos Sagan style &#8211; flash in outer space</title>
		<link>http://www.smart-page.net/blog/2010/04/03/cruising-the-cosmos-sagan-style-flash-in-outer-space/</link>
		<comments>http://www.smart-page.net/blog/2010/04/03/cruising-the-cosmos-sagan-style-flash-in-outer-space/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 21:22:36 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Cosmos]]></category>
		<category><![CDATA[Fzip]]></category>
		<category><![CDATA[Galaxy]]></category>
		<category><![CDATA[Milky Way]]></category>
		<category><![CDATA[Particles]]></category>
		<category><![CDATA[Sagan]]></category>
		<category><![CDATA[Stars]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=933</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/04/03/cruising-the-cosmos-sagan-style-flash-in-outer-space/" title="Cruising the cosmos Sagan style &#8211; flash in outer space"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/cosmos.7ax277njjhexoggsgc0ccw4w8.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Cruising the cosmos Sagan style &#8211; flash in outer space" style="float:left;padding:0 10px 10px 0;" ></a>In his TV series &#8220;Cosmos&#8221;, Carl Sagan travels the universe in a &#8220;ship of the imagination&#8221;. Uninfluenced by the laws of physics, &#8220;perfect as a snowflake, organic as a dandelion seed&#8221;, this vessel carries him between galaxies, stars, and planets. And now you can cruise the cosmos too! Recently I watched cosmos again and remembered [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/04/03/cruising-the-cosmos-sagan-style-flash-in-outer-space/" title="Cruising the cosmos Sagan style &#8211; flash in outer space"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/cosmos.7ax277njjhexoggsgc0ccw4w8.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Cruising the cosmos Sagan style &#8211; flash in outer space" style="float:left;padding:0 10px 10px 0;" ></a><p>In his TV series <a href="http://en.wikipedia.org/wiki/Cosmos:_A_Personal_Voyage" target="_blank">&#8220;Cosmos&#8221;</a>, <a href="http://en.wikipedia.org/wiki/Carl_Sagan"  target="_blank">Carl Sagan</a> travels the universe in a &#8220;ship of the imagination&#8221;. </p>
<p>Uninfluenced by the laws of physics, &#8220;perfect as a snowflake, organic as a dandelion seed&#8221;, this vessel carries him between galaxies, stars, and planets.</p>
<p><b><a href="http://www.smart-page.net/as3d/sp_stars"  target="_blank">And now you can cruise the cosmos too!</a></b><br />
<br/><br />
<span id="more-933"></span><br />
Recently I watched cosmos again and remembered how that sequence fascinated me as kid.<br />
The sheer scale of the distances involved blew my mind. It still does today.</p>
<p>The concept has been revisited by many popular movies and media (Man in Black, The Simpsons&#8230;) and is always the same &#8211; the camera enters the universe, our galaxy, solar system and finally stops on earth &#8211; sometimes entering the microcosm, like the DNA of a cell.</p>
<p>Years ago I experimented with something like a <a href="http://www.smart-page.net/blog/2009/08/05/pyramidial-multiscale-86400px-gigapixel-image/"  target="_blank">pyramidial image</a> to archive this effect in flash, unfortunately the result didn´t create the feeling of depth that I had hoped for.</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/04/cosmos2.jpg" alt="" title="cosmos2" width="680" height="100" class="alignnone size-full wp-image-934" /></p>
<p>But flash has advanced in those years&#8230; as I wrote before, in the strange attractor <a href="http://www.smart-page.net/blog/2009/09/15/strange-attractor-c4dpy4d-particle-bench/" target="_blank">post</a>, <a href="http://www.unitzeroone.com/blog/2009/03/18/flash-10-massive-amounts-of-3d-particles-with-alchemy-source-included/" target="_blank">Ralph Hauwert</a> and <a href="http://blog.joa-ebert.com/2009/04/03/massive-amounts-of-3d-particles-without-alchemy-and-pixelbender/" target="_blank">Joa Ebert</a> have published some astonishing code that renders nearly half a million particles in real-time!</p>
<p>First I decided that I would work with real data &#8211; otherwise this would become just another &#8220;random stars / noise flying at you&#8221; screensaver.</p>
<p>But after some research I learned that the actual distance of nearby stars (called <a href="http://en.wikipedia.org/wiki/Parallax#Stellar_parallax" target="_blank">&#8220;stellar parallax&#8221;</a>) is not always known, so that most models and databases project stars onto the inside of a virtual sphere.</p>
<p>Finally I found the <a href="http://astronexus.com/node/34" target="_blank">HYG database</a> &#8211; &#8220;a subset of the data in three major catalogs: the Hipparcos Catalog,the Yale Bright Star Catalog (5th Edition), and the Gliese Catalog of Nearby Stars (3rd Edition)&#8221;.<br />
It contains about 120.000 stars, many including their parallaxes and conveniently cartesian coordinates, so I saved the step of calculating xyz from right ascension, declination and distance &#8211; like I had to with other databases I tested.</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/04/cosmos3.jpg" alt="" title="cosmos3" width="680" height="100" class="alignnone size-full wp-image-935" /></p>
<p>The CSV file got stripped of all additional data aside from the positions with a simple parser &#8211; that got it down from 20 to 4MB &#8211; still too big for my taste.</p>
<p>So I added the Fzip library to Joa´s AS3 only version of Ralph´s experiment, parsed the position vectors, scaled them and got my first view on our galaxy &#8211; breathtaking.</p>
<p>Scaling, controls and a simple clipping where swiftly implemented and everything was set for the voyage to the stars&#8230;</p>
<p><br/><br/></p>
<h3>Tribute &#8211; &#8220;A Glorious Dawn&#8221; displaced </h3>
<p>While watching the result, an idea struck my mind:<br />
As the z-axis movement of the camera or the zooming into the szene is done by simply scaling the particle positions, its obviously possible to change their parameters in realtime&#8230;</p>
<p>I remembered my <a href="http://www.smart-page.net/blog/2008/07/12/dynamic-displacement/" target="_blank">displacement experiment</a> with papervision and quickly added a color parameter to the particle class, loaded an flv video and compiled this:</p>
<p><a href="http://www.smart-page.net/as3d/sp_sagan" target="_blank"><br />
<strong>&#8220;A Glorious Dawn&#8221; live rendered to a displaced point cloud</strong></a></p>
<p><a href="http://www.smart-page.net/as3d/sp_sagan" target="_blank"><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/04/saganvox.jpg" alt="" title="saganvox" width="680" height="362" class="alignnone size-full wp-image-1021" /></a></p>
<p><br/><br/></p>
<h3>Conclusion</h3>
<p>It´s possible to handle an awful lot of particles with flash, even more if haxe/alchemy &#8211; inlining gets involved.<br />
As the displacement experiment shows, the dataset can even be dynamic!</p>
<p>And hey &#8211; these are real stars, so this is science! <img src='http://www.smart-page.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><br/><br />
Hint: turn up your gamma adjustment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/04/03/cruising-the-cosmos-sagan-style-flash-in-outer-space/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Smart PRS Cinema4D Keyframe Tag</title>
		<link>http://www.smart-page.net/blog/2010/03/22/smart-prs-cinema4d-keyframe-tag/</link>
		<comments>http://www.smart-page.net/blog/2010/03/22/smart-prs-cinema4d-keyframe-tag/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 16:01:52 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[C4D]]></category>
		<category><![CDATA[Cinema4D]]></category>
		<category><![CDATA[Keyframes]]></category>
		<category><![CDATA[record]]></category>
		<category><![CDATA[Tag]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=916</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/03/22/smart-prs-cinema4d-keyframe-tag/" title="Smart PRS Cinema4D Keyframe Tag"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/smartprs_blog.3bajy4ciedtxr4gkocw0c0g0k.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Smart PRS Cinema4D Keyframe Tag" style="float:left;padding:0 10px 10px 0;" ></a>Smart PRS is a Cinema4D tag that allows to record position, rotation and scale of one or multiple objects to key frames. This is especially useful for all, who want to bake Thinking Particel setups and don’t own the MOCCA module. Take a look at the demonstration Video. Recently I tried to use the AfterEffects [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/03/22/smart-prs-cinema4d-keyframe-tag/" title="Smart PRS Cinema4D Keyframe Tag"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/smartprs_blog.3bajy4ciedtxr4gkocw0c0g0k.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Smart PRS Cinema4D Keyframe Tag" style="float:left;padding:0 10px 10px 0;" ></a><p>Smart PRS is a Cinema4D tag that allows to record position, rotation and scale of one or multiple objects to key frames.</p>
<p>This is especially useful for all, who want to bake Thinking Particel setups and don’t own the MOCCA module.</p>
<p><a href="http://www.smart-page.net/smartprs" target="_blank"><strong>Take a look at the demonstration Video.</strong></a><br/> <br/> <br/><br />
<span id="more-916"></span><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/03/prs.jpg" alt="" title="prs" width="340" height="322" class="alignright size-full wp-image-930" />Recently I tried to use the AfterEffects export Option from Cinema4D to pass a simple particle animation to AE.</p>
<p>Unfortunately this didn´t work out – the issue is that all animation capable export formats/plugins rely on key frames, and objects animated via Xpresso/Thinking Particles are most times not even present in the timeline as they get generated as “Particle Geometry”.</p>
<p>While this can be easily fixed by creating them manually and linking the particle positions to them, it´s still impossible to export that animation without key frames.</p>
<p>Cinema4D offers the option to “bake” certain motions to key frames, but not from simulations.<br />
Actually there is a plug-in called “Cappuccino” within the MOCCA module that allows this, but if you are not into character animation, chances are you don´t have it handy.<br />
<br/><br />
SmartPRS makes those animations export-and editable by recording them as key frames while the simulation is running.<br />
After that, the Xpresso setup can be removed from the scene and the animation edited or exported.</p>
<p>The plug-in even allows to capture the position of an object that gets moved in real-time by the mouse.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/03/22/smart-prs-cinema4d-keyframe-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The laughing man incident &#8211; defacing the web with OpenCV</title>
		<link>http://www.smart-page.net/blog/2010/03/15/the-laughing-man-incident-defacing-the-web-with-opencv/</link>
		<comments>http://www.smart-page.net/blog/2010/03/15/the-laughing-man-incident-defacing-the-web-with-opencv/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 18:37:45 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[face detection]]></category>
		<category><![CDATA[Laughing man]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Viola-Jones]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=855</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/03/15/the-laughing-man-incident-defacing-the-web-with-opencv/" title="The laughing man incident &#8211; defacing the web with OpenCV"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/lm.dcfc3pdr9hpv4sgs88so8kw8s.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The laughing man incident &#8211; defacing the web with OpenCV" style="float:left;padding:0 10px 10px 0;" ></a>In the series GITS:SAC, a hacker called &#8220;the laughing man&#8221; defaces himself and other persons by digitally placing an animated logo over their face. Now he is back and defaces the entire internet! Look for yourself and check if your brain has already been hacked! This experiment is really just an excuse to play around [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/03/15/the-laughing-man-incident-defacing-the-web-with-opencv/" title="The laughing man incident &#8211; defacing the web with OpenCV"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/lm.dcfc3pdr9hpv4sgs88so8kw8s.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The laughing man incident &#8211; defacing the web with OpenCV" style="float:left;padding:0 10px 10px 0;" ></a><p>In the series <a href="http://en.wikipedia.org/wiki/Ghost_in_the_Shell:_Stand_Alone_Complex" target="_blank">GITS:SAC</a>, a hacker called &#8220;the laughing man&#8221; defaces himself and other persons by digitally placing an animated logo over their face.</p>
<p>Now he is back and defaces the entire internet!</p>
<p><b><a href="http://www.smart-page.de/experiments/laughingman" target="_blank">Look for yourself and check if your brain has already been hacked!</a></b></p>
<p><span id="more-855"></span><br />
This experiment is really just an excuse to play around with <a href="http://en.wikipedia.org/wiki/Haar-like_features" target="_blank">hair cascades</a>.</p>
<p>In 2001, Michael Jones and Paul Viola published their <a href="http://en.wikipedia.org/wiki/Viola-Jones_object_detection_framework" target="_blank">object detection framework</a>, that introduced the integral image and cascade classifiers combined with a learning algorithm to achieve fast detection of facial features.</p>
<p>This method is still the quasi standard in face detection and an implementation of their <a href="http://research.microsoft.com/~viola/Pubs/Detect/violaJones_IJCV.pdf" target="_blank">paper </a> is available within the <a href="http://opencv.willowgarage.com/wiki/" target="_blank">Open Computer Vision library</a>.</p>
<p>That code and even the whole library has been ported to flash and there are many  great experiments out there &#8211; one by <a href="http://mrdoob.com/blog/post/643" target="_blank">mr.doob</a> even featuring the laughing man.<br />
So this has already been done and explored with flash, but after <a href="http://www.smart-page.net/blog/2009/05/24/multiple-object-motion-detection/" target="_blank">my multiple object detection adventure</a> I just had to do something &#8220;interesting&#8221; with the Viola-Jones detection.</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/03/lm3.jpg" alt="" title="lm3" width="680" height="100" class="alignnone size-full wp-image-888" /></p>
<p>However the idea to analyze and manipulate every image on any page is problematic.</p>
<p>Initially I was tempted to try this with JavaScript, even if I had some concerns  regarding the performance &#8211; it should have been possible with modern browsers/engines &#8230; but sadly it isn’t.</p>
<p>The issue is the browser sandbox.</p>
<p>Sure, you can replace images within an html document on the same domain, but you can’t just load a page from a foreign domain into a frame and mess around with its contents. So in essence it´s the same cross domain policy that we know from the flash runtime and thus the solution to this is also the same: pull the desired content  to your domain through a proxy.</p>
<p>Doing this with just streams or images is fairly simple and can be coded within a few lines, but fetching a complete page is a different story.<br />
I did end up with a proxy that does this quite well but it struggles with redirects, certain JavaScripts and naturally flash, Silverlight or other plugin related content.</p>
<p>Still I find it quite reassuring to know that defacing a website isn´t an easy task.<br />
After all, this topic is quite close to phishing and other black-hat stuff&#8230;</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/03/lm2.jpg" alt="" title="lm2" width="680" height="100" class="alignnone size-full wp-image-884" /></p>
<p>The detection part, on the other hand was quite simple &#8211; the actual OpenCV source was built quickly and works like a charm. Intel and other people where kind enough to contribute some of their research to the library &#8211; in form of xml lists with capable classifiers.</p>
<p>Because the server has to download first and then to compute all the images at once, you will notice a delay when loading a page with many images or with huge ones, although, the detection runs very fast.<br />
Also I have it check every image twice &#8211; once with a frontal and then with a portrait classifier list.<br />
The detection rate is quite satisfying &#8211; somewhat around 60-70% I would guess.</p>
<p>It would be possible to further improve that rate if one could adjust it to a fixed environment.</p>
<h3>Conclusion</h3>
<p>Sandboxes and cross domain policies are a good thing even if they are known to cause headaches to developers.<br />
They protect us from frauds and make sure that others have to ask permission before they can use foreign content within their web apps.</p>
<p>Yet, given some time and motivation, they can be bypassed. So, always keep an open eye…</p>
<p>As for face detection: this isn´t just great fun to play around with but also has many interesting applications, spanning from camera tracking over to privacy (Google uses it to blur out faces in street view or to filter content for the image search) to security (face recognition).</p>
<p>I recommend OpenCV to anybody who wants to fool around with face/object detection or argumented reality<br />
- and there´s much more&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/03/15/the-laughing-man-incident-defacing-the-web-with-opencv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SmartAA &#8211; reconstruct anti aliasing with Pixel Bender</title>
		<link>http://www.smart-page.net/blog/2010/02/21/smartaa-reconstruct-anti-aliasing-with-pixel-bender/</link>
		<comments>http://www.smart-page.net/blog/2010/02/21/smartaa-reconstruct-anti-aliasing-with-pixel-bender/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 00:59:43 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[After Effects]]></category>
		<category><![CDATA[aliasing]]></category>
		<category><![CDATA[anti]]></category>
		<category><![CDATA[b-spline]]></category>
		<category><![CDATA[bicubic]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[Mitchell-Netravali]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[Pixel Bender]]></category>
		<category><![CDATA[reconstruct]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=801</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/02/21/smartaa-reconstruct-anti-aliasing-with-pixel-bender/" title="SmartAA &#8211; reconstruct anti aliasing with Pixel Bender"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/smartaa1.3nzh85x4xvebmsc00gc0o4440.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="SmartAA &#8211; reconstruct anti aliasing with Pixel Bender" style="float:left;padding:0 10px 10px 0;" ></a>About three decades ago, pixels where as big as toasters &#8211; and mostly green. Today we have millions of them to deal with, and the terms anti-/aliasing are part of our daily live and every time an image is scaled, it gets interpolated to keep those bad &#8220;stairs&#8221; away from our eyes. But what if [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/02/21/smartaa-reconstruct-anti-aliasing-with-pixel-bender/" title="SmartAA &#8211; reconstruct anti aliasing with Pixel Bender"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/smartaa1.3nzh85x4xvebmsc00gc0o4440.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="SmartAA &#8211; reconstruct anti aliasing with Pixel Bender" style="float:left;padding:0 10px 10px 0;" ></a><p>About three decades ago, pixels where as big as toasters &#8211; and mostly green.</p>
<p>Today we have millions of them to deal with, and the terms anti-/aliasing are part of our daily live and every time an image is scaled, it gets interpolated to keep those bad &#8220;stairs&#8221; away from our eyes.</p>
<p>But what if the source image is aliased in the first place?</p>
<p><b>Checkout the <a href="http://www.smart-page.net/as3/sp_smartaa" target="_blank">demo of SmartAA!</a></b><br />
<br/><br />
<span id="more-801"></span><br />
While upsaling is the most common cause of <a href="http://en.wikipedia.org/wiki/Aliasing" target="_blank">aliasing</a>, there are images that are naturally aliased &#8211; for example images from a 3D render engine.</p>
<p>Of course there are many ways to <a href="http://en.wikipedia.org/wiki/Antialiasing" target="_blank">antialias</a> cg images when generating them &#8211; for example by rendering to a higher resolution than targeted and downscaling the result (FSAA)- or by rendering and merging four slightly offset variations.</p>
<p>While this is as computational intensive as it sounds, modern GPU´s can handle this task rather easily as they have their buffers and hardwired magic to do so, but still it’s not uncommon to come along aliased images in the world of computer graphics.</p>
<p>So is all this material &#8220;useless&#8221; or can an image that has never seen any antialiasing, or has been upscaled with the <a href="http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation" target="_blank">nearest neighbour</a> method, be reconstructed?</p>
<p>In fact all that modern imaging software does when rescaling an image is reconstructing its pixels to fit the new dimensions &#8211; most times with a <a href="http://en.wikipedia.org/wiki/Bicubic_interpolation" target="_blank">bicubic filter</a>.</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/02/smartAA01.jpg" alt="" title="smartAA01" width="692" height="138" class="alignnone size-full wp-image-805" /></p>
<h3 style="margin-top:10px; margin-bottom:5px">SmartAA is a bicubic BC-spline reconstruction filter for PixelBender.</h3>
<p>Its 3&#215;3 kernel gathers all neighboring pixels of the one to reconstruct and weights them with the <a href="http://de.wikipedia.org/wiki/Mitchell-Netravali-Filter" target="_blank">Mitchell-Netravali</a>(german link) filter.</p>
<p>In essence, this means that each pixel is modified by the average color of its surrounding friends.<br />
While &#8220;average&#8221; being the wrong term here as the influence of each pixel is determined by the spline curve of the Mitchell-Netravali filter.</p>
<p>This eliminates those hard, &#8220;stair-like&#8221; artifacts of the aliasing by visually &#8220;softening&#8221; or unsharping the image.</p>
<p>However this is not simply a destructive blurring effect but a reconstructive analysis of the source &#8220;signal&#8221;.</p>
<p><br/><br />
There are many known filters that do this hard job &#8211; it´s not easy to reconstruct information that was partly lost (or never there in the first place).<br />
<img src="http://www.smart-page.net/blog/wp-content/uploads/2010/02/space.jpg" alt="" title="space" width="175" height="179" class="alignright size-full wp-image-811" /><br />
Thus all of them suffer of the same issues &#8211; the result always shows some artifacts.<br />
Mostly it’s a visible unsharping, <a href="http://en.wikipedia.org/wiki/Anisotropy" target="_blank">anisotropy </a>or the so-called &#8220;<a href="http://en.wikipedia.org/wiki/Ringing_artifacts" target="_blank">ringing</a>&#8220;.</p>
<p>In general bicubic reconstruction methods create the best results.</p>
<p>Among the various possible filter methods the windowed Sinc(<a href="http://en.wikipedia.org/wiki/Lanczos_resampling" target="_blank">Lanczos</a>)- and Mitchell-Netravali filter are chosen the most as their output is considered to be the best mix of the inevitable unsharping, anisotropy and ringing.</p>
<p>Just for the record: there are &#8220;better&#8221; solutions, the so called &#8220;adaptive&#8221; or &#8220;smart&#8221; filters that try separate methods on edges, fills and other structures.<br />
They are particularly useful when working with sequences of moving images (video) but again slow to compute.</p>
<p>SmartAA on the other hand is a quite simple implementation of the M.-N. filter and runs blazingly fast when run on the GPU &#8211; producing about 70 redraws per sec on a 1024*768 image.</p>
<p>Unfortunately it´s not nearly as fast on the CPU.<br />
If you have a rather slow machine, you will have seen the demo struggling to keep a 24fps framerate, so its just! that bit too slow to to antialias the pixelated output of a flash based C64 emulator.</p>
<p>That would have been cool&#8230; would love to see something like that.</p>
<p><br/><br />
I kept it flash compatible anyway &#8211; still there might be applications.</p>
<p>Its a matter of personal reception, but to me the M.-N. filter looks better on videos as the inbuild &#8220;smooth&#8221;-method.<br />
Anyway &#8211; flash video has been criticized enaugh for high cpu usage so lets not make things worse <img src='http://www.smart-page.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also: like any reconstruction filter it won´t work in any given scenario as there are some natural and some specific limitations.</p>
<p><img src="http://www.smart-page.net/blog/wp-content/uploads/2010/02/smartAA02.jpg" alt="" title="smartAA02" width="690" height="133" class="alignnone size-full wp-image-815" /></p>
<p><br/><br />
<img src="http://www.smart-page.net/blog/wp-content/uploads/2010/02/smartAA04.jpg" alt="" title="smartAA04" width="254" height="175" class="alignright size-full wp-image-823" /><br />
So what can SmartAA do and what not? Here is a feature/limitation list:</p>
<p><em>Features:</em></p>
<p>- Works with Photoshop, After Effects, Flash<br />
- Supports alpha channel<br />
- Is real-time</p>
<p><em>Limitations:</em></p>
<p>- Does no up/down scaling &#8211; just reconstruction of anti aliasing<br />
- Is scenario specific &#8211; for example text will often look strange<br />
- works only with artifacts in the same pixel space.</p>
<p><br/><br />
Let me elaborate on the last point:<br />
<img src="http://www.smart-page.net/blog/wp-content/uploads/2010/02/smartAA03.jpg" alt="" title="smartAA03" width="200" height="91" class="alignright size-full wp-image-817" /><br />
As SmartAA takes only neighbouring pixels into account it isn´t able to reconstruct aliasing effects that span over greater distances than 2 pixels.<br />
For example if an image exists of 4*4 pixel blocks of the same color, those blocks would get rounded on the edges but will still be visible as rounded blocks.</p>
<p>But it works ideal on sources like aliased output from a render engine, or images that have been upscaled x2 with the nearest neighbour method.<br />
<br/><br />
<strong>Conclusion:</strong></p>
<p>Aliasing should be fought before it ends up within an image as there are more sophisticated methods to keep it from emerging than to reconstruct it after the damage is done.</p>
<p>But sometimes it´s inevitable and if you are looking for a simple but effective way to get rid of that ugly blocks within an image or video &#8211; SmartAA will do the trick.<br />
<br/><br />
<strong>Download:</strong></p>
<p><a href="http://www.smart-page.net/as3/sp_smartaa/SmartAA.zip">Grab the Shader here</a> and use it with Photoshop (<a href="http://www.adobe.com/devnet/pixelbender/" target="_blank">Pixel Bender Plugin</a> needed), After Effects or Flash!<br />
<br/><br />
<strong>Hint:</strong></p>
<p>Try to add a sharpen filter or better an unsharpen mask to the result to counter the blur effect.<br />
Don´t forget to use the width/hight properties &#8211; SmartAA will work without but there will be artifacts on the upper- and lower right corner.</p>
<p><br/><br />
I hope this is helpful to anyone out there and would love to hear some comments or ideas.</p>
<p><br/><br />
Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/02/21/smartaa-reconstruct-anti-aliasing-with-pixel-bender/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>The Steve Jobs IPad Adobe Flashplayer HTML5 Video rant</title>
		<link>http://www.smart-page.net/blog/2010/02/06/the-steve-jobs-ipad-adobe-flashplayer-html5-video-rant/</link>
		<comments>http://www.smart-page.net/blog/2010/02/06/the-steve-jobs-ipad-adobe-flashplayer-html5-video-rant/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 12:30:06 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[audio visualization]]></category>
		<category><![CDATA[Five3D]]></category>
		<category><![CDATA[Flashplayer]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[IPad]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[Steve Jobs]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=775</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2010/02/06/the-steve-jobs-ipad-adobe-flashplayer-html5-video-rant/" title="The Steve Jobs IPad Adobe Flashplayer HTML5 Video rant"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/sp_ball1.bivt75iqsqyeg48ww0wowowsc.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The Steve Jobs IPad Adobe Flashplayer HTML5 Video rant" style="float:left;padding:0 10px 10px 0;" ></a>The flame wars are on! CEOs, CTOs, platform evangelists and users are fighting the war of the worlds out there. It´s HTML5 vs. Flash, open vs. closed, H264 vs. OGG, desktop vs. mobile, truth vs. lie. Lets first calm down with this nice audio visualization before we dive in&#8230; Since Steve´s presentation of the iPad [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2010/02/06/the-steve-jobs-ipad-adobe-flashplayer-html5-video-rant/" title="The Steve Jobs IPad Adobe Flashplayer HTML5 Video rant"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/sp_ball1.bivt75iqsqyeg48ww0wowowsc.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="The Steve Jobs IPad Adobe Flashplayer HTML5 Video rant" style="float:left;padding:0 10px 10px 0;" ></a><p>The flame wars are on!</p>
<p>CEOs, CTOs, platform evangelists and users are fighting the war of the worlds out there.<br />
It´s HTML5 vs. Flash, open vs. closed, H264 vs. OGG, desktop vs. mobile, truth vs. lie.</p>
<p><b>Lets first calm down <a href="http://www.smart-page.de/as3d/sp_ball/" target="_blank">with this nice audio visualization</a> before we dive in&#8230;</b><br />
<br/><br />
<span id="more-775"></span><br />
Since Steve´s presentation of the iPad and recent statements from him and Apple it´s clear that they are not going to support flash on their mobile devices.</p>
<p>This has triggered an ongoing debate on Flash, HTML5, browser plugins and web technology in general.</p>
<p>Unfortunately the whole discussion is rather uncivilized as there are a lot of people involved who make their living from those technologies and standards &#8211; and even more who use them on a daily basis.</p>
<p>So much has been written on this topic during the last two weeks&#8230; much was impulsive, exaggerated or plain wrong misinformation while few statements showed greater insight or were just watered down by irony and harsh language.<br />
<br/><br />
<img src="http://www.smart-page.net/blog/wp-content/uploads/2010/02/battle.jpg" alt="" title="battle" width="692" height="150" class="alignnone size-full wp-image-780" /><br />
<br/><br />
So I am not going to take part in this discussion with a detailed view on the technology involved or why one standard is superior to another etc.. sorry, but there will be no rant <img src='http://www.smart-page.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Why? </p>
<p>Because this has already been done beautifully by others and because &#8211; it doesn´t matter.</p>
<p>What really matters is to get things done! To create content and to deliver it to the widest possible range of audience. </p>
<p>As a developer I don´t have the luxury of choosing my tools based on personal favor. I have to work with what’s best suited to achive the desired result &#8211; be it HTML, Flash or Silverlight or whatever may come along.</p>
<p>As a user however I have that luxury &#8211; I vote with every click and my wallet for and against technology that I consider to be worth my time or money.</p>
<p>So there is no point for these two groups of people to lash out against each other or certain technologies.<br />
Of course this doesn´t apply to CEOs, CTOs or platform evangelists &#8211; it´s their job to influence the aforesaid groups on their opinion.</p>
<p>So what will all this mean for the web? Almost nothing.</p>
<p>The web has always been based on open standards while innovation was often driven by the &#8220;big boys&#8221; like IBM, MS, Apple and many others.<br />
Finally this innovation gets adapted to open standards &#8211; as well as the economy assimilates ideas from the open source world.</p>
<p>And all this is healthy!<br />
<img src="http://www.smart-page.net/blog/wp-content/uploads/2010/02/evolution1.jpg" alt="" title="New ClicKclic Character" width="692" height="150" class="alignnone size-full wp-image-795" /></p>
<p>Sure &#8211; like in nature, it sometimes seems cruel and unforgiving, but whatever survives in the end may stay&#8230; just to be replaced by its successor if it doesn´t evolve.</p>
<p>And in the end everybody in this constantly changing ecosystem wins:</p>
<p>Companies get to sell their products and to rant about their competitors, developers get jobs instead of finally being replaced by generators, and users get more and more for their money.</p>
<p>So I am glad we live in a world with more than one operating system, programming language, browser, or pair of socks to choose from. </p>
<p>It´s the freedom &#8220;to choose&#8221; that makes the web/live so exciting. </p>
<p><br/><br />
Cheers!<br />
<br/><br/><br />
PS: About the audio visualization experiment in the opener:</p>
<p>I wanted to do something with Five3D for a long time now and well &#8211; here it is.<br />
You can load your own mp3´s via the right click menu.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2010/02/06/the-steve-jobs-ipad-adobe-flashplayer-html5-video-rant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sing like HAL with the Flash Player 10.1</title>
		<link>http://www.smart-page.net/blog/2009/12/30/sing-like-hal-with-the-flash-player-101/</link>
		<comments>http://www.smart-page.net/blog/2009/12/30/sing-like-hal-with-the-flash-player-101/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 22:49:29 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Flash Player 10.1]]></category>
		<category><![CDATA[Microphone]]></category>
		<category><![CDATA[Pitch]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=670</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2009/12/30/sing-like-hal-with-the-flash-player-101/" title="Sing like HAL with the Flash Player 10.1"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/10_11.dbpgxcadusn6skwc80csg08ks.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Sing like HAL with the Flash Player 10.1" style="float:left;padding:0 10px 10px 0;" ></a>Of course everybody remembers the scene from 2001 when Dave Bowman removes HAL´s memory banks. While being shut down HAL sings the song &#8216;daisy&#8217; and his voice continuously pitches down while his &#8216;mind fades&#8217;. With this little test app you can sing like HAL! &#8230;provided you installed the Flash Player 10.1 beta and have a [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2009/12/30/sing-like-hal-with-the-flash-player-101/" title="Sing like HAL with the Flash Player 10.1"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/10_11.dbpgxcadusn6skwc80csg08ks.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Sing like HAL with the Flash Player 10.1" style="float:left;padding:0 10px 10px 0;" ></a><p>Of course everybody remembers the scene from <a href="http://de.wikipedia.org/wiki/2001_%E2%80%93_Odyssee_im_Weltraum" target="_blank">2001</a> when Dave Bowman removes HAL´s memory banks.</p>
<p>While being shut down HAL sings the song &#8216;daisy&#8217; and his voice continuously pitches down while his &#8216;mind fades&#8217;.<br />
<strong><br />
<a href="http://www.smart-page.net/as3/sp_mictest/" target="_blank">With this little test app you can sing like HAL!</strong></a></p>
<p><span id="more-670"></span><br />
&#8230;provided you installed the <a href="http://labs.adobe.com/technologies/flashplayer10/" target="_blank">Flash Player 10.1 <del datetime="2010-11-23T01:39:09+00:00">beta</del></a> and have a microphone handy.</p>
<p>Yes 10.1 &#8211; as the new year is coming, so is the next subversion step of the flash player, bringing among other features video playback and p2p/streaming enhancements.<br />
The beta2 has been released at the 17th December and brought also the long-awaited <a href="http://labs.adobe.com/downloads/flashplayer10.html" target="_blank">debug version</a>. </p>
<p>But aside from the global error handling, the new feature I was looking forward to the most is the access to binary data coming from the microphone.</p>
<p>This will allow to develop a bunch of pretty interesting applications that make use of voice input &#8211; like voice recognition for example.</p>
<p>This little demo records data from the mic and plays it with an adjustable speed offset, pitching the sound. </p>
<p><embed type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" width="320" height="140" src="http://www.smart-page.net/as3/sp_mictest/flash10_1_mic_test.swf" /><br />
<br/><br />
You can <a href="http://www.smart-page.net/as3/sp_mictest/srcview" target="_blank">download the source here.</a></p>
<p><del datetime="2010-11-23T01:39:09+00:00">Note: to be able to compile the project you need to download the updated &#8220;<a href="http://labs.adobe.com/downloads/flashplayer10.html#pgswc" target="_blank">playerglobal.swc</a>&#8220;.<br />
</del></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2009/12/30/sing-like-hal-with-the-flash-player-101/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>SmartReLight &#8211; relighting with Pixel Bender</title>
		<link>http://www.smart-page.net/blog/2009/12/27/smartrelight-relighting-with-pixel-bender/</link>
		<comments>http://www.smart-page.net/blog/2009/12/27/smartrelight-relighting-with-pixel-bender/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 15:57:15 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Normals]]></category>
		<category><![CDATA[PixelBender]]></category>
		<category><![CDATA[Relighting]]></category>
		<category><![CDATA[SmartReLight]]></category>
		<category><![CDATA[Video post]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=642</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2009/12/27/smartrelight-relighting-with-pixel-bender/" title="SmartReLight &#8211; relighting with Pixel Bender"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/smartrelight.3itd6eb870qvdwc88ocswkwc0.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="SmartReLight &#8211; relighting with Pixel Bender" style="float:left;padding:0 10px 10px 0;" ></a>Relighting is an interesting method that is often used in video post production pipelines. Given the vector of its surface normal, it is possible to calculate the brightness of each pixel by a pseudo 3D lightning system. Checkout the demo of SmartReLight! As the &#8216;object space&#8217; &#8211; or &#8216;material&#8217; normal’s have to be known, relighting [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2009/12/27/smartrelight-relighting-with-pixel-bender/" title="SmartReLight &#8211; relighting with Pixel Bender"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/smartrelight.3itd6eb870qvdwc88ocswkwc0.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="SmartReLight &#8211; relighting with Pixel Bender" style="float:left;padding:0 10px 10px 0;" ></a><p>Relighting is an interesting method that is often used in video post production pipelines.</p>
<p>Given the vector of its surface normal, it is possible to calculate the brightness of each pixel by a pseudo 3D lightning system.</p>
<p><a href="http://www.smart-page.net/as3/sp_smartrelight" target="_blank"><strong>Checkout the demo of SmartReLight!</strong></a><br />
<br/><br />
<span id="more-642"></span><br />
As the &#8216;object space&#8217; &#8211; or &#8216;material&#8217; normal’s have to be known, relighting is mostly used within the post process of CG generated images or videos.</p>
<p>It’s a convenient way to archive great lighting and gives the artist most control as he can tune it in real-time without having to re- render the footage for every adjustment.</p>
<p>As you can see from this example, the complete lighting is done by the shader using only a color pass and the object normal’s:</p>
<p><img class="alignnone size-full wp-image-648" title="smartrelight2" src="http://www.smart-page.net/blog/wp-content/uploads/2007/05/smartrelight2.jpg" alt="smartrelight2" width="680" height="170" /><br />
<br/><br />
This implementation is fairly simple as it doesn´t support reflections and refractions like <a href="http://www.minning.de/software/normality" target="_blank">Normality</a> , but its fast and does the job &#8211; and what better way to get through the last cold days of the year than playing half an hour with Pixel Bender?</p>
<p>It’s also possible to relight already lighted sources to some extend, by not using the color- , but an already phong- shaded pass:</p>
<p><embed type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" width="680" height="350" src="http://www.smart-page.net/as3/sp_smartrelight/SmartReLight_Shadertest.swf" /><br />
<br/><br />
You can <a href="http://www.smart-page.net/as3/sp_smartrelight/SmartReLight.zip">download SmartReLight here</a> and the <a href="http://www.smart-page.net/as3/sp_smartrelight/srcview" target="_blank">source of the demo</a> including the shader <a href="http://www.smart-page.net/as3/sp_smartrelight/srcview" target="_blank">here</a>.<br />
<br/><br/></p>
<h3>Compiling PB shaders at runtime</h3>
<p>Last but not least a short but very interesting story:</p>
<p>Recently I was asked if it was possible to compile a PB shader at runtime.</p>
<p>Given it some thought &#8211; why not?</p>
<p>And as it turned out the hell of a chap Nicolas Canasse already <a href="http://ncannasse.fr/projects/pbj?version=232" target="_blank">took care of that matter</a>.<br />
There is also already an <a href="http://www.jamesward.com/2009/04/29/announcing-pbjas-an-actionscript-3-pixel-bender-shader-library/" target="_blank">AS3 port</a> by James Ward.<br />
<br/><br/></p>
<h3>All the best for 2010 !</h3>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2009/12/27/smartrelight-relighting-with-pixel-bender/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Flash AIML TTS Chatbot &#8211; &#8216;HAL9000&#8242; using PHP and Festival</title>
		<link>http://www.smart-page.net/blog/2009/10/16/flash-aiml-tts-chatbot-hal9000-using-php-and-festival/</link>
		<comments>http://www.smart-page.net/blog/2009/10/16/flash-aiml-tts-chatbot-hal9000-using-php-and-festival/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 21:42:09 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[AIML]]></category>
		<category><![CDATA[Chatbot]]></category>
		<category><![CDATA[Festival]]></category>
		<category><![CDATA[HAL9000]]></category>
		<category><![CDATA[LAME]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Program E]]></category>
		<category><![CDATA[TTS]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=562</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2009/10/16/flash-aiml-tts-chatbot-hal9000-using-php-and-festival/" title="Flash AIML TTS Chatbot &#8211; &#8216;HAL9000&#8242; using PHP and Festival"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/hal1dg3lkl0telko408cg4gc4ck84ekdjdxruf9s8k40s08o080wksth.bg9mdfdn8mis080ww0c0kg8sw.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Flash AIML TTS Chatbot &#8211; &#8216;HAL9000&#8242; using PHP and Festival" style="float:left;padding:0 10px 10px 0;" ></a>Ever dreamed of having a chat with you own personal AI? Well, we are still a bit behind Arthur C. Clarke´s dream of a self-aware AI like the HAL9000 but with AIML, Festival and Flash you can build your own talking chatbot in no time. Have a chat with HAL first. The Brain room: So [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2009/10/16/flash-aiml-tts-chatbot-hal9000-using-php-and-festival/" title="Flash AIML TTS Chatbot &#8211; &#8216;HAL9000&#8242; using PHP and Festival"><img src="http://www.smart-page.net/blog/wp-content/uploads/yapb_cache/hal1dg3lkl0telko408cg4gc4ck84ekdjdxruf9s8k40s08o080wksth.bg9mdfdn8mis080ww0c0kg8sw.h9fw4mcunmtegc04wgoo4wck.th.jpeg" width="200" height="150" alt="Flash AIML TTS Chatbot &#8211; &#8216;HAL9000&#8242; using PHP and Festival" style="float:left;padding:0 10px 10px 0;" ></a><p>Ever dreamed of having a chat with you own personal AI?</p>
<p>Well, we are still a bit behind Arthur C. Clarke´s dream of a self-aware AI like the <a href="http://en.wikipedia.org/wiki/HAL_9000" target="_blank">HAL9000</a> but with AIML, Festival and Flash you can build your own talking chatbot in no time.</p>
<p><strong><a href="http://www.smart-page.de/as3/sp_hal9000/" target="_blank">Have a chat with HAL first.</a></strong><br/><br/></p>
<p><span id="more-562"></span><br />
<img class="alignnone size-full wp-image-572" title="brainroom" src="http://www.smart-page.net/blog/wp-content/uploads/2009/10/brainroom.jpg" alt="brainroom" width="680" height="100" /></p>
<p><strong>The Brain room:</strong></p>
<p>So we are going to build ourselves the poor man’s version of a &#8220;Heuristically programmed ALgorithmic Computer&#8221; and of course we start with its brain.</p>
<p>The <a href="http://sourceforge.net/projects/programe/" target="_blank">Program E &#8211; AIML Manager</a> will function as the brain room and during the setup we install a set of data crystals (aka an AIML set).<br />
Program E runs on PHP and parses and stores the actual &#8220;brain&#8221; within a mysql database.</p>
<p>So create a new database, install Program E to <em>&#8220;mydir/programe&#8221;</em> and upload the <em>&#8220;talk2me.php&#8221;</em> from the project package at the end of this article into <em>&#8220;programe/src&#8221;</em>. </p>
<p>Then upload and parse an AIML brain file into the db &#8211; call the new bot &#8220;HAL&#8221;.<br />
<br/><br />
<img class="alignnone size-full wp-image-571" title="module1" src="http://www.smart-page.net/blog/wp-content/uploads/2009/10/module1.jpg" alt="module1" width="680" height="100" /></p>
<p><strong>The speech module:</strong></p>
<p>We will use the Festival Text To Speech package to make HAL talk.<br />
This needs a Unix based system and the installation is quite simple &#8211; refer to <a href="http://www.xenocafe.com/tutorials/php/festival_text_to_speech/index.php#text2wave" target="_blank">this tutorial</a> if you encounter problems.</p>
<p>Festival comes with a &#8220;text2wave&#8221; script and a suitable default language.</p>
<p>We will also need the LAME mp3 encoder in order to convert those created wav files to a transferable mp3 because speed is critical.</p>
<p>Within the package you will find some PHP files including a <em>&#8220;config.php&#8221;</em>.<br />
Upload and chmod them and modify the config to fit your servers directory structure.<br />
<br/><br />
<img class="alignnone size-full wp-image-569" title="hal3" src="http://www.smart-page.net/blog/wp-content/uploads/2009/10/hal3.jpg" alt="hal3" width="680" height="100" /></p>
<p><strong>The eye:</strong></p>
<p>Now we setup an interface to Program E and our TTS system &#8211; HAL´s famous &#8220;eye&#8221;.</p>
<p>Open the <em>&#8220;src/hal9000.fla&#8221;</em> and the <em>&#8220;src/Main.as&#8221;</em> and change the variable <em>&#8220;path&#8221;</em> in line 31.</p>
<p>Upload the recompiled <em>&#8220;index.swf&#8221;</em> along with the HTML and JS file and have a first small talk with your chatbot.<br />
<br/><br />
<a href="http://www.smart-page.de/as3/sp_hal9000/hal9000.zip">Download the project here !</a><br />
<br/><br/><br />
Note: <em>This is the poor &#8211; AND the lazy man´s way to build a talking chatbot.<br />
This could be implemented in many more elegant ways &#8211; it´s even possible to have a bidirectional voice communication with HAL by using an rmtp server and a speach recognition sdk. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2009/10/16/flash-aiml-tts-chatbot-hal9000-using-php-and-festival/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Realtime SSAO with After Effects and Pixel Bender</title>
		<link>http://www.smart-page.net/blog/2009/10/05/realtime-ssao-with-after-effects-and-pixel-bender/</link>
		<comments>http://www.smart-page.net/blog/2009/10/05/realtime-ssao-with-after-effects-and-pixel-bender/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 07:00:58 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[After Effects]]></category>
		<category><![CDATA[AFX]]></category>
		<category><![CDATA[AO]]></category>
		<category><![CDATA[Pixel Bender]]></category>
		<category><![CDATA[Screen Space Ambient Occlusion]]></category>
		<category><![CDATA[Smart SSAO]]></category>
		<category><![CDATA[SSAO]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=471</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2009/10/05/realtime-ssao-with-after-effects-and-pixel-bender/" title="Realtime SSAO with After Effects and Pixel Bender"><img src="http://www.smart-page.net/blog/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=471&amp;w=200&amp;h=150&amp;zc=1" width="200" height="150" alt="Realtime SSAO with After Effects and Pixel Bender" style="float:left;padding:0 10px 10px 0;" ></a>Screen Space Ambient Occlusion or SSAO is a method to compute an approximated AO pass in real-time! This is done by using the depth information of a 3D object or scene that has been stored from the Z-(depth) buffer of the renderer. Go ahead and try the interactive demo or see a video example! The [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2009/10/05/realtime-ssao-with-after-effects-and-pixel-bender/" title="Realtime SSAO with After Effects and Pixel Bender"><img src="http://www.smart-page.net/blog/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=471&amp;w=200&amp;h=150&amp;zc=1" width="200" height="150" alt="Realtime SSAO with After Effects and Pixel Bender" style="float:left;padding:0 10px 10px 0;" ></a><p>Screen Space Ambient Occlusion or <a href="http://en.wikipedia.org/wiki/Screen_Space_Ambient_Occlusion" target="_blank">SSAO</a> is a method to compute an approximated <a href="http://en.wikipedia.org/wiki/Ambient_occlusion" target="_blank">AO</a> pass in real-time! </p>
<p>This is done by using the depth information of a 3D object or scene that has been stored from the Z-(depth) buffer of the renderer.</p>
<p><b>Go ahead and try the <a href="http://www.smart-page.net/as3/sp_smartssao">interactive demo</a> or see a <a href="http://www.vconverter.de/?file=smartssao" target="_blank">video example!</a></b><br />
<br/><br />
<span id="more-471"></span></p>
<p>The technique was introduced 2007 at Siggraph by <a href="http://www.crytek.com/" target="_blank">Crytek Studios</a> and is becoming an often used feature within next generation live-3d engines or cg/video post applications.</p>
<p>After playing with the ray traced inside-out AO and having to realize that it´s not quite doable with Pixel Blender, I turned to SSAO and quickly got some nice results.</p>
<p>In short it´s all about importance sampling. </p>
<p>SmartSSAO looks up the depth information of 12 surrounding samples and checks if they get occluded to average the AO value.<br />
<img style="margin-top:10px; margin-bottom:5px;" src="http://www.smart-page.net/blog/wp-content/uploads/2009/10/sp_ssao3.jpg" alt="sp_ssao3" title="sp_ssao3" width="680" height="142" class="alignnone size-full wp-image-680" /></p>
<p>The disadvantages lie in the nature of SSAO being &#8220;screen spaced&#8221; which means that it can´t take objects from the off into account, and the result has to be blurred to reduce the inevitable noise.<br />
Also there is no ray bouncing, so classic AO is visually superior &#8211; but hey&#8230; who can argue with &#8220;real-time&#8221;?</p>
<p><strong><a href="http://www.vconverter.de/?file=smartssao2" target="_blank">View another video</a></strong> of the buffer and the solo SSAO pass without/with blurring.<br />
<span style="color: #ff6600;"><em>Please note that those strange looking anomalies on the buddahs arms originate from the badly ranged zmap I produced in a hurry.</em></span><br />
<br/><br />
<strong>To sum it all up:</strong></p>
<p>SSAO makes it possible to have AO in places where it normally isn´t possible &#8211; e.g. real-time engines (yes &#8211; even for Flash/Papervision), or within a video post process.</p>
<p>All that’s needed is the Zbuffer of a 3D rendering.<br />
<br/></p>
<p><strong>You can download the Shader <a href="http://www.smart-page.net/as3/sp_smartssao/SmartSSAO.zip" target="_blank">here </a>or get it packed with an <a href="http://www.smart-page.net/as3/sp_smartssao/SmartSSAO_example.zip" target="_blank">AFX example</a>.<br />
</strong><br/><br />
<i>Hint: As said before, the SSAO pass needs to be blurred in order to clear out the emerging noise &#8211; but don´t overdo it, as the blurring will &#8220;bleed&#8221; the result over to unwanted areas.<br />
This could be targeted by a special SSAO blur filter that would again have to take the depth map into account. </i><br />
<br/><br />
<em><a href="http://www.vconverter.de/?file=smartssao2" target="_blank">Click here to see this screenshot as video</a></em><br/><br />
<strong><img class="alignnone size-full wp-image-504" title="sp_ssao2" src="http://www.smart-page.net/blog/wp-content/uploads/2009/10/sp_ssao2.jpg" alt="sp_ssao2" width="700" height="401" /><br />
</strong></p>
<p><strong><span style="color: #ff6600;"><em><br />
Update:</em></span></strong></p>
<p>I feel like I should adress the X,Y-offset params of the filter which can be used to tweak the &#8220;shadow direction&#8221;.<br />
&#8220;Shadow direction&#8221; in quotes as (SS)AO is all about indirect lightning so this is a real &#8220;tweak&#8221; or an unrealistic param &#8211; which I thought might come in handy in some cases.</p>
<p>I was asked if the shader was performant enaugh for flash &#8211; and even if it looks a bit ugly codewise as I had to get rid of a loop &#8211; it surely is.</p>
<p>So I updated the package and made this small <a href="http://www.smart-page.net/as3/sp_smartssao" target="_blank"><strong>interactive flex demo</strong></a> :</p>
<p><embed style="margin-left:50px;" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" width="570" height="500" src="http://www.smart-page.net/as3/sp_smartssao/SmartSSAO_Shadertest.swf" /><br />
Be sure to try unchecking &#8220;color SSAO?&#8221; and &#8220;show SSAO?&#8221; to get an impression.</p>
<p>You can grab the source <strong><a href="http://www.smart-page.net/as3/sp_smartssao/srcview/index.html" target="_blank">here</a></strong>.</p>
<p><strong><span style="color: #ff6600;"><em><br />
Update 2:</em></span></strong></p>
<p>The filter now features an additional sampling radius parameter which controls the dispersion and allows to adjust it to the desired level of detail &#8211; this should also make it more useable for papervision.</p>
<p>I hope this little experiment will be of use to somebody out there and would love to hear any suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2009/10/05/realtime-ssao-with-after-effects-and-pixel-bender/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>GPU based Raytracing with Pixel Bender and After Effects</title>
		<link>http://www.smart-page.net/blog/2009/09/27/gpu-based-raytracing-with-pixel-bender-and-after-effects/</link>
		<comments>http://www.smart-page.net/blog/2009/09/27/gpu-based-raytracing-with-pixel-bender-and-after-effects/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 10:29:44 +0000</pubDate>
		<dc:creator>flashgordon</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[After Effects]]></category>
		<category><![CDATA[Ambient Occlusion]]></category>
		<category><![CDATA[AO]]></category>
		<category><![CDATA[GPU]]></category>
		<category><![CDATA[Pixel Bender]]></category>
		<category><![CDATA[Raytracing]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://www.smart-page.net/blog/?p=426</guid>
		<description><![CDATA[<a href="http://www.smart-page.net/blog/2009/09/27/gpu-based-raytracing-with-pixel-bender-and-after-effects/" title="GPU based Raytracing with Pixel Bender and After Effects"><img src="http://www.smart-page.net/blog/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=426&amp;w=200&amp;h=150&amp;zc=1" width="200" height="150" alt="GPU based Raytracing with Pixel Bender and After Effects" style="float:left;padding:0 10px 10px 0;" ></a>Since some years the idea of harnessing the power of modern graphic cards for 2D/3D applications has become more and more popular. Today we find GPU support in many CG applications like Photoshop or After Effects. But first the fun part: Watch a video raytraced with PB and AFX! The chaos group is even working [...]]]></description>
			<content:encoded><![CDATA[<a href="http://www.smart-page.net/blog/2009/09/27/gpu-based-raytracing-with-pixel-bender-and-after-effects/" title="GPU based Raytracing with Pixel Bender and After Effects"><img src="http://www.smart-page.net/blog/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=426&amp;w=200&amp;h=150&amp;zc=1" width="200" height="150" alt="GPU based Raytracing with Pixel Bender and After Effects" style="float:left;padding:0 10px 10px 0;" ></a><p>Since some years the idea of harnessing the power of modern graphic cards for 2D/3D applications has become more and more popular.</p>
<p>Today we find GPU support in many CG applications like Photoshop or After Effects.</p>
<p><b>But first the fun part: <a href="http://www.vconverter.de/?file=rt_aa_ao" target="_blank">Watch a video raytraced with PB and AFX!</a></b></p>
<p><span id="more-426"></span> The <a href="http://www.chaosgroup.com" target="_blank">chaos group</a> is even working on a GPU based real time version of Vray &#8211; a widely used modern GI raytracer.</p>
<p>In fact GPU shading is often more performant plus it quasi &#8216;adds&#8217; an unused/inactive processor.</p>
<p>One could argue that Pixel Bender doesn´t quite fit the term as its mostly run in software mode (on the CPU) &#8211; for<br />
example when executing a PB shader in Flash or rendering it with AFX&#8230; for now.</p>
<p>But PB is still young and the prospect of being able to run it within multiple adobe platforms (Flash,PS,AFX) is very compelling.</p>
<p>When I saw <a href="http://www.subblue.com/blog/2009/9/20/quaternion_julia" target="_blank">Tom Beddard´s PB port</a> of Keenan Crane&#8217;s genius julia set tracer, I remembered that I had planned to get into PB GPU raytracing once I got around <a href="http://mike.newgrounds.com/news/post/156863" target="_blank">Mike Welsh´s PB raytracer</a>.</p>
<p>So I spend some time with it, created a scene similar to &#8216;<a href="http://www.smart-page.de/as3d/sp_theeye/" target="_blank">The Eye&#8217;</a> and added viewport controls as well as anti aliasing.</p>
<p>The result can be viewed <a href="http://www.vconverter.de/?file=rt_aa_ao" target="_blank">here</a>.</p>
<p><em>Rendertime was 3:10 on a Q6600 for 4700 frames.</em></p>
<p>And <a href="http://www.smart-page.net/as3/sp_smartray/SmartRayTracer.pbk" target="_blank">here</a> is the modified shader.</p>
<p>I also fiddled around with adding an inside-out AO (<a href="http://en.wikipedia.org/wiki/Ambient_occlusion" target="_blank">ambient occlusion</a>) pass but wasn´t able to get satisfying results.<br />
It even almost fried my GPU in the process so in conclusion it’s doable but sadly not practical.</p>
<p><img class="alignnone size-full wp-image-443" title="ao2" src="http://www.smart-page.net/blog/wp-content/uploads/2009/09/ao2.jpg" alt="ao2" width="426" height="210" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smart-page.net/blog/2009/09/27/gpu-based-raytracing-with-pixel-bender-and-after-effects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

