3d design with openscad
Post on 06-Aug-2015
193 Views
Preview:
TRANSCRIPT
3D Design with OpenSCAD
Vicky Sommavicky@tgaw.com@TGAWhttp://tgaw.wordpress.comhttp://www.Shapeways.com/shops/tgaw
This presentation is on SlideShare at: http://www.slideshare.net/VickyTGAW/3d-design-with-openscad
OpenSCAD – Download• Free 3D Modeling Software• Available for Windows, Linux, and MacOS• Good at “clean” models (taking some of
worry out of the process– you can be oblivious to “non-manifold” and “bad face normals”)
• Because it’s instruction-base, it’s easy to visualize measurements and come back and tweak it
http://www.openscad.org/downloads.html
OpenSCAD – User ManualDon’t Be Intimidated! You Don’t Have to Memorize the Syntax!
Online User Manualhttps://en.wikibooks.org/wiki/OpenSCAD_User_Manual
Quick Cheat Sheethttp://www.openscad.org/cheatsheet/
OpenSCAD – Anatomy of User Interface
Text Editor – Where we put our instructions (“code”)
Viewing Area – Your handiwork! Renders of the model.
Console – Technical information about what’s going on (progress on rendering, any error messages)
OpenSCAD – Text Editor Commands
Icons to create new files, save, undo, redo, indent, preview, render, and most importantly for 3D Printing-- export to STL format.
OpenSCAD – Text Editor to Viewing Area
To see how your work looks, you can:• Use Preview ( ) or Render ( ) icons• Use the Design->Preview or Design->Render menu options• Or the fastest option - use F5 for Preview and F6 for Render
OpenSCAD – Viewing Area Commands
Commands for Viewing, Rendering, Zooming In, Changing Views, Turning On or Off Axis and Measurements Display, Showing Edges Versus Faces
OpenSCAD – The Mouse & the Viewing Area
• Left clicking and dragging allows you to rotate your view• Right clicking and dragging pans the view• Scroll wheel allows you to zoom in and out
OpenSCAD – Syntax Common Themes• ; - The end of an instruction (ie make a cube;)
• // - A comment or label– for your purposes– will be ignored by the viewing area
• { } - Grouping of commands
• [x,y,z] – “Vectors” (Coordinates, 3D sizes)
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/General
OpenSCAD – Primitive Objects – Cube
cube([10,10,10]); cube([10,20,30]);cube([x, y, z]);
Draws 3D boxesNot necessarily perfect cubes – you can make rectangles with it as well.
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#cube
OpenSCAD – Primitive Objects – Cylinder
cylinder(r=10,h=22);
cylinder(r1=10,r2=3,h=22);cylinder(r=x,h=z);cylinder(r1=x,r2=y,h=z);
Draws cylinders – and not necessarily perfect cylinders
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#cylinder
OpenSCAD – Primitive Objects – Cylinder
cylinder(r1=9, r2=0, h=9, $fn=4);
$fn parameter controls # of fragmentsIncrease– you can make really smooth objectsDecrease it– you can make Triangles, Pentagons, Pyramids, etc.
cylinder(r=9,$fn=3);cylinder(r=9,h=10,$fn=300);
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#cylinder
OpenSCAD – Primitive Objects – Sphere
sphere(d=22); sphere(d=22, $fn=100);sphere(d=x);Draws spheres – and you can control resolution
$fn parameter controls how smooth it looks
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#sphere
OpenSCAD – Primitive Objects
You can build a lot out of standard shapes
OpenSCAD – Primitive ObjectsYou can build a lot out of these standard shapes- “Bipedal Mech” by Mathew Ridgehttp://shpws.me/GQX5
OpenSCAD – 2D Objects - Text
text("TGAW");
Text(“x”);Draws text. Text is great for customizing your models, engraving, and embossing.
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Text
OpenSCAD – 2D Objects - TextText(“x”, Font=“Font Name”);Since OpenSCAD is installed on your machine, you can use any font already on your machine!
text("TGAW", font="Rockwell Extra Bold");
text("TGAW", font="Old English Text MT");
text("TGAW", font="Wingdings");
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Text
OpenSCAD – 2D Objects - Polygons
polygon([[-24,0],[0,0],[0,32] ,[-16,32],[-15,28],[-13,24] ,[-12,20],[-12,15],[-13,10]
,[-15,6],[-19,3]]);
Polygon([x1,y1],[x2,y2],etc);You specify the points to make customized shapes (which you can then extrude to 3D if needed)
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_Primitives#polygon
OpenSCAD – 2D Objects - Polygons
Need visual help making Polygons?
http://daid.eu/~daid/3d
A graphical interface that builds your polygon code for you.
OpenSCAD – 2D to 3D
linear_extrude(height = 10)polygon([[-24,0],[0,0],[0,32],[-16,32] ,[-15,28],[-13,24],[-12,20],[-12,15] ,[-13,10],[-15,6],[-19,3]]);
Linear_Extrude(height=x)Makes your 2D object (circle, square, polygon) 3DIt can even twist the object as it grows up
NO SEMICOLON AFTER IT (It’s not the end of the statement– we have to tell it what to extrude)
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion#Linear_Extrude
OpenSCAD – 2D to 3D
linear_extrude(height = 20, center = false , $fn = 100, twist=30)text("TGAW");
Linear_Extrude(height=x, twist=degrees)Works on text and you can do fancy stuff like twisting
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion#Linear_Extrude
OpenSCAD – 2D to 3D
rotate_extrude(convexity = 10, $fn=300)polygon([[-24,0],[0,0],[0,32],[-16,32],[-15,28] ,[13,24],[-12,20],[-12,15],[-13,10] ,[-15,6],[-19,3]]);
Rotate_Extrude()Your 2D object (circle, square, polygon) is rotated around to make a 3D object (like a cross section)
NO SEMICOLON AFTER ITIt’s not the end of the statement-- we need to tell it what to extrude.
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion#Rotate_Extrude
OpenSCAD – Import STL
import("C:\\Downloads\\VT.stl",convexity=10);
import(filepath, convexity=10);The import function lets you bring in existing 3D models into your project.
Note: In Your filepath, backslashes need to be doubled.C:\Downloads\MyStl.stl -> C:\\Downloads\\MyStl.stl
Tip: If you are using other people’s models, be sure to check and respect their licensing
(http://www.thingiverse.com/thing:818805 by GlynnLo)
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Importing_Geometry
OpenSCAD Basics – Transformations - Translate
cube([22,22,5]);
sphere(d=22, $fn=100);
cube([22,22,5]);
translate([11,11,0])sphere(d=22, $fn=100);
translate([x,y,z])Translate MOVES objects– lets you define the how far to move along each of the axes.
NO SEMICOLON AFTER IT (It’s not the end of the statement– we have to tell it what to translate)
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#translate
OpenSCAD – Transformations – Rotate
rotate([x,y,z])Rotate angles the object.
Guide to the axis is in your preview panel
NO SEMICOLON AFTER IT (It’s not the end of the statement– we have to tell it what to rotate)
It’s Okay if you Need Some Trial and Error : )
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate
OpenSCAD - Transformations – Rotate
rotate([0,-45,0])cube([22,22,5]);
rotate([0,0,30])cube([22,22,5]);
rotate([x,y,z])
rotate([30,-45,30])cube([22,22,5]);
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate
OpenSCAD - Transformations – Resizeresize([x,y,z],auto=true|false)Resize allows you to make your object different sizes where x, y, and z are your new dimensions
NO SEMICOLON AFTER IT (It’s not the end of the statement– we have to tell it what to resize)
If auto=false, anything left zero stays the same.
If auto=true, anything left zero is sized proportionally. resize([200,0,10], auto=true)import("VT.stl", convexity=10);
resize([200,0,10], auto=false)import("VT.stl", convexity=10);
import("VT.stl", convexity=10);
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#resize
OpenSCAD – CSG ModelingCSG stands for Constructive Solid Geometry. You don’t need to remember that
Do Remember:• Powerful!• Combines your primitive parts/objects. • Adding, Subtracting, Intersections
Credit: https://en.wikipedia.org/wiki/Constructive_solid_geometry#/media/File:Csg_tree.png
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling
OpenSCAD – CSG Modeling - UnionAdds objects into a one
union () { object1; object2;}
union(){ cube([5,10,5]); translate([5,10,2.5]) { rotate([0,-90,0]) cylinder(d=5, h=5, $fn=30); } translate([5,0,2.5]) { rotate([0,-90,0]) cylinder(d=5, h=5, $fn=30); }}
Two cylinders and a cube
After union – single rounded object
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#union
OpenSCAD – CSG Modeling - DifferenceSubtracts objects from each otherdifference () { object1; object2;}
difference(){ cube([5,10,5]); translate([5.5,10,2.5]) { rotate([0,-90,0]) cylinder(d=5, h=6, $fn=30); } translate([5.5,-1,2.5]) { rotate([0,-90,0]) cylinder(d=5, h=6, $fn=30); }}
Two cylinders and a cube
After “subtracting” the cylinders from the cube
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#difference
OpenSCAD – CSG Modeling - DifferencePractical Use of Difference – Engraving Text!difference(){ cube([5,10,5]); translate([5.5,10,2.5]) { rotate([0,-90,0]) cylinder(d=5, h=6, $fn=30); } translate([5.5,-1,2.5]) { rotate([0,-90,0]) cylinder(d=5, h=6, $fn=30); }
translate([2,6.5,0.5]) rotate([90,0,-90]) linear_extrude(height=2) text("V", font="Old English Text MT", size=4);}
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#difference
OpenSCAD – CSG Modeling - IntersectionTakes where both objects overlap (like a Venn Diagram)intersection () { object1; object2;}
intersection(){ cylinder(r=5,h=3); translate([4,0,0]) cylinder(r=5, h=3);}
Two cylinders
Intersection – an Almond Shape
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#intersection
OpenSCAD – CSG Modeling - IntersectionPractical Use of Intersection – Curving Details!
intersection(){ sphere(r=9.25, $fn=100); resize([0,0,11],auto=false) resize([12,0,0], auto=true) import("VT.stl", convexity=10);}
A sphere and a VT Logo Intersection – A curved VT Logo
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling#intersection
OpenSCAD – CSG Modeling - CombinationsPractical Use of Intersection – Curving Details!
union(){ sphere(r=9, $fn=100); intersection() { sphere(r=9.25, $fn=100); resize([0,0,11],auto=false) resize([12,0,0], auto=true) import("VT.stl", convexity=10); }}
Add a slightly smaller sphere and we have a curved, embossed VT logo on a sphere.
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling
OpenSCAD – Advanced - ModulesTo help readability and reusability, you can make modules.module name(){ //your code }
module base_sphere(){ sphere(r=9, $fn=100); }
module curved_VT(){ intersection() { sphere(r=9.25, $fn=100); resize([0,0,11],auto=false) resize([12,0,0], auto=true) import("VT.stl", convexity=10); } }
union(){ base_sphere(); curved_VT(); }
union(){ sphere(r=9, $fn=100); intersection() { sphere(r=9.25, $fn=100); resize([0,0,11],auto=false) resize([12,0,0], auto=true) import("VT.stl", convexity=10); }}
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Modules
Fun Fact – All objects in a model are already merged into one, no unions necessary
OpenSCAD – Advanced - LoopsLoops are powerful for repeated tasksfor ( i = [start : increment : end] ) { //your code } for (i=[0:5:15]){ translate([i,0,0]) cylinder(r=1, h=15, $fn=36); }
Translation– We are going to start at 0. Every 5 mm, draw a cylinder until we reach 15mm.
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#For_Loop
OpenSCAD – Advanced - Loops“Nested Loops”for ( i = [start : increment : end], j = [start : increment : end] ) { //your code } for (i=[0:5:15],j=[0:5:20]){ translate([i,j,0]) cylinder(r=1, h=15, $fn=36); }
Translation– We going to end up with 20 pegs in 4 columns and 5 rows.
Reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#For_Loop
OpenSCAD – TroubleshootingHaving Unexpected Results?
• Check Your Syntax(maybe there’s a semi colon after a translate)• Check the Console for error messages (which would include a
line number)
OpenSCAD – Troubleshooting• echo allows you to send details to the Console
• // allows you to comment out instructions so you can narrow down the culprit
echo("i:", i, " j:", j);
OpenSCAD – Troubleshooting• # allows you to have objects highlighted
difference(){ cube([5,10,5]); translate([5.5,10,2.5]) { rotate([0,-90,0]) cylinder(d=5, h=6, $fn=30); } translate([5.5,-1,2.5]) { #rotate([0,-90,0]) cylinder(d=5, h=6, $fn=30); }}
OpenSCAD – Saving and Exporting• Be sure to Save your code often
• When you’re ready to print, you’ll want to Export to STL file.• Pre-requisite– Do your official render (F6).• The system will remind you. : )
OpenSCAD – Code Scavenging!
OpenSCAD even comes with its OWN examples which you can open, review, and tweak to meet your needs.
OpenSCAD – Code Scavenging!
Thingiverse has a OpenSCAD area full of shared source code– just search “OpenSCAD”
http://www.thingiverse.com/search?q=OpenSCAD
You can download the final .STL file AND the original .SCAD files, so you can read and find out how it was made.
OpenSCAD – Code Scavenging!
• OpenSCAD Community Forumshttp://www.openscad.org/community.html
• OpenSCAD reddithttp://www.reddit.com/r/OpenSCAD/
• Good ole Google
OpenSCAD – OpenJSCAD
http://openjscad.org• Web-based• Has its own JavaScript, object-oriented
language• BUT 95% of the OpenSCAD Language is
supported
Quick Tips• User Guide at
https://github.com/Spiritdude/OpenJSCAD.org/wiki/User-Guide• //!OpenSCAD at the top tells it you’re using OpenSCAD• Shift-Enter in the “Text Editor” renders• Holding down the Left or Right Mouse Button lets you rotate the
View Pane • Holding down Shift Left Mouse Button lets you pan in the View Pane
THANK YOU!!!
https://twitter.com/tgaw
http://tgaw.wordpress.com
http://www.shapeways.com/shops/tgaw
http://www.instructables.com/member/VickyTGAW
http://instagram.com/VickyTGAW
Vicky Sommavicky@tgaw.com
top related