Skip to content

Commit

Permalink
gopher: body and eyes
Browse files Browse the repository at this point in the history
  • Loading branch information
unixpickle committed Feb 17, 2024
1 parent 1dddad1 commit 8427262
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/decoration/gopher/body.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"github.com/unixpickle/model3d/model3d"
"github.com/unixpickle/model3d/render3d"
"github.com/unixpickle/model3d/toolbox3d"
)

var BodyColor = render3d.NewColorRGB(0x73/255.0, 0xce/255.0, 0xdd/255.0)

func Body() (model3d.Solid, toolbox3d.CoordColorFunc) {
c1 := &model3d.Sphere{
Center: model3d.Z(0.5),
Radius: 0.15,
}
c2 := &model3d.Sphere{
Center: model3d.Z(1.5),
Radius: 0.1,
}
solid := model3d.MetaballSolid(nil, 0.82, c1, c2)
squishedSolid := model3d.TransformSolid(
&model3d.VecScale{Scale: model3d.XYZ(1.0, 0.7, 1.0)},
solid,
)
return squishedSolid, toolbox3d.ConstantCoordColorFunc(BodyColor)
}
43 changes: 43 additions & 0 deletions examples/decoration/gopher/eyes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"math"

"github.com/unixpickle/model3d/model2d"
"github.com/unixpickle/model3d/model3d"
"github.com/unixpickle/model3d/render3d"
"github.com/unixpickle/model3d/toolbox3d"
)

func Eyes() (model3d.Solid, toolbox3d.CoordColorFunc) {
ball := model3d.TranslateSolid(
model3d.RotateSolid(
model3d.VecScaleSolid(
&model3d.Sphere{Radius: 0.3},
model3d.XYZ(1.0, 0.3, 1.0),
),
model3d.X(1),
0.2,
),
model3d.YZ(0.6, 1.7),
)
combined := model3d.JoinedSolid{
model3d.TranslateSolid(
model3d.RotateSolid(ball, model3d.Z(1), 0.3),
model3d.X(-0.2),
),
model3d.TranslateSolid(
model3d.RotateSolid(ball, model3d.Z(1), -0.3),
model3d.X(0.2),
),
}
return combined, func(c model3d.Coord3D) render3d.Color {
c.X = math.Min(math.Abs(c.X-0.5), math.Abs(c.X+0.3))
dist := c.XZ().Dist(model2d.Y(1.7))
if dist < 0.1 {
return render3d.NewColor(0)
} else {
return render3d.NewColor(1.0)
}
}
}
21 changes: 21 additions & 0 deletions examples/decoration/gopher/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"github.com/unixpickle/model3d/model3d"
"github.com/unixpickle/model3d/render3d"
"github.com/unixpickle/model3d/toolbox3d"
)

func main() {
body, bodyColor := Body()
eyes, eyesColor := Eyes()
solid := model3d.JoinedSolid{body, eyes}
mesh, points := model3d.MarchingCubesInterior(solid, 0.02, 8)
cf := toolbox3d.JoinedSolidCoordColorFunc(
points,
body, bodyColor,
eyes, eyesColor,
)
render3d.SaveRotatingGIF("rendering.gif", mesh, model3d.Z(1), model3d.Y(-1), 300, 20, 5.0, cf.RenderColor)
render3d.SaveRandomGrid("rendering.png", mesh, 3, 3, 300, cf.RenderColor)
}

0 comments on commit 8427262

Please sign in to comment.