Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Aug 25, 2024
1 parent 6d8c361 commit d078123
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
6 changes: 5 additions & 1 deletion examples/bolt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions gsdfaux/gsdfaux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d078123

Please sign in to comment.