-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
164 lines (146 loc) · 4.57 KB
/
test.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
var context = require('gl-context')
var test = require('tape')
var allclose = require('test-allclose')
var icosphere = require('icosphere')
var createScene = require('./index')
var canvas = document.body.appendChild(document.createElement('canvas'))
var gl = context(canvas)
test('construction', function (t) {
var scene = createScene(gl)
t.ok(scene, 'scene constructed')
t.end()
})
test('initialization', function (t) {
var scene = createScene(gl)
scene.shapes([{complex: icosphere(2)}])
t.notOk(scene.ready, 'scene uninitialized')
scene.init()
t.ok(scene.ready, 'scene initialized')
t.end()
})
test('construction defaults', function (t) {
var scene = createScene(gl)
allclose(t)(scene.target, [0, 0, 0])
allclose(t)(scene.observer, [0, -10, 30])
t.equals(scene.near, 0.01)
t.equals(scene.far, 1000)
t.end()
})
test('construction options', function (t) {
var scene = createScene(gl, {
background: [0, 0, 0],
target: [5, 5, 5],
observer: [10, 10, 10],
near: 0,
far: 100
})
allclose(t)(scene.target, [5, 5, 5])
allclose(t)(scene.observer, [10, 10, 10])
allclose(t)(scene.background, [0, 0, 0])
t.equals(scene.near, 0)
t.equals(scene.far, 100)
t.end()
})
test('add one shape', function (t) {
var scene = createScene(gl)
scene.shapes([{complex: icosphere(2)}])
t.equals(scene._shapes.length, 1)
t.end()
})
test('add many shapes', function (t) {
var scene = createScene(gl)
scene.shapes([{complex: icosphere(2)}, {complex: icosphere(2)}])
t.equals(scene._shapes.length, 2)
t.end()
})
test('add one light', function (t) {
var scene = createScene(gl)
scene.lights([{position: [0, 0, 0]}])
t.equals(scene._lights.length, 1)
t.end()
})
test('add many light', function (t) {
var scene = createScene(gl)
scene.lights([{position: [0, 0, 0]}, {position: [0, 0, 0]}])
t.equals(scene._lights.length, 2)
t.end()
})
test('add shapes and lights', function (t) {
var scene = createScene(gl)
scene.shapes([{complex: icosphere(2)}, {complex: icosphere(2)}])
scene.lights([{position: [0, 0, 0]}, {position: [0, 0, 0]}])
t.equals(scene._shapes.length, 2)
t.equals(scene._lights.length, 2)
t.end()
})
test('custom material', function (t) {
var scene = createScene(gl)
var normal = require('gl-normal-material')
scene.shapes([{material: 'normal', complex: icosphere(2)}])
scene.materials({normal: normal})
scene.init()
t.ok(scene._materials.normal, 'material defined')
t.equal(scene._shapes[0].style.saturation, normal.styles.saturation.default)
t.equal(scene._shapes[0].style.absolute, normal.styles.absolute.default)
t.end()
})
test('draw', function (t) {
var scene = createScene(gl)
scene.shapes([{complex: icosphere(2)}])
scene.init()
t.equals(scene.frame, 0)
scene.draw()
t.equals(scene.frame, 1)
t.end()
})
test('default shape selectors', function (t) {
var scene = createScene(gl)
scene.shapes([{complex: icosphere(2)}])
t.equals(scene._shapes[0].id, 'shape-0')
t.equals(scene._shapes[0].className, '')
t.equals(scene.select('#shape-0').length, 1)
t.end()
})
test('default light selectors', function (t) {
var scene = createScene(gl)
scene.lights([{position: [0, 0, 0]}])
t.equals(scene._lights[0].id, 'light-0')
t.equals(scene._lights[0].className, '')
t.equals(scene.select('#light-0').length, 1)
t.end()
})
test('shape visibility', function (t) {
var scene = createScene(gl)
scene.shapes([{id: 'shape', complex: icosphere(2)}])
scene.init()
t.equals(scene._shapes[0].attributes.visible, true)
scene.select('#shape').hide()
t.equals(scene._shapes[0].attributes.visible, false)
scene.select('#shape').show()
t.equals(scene._shapes[0].attributes.visible, true)
scene.select('#shape').toggle()
t.equals(scene._shapes[0].attributes.visible, false)
t.end()
})
test('light visibility', function (t) {
var scene = createScene(gl)
scene.shapes([{id: 'shape', complex: icosphere(2)}])
scene.lights([{id: 'light', position: [0, 0, 0]}])
scene.init()
t.equals(scene._lights[0].attributes.visible, true)
scene.select('#light').hide()
t.equals(scene._lights[0].attributes.visible, false)
scene.select('#light').show()
t.equals(scene._lights[0].attributes.visible, true)
scene.select('#light').toggle()
t.equals(scene._lights[0].attributes.visible, false)
t.end()
})
test('add stylesheet', function (t) {
var scene = createScene(gl)
scene.shapes([{id: 'shape', complex: icosphere(2), material: 'normal'}])
scene.stylesheet({'#shape': {saturation: 0.5, absolute: false}})
scene.init()
t.deepEquals(scene._shapes[0].style, {saturation: 0.5, absolute: false})
t.end()
})