Skip to content

Commit

Permalink
glgl: use new version with fixed smooth bounds check
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Oct 2, 2024
1 parent 0466d0a commit e6ef23a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
9 changes: 9 additions & 0 deletions examples/fibonacci-showerhead/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/soypat/gsdf"
"github.com/soypat/gsdf/forge/threads"
"github.com/soypat/gsdf/glbuild"
"github.com/soypat/gsdf/gleval"
"github.com/soypat/gsdf/gsdfaux"
)

Expand Down Expand Up @@ -48,6 +49,13 @@ func scene() (glbuild.Shader3D, error) {
P: threadPitch,
}
)
t2d, err := showerThread.Thread()
if err != nil {
return nil, err
}
threadSDF, _ := gleval.NewCPUSDF2(t2d)
gsdfaux.RenderPNGFile("thread.png", threadSDF, 512, nil)

// Object accumulates the showerhead sdf.
var object glbuild.Shader3D

Expand All @@ -56,6 +64,7 @@ func scene() (glbuild.Shader3D, error) {
if err != nil {
return nil, err
}

threads, err := threads.Screw(threadheight+.5, showerThread)
if err != nil {
return nil, err
Expand Down
25 changes: 14 additions & 11 deletions forge/threads/plasticbuttress.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ func (butt PlasticButtress) Thread() (glbuild.Shader2D, error) {
t1 = 0.1227845609029046 // math.Tan(7.0 * math.Pi / 180)
)
const threadEngage = 0.6 // thread engagement

h0 := butt.P / (t0 + t1)
h1 := ((threadEngage / 2.0) * butt.P) + (0.5 * h0)
hp := butt.P / 2.0
p := butt.P
h0 := p / (t0 + t1)
h1 := ((threadEngage / 2.0) * p) + (0.5 * h0)
hp := p / 2.0
var tp ms2.PolygonBuilder

tp.AddXY(butt.P, 0)
tp.AddXY(butt.P, radius)
tp.AddXY(hp-((h0-h1)*t1), radius).Smooth(0.05*butt.P, 5)
tp.AddXY(t0*h0-hp, radius-h1).Smooth(0.15*butt.P, 5)
tp.AddXY((h0-h1)*t0-hp, radius).Smooth(0.15*butt.P, 5)
tp.AddXY(-butt.P, radius)
tp.AddXY(-butt.P, 0)
tp.AddXY(p, 0)
tp.AddXY(p, radius)
p2 := hp - ((h0 - h1) * t1)
tp.AddXY(p2, radius).Smooth(0.05*p, 5)
p3 := t0*h0 - hp
tp.AddXY(p3, radius-h1).Smooth(0.15*p, 5)
p4 := (h0-h1)*t0 - hp
tp.AddXY(p4, radius).Smooth(0.15*p, 5)
tp.AddXY(-p, radius)
tp.AddXY(-p, 0)
verts, err := tp.AppendVecs(nil)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.1
require (
github.com/chewxy/math32 v1.11.1
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71
github.com/soypat/glgl v0.0.0-20241002211926-dd918c50e92c
github.com/soypat/glgl v0.0.0-20241002235249-2e94328dcb41
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ github.com/soypat/glgl v0.0.0-20240919182556-c8a0c61170b5 h1:1XUEnlRfPTa5DEfZRl9
github.com/soypat/glgl v0.0.0-20240919182556-c8a0c61170b5/go.mod h1:1LcEp6XHSMCI91WlJHzl/aW4Bp5v6yQOiYFyjrlk350=
github.com/soypat/glgl v0.0.0-20241002211926-dd918c50e92c h1:AlK/fJ26jQn2fh7vFwWPMMGYYWH6U02P9FpgVG7mXLA=
github.com/soypat/glgl v0.0.0-20241002211926-dd918c50e92c/go.mod h1:1LcEp6XHSMCI91WlJHzl/aW4Bp5v6yQOiYFyjrlk350=
github.com/soypat/glgl v0.0.0-20241002235249-2e94328dcb41 h1:18vgZOd/q87AajjwwFYYIvdjAIqI7wbGDzryhU4DmlU=
github.com/soypat/glgl v0.0.0-20241002235249-2e94328dcb41/go.mod h1:1LcEp6XHSMCI91WlJHzl/aW4Bp5v6yQOiYFyjrlk350=
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 h1:m9O6OTJ627iFnN2JIWfdqlZCzneRO6EEBsHXI25P8ws=
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=

0 comments on commit e6ef23a

Please sign in to comment.