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

Related tags

Images tools stl
Overview

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.

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.)

    opened by aligator 4
  • 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.

    opened by bddap 2
  • 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.

    opened by tjhowse 1
  • 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?

    opened by tridiserkan 1
  • 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?

    opened by tridiserkan 2
Releases(v1.0.4)
Owner
Hagen Schendel
Hagen Schendel
: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

Quim Muntal 180 Sep 26, 2022
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

Robert Carlsen 531 Sep 11, 2022
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

pipelined 50 Jul 28, 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

Jaana Dogan 112 Sep 20, 2022
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

_Alvoras 8 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

Stephen Friedman 0 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

Gary Talent 12 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

Paul Mach 235 Sep 22, 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

Guillermo Estrada 60 Aug 14, 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

David Byttow 755 Sep 22, 2022
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

null 76 Aug 16, 2022
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.

Jonnas Fonini 63 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

Karpelès Lab Inc. 8 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

Jesse Donat 9 Jun 17, 2022
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

Hisham waleed karam 76 Sep 26, 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

Go 1.4k Sep 15, 2022
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

Tom 2k Sep 19, 2022
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

go-gl legacy 21 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

Erik Unger 124 Sep 26, 2022