From d07812377b64b7d7719071303588b35da0f2b982 Mon Sep 17 00:00:00 2001 From: Patricio Whittingslow Date: Sun, 25 Aug 2024 18:35:51 -0300 Subject: [PATCH] update README --- README.md | 16 +++++++++++++--- examples/bolt/main.go | 6 +++++- gsdfaux/gsdfaux.go | 8 +++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9009fea..a21beb3 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ Offshoot from [this project](https://github.com/soypat/sdf/pull/13). ![circle](https://github.com/user-attachments/assets/91c99f47-0c52-4cb1-83e7-452b03b69dff) -![iso-screw](https://github.com/user-attachments/assets/6bc987b9-d522-42a4-89df-71a20c3ae7ff) - +![bolt-example](https://github.com/user-attachments/assets/8da50871-2415-423f-beb3-0d78ad67c79e) ## Features @@ -92,7 +91,18 @@ Below is the 3D scene code. Omits rendering pipeline. union = gsdf.Difference(union, hole) // Convert from imperial inches units to millimeter: union = gsdf.Scale(union, 25.4) - renderSDF(union) + + stl, _ := os.Create("for3dprinting.stl") + err = gsdfaux.Render(object, gsdfaux.RenderConfig{ + STLOutput: stl, + Resolution: union.Bounds().Diagonal() / 200, + UseGPU: true, + }) ``` +![npt-flange-example](https://github.com/user-attachments/assets/32a00926-0a1e-47f0-8b6c-dda940240265) + +## More examples +![fibonacci-showerhead](https://github.com/user-attachments/assets/a72c366c-6ee0-43ba-9128-087a76524ff9) +![iso-screw](https://github.com/user-attachments/assets/6bc987b9-d522-42a4-89df-71a20c3ae7ff) ![array-triangles](https://github.com/user-attachments/assets/6a479889-2836-464c-b8ea-82109a5aad13) \ No newline at end of file diff --git a/examples/bolt/main.go b/examples/bolt/main.go index 3af31bb..c896987 100644 --- a/examples/bolt/main.go +++ b/examples/bolt/main.go @@ -4,9 +4,12 @@ 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" @@ -21,7 +24,7 @@ func init() { // scene generates the 3D object for rendering. func scene() (glbuild.Shader3D, error) { - const L, shank = 5, 3 + const L, shank = 8, 3 threader := threads.ISO{D: 3, P: 0.5, Ext: true} M3, err := threads.Bolt(threads.BoltParams{ Thread: threader, @@ -32,6 +35,7 @@ func scene() (glbuild.Shader3D, error) { if err != nil { return nil, err } + M3, _ = gsdf.Rotate(M3, math.Pi/2, ms3.Vec{Y: 1}) return M3, nil } diff --git a/gsdfaux/gsdfaux.go b/gsdfaux/gsdfaux.go index c4b9cab..5741f51 100644 --- a/gsdfaux/gsdfaux.go +++ b/gsdfaux/gsdfaux.go @@ -10,6 +10,7 @@ import ( "time" math "github.com/chewxy/math32" + "github.com/soypat/glgl/math/ms3" "github.com/soypat/gsdf" "github.com/soypat/gsdf/glbuild" "github.com/soypat/gsdf/gleval" @@ -76,17 +77,18 @@ func Render(s glbuild.Shader3D, cfg RenderConfig) (err error) { if cfg.VisualOutput != nil { watch = stopwatch() - const sceneSize = 0.5 + const sceneSize = 1.4 // We include the bounding box in the visualization. bb := s.Bounds() - envelope, err := gsdf.NewBoundsBoxFrame(bb) + envelope, err := gsdf.NewBoundsBoxFrame(bb.Add(ms3.Vec{100, 100, 100})) if err != nil { return err } visual := gsdf.Union(s, envelope) // Scale size and translate to center so visualization is in camera range. center := bb.Center() - visual = gsdf.Translate(visual, center.X, center.Y, center.Z) + sz := bb.Size() + visual = gsdf.Translate(visual, center.X, center.Y, center.Z-sz.Z) visual = gsdf.Scale(visual, sceneSize/bb.Diagonal()) _, err = glbuild.NewDefaultProgrammer().WriteFragVisualizerSDF3(cfg.VisualOutput, visual) if err != nil {