• Stars
    star
    169
  • Rank 224,453 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GhostSCAD enables you to programatically build complex 3D models in Go and render them in OpenSCAD

GhostSCAD

GhostSCAD is a piece of software that makes it easy to create CAD models using Go and compile them to the OpenSCAD language. It allows you to use the full power of a real programming language and use the rendering capabilities of OpenSCAD.

It requires GO 1.17.

Screenshot

See the blog post explaining the motivations here and a real-life example here.

Example

GhostSCAD aims to minimize the boilerplate but, since it uses a general purpose programming language, there is still some. First, you need to create a Go module for your project and add GhostSCAD to it:

mkdir design; cd design
go mod init example.com/design
go get github.com/ljanyst/ghostscad

Here's an example rendering a sphere of radius 10 and producing the appropriate OpenSCAD model in the main.scad file:

package main

import (
	. "github.com/ljanyst/ghostscad/primitive"
	"github.com/ljanyst/ghostscad/sys"
)

func main() {
	sys.Initialize()
	sys.RenderOne(Sphere(10))
}

You can generate such a minimal program by running:

go run github.com/ljanyst/ghostscad/util/stub_generator -file-name blah.go

Here's a slightly more elaborate example:

package main

import (
	"github.com/ljanyst/ghostscad/lib/shapes"
	"github.com/ljanyst/ghostscad/sys"

	. "github.com/ljanyst/ghostscad/primitive"
)

func main() {
	sys.Initialize()
	sector := shapes.NewSector(20, 45, 135).SetFn(72).Build()
	arc := shapes.NewArc(25, 45, 290).SetWidth(2).SetFn(72).Build()
	sys.RenderMultiple([]sys.Shape{
		{"sector", sector, sys.None},
		{"arc", arc, sys.None},
		{"sector-and-arc", NewList(sector, arc), sys.Default},
	})
}

It imports the complex shape library provided with GhostSCAD and renders multiple shapes. The parameter to sys.RenderMultiple is a slice of Shape object. The default shape is the one being rendered to sector-and-arc.scad unless the program is instructed otherwise via commandline parameters. You can list the available shapes:

]==> go build
]==> ./sector-and-arc -list-shapes
sector
arc
sector-and-arc (default)

You can render the one you like:

]==> ./sector-and-arc -shape arc
]==> ls arc.scad
arc.scad

You can also generate the STL file directly (if it were a 3D shape) by supplying the -stl parameter. Use the familiar -help to see all the available parameters.

There's a whole bunch of other examples in this code repository. The author leaves it as an exercise to the reader to find them. :)

Rendering Automation

One of the cool features of OpenSCAD is automatic re-rendering triggered by changes to the underlying SCAD files. Since GhostSCAD leverages the Go programming language, it also makes sense to use it in a fully-fledged code editor. Here's an Elisp function to compile and run the current go buffer in Emacs:

(defun go-run-this-file ()
  "go run"
  (interactive)
  (save-buffer)
  (shell-command (format "go run %s" (buffer-file-name))))

You can then bind it to a key combination in your go-mode hook like this:

(local-set-key (kbd "C-c C-r") 'go-run-this-file)

After you set this up, hitting "CTRL-C CTRL-R" compbination runs the code in the current go buffer and overwrites the main.scad file with the most recent version of your model. If you have OpenSCAD rendering this file, it will redraw your model automagically.

Happy hacking!

More Repositories

1

ssd-tensorflow

A Single Shot MultiBox Detector in TensorFlow
Python
169
star
2

image-segmentation-fcn

Semantic Image Segmentation using a Fully Convolutional Neural Network in TensorFlow
Python
87
star
3

scrapy-do

A daemon for scheduling Scrapy spiders
Python
65
star
4

carddav-util

A CardDAV import/export utility
Python
58
star
5

peroxide

A third-party ProtonMail bridge serving SMTP and IMAP
Go
58
star
6

traffic-lights-detector

A traffic lights detector using the TensorFlow object detection API
Python
31
star
7

pipilot

A software aircraft controller for RaspberryPi
JavaScript
9
star
8

calibre-hacks

Calibre hacks I use to generate ebooks from online content
Shell
8
star
9

tiva-cmake-template

CMake template for the Tiva microcontroller
C
4
star
10

threading-from-scratch

Implementing a threading system on top of Linux syscalls
C
4
star
11

deep-learning

My musings related to deep learning
Python
4
star
12

tv-table-rack

A 3D-printed computer rack for tiny electronics
Go
4
star
13

scrapy-rss-exporter

An RSS exporter for Scrapy
Python
3
star
14

jail

A sandbox container for GUI applications
Shell
2
star
15

silly-invaders

An Alien Invaders game on Tiva MCU
C
2
star
16

xrdclient

XRootD Client - Merged with the main project at https://github.com/xrootd/xrootd
C++
2
star
17

pico-enc28j60

A RaspberryPi Pico driver for the ENC28J60 controller
C
1
star
18

ray-tracer

My take at the Ray Tracer Challenge in Rust
Rust
1
star
19

gmailmigr

Tools for moving emails out of GMail
Python
1
star
20

monkey

A programming language written in go
Go
1
star
21

reef

JavaScript
1
star
22

gosh

A library of scripting helpers
Go
1
star
23

udacity-kalman-filters

Udacity Self-Driving Car ND Project - Kalman Filters
C++
1
star
24

udacity-path-planning

Udacity Self-Driving Car ND Project - Path Planning
C++
1
star