05 CSG Procedural
05 CSG Procedural
05 CSG Procedural
and
Procedural Modeling
Stelian Coros
Somewhat unrelated
Schedule for presentations
February 3 5 10 12 17 19 24 26
March 3 5 10 12 17 19 24 26 30
April 2 7 9 14 16 21 23 28 30
Send me:
ASAP: 3 choices for dates + approximate topic (scheduling)
1-2 weeks before your presentation: list of papers you plan to talk about
Day before each presentation: 3 questions for one of the papers that will be discussed
Previous Lecture: Solid Modeling
www.volumegraphics.com
Previous Lecture: From Surfaces to Voxels
• Ray casting
– Trace a ray from each voxel center
– Count intersections
• Odd: inside
• Even: outside
· · · · · · · · ·
· · · · · · · · ·
· · · · · · · · ·
· · · · · · · · ·
· · · · · · · · ·
· · · · · · · · ·
· · · · · · · · ·
· · · · · · · · ·
Real-life meshes
Real-life meshes
Real-life meshes
Real-life meshes: output of human
creativity, for better or worse
Alec Jacobson 9
Robust Inside-Outside Segmentation
using Generalized Winding Numbers
1 ray
Winding number vs ray casting
3 rays
Winding number vs ray casting
7 rays
Winding number vs ray casting
15 rays
Winding number vs ray casting
31 rays
Winding number vs ray casting
63 rays
Winding number vs ray casting
127 rays
Winding number vs ray casting
511 rays
Winding number vs ray casting
2047 rays
Robust Inside-Outside Segmentation
using Generalized Winding Numbers
– Boundary representations
• Polygonal meshes
• Subdivision surfaces Lower Level
• Implicit surfaces
– Volumetric models
– Parametric models
Higher Level
– Procedural/generative models
Constructive Solid Geometry (CSG)
subtract
intersect union
union
Leaves: CSG Primitives
• Simple shapes
– Cuboids
– Cylinders
– Prisms subtract
– Pyramids
– Spheres
– Cones intersect union
• Extrusions
• Surfaces of union
revolution
• Swept surfaces
Internal Nodes
• Boolean Operations
– Union
– Intersection
– Difference subtract
• Rigid Transformations
– Scale
– Translation intersect union
– Rotation
– Shear
union
Root: The Final Object
Booleans for Solids
Given overlapping shapes A and B:
• Use voxels/octrees/ADFs
– We can convert from b-reps to voxels/DF and back
– Process objects voxel by voxel
– Issues?
How Can We Implement Boolean Operations?
• Interface
– 3 panels
• Script
• View
• Info
• Compile (F5)
– Design->Compile
• Show Axes (Ctrl+2)
OpenSCAD CheatSheet
2D Primitives
• Circle
– circle(5);
– circle(r=5);
• Square
– square(5);
– square([4,8]);
• Polygon
– Need to specify points and paths, in this format:
polygon([points],[paths]);
• e.g., polygon( [ [0,0],[5,0],[5,5],[0,5] ]
, [ [0,1,2,3] ]);
• path is an optional parameter, assume in order if
omitted
• Notes:
– Remember the “;”
– Thickness is 1mm
– Use “[“ and “]” to pass multiple values
2D to 3D Extrusion
• Linear extrusion
– Extrudes a 2D shape along the Z axis
linear_extrude(height = 10, center = true, convexity =
10, twist = -100) translate([2, 0, 0]) circle(r = 1);
• Rotational extrusion
– Revolves a 2D shape around the Z axis
rotate_extrude($fn=200)
polygon( points=[[0,0],[2,1],[1,2],[1,3],[3,4],[0,5]]);
3D Primitives
• Sphere
– sphere(5);
sphere(r=5);
• Cube
– cube(5);
– cube([4,8,16]);
• Cylinder
– cylinder(20,10,5);
cylinder(h = 20, r1
= 10, r2 = 5);
– cylinder(h=20,r=10);
Transformations
• Translate
– e.g., translate([10,0,0])
sphere(5); // translate
along x axis
• Rotate
• Scale
• Order dependent
– Color(“yellow”)
translate([0,0,10])
rotate([45,0,0])
cylinder([20,10,0]);
– Color(“green”)
rotate([45,0,0])
translate([0,0,10])
cylinder([20,10,0]);
CSG
• Union
• Intersection
• Difference
• Example:
union()
{
translate([0,-25,-25]) cylinder(50,10,10);
rotate([90,0,0]) cylinder(50,8,8);
}
Module
• Procedures/Functions
module leaves() { cylinder(20,5,0); }
module box() { cube([5,10,15]); }
module tree() {
leaves();
scale([0.5,0.5,0.5]) translate([-2.5,-5,-
15]) box();
}
tree();
Module
• Parameters
module box(w,l,h,tx,ty,tz){
translate([tx,ty,tz])
cube([w,l,h]);
}
box(5,10,15,10,0,5);
• Default values
module box2(w=5,l=10,h=20){
echo("w=", w, " l=", l, " h=", h);
cube([w,l,h]);
}
box2();
Loops
• Assign() statement
– In openscad, one can only assign variables at
file top-level or module top-level
– If you need it inside the for loop, you need
to use assign(), e.g,:
Conditionals
• If/else/else if
– Syntax similar to C/C++
Useful Functions
• Goal:
– Describe 3D models algorithmically
• Best for models resulting from ...
– Repeating or similar structures
– Random processes
• Advantages:
– Automatic generation
– Concise representation
– Parameterized classes of models
Formal Grammars and Languages
• nonterminals : 0, 1
• terminals : [ , ]
• start : 0
• rules : (1 → 11), (0 → 1[0]0)
start: 0
1st recursion: 1[0]0
2nd recursion: 11[1[0]0]1[0]0
3rd recursion: 1111[11[1[0]0]1[0]0]11[1[0]0]1[0]0
L-system Example
• nonterminals : X, F
• terminals : + - [ ]
• start : X
• rules : (X → F-[[X]+X]+F[+FX]-X), (F → FF)
L-Systems Examples
• Tree examples
L-Systems Examples
Types of L-Systems
http://vimeo.com/68195050
Procedural Modeling of Buildings
• Pompeii
http://www.esri.com/software/cityengine/
Furniture Design
Input: Output:
3D Fabricatable
model Parts and
Connectors
Converting 3D Furniture Models to Fabricable Parts and Connectors, Lau et al., Siggraph 2011
Approach
3D Separate parts
model and
connectors
Formal
grammar
Production Rule 1
Production Rule 2
Examples of Production Rules
Production Rule 4
Production Rule 6
Production Rule 8
Sequence of Production Rules
All Production Rules
Formal Grammar for 2D Cabinets
Non-terminal
Symbols
- Collection of Parts
Terminal Symbols
- Separate Parts
Multiple valid
options