示例#1
0
文件: slicer.go 项目: fogleman/ln
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)
	}
}
示例#2
0
文件: slices.go 项目: fogleman/ln
func (s *Shape) Paths() ln.Paths {
	var result ln.Paths
	// for i := 0; i < 360; i++ {
	// 	fmt.Println(i)
	// 	a := ln.Radians(float64(i))
	// 	x := math.Cos(a)
	// 	y := math.Sin(a)
	// 	plane := ln.Plane{ln.Vector{}, ln.Vector{x, y, 0}}
	// 	paths := plane.IntersectMesh(&s.Mesh)
	// 	result = append(result, paths...)
	// }
	for i := 0; i <= 100; i++ {
		fmt.Println(i)
		p := float64(i) / 100
		plane := ln.Plane{ln.Vector{0, 0, p*2 - 1}, ln.Vector{0, 0, 1}}
		result = append(result, plane.IntersectMesh(&s.Mesh)...)
		plane = ln.Plane{ln.Vector{p*2 - 1, 0, 0}, ln.Vector{1, 0, 0}}
		result = append(result, plane.IntersectMesh(&s.Mesh)...)
		plane = ln.Plane{ln.Vector{0, p*2 - 1, 0}, ln.Vector{0, 1, 0}}
		result = append(result, plane.IntersectMesh(&s.Mesh)...)
	}
	return result
}