-
Notifications
You must be signed in to change notification settings - Fork 24
/
test.go
62 lines (51 loc) · 1.22 KB
/
test.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
package main
import (
"log"
. "github.com/fogleman/fauxgl"
"github.com/fogleman/ribbon"
"github.com/nfnt/resize"
)
const (
scale = 1
width = 4000 * 1
height = 1000 * 1
fovy = 8
near = 1
far = 10
)
var (
eye = V(0, 2, 4)
center = V(0, 0, 0)
up = V(0, 1, 0).Normalize()
light = V(0.25, 0.25, 0.75).Normalize()
)
func main() {
model, err := ribbon.LoadPDB("examples/test.pdb")
if err != nil {
log.Fatal(err)
}
mesh := NewEmptyMesh()
for _, c := range model.Chains {
m := c.Mesh()
mesh.Add(m)
}
mesh.BiUnitCube()
// mesh.SmoothNormalsThreshold(Radians(75))
mesh.SaveSTL("out.stl")
// create a rendering context
context := NewContext(width*scale, height*scale)
context.ClearColorBufferWith(HexColor("1D181F"))
// create transformation matrix and light direction
aspect := float64(width) / float64(height)
matrix := LookAt(eye, center, up).Perspective(fovy, aspect, near, far)
// render
shader := NewPhongShader(matrix, light, eye)
shader.AmbientColor = Gray(0.3)
shader.DiffuseColor = Gray(0.9)
context.Shader = shader
context.DrawTriangles(mesh.Triangles)
// save image
image := context.Image()
image = resize.Resize(width, height, image, resize.Bilinear)
SavePNG("out.png", image)
}