Skip to content

Commit 01f78a9

Browse files
committed
create showcase for many different models!
This will end up in the README, in higher resolution of course.
1 parent 1c192da commit 01f78a9

24 files changed

+420
-6
lines changed

examples/decoration/curvy_thing/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ func main() {
3232
},
3333
}
3434
log.Println("Creating mesh...")
35-
mesh := model3d.MarchingCubesSearch(solid, 0.01, 8)
35+
mesh := model3d.MarchingCubesSearch(solid, 0.03, 8)
36+
mesh = mesh.EliminateCoplanar(1e-8)
3637

3738
log.Println("Saving results...")
3839
mesh.SaveGroupedSTL("curvy_thing.stl")
7.04 KB
Loading

examples/decoration/pumpkin/main.go

+45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"log"
67
"math"
@@ -37,10 +38,54 @@ func main() {
3738
return [3]float64{79.0 / 255, 53.0 / 255, 0}
3839
}
3940

41+
outsideMesh := model3d.NewMesh()
42+
insideMesh := model3d.NewMesh()
43+
stemMesh := model3d.NewMesh()
44+
4045
log.Println("Creating mesh...")
4146
mesh := model3d.MarchingCubesSearch(base, 0.02, 8)
4247
mesh.AddMesh(model3d.MarchingCubesSearch(lid, 0.02, 8))
4348

49+
fmt.Println(mesh.Min(), mesh.Max())
50+
51+
dec := &model3d.Decimator{
52+
FeatureAngle: 0.1,
53+
PlaneDistance: 4e-4,
54+
BoundaryDistance: 1e-5,
55+
MinimumAspectRatio: 0.01,
56+
}
57+
fmt.Println("before", len(mesh.TriangleSlice()))
58+
mesh = dec.Decimate(mesh)
59+
fmt.Println("after", len(mesh.TriangleSlice()))
60+
61+
mesh.Iterate(func(t *model3d.Triangle) {
62+
c := t[0]
63+
if (PumpkinSolid{Scale: 1.025}).Contains(c) {
64+
expectedNormal := t[0].Geo().Coord3D()
65+
if math.Abs(expectedNormal.Dot(t.Normal())) > 0.5 {
66+
outsideMesh.Add(t)
67+
} else {
68+
insideMesh.Add(t)
69+
}
70+
} else {
71+
stemMesh.Add(t)
72+
}
73+
})
74+
75+
mat := model3d.NewMatrix3Rotation(
76+
model3d.Coord3D{X: 1}, math.Pi/2,
77+
)
78+
mat = model3d.NewMatrix3Rotation(
79+
model3d.Coord3D{Z: 1}, -math.Pi/2,
80+
).Mul(mat)
81+
outsideMesh = outsideMesh.MapCoords(mat.MulColumn)
82+
insideMesh = insideMesh.MapCoords(mat.MulColumn)
83+
stemMesh = stemMesh.MapCoords(mat.MulColumn)
84+
85+
outsideMesh.SaveGroupedSTL("pumpkin_outside.stl")
86+
insideMesh.SaveGroupedSTL("pumpkin_inside.stl")
87+
stemMesh.SaveGroupedSTL("pumpkin_stem.stl")
88+
4489
log.Println("Saving mesh...")
4590
ioutil.WriteFile("pumpkin.zip", mesh.EncodeMaterialOBJ(colorFunc), 0755)
4691

14.3 KB
Loading

examples/decoration/rock/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
const (
1414
AdditionSamples = 1000
1515
KeepSamples = 990
16-
GridSize = 3
16+
GridSize = 10
1717
)
1818

1919
func main() {
@@ -50,7 +50,7 @@ func main() {
5050
for i := 0; i < 100; i++ {
5151
rock = AddConstraint(rock)
5252
}
53-
min := model3d.Coord3D{X: float64(i) * 1.1, Y: float64(j) * 1.1, Z: 0}
53+
min := model3d.Coord3D{X: float64(i)*5.0 + rand.Float64()*4, Y: float64(j)*5.0 + rand.Float64()*4, Z: 0}
5454
mesh.AddMesh(rock.Mesh().MapCoords(min.Add))
5555
}
5656
}
-22.4 KB
Loading

examples/decoration/rose/main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ func main() {
2424
}
2525
collider := model3d.MeshToCollider(m)
2626
solid := model3d.NewColliderSolidHollow(collider, 0.1)
27-
m1 := model3d.MarchingCubesSearch(solid, 0.01, 8).Blur(-1)
27+
m1 := model3d.MarchingCubesSearch(solid, 0.02, 8)
28+
dec := &model3d.Decimator{
29+
FeatureAngle: 0.1,
30+
PlaneDistance: 4e-4,
31+
BoundaryDistance: 1e-5,
32+
MinimumAspectRatio: 0.01,
33+
}
34+
m1 = dec.Decimate(m1)
2835
m1.SaveGroupedSTL("rose.stl")
2936

3037
log.Println("Generating rendering...")
-7.2 KB
Loading

examples/decoration/vase/main.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"math"
67

@@ -32,11 +33,21 @@ func main() {
3233
Ratio: 0.5,
3334
}
3435

35-
mesh := model3d.MarchingCubesSearch(model3d.TransformSolid(ax, VaseSolid{}), 0.015, 8)
36+
mesh := model3d.MarchingCubesSearch(model3d.TransformSolid(ax, VaseSolid{}), 0.02, 8)
3637
mesh = mesh.MapCoords(ax.Inverse().Apply)
3738

39+
dec := &model3d.Decimator{
40+
FeatureAngle: 0.1,
41+
PlaneDistance: 4e-4,
42+
BoundaryDistance: 1e-5,
43+
MinimumAspectRatio: 0.01,
44+
}
45+
fmt.Println("before", len(mesh.TriangleSlice()))
46+
mesh = dec.Decimate(mesh)
47+
fmt.Println("after", len(mesh.TriangleSlice()))
48+
3849
log.Println("Flattening base...")
39-
mesh = mesh.FlattenBase(0)
50+
//mesh = mesh.FlattenBase(0)
4051

4152
log.Println("Saving STL...")
4253
mesh.SaveGroupedSTL("vase.stl")
11.1 KB
Loading
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# showcase
2+
3+
This example renders a bunch of different 3D models created by various `model3d` examples. It is meant to produce a sort of "banner ad" for `model3d` as a whole.
4+
5+
Included are:
6+
7+
* Wine glass - `examples/parody/place_setting`
8+
* Pumpkin - `examples/decoration/pumpkin`
9+
* Curvy thing - `examples/decoration/curvy_thing`
10+
* Vase - `examples/decoration/vase`
11+
* Rose - `examples/decoration/rose`
12+
* Rocks - `examples/decoration/rock`
13+
14+
The result looks like this:
15+
16+
![Output](output.png)
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import "github.com/unixpickle/model3d"
4+
5+
var LightDirection = model3d.Coord3D{X: 2, Y: -3, Z: 3}.Normalize()
6+
7+
const (
8+
CameraY = -5
9+
CameraZ = 4
10+
11+
WineGlassX = -6.5
12+
WineGlassY = 9.0
13+
14+
PumpkinX = -2
15+
PumpkinY = 10
16+
17+
RocksY = 15.0
18+
19+
VaseX = 5
20+
VaseY = 11
21+
RoseX = VaseX
22+
RoseY = VaseY
23+
RoseZ = 7
24+
RoseStemRadius = 0.15
25+
26+
CurvyThingX = 1.8
27+
CurvyThingY = 9.0
28+
29+
RoomRadius = 100.0
30+
)

examples/renderings/showcase/main.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"math"
6+
7+
"github.com/unixpickle/model3d/render3d"
8+
9+
"github.com/unixpickle/model3d"
10+
)
11+
12+
func main() {
13+
scene := render3d.JoinedObject{
14+
NewFloorObject(),
15+
NewDomeObject(),
16+
ReadVase(),
17+
ReadRose(),
18+
ReadWineGlass(),
19+
ReadPumpkin(),
20+
ReadRocks(),
21+
ReadCurvyThing(),
22+
}
23+
24+
RenderScene(scene)
25+
}
26+
27+
func RenderScene(scene render3d.Object) {
28+
renderer := render3d.RecursiveRayTracer{
29+
Camera: render3d.NewCameraAt(model3d.Coord3D{Y: CameraY, Z: CameraZ},
30+
model3d.Coord3D{Y: RoomRadius, Z: CameraZ}, math.Pi/3.6),
31+
32+
FocusPoints: []render3d.FocusPoint{
33+
&render3d.PhongFocusPoint{
34+
Target: LightDirection.Scale(RoomRadius),
35+
Alpha: 20.0,
36+
MaterialFilter: func(m render3d.Material) bool {
37+
switch m.(type) {
38+
case *render3d.PhongMaterial:
39+
return true
40+
case *render3d.LambertMaterial:
41+
return true
42+
}
43+
return false
44+
},
45+
},
46+
},
47+
FocusPointProbs: []float64{0.3},
48+
49+
MaxDepth: 10,
50+
NumSamples: 100,
51+
Antialias: 1.0,
52+
Cutoff: 1e-4,
53+
54+
LogFunc: func(p, samples float64) {
55+
fmt.Printf("\rRendering %.1f%%...", p*100)
56+
},
57+
}
58+
59+
fmt.Println("Variance:", renderer.RayVariance(scene, 200, 133, 2))
60+
61+
img := render3d.NewImage(480, 320)
62+
renderer.Render(img, scene)
63+
fmt.Println()
64+
img.Save("output.png")
65+
}

0 commit comments

Comments
 (0)