Lua Enters the House – Part One

The first time I ever thought about 3D design (beyond UI design) was when I wanted to get a custom part made a few years back.  It was a simple part that I would use to connect drinking straws together to form some simple structures.  At that time, the process of creation to plastic molded part was completely foreign to me, cost thousands of dollars, and simply was not pursuable.

Flash forward to 2010, and I purchased a CupCake from MakerBot.  While the machine didn’t work too well, I was hooked on the 3D prototyping in your home, scene.  I was still left with the desire to design some stuff though.  I am not a graphics designer, and I’ve never really used any visual design tools.  Even though experts make those things look really easy to use, I guess I just have a mental block to get over, and some hours of practice.  I am well versed in programming though, and luckily for me there was the OpenScad program, which looked really easy to pick up because it was a text based programming environment, rather than being visual.

Using OpenScad has been great.  I’ve been able to crank out literally more than 100 designs, in less than a year, using this simple program.  Granted, my designs are fairly simply, and most of them not particularly useful, but still.  For a guy that never did design work before, and was impeded by the scare of the learning curve, OpenScad has been a great introduction to design tools for me.

After using OpenScad for about 9 months now, I think I am getting close to truly understanding its limitations.  I would characterize the limitations, to my current design skills, in a couple of ways.

The first limitation is fairly mechanical, and relatively simple to solve.  Basically, under the covers, OpenScad utilizes a ‘set of vertices’ to get stuff done.  It works best when that set of vertices is pre-configured.  This is great when the number of vertices is small, and can easily be typed in by hand.  When it’s a larger set, that’s generated from an algorithm, you’re pretty much out of luck.  You can not dynamically create an array from within the programming environment.

This particular limitation has forced me to code up routines in such a way that dynamic arrays are not required.  Things are more incremental.  This might not actually be a very bad thing, but it is a limitation.  If OpenScad had a way to allow the creation of an array, and append to it, my life in OpenScad would be a lot simpler, and I would be able to create even more fancy designs.

The other limitation is more subtle, and languagey in nature.  You do not have ‘true’ variables.  You can in fact assign a value to a subtree of a graph, but there is not a concept of a variable that has scope outside the subtree, which can be easily changed.  This is challenging if you want to do something in a loop where the variable state needs to be saved/incremented between iterations of the loop.  It is possible to use the ‘assign()’ mechanism.  It just makes for some very odd looking/feeling code.

The last blocker is the fact that ‘function’ is more like a macro.  You can create a function that returns a value, but it can not have any statements other than the return expression.  That means that I can not create a function that does any real amount of calculation, or iteration, and return a result.  You can get around this for some functions, by creating more functions, but ultimately, you’ll run out of room, and need a simple loop construct, and it won’t be there.

All these ‘limitations’ are simply the constraints of the system.  They don’t detract from OpenScad in the least.  They do point towards an alternative direction to take things though.  Now that I understand it more, I view OpenScad in a different light.  Instead of being my end all be all environment where I do all of my design work, I view it like this.  OpenScad is just an exchange format, and there so happens to be a convenient OpenScad viewer attached to it.

When I think of it in these terms, I’m a little more free to come up with a more evolved design chain.  Instead of trying to make OpenScad do everything I want, I will just use it for the things it is good at.  The best thing it brings to the table are the connection to CGAL to create .stl files that represent the CSG commands that are used within the programs.  That is, OpenScad gives you the ability to use CSG to construct models.  Then it conveniently turns those models into .stl files which can be printed.  That’s goodness.  Feeding this machinery is what I want to change.

In steps Lua…

<End of Part One>

Advertisements

3 Comments on “Lua Enters the House – Part One”

  1. Hi Will,

    I would really like you to give RapCAD a try, the current version has functions with bodies, and true variables and the upcoming version 0.4.0 has dynamic arrays.

    I know that you are thinking that openscad is a document or interchange format, which is fair enough. But I am wondering whether you will be able to try out some more complex designs in RapCAD.

    Regards

    Giles

    • Yes, of course. I have in fact downloaded and am playing with the latest RapCAD. I see that as an easy replacement for OpenScad. The functions with bodies is certainly a beneficial addition, and will obviate the need for using Lua for many situations.

      I see myself using both. There are still things I can do with a more robust language, like Lua. For instance, I can easily embed it in a microcontroller, and send programs directly to the machine, without having to go through .stl files. That will have some interesting implications.

      I look forward to the time when you hit ‘1.0’ on RapCad so I can start uploading designs in rapcad format rather than OpenScad.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s