-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatatypes_test.go
94 lines (81 loc) · 1.79 KB
/
datatypes_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import "testing"
func TestVertices(t *testing.T) {
in := `
Metasequoia Document
Format Text Ver 1.0
unknown {
Object {
vertex 1 {
-1 -1 -1
}
}
}
Material 1 {
"texture1" power(5.00) tex("somefile.bmp")
}
Object "bone:Bone" {
vertex 5 {
0.0000 1 02
3.14 4.0 5.0
6 7 8
9 10 11
12 13 14
}
face 2 {
2 V(0 1)
3 V(2 3 4) M(1) UV(0.0 1.0 0.5 0.5 0.25 0.25)
}
}
`
scene := Scene{}
if err := scene.Parse([]byte(in)); err != nil {
t.Error(err)
return
}
v := scene.Objects[0].Vertices[0]
if v.X != 0 || v.Y != 1 || v.Z != 2 {
t.Error("Got vertex", v)
t.Error("Expected 0, 1, 2")
return
}
v = scene.Objects[0].Vertices[1]
if v.X != 3.14 || v.Y != 4 || v.Z != 5 {
t.Error("Got vertex", v)
t.Error("Expected 3.14, 4, 5")
return
}
f := scene.Objects[0].Faces[0]
if f.VertexIndices[0] != 0 || f.VertexIndices[1] != 1 || f.VertexIndices[2] >= 0 || f.VertexIndices[3] >= 0 {
t.Error("Got face", f)
t.Error("Expected 0, 1")
return
}
f = scene.Objects[0].Faces[1]
if f.VertexIndices[0] != 2 || f.VertexIndices[1] != 3 || f.VertexIndices[2] != 4 || f.VertexIndices[3] >= 0 {
t.Error("Got face", f)
t.Error("Expected 2, 3, 4")
return
}
if f.TextureCoordinates[0] != 0.0 ||
f.TextureCoordinates[1] != 1.0 ||
f.TextureCoordinates[2] != 0.5 ||
f.TextureCoordinates[3] != 0.5 ||
f.TextureCoordinates[4] != 0.25 ||
f.TextureCoordinates[5] != 0.25 {
t.Error("Bad texture coordinates,", f.TextureCoordinates)
t.Error("Expected 0.0 1.0 0.5 0.5 0.25 0.25")
return
}
m := scene.Materials[0]
if m.Name != "texture1" {
t.Error("Texture name is", m.Name)
t.Error("Expected texture1")
return
}
if m.TextureMappingFile != "somefile.bmp" {
t.Error("TextureMappingFile is", m.TextureMappingFile)
t.Error("Expected somefile.bmp")
return
}
}