47
From Code to Coffee Table with Blender and Sly Matt Meshulam ChiPy 2015-03-12

From Code to Coffee Table with Blender and Sly

Embed Size (px)

Citation preview

From Code to Coffee Table with Blender and Sly

Matt MeshulamChiPy 2015-03-12

About Me

By day - Developer Experience at

Member of Pumping Station: One

Side projects involving electronics, music, woodworking, Python, cooking, visual art

The Metropol Table

Conception

CNC enables novel construction methods that require unique, high precision parts.

Fabrication tools exist, but what about upstream design tools?

I want a new coffee table.

Fabrication Software

● Vectric VCarve - Convert vector images to G-code toolpaths

● ShopBot software - Calibrate axes and run G-code on the ShopBot

G-code (yuck!)

Metropol Parasol, Seville, Spain

Study 1: ShopBotsaurus RexPattern via http://www.instructables.com/id/Build-a-6-0-tall-Wooden-T-Rex-Model/

Study 2: Design composeable parts

Create a 3D model in Blender

Use 123D Make to convert model into fab-able parts

Blender model

123D Make

Autodesk 123D Make

:-)● Free● Designed for CNC

construction● Many cool built-in

features

:-(● Unstable● GUI only● Hard to extend

A better design tool?

● Artistic/exploratory workflow ● Precise and reproducible operations● Output in a useful format (2D vector

shapes)● Aware of physical 3D concepts (e.g.

intersection)

Existing programmatic CAD tools

OpenSCADFreeCADPythonOCCCadquery

Why Blender?

● Intended for artistic uses● Awesome Python API● Large user base● Open source

Why NOT Blender?

● It’s not CAD● Mesh-based● Poor support for physical construction

A Quick Tour of Blender

bpy - Main Blender Python module

Programmatic equivalent of the GUI

Highly imperative - Operations apply to the global selection context

Great for macros/automation, not for complex apps

A bpy operation - No arg for what you’re resizing!

bmesh - Low level mesh interface

Meshes are Python objects

A BMesh object contains:- Vertices- Edges (2 verts)- Faces (3+ verts)

bmesh (cont’d)

Users must ensure mesh consistency

Tightly coupled to C data structures - be careful directly modifying mesh data!

bmesh.ops - BMesh Operations

Most GUI (bpy) ops have underlying BMesh implementations

(Mostly) well documented

bmesh.ops - Example

Blender’s classes for 3D math: Matrix, Vector, etc.

Available as a standalone module

mathutils

Wait, what are we trying to do again?

Wait, what are we trying to do again?

Introducing Sly

A Python library for 3D construction from 2D parts

Uses Blender for I/O, but fairly decoupled

Only ~350 SLoC

Two core concepts

Slice - A 2D polygon (with thickness) positioned in 3D space.

Cut - Material to be removed from a slice so it can interlock with another slice

Let’s see it in action!

Manually sculpted mesh

Mirroring and smoothing - Blender mesh modifiers

Specify slice locations and orientations

Extract slices from selected mesh

Apply an operation to each one

Add slices to vector output and Blender scene

Script generates slices

Rendered slices include cutouts

Generated vectors, manually positioned

Sly implementationExtracting slices from a model:

Sly implementation (cont’d)

Shapely - http://toblerity.org/shapely/● Great polygon library● GIS-focused but general purpose● Support for geometric operations:

intersections, unions, etc.● Slices use Shaply polygons internally

Sly Roadmap

● Installer, tests, docs● Command line operation● Better Blender GUI integration● Smart slice placement● Output to G-code?● Different construction modes?

Want more?

In-depth sessions at PS:1 starting in April, email me to get notified: [email protected]

Contribute on GitHub: github.com/meshulam/sly

Thanks!

Twitter: @mattmeshulam

GitHub: meshulam