sweet.js macro for three.js (webgl)

I know you’re not supposed to use macros when a simple function with a callback parameter will do, but I really wanted to try out sweet.js, the library that adds macro compilation to JavaScript.

I also started exploring three.js, a WebGL library.

The macro I wrote simplifies the render loop, you supply the scene and camera object and the body of the loop and you’re set. The macro sets up the renderer.

Again, not the most appropriate use of macros but it was a nice small way of getting used to macro definition syntax and to explore how much potential power there is.

There’s also a Grunt task plugin to run sweet.js which automates the whole macro compilation step. Just add file watching and reloading and the experience is pretty much the same as developing with CoffeeScript.

Hope this encourages other JS devs to check out what sweet.js can offer and maybe one day we’ll have a nice set of macros to simplify the common JS frameworks out there.

Cheers,
Rudolf
@go_august

Comments are Closed