Skip to content

Instantly share code, notes, and snippets.

@fogleman
Created July 20, 2016 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogleman/efde61f36060f9403bc48648b6c9fb0a to your computer and use it in GitHub Desktop.
Save fogleman/efde61f36060f9403bc48648b6c9fb0a to your computer and use it in GitHub Desktop.
Slices
package main
import (
"fmt"
"github.com/fogleman/ln/ln"
)
const Slices = 10
const Size = 1024
func main() {
// mesh, err := ln.LoadBinarySTL("bowser.stl")
mesh, err := ln.LoadOBJ("examples/suzanne.obj")
if err != nil {
panic(err)
}
mesh.FitInside(ln.Box{ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1}}, ln.Vector{0.5, 0.5, 0.5})
for i := 0; i < Slices; i++ {
fmt.Printf("slice%04d\n", i)
p := (float64(i)/(Slices-1))*2 - 1
point := ln.Vector{0, 0, p}
plane := ln.Plane{point, ln.Vector{0, 0, 1}}
paths := plane.IntersectMesh(mesh)
paths = paths.Transform(ln.Scale(ln.Vector{Size / 2, Size / 2, 1}).Translate(ln.Vector{Size / 2, Size / 2, 0}))
// paths.WriteToPNG(fmt.Sprintf("slice%04d.png", i), Size, Size)
paths.WriteToSVG(fmt.Sprintf("slice%04d.svg", i), Size, Size)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment