A library to read, write, and transform Stereolithography (.stl) files in Go.

stl

A library to read, write, and transform Stereolithography (.stl) files in Go. It is used in the command line STL manipulation tool stltool.

Features

  • Read and write STL files in either binary or ASCII form
  • Check correctness of STL files
  • Measure models
  • Various linear model transformations
    • Scale
    • Rotate
    • Translate (Move)
    • Fit into box
    • Apply generic 4x4 transformation matrix

Applications

  • Save 3D models as STL
  • Import STL models
  • Repair and manipulation of STL models
  • General pre-processing before processing STL models in a 3D printing slicer
  • Writing a slicer in Go (I hope someone does this one day)

Installation

Using go's builtin installation mechanism:

go get github.com/hschendel/stl

Usage Example

solid, errRead := stl.ReadFile(inputFilename)
if errRead != nil {
  // handle
}
solid.Scale(25.4) // Convert from Inches to mm
errWrite := solid.WriteFile(outputFilename)

Stream Processing STL Files

You can implement the stl.Writer interface to directly write into your own data structures. This way you can use the stl.CopyFile and stl.CopyAll functions.

var ownData ownDataStructure // implements stl.Writer
err := stl.CopyFile("somefile.stl", &ownData)

Further Reading

The package godoc documentation should be helpful. Or just start a local godoc server using this command:

godoc -http=:6060

Then open http://localhost:6060/pkg/github.com/hschendel/stl/ in your browser.

License

The stl package is licensed under the MIT license. See LICENSE file.

Owner
Comments
  • support of binary files starting with

    support of binary files starting with "solid " in isASCIIFile

    There are some binary stl files which start with "solid ". This breaks the assumption that files with "solid " are always ascii files.

    An example is the very popular 3DBenchy.stl from https://www.thingiverse.com/thing:763622/files

    To fix this I used this method: https://stackoverflow.com/a/7394842/353337 -> validate if the lenght field matches the actual file

    I am not fully happy about my solution because it now opens the file two times. I did this because otherwise it would be much more complicated code as the first 84 bits are already read and they would need a special treat in ascii parsing (as we cannot go "back" using the reader).

    I have added a test case for this.

    Edit: by the way: as you wrote this in your readme:

    Writing a slicer in Go (I hope someone does this one day)

    I am trying exactly this. (But I use your lib only for stl loading as I need full control over the datatypes.)

  • Fix axis angle rotations

    Fix axis angle rotations

    RotationMatrix() was generating some weird transformations, like mirroring instead of rotating.

    I wasn't sure where the bug was exactly, so I rewrote some stuff using section 5.2 this paper as a reference.

  • Vec3 methods are private

    Vec3 methods are private

    I am using this module to import STL files. I'd like to be able to do maths on the results, however the methods on stl.Vec3 are all private, which means I need to convert stl.Vec3 into an internal representation. Would you be amenable to a PR that either A) Makes the stl.Vec3 methods public (add, diff, cross, etc), or B) Adds public accessors for each dimension (stl.Vec3.X(), stl.Vec3.Y(), stl.Vec3.Z()) such that I can implement the maths methods in my own code via an interface?

    Cheers, tjhowse.

  • Floating point decimal number

    Floating point decimal number

    Hi, I guess this is causing from me but I could not change vertex point decimal numbers to 2 from 7. Even when I take solid as a variable from pointer, after few lines which are pretty sure making changes on my slices not on "stl.Solid" datatype, both my slices and solid pointer change values back.

    If I could been able to change decimal coding to 2 from 7 it would be okay for me right now. Did you do this in writebinary.go?

  • Vertice mapping

    Vertice mapping

    Hi there,

    I am trying to rotate and translate triangles one by one and I came across an issue:

    Initial solid has lower number of vertices than the last one. I store every vertice and its new corresponding point so that I can form a translation vector if I come across the same vertice in different triangle.

    This was basically my procedure but after translation some vertices does not match and most of the case differ with very small value but this causes an increase in number of vertices. Do you have an idea why this can be happening?

Related tags
:eyeglasses: Go library for [d]encoding glTF 2.0 files
:eyeglasses: Go library for [d]encoding glTF 2.0 files

gltf A Go module for efficient and robust serialization/deserialization of glTF 2.0, a royalty-free specification for the efficient transmission and l

Jan 1, 2023
Decode embedded EXIF meta data from image files.

goexif Provides decoding of basic exif and tiff encoded data. Still in alpha - no guarantees. Suggestions and pull requests are welcome. Functionality

Dec 17, 2022
Process audio files with pipelined DSP framework
Process audio files with pipelined DSP framework

phono is a command for audio processing. It's build on top of pipelined DSP framework. Installation Prerequisites: lame to enable mp3 encoding To link

Oct 4, 2022
Merge multiple pprof profile files into a single file

pprof-merge Merges multiple pprof profile files into one. Installation $ go get github.com/rakyll/pprof-merge Usage $ pprof-merge profile1.data profi

Dec 15, 2022
Paprika is a toolbox for creating short clips from multiple png files.
Paprika is a toolbox for creating short clips from multiple png files.

Paprika Paprika is a toolbox for creating short clips from multiple png files. Requirements This program is mainly a wrapper around ffmpeg. As such, y

Feb 16, 2022
Converts Apple .heic files to .jpg

heic-to-jpg Converts Apple .heic files to .jpg Install this necessary tool: sudo apt-get install libheif-examples Put all your .heic files in the heic

Dec 30, 2021
This is old and unmaintained code, ignore it. starfish is a simple, SDL based, 2D graphics and user input library for Go. If you intend to work on it, please fork from the 'devel' branch, not 'master'. Current release: 0.12.0

What is starfish? What starfish is: starfish is a simple 2D graphics and user input library for Go built on SDL. What starfish is not: While it is bui

Jun 4, 2019
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Dec 30, 2022
Image processing library and rendering toolkit for Go.

blend Image processing library and rendering toolkit for Go. (WIP) Installation: This library is compatible with Go1. go get github.com/phrozen/blend

Nov 11, 2022
A lightning fast image processing and resizing library for Go

govips A lightning fast image processing and resizing library for Go This package wraps the core functionality of libvips image processing library by

Jan 8, 2023
Go cross-platform glfw library for creating an OpenGL context and receiving events.

glfw Package glfw experimentally provides a glfw-like API with desktop (via glfw) and browser (via HTML5 canvas) backends. It is used for creating a G

Sep 27, 2022
go-pix is a Go library for generating Pix transactions using Copy and Paste or QR codes. 💳 💰
go-pix is a Go library for generating Pix transactions using Copy and Paste or QR codes. 💳 💰

go-pix go-pix is a Go library for generating Pix transactions using Copy and Paste or QR codes.

Sep 12, 2022
A go library for reading and creating ISO9660 images

iso9660 A package for reading and creating ISO9660, forked from https://github.com/kdomanski/iso9660. Requires Go 1.13 or newer. Joliet and Rock Ridge

Mar 4, 2021
JPEG-MPO Decoder / Converter Library and CLI Tool

MPO Decoder Library Simple Go JPEG MPO (Multi Picture Object) Decoder - Library and CLI Tool The library and CLI tool contain the ability to convert M

Sep 26, 2022
geoserver is a Go library for manipulating a GeoServer instance via the GeoServer REST API.
geoserver is a Go library for manipulating a GeoServer instance via the GeoServer REST API.

Geoserver geoserver Is a Go Package For Manipulating a GeoServer Instance via the GeoServer REST API. How to install: go get -v gopkg.in/hishamkaram/g

Dec 22, 2022
S2 geometry library in Go

Overview S2 is a library for spherical geometry that aims to have the same robustness, flexibility, and performance as the best planar geometry librar

Jan 8, 2023
Go package for fast high-level image processing powered by libvips C library

bimg Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API. bimg was designed to be

Jan 2, 2023
Go bindings to OpenGL Utility Library

GLU This package offers minimal bindings for GLU functions. Usage go get github.com/go-gl-legacy/glu License Copyright 2012 The go-gl Authors. All ri

Aug 18, 2018
Go binding for the cairo graphics library

go-cairo Go binding for the cairo graphics library Based on Dethe Elza's version https://bitbucket.org/dethe/gocairo but significantly extended and up

Dec 19, 2022