Skip to content

Commit

Permalink
gl_inet: lid and hole
Browse files Browse the repository at this point in the history
  • Loading branch information
unixpickle committed Jan 7, 2024
1 parent 890ef42 commit f56d7e3
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
21 changes: 2 additions & 19 deletions examples/parody/gl_inet/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
BodyPowerHoleWidth = 0.15
)

func InetBody() model3d.Solid {
func InetBody(doPowerHole bool) model3d.Solid {
sphere := model3d.Sphere{
Center: model3d.Z(-BodyRadius + 1.0),
Radius: BodyRadius,
Expand All @@ -24,23 +24,6 @@ func InetBody() model3d.Solid {
model2d.Ones(-BodySideLength/2+BodyCornerRadius),
model2d.Ones(BodySideLength/2-BodyCornerRadius),
)
holes := model3d.JoinedSolid{
&model3d.Cylinder{
P1: model3d.XYZ(-0.25, 0.9, 0.8),
P2: model3d.XYZ(-0.25, 1.0, 1.0),
Radius: 0.02,
},
&model3d.Cylinder{
P1: model3d.XYZ(0.0, 0.9, 0.8),
P2: model3d.XYZ(0.0, 1.0, 1.0),
Radius: 0.02,
},
&model3d.Cylinder{
P1: model3d.XYZ(0.25, 0.9, 0.8),
P2: model3d.XYZ(0.25, 1.0, 1.0),
Radius: 0.02,
},
}
powerHole2d := model2d.NewColliderSolidInset(
model2d.NewRect(
model2d.XY(0.8-BodyPowerHoleRadius-BodyPowerHoleWidth, 0.15+BodyPowerHoleRadius),
Expand All @@ -60,7 +43,7 @@ func InetBody() model3d.Solid {
if !sphere.Contains(c) {
return false
}
if holes.Contains(c) || powerHole.Contains(c) {
if doPowerHole && powerHole.Contains(c) {
return false
}
return baseRect.SDF(c.XY()) > -BodyCornerRadius
Expand Down
64 changes: 64 additions & 0 deletions examples/parody/gl_inet/lid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"github.com/unixpickle/model3d/model2d"
"github.com/unixpickle/model3d/model3d"
)

const (
LidThickness = 0.08
LidSlack = 0.02
InnerInset = 0.35
BodyHoleMinZ = 0.2
)

func LidAndCutout() (model3d.Solid, model3d.Solid) {
body := InetBody(false)
lid := &model3d.SubtractedSolid{
Positive: body,
Negative: model3d.TranslateSolid(body, model3d.Z(-LidThickness)),
}
baseRect := model2d.NewRect(
model2d.Ones(-BodySideLength/2+BodyCornerRadius+InnerInset),
model2d.Ones(BodySideLength/2-BodyCornerRadius-InnerInset),
)
bodyHole := model3d.ProfileSolid(
model2d.NewColliderSolidInset(baseRect, -BodyCornerRadius),
BodyHoleMinZ,
100.0,
)
holes := model3d.JoinedSolid{
&model3d.Cylinder{
P1: model3d.XYZ(-0.25, 0.9, 0.8),
P2: model3d.XYZ(-0.25, 0.9, 1.0),
Radius: 0.02,
},
&model3d.Cylinder{
P1: model3d.XYZ(0.0, 0.9, 0.8),
P2: model3d.XYZ(0.0, 0.9, 1.0),
Radius: 0.02,
},
&model3d.Cylinder{
P1: model3d.XYZ(0.25, 0.9, 0.8),
P2: model3d.XYZ(0.25, 0.9, 1.0),
Radius: 0.02,
},
}
lidInnerEdge := &model3d.SubtractedSolid{
Positive: model3d.ProfileSolid(
model2d.NewColliderSolidInset(baseRect, -BodyCornerRadius+LidSlack),
0.7,
0.89,
),
Negative: model3d.ProfileSolid(
model2d.NewColliderSolidInset(baseRect, -BodyCornerRadius+LidSlack+LidThickness),
0.7,
0.89,
),
}

return &model3d.SubtractedSolid{
Positive: model3d.JoinedSolid{lid, lidInnerEdge},
Negative: holes,
}, model3d.JoinedSolid{bodyHole, lid}
}
9 changes: 7 additions & 2 deletions examples/parody/gl_inet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
)

func main() {
body := InetBody()
body := InetBody(true)

lid, lidCutout := LidAndCutout()

jack := EthernetJackSolid()
min, max := jack.Min(), jack.Max()
Expand Down Expand Up @@ -38,6 +40,7 @@ func main() {
jackHole,
usbPort,
fanHole,
lidCutout,
},
},
usbInner,
Expand All @@ -50,8 +53,10 @@ func main() {
}

log.Println("Creating mesh...")
lidMesh := model3d.DualContour(lid, 0.01, true, false)
lidMesh.SaveGroupedSTL("lid.stl")
mesh, interior := model3d.DualContourInterior(joined, 0.01, true, false)
mesh.SaveGroupedSTL("out.stl")
mesh.SaveGroupedSTL("body.stl")
colorFunc := toolbox3d.JoinedSolidCoordColorFunc(
interior,
body, render3d.NewColorRGB(224.0/255, 209.0/255, 0),
Expand Down

0 comments on commit f56d7e3

Please sign in to comment.