Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Aug 26, 2024
1 parent 8b1c442 commit 88617dc
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 86 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Offshoot from [this project](https://github.com/soypat/sdf/pull/13).
- `gleval`: SDF evaluation interfaces and facilities, both CPU and GPU bound.
- `glrender`: Triangle rendering logic which consumes gleval. STL generation.
- `forge`: Composed shape generation such as `threads` package for generating screw threads. Engineering applications.

- `gsdfaux`: High level helper functions to get users started up with `gsdf`. See [examples](./examples).

## Part design - NPT Flange example.
This was converted from the [original example](https://github.com/soypat/sdf/blob/main/examples/npt-flange/flange.go). See [README](https://github.com/soypat/sdf/tree/main/examples) for images.
Expand Down Expand Up @@ -95,7 +95,7 @@ Below is the 3D scene code. Omits rendering pipeline.
stl, _ := os.Create("for3dprinting.stl")
err = gsdfaux.Render(object, gsdfaux.RenderConfig{
STLOutput: stl,
Resolution: union.Bounds().Diagonal() / 200,
Resolution: union.Bounds().Diagonal() / 200,
UseGPU: true,
})
```
Expand Down
73 changes: 36 additions & 37 deletions examples/fibonacci-showerhead/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,8 @@ func init() {
runtime.LockOSThread() // In case we wish to use OpenGL.
}

func run() error {
useGPU := flag.Bool("gpu", false, "Enable GPU usage")
flag.Parse()
object, err := scene()
if err != nil {
return err
}
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.Render(object, gsdfaux.RenderConfig{
STLOutput: fpstl,
VisualOutput: fpvis,
Resolution: object.Bounds().Diagonal() / 200,
UseGPU: *useGPU,
})

return err
}

func main() {
err := run()
if err != nil {
log.Fatal(err)
}
fmt.Println("showerhead example done")
}

// scene returns the showerhead object.
func scene() (glbuild.Shader3D, error) {

// Showerhead parameters as defined by showerhead geometry.
const (
threadExtDiameter = 65.
Expand Down Expand Up @@ -119,6 +82,42 @@ func scene() (glbuild.Shader3D, error) {
return object, nil
}

func run() error {
useGPU := flag.Bool("gpu", false, "Enable GPU usage")
flag.Parse()
object, err := scene()
if err != nil {
return err
}
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.Render(object, gsdfaux.RenderConfig{
STLOutput: fpstl,
VisualOutput: fpvis,
Resolution: object.Bounds().Diagonal() / 200,
UseGPU: *useGPU,
})

return err
}

func main() {
err := run()
if err != nil {
log.Fatal(err)
}
fmt.Println("showerhead example done")
}

func fibonacci(n int) ms2.Vec {
// Angle of divergence is very sensitive- 137.3 to 137.5 varies pattern greatly.
const angleOfDivergence = 137.3
Expand Down
31 changes: 22 additions & 9 deletions examples/image/image.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"image"
"image/color"
"image/png"
Expand All @@ -13,28 +12,42 @@ import (
"github.com/soypat/glgl/math/ms2"
"github.com/soypat/glgl/math/ms3"
"github.com/soypat/gsdf"
"github.com/soypat/gsdf/glbuild"
"github.com/soypat/gsdf/gleval"
"github.com/soypat/gsdf/glrender"
)

const size = 256
const dim = 20

func main() {
img := image.NewRGBA(image.Rect(0, 0, 2*size, size))
renderer, err := glrender.NewImageRendererSDF2(4096, colorConversion)
func scene() (glbuild.Shader2D, error) {
s, err := gsdf.NewCircle(dim)
if err != nil {
log.Fatal(err)
return nil, err
}

s, _ := gsdf.NewCircle(dim)
poly, _ := gsdf.NewPolygon([]ms2.Vec{
poly, err := gsdf.NewPolygon([]ms2.Vec{
{X: dim, Y: 0},
{X: 3 * dim, Y: dim},
{X: 3 * dim, Y: -dim},
})
if err != nil {
return nil, err
}
s = gsdf.Union2D(s, poly)
fmt.Println(s.Bounds())
return s, nil
}

func main() {
img := image.NewRGBA(image.Rect(0, 0, 2*size, size))
renderer, err := glrender.NewImageRendererSDF2(4096, colorConversion)
if err != nil {
log.Fatal(err)
}
s, err := scene()
if err != nil {
log.Fatal(err)
}

sdf, err := gleval.NewCPUSDF2(s)
if err != nil {
log.Fatal(err)
Expand Down
76 changes: 38 additions & 38 deletions examples/npt-flange/flange.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,11 @@ import (
"github.com/soypat/gsdf/gsdfaux"
)

func init() {
runtime.LockOSThread() // For when using GPU this is required.
}

const visualization = "nptflange.glsl"
const stl = "nptflange.stl"

func run() error {
useGPU := flag.Bool("gpu", false, "Enable GPU rendering")
flag.Parse()
s, err := scene()
if err != nil {
return err
}

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.Render(s, gsdfaux.RenderConfig{
STLOutput: fpstl,
VisualOutput: fpvis,
Resolution: s.Bounds().Diagonal() / 200,
UseGPU: *useGPU,
})
return err
}

func main() {
err := run()
if err != nil {
log.Fatal(err)
}
fmt.Println("finished npt-flange example")
func init() {
runtime.LockOSThread() // For when using GPU this is required.
}

func scene() (glbuild.Shader3D, error) {
Expand Down Expand Up @@ -93,3 +57,39 @@ func scene() (glbuild.Shader3D, error) {
union = gsdf.Scale(union, 25.4)
return union, nil
}

func run() error {
useGPU := flag.Bool("gpu", false, "Enable GPU rendering")
flag.Parse()
s, err := scene()
if err != nil {
return err
}

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.Render(s, gsdfaux.RenderConfig{
STLOutput: fpstl,
VisualOutput: fpvis,
Resolution: s.Bounds().Diagonal() / 200,
UseGPU: *useGPU,
})
return err
}

func main() {
err := run()
if err != nil {
log.Fatal(err)
}
fmt.Println("finished npt-flange example")
}

0 comments on commit 88617dc

Please sign in to comment.