From f56d7e38bbf0e832b7d6dab89d2d46b0b8e24f35 Mon Sep 17 00:00:00 2001 From: Alex Nichol Date: Sun, 7 Jan 2024 14:02:01 -0500 Subject: [PATCH] gl_inet: lid and hole --- examples/parody/gl_inet/body.go | 21 ++--------- examples/parody/gl_inet/lid.go | 64 +++++++++++++++++++++++++++++++++ examples/parody/gl_inet/main.go | 9 +++-- 3 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 examples/parody/gl_inet/lid.go diff --git a/examples/parody/gl_inet/body.go b/examples/parody/gl_inet/body.go index 1166ce7..14302d5 100644 --- a/examples/parody/gl_inet/body.go +++ b/examples/parody/gl_inet/body.go @@ -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, @@ -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), @@ -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 diff --git a/examples/parody/gl_inet/lid.go b/examples/parody/gl_inet/lid.go new file mode 100644 index 0000000..c0328a0 --- /dev/null +++ b/examples/parody/gl_inet/lid.go @@ -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} +} diff --git a/examples/parody/gl_inet/main.go b/examples/parody/gl_inet/main.go index 740a026..f868ada 100644 --- a/examples/parody/gl_inet/main.go +++ b/examples/parody/gl_inet/main.go @@ -9,7 +9,9 @@ import ( ) func main() { - body := InetBody() + body := InetBody(true) + + lid, lidCutout := LidAndCutout() jack := EthernetJackSolid() min, max := jack.Min(), jack.Max() @@ -38,6 +40,7 @@ func main() { jackHole, usbPort, fanHole, + lidCutout, }, }, usbInner, @@ -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),