Projects tagged "3d"
This page highlights several of my personal software projects.
Table of Contents
SDF Modeling January 2021
Generate 3D meshes based on signed distance functions with a dirt simple Python API.
The goal of this library is to provide a simple, fun, and easy-to-use API for generating 3D models in our favorite language Python. The code simply uses the Marching Cubes algorithm to generate a mesh from a signed distance function (SDF). This would normally be abysmally slow in Python. However, numpy is used to evaluate the SDF on entire batches of points simultaneously. Furthermore, multiple threads are used to process batches in parallel. The result is surprisingly fast (for marching cubes). Supports text, 2D extrusion & revolution, image masks, various file formats, and more!
The code below is a complete example which generates the model shown in the image. This is the canonical Constructive Solid Geometry example. Note the use of operators for intersection, union, and difference.
from sdf import * f = sphere(1) & box(1.5) c = cylinder(0.5) f -= c.orient(X) | c.orient(Y) | c.orient(Z) f.save('out.stl')
Heightmap Meshing August 2019
Convert any grayscale heightmap into a 3D triangle mesh.
This is a modern implementation of a nice algorithm from the 1995 paper Fast Polygonal Approximation of Terrains and Height Fields by Garland and Heckbert. The meshes produced by
hmm satisfy the Delaunay condition and can satisfy a specified maximal error or maximal number of triangles or vertices. It's also very fast!
Cellular Forms June 2019
An implementation of Andy Lomas' Cellular Forms.
This is an implementation of a generative algorithm by Andy Lomas, described in his paper Cellular Forms: an Artistic Exploration of Morphogenesis.
While Andy implemented his algorithm on the GPU, my implementation is CPU-based. It includes a real-time viewer where you can watch the forms grow. It can also export STLs, which I used to then ray-trace the results. I found it interesting to "chop" the models in half, revealing their intricate inner structure as shown in the image here.
DLA February 2019
Fast diffusion-limited aggregation in both 2D and 3D.
This is a small program that generates diffusion-limited aggregations in either 2D or 3D. The output is a CSV file containing the coordinates of the particles and their relationship to one another. Rendering is out of scope, but I have produced several example renders. The code is very configurable - there are a few parameters that you can tweak and there are also several code hooks that allow you to alter the algorithm's behavior.
3D Packing June 2017
Tightly pack 3D meshes into as small of a volume as possible.
Formlabs recently announced the Fuse 1, a 3D printer that works via Selective Laser Sintering. This technique uses a nylon powder which conveniently supports the structures as they are printed. No scaffolding or supports are needed, so we can print as many objects as we can pack into the volume.
This begs the question - how many 3DBenchy boats can the Fuse 1 print in a single batch? As soon as the printer was announced, I immediately gravitated toward this algorithmic challenge.
With naive bin packing, 82 boats can be packed into the printer volume. But with some more advanced packing algorithms, 113 boats can fit - a 37.8% improvement!
Ribbon Diagrams February 2017
Parse PDB files and render ribbon diagrams of proteins.
Ribbon diagrams are 3D schematic representations of protein structure.
You've probably happened upon these before. I always thought they looked very complex and never figured I'd know how to create such a diagram myself. After creating FauxGL, however, I was in search of interesting 3D visualizations and decided to research these interesting diagrams.
Roughly, proteins are chains of amino acids that are pieced together while reading genetic code. As a protein is formed, these chains will fold in various ways, forming helixes, strands, and coils. A ribbon diagram depicts the 3D structure of the protein as well as these common secondary structures.
The Protein Data Bank is an online database of over 130,000 PDB files. These files encode all of the information needed to produce a ribbon diagram. With this software, you can simply type
rcsb XXXX where
XXXX is the alphanumeric PDB code and a PNG will be generated in a few seconds.
FauxGL January 2017
3D software rendering in pure Go. No OpenGL, no C extensions, no nothin'.
It's like OpenGL, but it's not. It's FauxGL.
It doesn't use your graphics card, only your CPU. So it's slow and unsuitable for realtime rendering. But it's still pretty fast. It works the same way OpenGL works - rasterization.
I mostly wrote this for fun and for learning, but I've already found it useful in other projects.
- STL, OBJ, PLY, 3DS file formats
- triangle rasterization
- vertex and fragment "shaders"
- view volume clipping, face culling
- alpha blending
- depth biasing
- wireframe rendering
- built-in shapes (plane, sphere, cube, cylinder, cone)
- anti-aliasing (via supersampling)
- parallel processing
Mesh Simplification May 2016
Simple command line tool for simplifying meshes in STL format.
This is a straight-forward implementation of Surface Simplification Using Quadric Error Metrics, SIGGRAPH 97, written in Go. Some problematic meshes don't simplify very well, but overall it works nicely. Watch the animation - the mesh is repeatedly simplified, starting with 86632 triangles and ending with just 64 triangles. The bunny remains recognizable for an impressive duration.
Line Art January 2016
Rendering engine that produces 2D vector graphics (think SVGs) depicting 3D scenes.
Unlike OpenGL, where the output of the rendering pipeline is a rastered image, the output of
ln is a set of 2D vector paths. It supports texturing, CSG, and more! I created this so I could plot 3D drawings with my pen plotter, which naturally requires vector input.
Path Tracer January 2015
CPU-only, unidirectional path tracing engine written in Go.
This was the first thing that I wrote using Go and I've been loving it ever since! The inspiration for this project came from Evan Wallace's WebGL Path Tracing.
- Supports OBJ and STL file formats
- Supports textures, bump maps and normal maps
- Supports raymarching of signed distance fields
- Supports volume rendering from image slices
- Supports various material properties
- Supports configurable depth of field
- Supports iterative rendering
- Supports adaptive sampling and firefly reduction
- Uses k-d trees to accelerate ray intersection tests
- Uses all CPU cores in parallel
- 100% pure Go with no dependencies besides the standard library
GPS September 2014
Real-time 3D visualization of actual GPS satellite locations.
This code interfaces with a USB GPS receiver and produces a 3D visualization of GPS satellite positions for all of the satellites that are currently in view.
HiRISE August 2014
Fly through real Martian landscapes using data released by HiRISE.
This code converts HiRISE DTMs from their PDS format to a 3D mesh in STL format with an accompanying normal map texture for high-resolution lighting. The visualizer was written using
pg, my Python OpenGL library.