Author Topic: Oozby (Oozebane + Ruby) - an openscad precompiler language  (Read 12444 times)

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Oozby (Oozebane + Ruby) - an openscad precompiler language
« on: September 04, 2013, 07:20:56 pm »
It's not even strictly an electronics thing, but I think it's relevent to a few of you. 3D printers are super useful and increasingly affordable and reliable. I recently invested in a Makerbot Replicator 2 and I love it! Designing organic stuff in Sculptris is rad fun, and OpenSCAD is a really neat tool for making mechanical precise parts.


But the OpenSCAD language is horrible. It doesn't even have variables, and yet claims to be a programming language. Well, using functions in place of variables is a pain, and other annoying limitations like not being about to easily produce rounded rectangular prisms, weird inconsistent naming conventions, and more, have motivated me to make a cool thing:


Oozby is my experimental new language project. It's kind of in between coffeescript and markaby in how it works. You write a program, pretty similar to how you might in openscad, but with good clear syntax and all the power of ruby, and the oozby utility automatically parses, executes, and outputs the result of your program each time you save the file, making a .scad file for OpenSCAD, which automatically reloads the code and renders it as you program. It's really early days and it's full of bugs. Every time I use it I find a new bug. But It's also really exciting and just being able to make a cube with a border radius is incredible and wonderful. In the future I want to add verification features which will preemptively detect potential bugs and warn you about issues you might encounter - things which leave me scratching my head for hours in OpenSCAD. But already there are an incredible amount of features afforded, many just automatic for having used ruby! Here's a non-exhaustive list:

 *  For built in functions which take an `r` parameter like `sphere`, `circle`, `cylinder`, you can specify any of these instead:
 *  * `r`, `radius`
 *  * `r1`, `radius_1`, `radius1`
 *  * `r2`, `radius_2`, `radius2`
 *  * `d`, `dia`, `diameter`: _anything specified as diameter will be automatically halved, taking a lot of `/ 2.0` statements out of your code_
 *  * and of course `d1`, `dia1`, `dia_1`, `diameter1`, `diameter_1`, `d2`, `dia2`, `dia_2`, `diameter2`, `diameter_2`
 *  For cylinders you can specify a Range for the radius option instead of specifying r1 and r2 to make tapering shapes
 *  Built in functions which take 'h' like `cylinder` and `linear_extrude` can take `height` instead if you like
 *  Cubes and Squares have a `radius` option, which if `> 0.0` causes the corners to be rounded very cleanly.
 *  All the round things have a 'facets' option which translates to $fn
 *  No semicolons (of course!) - specify one function as the parent of the next by using a block or use the > operator (see examples)
 *  Lambda, classes, methods, oh my!
 *  Built in functions like translate, rotate, scale, which take a 2d or 3d vector [x,y,z] can instead have options passed like this:
 *  *  `translate(x: 5, y: 6)` - unspecified items default to 0
 *  *  `scale(y: 2)` - unspecified items default to 1 for scale. Smart!
 *  Specify defaults: You can create a context within a block where everything defaults to `center: true`! How many times have you had to write `center = true` again and again when constructing something with lots of symmetry in OpenSCAD?
 *  Establish a scope within a block with specific resolution settings
 *  Totally legit scope.
 *  Actual variables.
 *  All the kinds of looping, enumeration and hard core maths Ruby is capable of. It's just ruby code after all! Need a complex number? the core Complex class has you covered! Want a mathematical Matrix? The Matrix class included in the standard ruby library is here to help! Need to work with insanely big numbers? bigdecimal to the rescue!
 *  Everything in RubyGems: Parse an MP3 and print out a phonograph record! Digest an XML feed of geological data and extrude 3d shapes from it with nokogiri! Query sensor data from webcams, arduinos, microphones, buttons, joysticks, and generic usb devices! Directly read image formats with gems like ChunkyPNG and rmagick! Create automated production workflows, importing data from online store orders directly in to your printing pipeline!

So if that sounds like a rad thing, I'd love it if you help me come up with future ideas for where this should go, play with it, make cool stuff. I'm pretty excited.


Check it out over on github at https://github.com/bluebie/oozby

dougal

  • Sr. Member
  • ****
  • Posts: 289
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #1 on: September 05, 2013, 05:51:19 am »
I don't have a 3D printer, or even easy access to one, but I've been keeping an envious eye on that area.


Very cool, Bluebie!


Dust

  • Newbie
  • *
  • Posts: 1
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #2 on: September 05, 2013, 10:33:23 pm »
 ::)
Have you even looked at the manual for openscad?  of course it has variables

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #3 on: September 06, 2013, 01:27:57 am »
Have you even read the manual for openscad? What they call variables are constants. You can only set them once, you can only set them at the start of a program or the start of a module - not within any ifs or loops or anything else. It is just one of uncountable quirks of openscad that they call constants "variables" despite not being able to vary their value - along with their rectangular prisms being called cubes and their rectangles being called squares.

DeuxVis

  • Full Member
  • ***
  • Posts: 107
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #4 on: October 03, 2013, 04:35:56 am »
Awesome ! You just gave me a nice reason to start using ruby.

DeuxVis

  • Full Member
  • ***
  • Posts: 107
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #5 on: October 10, 2013, 12:59:32 pm »
I've started using it a bit and I really like it !

I'm quite slow about learning it, but my first request would be a way to propagate the comments from the oozby file into the scad file.


On a side note, I was adevrtising it in the reprap community andsomeone told me something "similar" was being worked on currently : https://github.com/Joaz/CrystalScad
I have no idea if this is actually the same idea, but hey, funny how "great minds come alike" - this one is using ruby too !

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #6 on: October 12, 2013, 08:48:54 pm »

I'll think about that comments thing some more. It seems like it'd be straight forward enough for comments which take up the entire line, but for comments which go at the end of a line I'm not quite so sure. Seems complex to implement and a potential source of lots of edge cases and bugs. It is something I have been thinking about before though. What's the usefulness of it to you? Just so you can find your place again when trying to understand the code oozby produces?

That CrystalScad is really interesting! I think I will add support for that reversed syntax where translate(x: 5) { cube(1) } can instead be cube(1).translate(x: 5). So cool! Reminds me a bit of constructing documents in jQuery.
« Last Edit: October 12, 2013, 08:52:46 pm by Bluebie »

DeuxVis

  • Full Member
  • ***
  • Posts: 107
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #7 on: October 14, 2013, 01:12:55 am »
Full line comments only sounds fine.

Yup the idea is to help navigate the lengthy generated scad code, mainly to "debug" the oozby code.
Another goal, in the context of distribution of the design sources, is to keep the ability for other people without oozby to work based on the scad code - disabling a part of the design, etc.

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #8 on: October 14, 2013, 05:19:47 pm »
To be honest, that's a pretty low priority. I've always been treating OpenSCAD as a bytecode in oozby, not a language. I think I'd rather focus my energy on making oozby easier to install - using RubyPackager, making gui apps

DeuxVis

  • Full Member
  • ***
  • Posts: 107
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #9 on: October 14, 2013, 11:59:45 pm »
Understand that. I'm just not yet used to think about openscad files as an intermediary format.

And yeah ease of install/use first, as it will make it a possible tool for more people.

Mark

  • Full Member
  • ***
  • Posts: 196
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #10 on: October 15, 2013, 11:49:50 am »
For what its worth Vic Oliver of ReRap fame in NZ is suggesting Repetier which is free and available for Win, Linux and Mac at
http://www.repetier.com/download/

He has just produced a 200 x 260 x 175mm tall OpenSource version in The Shed magazine and put the plans at thingiverse.

Mark

DeuxVis

  • Full Member
  • ***
  • Posts: 107
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #11 on: October 17, 2013, 01:28:13 am »
Mmm, just to clarify for people who don't know the 3d printing ecosystem, Repetier is software but not a design tool for parts to be printed like Bluebie's oozby is.

Repetier offer both a firmware for reprap electronics (running on the 3d printer itself) and a host software (running on your computer and talking to the printer).

For what its worth Vic Oliver of ReRap fame in NZ is suggesting Repetier which is free and available for Win, Linux and Mac at
http://www.repetier.com/download/

He has just produced a 200 x 260 x 175mm tall OpenSource version in The Shed magazine and put the plans at thingiverse.

Mark

Mark

  • Full Member
  • ***
  • Posts: 196
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #12 on: October 19, 2013, 03:13:15 am »
DeuxVis
Ooops .. thanks for the clarification and sorry about getting it wrong...


Mark

DeuxVis

  • Full Member
  • ***
  • Posts: 107
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #13 on: October 25, 2013, 05:25:52 am »
Hi Bluebie, got a new request that would replace the propagation of comments into scad code for my usage :

Could you please add the "echo" function to DefaultOpenSCADMethods in preprocessor.rb ?

Just verified it seems to work. Sample usage :

Code: [Select]
# Based on nophead's experimentations : http://hydraraptor.blogspot.fr/2011/02/polyholes.html
def polyhole( h, d )
  n = [ 2.0  * d, 3.0 ].max.round
  actual_dia = d / cos( 180 / n )
  echo( "Polyhole faces : " + n.to_s + " / dia in : " + d.to_s + " / dia out : " + actual_dia.to_s )
  cylinder( h: h, dia: actual_dia, facets: n )
end

Then

Code: [Select]
polyhole( 8, 3 )

gives openscad code (only showing echo there)

Code: [Select]
echo("Polyhole faces : 6 / dia in : 3 / dia out : 3.4641016151377544");

which spits out the message I wanted to see in the openscad console during render.

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Oozby (Oozebane + Ruby) - an openscad precompiler language
« Reply #14 on: October 25, 2013, 07:48:08 pm »
Done. Thanks for the tip, Deux!