forked from EliCDavis/polyform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (65 loc) · 1.59 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"image/color"
"github.com/EliCDavis/polyform/formats/obj"
"github.com/EliCDavis/polyform/modeling"
"github.com/EliCDavis/polyform/modeling/meshops"
"github.com/EliCDavis/polyform/modeling/primitives"
"github.com/EliCDavis/polyform/rendering"
"github.com/EliCDavis/polyform/rendering/materials"
"github.com/EliCDavis/vector/vector3"
)
func plumbob() modeling.Mesh {
return primitives.
UVSphere(1, 2, 8).
Transform(
meshops.ScaleAttribute3DTransformer{
Amount: vector3.New(1., 2., 1.),
},
meshops.UnweldTransformer{},
meshops.FlatNormalsTransformer{},
).
SetMaterial(modeling.Material{
Name: "Plumbob",
DiffuseColor: color.RGBA{0, 255, 0, 255},
Transparency: .1,
SpecularHighlight: 50,
SpecularColor: color.RGBA{0, 255, 0, 255},
})
}
func render() {
jewelColor := vector3.New(0., 0.9, 0.4)
jewelMat := materials.NewDielectricWithColor(1.5, jewelColor)
scene := []rendering.Hittable{
rendering.NewMesh(
plumbob(),
jewelMat,
),
rendering.NewMesh(
plumbob().Transform(
meshops.ScaleAttribute3DTransformer{
Amount: vector3.Fill(0.9),
},
meshops.FlipTriangleWindingTransformer{},
),
jewelMat,
),
}
origin := vector3.New(2.1, 0.5, 2.1)
lookat := vector3.Zero[float64]()
camera := rendering.NewDefaultCamera(1, origin, lookat, 0, 0)
err := rendering.RenderToFile(50, 200, 500, scene, camera, "tmp/plumbob/preview.png", nil)
if err != nil {
panic(err)
}
}
func main() {
err := obj.Save(
"tmp/plumbob/plumbob.obj",
plumbob(),
)
if err != nil {
panic(err)
}
render()
}