Instructables

Programmatic Creation of a 3D Model for 3D Printing

Featured
Picture of Programmatic Creation of a 3D Model for 3D Printing
1john1_12.jpg
vrml_viewer2.jpg
pic 002b.jpg
pic005.jpg
 
One of my favorite hobbies is making rolling ball sculptures.  I usually make RBSs out of copper but being a geek I thought it would be cool to make a virtual sculpture and 3D print it on Shapeways. 

I started first by trying to model an RBS with Blender.  I quickly realized that doing anything in Blender takes quite a time commitment and has a steep learning curve.  I tried evaluating some other 3D modeling programs but every package seemed too difficult to use to build an RBS for my apparently little brain.

I realized quickly that whenever I made a virtual 3D model, I would need to be able to easily build it and modify it.  Well, modifying a rolling ball sculpture has consequences such that any change made higher up will affect a portion of the track lower down.  Being a computer programmer kind of guy, I thought it would be interesting to try to make a virtual model programmactically which would give me the freedom of making something which could be very accurate and forgiving as far as modifying the model.

 
Remove these adsRemove these ads by Signing Up

Step 1: Use VRML to Create a simple 3D Virtual Model

Picture of Use VRML to Create a simple 3D Virtual Model
To start I decided to use VRML (Virtual Reality Modeling Language).  VRML comes in a few flavors.  There's VRML 1.0, 2.0 and then came X3D.  X3D is sort of XML based and the latest and probably last version of VRML.  I had already played with VRML 2.0 before so I went with that because I was too lazy to learn X3D.  Looking at it, though, it's very similar to VRML so it really is that I'm just that I'm too lazy really to try to learn it.

VRML allows you to describe a 3D scene by using primitives like cubes, spheres, extrusions, meshes, etc.  There's options for placing an object or a group of objects in xyz space as well as the ability to scale and rotate them.  VRML is fairly easy to learn and use.  Since it has been around a while, there's plenty of example code on the web so google to your heart's content.

To create a VRML file, you simple create a file using notepad or your favorite text editor and create it with a ".wrl" extension.

On the first line you put:

#VRML V2.0 utf8

Then you put your code for your shape or shapes.  For an RBS I basically use Extrusions for everything.  Here's an example of a RBS Rail:

Transform {
  translation 0 0 0
  children Shape {
    appearance Appearance {
      material Material {
  diffuseColor 0.757827 0.771796 0.771797
  ambientIntensity 0.5
  specularColor 0.708205 0.708205 0.708205
  emissiveColor 0.000000 0.000000 0.000000
  shininess 1
  transparency 0.000000
      } # end material
    } # end appearance
    geometry Extrusion {
      beginCap TRUE
      endCap TRUE
      creaseAngle 0
      solid TRUE
      crossSection [
      0.00150000 0.00000000,
      0.00121353 0.00088168,
      0.00046353 0.00142658,
      -0.00046352 0.00142658,
      -0.00121353 0.00088168,
      -0.00150000 0.00000000,
      -0.00121353 -0.00088168,
      -0.00046353 -0.00142658,
      0.00046352 -0.00142659,
      0.00121352 -0.00088168,
      0.00150000 0.00000000
      ] # end cross section
      spine [
0 0 0,
0 0 -0.01,
0 -0.01 -0.02,
0 -0.02 -0.02
      ] # end spine
    } # end extrusion
  } # end shape
}

You can end with this code but it's not really necessary usually:

NavigationInfo{
  type "EXAMINE"
} # end NavigationInfo


So what does it all mean?

The first line identifies a VRML file.
The "geometry Extrusion" section defines the extrusion with endcaps, a circular crosssection of xy points, which gets extruded across 4 xyz points.
The "Shape" section defines attributes about the shape which surrounds the geometry Extrusion section.
The "Transform" section defines either where to move the object xyz or scale or rotate the object.  Several Transforms can surround other transforms.  So, for example the inside transform can be for rotation, there could be another that surrounds that transform that could be for scale, and another transform which surrounds both of the others which could be for xyz translation.
The "NavigationInfo" section is for some VRML viewers to know what to do.  You can go into examine mode, or go into flythrough mode, there may be other modes you could do, I don't know them all.


instony1 year ago
Great intro, thank you! I've been trying out some of the techniques and there's one thing I haven't been able to work out how to do. How do you get the vrml to subtract a shape from an existing one in order to cut a hole, like the gills in your raspberry pi case for instance?
swirlingbrain (author)  instony1 year ago
vrml can't do boolean operations. So no add, no subtract, no xor. I did the grill the hard way by making a bunch of sticks using a -for- loop. You could make most of the box, then take it into blender to do the boolean subtract. For example, make the box and make some characters, then take it into blender select the two objects and do the boolean subtract. I hope that helps.
Lindie1 year ago
Wow! Nice!
sethcim1 year ago
These are awesome! Could totally open a new dimension for RBSes. I would appreciate a little more depth on the algorithms so we can follow the instructions. In particular, I'm curious how you worked out the banking angle and smoothly joined sections with different bank.

Thanks for posting!
swirlingbrain (author)  sethcim1 year ago
I figure the parser that does a lot of the work would be a whole new topic for another instructable. Anyway, for the banking, if you can imagine, I have an invisible center rail on which I rotate the other two rails. So when I want to turn left, the right rail goes up and in a little and the left rail goes down and in a little according to a z rotation. The track is sort of built in short steps. So the parser sort of figures about 3 steps before the next turn and 3 steps into the next turn to incrementally start banking. After a curve the parser un-banks for about 3 steps before the end of the curve and 3 steps after the curve until it's back to normal no bank for straight track or banked to the next curve for curves.To figure the bank, at first I just guessed and manually set the bank based on the diameter of the curve and that worked. Later, I figured a formula to do the same thing. I figured that this incremental banking was not smoothing so a wrote a function that would smooth the entire track sort of in an Fast Fourier Transform (FFT) sort of and averaging over several steps fashion. I hope that helps.
Yes, that makes sense. Thanks for your quick reply.
Jayefuu1 year ago
Great first Instructable! That Pi case needs its own Instructable too! :D
ChrysN1 year ago
Those look amazing, nicely done!
Awesome!
Wow, this is really good.
rachel1 year ago
Sweet! This is great stuff.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!