diff --git a/examples/decoration/gopher/ears.go b/examples/decoration/gopher/ears.go new file mode 100644 index 0000000..bdad243 --- /dev/null +++ b/examples/decoration/gopher/ears.go @@ -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 + } + } +} diff --git a/examples/decoration/gopher/main.go b/examples/decoration/gopher/main.go index d78a59b..99ad4e7 100644 --- a/examples/decoration/gopher/main.go +++ b/examples/decoration/gopher/main.go @@ -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) diff --git a/examples/decoration/gopher/nose.go b/examples/decoration/gopher/nose.go new file mode 100644 index 0000000..edb2df4 --- /dev/null +++ b/examples/decoration/gopher/nose.go @@ -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 + } + } +} diff --git a/examples/decoration/gopher/teeth.go b/examples/decoration/gopher/teeth.go new file mode 100644 index 0000000..0fa4e86 --- /dev/null +++ b/examples/decoration/gopher/teeth.go @@ -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)) +}