Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

bluecube/codecad

Repository files navigation

CodeCad: A programming CAD based on signed distance functions

The project is dead

Some good points:

  • The modeling API turned out to be surprisingly comfortable. Might be worth reusing in some later project.
  • OpenCL and Python is an awesome combination.

... and some bad points ..

  • SDF is a neat way to represent geometry, but there are some serious drawbacks
    • It's hard to make them robust. Things like s.offset(-1).offset(1) tend to break the invariants create weird glitches. This becomes extra visible when using the distance function value for shading, but is hard to avoid even when just working for surface export.
    • While physical objects are mostly comprised of their insides, the surface is where the interesting things happen and it is a bit wastefull to have to find the surface agin for every rendering operation, physics query...
  • Only code for modelling is not good enough. While some things are easier than with GUI clickery, most are more difficult and I'm still looking for a way that is bettern than either of these.

Now you can enjoy the old description:

Inspired by OpenSCAD and ImplicitCad, implemented in Python using OpenCL for computing power.

CodeCad cube logo

Currently CodeCad consists mostly of an API for representing and manipulating geometry using CSG operations and exports to STL and image. There is also a simple part/assembly model and BOM generator.

Goals

At this stage the main goal is to have usability on par with OpenSCAD. We're not there yet, although some useable models can already be created.

In the long term this should have a working GUI and parametric sketch tools.

Who knows what's next. Maybe turning this into a slicer?

Requirements

The main requirement to run CodeCad is a working OpenCL implementation. Your GPU should provide one, or try POCL.

CodeCad might work on Windows, but it hasn't been tested.

Example Code

The cube at the beginning of this file was generated by the following piece of code:

import codecad
from codecad.shapes import *

width = 0.6
stroke = 0.2

# Build the C shape  1 unit high
c = (rectangle(width, 1 - width + stroke / 2)
     + circle(d=width).translated_y((1 - width) / 2)
     + circle(d=width).translated_y(-(1 - width) / 2))
c = c.shell(stroke)
c -= rectangle(width, 1 - width).translated_x(width / 2)

# Scale it to 1 unit sized cube and prepare for adding
c = (c
     .scaled(0.6)
     .extruded(0.12)
     .rotated_x(90)
     .translated_y(-0.5))

# Put the logo together
logo = box() + c + c.rotated_z(90)
logo = (logo
        .scaled(100)
        .rotated_z(-45)
        .rotated_x(15))

codecad.commandline_render(logo)