Skip to content

Commit

Permalink
gopher: ears, mouth and nose
Browse files Browse the repository at this point in the history
  • Loading branch information
unixpickle committed Feb 17, 2024
1 parent 8427262 commit 7068e98
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
45 changes: 45 additions & 0 deletions examples/decoration/gopher/ears.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

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

func Ears() (model3d.Solid, toolbox3d.CoordColorFunc) {
const tiltFactor = 0.99
earSolid := &model3d.Cylinder{
P1: model3d.XYZ(-0.8, 0.1, 2.0),
P2: model3d.XYZ(-0.8*tiltFactor, 0.2, 2.0*tiltFactor),
Radius: 0.2,
}
insideSolid := &model3d.Cylinder{
P1: model3d.XYZ(-0.8, 0.1, 2.0),
P2: model3d.XYZ(-0.8*tiltFactor, 0.2, 2.0*tiltFactor),
Radius: 0.1,
}
insideSolid.P1.Y -= 0.1
insideSolid.P2.Y += 0.1

otherEar := *earSolid
otherEar.P1.X *= -1
otherEar.P2.X *= -1
bothEars := model3d.JoinedSolid{
earSolid, &otherEar,
}

otherInside := *insideSolid
otherInside.P1.X *= -1
otherInside.P2.X *= -1
bothInside := model3d.JoinedSolid{
insideSolid, &otherInside,
}

return bothEars, func(c model3d.Coord3D) render3d.Color {
if bothInside.Contains(c) {
return render3d.NewColor(0)
} else {
return BodyColor
}
}
}
8 changes: 7 additions & 1 deletion examples/decoration/gopher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import (
func main() {
body, bodyColor := Body()
eyes, eyesColor := Eyes()
solid := model3d.JoinedSolid{body, eyes}
ears, earsColor := Ears()
nose, noseColor := Nose()
teeth, teethColor := Teeth()
solid := model3d.JoinedSolid{body, eyes, ears, nose, teeth}
mesh, points := model3d.MarchingCubesInterior(solid, 0.02, 8)
cf := toolbox3d.JoinedSolidCoordColorFunc(
points,
body, bodyColor,
eyes, eyesColor,
ears, earsColor,
nose, noseColor,
teeth, teethColor,
)
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)
Expand Down
32 changes: 32 additions & 0 deletions examples/decoration/gopher/nose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

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

var NoseColor = render3d.NewColorRGB(0xd9/255.0, 0xce/255.0, 0x98/255.0)

func Nose() (model3d.Solid, toolbox3d.CoordColorFunc) {
mound := &model3d.Torus{
Center: model3d.YZ(0.4, 1.0),
Axis: model3d.YZ(-0.5, 0.55).Normalize(),
InnerRadius: 0.15,
OuterRadius: 0.3,
}
dot := model3d.TranslateSolid(
model3d.VecScaleSolid(
&model3d.Sphere{Radius: 0.1},
model3d.XYZ(1.0, 1.0, 0.8),
),
model3d.YZ(0.7, 1.35),
)
return model3d.JoinedSolid{mound, dot}, func(c model3d.Coord3D) render3d.Color {
if dot.Contains(c) {
return render3d.NewColor(0)
} else {
return NoseColor
}
}
}
20 changes: 20 additions & 0 deletions examples/decoration/gopher/teeth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

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

func Teeth() (model3d.Solid, toolbox3d.CoordColorFunc) {
tooth := &model3d.Capsule{
P1: model3d.YZ(0.69, 1.15),
P2: model3d.YZ(0.69, 0.95),
Radius: 0.055,
}
teeth := model3d.JoinedSolid{
model3d.TranslateSolid(tooth, model3d.X(-0.055)),
model3d.TranslateSolid(tooth, model3d.X(0.055)),
}
return teeth, toolbox3d.ConstantCoordColorFunc(render3d.NewColor(1.0))
}

0 comments on commit 7068e98

Please sign in to comment.