generated from soypat/go-module-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
88 lines (78 loc) · 1.95 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"flag"
"fmt"
"log"
"math"
"os"
"runtime"
"github.com/soypat/glgl/math/ms3"
"github.com/soypat/gsdf"
"github.com/soypat/gsdf/forge/threads"
"github.com/soypat/gsdf/glbuild"
"github.com/soypat/gsdf/gsdfaux"
)
const visualization = "bolt.glsl"
const stl = "bolt.stl"
func init() {
runtime.LockOSThread() // For when using GPU this is required.
}
// scene generates the 3D object for rendering.
func scene(bld *gsdf.Builder) (glbuild.Shader3D, error) {
const L, shank = 8, 3
threader := threads.ISO{D: 3, P: 0.5, Ext: true}
M3, err := threads.Bolt(bld, threads.BoltParams{
Thread: threader,
Style: threads.NutHex,
TotalLength: L + shank,
ShankLength: shank,
})
if err != nil {
return nil, err
}
M3 = bld.Rotate(M3, 2.5*math.Pi/2, ms3.Vec{X: 1, Z: 0.1})
return M3, bld.Err()
}
func run() error {
var (
useGPU bool
resolution float64
flagResDiv uint
)
flag.BoolVar(&useGPU, "gpu", false, "enable GPU usage")
flag.Float64Var(&resolution, "res", 0, "Set resolution in shape units. Useful for setting the minimum level of detail to a fixed amount for final result. If not set resdiv used [mm/in]")
flag.UintVar(&flagResDiv, "resdiv", 200, "Set resolution in bounding box diagonal divisions. Useful for prototyping when constant speed of rendering is desired.")
flag.Parse()
var bld gsdf.Builder
object, err := scene(&bld)
if err != nil {
return err
}
if resolution == 0 {
resolution = float64(object.Bounds().Diagonal()) / float64(flagResDiv)
}
fpstl, err := os.Create(stl)
if err != nil {
return err
}
defer fpstl.Close()
fpvis, err := os.Create(visualization)
if err != nil {
return err
}
defer fpvis.Close()
err = gsdfaux.RenderShader3D(object, gsdfaux.RenderConfig{
STLOutput: fpstl,
VisualOutput: fpvis,
Resolution: float32(resolution),
UseGPU: useGPU,
})
return err
}
func main() {
err := run()
if err != nil {
log.Fatal(err)
}
fmt.Println("bolt example done")
}