Blog

Archive
| All posts |
  • A major new node created for Plane9!

    published on 10/11/2009 3:00 PM

    While working on a new feature for v1.2 i accidentally managed to take a wonderful detour.

    It all started with a effect I noticed in a music video. It looked nice so I wanted to try to recreate it in realtime however that couldn't be done with the current system.

    What I needed was to be able to manipulate each cloned object individually. So I though I would create a new node for this effect but that seemed limited. All I needed was bit of math and access to the created objects.

    After some digging i found the Nullsoft Expression Parser. Used by the famous AVS winamp plugin and free for anyone to use. Its fast and supports many functions. But after about 5 hours later I had to give up. The project was built using an old version of visual studio and compiling in under anything else makes it crash hard. Turning off all optimization and debug injection helped but it still crashed.

    My guess is that it crashes because they assume the compiler has placed the code as they have written it in C. This is so they can grab the compiled code and memcpy it into their VM.

    Because of this I had to throw all that work out the window. But during my searching I found another lib created by Brian Allen Vanderburg II. I had dismissed it since I though AVS expression parser would be more resistant to bad user input. Now however I was forced to look into it again and I'm very happy that I did. A few hours later the node was complete and a framework added to easily add an expression port to any node I though needed it.

    So this means that Plane9 now has the major feature of AVS in it. That is anyone that creates a scene can now create math expressions for different nodes. This is best shown by an example. Take the problem I was trying to solve from the start. All I now have to write into the 'Expression' port of the new node looks as follows

    t = sin(10+x / 8 * time)+
    sin(10+y / 8 * time)+
    cos((10+x + y) / 8* time) +
    sin(length(15-x, 15-y) / 16 );
    scale.x = scale.y = scale.z = t*0.5; 
    col.r = 0.74;
    col.g = 1;
    col.b = 1;
    

    and the result of that little expression in the scene looks like this

    ![http://www.plane9.com/forumimages/2009-10-11-blobby.jpg)

    Now you might be wondering if any features was lost compared to AVS. Well actually not. I have even more then AVS has. Some of the functions that can be used abs, mod, ipart, fpart, min, max, sqrt, sinc, cos, tan, sinh, cosh, tanh, asin, acos, atan, log, ln, exp, logn, ceil, floor, deg, rad, rect2pol, pol2rect, if, select, equal, above, below, clip, clamp, length, beat, waveform, spectrum

    Adding new functions into the parse is very, very easy so expect this list to grow.