Sei sulla pagina 1di 33

Introduction to OpenSCAD

Steve Graves

Teaching Goals

Concepts Not Nuts and Bolts

Ask questions. Classes are for active learning. There are


proal! "an! levels of e#perience in class. Don$t e sh!%
ever!one &as a nuie once.

If a question refers to so"ething co"ing up% it is a good


question. But I "ight defer it.

I plan on la!ing the foundation first% ut have several useful


concepts that go a little further than the asics. Going to tr! to
touch all of the".

I e#pect that after this class !ou &ill feel confident to create a
si"ple o'ect.

(se the )anual

I a" not going to regurgitate the "anual.

Concepts are "ore i"portant than details.

In the real &orld% open ooks are allo&ed.

(se help "enu to open "anual.

Don$t clutter "ind &ith para"eter details. It &ill


happen auto"aticall!.

Concepts

*hat is OpenSCAD+

*hat is the ,D printing process and ho& does OpenSCAD fit in


it+

*hat are asic concepts for all progra"s that create ,D o'ects+

*hat is OpenSCAD$s s!nta# and ho& is it unique+

*hat are so"e OpenSCAD user interface tips+

*hat are so"e design patterns+

(se Divide and Conquer.

Don$t reinvent the &heel.



*hat is OpenSCAD+

-rogra" to design ,D o'ects. It has eco"e the defacto


standard on thingiverse for para"etric designs.

Open source and free.

Other free progra"s are Blender% Sketch(p% .reeCad and


/eeksCad

OpenSCAD generates o'ects fro" progra"s0scripts+1 and


is "ostl! non2interactive.

A progra" "eans para"etric designs that are


"athe"aticall! precise.

OpenSCAD (ser Interface

3eft hand side is te#t edit &indo& for &riting code. Other
te#t editors can e used. 4e"acs is a good e#a"ple.

5ight hand side is &indo& for inspecting rendered ,D


o'ect.

O'ect in right hand &indo& can e "anipulated using


standard OpenG3 "ouse "oves.

3eft "ouse allo&s one to rotate o'ect.

5ight "ouse pans.

)iddle "ouse or &heel 6oo"s.



*hat is the ,D -rinting -rocess+

,D o'ect is designed 0OpenSCAD1

An ST3 file is e#ported.

A slicer progra" reaks ST3 file into la!ers and


generates G code.

G code is sent to printer.



General ,D O'ect Creation Concepts

7e! concept is 8Transfor"ed Shapes are Co"ined9 into


ne& "ore co"ple# shapes.

Co"ple# o'ects are created fro" si"ple 8Shapes9 called


pri"itives.

Si"ple and co"ple# shapes are "odified &ith


8Transfor"ations9 like translate% si6e% color.

-ri"itive shapes are 8Co"ined9 in various &a!s using


oolean logic and other "ore co"plicated functions.

Au#iliar! functions are used to do "ath% etc.



,D 0and :D1 -ri"itives

Cue

Sphere

C!linder

-ol!hedron

Square 0:D1

Circle 0:D1

-ol!gon 0:D1

)aking ,D fro" :D

:D pri"itives are turned into ,D ! e#trusion

T&o asic t!pes of e#trusion

linear;e#trude

rotate;e#trude

Co"ining Shapes

(nion 0All shapes added together1

Difference 0Shapes after <


st
shape are sutracted1

Intersection 0Intersection of all shapes1

)inko&ski 0.unction &ith interesting properties to


add t&o shapes1

/ull 0=nclose "ultiple shapes in "ini"u" shape1



Transfor"ing Shapes

Scale

5esi6e

5otate

Translate

)irror

)ult"atri#

Color

OpenSCAD ,D O'ect Creation
,D o'ects are created using the general pattern
Co"ine01>
optTransfor"01 optTransfor"01 ... Shape01?
optTransfor"01 optTransfor"01 ... Shape01?
...
@
*ork fro" end of line to&ard front of line.
*ork fro" inner"ost to outer"ost

S!nta#

.unctions 0"odules1 are overloaded.

Aariales have unusual scope.

Aariales do not store shapes. Shapes are i"plicit entities.

Arra!s BC are used a lot to represent points or vectors. Aer! often as


para"eters to functions. Be&areD 5e"e"er to use BC as &ell as 01. In
"ost cases there is no s!nta# error if !ou don$t.

3ines are ter"inated &ith se"icolon.

A 8line9 of code has a shape 'ust efore the se"icolon. That shape
can e 8transfor"ed9 ! functions efore it. These functions have no
se"icolons. The transfor"ations are applied in reverse order 0closest
first and &orking ack1.

)ore on s!nta#

*e can learn "ore aout the &orking s!nta# !


looking at the s!nta# for a "odule.

)odules i"plicitl! return shapes.

So a "odule "ust create a shape internall! or get


one 8passed9 to it.

Shapes are 8passed9 as children% not para"eters.


5e"e"er shapes are not stored in variales.

)odule S!nta#
)odule na"e0para"eter<% para"eter:% ...1>
Code that creates a shape internall!
andEor
Code that operates on children called child0F1%
child0<1 up to child0Gchildren 2 <1
@

Calling a "odule

Three general for"s. =ach relates to earlier pattern


of Co"ine% Transfor" and Shape

Calling a "odule as a Co"ine
Na"e0-ara<%...1>
Child0F1?
Child0<1?
H
@

Child is an! construct that "akes a shape

i.e. line of optTransfor"01 Shape01?


or the for" of Co"ine01> % call to another "odule% etc.

Calling a "odule as transfor"
Na"e0opt-ara<% opt-ara:% H1 Child?

Child is an! construct that "akes a shape.



Calling "odule as shape
Na"e0opt-ara<% opt-ara:% H1?

Note no children% ends &ith se"icolon

A shape is created internall! to "odule

)odules "aking shapes are a co""on for".

.or e#a"ple% a "odule to create a olt "ight e


olt0dia% len1?

(ser Interface Tips

(se 8Thro&n Together9 vie& and 8Co"pile9 for a quick


and dirt! look at design

Break large s!ste"s into files to est use aove technique.


(se .stl files to speed up rendering in co"ple# designs.

(se 8Co"pile and 5ender9 for "ore refined look 0and


longer &ait for processing1

There is a co""entEunco""ent function

Set Gfs high during develop"ent



(seful Design -atterns

Identif! all the para"eters for o'ect0s1 eing


created

Assign a variale to each para"eter efore creating


design

)ore Design -atterns
difference01>
union01>
union child0F1?
union child0<1?
@
difference child0<1? 0(nion is difference child0F11
difference child0:1?
H
@

)ore Design -atterns
"odule oneShape01>
...?
@
"odule shapeT&o01>
...?
@
union01>
transfor"ations01 shapeOne01?
transfor"ations01 shapeT&o01?
@

Divide and Conquer

Shapes are ovious

)oves and rotates can also e divided. Create parts


in local coordinate s!ste"s% then "ove the" into
position in gloal coordinate s!ste".

Don$t 5einvent the *heel

So"eod! has alread! &ritten a 8*heel9 "odule.

(se uiltin )CAD lirar!

Search thingiverse

Search the Internet



TipI (se Gfn for "ore shapes

The Gfn para"eter can e used &ith c!linder to


create shapes &ith sides.

)inko&ski 0OperationD1

Aer! useful ut hard to understand.

One shape is added to another shape at ever! point in the


shape. Order doesn$t "atter.

Si"ilar to "atri# addition.

The additions at the surface are the onl! ones that have an
effect.

I"agine one shape eing s"eared onto the other shape.

*arningI )inko&ski is incredil! slo& &ith spheres.



)inko&ski =#a"ple

)inko&ski Ani"ated

(se "odule for shape 8variales9
/*
* This creates a shell of given thickness
* around an arbitrary shape
*/
module shell(thickness){
difference(){
minkowski(){
child(0);
sphere(rthickness! center true);
"
child(0);
"
"
shell(#0){
cylinder(r$%);
"

Creating "anifold designs

)anifold effectivel! "eans &ater2tight.

3eaks happen at shared oundaries. Shared


oundaries also slo& do&n processing.

=#tend o'ects that sutract e!ond surface.

=ither use 8glue9 o'ects or e#tend surfaces into


other o'ects for unions.

Spheres can so"eti"es fail to e "anifold. (se


circle and rotate;e#trude instead.

)ore on "anifold designs

(se thro&n together and co"pile to see


questionale oundaries.

Potrebbero piacerti anche