Explore Modeling with the Constructive Solid Geometry Library

Alec Shedelbower, Wolfram Research
Keren Garcia, Wolfram Research

(RowDefault[, (Spacer1), , (Spacer1), ])  #WolframTechConf

Overview

Types of Modeling

Constructive Solid Geometry (CSG)

Geometric Models Paclet

Demo

Questions

Types of Modeling

Modeling

There are many ways to model a 3D object.

The best method depends on what we plan to use the model for:

({{, , }, {"Rendering", "Simulation/Computation", "3D Printing/Manufacturing"}})

The use cases will determine what we model and how we represent it.

Surface Modeling

Only model the object’s surface.

Used when we only need to render an object, since this just requires surface data.

({{, , }, {"Animation", "Video Games", "Visualizations"}})

Surface Modeling – Drawbacks

Missing a clearly defined interior, which is typically required for computations or manufacturing.

In some cases we may be able to process the surface into a solid representation, but there are no guarantees.

Solid Modeling

Model the interior (volume) of the object. The surface can be implied.

(RowDefault[, (SwatchLegend["Volume", "Surface"])])

Useful for simulations and manufacturing, since the object’s interior is well-defined. We can still render it easily as well.

However, there are different ways to actually represent the solid model.

Solid Modeling  – Representations

There are three common ways to represent a solid 3D model:

({{, , }, {"Boundary Representation (B-Rep)", "Solid Mesh", "Constructive Solid Geometry"}, {"106 Polygons", "238 Tetrahedrons", "2 Primitives"}})

B-Rep – Closed surface, typically a polygon mesh.
Solid Mesh – Mesh consisting of volumetric cells, such as tetrahedrons.
CSG – Model defined by applying Boolean operations to primitive regions.

Explicit Modeling

Both B-Reps and Solid Meshes are examples of explicit modeling.

Explicit Modeling – Models are defined by their geometry alone (ex. vertices, edges, faces), which are directly edited by the user.

({{, }, {"Boundary Representation (B-Rep)", "Solid Mesh"}, {"106 Polygons", "238 Tetrahedrons"}})

Explicit Modeling – Drawbacks

Explicit modeling is common, but it comes with many drawbacks:

Complex visual editors are often a necessity.

Difficult to make changes to an existing model.

Discretization accuracy is often “baked” into the model, and cannot be easily adjusted.

Tend to require more memory, especially for solid models.

What we would like is instead is parametric modeling.

Parametric Modeling

In contrast, parametric modeling maintains the original/true representation of the model, with the ability to adjust its parameters after the fact.

Easy to modify/iterate on existing models.

Convert to other format with whatever accuracy is required for the task.

Can still be rendered relatively quickly.

Recap

We want a modeling system that is:

Solid-First – Model is guaranteed to have volume.

Parametric – Easy to modify (no worrying about vertices/edges).

Fast to Render – Quickly see changes as they occur.

Code-First – No complicated editor required.

Intuitive – Closer to sculpting or machining.

Which is why we have chosen...

Constructive
Solid Geometry
(CSG)

Constructive Solid Geometry

CSG is a technique for creating 3D models by combining primitive regions through Boolean operations (Union, Intersection, Difference).

Forms a tree structure, where leaf nodes are primitives and internal nodes are Boolean operations.

CSGRegion represents a CSG object in the Wolfram Language.

CSGRegion

Specify a region by giving an operation and a list of primitive regions:

CSGRegion["Intersection",{Cube[1.5],Ball[]}]

CSGRegions can be nested to form complex models:

//CSGRegionTree

More neat examples:

CSGRegion["Difference",{Style[Icosahedron[1],],CSGRegion[{Style[Icosahedron[0.8],],Style[Cube[{0,0,5},9.5],]}]}]

pts=Flatten[Table[{x,y,z},{x,{-1,1}},{y,{-1,1}},{z,{-1,1}}],2];
chunks=CSGRegion["Intersection",{Ball[{0,0,0},2],Cube[#,2]}]&/@pts;
colors={,,,,,,,};
CSGRegion[Table[Style[Translate[chunks[[i]],#*pts[[i]]],colors[[i]]],{i,8}],ImageSize->Tiny]&/@{0,1/2,1}

CSGRegion – Progress

We are continuing to improve CSGRegion. For example, version 14.2 will bring full annotation support to CSGRegion.

CSGRegion["Intersection",{
Annotation[Cube[1.5],"Material"->"Metal"],Annotation[Ball[],"CSGRegionStyle"->]
},ImageSize->Tiny]

Annotate[{%,{1}},"CSGRegionStyle"->]

AnnotationValue[{%,{1}},"Material"]

Full list of annotation symbols:

Annotation • Annotate • AnnotationValue • AnnotationKeys • AnnotationDelete

CSGRegion – Beyond Primitives

Even though CSGRegions are easier to model than meshes, it can still be difficult to make complex models from basic primitives.

What we want is to have a library of easily accessible CSG parts that could then be assembled into more complex models.

This is the goal of the new Geometric Models Paclet.

Geometric Models
Paclet

Geometric Models Paclet

Provide a library of parameterized parts to facilitate the creation of complex models, with a focus on mechanical and industrial design.

Paclet will be available from the Paclet Repository.

Part Libraries

Goal is to convert existing part libraries to the Wolfram Language (i.e. CSGRegion).

Current focus has been on libraries made for OpenSCAD, including:

({{, }, {"BOLTS", "NopSCADlib"}})

Part Libraries – BOLTS

Free open-source library of parts for CAD applications. Includes parts such as screws, washers, and bearings.

Many models are sourced from official standards bodies (ex. ISO).

Part Libraries – NopSCADlib

Library of parts for 3D printers, electronics, and more.

({{, , , , }})

Demo

GeometricModel – Disclaimer

Note that this paclet is still in active development, and everything I show here is subject to change.

Particularly, the typesetting and naming are not finalized.

The current design is loosely based on SystemModel, so some syntax may seem familiar.

GeometricModel – Referencing Models

Models are referenced by a qualified name:

GeometricModel["NopSCADlib.Vitamins.Blower"]

Base names can be used if unique:

GeometricModel["Blower"]

Names can be searched for using the asterisk notation:

GeometricModel["BOLTS.Washers.*"]//Column

GeometricModel – Properties

model=GeometricModel["MetricPlainWasherWithChamfer"]

Models have a list of properties you can access using bracket notation:

(* List all available properties *)
model["Properties"]

(* Show a short summary of the model *)
model["Summary"]

(* Show the Graphics3D for the model *)
model["Graphics"]

(* Give the geometric region of the model *)
model["Region"]

Note that this region is a CSGRegion:

%//CSGRegionTree

GeometricModel – Parameters

model=GeometricModel["LED"]

Show parameter information for the model:

model["Parameters"]

Set the value of a parameter:

GeometricModel["LED",<|"color"->Green|>]

Parameters respect units:

GeometricModel["LED",<|"bodyHeight"->#|>]&/@{(Quantity[2, "mm", millimeters, "Millimeters"]),(Quantity[2, "cm", centimeters, "Centimeters"])}

Some models include parameter presets:

model["ParameterPresets"]

Use a specific preset by name:

GeometricModel["LED","LED8mm"]

Show all the presets:

GraphicsRow[Show[GeometricModel[model,#]["Graphics"],]&/@Keys[model["ParameterPresets"]],ImageSize->Medium]

GeometricModel – Composition

One key aspect we’re still working on is the ability to combine models to form new composite models.

Here’s a rough idea of the kind of workflow we want to improve:

{sr,nr,wr}=GeometricModel[#]["Region"]&/@{"MetricHexSocketHeadCapScrew","MetricHexagonThinNut","MetricPlainWasher"}

screw=CSGRegion[{
Style[sr,],
Style[Translate[wr,{0,0,5}],],Translate[Style[nr,],{0,0,12.4-5}]
}]

screws=CSGRegion[];
base=Cuboid[{-40,-40,0},{40,40,5}];
CSGRegion[{Style[base,],screws}]

Geometric Models – Remaining Work

Mechanism for model composition

Support for more part libraries

General refinement and polish

Conclusion

Questions

Please write any questions in the Q&A tab.

ReconstructionMesh

GradientFittedMesh

ConvexHullMesh

Thank You