WooScript

Now it’s time for something completely different. I came across a program called StructureSynth thanks to one of our HTML contractors at work. It allows you to define basic geometry patterns using a simple proprietary language. These geometric objects can then be raytraced using the fast pathtracer that’s part of the product.

It’s a hell of a lot cooler than anything I’m going to get round to building. BUT, I fancied the challenge anyway, so I started writing my own geometric scripting language called WooScript.

The basic language borrows quite a bit from the StructureSynth geometric language, but I’ve tweaked it because I felt like it.

The basics of all objects are defined using rules, and a rule definition looks like this.

rule r1 {
}

You can define as many rules as you want, and there are also some basic intrinsic rules built into the system like “box” which unexpectedly creates… a box.

I’ve only got three operations in the language, call, repeat and adjust. call() is the basic method of firing off a rule, and here is the simplest rule you can write in WooScript.

rule main {
call(box)
}

Which gives the following pretty image.

A box

Simple WooScript

I’ll admit that you probably aren’t blown away by this image, but I was pretty happy when it appeared. Next up is the ability to adjust basic aspects of the scene. Similarly to StructureSynth the system keeps a stack of position, rotation, colour, etc. and you adjust these parameters using the adjust() function. The following rule instantiates a box, adjusts the y position by 2, and instantiates another.

rule main {
call(box)
adjust(y, +2)
call(box)
}
two boxes

Two boxes with an adjust

There’s some fun to be had with the parameter “+2″. One of the things I wanted in StructureSynth was the ability to specify a random number within a range, and in WooScript you can do this by specifying “+1:2″. You can also specify a pair of numbers to use randomly by using “+1,2″. You also have different operators like “=”, “-“, “*”, “/”. If I wanted to specify a random position for the first box I can use adjust(y, =0:1). i.e.

rule main {
adjust(y, =0:1)
call(box)
adjust(y, +1:2)
call(box)
}
2 cubes, random offsets

WooScript generating two cubes with random offsets

To show how random this is I’ll introduce the idea of recursion. To make this code recursive we change it so that the main rule instantiates a child rule “r1″, which then calls itself. Recursion is limited to 10 deep in the current WooTracer for testing purposes!

rule main {
call(r1)
}

rule r1 {
adjust(y, =0:1)
call(box)
adjust(y, +1:2)
call(box)
adjust(x, +1)
call(r1)
}
lots of cubes

Recursive rule building cubes

Recursion is nice and dandy, but it’s a pain to always run up to the recursion limit, so I’ve also added a repeat function which calls a rule a fixed number of times. To convert this from recursive to using repeat you take out the recursion call like so.

rule main {
repeat(r1, 10)
}

rule r1 {
adjust(y, =0:1)
call(box)
adjust(y, +1:2)
call(box)
adjust(x, +1)
}

I’ve also added the ability to adjust the rotation of the objects around the 3 primary axis. By adding an adjustment to ry (rotation about the y axis) you can get a curvey version of the shape that I’ve been putting together so far.

rule main {
repeat(r1, 10)
}

rule r1 {
adjust(y, =0:1)
call(box)
adjust(y, +1:2)
call(box)
adjust(x, +1)
adjust(ry, -10)
}
Cubes in an arc

Arc of cube pillars

And I guess that’ll do it for today. Next on the list is adding some colour adjustments and working on how to carry rotations down the stack. I’m using euler angles at the minute and that’s turning out to be a huge pain in the arse.

Hope you enjoyed seeing progress so far, and here’s a pretty render to leave it with.

cubes

Circle of cubes using wooscript

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Spam Protection *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>