-
Notifications
You must be signed in to change notification settings - Fork 1
/
bundle.js.map
119 lines (119 loc) · 582 KB
/
bundle.js.map
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
{
"version": 3,
"sources": [
"node_modules/browser-pack/_prelude.js",
"node_modules/gl-matrix/src/gl-matrix.js",
"node_modules/gl-matrix/src/gl-matrix/common.js",
"node_modules/gl-matrix/src/gl-matrix/mat2.js",
"node_modules/gl-matrix/src/gl-matrix/mat2d.js",
"node_modules/gl-matrix/src/gl-matrix/mat3.js",
"node_modules/gl-matrix/src/gl-matrix/mat4.js",
"node_modules/gl-matrix/src/gl-matrix/quat.js",
"node_modules/gl-matrix/src/gl-matrix/vec2.js",
"node_modules/gl-matrix/src/gl-matrix/vec3.js",
"node_modules/gl-matrix/src/gl-matrix/vec4.js",
"node_modules/regl/lib/attribute.js",
"node_modules/regl/lib/buffer.js",
"node_modules/regl/lib/constants/arraytypes.json",
"node_modules/regl/lib/constants/dtypes.json",
"node_modules/regl/lib/constants/primitives.json",
"node_modules/regl/lib/constants/usage.json",
"node_modules/regl/lib/core.js",
"node_modules/regl/lib/dynamic.js",
"node_modules/regl/lib/elements.js",
"node_modules/regl/lib/extension.js",
"node_modules/regl/lib/framebuffer.js",
"node_modules/regl/lib/limits.js",
"node_modules/regl/lib/read.js",
"node_modules/regl/lib/renderbuffer.js",
"node_modules/regl/lib/shader.js",
"node_modules/regl/lib/stats.js",
"node_modules/regl/lib/strings.js",
"node_modules/regl/lib/texture.js",
"node_modules/regl/lib/timer.js",
"node_modules/regl/lib/util/check.js",
"node_modules/regl/lib/util/clock.js",
"node_modules/regl/lib/util/codegen.js",
"node_modules/regl/lib/util/extend.js",
"node_modules/regl/lib/util/is-array-like.js",
"node_modules/regl/lib/util/is-ndarray.js",
"node_modules/regl/lib/util/is-typed-array.js",
"node_modules/regl/lib/util/loop.js",
"node_modules/regl/lib/util/pool.js",
"node_modules/regl/lib/util/raf.js",
"node_modules/regl/lib/util/to-half-float.js",
"node_modules/regl/lib/util/values.js",
"node_modules/regl/lib/webgl.js",
"node_modules/regl/regl.js",
"node_modules/resl/index.js",
"node_modules/webgl-obj-loader/webgl-obj-loader.js",
"src/camera.js",
"src/entity.js",
"src/index.js",
"src/picker.js",
"src/projection.js",
"src/ray.js",
"src/screen.js",
"src/shader.js"
],
"names": [],
"mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1uBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxlEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxlBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC3kBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjmBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvXA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACZA;AACA;AACA;AACA;AACA;AACA;;ACLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9wGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzRA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACh3BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/hDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC7nBA;AACA;AACA;AACA;AACA;AACA;;ACLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACPA;AACA;AACA;AACA;AACA;;ACJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACbA;AACA;AACA;AACA;AACA;;ACJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5CA;AACA;AACA;AACA;;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5MA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACleA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACraA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;YCxXA,IAAM,KAAM,QAAQ,aAEhB,UAAa,EAAG,EAAG,EAAG,EAAG,EAAG,GAC5B,UAAa,EAAG,EAAG,EAAG,EAAG,EAAG,GAE1B,YAAc,SAAC,GAAD,MAAS,IAAY,SAAS,EAAG,SAAS,EAAG,SAAS,GAA3C,UACzB,YAAc,SAAC,EAAG,EAAG,GAAP,MAAa,WAAa,EAAA,EAAG,EAAA,EAAG,EAAA,IAE9C,YAAc,WAAA,MAAM,WACpB,YAAc,SAAC,EAAG,EAAG,GAAP,MAAa,WAAa,EAAA,EAAG,EAAA,EAAG,EAAA,IAE9C,KAAO,SAAC,EAAG,EAAG,GAClB,GAAI,GAAK,EAAG,EAAK,EAAG,EAAK,CAEd,KAAP,IAAU,GAAM,GACT,IAAP,IAAU,GAAM,GACT,IAAP,IAAU,GAAM,EAEpB,IAAI,GAAW,KAAK,KAAK,KAAK,IAAI,EAAI,GAAK,KAAK,IAAI,EAAI,GAAK,KAAK,IAAI,EAAI,KAAO,CAEjF,UAAS,GAAK,EAAK,EAAW,EAC9B,SAAS,GAAK,EAAK,EAAW,EAC9B,SAAS,GAAK,EAAK,EAAW,GAG1B,OAAS,SAAC,EAAG,EAAG,GACpB,SAAS,GAAK,EACd,SAAS,GAAK,EACd,SAAS,GAAK,GAGV,WAAa,WACjB,GAAI,GAAS,GAAI,cAAa,GAM9B,OALA,KAAI,KAAK,SAAS,GAClB,IAAI,KAAK,OAAO,EAAQ,EAAQ,IAAI,SAAS,SAAS,cAAc,IAAK,EAAG,EAAG,IAC/E,IAAI,KAAK,OAAO,EAAQ,EAAQ,IAAI,SAAS,SAAS,cAAc,IAAK,EAAG,EAAG,IAC/E,IAAI,KAAK,OAAO,EAAQ,EAAQ,IAAI,SAAS,SAAS,cAAc,IAAK,EAAG,EAAG,IAC/E,IAAI,KAAK,UAAU,EAAQ,IAAU,cAAc,GAAI,cAAc,GAAI,cAAc,IAChF,EAGT,QAAO,SAAW,YAAA,YAAa,YAAA,YAAa,YAAA,YAAa,YAAA,YAAa,KAAA,KAAM,OAAA,OAAQ,WAAA;;;YCzCpF,IAAM,KAAM,QAAQ,aACd,IAAM,QAAQ,kBAEpB,QAAO,QAAU,SAAC,GAAD,MAAU,UAAC,EAAM,EAAQ,EAAS,EAAQ,EAAU,EAAU,GAC7E,GAAI,IAAS,EAAG,EAAG,EAAG,GAClB,GAAU,EAAG,GAEX,EAAgB,WAEpB,IAAK,GADD,MACK,EAAI,EAAG,EAAI,EAAK,SAAS,OAAQ,IACpC,EAAI,IAAM,EACZ,EAAI,KAAK,EAAK,SAAS,IAEvB,EAAI,KAAK,EAAI,EAAK,SAAS,GAG/B,OAAO,IAGH,EAAc,WAAA,MAAM,IACpB,EAAc,SAAC,EAAG,EAAG,GAAP,MAAa,IAAa,EAAA,EAAG,EAAA,EAAG,EAAA,IAE9C,EAAW,WAAA,MAAM,IACjB,EAAW,SAAC,EAAG,EAAG,EAAG,GAAV,MAAgB,IAAS,EAAG,EAAG,EAAG,IAE7C,EAAa,WAAA,MAAM,IAGnB,EAAY,WAAA,MAAM,IAClB,EAAY,SAAC,EAAG,GAAJ,MAAU,IAAU,EAAG,IAEnC,EAAe,WACnB,GAAI,GAAS,GAAI,cAAa,GAO9B,OANA,KAAI,KAAK,SAAS,GAClB,IAAI,KAAK,UAAU,EAAQ,GAAS,EAAS,EAAG,EAAS,EAAG,EAAS,IACrE,IAAI,KAAK,OAAO,EAAQ,EAAQ,IAAI,SAAS,SAAS,EAAS,IAAK,EAAG,EAAG,IAC1E,IAAI,KAAK,OAAO,EAAQ,EAAQ,IAAI,SAAS,SAAS,EAAS,IAAK,EAAG,EAAG,IAC1E,IAAI,KAAK,OAAO,EAAQ,EAAQ,IAAI,SAAS,SAAS,EAAS,IAAK,EAAG,EAAG,IAC1E,IAAI,KAAK,MAAM,EAAQ,GAAS,EAAO,EAAO,IACvC,GAGH,EAAO,GACX,KAAM,EAAO,SACb,KAAM,EAAO,OACb,YACE,SAAU,EAAK,SACf,GAAI,GAEN,SAAU,EAAK,QACf,UACE,UAAW,EACX,KAAM,EAAO,WACb,WAAY,WACZ,cAAe,GAAI,GAAI,IACvB,WAAY,EAAG,EAAG,GAClB,aAAc,GAAI,GAAI,GACtB,aAAc,EACd,gBAAiB,EACjB,QAAS,EACT,MAAO,EACP,OAAQ,GAEV,MACE,QAAQ,EACR,KAAM,SAGV,QAAS,YAAA,EAAa,YAAA,EAAa,SAAA,EAAU,SAAA,EAAU,UAAA,EAAW,UAAA,EAAW,KAAA;;;sJCpE/E,OAAO,KAAe,QAAQ,UAC9B,OAAO,IAAe,QAAQ,aAC9B,OAAO,IAAe,QAAQ,oBAG9B,OAAO,OAAe,QAAQ,eAC9B,OAAO,WAAe,QAAQ,mBAC9B,OAAO,OAAe,QAAQ,eAC9B,OAAO,IAAe,QAAQ,YAC9B,OAAO,OAAe,QAAQ,eAC9B,OAAO,aAAe,QAAQ,eAAe,MAC7C,OAAO,aAAe,QAAQ,cAgB9B,KAAK,GAdC,OAAS,GACT,OAAS,EACT,OAAS,GAET,OAAM,OAAA,mBAAI,MAAM,SAAQ,IAAI,SAAA,GAAA,SAAK,OAAA,mBAAI,MAAM,UAAS,IAAK,SAAA,GAAA,MAAK,OAAM,YAEtE,KAAO,GAEP,OAAA,OAEA,UACA,WACA,YAEK,EAAI,EAAG,EAAI,MAAO,IACzB,IAAK,GAAI,GAAI,EAAG,EAAI,OAAQ,IAC1B,IAAK,GAAI,GAAI,EAAG,EAAI,OAAQ,IAAK,CAC/B,GAAI,MAAO,CAED,KAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAEhC,IAAN,GAAiB,IAAN,GAAiB,IAAN,IAAS,KAAO,GAE1C,IAAI,GAAG,GAAG,GAAK,KAKrB,QAAQ,SACN,UACE,OACE,KAAM,QACN,IAAK,qBACL,OAAQ,SAAC,GAAD,MAAU,MAAK,SACrB,KAAM,EACN,IAAK,SACL,IAAK,SACL,MAAO,SACP,MAAO,aAGX,SACC,KAAM,OACN,IAAK,kBACL,OAAQ,SAAC,GAAD,MAAU,IAAI,KAAI,KAAK,KAEhC,cACE,KAAM,OACN,IAAK,sBACL,OAAQ,SAAC,GAAD,MAAU,cAAa,KAEjC,SACE,KAAM,OACN,IAAK,kBACL,OAAQ,SAAC,GAAD,MAAU,IAAI,KAAI,KAAK,KAEjC,SACE,KAAM,QACN,IAAK,oBACL,OAAQ,SAAC,GAAD,MAAU,MAAK,SACrB,KAAM,EACN,IAAK,SACL,IAAK,aAGT,UACE,KAAM,OACN,IAAK,mBACL,OAAQ,SAAC,GAAD,MAAU,IAAI,KAAI,KAAK,KAEjC,UACE,KAAM,QACN,IAAK,mBACL,OAAQ,SAAC,GAAD,MAAU,MAAK,SACrB,KAAM,EACN,IAAK,SACL,IAAK,SACL,MAAO,SACP,MAAO,aAGX,SACE,KAAM,OACN,IAAK,kBACL,OAAQ,SAAC,GAAD,MAAU,IAAI,KAAI,KAAK,KAEjC,SACE,KAAM,QACN,IAAK,oBACL,OAAQ,SAAC,GAAD,MAAU,MAAK,SACrB,KAAM,EACN,IAAK,SACL,IAAK,cAIX,OAAQ,SAAA,GAA4F,GAA1F,GAA0F,EAA1F,MAAO,EAAmF,EAAnF,QAAS,EAA0E,EAA1E,aAAc,EAA4D,EAA5D,SAAU,EAAkD,EAAlD,SAAU,EAAwC,EAAxC,QAAS,EAA+B,EAA/B,QAAS,EAAsB,EAAtB,QAAS,EAAa,EAAb,OACrF,QAAO,YAEP,UAAY,EACZ,YAAc,EACd,WAAa,EAEb,OAAO,YAAY,MAAQ,EAAG,EAAY,EAAT,QACjC,OAAO,YAAY,GAAI,EAAG,EAGxB,IAAM,IAAa,EAAG,MAAQ,EAAG,EAAG,GAAI,EAAG,OAAS,GAC9C,GAAa,EAAG,EAAG,EAAG,EAAG,EAAG,GAC5B,EAAQ,GACR,EAAQ,aAAa,EAAU,EAAc,EAAU,OAAQ,EAAU,EAAU,EACzF,GAAM,UAAU,EAAG,GACnB,SAAS,KAAK,EAId,IAAM,IAAa,EAAG,EAAG,EAAG,EAAG,EAAG,IAC5B,GAAa,EAAG,EAAG,EAAG,EAAG,EAAG,GAC5B,EAAQ,CACd,QAAS,aAAa,EAAS,EAAc,EAAS,OAAQ,EAAU,EAAU,GAClF,OAAO,SAAS,IAAK,EAAG,EAAG,IAC3B,SAAS,KAAK,OAGhB,KAAK,GAAI,GAAI,EAAG,EAAI,MAAO,IACzB,IAAK,GAAI,GAAI,EAAG,EAAI,OAAQ,IAC1B,IAAK,GAAI,GAAI,EAAG,EAAI,OAAQ,IAAK,CAC/B,GAAI,GAAO,IAAI,GAAG,GAAG,EACrB,IAAI,EAAO,EAAG,CACZ,GAAI,GAAQ,EACR,EAAS,EACT,EAAU,EACV,EAAQ,EACN,GAAa,EAAG,EAAG,EAAG,EAAG,EAAG,GAC5B,GAAa,EAAG,EAAG,EAAG,EAAG,EAAG,EAErB,KAAT,IACF,EAAQ,EACR,EAAU,EACV,EAAS,GAAK,GACd,EAAQ,IAGG,IAAT,IACF,EAAQ,EACR,EAAU,EACV,EAAS,GAAK,GAGhB,IAAI,GAAS,aAAa,EAAO,EAAQ,EAAS,OAAQ,EAAU,EAAU,EAC9E,UAAS,KAAK,IAMtB,KAAK,MAAM,WACT,KAAK,OACH,OAAQ,GAAI,GAAI,GAAI,KACpB,MAAO,GAIP,IAAI,GAAW,OAAO,cAElB,GAAU,EAAG,EAAG,EAAG,EAAG,EAAG,EAEzB,QAAO,aAAa,gBAAgB,EAAM,GAAK,KAC/C,OAAO,aAAa,eAAgB,EAAM,GAAK,KAC/C,OAAO,aAAa,WAAgB,EAAM,GAAK,KAC/C,OAAO,aAAa,eAAgB,EAAM,GAAK,KAC/C,OAAO,aAAa,gBAAgB,EAAM,GAAK,KAC/C,OAAO,aAAa,aAAgB,EAAM,GAAK,KAC/C,OAAO,aAAa,eAAgB,EAAM,GAAK,IAEnD,IAAI,IAAa,EAAG,EAAG,EAAG,EAAG,EAAG,EAEhC,GAAS,GAAK,EAAM,EAAI,KAAK,IAAI,IAAI,SAAS,SAAS,EAAS,EAAI,KACpE,EAAS,GAAK,EAAM,EAAI,KAAK,IAAI,IAAI,SAAS,SAAS,EAAS,EAAI,KAEpE,EAAS,EAAI,EAAM,EAEnB,EAAS,GAAK,EAAM,EAAI,KAAK,IAAI,IAAI,SAAS,SAAS,EAAS,IAChE,EAAS,GAAK,EAAM,EAAI,KAAK,IAAI,IAAI,SAAS,SAAS,EAAS,IAEhE,OAAO,KAAK,EAAS,EAAG,EAAS,EAAG,EAAS,EAI7C,IAAI,GAAU,OAAO,WAAa,EAC9B,EAAU,OAAO,YAAc,EAE/B,GACF,OAAO,cAAc,EACrB,OAAO,cAAc,EACrB,OAAO,cAAc,GAGnB,EAAW,OAAO,iBAAiB,EAAQ,EAAS,EAAS,IAE7D,GACF,EAAG,KAAK,MAAM,EAAS,YAAY,GAAK,EAAS,SAAS,MAAM,IAChE,EAAG,KAAK,MAAM,EAAS,YAAY,GAAK,EAAS,SAAS,MAAM,IAChE,EAAG,KAAK,MAAM,EAAS,YAAY,GAAK,EAAS,SAAS,MAAM,IAGlE,QAAO,YAAY,EAAI,EAAG,EAAI,EAAG,EAAI,EAGvC,KAAK,GAAI,GAAI,EAAG,EAAI,SAAS,OAAQ,IACnC,SAAS,GAAG,YAMpB,OAAO,YAAY,SAAC,GAClB,OAAO,OAAyB,GAAlB,EAAM,UAAmC,GAAlB,EAAM,UAAiB,KAG9D,OAAO,QAAQ,SAAC,GACd,MAAuB,IAAf,EAAM,OACV,KAAO,IAAG,KAAO,GACjB,KAAO,KAAI,KAAO,MAGxB,OAAO,QAAQ,SAAC,GAEd,GAAI,GAAU,OAAO,WAAa,EAC9B,EAAU,OAAO,YAAc,EAE/B,GACF,OAAO,cAAc,EACrB,OAAO,cAAc,EACrB,OAAO,cAAc,GAGnB,EAAW,OAAO,iBAAiB,EAAQ,EAAS,EAAS,IAE7D,GACF,EAAG,KAAK,MAAM,EAAS,YAAY,GAAK,EAAS,SAAS,MAAM,IAChE,EAAG,KAAK,MAAM,EAAS,YAAY,GAAK,EAAS,SAAS,MAAM,IAChE,EAAG,KAAK,MAAM,EAAS,YAAY,GAAK,EAAS,SAAS,MAAM,KAI5D,GAAa,EAAG,EAAG,EAAG,EAAG,EAAG,GAC9B,EAAQ,EACR,EAAS,aAAa,UAAW,WAAY,YAAa,OAAQ,EAAK,EAAU,EACrF,UAAS,KAAK;;;YCpRhB,IAAM,KAAM,QAAQ,aACd,IAAM,QAAQ,YAEd,yBAA2B,SAAC,EAAG,GACnC,GAAI,GAAI,OAAO,WACX,EAAI,OAAO,YACX,EAAyB,IAAI,KAAK,QAItC,OAHA,GAAuB,GAAK,EAAI,EAAI,EAAI,EACxC,EAAuB,GAAK,EAAI,EAAI,EAAI,EACxC,EAAuB,IAAK,EACrB,GAGH,YAAc,SAAC,GACnB,GAAI,GAAa,IAAI,KAAK,QAK1B,OAJA,GAAW,GAAK,EAAuB,GACvC,EAAW,GAAK,EAAuB,GACvC,EAAW,GAAK,EAAuB,GACvC,EAAW,IAAM,EAAuB,GACjC,GAGH,WAAa,SAAC,GAClB,GAAI,GAAY,IAAI,KAAK,SACrB,EAAqB,IAAI,KAAK,QAIlC,OAHA,KAAI,KAAK,OAAO,EAAoB,cACpC,IAAI,KAAK,SAAS,EAAW,EAAoB,GACjD,EAAU,GAAK,EACR,GAGH,aAAe,SAAC,GACpB,GAAI,GAAc,IAAI,KAAK,SACvB,EAAe,IAAI,KAAK,QAG5B,OAFA,KAAI,KAAK,OAAO,EAAc,OAAO,cACrC,IAAI,KAAK,SAAS,EAAa,EAAc,GACtC,GAGH,oBAAsB,SAAC,EAAG,GAC9B,GAAI,GAAmB,yBAAyB,EAAG,GAC/C,EAAmB,YAAY,GAC/B,EAAmB,WAAW,GAC9B,EAAmB,aAAa,GAEhC,EAAc,IAAI,KAAK,QAK3B,OAJA,GAAY,GAAK,EAAY,GAC7B,EAAY,GAAK,EAAY,GAC7B,EAAY,GAAK,EAAY,GAC7B,IAAI,KAAK,UAAU,EAAa,GACzB,GAGH,iBAAmB,SAAC,EAAQ,EAAG,EAAG,GACtC,GAAI,GAAc,oBAAoB,EAAG,GAErC,EAAW,IAAI,OAAO,EAAQ,EAAa,EAE/C,OAAO,GAGT,QAAO,SAAY,oBAAA,oBAAqB,iBAAA;;;YC7DxC,IAAM,KAAM,QAAQ,YAEpB,QAAO,QAAU,WACf,GAAI,GAAS,GAAI,cAAa,IAC1B,EAAO,IAAI,SAAS,SAAS,IAC7B,EAAS,OAAO,WAAa,OAAO,YACpC,EAAO,GACP,EAAM,GAEV,OADA,KAAI,KAAK,YAAY,EAAQ,EAAM,EAAQ,EAAM,GAC1C;;;YCTT,IAAM,KAAM,QAAQ,aAEd,OAAS,SAAC,EAAQ,EAAW,GACjC,GAAM,GAAY,WAAA,MAAM,IAClB,EAAe,WAAA,MAAM,IACrB,EAAc,WAAA,MAAM,IAEpB,EAAW,SAAC,GAChB,OACE,EAAU,GAAK,EACf,EAAU,GAAK,EACf,EAAU,GAAK,IAIb,EAAO,SAAC,GACZ,GAAI,GAAI,EAAI,EAAU,EACtB,QACE,EAAU,GAAK,EACf,EAAU,GAAK,EACf,EAAU,GAAK,IAIb,EAAO,SAAC,GACZ,GAAI,GAAI,EAAI,EAAU,EACtB,QACE,EAAU,GAAK,EACf,EAAU,GAAK,EACf,EAAU,GAAK,IAIb,EAAO,SAAC,GACZ,GAAI,GAAI,EAAI,EAAU,EACtB,QACE,EAAU,GAAK,EACf,EAAU,GAAK,EACf,EAAU,GAAK,GAInB,QAAS,UAAA,EAAW,aAAA,EAAc,YAAA,EAAa,SAAA,EAAU,KAAA,EAAM,KAAA,EAAM,KAAA,IAGjE,uBAAyB,SAAC,EAAK,EAAU,EAAU,GACvD,GAGI,IAFO,EAAI,cAEc,IAAI,KAAK,SACtC,KAAI,KAAK,eAAe,EAAwB,EAEhD,IAAI,GAAQ,IAAI,KAAK,QAiGrB,OAhGA,KAAI,KAAK,UAAU,EAAO,EAAwB,EAAI,cAgG/C,EAGT,QAAO,SAAY,OAAA,OAAQ,uBAAA;;;YCxJ3B,IAAM,QAAS,SAAS,cAAc,UAEhC,gBAAkB,WACtB,GAAI,GAAU,SAAS,oBAAsB,SAAS,qBACtD,OAAO,KAAY,QAGf,YAAc,WAClB,OAAO,mBAAqB,OAAO,oBAAsB,OAAO,sBAChE,SAAS,gBAAkB,SAAS,iBAAmB,SAAS,mBAChE,OAAO,qBAGT,QAAO,QAAU,WACf,cAGF,IAAI,QAEJ,UAAS,UAAY,SAAU,GACzB,mBACE,KAAK,QAAQ,EAAM,SAAU,GAC/B,KAAK,KAAK,EAAM,OAKtB,SAAS,QAAU,SAAU,GACvB,mBACE,KAAK,QAAQ,EAAM,OAAQ,GAC7B,KAAK,OAAO,KAAK,QAAQ,EAAM,MAAO,GAK5C,IAAM,cAAe,SAAU,GAC7B,MAAI,mBACM,KAAK,QAAQ,IAAW,OAEhC,UAIE,YAAc,SAAU,GAC5B,SAAS,YAAc,SAAU,GAC3B,mBACF,EAAS,KAKT,QAAU,SAAU,GACxB,SAAS,QAAU,SAAU,GACvB,kBACF,EAAS,GAET,gBAKA,QAAU,SAAU,GACxB,SAAS,QAAU,SAAU,GACvB,mBACF,EAAS,GAEX,EAAM,kBAIV,QAAO,SACL,OAAQ,OACR,gBAAiB,gBACjB,YAAa,YACb,aAAc,aACd,YAAa,YACb,QAAS,QACT,QAAS;;;YC7EX,QAAO,QAAU,SAAC,GAChB,GAAM,GAAS,EAAK,MAAM,cAAc,GAAG,MAAM,gBAAgB,GAC3D,EAAW,EAAK,MAAM,gBAAgB,EAC5C,QAAS,OAAA,EAAQ,SAAA",
"file": "generated.js",
"sourceRoot": "",
"sourcesContent": [
"(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})",
"/**\n * @fileoverview gl-matrix - High performance matrix and vector operations\n * @author Brandon Jones\n * @author Colin MacKenzie IV\n * @version 2.3.2\n */\n\n/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n// END HEADER\n\nexports.glMatrix = require(\"./gl-matrix/common.js\");\nexports.mat2 = require(\"./gl-matrix/mat2.js\");\nexports.mat2d = require(\"./gl-matrix/mat2d.js\");\nexports.mat3 = require(\"./gl-matrix/mat3.js\");\nexports.mat4 = require(\"./gl-matrix/mat4.js\");\nexports.quat = require(\"./gl-matrix/quat.js\");\nexports.vec2 = require(\"./gl-matrix/vec2.js\");\nexports.vec3 = require(\"./gl-matrix/vec3.js\");\nexports.vec4 = require(\"./gl-matrix/vec4.js\");",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\n/**\n * @class Common utilities\n * @name glMatrix\n */\nvar glMatrix = {};\n\n// Configuration Constants\nglMatrix.EPSILON = 0.000001;\nglMatrix.ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;\nglMatrix.RANDOM = Math.random;\nglMatrix.ENABLE_SIMD = false;\n\n// Capability detection\nglMatrix.SIMD_AVAILABLE = (glMatrix.ARRAY_TYPE === Float32Array) && ('SIMD' in this);\nglMatrix.USE_SIMD = glMatrix.ENABLE_SIMD && glMatrix.SIMD_AVAILABLE;\n\n/**\n * Sets the type of array used when creating new vectors and matrices\n *\n * @param {Type} type Array type, such as Float32Array or Array\n */\nglMatrix.setMatrixArrayType = function(type) {\n glMatrix.ARRAY_TYPE = type;\n}\n\nvar degree = Math.PI / 180;\n\n/**\n* Convert Degree To Radian\n*\n* @param {Number} Angle in Degrees\n*/\nglMatrix.toRadian = function(a){\n return a * degree;\n}\n\n/**\n * Tests whether or not the arguments have approximately the same value, within an absolute\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less \n * than or equal to 1.0, and a relative tolerance is used for larger values)\n * \n * @param {Number} a The first number to test.\n * @param {Number} b The second number to test.\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\n */\nglMatrix.equals = function(a, b) {\n\treturn Math.abs(a - b) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a), Math.abs(b));\n}\n\nmodule.exports = glMatrix;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\n\n/**\n * @class 2x2 Matrix\n * @name mat2\n */\nvar mat2 = {};\n\n/**\n * Creates a new identity mat2\n *\n * @returns {mat2} a new 2x2 matrix\n */\nmat2.create = function() {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Creates a new mat2 initialized with values from an existing matrix\n *\n * @param {mat2} a matrix to clone\n * @returns {mat2} a new 2x2 matrix\n */\nmat2.clone = function(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Copy the values from one mat2 to another\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Set a mat2 to the identity matrix\n *\n * @param {mat2} out the receiving matrix\n * @returns {mat2} out\n */\nmat2.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Create a new mat2 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out A new 2x2 matrix\n */\nmat2.fromValues = function(m00, m01, m10, m11) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n};\n\n/**\n * Set the components of a mat2 to the given values\n *\n * @param {mat2} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m10 Component in column 1, row 0 position (index 2)\n * @param {Number} m11 Component in column 1, row 1 position (index 3)\n * @returns {mat2} out\n */\nmat2.set = function(out, m00, m01, m10, m11) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m10;\n out[3] = m11;\n return out;\n};\n\n\n/**\n * Transpose the values of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a1 = a[1];\n out[1] = a[2];\n out[2] = a1;\n } else {\n out[0] = a[0];\n out[1] = a[2];\n out[2] = a[1];\n out[3] = a[3];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.invert = function(out, a) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n\n // Calculate the determinant\n det = a0 * a3 - a2 * a1;\n\n if (!det) {\n return null;\n }\n det = 1.0 / det;\n \n out[0] = a3 * det;\n out[1] = -a1 * det;\n out[2] = -a2 * det;\n out[3] = a0 * det;\n\n return out;\n};\n\n/**\n * Calculates the adjugate of a mat2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the source matrix\n * @returns {mat2} out\n */\nmat2.adjoint = function(out, a) {\n // Caching this value is nessecary if out == a\n var a0 = a[0];\n out[0] = a[3];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a0;\n\n return out;\n};\n\n/**\n * Calculates the determinant of a mat2\n *\n * @param {mat2} a the source matrix\n * @returns {Number} determinant of a\n */\nmat2.determinant = function (a) {\n return a[0] * a[3] - a[2] * a[1];\n};\n\n/**\n * Multiplies two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the first operand\n * @param {mat2} b the second operand\n * @returns {mat2} out\n */\nmat2.multiply = function (out, a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n return out;\n};\n\n/**\n * Alias for {@link mat2.multiply}\n * @function\n */\nmat2.mul = mat2.multiply;\n\n/**\n * Rotates a mat2 by the given angle\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\nmat2.rotate = function (out, a, rad) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n return out;\n};\n\n/**\n * Scales the mat2 by the dimensions in the given vec2\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the matrix to rotate\n * @param {vec2} v the vec2 to scale the matrix by\n * @returns {mat2} out\n **/\nmat2.scale = function(out, a, v) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n v0 = v[0], v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n return out;\n};\n\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.rotate(dest, dest, rad);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2} out\n */\nmat2.fromRotation = function(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n return out;\n}\n\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2.identity(dest);\n * mat2.scale(dest, dest, vec);\n *\n * @param {mat2} out mat2 receiving operation result\n * @param {vec2} v Scaling vector\n * @returns {mat2} out\n */\nmat2.fromScaling = function(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n return out;\n}\n\n/**\n * Returns a string representation of a mat2\n *\n * @param {mat2} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat2.str = function (a) {\n return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\n/**\n * Returns Frobenius norm of a mat2\n *\n * @param {mat2} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\nmat2.frob = function (a) {\n return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2)))\n};\n\n/**\n * Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix\n * @param {mat2} L the lower triangular matrix \n * @param {mat2} D the diagonal matrix \n * @param {mat2} U the upper triangular matrix \n * @param {mat2} a the input matrix to factorize\n */\n\nmat2.LDU = function (L, D, U, a) { \n L[2] = a[2]/a[0]; \n U[0] = a[0]; \n U[1] = a[1]; \n U[3] = a[3] - L[2] * U[1]; \n return [L, D, U]; \n}; \n\n/**\n * Adds two mat2's\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the first operand\n * @param {mat2} b the second operand\n * @returns {mat2} out\n */\nmat2.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n};\n\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the first operand\n * @param {mat2} b the second operand\n * @returns {mat2} out\n */\nmat2.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n};\n\n/**\n * Alias for {@link mat2.subtract}\n * @function\n */\nmat2.sub = mat2.subtract;\n\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {mat2} a The first matrix.\n * @param {mat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat2.exactEquals = function (a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n};\n\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {mat2} a The first matrix.\n * @param {mat2} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat2.equals = function (a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];\n return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&\n Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)));\n};\n\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2} out the receiving matrix\n * @param {mat2} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2} out\n */\nmat2.multiplyScalar = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n};\n\n/**\n * Adds two mat2's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2} out the receiving vector\n * @param {mat2} a the first operand\n * @param {mat2} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2} out\n */\nmat2.multiplyScalarAndAdd = function(out, a, b, scale) {\n out[0] = a[0] + (b[0] * scale);\n out[1] = a[1] + (b[1] * scale);\n out[2] = a[2] + (b[2] * scale);\n out[3] = a[3] + (b[3] * scale);\n return out;\n};\n\nmodule.exports = mat2;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\n\n/**\n * @class 2x3 Matrix\n * @name mat2d\n * \n * @description \n * A mat2d contains six elements defined as:\n * <pre>\n * [a, c, tx,\n * b, d, ty]\n * </pre>\n * This is a short form for the 3x3 matrix:\n * <pre>\n * [a, c, tx,\n * b, d, ty,\n * 0, 0, 1]\n * </pre>\n * The last row is ignored so the array is shorter and operations are faster.\n */\nvar mat2d = {};\n\n/**\n * Creates a new identity mat2d\n *\n * @returns {mat2d} a new 2x3 matrix\n */\nmat2d.create = function() {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n};\n\n/**\n * Creates a new mat2d initialized with values from an existing matrix\n *\n * @param {mat2d} a matrix to clone\n * @returns {mat2d} a new 2x3 matrix\n */\nmat2d.clone = function(a) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n};\n\n/**\n * Copy the values from one mat2d to another\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the source matrix\n * @returns {mat2d} out\n */\nmat2d.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n return out;\n};\n\n/**\n * Set a mat2d to the identity matrix\n *\n * @param {mat2d} out the receiving matrix\n * @returns {mat2d} out\n */\nmat2d.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n return out;\n};\n\n/**\n * Create a new mat2d with the given values\n *\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} A new mat2d\n */\nmat2d.fromValues = function(a, b, c, d, tx, ty) {\n var out = new glMatrix.ARRAY_TYPE(6);\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n};\n\n/**\n * Set the components of a mat2d to the given values\n *\n * @param {mat2d} out the receiving matrix\n * @param {Number} a Component A (index 0)\n * @param {Number} b Component B (index 1)\n * @param {Number} c Component C (index 2)\n * @param {Number} d Component D (index 3)\n * @param {Number} tx Component TX (index 4)\n * @param {Number} ty Component TY (index 5)\n * @returns {mat2d} out\n */\nmat2d.set = function(out, a, b, c, d, tx, ty) {\n out[0] = a;\n out[1] = b;\n out[2] = c;\n out[3] = d;\n out[4] = tx;\n out[5] = ty;\n return out;\n};\n\n/**\n * Inverts a mat2d\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the source matrix\n * @returns {mat2d} out\n */\nmat2d.invert = function(out, a) {\n var aa = a[0], ab = a[1], ac = a[2], ad = a[3],\n atx = a[4], aty = a[5];\n\n var det = aa * ad - ab * ac;\n if(!det){\n return null;\n }\n det = 1.0 / det;\n\n out[0] = ad * det;\n out[1] = -ab * det;\n out[2] = -ac * det;\n out[3] = aa * det;\n out[4] = (ac * aty - ad * atx) * det;\n out[5] = (ab * atx - aa * aty) * det;\n return out;\n};\n\n/**\n * Calculates the determinant of a mat2d\n *\n * @param {mat2d} a the source matrix\n * @returns {Number} determinant of a\n */\nmat2d.determinant = function (a) {\n return a[0] * a[3] - a[1] * a[2];\n};\n\n/**\n * Multiplies two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the first operand\n * @param {mat2d} b the second operand\n * @returns {mat2d} out\n */\nmat2d.multiply = function (out, a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],\n b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];\n out[0] = a0 * b0 + a2 * b1;\n out[1] = a1 * b0 + a3 * b1;\n out[2] = a0 * b2 + a2 * b3;\n out[3] = a1 * b2 + a3 * b3;\n out[4] = a0 * b4 + a2 * b5 + a4;\n out[5] = a1 * b4 + a3 * b5 + a5;\n return out;\n};\n\n/**\n * Alias for {@link mat2d.multiply}\n * @function\n */\nmat2d.mul = mat2d.multiply;\n\n/**\n * Rotates a mat2d by the given angle\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\nmat2d.rotate = function (out, a, rad) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],\n s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = a0 * c + a2 * s;\n out[1] = a1 * c + a3 * s;\n out[2] = a0 * -s + a2 * c;\n out[3] = a1 * -s + a3 * c;\n out[4] = a4;\n out[5] = a5;\n return out;\n};\n\n/**\n * Scales the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the matrix to translate\n * @param {vec2} v the vec2 to scale the matrix by\n * @returns {mat2d} out\n **/\nmat2d.scale = function(out, a, v) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],\n v0 = v[0], v1 = v[1];\n out[0] = a0 * v0;\n out[1] = a1 * v0;\n out[2] = a2 * v1;\n out[3] = a3 * v1;\n out[4] = a4;\n out[5] = a5;\n return out;\n};\n\n/**\n * Translates the mat2d by the dimensions in the given vec2\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the matrix to translate\n * @param {vec2} v the vec2 to translate the matrix by\n * @returns {mat2d} out\n **/\nmat2d.translate = function(out, a, v) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],\n v0 = v[0], v1 = v[1];\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = a0 * v0 + a2 * v1 + a4;\n out[5] = a1 * v0 + a3 * v1 + a5;\n return out;\n};\n\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.rotate(dest, dest, rad);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat2d} out\n */\nmat2d.fromRotation = function(out, rad) {\n var s = Math.sin(rad), c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = -s;\n out[3] = c;\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.scale(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {vec2} v Scaling vector\n * @returns {mat2d} out\n */\nmat2d.fromScaling = function(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = v[1];\n out[4] = 0;\n out[5] = 0;\n return out;\n}\n\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat2d.identity(dest);\n * mat2d.translate(dest, dest, vec);\n *\n * @param {mat2d} out mat2d receiving operation result\n * @param {vec2} v Translation vector\n * @returns {mat2d} out\n */\nmat2d.fromTranslation = function(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = v[0];\n out[5] = v[1];\n return out;\n}\n\n/**\n * Returns a string representation of a mat2d\n *\n * @param {mat2d} a matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat2d.str = function (a) {\n return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + \n a[3] + ', ' + a[4] + ', ' + a[5] + ')';\n};\n\n/**\n * Returns Frobenius norm of a mat2d\n *\n * @param {mat2d} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\nmat2d.frob = function (a) { \n return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + 1))\n}; \n\n/**\n * Adds two mat2d's\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the first operand\n * @param {mat2d} b the second operand\n * @returns {mat2d} out\n */\nmat2d.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n return out;\n};\n\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the first operand\n * @param {mat2d} b the second operand\n * @returns {mat2d} out\n */\nmat2d.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n return out;\n};\n\n/**\n * Alias for {@link mat2d.subtract}\n * @function\n */\nmat2d.sub = mat2d.subtract;\n\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat2d} out the receiving matrix\n * @param {mat2d} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat2d} out\n */\nmat2d.multiplyScalar = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n return out;\n};\n\n/**\n * Adds two mat2d's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat2d} out the receiving vector\n * @param {mat2d} a the first operand\n * @param {mat2d} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat2d} out\n */\nmat2d.multiplyScalarAndAdd = function(out, a, b, scale) {\n out[0] = a[0] + (b[0] * scale);\n out[1] = a[1] + (b[1] * scale);\n out[2] = a[2] + (b[2] * scale);\n out[3] = a[3] + (b[3] * scale);\n out[4] = a[4] + (b[4] * scale);\n out[5] = a[5] + (b[5] * scale);\n return out;\n};\n\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {mat2d} a The first matrix.\n * @param {mat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat2d.exactEquals = function (a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5];\n};\n\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {mat2d} a The first matrix.\n * @param {mat2d} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat2d.equals = function (a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];\n return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&\n Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&\n Math.abs(a4 - b4) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&\n Math.abs(a5 - b5) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a5), Math.abs(b5)));\n};\n\nmodule.exports = mat2d;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\n\n/**\n * @class 3x3 Matrix\n * @name mat3\n */\nvar mat3 = {};\n\n/**\n * Creates a new identity mat3\n *\n * @returns {mat3} a new 3x3 matrix\n */\nmat3.create = function() {\n var out = new glMatrix.ARRAY_TYPE(9);\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n};\n\n/**\n * Copies the upper-left 3x3 values into the given mat3.\n *\n * @param {mat3} out the receiving 3x3 matrix\n * @param {mat4} a the source 4x4 matrix\n * @returns {mat3} out\n */\nmat3.fromMat4 = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[4];\n out[4] = a[5];\n out[5] = a[6];\n out[6] = a[8];\n out[7] = a[9];\n out[8] = a[10];\n return out;\n};\n\n/**\n * Creates a new mat3 initialized with values from an existing matrix\n *\n * @param {mat3} a matrix to clone\n * @returns {mat3} a new 3x3 matrix\n */\nmat3.clone = function(a) {\n var out = new glMatrix.ARRAY_TYPE(9);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n};\n\n/**\n * Copy the values from one mat3 to another\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n};\n\n/**\n * Create a new mat3 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\n * @param {Number} m10 Component in column 1, row 0 position (index 3)\n * @param {Number} m11 Component in column 1, row 1 position (index 4)\n * @param {Number} m12 Component in column 1, row 2 position (index 5)\n * @param {Number} m20 Component in column 2, row 0 position (index 6)\n * @param {Number} m21 Component in column 2, row 1 position (index 7)\n * @param {Number} m22 Component in column 2, row 2 position (index 8)\n * @returns {mat3} A new mat3\n */\nmat3.fromValues = function(m00, m01, m02, m10, m11, m12, m20, m21, m22) {\n var out = new glMatrix.ARRAY_TYPE(9);\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m10;\n out[4] = m11;\n out[5] = m12;\n out[6] = m20;\n out[7] = m21;\n out[8] = m22;\n return out;\n};\n\n/**\n * Set the components of a mat3 to the given values\n *\n * @param {mat3} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\n * @param {Number} m10 Component in column 1, row 0 position (index 3)\n * @param {Number} m11 Component in column 1, row 1 position (index 4)\n * @param {Number} m12 Component in column 1, row 2 position (index 5)\n * @param {Number} m20 Component in column 2, row 0 position (index 6)\n * @param {Number} m21 Component in column 2, row 1 position (index 7)\n * @param {Number} m22 Component in column 2, row 2 position (index 8)\n * @returns {mat3} out\n */\nmat3.set = function(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m10;\n out[4] = m11;\n out[5] = m12;\n out[6] = m20;\n out[7] = m21;\n out[8] = m22;\n return out;\n};\n\n/**\n * Set a mat3 to the identity matrix\n *\n * @param {mat3} out the receiving matrix\n * @returns {mat3} out\n */\nmat3.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1], a02 = a[2], a12 = a[5];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a01;\n out[5] = a[7];\n out[6] = a02;\n out[7] = a12;\n } else {\n out[0] = a[0];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a[1];\n out[4] = a[4];\n out[5] = a[7];\n out[6] = a[2];\n out[7] = a[5];\n out[8] = a[8];\n }\n \n return out;\n};\n\n/**\n * Inverts a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.invert = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n\n b01 = a22 * a11 - a12 * a21,\n b11 = -a22 * a10 + a12 * a20,\n b21 = a21 * a10 - a11 * a20,\n\n // Calculate the determinant\n det = a00 * b01 + a01 * b11 + a02 * b21;\n\n if (!det) { \n return null; \n }\n det = 1.0 / det;\n\n out[0] = b01 * det;\n out[1] = (-a22 * a01 + a02 * a21) * det;\n out[2] = (a12 * a01 - a02 * a11) * det;\n out[3] = b11 * det;\n out[4] = (a22 * a00 - a02 * a20) * det;\n out[5] = (-a12 * a00 + a02 * a10) * det;\n out[6] = b21 * det;\n out[7] = (-a21 * a00 + a01 * a20) * det;\n out[8] = (a11 * a00 - a01 * a10) * det;\n return out;\n};\n\n/**\n * Calculates the adjugate of a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the source matrix\n * @returns {mat3} out\n */\nmat3.adjoint = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8];\n\n out[0] = (a11 * a22 - a12 * a21);\n out[1] = (a02 * a21 - a01 * a22);\n out[2] = (a01 * a12 - a02 * a11);\n out[3] = (a12 * a20 - a10 * a22);\n out[4] = (a00 * a22 - a02 * a20);\n out[5] = (a02 * a10 - a00 * a12);\n out[6] = (a10 * a21 - a11 * a20);\n out[7] = (a01 * a20 - a00 * a21);\n out[8] = (a00 * a11 - a01 * a10);\n return out;\n};\n\n/**\n * Calculates the determinant of a mat3\n *\n * @param {mat3} a the source matrix\n * @returns {Number} determinant of a\n */\nmat3.determinant = function (a) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8];\n\n return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);\n};\n\n/**\n * Multiplies two mat3's\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the first operand\n * @param {mat3} b the second operand\n * @returns {mat3} out\n */\nmat3.multiply = function (out, a, b) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n\n b00 = b[0], b01 = b[1], b02 = b[2],\n b10 = b[3], b11 = b[4], b12 = b[5],\n b20 = b[6], b21 = b[7], b22 = b[8];\n\n out[0] = b00 * a00 + b01 * a10 + b02 * a20;\n out[1] = b00 * a01 + b01 * a11 + b02 * a21;\n out[2] = b00 * a02 + b01 * a12 + b02 * a22;\n\n out[3] = b10 * a00 + b11 * a10 + b12 * a20;\n out[4] = b10 * a01 + b11 * a11 + b12 * a21;\n out[5] = b10 * a02 + b11 * a12 + b12 * a22;\n\n out[6] = b20 * a00 + b21 * a10 + b22 * a20;\n out[7] = b20 * a01 + b21 * a11 + b22 * a21;\n out[8] = b20 * a02 + b21 * a12 + b22 * a22;\n return out;\n};\n\n/**\n * Alias for {@link mat3.multiply}\n * @function\n */\nmat3.mul = mat3.multiply;\n\n/**\n * Translate a mat3 by the given vector\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the matrix to translate\n * @param {vec2} v vector to translate by\n * @returns {mat3} out\n */\nmat3.translate = function(out, a, v) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n x = v[0], y = v[1];\n\n out[0] = a00;\n out[1] = a01;\n out[2] = a02;\n\n out[3] = a10;\n out[4] = a11;\n out[5] = a12;\n\n out[6] = x * a00 + y * a10 + a20;\n out[7] = x * a01 + y * a11 + a21;\n out[8] = x * a02 + y * a12 + a22;\n return out;\n};\n\n/**\n * Rotates a mat3 by the given angle\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat3} out\n */\nmat3.rotate = function (out, a, rad) {\n var a00 = a[0], a01 = a[1], a02 = a[2],\n a10 = a[3], a11 = a[4], a12 = a[5],\n a20 = a[6], a21 = a[7], a22 = a[8],\n\n s = Math.sin(rad),\n c = Math.cos(rad);\n\n out[0] = c * a00 + s * a10;\n out[1] = c * a01 + s * a11;\n out[2] = c * a02 + s * a12;\n\n out[3] = c * a10 - s * a00;\n out[4] = c * a11 - s * a01;\n out[5] = c * a12 - s * a02;\n\n out[6] = a20;\n out[7] = a21;\n out[8] = a22;\n return out;\n};\n\n/**\n * Scales the mat3 by the dimensions in the given vec2\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the matrix to rotate\n * @param {vec2} v the vec2 to scale the matrix by\n * @returns {mat3} out\n **/\nmat3.scale = function(out, a, v) {\n var x = v[0], y = v[1];\n\n out[0] = x * a[0];\n out[1] = x * a[1];\n out[2] = x * a[2];\n\n out[3] = y * a[3];\n out[4] = y * a[4];\n out[5] = y * a[5];\n\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n};\n\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat3.identity(dest);\n * mat3.translate(dest, dest, vec);\n *\n * @param {mat3} out mat3 receiving operation result\n * @param {vec2} v Translation vector\n * @returns {mat3} out\n */\nmat3.fromTranslation = function(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = v[0];\n out[7] = v[1];\n out[8] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from a given angle\n * This is equivalent to (but much faster than):\n *\n * mat3.identity(dest);\n * mat3.rotate(dest, dest, rad);\n *\n * @param {mat3} out mat3 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat3} out\n */\nmat3.fromRotation = function(out, rad) {\n var s = Math.sin(rad), c = Math.cos(rad);\n\n out[0] = c;\n out[1] = s;\n out[2] = 0;\n\n out[3] = -s;\n out[4] = c;\n out[5] = 0;\n\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat3.identity(dest);\n * mat3.scale(dest, dest, vec);\n *\n * @param {mat3} out mat3 receiving operation result\n * @param {vec2} v Scaling vector\n * @returns {mat3} out\n */\nmat3.fromScaling = function(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n\n out[3] = 0;\n out[4] = v[1];\n out[5] = 0;\n\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n\n/**\n * Copies the values from a mat2d into a mat3\n *\n * @param {mat3} out the receiving matrix\n * @param {mat2d} a the matrix to copy\n * @returns {mat3} out\n **/\nmat3.fromMat2d = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = 0;\n\n out[3] = a[2];\n out[4] = a[3];\n out[5] = 0;\n\n out[6] = a[4];\n out[7] = a[5];\n out[8] = 1;\n return out;\n};\n\n/**\n* Calculates a 3x3 matrix from the given quaternion\n*\n* @param {mat3} out mat3 receiving operation result\n* @param {quat} q Quaternion to create matrix from\n*\n* @returns {mat3} out\n*/\nmat3.fromQuat = function (out, q) {\n var x = q[0], y = q[1], z = q[2], w = q[3],\n x2 = x + x,\n y2 = y + y,\n z2 = z + z,\n\n xx = x * x2,\n yx = y * x2,\n yy = y * y2,\n zx = z * x2,\n zy = z * y2,\n zz = z * z2,\n wx = w * x2,\n wy = w * y2,\n wz = w * z2;\n\n out[0] = 1 - yy - zz;\n out[3] = yx - wz;\n out[6] = zx + wy;\n\n out[1] = yx + wz;\n out[4] = 1 - xx - zz;\n out[7] = zy - wx;\n\n out[2] = zx - wy;\n out[5] = zy + wx;\n out[8] = 1 - xx - yy;\n\n return out;\n};\n\n/**\n* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix\n*\n* @param {mat3} out mat3 receiving operation result\n* @param {mat4} a Mat4 to derive the normal matrix from\n*\n* @returns {mat3} out\n*/\nmat3.normalFromMat4 = function (out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n b00 = a00 * a11 - a01 * a10,\n b01 = a00 * a12 - a02 * a10,\n b02 = a00 * a13 - a03 * a10,\n b03 = a01 * a12 - a02 * a11,\n b04 = a01 * a13 - a03 * a11,\n b05 = a02 * a13 - a03 * a12,\n b06 = a20 * a31 - a21 * a30,\n b07 = a20 * a32 - a22 * a30,\n b08 = a20 * a33 - a23 * a30,\n b09 = a21 * a32 - a22 * a31,\n b10 = a21 * a33 - a23 * a31,\n b11 = a22 * a33 - a23 * a32,\n\n // Calculate the determinant\n det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) { \n return null; \n }\n det = 1.0 / det;\n\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n\n out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n\n out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n\n return out;\n};\n\n/**\n * Returns a string representation of a mat3\n *\n * @param {mat3} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat3.str = function (a) {\n return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + \n a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + \n a[6] + ', ' + a[7] + ', ' + a[8] + ')';\n};\n\n/**\n * Returns Frobenius norm of a mat3\n *\n * @param {mat3} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\nmat3.frob = function (a) {\n return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2)))\n};\n\n/**\n * Adds two mat3's\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the first operand\n * @param {mat3} b the second operand\n * @returns {mat3} out\n */\nmat3.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n out[6] = a[6] + b[6];\n out[7] = a[7] + b[7];\n out[8] = a[8] + b[8];\n return out;\n};\n\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the first operand\n * @param {mat3} b the second operand\n * @returns {mat3} out\n */\nmat3.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n out[6] = a[6] - b[6];\n out[7] = a[7] - b[7];\n out[8] = a[8] - b[8];\n return out;\n};\n\n/**\n * Alias for {@link mat3.subtract}\n * @function\n */\nmat3.sub = mat3.subtract;\n\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat3} out the receiving matrix\n * @param {mat3} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat3} out\n */\nmat3.multiplyScalar = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n out[6] = a[6] * b;\n out[7] = a[7] * b;\n out[8] = a[8] * b;\n return out;\n};\n\n/**\n * Adds two mat3's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat3} out the receiving vector\n * @param {mat3} a the first operand\n * @param {mat3} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat3} out\n */\nmat3.multiplyScalarAndAdd = function(out, a, b, scale) {\n out[0] = a[0] + (b[0] * scale);\n out[1] = a[1] + (b[1] * scale);\n out[2] = a[2] + (b[2] * scale);\n out[3] = a[3] + (b[3] * scale);\n out[4] = a[4] + (b[4] * scale);\n out[5] = a[5] + (b[5] * scale);\n out[6] = a[6] + (b[6] * scale);\n out[7] = a[7] + (b[7] * scale);\n out[8] = a[8] + (b[8] * scale);\n return out;\n};\n\n/*\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {mat3} a The first matrix.\n * @param {mat3} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat3.exactEquals = function (a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && \n a[3] === b[3] && a[4] === b[4] && a[5] === b[5] &&\n a[6] === b[6] && a[7] === b[7] && a[8] === b[8];\n};\n\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {mat3} a The first matrix.\n * @param {mat3} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat3.equals = function (a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7], a8 = a[8];\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = a[6], b7 = b[7], b8 = b[8];\n return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&\n Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&\n Math.abs(a4 - b4) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&\n Math.abs(a5 - b5) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&\n Math.abs(a6 - b6) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&\n Math.abs(a7 - b7) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&\n Math.abs(a8 - b8) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a8), Math.abs(b8)));\n};\n\n\nmodule.exports = mat3;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\n\n/**\n * @class 4x4 Matrix\n * @name mat4\n */\nvar mat4 = {\n scalar: {},\n SIMD: {},\n};\n\n/**\n * Creates a new identity mat4\n *\n * @returns {mat4} a new 4x4 matrix\n */\nmat4.create = function() {\n var out = new glMatrix.ARRAY_TYPE(16);\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n};\n\n/**\n * Creates a new mat4 initialized with values from an existing matrix\n *\n * @param {mat4} a matrix to clone\n * @returns {mat4} a new 4x4 matrix\n */\nmat4.clone = function(a) {\n var out = new glMatrix.ARRAY_TYPE(16);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Copy the values from one mat4 to another\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Create a new mat4 with the given values\n *\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\n * @param {Number} m03 Component in column 0, row 3 position (index 3)\n * @param {Number} m10 Component in column 1, row 0 position (index 4)\n * @param {Number} m11 Component in column 1, row 1 position (index 5)\n * @param {Number} m12 Component in column 1, row 2 position (index 6)\n * @param {Number} m13 Component in column 1, row 3 position (index 7)\n * @param {Number} m20 Component in column 2, row 0 position (index 8)\n * @param {Number} m21 Component in column 2, row 1 position (index 9)\n * @param {Number} m22 Component in column 2, row 2 position (index 10)\n * @param {Number} m23 Component in column 2, row 3 position (index 11)\n * @param {Number} m30 Component in column 3, row 0 position (index 12)\n * @param {Number} m31 Component in column 3, row 1 position (index 13)\n * @param {Number} m32 Component in column 3, row 2 position (index 14)\n * @param {Number} m33 Component in column 3, row 3 position (index 15)\n * @returns {mat4} A new mat4\n */\nmat4.fromValues = function(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {\n var out = new glMatrix.ARRAY_TYPE(16);\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m03;\n out[4] = m10;\n out[5] = m11;\n out[6] = m12;\n out[7] = m13;\n out[8] = m20;\n out[9] = m21;\n out[10] = m22;\n out[11] = m23;\n out[12] = m30;\n out[13] = m31;\n out[14] = m32;\n out[15] = m33;\n return out;\n};\n\n/**\n * Set the components of a mat4 to the given values\n *\n * @param {mat4} out the receiving matrix\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\n * @param {Number} m03 Component in column 0, row 3 position (index 3)\n * @param {Number} m10 Component in column 1, row 0 position (index 4)\n * @param {Number} m11 Component in column 1, row 1 position (index 5)\n * @param {Number} m12 Component in column 1, row 2 position (index 6)\n * @param {Number} m13 Component in column 1, row 3 position (index 7)\n * @param {Number} m20 Component in column 2, row 0 position (index 8)\n * @param {Number} m21 Component in column 2, row 1 position (index 9)\n * @param {Number} m22 Component in column 2, row 2 position (index 10)\n * @param {Number} m23 Component in column 2, row 3 position (index 11)\n * @param {Number} m30 Component in column 3, row 0 position (index 12)\n * @param {Number} m31 Component in column 3, row 1 position (index 13)\n * @param {Number} m32 Component in column 3, row 2 position (index 14)\n * @param {Number} m33 Component in column 3, row 3 position (index 15)\n * @returns {mat4} out\n */\nmat4.set = function(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m03;\n out[4] = m10;\n out[5] = m11;\n out[6] = m12;\n out[7] = m13;\n out[8] = m20;\n out[9] = m21;\n out[10] = m22;\n out[11] = m23;\n out[12] = m30;\n out[13] = m31;\n out[14] = m32;\n out[15] = m33;\n return out;\n};\n\n\n/**\n * Set a mat4 to the identity matrix\n *\n * @param {mat4} out the receiving matrix\n * @returns {mat4} out\n */\nmat4.identity = function(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n};\n\n/**\n * Transpose the values of a mat4 not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.scalar.transpose = function(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1], a02 = a[2], a03 = a[3],\n a12 = a[6], a13 = a[7],\n a23 = a[11];\n\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a01;\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a02;\n out[9] = a12;\n out[11] = a[14];\n out[12] = a03;\n out[13] = a13;\n out[14] = a23;\n } else {\n out[0] = a[0];\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a[1];\n out[5] = a[5];\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a[2];\n out[9] = a[6];\n out[10] = a[10];\n out[11] = a[14];\n out[12] = a[3];\n out[13] = a[7];\n out[14] = a[11];\n out[15] = a[15];\n }\n\n return out;\n};\n\n/**\n * Transpose the values of a mat4 using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.SIMD.transpose = function(out, a) {\n var a0, a1, a2, a3,\n tmp01, tmp23,\n out0, out1, out2, out3;\n\n a0 = SIMD.Float32x4.load(a, 0);\n a1 = SIMD.Float32x4.load(a, 4);\n a2 = SIMD.Float32x4.load(a, 8);\n a3 = SIMD.Float32x4.load(a, 12);\n\n tmp01 = SIMD.Float32x4.shuffle(a0, a1, 0, 1, 4, 5);\n tmp23 = SIMD.Float32x4.shuffle(a2, a3, 0, 1, 4, 5);\n out0 = SIMD.Float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);\n out1 = SIMD.Float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);\n SIMD.Float32x4.store(out, 0, out0);\n SIMD.Float32x4.store(out, 4, out1);\n\n tmp01 = SIMD.Float32x4.shuffle(a0, a1, 2, 3, 6, 7);\n tmp23 = SIMD.Float32x4.shuffle(a2, a3, 2, 3, 6, 7);\n out2 = SIMD.Float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);\n out3 = SIMD.Float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);\n SIMD.Float32x4.store(out, 8, out2);\n SIMD.Float32x4.store(out, 12, out3);\n\n return out;\n};\n\n/**\n * Transpse a mat4 using SIMD if available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.transpose = glMatrix.USE_SIMD ? mat4.SIMD.transpose : mat4.scalar.transpose;\n\n/**\n * Inverts a mat4 not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.scalar.invert = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n b00 = a00 * a11 - a01 * a10,\n b01 = a00 * a12 - a02 * a10,\n b02 = a00 * a13 - a03 * a10,\n b03 = a01 * a12 - a02 * a11,\n b04 = a01 * a13 - a03 * a11,\n b05 = a02 * a13 - a03 * a12,\n b06 = a20 * a31 - a21 * a30,\n b07 = a20 * a32 - a22 * a30,\n b08 = a20 * a33 - a23 * a30,\n b09 = a21 * a32 - a22 * a31,\n b10 = a21 * a33 - a23 * a31,\n b11 = a22 * a33 - a23 * a32,\n\n // Calculate the determinant\n det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) {\n return null;\n }\n det = 1.0 / det;\n\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;\n out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;\n out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;\n out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;\n out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;\n out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;\n out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;\n\n return out;\n};\n\n/**\n * Inverts a mat4 using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.SIMD.invert = function(out, a) {\n var row0, row1, row2, row3,\n tmp1,\n minor0, minor1, minor2, minor3,\n det,\n a0 = SIMD.Float32x4.load(a, 0),\n a1 = SIMD.Float32x4.load(a, 4),\n a2 = SIMD.Float32x4.load(a, 8),\n a3 = SIMD.Float32x4.load(a, 12);\n\n // Compute matrix adjugate\n tmp1 = SIMD.Float32x4.shuffle(a0, a1, 0, 1, 4, 5);\n row1 = SIMD.Float32x4.shuffle(a2, a3, 0, 1, 4, 5);\n row0 = SIMD.Float32x4.shuffle(tmp1, row1, 0, 2, 4, 6);\n row1 = SIMD.Float32x4.shuffle(row1, tmp1, 1, 3, 5, 7);\n tmp1 = SIMD.Float32x4.shuffle(a0, a1, 2, 3, 6, 7);\n row3 = SIMD.Float32x4.shuffle(a2, a3, 2, 3, 6, 7);\n row2 = SIMD.Float32x4.shuffle(tmp1, row3, 0, 2, 4, 6);\n row3 = SIMD.Float32x4.shuffle(row3, tmp1, 1, 3, 5, 7);\n\n tmp1 = SIMD.Float32x4.mul(row2, row3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor0 = SIMD.Float32x4.mul(row1, tmp1);\n minor1 = SIMD.Float32x4.mul(row0, tmp1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row1, tmp1), minor0);\n minor1 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor1);\n minor1 = SIMD.Float32x4.swizzle(minor1, 2, 3, 0, 1);\n\n tmp1 = SIMD.Float32x4.mul(row1, row2);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor0);\n minor3 = SIMD.Float32x4.mul(row0, tmp1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row3, tmp1));\n minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor3);\n minor3 = SIMD.Float32x4.swizzle(minor3, 2, 3, 0, 1);\n\n tmp1 = SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(row1, 2, 3, 0, 1), row3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n row2 = SIMD.Float32x4.swizzle(row2, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor0);\n minor2 = SIMD.Float32x4.mul(row0, tmp1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row2, tmp1));\n minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor2);\n minor2 = SIMD.Float32x4.swizzle(minor2, 2, 3, 0, 1);\n\n tmp1 = SIMD.Float32x4.mul(row0, row1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor2);\n minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row2, tmp1), minor3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row3, tmp1), minor2);\n minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row2, tmp1));\n\n tmp1 = SIMD.Float32x4.mul(row0, row3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row2, tmp1));\n minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor2);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor1);\n minor2 = SIMD.Float32x4.sub(minor2, SIMD.Float32x4.mul(row1, tmp1));\n\n tmp1 = SIMD.Float32x4.mul(row0, row2);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor1);\n minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row1, tmp1));\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row3, tmp1));\n minor3 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor3);\n\n // Compute matrix determinant\n det = SIMD.Float32x4.mul(row0, minor0);\n det = SIMD.Float32x4.add(SIMD.Float32x4.swizzle(det, 2, 3, 0, 1), det);\n det = SIMD.Float32x4.add(SIMD.Float32x4.swizzle(det, 1, 0, 3, 2), det);\n tmp1 = SIMD.Float32x4.reciprocalApproximation(det);\n det = SIMD.Float32x4.sub(\n SIMD.Float32x4.add(tmp1, tmp1),\n SIMD.Float32x4.mul(det, SIMD.Float32x4.mul(tmp1, tmp1)));\n det = SIMD.Float32x4.swizzle(det, 0, 0, 0, 0);\n if (!det) {\n return null;\n }\n\n // Compute matrix inverse\n SIMD.Float32x4.store(out, 0, SIMD.Float32x4.mul(det, minor0));\n SIMD.Float32x4.store(out, 4, SIMD.Float32x4.mul(det, minor1));\n SIMD.Float32x4.store(out, 8, SIMD.Float32x4.mul(det, minor2));\n SIMD.Float32x4.store(out, 12, SIMD.Float32x4.mul(det, minor3));\n return out;\n}\n\n/**\n * Inverts a mat4 using SIMD if available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.invert = glMatrix.USE_SIMD ? mat4.SIMD.invert : mat4.scalar.invert;\n\n/**\n * Calculates the adjugate of a mat4 not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.scalar.adjoint = function(out, a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];\n\n out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));\n out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));\n out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));\n out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));\n out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));\n out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));\n out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));\n out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));\n out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));\n out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));\n out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));\n out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));\n out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));\n out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));\n out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));\n out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));\n return out;\n};\n\n/**\n * Calculates the adjugate of a mat4 using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\nmat4.SIMD.adjoint = function(out, a) {\n var a0, a1, a2, a3;\n var row0, row1, row2, row3;\n var tmp1;\n var minor0, minor1, minor2, minor3;\n\n var a0 = SIMD.Float32x4.load(a, 0);\n var a1 = SIMD.Float32x4.load(a, 4);\n var a2 = SIMD.Float32x4.load(a, 8);\n var a3 = SIMD.Float32x4.load(a, 12);\n\n // Transpose the source matrix. Sort of. Not a true transpose operation\n tmp1 = SIMD.Float32x4.shuffle(a0, a1, 0, 1, 4, 5);\n row1 = SIMD.Float32x4.shuffle(a2, a3, 0, 1, 4, 5);\n row0 = SIMD.Float32x4.shuffle(tmp1, row1, 0, 2, 4, 6);\n row1 = SIMD.Float32x4.shuffle(row1, tmp1, 1, 3, 5, 7);\n\n tmp1 = SIMD.Float32x4.shuffle(a0, a1, 2, 3, 6, 7);\n row3 = SIMD.Float32x4.shuffle(a2, a3, 2, 3, 6, 7);\n row2 = SIMD.Float32x4.shuffle(tmp1, row3, 0, 2, 4, 6);\n row3 = SIMD.Float32x4.shuffle(row3, tmp1, 1, 3, 5, 7);\n\n tmp1 = SIMD.Float32x4.mul(row2, row3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor0 = SIMD.Float32x4.mul(row1, tmp1);\n minor1 = SIMD.Float32x4.mul(row0, tmp1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row1, tmp1), minor0);\n minor1 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor1);\n minor1 = SIMD.Float32x4.swizzle(minor1, 2, 3, 0, 1);\n\n tmp1 = SIMD.Float32x4.mul(row1, row2);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor0);\n minor3 = SIMD.Float32x4.mul(row0, tmp1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row3, tmp1));\n minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor3);\n minor3 = SIMD.Float32x4.swizzle(minor3, 2, 3, 0, 1);\n\n tmp1 = SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(row1, 2, 3, 0, 1), row3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n row2 = SIMD.Float32x4.swizzle(row2, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor0);\n minor2 = SIMD.Float32x4.mul(row0, tmp1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor0 = SIMD.Float32x4.sub(minor0, SIMD.Float32x4.mul(row2, tmp1));\n minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row0, tmp1), minor2);\n minor2 = SIMD.Float32x4.swizzle(minor2, 2, 3, 0, 1);\n\n tmp1 = SIMD.Float32x4.mul(row0, row1);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor2);\n minor3 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row2, tmp1), minor3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor2 = SIMD.Float32x4.sub(SIMD.Float32x4.mul(row3, tmp1), minor2);\n minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row2, tmp1));\n\n tmp1 = SIMD.Float32x4.mul(row0, row3);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row2, tmp1));\n minor2 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor2);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row2, tmp1), minor1);\n minor2 = SIMD.Float32x4.sub(minor2, SIMD.Float32x4.mul(row1, tmp1));\n\n tmp1 = SIMD.Float32x4.mul(row0, row2);\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 1, 0, 3, 2);\n minor1 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row3, tmp1), minor1);\n minor3 = SIMD.Float32x4.sub(minor3, SIMD.Float32x4.mul(row1, tmp1));\n tmp1 = SIMD.Float32x4.swizzle(tmp1, 2, 3, 0, 1);\n minor1 = SIMD.Float32x4.sub(minor1, SIMD.Float32x4.mul(row3, tmp1));\n minor3 = SIMD.Float32x4.add(SIMD.Float32x4.mul(row1, tmp1), minor3);\n\n SIMD.Float32x4.store(out, 0, minor0);\n SIMD.Float32x4.store(out, 4, minor1);\n SIMD.Float32x4.store(out, 8, minor2);\n SIMD.Float32x4.store(out, 12, minor3);\n return out;\n};\n\n/**\n * Calculates the adjugate of a mat4 using SIMD if available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the source matrix\n * @returns {mat4} out\n */\n mat4.adjoint = glMatrix.USE_SIMD ? mat4.SIMD.adjoint : mat4.scalar.adjoint;\n\n/**\n * Calculates the determinant of a mat4\n *\n * @param {mat4} a the source matrix\n * @returns {Number} determinant of a\n */\nmat4.determinant = function (a) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],\n\n b00 = a00 * a11 - a01 * a10,\n b01 = a00 * a12 - a02 * a10,\n b02 = a00 * a13 - a03 * a10,\n b03 = a01 * a12 - a02 * a11,\n b04 = a01 * a13 - a03 * a11,\n b05 = a02 * a13 - a03 * a12,\n b06 = a20 * a31 - a21 * a30,\n b07 = a20 * a32 - a22 * a30,\n b08 = a20 * a33 - a23 * a30,\n b09 = a21 * a32 - a22 * a31,\n b10 = a21 * a33 - a23 * a31,\n b11 = a22 * a33 - a23 * a32;\n\n // Calculate the determinant\n return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n};\n\n/**\n * Multiplies two mat4's explicitly using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand, must be a Float32Array\n * @param {mat4} b the second operand, must be a Float32Array\n * @returns {mat4} out\n */\nmat4.SIMD.multiply = function (out, a, b) {\n var a0 = SIMD.Float32x4.load(a, 0);\n var a1 = SIMD.Float32x4.load(a, 4);\n var a2 = SIMD.Float32x4.load(a, 8);\n var a3 = SIMD.Float32x4.load(a, 12);\n\n var b0 = SIMD.Float32x4.load(b, 0);\n var out0 = SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 0, 0, 0, 0), a0),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 1, 1, 1, 1), a1),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 2, 2, 2, 2), a2),\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b0, 3, 3, 3, 3), a3))));\n SIMD.Float32x4.store(out, 0, out0);\n\n var b1 = SIMD.Float32x4.load(b, 4);\n var out1 = SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 0, 0, 0, 0), a0),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 1, 1, 1, 1), a1),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 2, 2, 2, 2), a2),\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b1, 3, 3, 3, 3), a3))));\n SIMD.Float32x4.store(out, 4, out1);\n\n var b2 = SIMD.Float32x4.load(b, 8);\n var out2 = SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 0, 0, 0, 0), a0),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 1, 1, 1, 1), a1),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 2, 2, 2, 2), a2),\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b2, 3, 3, 3, 3), a3))));\n SIMD.Float32x4.store(out, 8, out2);\n\n var b3 = SIMD.Float32x4.load(b, 12);\n var out3 = SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 0, 0, 0, 0), a0),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 1, 1, 1, 1), a1),\n SIMD.Float32x4.add(\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 2, 2, 2, 2), a2),\n SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(b3, 3, 3, 3, 3), a3))));\n SIMD.Float32x4.store(out, 12, out3);\n\n return out;\n};\n\n/**\n * Multiplies two mat4's explicitly not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @returns {mat4} out\n */\nmat4.scalar.multiply = function (out, a, b) {\n var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],\n a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],\n a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],\n a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];\n\n // Cache only the current line of the second matrix\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];\n out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];\n out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];\n out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n\n b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];\n out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;\n out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;\n out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;\n out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;\n return out;\n};\n\n/**\n * Multiplies two mat4's using SIMD if available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @returns {mat4} out\n */\nmat4.multiply = glMatrix.USE_SIMD ? mat4.SIMD.multiply : mat4.scalar.multiply;\n\n/**\n * Alias for {@link mat4.multiply}\n * @function\n */\nmat4.mul = mat4.multiply;\n\n/**\n * Translate a mat4 by the given vector not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to translate\n * @param {vec3} v vector to translate by\n * @returns {mat4} out\n */\nmat4.scalar.translate = function (out, a, v) {\n var x = v[0], y = v[1], z = v[2],\n a00, a01, a02, a03,\n a10, a11, a12, a13,\n a20, a21, a22, a23;\n\n if (a === out) {\n out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];\n out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];\n out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];\n out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];\n } else {\n a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;\n out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;\n out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;\n\n out[12] = a00 * x + a10 * y + a20 * z + a[12];\n out[13] = a01 * x + a11 * y + a21 * z + a[13];\n out[14] = a02 * x + a12 * y + a22 * z + a[14];\n out[15] = a03 * x + a13 * y + a23 * z + a[15];\n }\n\n return out;\n};\n\n/**\n * Translates a mat4 by the given vector using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to translate\n * @param {vec3} v vector to translate by\n * @returns {mat4} out\n */\nmat4.SIMD.translate = function (out, a, v) {\n var a0 = SIMD.Float32x4.load(a, 0),\n a1 = SIMD.Float32x4.load(a, 4),\n a2 = SIMD.Float32x4.load(a, 8),\n a3 = SIMD.Float32x4.load(a, 12),\n vec = SIMD.Float32x4(v[0], v[1], v[2] , 0);\n\n if (a !== out) {\n out[0] = a[0]; out[1] = a[1]; out[2] = a[2]; out[3] = a[3];\n out[4] = a[4]; out[5] = a[5]; out[6] = a[6]; out[7] = a[7];\n out[8] = a[8]; out[9] = a[9]; out[10] = a[10]; out[11] = a[11];\n }\n\n a0 = SIMD.Float32x4.mul(a0, SIMD.Float32x4.swizzle(vec, 0, 0, 0, 0));\n a1 = SIMD.Float32x4.mul(a1, SIMD.Float32x4.swizzle(vec, 1, 1, 1, 1));\n a2 = SIMD.Float32x4.mul(a2, SIMD.Float32x4.swizzle(vec, 2, 2, 2, 2));\n\n var t0 = SIMD.Float32x4.add(a0, SIMD.Float32x4.add(a1, SIMD.Float32x4.add(a2, a3)));\n SIMD.Float32x4.store(out, 12, t0);\n\n return out;\n};\n\n/**\n * Translates a mat4 by the given vector using SIMD if available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to translate\n * @param {vec3} v vector to translate by\n * @returns {mat4} out\n */\nmat4.translate = glMatrix.USE_SIMD ? mat4.SIMD.translate : mat4.scalar.translate;\n\n/**\n * Scales the mat4 by the dimensions in the given vec3 not using vectorization\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to scale\n * @param {vec3} v the vec3 to scale the matrix by\n * @returns {mat4} out\n **/\nmat4.scalar.scale = function(out, a, v) {\n var x = v[0], y = v[1], z = v[2];\n\n out[0] = a[0] * x;\n out[1] = a[1] * x;\n out[2] = a[2] * x;\n out[3] = a[3] * x;\n out[4] = a[4] * y;\n out[5] = a[5] * y;\n out[6] = a[6] * y;\n out[7] = a[7] * y;\n out[8] = a[8] * z;\n out[9] = a[9] * z;\n out[10] = a[10] * z;\n out[11] = a[11] * z;\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Scales the mat4 by the dimensions in the given vec3 using vectorization\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to scale\n * @param {vec3} v the vec3 to scale the matrix by\n * @returns {mat4} out\n **/\nmat4.SIMD.scale = function(out, a, v) {\n var a0, a1, a2;\n var vec = SIMD.Float32x4(v[0], v[1], v[2], 0);\n\n a0 = SIMD.Float32x4.load(a, 0);\n SIMD.Float32x4.store(\n out, 0, SIMD.Float32x4.mul(a0, SIMD.Float32x4.swizzle(vec, 0, 0, 0, 0)));\n\n a1 = SIMD.Float32x4.load(a, 4);\n SIMD.Float32x4.store(\n out, 4, SIMD.Float32x4.mul(a1, SIMD.Float32x4.swizzle(vec, 1, 1, 1, 1)));\n\n a2 = SIMD.Float32x4.load(a, 8);\n SIMD.Float32x4.store(\n out, 8, SIMD.Float32x4.mul(a2, SIMD.Float32x4.swizzle(vec, 2, 2, 2, 2)));\n\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n};\n\n/**\n * Scales the mat4 by the dimensions in the given vec3 using SIMD if available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to scale\n * @param {vec3} v the vec3 to scale the matrix by\n * @returns {mat4} out\n */\nmat4.scale = glMatrix.USE_SIMD ? mat4.SIMD.scale : mat4.scalar.scale;\n\n/**\n * Rotates a mat4 by the given angle around the given axis\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @param {vec3} axis the axis to rotate around\n * @returns {mat4} out\n */\nmat4.rotate = function (out, a, rad, axis) {\n var x = axis[0], y = axis[1], z = axis[2],\n len = Math.sqrt(x * x + y * y + z * z),\n s, c, t,\n a00, a01, a02, a03,\n a10, a11, a12, a13,\n a20, a21, a22, a23,\n b00, b01, b02,\n b10, b11, b12,\n b20, b21, b22;\n\n if (Math.abs(len) < glMatrix.EPSILON) { return null; }\n\n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c;\n\n a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];\n a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];\n a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];\n\n // Construct the elements of the rotation matrix\n b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;\n b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;\n b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;\n\n // Perform rotation-specific matrix multiplication\n out[0] = a00 * b00 + a10 * b01 + a20 * b02;\n out[1] = a01 * b00 + a11 * b01 + a21 * b02;\n out[2] = a02 * b00 + a12 * b01 + a22 * b02;\n out[3] = a03 * b00 + a13 * b01 + a23 * b02;\n out[4] = a00 * b10 + a10 * b11 + a20 * b12;\n out[5] = a01 * b10 + a11 * b11 + a21 * b12;\n out[6] = a02 * b10 + a12 * b11 + a22 * b12;\n out[7] = a03 * b10 + a13 * b11 + a23 * b12;\n out[8] = a00 * b20 + a10 * b21 + a20 * b22;\n out[9] = a01 * b20 + a11 * b21 + a21 * b22;\n out[10] = a02 * b20 + a12 * b21 + a22 * b22;\n out[11] = a03 * b20 + a13 * b21 + a23 * b22;\n\n if (a !== out) { // If the source and destination differ, copy the unchanged last row\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the X axis not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.scalar.rotateX = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7],\n a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[4] = a10 * c + a20 * s;\n out[5] = a11 * c + a21 * s;\n out[6] = a12 * c + a22 * s;\n out[7] = a13 * c + a23 * s;\n out[8] = a20 * c - a10 * s;\n out[9] = a21 * c - a11 * s;\n out[10] = a22 * c - a12 * s;\n out[11] = a23 * c - a13 * s;\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the X axis using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.SIMD.rotateX = function (out, a, rad) {\n var s = SIMD.Float32x4.splat(Math.sin(rad)),\n c = SIMD.Float32x4.splat(Math.cos(rad));\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n var a_1 = SIMD.Float32x4.load(a, 4);\n var a_2 = SIMD.Float32x4.load(a, 8);\n SIMD.Float32x4.store(out, 4,\n SIMD.Float32x4.add(SIMD.Float32x4.mul(a_1, c), SIMD.Float32x4.mul(a_2, s)));\n SIMD.Float32x4.store(out, 8,\n SIMD.Float32x4.sub(SIMD.Float32x4.mul(a_2, c), SIMD.Float32x4.mul(a_1, s)));\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the X axis using SIMD if availabe and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.rotateX = glMatrix.USE_SIMD ? mat4.SIMD.rotateX : mat4.scalar.rotateX;\n\n/**\n * Rotates a matrix by the given angle around the Y axis not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.scalar.rotateY = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3],\n a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[0] = a00 * c - a20 * s;\n out[1] = a01 * c - a21 * s;\n out[2] = a02 * c - a22 * s;\n out[3] = a03 * c - a23 * s;\n out[8] = a00 * s + a20 * c;\n out[9] = a01 * s + a21 * c;\n out[10] = a02 * s + a22 * c;\n out[11] = a03 * s + a23 * c;\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Y axis using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.SIMD.rotateY = function (out, a, rad) {\n var s = SIMD.Float32x4.splat(Math.sin(rad)),\n c = SIMD.Float32x4.splat(Math.cos(rad));\n\n if (a !== out) { // If the source and destination differ, copy the unchanged rows\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n var a_0 = SIMD.Float32x4.load(a, 0);\n var a_2 = SIMD.Float32x4.load(a, 8);\n SIMD.Float32x4.store(out, 0,\n SIMD.Float32x4.sub(SIMD.Float32x4.mul(a_0, c), SIMD.Float32x4.mul(a_2, s)));\n SIMD.Float32x4.store(out, 8,\n SIMD.Float32x4.add(SIMD.Float32x4.mul(a_0, s), SIMD.Float32x4.mul(a_2, c)));\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Y axis if SIMD available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\n mat4.rotateY = glMatrix.USE_SIMD ? mat4.SIMD.rotateY : mat4.scalar.rotateY;\n\n/**\n * Rotates a matrix by the given angle around the Z axis not using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.scalar.rotateZ = function (out, a, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad),\n a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3],\n a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n\n if (a !== out) { // If the source and destination differ, copy the unchanged last row\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n out[0] = a00 * c + a10 * s;\n out[1] = a01 * c + a11 * s;\n out[2] = a02 * c + a12 * s;\n out[3] = a03 * c + a13 * s;\n out[4] = a10 * c - a00 * s;\n out[5] = a11 * c - a01 * s;\n out[6] = a12 * c - a02 * s;\n out[7] = a13 * c - a03 * s;\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Z axis using SIMD\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.SIMD.rotateZ = function (out, a, rad) {\n var s = SIMD.Float32x4.splat(Math.sin(rad)),\n c = SIMD.Float32x4.splat(Math.cos(rad));\n\n if (a !== out) { // If the source and destination differ, copy the unchanged last row\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n // Perform axis-specific matrix multiplication\n var a_0 = SIMD.Float32x4.load(a, 0);\n var a_1 = SIMD.Float32x4.load(a, 4);\n SIMD.Float32x4.store(out, 0,\n SIMD.Float32x4.add(SIMD.Float32x4.mul(a_0, c), SIMD.Float32x4.mul(a_1, s)));\n SIMD.Float32x4.store(out, 4,\n SIMD.Float32x4.sub(SIMD.Float32x4.mul(a_1, c), SIMD.Float32x4.mul(a_0, s)));\n return out;\n};\n\n/**\n * Rotates a matrix by the given angle around the Z axis if SIMD available and enabled\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to rotate\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\n mat4.rotateZ = glMatrix.USE_SIMD ? mat4.SIMD.rotateZ : mat4.scalar.rotateZ;\n\n/**\n * Creates a matrix from a vector translation\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.translate(dest, dest, vec);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {vec3} v Translation vector\n * @returns {mat4} out\n */\nmat4.fromTranslation = function(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from a vector scaling\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.scale(dest, dest, vec);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {vec3} v Scaling vector\n * @returns {mat4} out\n */\nmat4.fromScaling = function(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = v[1];\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = v[2];\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from a given angle around a given axis\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.rotate(dest, dest, rad, axis);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @param {vec3} axis the axis to rotate around\n * @returns {mat4} out\n */\nmat4.fromRotation = function(out, rad, axis) {\n var x = axis[0], y = axis[1], z = axis[2],\n len = Math.sqrt(x * x + y * y + z * z),\n s, c, t;\n\n if (Math.abs(len) < glMatrix.EPSILON) { return null; }\n\n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c;\n\n // Perform rotation-specific matrix multiplication\n out[0] = x * x * t + c;\n out[1] = y * x * t + z * s;\n out[2] = z * x * t - y * s;\n out[3] = 0;\n out[4] = x * y * t - z * s;\n out[5] = y * y * t + c;\n out[6] = z * y * t + x * s;\n out[7] = 0;\n out[8] = x * z * t + y * s;\n out[9] = y * z * t - x * s;\n out[10] = z * z * t + c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from the given angle around the X axis\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.rotateX(dest, dest, rad);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.fromXRotation = function(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n\n // Perform axis-specific matrix multiplication\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = c;\n out[6] = s;\n out[7] = 0;\n out[8] = 0;\n out[9] = -s;\n out[10] = c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from the given angle around the Y axis\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.rotateY(dest, dest, rad);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.fromYRotation = function(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n\n // Perform axis-specific matrix multiplication\n out[0] = c;\n out[1] = 0;\n out[2] = -s;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = s;\n out[9] = 0;\n out[10] = c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from the given angle around the Z axis\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.rotateZ(dest, dest, rad);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {Number} rad the angle to rotate the matrix by\n * @returns {mat4} out\n */\nmat4.fromZRotation = function(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n\n // Perform axis-specific matrix multiplication\n out[0] = c;\n out[1] = s;\n out[2] = 0;\n out[3] = 0;\n out[4] = -s;\n out[5] = c;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n\n/**\n * Creates a matrix from a quaternion rotation and vector translation\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.translate(dest, vec);\n * var quatMat = mat4.create();\n * quat4.toMat4(quat, quatMat);\n * mat4.multiply(dest, quatMat);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat4} q Rotation quaternion\n * @param {vec3} v Translation vector\n * @returns {mat4} out\n */\nmat4.fromRotationTranslation = function (out, q, v) {\n // Quaternion math\n var x = q[0], y = q[1], z = q[2], w = q[3],\n x2 = x + x,\n y2 = y + y,\n z2 = z + z,\n\n xx = x * x2,\n xy = x * y2,\n xz = x * z2,\n yy = y * y2,\n yz = y * z2,\n zz = z * z2,\n wx = w * x2,\n wy = w * y2,\n wz = w * z2;\n\n out[0] = 1 - (yy + zz);\n out[1] = xy + wz;\n out[2] = xz - wy;\n out[3] = 0;\n out[4] = xy - wz;\n out[5] = 1 - (xx + zz);\n out[6] = yz + wx;\n out[7] = 0;\n out[8] = xz + wy;\n out[9] = yz - wx;\n out[10] = 1 - (xx + yy);\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n\n return out;\n};\n\n/**\n * Returns the translation vector component of a transformation\n * matrix. If a matrix is built with fromRotationTranslation,\n * the returned vector will be the same as the translation vector\n * originally supplied.\n * @param {vec3} out Vector to receive translation component\n * @param {mat4} mat Matrix to be decomposed (input)\n * @return {vec3} out\n */\nmat4.getTranslation = function (out, mat) {\n out[0] = mat[12];\n out[1] = mat[13];\n out[2] = mat[14];\n\n return out;\n};\n\n/**\n * Returns a quaternion representing the rotational component\n * of a transformation matrix. If a matrix is built with\n * fromRotationTranslation, the returned quaternion will be the\n * same as the quaternion originally supplied.\n * @param {quat} out Quaternion to receive the rotation component\n * @param {mat4} mat Matrix to be decomposed (input)\n * @return {quat} out\n */\nmat4.getRotation = function (out, mat) {\n // Algorithm taken from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm\n var trace = mat[0] + mat[5] + mat[10];\n var S = 0;\n\n if (trace > 0) { \n S = Math.sqrt(trace + 1.0) * 2;\n out[3] = 0.25 * S;\n out[0] = (mat[6] - mat[9]) / S;\n out[1] = (mat[8] - mat[2]) / S; \n out[2] = (mat[1] - mat[4]) / S; \n } else if ((mat[0] > mat[5])&(mat[0] > mat[10])) { \n S = Math.sqrt(1.0 + mat[0] - mat[5] - mat[10]) * 2;\n out[3] = (mat[6] - mat[9]) / S;\n out[0] = 0.25 * S;\n out[1] = (mat[1] + mat[4]) / S; \n out[2] = (mat[8] + mat[2]) / S; \n } else if (mat[5] > mat[10]) { \n S = Math.sqrt(1.0 + mat[5] - mat[0] - mat[10]) * 2;\n out[3] = (mat[8] - mat[2]) / S;\n out[0] = (mat[1] + mat[4]) / S; \n out[1] = 0.25 * S;\n out[2] = (mat[6] + mat[9]) / S; \n } else { \n S = Math.sqrt(1.0 + mat[10] - mat[0] - mat[5]) * 2;\n out[3] = (mat[1] - mat[4]) / S;\n out[0] = (mat[8] + mat[2]) / S;\n out[1] = (mat[6] + mat[9]) / S;\n out[2] = 0.25 * S;\n }\n\n return out;\n};\n\n/**\n * Creates a matrix from a quaternion rotation, vector translation and vector scale\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.translate(dest, vec);\n * var quatMat = mat4.create();\n * quat4.toMat4(quat, quatMat);\n * mat4.multiply(dest, quatMat);\n * mat4.scale(dest, scale)\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat4} q Rotation quaternion\n * @param {vec3} v Translation vector\n * @param {vec3} s Scaling vector\n * @returns {mat4} out\n */\nmat4.fromRotationTranslationScale = function (out, q, v, s) {\n // Quaternion math\n var x = q[0], y = q[1], z = q[2], w = q[3],\n x2 = x + x,\n y2 = y + y,\n z2 = z + z,\n\n xx = x * x2,\n xy = x * y2,\n xz = x * z2,\n yy = y * y2,\n yz = y * z2,\n zz = z * z2,\n wx = w * x2,\n wy = w * y2,\n wz = w * z2,\n sx = s[0],\n sy = s[1],\n sz = s[2];\n\n out[0] = (1 - (yy + zz)) * sx;\n out[1] = (xy + wz) * sx;\n out[2] = (xz - wy) * sx;\n out[3] = 0;\n out[4] = (xy - wz) * sy;\n out[5] = (1 - (xx + zz)) * sy;\n out[6] = (yz + wx) * sy;\n out[7] = 0;\n out[8] = (xz + wy) * sz;\n out[9] = (yz - wx) * sz;\n out[10] = (1 - (xx + yy)) * sz;\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n\n return out;\n};\n\n/**\n * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin\n * This is equivalent to (but much faster than):\n *\n * mat4.identity(dest);\n * mat4.translate(dest, vec);\n * mat4.translate(dest, origin);\n * var quatMat = mat4.create();\n * quat4.toMat4(quat, quatMat);\n * mat4.multiply(dest, quatMat);\n * mat4.scale(dest, scale)\n * mat4.translate(dest, negativeOrigin);\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat4} q Rotation quaternion\n * @param {vec3} v Translation vector\n * @param {vec3} s Scaling vector\n * @param {vec3} o The origin vector around which to scale and rotate\n * @returns {mat4} out\n */\nmat4.fromRotationTranslationScaleOrigin = function (out, q, v, s, o) {\n // Quaternion math\n var x = q[0], y = q[1], z = q[2], w = q[3],\n x2 = x + x,\n y2 = y + y,\n z2 = z + z,\n\n xx = x * x2,\n xy = x * y2,\n xz = x * z2,\n yy = y * y2,\n yz = y * z2,\n zz = z * z2,\n wx = w * x2,\n wy = w * y2,\n wz = w * z2,\n\n sx = s[0],\n sy = s[1],\n sz = s[2],\n\n ox = o[0],\n oy = o[1],\n oz = o[2];\n\n out[0] = (1 - (yy + zz)) * sx;\n out[1] = (xy + wz) * sx;\n out[2] = (xz - wy) * sx;\n out[3] = 0;\n out[4] = (xy - wz) * sy;\n out[5] = (1 - (xx + zz)) * sy;\n out[6] = (yz + wx) * sy;\n out[7] = 0;\n out[8] = (xz + wy) * sz;\n out[9] = (yz - wx) * sz;\n out[10] = (1 - (xx + yy)) * sz;\n out[11] = 0;\n out[12] = v[0] + ox - (out[0] * ox + out[4] * oy + out[8] * oz);\n out[13] = v[1] + oy - (out[1] * ox + out[5] * oy + out[9] * oz);\n out[14] = v[2] + oz - (out[2] * ox + out[6] * oy + out[10] * oz);\n out[15] = 1;\n\n return out;\n};\n\n/**\n * Calculates a 4x4 matrix from the given quaternion\n *\n * @param {mat4} out mat4 receiving operation result\n * @param {quat} q Quaternion to create matrix from\n *\n * @returns {mat4} out\n */\nmat4.fromQuat = function (out, q) {\n var x = q[0], y = q[1], z = q[2], w = q[3],\n x2 = x + x,\n y2 = y + y,\n z2 = z + z,\n\n xx = x * x2,\n yx = y * x2,\n yy = y * y2,\n zx = z * x2,\n zy = z * y2,\n zz = z * z2,\n wx = w * x2,\n wy = w * y2,\n wz = w * z2;\n\n out[0] = 1 - yy - zz;\n out[1] = yx + wz;\n out[2] = zx - wy;\n out[3] = 0;\n\n out[4] = yx - wz;\n out[5] = 1 - xx - zz;\n out[6] = zy + wx;\n out[7] = 0;\n\n out[8] = zx + wy;\n out[9] = zy - wx;\n out[10] = 1 - xx - yy;\n out[11] = 0;\n\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n\n return out;\n};\n\n/**\n * Generates a frustum matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {Number} left Left bound of the frustum\n * @param {Number} right Right bound of the frustum\n * @param {Number} bottom Bottom bound of the frustum\n * @param {Number} top Top bound of the frustum\n * @param {Number} near Near bound of the frustum\n * @param {Number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.frustum = function (out, left, right, bottom, top, near, far) {\n var rl = 1 / (right - left),\n tb = 1 / (top - bottom),\n nf = 1 / (near - far);\n out[0] = (near * 2) * rl;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = (near * 2) * tb;\n out[6] = 0;\n out[7] = 0;\n out[8] = (right + left) * rl;\n out[9] = (top + bottom) * tb;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = (far * near * 2) * nf;\n out[15] = 0;\n return out;\n};\n\n/**\n * Generates a perspective projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} fovy Vertical field of view in radians\n * @param {number} aspect Aspect ratio. typically viewport width/height\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.perspective = function (out, fovy, aspect, near, far) {\n var f = 1.0 / Math.tan(fovy / 2),\n nf = 1 / (near - far);\n out[0] = f / aspect;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = f;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = (2 * far * near) * nf;\n out[15] = 0;\n return out;\n};\n\n/**\n * Generates a perspective projection matrix with the given field of view.\n * This is primarily useful for generating projection matrices to be used\n * with the still experiemental WebVR API.\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.perspectiveFromFieldOfView = function (out, fov, near, far) {\n var upTan = Math.tan(fov.upDegrees * Math.PI/180.0),\n downTan = Math.tan(fov.downDegrees * Math.PI/180.0),\n leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0),\n rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0),\n xScale = 2.0 / (leftTan + rightTan),\n yScale = 2.0 / (upTan + downTan);\n\n out[0] = xScale;\n out[1] = 0.0;\n out[2] = 0.0;\n out[3] = 0.0;\n out[4] = 0.0;\n out[5] = yScale;\n out[6] = 0.0;\n out[7] = 0.0;\n out[8] = -((leftTan - rightTan) * xScale * 0.5);\n out[9] = ((upTan - downTan) * yScale * 0.5);\n out[10] = far / (near - far);\n out[11] = -1.0;\n out[12] = 0.0;\n out[13] = 0.0;\n out[14] = (far * near) / (near - far);\n out[15] = 0.0;\n return out;\n}\n\n/**\n * Generates a orthogonal projection matrix with the given bounds\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {number} left Left bound of the frustum\n * @param {number} right Right bound of the frustum\n * @param {number} bottom Bottom bound of the frustum\n * @param {number} top Top bound of the frustum\n * @param {number} near Near bound of the frustum\n * @param {number} far Far bound of the frustum\n * @returns {mat4} out\n */\nmat4.ortho = function (out, left, right, bottom, top, near, far) {\n var lr = 1 / (left - right),\n bt = 1 / (bottom - top),\n nf = 1 / (near - far);\n out[0] = -2 * lr;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = -2 * bt;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 2 * nf;\n out[11] = 0;\n out[12] = (left + right) * lr;\n out[13] = (top + bottom) * bt;\n out[14] = (far + near) * nf;\n out[15] = 1;\n return out;\n};\n\n/**\n * Generates a look-at matrix with the given eye position, focal point, and up axis\n *\n * @param {mat4} out mat4 frustum matrix will be written into\n * @param {vec3} eye Position of the viewer\n * @param {vec3} center Point the viewer is looking at\n * @param {vec3} up vec3 pointing up\n * @returns {mat4} out\n */\nmat4.lookAt = function (out, eye, center, up) {\n var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,\n eyex = eye[0],\n eyey = eye[1],\n eyez = eye[2],\n upx = up[0],\n upy = up[1],\n upz = up[2],\n centerx = center[0],\n centery = center[1],\n centerz = center[2];\n\n if (Math.abs(eyex - centerx) < glMatrix.EPSILON &&\n Math.abs(eyey - centery) < glMatrix.EPSILON &&\n Math.abs(eyez - centerz) < glMatrix.EPSILON) {\n return mat4.identity(out);\n }\n\n z0 = eyex - centerx;\n z1 = eyey - centery;\n z2 = eyez - centerz;\n\n len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);\n z0 *= len;\n z1 *= len;\n z2 *= len;\n\n x0 = upy * z2 - upz * z1;\n x1 = upz * z0 - upx * z2;\n x2 = upx * z1 - upy * z0;\n len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);\n if (!len) {\n x0 = 0;\n x1 = 0;\n x2 = 0;\n } else {\n len = 1 / len;\n x0 *= len;\n x1 *= len;\n x2 *= len;\n }\n\n y0 = z1 * x2 - z2 * x1;\n y1 = z2 * x0 - z0 * x2;\n y2 = z0 * x1 - z1 * x0;\n\n len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);\n if (!len) {\n y0 = 0;\n y1 = 0;\n y2 = 0;\n } else {\n len = 1 / len;\n y0 *= len;\n y1 *= len;\n y2 *= len;\n }\n\n out[0] = x0;\n out[1] = y0;\n out[2] = z0;\n out[3] = 0;\n out[4] = x1;\n out[5] = y1;\n out[6] = z1;\n out[7] = 0;\n out[8] = x2;\n out[9] = y2;\n out[10] = z2;\n out[11] = 0;\n out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);\n out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);\n out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);\n out[15] = 1;\n\n return out;\n};\n\n/**\n * Returns a string representation of a mat4\n *\n * @param {mat4} mat matrix to represent as a string\n * @returns {String} string representation of the matrix\n */\nmat4.str = function (a) {\n return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +\n a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +\n a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +\n a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';\n};\n\n/**\n * Returns Frobenius norm of a mat4\n *\n * @param {mat4} a the matrix to calculate Frobenius norm of\n * @returns {Number} Frobenius norm\n */\nmat4.frob = function (a) {\n return(Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2) ))\n};\n\n/**\n * Adds two mat4's\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @returns {mat4} out\n */\nmat4.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n out[6] = a[6] + b[6];\n out[7] = a[7] + b[7];\n out[8] = a[8] + b[8];\n out[9] = a[9] + b[9];\n out[10] = a[10] + b[10];\n out[11] = a[11] + b[11];\n out[12] = a[12] + b[12];\n out[13] = a[13] + b[13];\n out[14] = a[14] + b[14];\n out[15] = a[15] + b[15];\n return out;\n};\n\n/**\n * Subtracts matrix b from matrix a\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @returns {mat4} out\n */\nmat4.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n out[6] = a[6] - b[6];\n out[7] = a[7] - b[7];\n out[8] = a[8] - b[8];\n out[9] = a[9] - b[9];\n out[10] = a[10] - b[10];\n out[11] = a[11] - b[11];\n out[12] = a[12] - b[12];\n out[13] = a[13] - b[13];\n out[14] = a[14] - b[14];\n out[15] = a[15] - b[15];\n return out;\n};\n\n/**\n * Alias for {@link mat4.subtract}\n * @function\n */\nmat4.sub = mat4.subtract;\n\n/**\n * Multiply each element of the matrix by a scalar.\n *\n * @param {mat4} out the receiving matrix\n * @param {mat4} a the matrix to scale\n * @param {Number} b amount to scale the matrix's elements by\n * @returns {mat4} out\n */\nmat4.multiplyScalar = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n out[6] = a[6] * b;\n out[7] = a[7] * b;\n out[8] = a[8] * b;\n out[9] = a[9] * b;\n out[10] = a[10] * b;\n out[11] = a[11] * b;\n out[12] = a[12] * b;\n out[13] = a[13] * b;\n out[14] = a[14] * b;\n out[15] = a[15] * b;\n return out;\n};\n\n/**\n * Adds two mat4's after multiplying each element of the second operand by a scalar value.\n *\n * @param {mat4} out the receiving vector\n * @param {mat4} a the first operand\n * @param {mat4} b the second operand\n * @param {Number} scale the amount to scale b's elements by before adding\n * @returns {mat4} out\n */\nmat4.multiplyScalarAndAdd = function(out, a, b, scale) {\n out[0] = a[0] + (b[0] * scale);\n out[1] = a[1] + (b[1] * scale);\n out[2] = a[2] + (b[2] * scale);\n out[3] = a[3] + (b[3] * scale);\n out[4] = a[4] + (b[4] * scale);\n out[5] = a[5] + (b[5] * scale);\n out[6] = a[6] + (b[6] * scale);\n out[7] = a[7] + (b[7] * scale);\n out[8] = a[8] + (b[8] * scale);\n out[9] = a[9] + (b[9] * scale);\n out[10] = a[10] + (b[10] * scale);\n out[11] = a[11] + (b[11] * scale);\n out[12] = a[12] + (b[12] * scale);\n out[13] = a[13] + (b[13] * scale);\n out[14] = a[14] + (b[14] * scale);\n out[15] = a[15] + (b[15] * scale);\n return out;\n};\n\n/**\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\n *\n * @param {mat4} a The first matrix.\n * @param {mat4} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat4.exactEquals = function (a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && \n a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && \n a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] &&\n a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];\n};\n\n/**\n * Returns whether or not the matrices have approximately the same elements in the same position.\n *\n * @param {mat4} a The first matrix.\n * @param {mat4} b The second matrix.\n * @returns {Boolean} True if the matrices are equal, false otherwise.\n */\nmat4.equals = function (a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7], \n a8 = a[8], a9 = a[9], a10 = a[10], a11 = a[11], \n a12 = a[12], a13 = a[13], a14 = a[14], a15 = a[15];\n\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3],\n b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], \n b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], \n b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];\n\n return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&\n Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&\n Math.abs(a4 - b4) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&\n Math.abs(a5 - b5) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&\n Math.abs(a6 - b6) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&\n Math.abs(a7 - b7) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&\n Math.abs(a8 - b8) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a8), Math.abs(b8)) &&\n Math.abs(a9 - b9) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a9), Math.abs(b9)) &&\n Math.abs(a10 - b10) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a10), Math.abs(b10)) &&\n Math.abs(a11 - b11) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a11), Math.abs(b11)) &&\n Math.abs(a12 - b12) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a12), Math.abs(b12)) &&\n Math.abs(a13 - b13) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a13), Math.abs(b13)) &&\n Math.abs(a14 - b14) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a14), Math.abs(b14)) &&\n Math.abs(a15 - b15) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a15), Math.abs(b15)));\n};\n\n\n\nmodule.exports = mat4;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\nvar mat3 = require(\"./mat3.js\");\nvar vec3 = require(\"./vec3.js\");\nvar vec4 = require(\"./vec4.js\");\n\n/**\n * @class Quaternion\n * @name quat\n */\nvar quat = {};\n\n/**\n * Creates a new identity quat\n *\n * @returns {quat} a new quaternion\n */\nquat.create = function() {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Sets a quaternion to represent the shortest rotation from one\n * vector to another.\n *\n * Both vectors are assumed to be unit length.\n *\n * @param {quat} out the receiving quaternion.\n * @param {vec3} a the initial vector\n * @param {vec3} b the destination vector\n * @returns {quat} out\n */\nquat.rotationTo = (function() {\n var tmpvec3 = vec3.create();\n var xUnitVec3 = vec3.fromValues(1,0,0);\n var yUnitVec3 = vec3.fromValues(0,1,0);\n\n return function(out, a, b) {\n var dot = vec3.dot(a, b);\n if (dot < -0.999999) {\n vec3.cross(tmpvec3, xUnitVec3, a);\n if (vec3.length(tmpvec3) < 0.000001)\n vec3.cross(tmpvec3, yUnitVec3, a);\n vec3.normalize(tmpvec3, tmpvec3);\n quat.setAxisAngle(out, tmpvec3, Math.PI);\n return out;\n } else if (dot > 0.999999) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n } else {\n vec3.cross(tmpvec3, a, b);\n out[0] = tmpvec3[0];\n out[1] = tmpvec3[1];\n out[2] = tmpvec3[2];\n out[3] = 1 + dot;\n return quat.normalize(out, out);\n }\n };\n})();\n\n/**\n * Sets the specified quaternion with values corresponding to the given\n * axes. Each axis is a vec3 and is expected to be unit length and\n * perpendicular to all other specified axes.\n *\n * @param {vec3} view the vector representing the viewing direction\n * @param {vec3} right the vector representing the local \"right\" direction\n * @param {vec3} up the vector representing the local \"up\" direction\n * @returns {quat} out\n */\nquat.setAxes = (function() {\n var matr = mat3.create();\n\n return function(out, view, right, up) {\n matr[0] = right[0];\n matr[3] = right[1];\n matr[6] = right[2];\n\n matr[1] = up[0];\n matr[4] = up[1];\n matr[7] = up[2];\n\n matr[2] = -view[0];\n matr[5] = -view[1];\n matr[8] = -view[2];\n\n return quat.normalize(out, quat.fromMat3(out, matr));\n };\n})();\n\n/**\n * Creates a new quat initialized with values from an existing quaternion\n *\n * @param {quat} a quaternion to clone\n * @returns {quat} a new quaternion\n * @function\n */\nquat.clone = vec4.clone;\n\n/**\n * Creates a new quat initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {quat} a new quaternion\n * @function\n */\nquat.fromValues = vec4.fromValues;\n\n/**\n * Copy the values from one quat to another\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the source quaternion\n * @returns {quat} out\n * @function\n */\nquat.copy = vec4.copy;\n\n/**\n * Set the components of a quat to the given values\n *\n * @param {quat} out the receiving quaternion\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {quat} out\n * @function\n */\nquat.set = vec4.set;\n\n/**\n * Set a quat to the identity quaternion\n *\n * @param {quat} out the receiving quaternion\n * @returns {quat} out\n */\nquat.identity = function(out) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n};\n\n/**\n * Sets a quat from the given angle and rotation axis,\n * then returns it.\n *\n * @param {quat} out the receiving quaternion\n * @param {vec3} axis the axis around which to rotate\n * @param {Number} rad the angle in radians\n * @returns {quat} out\n **/\nquat.setAxisAngle = function(out, axis, rad) {\n rad = rad * 0.5;\n var s = Math.sin(rad);\n out[0] = s * axis[0];\n out[1] = s * axis[1];\n out[2] = s * axis[2];\n out[3] = Math.cos(rad);\n return out;\n};\n\n/**\n * Gets the rotation axis and angle for a given\n * quaternion. If a quaternion is created with\n * setAxisAngle, this method will return the same\n * values as providied in the original parameter list\n * OR functionally equivalent values.\n * Example: The quaternion formed by axis [0, 0, 1] and\n * angle -90 is the same as the quaternion formed by\n * [0, 0, 1] and 270. This method favors the latter.\n * @param {vec3} out_axis Vector receiving the axis of rotation\n * @param {quat} q Quaternion to be decomposed\n * @return {Number} Angle, in radians, of the rotation\n */\nquat.getAxisAngle = function(out_axis, q) {\n var rad = Math.acos(q[3]) * 2.0;\n var s = Math.sin(rad / 2.0);\n if (s != 0.0) {\n out_axis[0] = q[0] / s;\n out_axis[1] = q[1] / s;\n out_axis[2] = q[2] / s;\n } else {\n // If s is zero, return any axis (no rotation - axis does not matter)\n out_axis[0] = 1;\n out_axis[1] = 0;\n out_axis[2] = 0;\n }\n return rad;\n};\n\n/**\n * Adds two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {quat} out\n * @function\n */\nquat.add = vec4.add;\n\n/**\n * Multiplies two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {quat} out\n */\nquat.multiply = function(out, a, b) {\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = b[0], by = b[1], bz = b[2], bw = b[3];\n\n out[0] = ax * bw + aw * bx + ay * bz - az * by;\n out[1] = ay * bw + aw * by + az * bx - ax * bz;\n out[2] = az * bw + aw * bz + ax * by - ay * bx;\n out[3] = aw * bw - ax * bx - ay * by - az * bz;\n return out;\n};\n\n/**\n * Alias for {@link quat.multiply}\n * @function\n */\nquat.mul = quat.multiply;\n\n/**\n * Scales a quat by a scalar number\n *\n * @param {quat} out the receiving vector\n * @param {quat} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {quat} out\n * @function\n */\nquat.scale = vec4.scale;\n\n/**\n * Rotates a quaternion by the given angle about the X axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateX = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw + aw * bx;\n out[1] = ay * bw + az * bx;\n out[2] = az * bw - ay * bx;\n out[3] = aw * bw - ax * bx;\n return out;\n};\n\n/**\n * Rotates a quaternion by the given angle about the Y axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateY = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n by = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw - az * by;\n out[1] = ay * bw + aw * by;\n out[2] = az * bw + ax * by;\n out[3] = aw * bw - ay * by;\n return out;\n};\n\n/**\n * Rotates a quaternion by the given angle about the Z axis\n *\n * @param {quat} out quat receiving operation result\n * @param {quat} a quat to rotate\n * @param {number} rad angle (in radians) to rotate\n * @returns {quat} out\n */\nquat.rotateZ = function (out, a, rad) {\n rad *= 0.5; \n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bz = Math.sin(rad), bw = Math.cos(rad);\n\n out[0] = ax * bw + ay * bz;\n out[1] = ay * bw - ax * bz;\n out[2] = az * bw + aw * bz;\n out[3] = aw * bw - az * bz;\n return out;\n};\n\n/**\n * Calculates the W component of a quat from the X, Y, and Z components.\n * Assumes that quaternion is 1 unit in length.\n * Any existing W component will be ignored.\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate W component of\n * @returns {quat} out\n */\nquat.calculateW = function (out, a) {\n var x = a[0], y = a[1], z = a[2];\n\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));\n return out;\n};\n\n/**\n * Calculates the dot product of two quat's\n *\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @returns {Number} dot product of a and b\n * @function\n */\nquat.dot = vec4.dot;\n\n/**\n * Performs a linear interpolation between two quat's\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {quat} out\n * @function\n */\nquat.lerp = vec4.lerp;\n\n/**\n * Performs a spherical linear interpolation between two quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {quat} out\n */\nquat.slerp = function (out, a, b, t) {\n // benchmarks:\n // http://jsperf.com/quaternion-slerp-implementations\n\n var ax = a[0], ay = a[1], az = a[2], aw = a[3],\n bx = b[0], by = b[1], bz = b[2], bw = b[3];\n\n var omega, cosom, sinom, scale0, scale1;\n\n // calc cosine\n cosom = ax * bx + ay * by + az * bz + aw * bw;\n // adjust signs (if necessary)\n if ( cosom < 0.0 ) {\n cosom = -cosom;\n bx = - bx;\n by = - by;\n bz = - bz;\n bw = - bw;\n }\n // calculate coefficients\n if ( (1.0 - cosom) > 0.000001 ) {\n // standard case (slerp)\n omega = Math.acos(cosom);\n sinom = Math.sin(omega);\n scale0 = Math.sin((1.0 - t) * omega) / sinom;\n scale1 = Math.sin(t * omega) / sinom;\n } else { \n // \"from\" and \"to\" quaternions are very close \n // ... so we can do a linear interpolation\n scale0 = 1.0 - t;\n scale1 = t;\n }\n // calculate final values\n out[0] = scale0 * ax + scale1 * bx;\n out[1] = scale0 * ay + scale1 * by;\n out[2] = scale0 * az + scale1 * bz;\n out[3] = scale0 * aw + scale1 * bw;\n \n return out;\n};\n\n/**\n * Performs a spherical linear interpolation with two control points\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a the first operand\n * @param {quat} b the second operand\n * @param {quat} c the third operand\n * @param {quat} d the fourth operand\n * @param {Number} t interpolation amount\n * @returns {quat} out\n */\nquat.sqlerp = (function () {\n var temp1 = quat.create();\n var temp2 = quat.create();\n \n return function (out, a, b, c, d, t) {\n quat.slerp(temp1, a, d, t);\n quat.slerp(temp2, b, c, t);\n quat.slerp(out, temp1, temp2, 2 * t * (1 - t));\n \n return out;\n };\n}());\n\n/**\n * Calculates the inverse of a quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate inverse of\n * @returns {quat} out\n */\nquat.invert = function(out, a) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],\n dot = a0*a0 + a1*a1 + a2*a2 + a3*a3,\n invDot = dot ? 1.0/dot : 0;\n \n // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0\n\n out[0] = -a0*invDot;\n out[1] = -a1*invDot;\n out[2] = -a2*invDot;\n out[3] = a3*invDot;\n return out;\n};\n\n/**\n * Calculates the conjugate of a quat\n * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quat to calculate conjugate of\n * @returns {quat} out\n */\nquat.conjugate = function (out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Calculates the length of a quat\n *\n * @param {quat} a vector to calculate length of\n * @returns {Number} length of a\n * @function\n */\nquat.length = vec4.length;\n\n/**\n * Alias for {@link quat.length}\n * @function\n */\nquat.len = quat.length;\n\n/**\n * Calculates the squared length of a quat\n *\n * @param {quat} a vector to calculate squared length of\n * @returns {Number} squared length of a\n * @function\n */\nquat.squaredLength = vec4.squaredLength;\n\n/**\n * Alias for {@link quat.squaredLength}\n * @function\n */\nquat.sqrLen = quat.squaredLength;\n\n/**\n * Normalize a quat\n *\n * @param {quat} out the receiving quaternion\n * @param {quat} a quaternion to normalize\n * @returns {quat} out\n * @function\n */\nquat.normalize = vec4.normalize;\n\n/**\n * Creates a quaternion from the given 3x3 rotation matrix.\n *\n * NOTE: The resultant quaternion is not normalized, so you should be sure\n * to renormalize the quaternion yourself where necessary.\n *\n * @param {quat} out the receiving quaternion\n * @param {mat3} m rotation matrix\n * @returns {quat} out\n * @function\n */\nquat.fromMat3 = function(out, m) {\n // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes\n // article \"Quaternion Calculus and Fast Animation\".\n var fTrace = m[0] + m[4] + m[8];\n var fRoot;\n\n if ( fTrace > 0.0 ) {\n // |w| > 1/2, may as well choose w > 1/2\n fRoot = Math.sqrt(fTrace + 1.0); // 2w\n out[3] = 0.5 * fRoot;\n fRoot = 0.5/fRoot; // 1/(4w)\n out[0] = (m[5]-m[7])*fRoot;\n out[1] = (m[6]-m[2])*fRoot;\n out[2] = (m[1]-m[3])*fRoot;\n } else {\n // |w| <= 1/2\n var i = 0;\n if ( m[4] > m[0] )\n i = 1;\n if ( m[8] > m[i*3+i] )\n i = 2;\n var j = (i+1)%3;\n var k = (i+2)%3;\n \n fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0);\n out[i] = 0.5 * fRoot;\n fRoot = 0.5 / fRoot;\n out[3] = (m[j*3+k] - m[k*3+j]) * fRoot;\n out[j] = (m[j*3+i] + m[i*3+j]) * fRoot;\n out[k] = (m[k*3+i] + m[i*3+k]) * fRoot;\n }\n \n return out;\n};\n\n/**\n * Returns a string representation of a quatenion\n *\n * @param {quat} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nquat.str = function (a) {\n return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\n/**\n * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)\n *\n * @param {quat} a The first quaternion.\n * @param {quat} b The second quaternion.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nquat.exactEquals = vec4.exactEquals;\n\n/**\n * Returns whether or not the quaternions have approximately the same elements in the same position.\n *\n * @param {quat} a The first vector.\n * @param {quat} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nquat.equals = vec4.equals;\n\nmodule.exports = quat;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\n\n/**\n * @class 2 Dimensional Vector\n * @name vec2\n */\nvar vec2 = {};\n\n/**\n * Creates a new, empty vec2\n *\n * @returns {vec2} a new 2D vector\n */\nvec2.create = function() {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = 0;\n out[1] = 0;\n return out;\n};\n\n/**\n * Creates a new vec2 initialized with values from an existing vector\n *\n * @param {vec2} a vector to clone\n * @returns {vec2} a new 2D vector\n */\nvec2.clone = function(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n};\n\n/**\n * Creates a new vec2 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} a new 2D vector\n */\nvec2.fromValues = function(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n};\n\n/**\n * Copy the values from one vec2 to another\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the source vector\n * @returns {vec2} out\n */\nvec2.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n};\n\n/**\n * Set the components of a vec2 to the given values\n *\n * @param {vec2} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @returns {vec2} out\n */\nvec2.set = function(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n};\n\n/**\n * Adds two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n};\n\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n};\n\n/**\n * Alias for {@link vec2.subtract}\n * @function\n */\nvec2.sub = vec2.subtract;\n\n/**\n * Multiplies two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n};\n\n/**\n * Alias for {@link vec2.multiply}\n * @function\n */\nvec2.mul = vec2.multiply;\n\n/**\n * Divides two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n};\n\n/**\n * Alias for {@link vec2.divide}\n * @function\n */\nvec2.div = vec2.divide;\n\n/**\n * Math.ceil the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to ceil\n * @returns {vec2} out\n */\nvec2.ceil = function (out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n};\n\n/**\n * Math.floor the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to floor\n * @returns {vec2} out\n */\nvec2.floor = function (out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n};\n\n/**\n * Returns the minimum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec2} out\n */\nvec2.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n};\n\n/**\n * Math.round the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to round\n * @returns {vec2} out\n */\nvec2.round = function (out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n};\n\n/**\n * Scales a vec2 by a scalar number\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec2} out\n */\nvec2.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n};\n\n/**\n * Adds two vec2's after scaling the second operand by a scalar value\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec2} out\n */\nvec2.scaleAndAdd = function(out, a, b, scale) {\n out[0] = a[0] + (b[0] * scale);\n out[1] = a[1] + (b[1] * scale);\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} distance between a and b\n */\nvec2.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.sqrt(x*x + y*y);\n};\n\n/**\n * Alias for {@link vec2.distance}\n * @function\n */\nvec2.dist = vec2.distance;\n\n/**\n * Calculates the squared euclidian distance between two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec2.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x*x + y*y;\n};\n\n/**\n * Alias for {@link vec2.squaredDistance}\n * @function\n */\nvec2.sqrDist = vec2.squaredDistance;\n\n/**\n * Calculates the length of a vec2\n *\n * @param {vec2} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec2.length = function (a) {\n var x = a[0],\n y = a[1];\n return Math.sqrt(x*x + y*y);\n};\n\n/**\n * Alias for {@link vec2.length}\n * @function\n */\nvec2.len = vec2.length;\n\n/**\n * Calculates the squared length of a vec2\n *\n * @param {vec2} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec2.squaredLength = function (a) {\n var x = a[0],\n y = a[1];\n return x*x + y*y;\n};\n\n/**\n * Alias for {@link vec2.squaredLength}\n * @function\n */\nvec2.sqrLen = vec2.squaredLength;\n\n/**\n * Negates the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to negate\n * @returns {vec2} out\n */\nvec2.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n};\n\n/**\n * Returns the inverse of the components of a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to invert\n * @returns {vec2} out\n */\nvec2.inverse = function(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n};\n\n/**\n * Normalize a vec2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a vector to normalize\n * @returns {vec2} out\n */\nvec2.normalize = function(out, a) {\n var x = a[0],\n y = a[1];\n var len = x*x + y*y;\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n }\n return out;\n};\n\n/**\n * Calculates the dot product of two vec2's\n *\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec2.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1];\n};\n\n/**\n * Computes the cross product of two vec2's\n * Note that the cross product must by definition produce a 3D vector\n *\n * @param {vec3} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @returns {vec3} out\n */\nvec2.cross = function(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n};\n\n/**\n * Performs a linear interpolation between two vec2's\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the first operand\n * @param {vec2} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec2} out\n */\nvec2.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n};\n\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec2} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec2} out\n */\nvec2.random = function (out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n};\n\n/**\n * Transforms the vec2 with a mat2\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to transform\n * @param {mat2} m matrix to transform with\n * @returns {vec2} out\n */\nvec2.transformMat2 = function(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n};\n\n/**\n * Transforms the vec2 with a mat2d\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to transform\n * @param {mat2d} m matrix to transform with\n * @returns {vec2} out\n */\nvec2.transformMat2d = function(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n};\n\n/**\n * Transforms the vec2 with a mat3\n * 3rd vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to transform\n * @param {mat3} m matrix to transform with\n * @returns {vec2} out\n */\nvec2.transformMat3 = function(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n};\n\n/**\n * Transforms the vec2 with a mat4\n * 3rd vector component is implicitly '0'\n * 4th vector component is implicitly '1'\n *\n * @param {vec2} out the receiving vector\n * @param {vec2} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec2} out\n */\nvec2.transformMat4 = function(out, a, m) {\n var x = a[0], \n y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n};\n\n/**\n * Perform some operation over an array of vec2s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\nvec2.forEach = (function() {\n var vec = vec2.create();\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 2;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec2} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec2.str = function (a) {\n return 'vec2(' + a[0] + ', ' + a[1] + ')';\n};\n\n/**\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\n *\n * @param {vec2} a The first vector.\n * @param {vec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nvec2.exactEquals = function (a, b) {\n return a[0] === b[0] && a[1] === b[1];\n};\n\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {vec2} a The first vector.\n * @param {vec2} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nvec2.equals = function (a, b) {\n var a0 = a[0], a1 = a[1];\n var b0 = b[0], b1 = b[1];\n return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)));\n};\n\nmodule.exports = vec2;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\n\n/**\n * @class 3 Dimensional Vector\n * @name vec3\n */\nvar vec3 = {};\n\n/**\n * Creates a new, empty vec3\n *\n * @returns {vec3} a new 3D vector\n */\nvec3.create = function() {\n var out = new glMatrix.ARRAY_TYPE(3);\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n return out;\n};\n\n/**\n * Creates a new vec3 initialized with values from an existing vector\n *\n * @param {vec3} a vector to clone\n * @returns {vec3} a new 3D vector\n */\nvec3.clone = function(a) {\n var out = new glMatrix.ARRAY_TYPE(3);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n};\n\n/**\n * Creates a new vec3 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} a new 3D vector\n */\nvec3.fromValues = function(x, y, z) {\n var out = new glMatrix.ARRAY_TYPE(3);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n};\n\n/**\n * Copy the values from one vec3 to another\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the source vector\n * @returns {vec3} out\n */\nvec3.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n};\n\n/**\n * Set the components of a vec3 to the given values\n *\n * @param {vec3} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @returns {vec3} out\n */\nvec3.set = function(out, x, y, z) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n};\n\n/**\n * Adds two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n return out;\n};\n\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n return out;\n};\n\n/**\n * Alias for {@link vec3.subtract}\n * @function\n */\nvec3.sub = vec3.subtract;\n\n/**\n * Multiplies two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n return out;\n};\n\n/**\n * Alias for {@link vec3.multiply}\n * @function\n */\nvec3.mul = vec3.multiply;\n\n/**\n * Divides two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n return out;\n};\n\n/**\n * Alias for {@link vec3.divide}\n * @function\n */\nvec3.div = vec3.divide;\n\n/**\n * Math.ceil the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to ceil\n * @returns {vec3} out\n */\nvec3.ceil = function (out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n out[2] = Math.ceil(a[2]);\n return out;\n};\n\n/**\n * Math.floor the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to floor\n * @returns {vec3} out\n */\nvec3.floor = function (out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n out[2] = Math.floor(a[2]);\n return out;\n};\n\n/**\n * Returns the minimum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n return out;\n};\n\n/**\n * Math.round the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to round\n * @returns {vec3} out\n */\nvec3.round = function (out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n out[2] = Math.round(a[2]);\n return out;\n};\n\n/**\n * Scales a vec3 by a scalar number\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec3} out\n */\nvec3.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n return out;\n};\n\n/**\n * Adds two vec3's after scaling the second operand by a scalar value\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec3} out\n */\nvec3.scaleAndAdd = function(out, a, b, scale) {\n out[0] = a[0] + (b[0] * scale);\n out[1] = a[1] + (b[1] * scale);\n out[2] = a[2] + (b[2] * scale);\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} distance between a and b\n */\nvec3.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2];\n return Math.sqrt(x*x + y*y + z*z);\n};\n\n/**\n * Alias for {@link vec3.distance}\n * @function\n */\nvec3.dist = vec3.distance;\n\n/**\n * Calculates the squared euclidian distance between two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec3.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2];\n return x*x + y*y + z*z;\n};\n\n/**\n * Alias for {@link vec3.squaredDistance}\n * @function\n */\nvec3.sqrDist = vec3.squaredDistance;\n\n/**\n * Calculates the length of a vec3\n *\n * @param {vec3} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec3.length = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n return Math.sqrt(x*x + y*y + z*z);\n};\n\n/**\n * Alias for {@link vec3.length}\n * @function\n */\nvec3.len = vec3.length;\n\n/**\n * Calculates the squared length of a vec3\n *\n * @param {vec3} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec3.squaredLength = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n return x*x + y*y + z*z;\n};\n\n/**\n * Alias for {@link vec3.squaredLength}\n * @function\n */\nvec3.sqrLen = vec3.squaredLength;\n\n/**\n * Negates the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to negate\n * @returns {vec3} out\n */\nvec3.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n return out;\n};\n\n/**\n * Returns the inverse of the components of a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to invert\n * @returns {vec3} out\n */\nvec3.inverse = function(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n out[2] = 1.0 / a[2];\n return out;\n};\n\n/**\n * Normalize a vec3\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a vector to normalize\n * @returns {vec3} out\n */\nvec3.normalize = function(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n var len = x*x + y*y + z*z;\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n out[2] = a[2] * len;\n }\n return out;\n};\n\n/**\n * Calculates the dot product of two vec3's\n *\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec3.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n};\n\n/**\n * Computes the cross product of two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @returns {vec3} out\n */\nvec3.cross = function(out, a, b) {\n var ax = a[0], ay = a[1], az = a[2],\n bx = b[0], by = b[1], bz = b[2];\n\n out[0] = ay * bz - az * by;\n out[1] = az * bx - ax * bz;\n out[2] = ax * by - ay * bx;\n return out;\n};\n\n/**\n * Performs a linear interpolation between two vec3's\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec3} out\n */\nvec3.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1],\n az = a[2];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n return out;\n};\n\n/**\n * Performs a hermite interpolation with two control points\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {vec3} c the third operand\n * @param {vec3} d the fourth operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec3} out\n */\nvec3.hermite = function (out, a, b, c, d, t) {\n var factorTimes2 = t * t,\n factor1 = factorTimes2 * (2 * t - 3) + 1,\n factor2 = factorTimes2 * (t - 2) + t,\n factor3 = factorTimes2 * (t - 1),\n factor4 = factorTimes2 * (3 - 2 * t);\n \n out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;\n out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;\n out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;\n \n return out;\n};\n\n/**\n * Performs a bezier interpolation with two control points\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the first operand\n * @param {vec3} b the second operand\n * @param {vec3} c the third operand\n * @param {vec3} d the fourth operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec3} out\n */\nvec3.bezier = function (out, a, b, c, d, t) {\n var inverseFactor = 1 - t,\n inverseFactorTimesTwo = inverseFactor * inverseFactor,\n factorTimes2 = t * t,\n factor1 = inverseFactorTimesTwo * inverseFactor,\n factor2 = 3 * t * inverseFactorTimesTwo,\n factor3 = 3 * factorTimes2 * inverseFactor,\n factor4 = factorTimes2 * t;\n \n out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;\n out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;\n out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;\n \n return out;\n};\n\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec3} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec3} out\n */\nvec3.random = function (out, scale) {\n scale = scale || 1.0;\n\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n var z = (glMatrix.RANDOM() * 2.0) - 1.0;\n var zScale = Math.sqrt(1.0-z*z) * scale;\n\n out[0] = Math.cos(r) * zScale;\n out[1] = Math.sin(r) * zScale;\n out[2] = z * scale;\n return out;\n};\n\n/**\n * Transforms the vec3 with a mat4.\n * 4th vector component is implicitly '1'\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec3} out\n */\nvec3.transformMat4 = function(out, a, m) {\n var x = a[0], y = a[1], z = a[2],\n w = m[3] * x + m[7] * y + m[11] * z + m[15];\n w = w || 1.0;\n out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;\n out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;\n out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;\n return out;\n};\n\n/**\n * Transforms the vec3 with a mat3.\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {mat4} m the 3x3 matrix to transform with\n * @returns {vec3} out\n */\nvec3.transformMat3 = function(out, a, m) {\n var x = a[0], y = a[1], z = a[2];\n out[0] = x * m[0] + y * m[3] + z * m[6];\n out[1] = x * m[1] + y * m[4] + z * m[7];\n out[2] = x * m[2] + y * m[5] + z * m[8];\n return out;\n};\n\n/**\n * Transforms the vec3 with a quat\n *\n * @param {vec3} out the receiving vector\n * @param {vec3} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec3} out\n */\nvec3.transformQuat = function(out, a, q) {\n // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations\n\n var x = a[0], y = a[1], z = a[2],\n qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n // calculate quat * vec\n ix = qw * x + qy * z - qz * y,\n iy = qw * y + qz * x - qx * z,\n iz = qw * z + qx * y - qy * x,\n iw = -qx * x - qy * y - qz * z;\n\n // calculate result * inverse quat\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n return out;\n};\n\n/**\n * Rotate a 3D vector around the x-axis\n * @param {vec3} out The receiving vec3\n * @param {vec3} a The vec3 point to rotate\n * @param {vec3} b The origin of the rotation\n * @param {Number} c The angle of rotation\n * @returns {vec3} out\n */\nvec3.rotateX = function(out, a, b, c){\n var p = [], r=[];\n\t //Translate point to the origin\n\t p[0] = a[0] - b[0];\n\t p[1] = a[1] - b[1];\n \tp[2] = a[2] - b[2];\n\n\t //perform rotation\n\t r[0] = p[0];\n\t r[1] = p[1]*Math.cos(c) - p[2]*Math.sin(c);\n\t r[2] = p[1]*Math.sin(c) + p[2]*Math.cos(c);\n\n\t //translate to correct position\n\t out[0] = r[0] + b[0];\n\t out[1] = r[1] + b[1];\n\t out[2] = r[2] + b[2];\n\n \treturn out;\n};\n\n/**\n * Rotate a 3D vector around the y-axis\n * @param {vec3} out The receiving vec3\n * @param {vec3} a The vec3 point to rotate\n * @param {vec3} b The origin of the rotation\n * @param {Number} c The angle of rotation\n * @returns {vec3} out\n */\nvec3.rotateY = function(out, a, b, c){\n \tvar p = [], r=[];\n \t//Translate point to the origin\n \tp[0] = a[0] - b[0];\n \tp[1] = a[1] - b[1];\n \tp[2] = a[2] - b[2];\n \n \t//perform rotation\n \tr[0] = p[2]*Math.sin(c) + p[0]*Math.cos(c);\n \tr[1] = p[1];\n \tr[2] = p[2]*Math.cos(c) - p[0]*Math.sin(c);\n \n \t//translate to correct position\n \tout[0] = r[0] + b[0];\n \tout[1] = r[1] + b[1];\n \tout[2] = r[2] + b[2];\n \n \treturn out;\n};\n\n/**\n * Rotate a 3D vector around the z-axis\n * @param {vec3} out The receiving vec3\n * @param {vec3} a The vec3 point to rotate\n * @param {vec3} b The origin of the rotation\n * @param {Number} c The angle of rotation\n * @returns {vec3} out\n */\nvec3.rotateZ = function(out, a, b, c){\n \tvar p = [], r=[];\n \t//Translate point to the origin\n \tp[0] = a[0] - b[0];\n \tp[1] = a[1] - b[1];\n \tp[2] = a[2] - b[2];\n \n \t//perform rotation\n \tr[0] = p[0]*Math.cos(c) - p[1]*Math.sin(c);\n \tr[1] = p[0]*Math.sin(c) + p[1]*Math.cos(c);\n \tr[2] = p[2];\n \n \t//translate to correct position\n \tout[0] = r[0] + b[0];\n \tout[1] = r[1] + b[1];\n \tout[2] = r[2] + b[2];\n \n \treturn out;\n};\n\n/**\n * Perform some operation over an array of vec3s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\nvec3.forEach = (function() {\n var vec = vec3.create();\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 3;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2];\n }\n \n return a;\n };\n})();\n\n/**\n * Get the angle between two 3D vectors\n * @param {vec3} a The first operand\n * @param {vec3} b The second operand\n * @returns {Number} The angle in radians\n */\nvec3.angle = function(a, b) {\n \n var tempA = vec3.fromValues(a[0], a[1], a[2]);\n var tempB = vec3.fromValues(b[0], b[1], b[2]);\n \n vec3.normalize(tempA, tempA);\n vec3.normalize(tempB, tempB);\n \n var cosine = vec3.dot(tempA, tempB);\n\n if(cosine > 1.0){\n return 0;\n } else {\n return Math.acos(cosine);\n } \n};\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec3} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec3.str = function (a) {\n return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';\n};\n\n/**\n * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)\n *\n * @param {vec3} a The first vector.\n * @param {vec3} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nvec3.exactEquals = function (a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];\n};\n\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {vec3} a The first vector.\n * @param {vec3} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nvec3.equals = function (a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2];\n var b0 = b[0], b1 = b[1], b2 = b[2];\n return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)));\n};\n\nmodule.exports = vec3;\n",
"/* Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. */\n\nvar glMatrix = require(\"./common.js\");\n\n/**\n * @class 4 Dimensional Vector\n * @name vec4\n */\nvar vec4 = {};\n\n/**\n * Creates a new, empty vec4\n *\n * @returns {vec4} a new 4D vector\n */\nvec4.create = function() {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n return out;\n};\n\n/**\n * Creates a new vec4 initialized with values from an existing vector\n *\n * @param {vec4} a vector to clone\n * @returns {vec4} a new 4D vector\n */\nvec4.clone = function(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Creates a new vec4 initialized with the given values\n *\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} a new 4D vector\n */\nvec4.fromValues = function(x, y, z, w) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n};\n\n/**\n * Copy the values from one vec4 to another\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the source vector\n * @returns {vec4} out\n */\nvec4.copy = function(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n};\n\n/**\n * Set the components of a vec4 to the given values\n *\n * @param {vec4} out the receiving vector\n * @param {Number} x X component\n * @param {Number} y Y component\n * @param {Number} z Z component\n * @param {Number} w W component\n * @returns {vec4} out\n */\nvec4.set = function(out, x, y, z, w) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n};\n\n/**\n * Adds two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.add = function(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n};\n\n/**\n * Subtracts vector b from vector a\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.subtract = function(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n};\n\n/**\n * Alias for {@link vec4.subtract}\n * @function\n */\nvec4.sub = vec4.subtract;\n\n/**\n * Multiplies two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.multiply = function(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n out[3] = a[3] * b[3];\n return out;\n};\n\n/**\n * Alias for {@link vec4.multiply}\n * @function\n */\nvec4.mul = vec4.multiply;\n\n/**\n * Divides two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.divide = function(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n out[3] = a[3] / b[3];\n return out;\n};\n\n/**\n * Alias for {@link vec4.divide}\n * @function\n */\nvec4.div = vec4.divide;\n\n/**\n * Math.ceil the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to ceil\n * @returns {vec4} out\n */\nvec4.ceil = function (out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n out[2] = Math.ceil(a[2]);\n out[3] = Math.ceil(a[3]);\n return out;\n};\n\n/**\n * Math.floor the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to floor\n * @returns {vec4} out\n */\nvec4.floor = function (out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n out[2] = Math.floor(a[2]);\n out[3] = Math.floor(a[3]);\n return out;\n};\n\n/**\n * Returns the minimum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.min = function(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n out[3] = Math.min(a[3], b[3]);\n return out;\n};\n\n/**\n * Returns the maximum of two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {vec4} out\n */\nvec4.max = function(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n out[3] = Math.max(a[3], b[3]);\n return out;\n};\n\n/**\n * Math.round the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to round\n * @returns {vec4} out\n */\nvec4.round = function (out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n out[2] = Math.round(a[2]);\n out[3] = Math.round(a[3]);\n return out;\n};\n\n/**\n * Scales a vec4 by a scalar number\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to scale\n * @param {Number} b amount to scale the vector by\n * @returns {vec4} out\n */\nvec4.scale = function(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n};\n\n/**\n * Adds two vec4's after scaling the second operand by a scalar value\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @param {Number} scale the amount to scale b by before adding\n * @returns {vec4} out\n */\nvec4.scaleAndAdd = function(out, a, b, scale) {\n out[0] = a[0] + (b[0] * scale);\n out[1] = a[1] + (b[1] * scale);\n out[2] = a[2] + (b[2] * scale);\n out[3] = a[3] + (b[3] * scale);\n return out;\n};\n\n/**\n * Calculates the euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} distance between a and b\n */\nvec4.distance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2],\n w = b[3] - a[3];\n return Math.sqrt(x*x + y*y + z*z + w*w);\n};\n\n/**\n * Alias for {@link vec4.distance}\n * @function\n */\nvec4.dist = vec4.distance;\n\n/**\n * Calculates the squared euclidian distance between two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} squared distance between a and b\n */\nvec4.squaredDistance = function(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1],\n z = b[2] - a[2],\n w = b[3] - a[3];\n return x*x + y*y + z*z + w*w;\n};\n\n/**\n * Alias for {@link vec4.squaredDistance}\n * @function\n */\nvec4.sqrDist = vec4.squaredDistance;\n\n/**\n * Calculates the length of a vec4\n *\n * @param {vec4} a vector to calculate length of\n * @returns {Number} length of a\n */\nvec4.length = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n return Math.sqrt(x*x + y*y + z*z + w*w);\n};\n\n/**\n * Alias for {@link vec4.length}\n * @function\n */\nvec4.len = vec4.length;\n\n/**\n * Calculates the squared length of a vec4\n *\n * @param {vec4} a vector to calculate squared length of\n * @returns {Number} squared length of a\n */\nvec4.squaredLength = function (a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n return x*x + y*y + z*z + w*w;\n};\n\n/**\n * Alias for {@link vec4.squaredLength}\n * @function\n */\nvec4.sqrLen = vec4.squaredLength;\n\n/**\n * Negates the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to negate\n * @returns {vec4} out\n */\nvec4.negate = function(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = -a[3];\n return out;\n};\n\n/**\n * Returns the inverse of the components of a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to invert\n * @returns {vec4} out\n */\nvec4.inverse = function(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n out[2] = 1.0 / a[2];\n out[3] = 1.0 / a[3];\n return out;\n};\n\n/**\n * Normalize a vec4\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a vector to normalize\n * @returns {vec4} out\n */\nvec4.normalize = function(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n var len = x*x + y*y + z*z + w*w;\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n out[0] = x * len;\n out[1] = y * len;\n out[2] = z * len;\n out[3] = w * len;\n }\n return out;\n};\n\n/**\n * Calculates the dot product of two vec4's\n *\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @returns {Number} dot product of a and b\n */\nvec4.dot = function (a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];\n};\n\n/**\n * Performs a linear interpolation between two vec4's\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the first operand\n * @param {vec4} b the second operand\n * @param {Number} t interpolation amount between the two inputs\n * @returns {vec4} out\n */\nvec4.lerp = function (out, a, b, t) {\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n out[3] = aw + t * (b[3] - aw);\n return out;\n};\n\n/**\n * Generates a random vector with the given scale\n *\n * @param {vec4} out the receiving vector\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\n * @returns {vec4} out\n */\nvec4.random = function (out, scale) {\n scale = scale || 1.0;\n\n //TODO: This is a pretty awful way of doing this. Find something better.\n out[0] = glMatrix.RANDOM();\n out[1] = glMatrix.RANDOM();\n out[2] = glMatrix.RANDOM();\n out[3] = glMatrix.RANDOM();\n vec4.normalize(out, out);\n vec4.scale(out, out, scale);\n return out;\n};\n\n/**\n * Transforms the vec4 with a mat4.\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {mat4} m matrix to transform with\n * @returns {vec4} out\n */\nvec4.transformMat4 = function(out, a, m) {\n var x = a[0], y = a[1], z = a[2], w = a[3];\n out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;\n out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;\n out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;\n out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;\n return out;\n};\n\n/**\n * Transforms the vec4 with a quat\n *\n * @param {vec4} out the receiving vector\n * @param {vec4} a the vector to transform\n * @param {quat} q quaternion to transform with\n * @returns {vec4} out\n */\nvec4.transformQuat = function(out, a, q) {\n var x = a[0], y = a[1], z = a[2],\n qx = q[0], qy = q[1], qz = q[2], qw = q[3],\n\n // calculate quat * vec\n ix = qw * x + qy * z - qz * y,\n iy = qw * y + qz * x - qx * z,\n iz = qw * z + qx * y - qy * x,\n iw = -qx * x - qy * y - qz * z;\n\n // calculate result * inverse quat\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n out[3] = a[3];\n return out;\n};\n\n/**\n * Perform some operation over an array of vec4s.\n *\n * @param {Array} a the array of vectors to iterate over\n * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed\n * @param {Number} offset Number of elements to skip at the beginning of the array\n * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array\n * @param {Function} fn Function to call for each vector in the array\n * @param {Object} [arg] additional argument to pass to fn\n * @returns {Array} a\n * @function\n */\nvec4.forEach = (function() {\n var vec = vec4.create();\n\n return function(a, stride, offset, count, fn, arg) {\n var i, l;\n if(!stride) {\n stride = 4;\n }\n\n if(!offset) {\n offset = 0;\n }\n \n if(count) {\n l = Math.min((count * stride) + offset, a.length);\n } else {\n l = a.length;\n }\n\n for(i = offset; i < l; i += stride) {\n vec[0] = a[i]; vec[1] = a[i+1]; vec[2] = a[i+2]; vec[3] = a[i+3];\n fn(vec, vec, arg);\n a[i] = vec[0]; a[i+1] = vec[1]; a[i+2] = vec[2]; a[i+3] = vec[3];\n }\n \n return a;\n };\n})();\n\n/**\n * Returns a string representation of a vector\n *\n * @param {vec4} vec vector to represent as a string\n * @returns {String} string representation of the vector\n */\nvec4.str = function (a) {\n return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n};\n\n/**\n * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)\n *\n * @param {vec4} a The first vector.\n * @param {vec4} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nvec4.exactEquals = function (a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n};\n\n/**\n * Returns whether or not the vectors have approximately the same elements in the same position.\n *\n * @param {vec4} a The first vector.\n * @param {vec4} b The second vector.\n * @returns {Boolean} True if the vectors are equal, false otherwise.\n */\nvec4.equals = function (a, b) {\n var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];\n var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];\n return (Math.abs(a0 - b0) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n Math.abs(a2 - b2) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&\n Math.abs(a3 - b3) <= glMatrix.EPSILON*Math.max(1.0, Math.abs(a3), Math.abs(b3)));\n};\n\nmodule.exports = vec4;\n",
"var GL_FLOAT = 5126\n\nfunction AttributeRecord () {\n this.state = 0\n\n this.x = 0.0\n this.y = 0.0\n this.z = 0.0\n this.w = 0.0\n\n this.buffer = null\n this.size = 0\n this.normalized = false\n this.type = GL_FLOAT\n this.offset = 0\n this.stride = 0\n this.divisor = 0\n}\n\nmodule.exports = function wrapAttributeState (\n gl,\n extensions,\n limits,\n bufferState,\n stringStore) {\n var NUM_ATTRIBUTES = limits.maxAttributes\n var attributeBindings = new Array(NUM_ATTRIBUTES)\n for (var i = 0; i < NUM_ATTRIBUTES; ++i) {\n attributeBindings[i] = new AttributeRecord()\n }\n\n return {\n Record: AttributeRecord,\n scope: {},\n state: attributeBindings\n }\n}\n",
"var check = require('./util/check')\nvar isTypedArray = require('./util/is-typed-array')\nvar isNDArrayLike = require('./util/is-ndarray')\nvar values = require('./util/values')\nvar pool = require('./util/pool')\n\nvar arrayTypes = require('./constants/arraytypes.json')\nvar bufferTypes = require('./constants/dtypes.json')\nvar usageTypes = require('./constants/usage.json')\n\nvar GL_STATIC_DRAW = 0x88E4\nvar GL_STREAM_DRAW = 0x88E0\n\nvar GL_UNSIGNED_BYTE = 5121\nvar GL_FLOAT = 5126\n\nvar DTYPES_SIZES = []\nDTYPES_SIZES[5120] = 1 // int8\nDTYPES_SIZES[5122] = 2 // int16\nDTYPES_SIZES[5124] = 4 // int32\nDTYPES_SIZES[5121] = 1 // uint8\nDTYPES_SIZES[5123] = 2 // uint16\nDTYPES_SIZES[5125] = 4 // uint32\nDTYPES_SIZES[5126] = 4 // float32\n\nfunction typedArrayCode (data) {\n return arrayTypes[Object.prototype.toString.call(data)] | 0\n}\n\nfunction copyArray (out, inp) {\n for (var i = 0; i < inp.length; ++i) {\n out[i] = inp[i]\n }\n}\n\nfunction transpose (\n result, data, shapeX, shapeY, strideX, strideY, offset) {\n var ptr = 0\n for (var i = 0; i < shapeX; ++i) {\n for (var j = 0; j < shapeY; ++j) {\n result[ptr++] = data[strideX * i + strideY * j + offset]\n }\n }\n}\n\nfunction flatten (result, data, dimension) {\n var ptr = 0\n for (var i = 0; i < data.length; ++i) {\n var v = data[i]\n for (var j = 0; j < dimension; ++j) {\n result[ptr++] = v[j]\n }\n }\n}\n\nmodule.exports = function wrapBufferState (gl, stats, config) {\n var bufferCount = 0\n var bufferSet = {}\n\n function REGLBuffer (type) {\n this.id = bufferCount++\n this.buffer = gl.createBuffer()\n this.type = type\n this.usage = GL_STATIC_DRAW\n this.byteLength = 0\n this.dimension = 1\n this.dtype = GL_UNSIGNED_BYTE\n\n if (config.profile) {\n this.stats = {size: 0}\n }\n }\n\n REGLBuffer.prototype.bind = function () {\n gl.bindBuffer(this.type, this.buffer)\n }\n\n REGLBuffer.prototype.destroy = function () {\n destroy(this)\n }\n\n var streamPool = []\n\n function createStream (type, data) {\n var buffer = streamPool.pop()\n if (!buffer) {\n buffer = new REGLBuffer(type)\n }\n buffer.bind()\n initBufferFromData(buffer, data, GL_STREAM_DRAW, 0, 1)\n return buffer\n }\n\n function destroyStream (stream) {\n streamPool.push(stream)\n }\n\n function initBufferFromTypedArray (buffer, data, usage) {\n buffer.byteLength = data.byteLength\n gl.bufferData(buffer.type, data, usage)\n }\n\n function initBufferFromData (buffer, data, usage, dtype, dimension) {\n buffer.usage = usage\n if (Array.isArray(data)) {\n buffer.dtype = dtype || GL_FLOAT\n if (data.length > 0) {\n var flatData\n if (Array.isArray(data[0])) {\n buffer.dimension = data[0].length\n flatData = pool.allocType(\n buffer.dtype,\n data.length * buffer.dimension)\n flatten(flatData, data, buffer.dimension)\n initBufferFromTypedArray(buffer, flatData, usage)\n pool.freeType(flatData)\n } else if (typeof data[0] === 'number') {\n buffer.dimension = dimension\n var typedData = pool.allocType(buffer.dtype, data.length)\n copyArray(typedData, data)\n initBufferFromTypedArray(buffer, typedData, usage)\n pool.freeType(typedData)\n } else if (isTypedArray(data[0])) {\n buffer.dimension = data[0].length\n buffer.dtype = dtype || typedArrayCode(data[0]) || GL_FLOAT\n flatData = pool.allocType(\n buffer.dtype,\n data.length * buffer.dimension)\n flatten(flatData, data, buffer.dimension)\n initBufferFromTypedArray(buffer, flatData, usage)\n pool.freeType(flatData)\n } else {\n check.raise('invalid buffer data')\n }\n }\n } else if (isTypedArray(data)) {\n buffer.dtype = dtype || typedArrayCode(data)\n buffer.dimension = dimension\n initBufferFromTypedArray(buffer, data, usage)\n } else if (isNDArrayLike(data)) {\n var shape = data.shape\n var stride = data.stride\n var offset = data.offset\n\n var shapeX = 0\n var shapeY = 0\n var strideX = 0\n var strideY = 0\n if (shape.length === 1) {\n shapeX = shape[0]\n shapeY = 1\n strideX = stride[0]\n strideY = 0\n } else if (shape.length === 2) {\n shapeX = shape[0]\n shapeY = shape[1]\n strideX = stride[0]\n strideY = stride[1]\n } else {\n check.raise('invalid shape')\n }\n\n buffer.dtype = dtype || typedArrayCode(data.data) || GL_FLOAT\n buffer.dimension = shapeY\n\n var transposeData = pool.allocType(buffer.dtype, shapeX * shapeY)\n transpose(transposeData,\n data.data,\n shapeX, shapeY,\n strideX, strideY,\n offset)\n initBufferFromTypedArray(buffer, transposeData, usage)\n pool.freeType(transposeData)\n } else {\n check.raise('invalid buffer data')\n }\n }\n\n function destroy (buffer) {\n stats.bufferCount--\n\n var handle = buffer.buffer\n check(handle, 'buffer must not be deleted already')\n gl.deleteBuffer(handle)\n buffer.buffer = null\n delete bufferSet[buffer.id]\n }\n\n function createBuffer (options, type, deferInit) {\n stats.bufferCount++\n\n var buffer = new REGLBuffer(type)\n bufferSet[buffer.id] = buffer\n\n function reglBuffer (options) {\n var usage = GL_STATIC_DRAW\n var data = null\n var byteLength = 0\n var dtype = 0\n var dimension = 1\n if (Array.isArray(options) ||\n isTypedArray(options) ||\n isNDArrayLike(options)) {\n data = options\n } else if (typeof options === 'number') {\n byteLength = options | 0\n } else if (options) {\n check.type(\n options, 'object',\n 'buffer arguments must be an object, a number or an array')\n\n if ('data' in options) {\n check(\n data === null ||\n Array.isArray(data) ||\n isTypedArray(data) ||\n isNDArrayLike(data),\n 'invalid data for buffer')\n data = options.data\n }\n\n if ('usage' in options) {\n check.parameter(options.usage, usageTypes, 'invalid buffer usage')\n usage = usageTypes[options.usage]\n }\n\n if ('type' in options) {\n check.parameter(options.type, bufferTypes, 'invalid buffer type')\n dtype = bufferTypes[options.type]\n }\n\n if ('dimension' in options) {\n check.type(options.dimension, 'number', 'invalid dimension')\n dimension = options.dimension | 0\n }\n\n if ('length' in options) {\n check.nni(byteLength, 'buffer length must be a nonnegative integer')\n byteLength = options.length | 0\n }\n }\n\n buffer.bind()\n if (!data) {\n gl.bufferData(buffer.type, byteLength, usage)\n buffer.dtype = dtype || GL_UNSIGNED_BYTE\n buffer.usage = usage\n buffer.dimension = dimension\n buffer.byteLength = byteLength\n } else {\n initBufferFromData(buffer, data, usage, dtype, dimension)\n }\n\n if (config.profile) {\n buffer.stats.size = buffer.byteLength * DTYPES_SIZES[buffer.dtype]\n }\n\n return reglBuffer\n }\n\n function setSubData (data, offset) {\n check(offset + data.byteLength <= buffer.byteLength,\n 'invalid buffer subdata call, buffer is too small. ' + ' Can\\'t write data of size ' + data.byteLength + ' starting from offset ' + offset + ' to a buffer of size ' + buffer.byteLength)\n\n gl.bufferSubData(buffer.type, offset, data)\n }\n\n function subdata (data, offset_) {\n var offset = (offset_ || 0) | 0\n buffer.bind()\n if (Array.isArray(data)) {\n if (data.length > 0) {\n if (typeof data[0] === 'number') {\n var converted = pool.allocType(buffer.dtype, data.length)\n copyArray(converted, data)\n setSubData(converted, offset)\n pool.freeType(converted)\n } else if (Array.isArray(data[0]) || isTypedArray(data[0])) {\n var dimension = data[0].length\n var flatData = pool.allocType(buffer.dtype, data.length * dimension)\n flatten(flatData, data, dimension)\n setSubData(flatData, offset)\n pool.freeType(flatData)\n } else {\n check.raise('invalid buffer data')\n }\n }\n } else if (isTypedArray(data)) {\n setSubData(data, offset)\n } else if (isNDArrayLike(data)) {\n var shape = data.shape\n var stride = data.stride\n\n var shapeX = 0\n var shapeY = 0\n var strideX = 0\n var strideY = 0\n if (shape.length === 1) {\n shapeX = shape[0]\n shapeY = 1\n strideX = stride[0]\n strideY = 0\n } else if (shape.length === 2) {\n shapeX = shape[0]\n shapeY = shape[1]\n strideX = stride[0]\n strideY = stride[1]\n } else {\n check.raise('invalid shape')\n }\n var dtype = Array.isArray(data.data)\n ? buffer.dtype\n : typedArrayCode(data.data)\n\n var transposeData = pool.allocType(dtype, shapeX * shapeY)\n transpose(transposeData,\n data.data,\n shapeX, shapeY,\n strideX, strideY,\n data.offset)\n setSubData(transposeData, offset)\n pool.freeType(transposeData)\n } else {\n check.raise('invalid data for buffer subdata')\n }\n return reglBuffer\n }\n\n if (!deferInit) {\n reglBuffer(options)\n }\n\n reglBuffer._reglType = 'buffer'\n reglBuffer._buffer = buffer\n reglBuffer.subdata = subdata\n if (config.profile) {\n reglBuffer.stats = buffer.stats\n }\n reglBuffer.destroy = function () { destroy(buffer) }\n\n return reglBuffer\n }\n\n if (config.profile) {\n stats.getTotalBufferSize = function () {\n var total = 0\n // TODO: Right now, the streams are not part of the total count.\n Object.keys(bufferSet).forEach(function (key) {\n total += bufferSet[key].stats.size\n })\n return total\n }\n }\n\n return {\n create: createBuffer,\n\n createStream: createStream,\n destroyStream: destroyStream,\n\n clear: function () {\n values(bufferSet).forEach(destroy)\n streamPool.forEach(destroy)\n },\n\n getBuffer: function (wrapper) {\n if (wrapper && wrapper._buffer instanceof REGLBuffer) {\n return wrapper._buffer\n }\n return null\n },\n\n _initBuffer: initBufferFromData\n }\n}\n",
"module.exports={\n \"[object Int8Array]\": 5120\n, \"[object Int16Array]\": 5122\n, \"[object Int32Array]\": 5124\n, \"[object Uint8Array]\": 5121\n, \"[object Uint8ClampedArray]\": 5121\n, \"[object Uint16Array]\": 5123\n, \"[object Uint32Array]\": 5125\n, \"[object Float32Array]\": 5126\n, \"[object Float64Array]\": 5121\n, \"[object ArrayBuffer]\": 5121\n}\n",
"module.exports={\n \"int8\": 5120\n, \"int16\": 5122\n, \"int32\": 5124\n, \"uint8\": 5121\n, \"uint16\": 5123\n, \"uint32\": 5125\n, \"float\": 5126\n, \"float32\": 5126\n}\n",
"module.exports={\n \"points\": 0,\n \"point\": 0,\n \"lines\": 1,\n \"line\": 1,\n \"line loop\": 2,\n \"line strip\": 3,\n \"triangles\": 4,\n \"triangle\": 4,\n \"triangle strip\": 5,\n \"triangle fan\": 6\n}\n",
"module.exports={\n \"static\": 35044,\n \"dynamic\": 35048,\n \"stream\": 35040\n}\n",
"var check = require('./util/check')\nvar createEnvironment = require('./util/codegen')\nvar loop = require('./util/loop')\nvar isTypedArray = require('./util/is-typed-array')\nvar isNDArray = require('./util/is-ndarray')\nvar isArrayLike = require('./util/is-array-like')\nvar dynamic = require('./dynamic')\n\nvar primTypes = require('./constants/primitives.json')\nvar glTypes = require('./constants/dtypes.json')\n\n// \"cute\" names for vector components\nvar CUTE_COMPONENTS = 'xyzw'.split('')\n\nvar GL_UNSIGNED_BYTE = 5121\n\nvar ATTRIB_STATE_POINTER = 1\nvar ATTRIB_STATE_CONSTANT = 2\n\nvar DYN_FUNC = 0\nvar DYN_PROP = 1\nvar DYN_CONTEXT = 2\nvar DYN_STATE = 3\nvar DYN_THUNK = 4\n\nvar S_DITHER = 'dither'\nvar S_BLEND_ENABLE = 'blend.enable'\nvar S_BLEND_COLOR = 'blend.color'\nvar S_BLEND_EQUATION = 'blend.equation'\nvar S_BLEND_FUNC = 'blend.func'\nvar S_DEPTH_ENABLE = 'depth.enable'\nvar S_DEPTH_FUNC = 'depth.func'\nvar S_DEPTH_RANGE = 'depth.range'\nvar S_DEPTH_MASK = 'depth.mask'\nvar S_COLOR_MASK = 'colorMask'\nvar S_CULL_ENABLE = 'cull.enable'\nvar S_CULL_FACE = 'cull.face'\nvar S_FRONT_FACE = 'frontFace'\nvar S_LINE_WIDTH = 'lineWidth'\nvar S_POLYGON_OFFSET_ENABLE = 'polygonOffset.enable'\nvar S_POLYGON_OFFSET_OFFSET = 'polygonOffset.offset'\nvar S_SAMPLE_ALPHA = 'sample.alpha'\nvar S_SAMPLE_ENABLE = 'sample.enable'\nvar S_SAMPLE_COVERAGE = 'sample.coverage'\nvar S_STENCIL_ENABLE = 'stencil.enable'\nvar S_STENCIL_MASK = 'stencil.mask'\nvar S_STENCIL_FUNC = 'stencil.func'\nvar S_STENCIL_OPFRONT = 'stencil.opFront'\nvar S_STENCIL_OPBACK = 'stencil.opBack'\nvar S_SCISSOR_ENABLE = 'scissor.enable'\nvar S_SCISSOR_BOX = 'scissor.box'\nvar S_VIEWPORT = 'viewport'\n\nvar S_PROFILE = 'profile'\n\nvar S_FRAMEBUFFER = 'framebuffer'\nvar S_VERT = 'vert'\nvar S_FRAG = 'frag'\nvar S_ELEMENTS = 'elements'\nvar S_PRIMITIVE = 'primitive'\nvar S_COUNT = 'count'\nvar S_OFFSET = 'offset'\nvar S_INSTANCES = 'instances'\n\nvar SUFFIX_WIDTH = 'Width'\nvar SUFFIX_HEIGHT = 'Height'\n\nvar S_FRAMEBUFFER_WIDTH = S_FRAMEBUFFER + SUFFIX_WIDTH\nvar S_FRAMEBUFFER_HEIGHT = S_FRAMEBUFFER + SUFFIX_HEIGHT\nvar S_VIEWPORT_WIDTH = S_VIEWPORT + SUFFIX_WIDTH\nvar S_VIEWPORT_HEIGHT = S_VIEWPORT + SUFFIX_HEIGHT\nvar S_DRAWINGBUFFER = 'drawingBuffer'\nvar S_DRAWINGBUFFER_WIDTH = S_DRAWINGBUFFER + SUFFIX_WIDTH\nvar S_DRAWINGBUFFER_HEIGHT = S_DRAWINGBUFFER + SUFFIX_HEIGHT\n\nvar NESTED_OPTIONS = [\n S_BLEND_FUNC,\n S_BLEND_EQUATION,\n S_STENCIL_FUNC,\n S_STENCIL_OPFRONT,\n S_STENCIL_OPBACK,\n S_SAMPLE_COVERAGE,\n S_VIEWPORT,\n S_SCISSOR_BOX,\n S_POLYGON_OFFSET_OFFSET\n]\n\nvar GL_ARRAY_BUFFER = 34962\nvar GL_ELEMENT_ARRAY_BUFFER = 34963\n\nvar GL_FRAGMENT_SHADER = 35632\nvar GL_VERTEX_SHADER = 35633\n\nvar GL_TEXTURE_2D = 0x0DE1\nvar GL_TEXTURE_CUBE_MAP = 0x8513\n\nvar GL_CULL_FACE = 0x0B44\nvar GL_BLEND = 0x0BE2\nvar GL_DITHER = 0x0BD0\nvar GL_STENCIL_TEST = 0x0B90\nvar GL_DEPTH_TEST = 0x0B71\nvar GL_SCISSOR_TEST = 0x0C11\nvar GL_POLYGON_OFFSET_FILL = 0x8037\nvar GL_SAMPLE_ALPHA_TO_COVERAGE = 0x809E\nvar GL_SAMPLE_COVERAGE = 0x80A0\n\nvar GL_FLOAT = 5126\nvar GL_FLOAT_VEC2 = 35664\nvar GL_FLOAT_VEC3 = 35665\nvar GL_FLOAT_VEC4 = 35666\nvar GL_INT = 5124\nvar GL_INT_VEC2 = 35667\nvar GL_INT_VEC3 = 35668\nvar GL_INT_VEC4 = 35669\nvar GL_BOOL = 35670\nvar GL_BOOL_VEC2 = 35671\nvar GL_BOOL_VEC3 = 35672\nvar GL_BOOL_VEC4 = 35673\nvar GL_FLOAT_MAT2 = 35674\nvar GL_FLOAT_MAT3 = 35675\nvar GL_FLOAT_MAT4 = 35676\nvar GL_SAMPLER_2D = 35678\nvar GL_SAMPLER_CUBE = 35680\n\nvar GL_TRIANGLES = 4\n\nvar GL_FRONT = 1028\nvar GL_BACK = 1029\nvar GL_CW = 0x0900\nvar GL_CCW = 0x0901\nvar GL_MIN_EXT = 0x8007\nvar GL_MAX_EXT = 0x8008\nvar GL_ALWAYS = 519\nvar GL_KEEP = 7680\nvar GL_ZERO = 0\nvar GL_ONE = 1\nvar GL_FUNC_ADD = 0x8006\nvar GL_LESS = 513\n\nvar GL_FRAMEBUFFER = 0x8D40\nvar GL_COLOR_ATTACHMENT0 = 0x8CE0\n\nvar blendFuncs = {\n '0': 0,\n '1': 1,\n 'zero': 0,\n 'one': 1,\n 'src color': 768,\n 'one minus src color': 769,\n 'src alpha': 770,\n 'one minus src alpha': 771,\n 'dst color': 774,\n 'one minus dst color': 775,\n 'dst alpha': 772,\n 'one minus dst alpha': 773,\n 'constant color': 32769,\n 'one minus constant color': 32770,\n 'constant alpha': 32771,\n 'one minus constant alpha': 32772,\n 'src alpha saturate': 776\n}\n\nvar compareFuncs = {\n 'never': 512,\n 'less': 513,\n '<': 513,\n 'equal': 514,\n '=': 514,\n '==': 514,\n '===': 514,\n 'lequal': 515,\n '<=': 515,\n 'greater': 516,\n '>': 516,\n 'notequal': 517,\n '!=': 517,\n '!==': 517,\n 'gequal': 518,\n '>=': 518,\n 'always': 519\n}\n\nvar stencilOps = {\n '0': 0,\n 'zero': 0,\n 'keep': 7680,\n 'replace': 7681,\n 'increment': 7682,\n 'decrement': 7683,\n 'increment wrap': 34055,\n 'decrement wrap': 34056,\n 'invert': 5386\n}\n\nvar shaderType = {\n 'frag': GL_FRAGMENT_SHADER,\n 'vert': GL_VERTEX_SHADER\n}\n\nvar orientationType = {\n 'cw': GL_CW,\n 'ccw': GL_CCW\n}\n\nfunction isBufferArgs (x) {\n return Array.isArray(x) ||\n isTypedArray(x) ||\n isNDArray(x)\n}\n\n// Make sure viewport is processed first\nfunction sortState (state) {\n return state.sort(function (a, b) {\n if (a === S_VIEWPORT) {\n return -1\n } else if (b === S_VIEWPORT) {\n return 1\n }\n return (a < b) ? -1 : 1\n })\n}\n\nfunction Declaration (thisDep, contextDep, propDep, append) {\n this.thisDep = thisDep\n this.contextDep = contextDep\n this.propDep = propDep\n this.append = append\n}\n\nfunction isStatic (decl) {\n return decl && !(decl.thisDep || decl.contextDep || decl.propDep)\n}\n\nfunction createStaticDecl (append) {\n return new Declaration(false, false, false, append)\n}\n\nfunction createDynamicDecl (dyn, append) {\n var type = dyn.type\n if (type === DYN_FUNC) {\n var numArgs = dyn.data.length\n return new Declaration(\n true,\n numArgs >= 1,\n numArgs >= 2,\n append)\n } else if (type === DYN_THUNK) {\n var data = dyn.data\n return new Declaration(\n data.thisDep,\n data.contextDep,\n data.propDep,\n append)\n } else {\n return new Declaration(\n type === DYN_STATE,\n type === DYN_CONTEXT,\n type === DYN_PROP,\n append)\n }\n}\n\nvar SCOPE_DECL = new Declaration(false, false, false, function () {})\n\nmodule.exports = function reglCore (\n gl,\n stringStore,\n extensions,\n limits,\n bufferState,\n elementState,\n textureState,\n framebufferState,\n uniformState,\n attributeState,\n shaderState,\n drawState,\n contextState,\n timer,\n config) {\n var AttributeRecord = attributeState.Record\n\n var blendEquations = {\n 'add': 32774,\n 'subtract': 32778,\n 'reverse subtract': 32779\n }\n if (extensions.ext_blend_minmax) {\n blendEquations.min = GL_MIN_EXT\n blendEquations.max = GL_MAX_EXT\n }\n\n var extInstancing = extensions.angle_instanced_arrays\n var extDrawBuffers = extensions.webgl_draw_buffers\n\n // ===================================================\n // ===================================================\n // WEBGL STATE\n // ===================================================\n // ===================================================\n var currentState = {\n dirty: true,\n profile: config.profile\n }\n var nextState = {}\n var GL_STATE_NAMES = []\n var GL_FLAGS = {}\n var GL_VARIABLES = {}\n\n function propName (name) {\n return name.replace('.', '_')\n }\n\n function stateFlag (sname, cap, init) {\n var name = propName(sname)\n GL_STATE_NAMES.push(sname)\n nextState[name] = currentState[name] = !!init\n GL_FLAGS[name] = cap\n }\n\n function stateVariable (sname, func, init) {\n var name = propName(sname)\n GL_STATE_NAMES.push(sname)\n if (Array.isArray(init)) {\n currentState[name] = init.slice()\n nextState[name] = init.slice()\n } else {\n currentState[name] = nextState[name] = init\n }\n GL_VARIABLES[name] = func\n }\n\n // Dithering\n stateFlag(S_DITHER, GL_DITHER)\n\n // Blending\n stateFlag(S_BLEND_ENABLE, GL_BLEND)\n stateVariable(S_BLEND_COLOR, 'blendColor', [0, 0, 0, 0])\n stateVariable(S_BLEND_EQUATION, 'blendEquationSeparate',\n [GL_FUNC_ADD, GL_FUNC_ADD])\n stateVariable(S_BLEND_FUNC, 'blendFuncSeparate',\n [GL_ONE, GL_ZERO, GL_ONE, GL_ZERO])\n\n // Depth\n stateFlag(S_DEPTH_ENABLE, GL_DEPTH_TEST, true)\n stateVariable(S_DEPTH_FUNC, 'depthFunc', GL_LESS)\n stateVariable(S_DEPTH_RANGE, 'depthRange', [0, 1])\n stateVariable(S_DEPTH_MASK, 'depthMask', true)\n\n // Color mask\n stateVariable(S_COLOR_MASK, S_COLOR_MASK, [true, true, true, true])\n\n // Face culling\n stateFlag(S_CULL_ENABLE, GL_CULL_FACE)\n stateVariable(S_CULL_FACE, 'cullFace', GL_BACK)\n\n // Front face orientation\n stateVariable(S_FRONT_FACE, S_FRONT_FACE, GL_CCW)\n\n // Line width\n stateVariable(S_LINE_WIDTH, S_LINE_WIDTH, 1)\n\n // Polygon offset\n stateFlag(S_POLYGON_OFFSET_ENABLE, GL_POLYGON_OFFSET_FILL)\n stateVariable(S_POLYGON_OFFSET_OFFSET, 'polygonOffset', [0, 0])\n\n // Sample coverage\n stateFlag(S_SAMPLE_ALPHA, GL_SAMPLE_ALPHA_TO_COVERAGE)\n stateFlag(S_SAMPLE_ENABLE, GL_SAMPLE_COVERAGE)\n stateVariable(S_SAMPLE_COVERAGE, 'sampleCoverage', [1, false])\n\n // Stencil\n stateFlag(S_STENCIL_ENABLE, GL_STENCIL_TEST)\n stateVariable(S_STENCIL_MASK, 'stencilMask', -1)\n stateVariable(S_STENCIL_FUNC, 'stencilFunc', [GL_ALWAYS, 0, -1])\n stateVariable(S_STENCIL_OPFRONT, 'stencilOpSeparate',\n [GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP])\n stateVariable(S_STENCIL_OPBACK, 'stencilOpSeparate',\n [GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP])\n\n // Scissor\n stateFlag(S_SCISSOR_ENABLE, GL_SCISSOR_TEST)\n stateVariable(S_SCISSOR_BOX, 'scissor',\n [0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight])\n\n // Viewport\n stateVariable(S_VIEWPORT, S_VIEWPORT,\n [0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight])\n\n // ===================================================\n // ===================================================\n // ENVIRONMENT\n // ===================================================\n // ===================================================\n var sharedState = {\n gl: gl,\n context: contextState,\n strings: stringStore,\n next: nextState,\n current: currentState,\n draw: drawState,\n elements: elementState,\n buffer: bufferState,\n shader: shaderState,\n attributes: attributeState.state,\n uniforms: uniformState,\n framebuffer: framebufferState,\n extensions: extensions,\n\n timer: timer,\n isBufferArgs: isBufferArgs\n }\n\n var sharedConstants = {\n primTypes: primTypes,\n compareFuncs: compareFuncs,\n blendFuncs: blendFuncs,\n blendEquations: blendEquations,\n stencilOps: stencilOps,\n glTypes: glTypes,\n orientationType: orientationType\n }\n\n check.optional(function () {\n sharedState.isArrayLike = isArrayLike\n })\n\n if (extDrawBuffers) {\n sharedConstants.backBuffer = [GL_BACK]\n sharedConstants.drawBuffer = loop(limits.maxDrawbuffers, function (i) {\n if (i === 0) {\n return [0]\n }\n return loop(i, function (j) {\n return GL_COLOR_ATTACHMENT0 + j\n })\n })\n }\n\n var drawCallCounter = 0\n function createREGLEnvironment () {\n var env = createEnvironment()\n var link = env.link\n var global = env.global\n env.id = drawCallCounter++\n\n env.batchId = '0'\n\n // link shared state\n var SHARED = link(sharedState)\n var shared = env.shared = {\n props: 'a0'\n }\n Object.keys(sharedState).forEach(function (prop) {\n shared[prop] = global.def(SHARED, '.', prop)\n })\n\n // Inject runtime assertion stuff for debug builds\n check.optional(function () {\n env.CHECK = link(check)\n env.commandStr = check.guessCommand()\n env.command = link(env.commandStr)\n env.assert = function (block, pred, message) {\n block(\n 'if(!(', pred, '))',\n this.CHECK, '.commandRaise(', link(message), ',', this.command, ');')\n }\n })\n\n // Copy GL state variables over\n var nextVars = env.next = {}\n var currentVars = env.current = {}\n Object.keys(GL_VARIABLES).forEach(function (variable) {\n if (Array.isArray(currentState[variable])) {\n nextVars[variable] = global.def(shared.next, '.', variable)\n currentVars[variable] = global.def(shared.current, '.', variable)\n }\n })\n\n // Initialize shared constants\n var constants = env.constants = {}\n Object.keys(sharedConstants).forEach(function (name) {\n constants[name] = global.def(JSON.stringify(sharedConstants[name]))\n })\n\n // Helper function for calling a block\n env.invoke = function (block, x) {\n switch (x.type) {\n case DYN_FUNC:\n var argList = [\n 'this',\n shared.context,\n shared.props,\n env.batchId\n ]\n return block.def(\n link(x.data), '.call(',\n argList.slice(0, Math.max(x.data.length + 1, 4)),\n ')')\n case DYN_PROP:\n return block.def(shared.props, x.data)\n case DYN_CONTEXT:\n return block.def(shared.context, x.data)\n case DYN_STATE:\n return block.def('this', x.data)\n case DYN_THUNK:\n x.data.append(env, block)\n return x.data.ref\n }\n }\n\n env.attribCache = {}\n\n var scopeAttribs = {}\n env.scopeAttrib = function (name) {\n var id = stringStore.id(name)\n if (id in scopeAttribs) {\n return scopeAttribs[id]\n }\n var binding = attributeState.scope[id]\n if (!binding) {\n binding = attributeState.scope[id] = new AttributeRecord()\n }\n var result = scopeAttribs[id] = link(binding)\n return result\n }\n\n return env\n }\n\n // ===================================================\n // ===================================================\n // PARSING\n // ===================================================\n // ===================================================\n function parseProfile (options) {\n var staticOptions = options.static\n var dynamicOptions = options.dynamic\n\n var profileEnable\n if (S_PROFILE in staticOptions) {\n var value = !!staticOptions[S_PROFILE]\n profileEnable = createStaticDecl(function (env, scope) {\n return value\n })\n profileEnable.enable = value\n } else if (S_PROFILE in dynamicOptions) {\n var dyn = dynamicOptions[S_PROFILE]\n profileEnable = createDynamicDecl(dyn, function (env, scope) {\n return env.invoke(scope, dyn)\n })\n }\n\n return profileEnable\n }\n\n function parseFramebuffer (options) {\n var staticOptions = options.static\n var dynamicOptions = options.dynamic\n\n if (S_FRAMEBUFFER in staticOptions) {\n var framebuffer = staticOptions[S_FRAMEBUFFER]\n if (framebuffer) {\n framebuffer = framebufferState.getFramebuffer(framebuffer)\n check.command(framebuffer, 'invalid framebuffer object')\n return createStaticDecl(function (env, block) {\n var FRAMEBUFFER = env.link(framebuffer)\n var shared = env.shared\n block.set(\n shared.framebuffer,\n '.next',\n FRAMEBUFFER)\n var CONTEXT = shared.context\n block.set(\n CONTEXT,\n '.' + S_FRAMEBUFFER_WIDTH,\n FRAMEBUFFER + '.width')\n block.set(\n CONTEXT,\n '.' + S_FRAMEBUFFER_HEIGHT,\n FRAMEBUFFER + '.height')\n return FRAMEBUFFER\n })\n } else {\n return createStaticDecl(function (env, scope) {\n var shared = env.shared\n scope.set(\n shared.framebuffer,\n '.next',\n 'null')\n var CONTEXT = shared.context\n scope.set(\n CONTEXT,\n '.' + S_FRAMEBUFFER_WIDTH,\n CONTEXT + '.' + S_DRAWINGBUFFER_WIDTH)\n scope.set(\n CONTEXT,\n '.' + S_FRAMEBUFFER_HEIGHT,\n CONTEXT + '.' + S_DRAWINGBUFFER_HEIGHT)\n return 'null'\n })\n }\n } else if (S_FRAMEBUFFER in dynamicOptions) {\n var dyn = dynamicOptions[S_FRAMEBUFFER]\n return createDynamicDecl(dyn, function (env, scope) {\n var FRAMEBUFFER_FUNC = env.invoke(scope, dyn)\n var shared = env.shared\n var FRAMEBUFFER_STATE = shared.framebuffer\n var FRAMEBUFFER = scope.def(\n FRAMEBUFFER_STATE, '.getFramebuffer(', FRAMEBUFFER_FUNC, ')')\n\n check.optional(function () {\n env.assert(scope,\n '!' + FRAMEBUFFER_FUNC + '||' + FRAMEBUFFER,\n 'invalid framebuffer object')\n })\n\n scope.set(\n FRAMEBUFFER_STATE,\n '.next',\n FRAMEBUFFER)\n var CONTEXT = shared.context\n scope.set(\n CONTEXT,\n '.' + S_FRAMEBUFFER_WIDTH,\n FRAMEBUFFER + '?' + FRAMEBUFFER + '.width:' +\n CONTEXT + '.' + S_DRAWINGBUFFER_WIDTH)\n scope.set(\n CONTEXT,\n '.' + S_FRAMEBUFFER_HEIGHT,\n FRAMEBUFFER +\n '?' + FRAMEBUFFER + '.height:' +\n CONTEXT + '.' + S_DRAWINGBUFFER_HEIGHT)\n return FRAMEBUFFER\n })\n } else {\n return null\n }\n }\n\n function parseViewportScissor (options, framebuffer) {\n var staticOptions = options.static\n var dynamicOptions = options.dynamic\n\n function parseBox (param) {\n if (param in staticOptions) {\n var box = staticOptions[param]\n check.commandType(box, 'object', 'invalid ' + param)\n\n var isStatic = true\n var x = box.x | 0\n var y = box.y | 0\n check.command(x >= 0 && y >= 0, 'invalid ' + param)\n var w, h\n if ('width' in box) {\n w = box.width | 0\n check.command(w > 0, 'invalid ' + param)\n } else {\n isStatic = false\n }\n if ('height' in box) {\n h = box.height | 0\n check.command(h > 0, 'invalid ' + param)\n } else {\n isStatic = false\n }\n\n return new Declaration(\n !isStatic && framebuffer && framebuffer.thisDep,\n !isStatic && framebuffer && framebuffer.contextDep,\n !isStatic && framebuffer && framebuffer.propDep,\n function (env, scope) {\n var CONTEXT = env.shared.context\n var BOX_W = w\n if (!('width' in box)) {\n BOX_W = scope.def(CONTEXT, '.', S_FRAMEBUFFER_WIDTH, '-', x)\n } else {\n check.command(w > 0, 'invalid ' + param)\n }\n var BOX_H = h\n if (!('height' in box)) {\n BOX_H = scope.def(CONTEXT, '.', S_FRAMEBUFFER_HEIGHT, '-', y)\n } else {\n check.command(h > 0, 'invalid ' + param)\n }\n return [x, y, BOX_W, BOX_H]\n })\n } else if (param in dynamicOptions) {\n var dynBox = dynamicOptions[param]\n var result = createDynamicDecl(dynBox, function (env, scope) {\n var BOX = env.invoke(scope, dynBox)\n\n check.optional(function () {\n env.assert(scope,\n BOX + '&&typeof ' + BOX + '===\"object\"',\n 'invalid ' + param)\n })\n\n var CONTEXT = env.shared.context\n var BOX_X = scope.def(BOX, '.x|0')\n var BOX_Y = scope.def(BOX, '.y|0')\n var BOX_W = scope.def(\n '\"width\" in ', BOX, '?', BOX, '.width|0:',\n '(', CONTEXT, '.', S_FRAMEBUFFER_WIDTH, '-', BOX_X, ')')\n var BOX_H = scope.def(\n '\"height\" in ', BOX, '?', BOX, '.height|0:',\n '(', CONTEXT, '.', S_FRAMEBUFFER_HEIGHT, '-', BOX_Y, ')')\n\n check.optional(function () {\n env.assert(scope,\n BOX_X + '>=0&&' +\n BOX_Y + '>=0&&' +\n BOX_W + '>0&&' +\n BOX_H + '>0',\n 'invalid ' + param)\n })\n\n return [BOX_X, BOX_Y, BOX_W, BOX_H]\n })\n if (framebuffer) {\n result.thisDep = result.thisDep || framebuffer.thisDep\n result.contextDep = result.contextDep || framebuffer.contextDep\n result.propDep = result.propDep || framebuffer.propDep\n }\n return result\n } else if (framebuffer) {\n return new Declaration(\n framebuffer.thisDep,\n framebuffer.contextDep,\n framebuffer.propDep,\n function (env, scope) {\n var CONTEXT = env.shared.context\n return [\n 0, 0,\n scope.def(CONTEXT, '.', S_FRAMEBUFFER_WIDTH),\n scope.def(CONTEXT, '.', S_FRAMEBUFFER_HEIGHT)]\n })\n } else {\n return null\n }\n }\n\n var viewport = parseBox(S_VIEWPORT)\n\n if (viewport) {\n var prevViewport = viewport\n viewport = new Declaration(\n viewport.thisDep,\n viewport.contextDep,\n viewport.propDep,\n function (env, scope) {\n var VIEWPORT = prevViewport.append(env, scope)\n var CONTEXT = env.shared.context\n scope.set(\n CONTEXT,\n '.' + S_VIEWPORT_WIDTH,\n VIEWPORT[2])\n scope.set(\n CONTEXT,\n '.' + S_VIEWPORT_HEIGHT,\n VIEWPORT[3])\n return VIEWPORT\n })\n }\n\n return {\n viewport: viewport,\n scissor_box: parseBox(S_SCISSOR_BOX)\n }\n }\n\n function parseProgram (options) {\n var staticOptions = options.static\n var dynamicOptions = options.dynamic\n\n function parseShader (name) {\n if (name in staticOptions) {\n var id = stringStore.id(staticOptions[name])\n check.optional(function () {\n shaderState.shader(shaderType[name], id, check.guessCommand())\n })\n var result = createStaticDecl(function () {\n return id\n })\n result.id = id\n return result\n } else if (name in dynamicOptions) {\n var dyn = dynamicOptions[name]\n return createDynamicDecl(dyn, function (env, scope) {\n var str = env.invoke(scope, dyn)\n var id = scope.def(env.shared.strings, '.id(', str, ')')\n check.optional(function () {\n scope(\n env.shared.shader, '.shader(',\n shaderType[name], ',',\n id, ',',\n env.command, ');')\n })\n return id\n })\n }\n return null\n }\n\n var frag = parseShader(S_FRAG)\n var vert = parseShader(S_VERT)\n\n var program = null\n var progVar\n if (isStatic(frag) && isStatic(vert)) {\n program = shaderState.program(vert.id, frag.id)\n progVar = createStaticDecl(function (env, scope) {\n return env.link(program)\n })\n } else {\n progVar = new Declaration(\n (frag && frag.thisDep) || (vert && vert.thisDep),\n (frag && frag.contextDep) || (vert && vert.contextDep),\n (frag && frag.propDep) || (vert && vert.propDep),\n function (env, scope) {\n var SHADER_STATE = env.shared.shader\n var fragId\n if (frag) {\n fragId = frag.append(env, scope)\n } else {\n fragId = scope.def(SHADER_STATE, '.', S_FRAG)\n }\n var vertId\n if (vert) {\n vertId = vert.append(env, scope)\n } else {\n vertId = scope.def(SHADER_STATE, '.', S_VERT)\n }\n var progDef = SHADER_STATE + '.program(' + vertId + ',' + fragId\n check.optional(function () {\n progDef += ',' + env.command\n })\n return scope.def(progDef + ')')\n })\n }\n\n return {\n frag: frag,\n vert: vert,\n progVar: progVar,\n program: program\n }\n }\n\n function parseDraw (options) {\n var staticOptions = options.static\n var dynamicOptions = options.dynamic\n\n function parseElements () {\n if (S_ELEMENTS in staticOptions) {\n var elements = staticOptions[S_ELEMENTS]\n if (isBufferArgs(elements)) {\n elements = elementState.getElements(elementState.create(elements))\n } else if (elements) {\n elements = elementState.getElements(elements)\n check.command(elements, 'invalid elements')\n }\n var result = createStaticDecl(function (env, scope) {\n if (elements) {\n var result = env.link(elements)\n env.ELEMENTS = result\n return result\n }\n env.ELEMENTS = null\n return null\n })\n result.value = elements\n return result\n } else if (S_ELEMENTS in dynamicOptions) {\n var dyn = dynamicOptions[S_ELEMENTS]\n return createDynamicDecl(dyn, function (env, scope) {\n var shared = env.shared\n\n var IS_BUFFER_ARGS = shared.isBufferArgs\n var ELEMENT_STATE = shared.elements\n\n var elementDefn = env.invoke(scope, dyn)\n var elements = scope.def('null')\n var elementStream = scope.def(IS_BUFFER_ARGS, '(', elementDefn, ')')\n\n var ifte = env.cond(elementStream)\n .then(elements, '=', ELEMENT_STATE, '.createStream(', elementDefn, ');')\n .else(elements, '=', ELEMENT_STATE, '.getElements(', elementDefn, ');')\n\n check.optional(function () {\n env.assert(ifte.else,\n '!' + elementDefn + '||' + elements,\n 'invalid elements')\n })\n\n scope.entry(ifte)\n scope.exit(\n env.cond(elementStream)\n .then(ELEMENT_STATE, '.destroyStream(', elements, ');'))\n\n env.ELEMENTS = elements\n\n return elements\n })\n }\n\n return null\n }\n\n var elements = parseElements()\n\n function parsePrimitive () {\n if (S_PRIMITIVE in staticOptions) {\n var primitive = staticOptions[S_PRIMITIVE]\n check.commandParameter(primitive, primTypes, 'invalid primitve')\n return createStaticDecl(function (env, scope) {\n return primTypes[primitive]\n })\n } else if (S_PRIMITIVE in dynamicOptions) {\n var dynPrimitive = dynamicOptions[S_PRIMITIVE]\n return createDynamicDecl(dynPrimitive, function (env, scope) {\n var PRIM_TYPES = env.constants.primTypes\n var prim = env.invoke(scope, dynPrimitive)\n check.optional(function () {\n env.assert(scope,\n prim + ' in ' + PRIM_TYPES,\n 'invalid primitive, must be one of ' + Object.keys(primTypes))\n })\n return scope.def(PRIM_TYPES, '[', prim, ']')\n })\n } else if (elements) {\n if (isStatic(elements)) {\n if (elements.value) {\n return createStaticDecl(function (env, scope) {\n return scope.def(env.ELEMENTS, '.primType')\n })\n } else {\n return createStaticDecl(function () {\n return GL_TRIANGLES\n })\n }\n } else {\n return new Declaration(\n elements.thisDep,\n elements.contextDep,\n elements.propDep,\n function (env, scope) {\n var elements = env.ELEMENTS\n return scope.def(elements, '?', elements, '.primType:', GL_TRIANGLES)\n })\n }\n }\n return null\n }\n\n function parseParam (param, isOffset) {\n if (param in staticOptions) {\n var value = staticOptions[param] | 0\n check.command(!isOffset || value >= 0, 'invalid ' + param)\n return createStaticDecl(function (env, scope) {\n if (isOffset) {\n env.OFFSET = value\n }\n return value\n })\n } else if (param in dynamicOptions) {\n var dynValue = dynamicOptions[param]\n return createDynamicDecl(dynValue, function (env, scope) {\n var result = env.invoke(scope, dynValue)\n if (isOffset) {\n env.OFFSET = result\n check.optional(function () {\n env.assert(scope,\n result + '>=0',\n 'invalid ' + param)\n })\n }\n return result\n })\n } else if (isOffset && elements) {\n return createStaticDecl(function (env, scope) {\n env.OFFSET = '0'\n return 0\n })\n }\n return null\n }\n\n var OFFSET = parseParam(S_OFFSET, true)\n\n function parseVertCount () {\n if (S_COUNT in staticOptions) {\n var count = staticOptions[S_COUNT] | 0\n check.command(\n typeof count === 'number' && count >= 0, 'invalid vertex count')\n return createStaticDecl(function () {\n return count\n })\n } else if (S_COUNT in dynamicOptions) {\n var dynCount = dynamicOptions[S_COUNT]\n return createDynamicDecl(dynCount, function (env, scope) {\n var result = env.invoke(scope, dynCount)\n check.optional(function () {\n env.assert(scope,\n 'typeof ' + result + '===\"number\"&&' +\n result + '>=0&&' +\n result + '===(' + result + '|0)',\n 'invalid vertex count')\n })\n return result\n })\n } else if (elements) {\n if (isStatic(elements)) {\n if (elements) {\n if (OFFSET) {\n return new Declaration(\n OFFSET.thisDep,\n OFFSET.contextDep,\n OFFSET.propDep,\n function (env, scope) {\n var result = scope.def(\n env.ELEMENTS, '.vertCount-', env.OFFSET)\n\n check.optional(function () {\n env.assert(scope,\n result + '>=0',\n 'invalid vertex offset/element buffer too small')\n })\n\n return result\n })\n } else {\n return createStaticDecl(function (env, scope) {\n return scope.def(env.ELEMENTS, '.vertCount')\n })\n }\n } else {\n var result = createStaticDecl(function () {\n return -1\n })\n check.optional(function () {\n result.MISSING = true\n })\n return result\n }\n } else {\n var variable = new Declaration(\n elements.thisDep || OFFSET.thisDep,\n elements.contextDep || OFFSET.contextDep,\n elements.propDep || OFFSET.propDep,\n function (env, scope) {\n var elements = env.ELEMENTS\n if (env.OFFSET) {\n return scope.def(elements, '?', elements, '.vertCount-',\n env.OFFSET, ':-1')\n }\n return scope.def(elements, '?', elements, '.vertCount:-1')\n })\n check.optional(function () {\n variable.DYNAMIC = true\n })\n return variable\n }\n }\n return null\n }\n\n return {\n elements: elements,\n primitive: parsePrimitive(),\n count: parseVertCount(),\n instances: parseParam(S_INSTANCES, false),\n offset: OFFSET\n }\n }\n\n function parseGLState (options) {\n var staticOptions = options.static\n var dynamicOptions = options.dynamic\n\n var STATE = {}\n\n GL_STATE_NAMES.forEach(function (prop) {\n var param = propName(prop)\n\n function parseParam (parseStatic, parseDynamic) {\n if (prop in staticOptions) {\n var value = parseStatic(staticOptions[prop])\n STATE[param] = createStaticDecl(function () {\n return value\n })\n } else if (prop in dynamicOptions) {\n var dyn = dynamicOptions[prop]\n STATE[param] = createDynamicDecl(dyn, function (env, scope) {\n return parseDynamic(env, scope, env.invoke(scope, dyn))\n })\n }\n }\n\n switch (prop) {\n case S_CULL_ENABLE:\n case S_BLEND_ENABLE:\n case S_DITHER:\n case S_STENCIL_ENABLE:\n case S_DEPTH_ENABLE:\n case S_SCISSOR_ENABLE:\n case S_POLYGON_OFFSET_ENABLE:\n case S_SAMPLE_ALPHA:\n case S_SAMPLE_ENABLE:\n case S_DEPTH_MASK:\n return parseParam(\n function (value) {\n check.commandType(value, 'boolean', prop)\n return value\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n 'typeof ' + value + '===\"boolean\"',\n 'invalid flag ' + prop)\n })\n return value\n })\n\n case S_DEPTH_FUNC:\n return parseParam(\n function (value) {\n check.commandParameter(value, compareFuncs, 'invalid ' + prop)\n return compareFuncs[value]\n },\n function (env, scope, value) {\n var COMPARE_FUNCS = env.constants.compareFuncs\n check.optional(function () {\n env.assert(scope,\n value + ' in ' + COMPARE_FUNCS,\n 'invalid ' + prop + ', must be one of ' + Object.keys(compareFuncs))\n })\n return scope.def(COMPARE_FUNCS, '[', value, ']')\n })\n\n case S_DEPTH_RANGE:\n return parseParam(\n function (value) {\n check.command(\n isArrayLike(value) &&\n value.length === 2 &&\n typeof value[0] === 'number' &&\n typeof value[1] === 'number' &&\n value[0] <= value[1],\n 'depth range is 2d array')\n return value\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n env.shared.isArrayLike + '(' + value + ')&&' +\n value + '.length===2&&' +\n 'typeof ' + value + '[0]===\"number\"&&' +\n 'typeof ' + value + '[1]===\"number\"&&' +\n value + '[0]<=' + value + '[1]',\n 'depth range must be a 2d array')\n })\n\n var Z_NEAR = scope.def('+', value, '[0]')\n var Z_FAR = scope.def('+', value, '[1]')\n return [Z_NEAR, Z_FAR]\n })\n\n case S_BLEND_FUNC:\n return parseParam(\n function (value) {\n check.commandType(value, 'object', 'blend.func')\n var srcRGB = ('srcRGB' in value ? value.srcRGB : value.src)\n var srcAlpha = ('srcAlpha' in value ? value.srcAlpha : value.src)\n var dstRGB = ('dstRGB' in value ? value.dstRGB : value.dst)\n var dstAlpha = ('dstAlpha' in value ? value.dstAlpha : value.dst)\n check.commandParameter(srcRGB, blendFuncs, param + '.srcRGB')\n check.commandParameter(srcAlpha, blendFuncs, param + '.srcAlpha')\n check.commandParameter(dstRGB, blendFuncs, param + '.dstRGB')\n check.commandParameter(dstAlpha, blendFuncs, param + '.dstAlpha')\n return [\n blendFuncs[srcRGB],\n blendFuncs[dstRGB],\n blendFuncs[srcAlpha],\n blendFuncs[dstAlpha]\n ]\n },\n function (env, scope, value) {\n var BLEND_FUNCS = env.constants.blendFuncs\n\n check.optional(function () {\n env.assert(scope,\n value + '&&typeof ' + value + '===\"object\"',\n 'invalid blend func, must be an object')\n })\n\n function read (prefix, suffix) {\n var func = scope.def(\n '\"', prefix, suffix, '\" in ', value,\n '?', value, '.', prefix, suffix,\n ':', value, '.', prefix)\n\n check.optional(function () {\n env.assert(scope,\n func + ' in ' + BLEND_FUNCS,\n 'invalid ' + prop + '.' + prefix + suffix + ', must be one of ' + Object.keys(blendFuncs))\n })\n\n return scope.def(BLEND_FUNCS, '[', func, ']')\n }\n\n var SRC_RGB = read('src', 'RGB')\n var SRC_ALPHA = read('src', 'Alpha')\n var DST_RGB = read('dst', 'RGB')\n var DST_ALPHA = read('dst', 'Alpha')\n\n return [SRC_RGB, DST_RGB, SRC_ALPHA, DST_ALPHA]\n })\n\n case S_BLEND_EQUATION:\n return parseParam(\n function (value) {\n if (typeof value === 'string') {\n check.commandParameter(value, blendEquations, 'invalid ' + prop)\n return [\n blendEquations[value],\n blendEquations[value]\n ]\n } else if (typeof value === 'object') {\n check.commandParameter(\n value.rgb, blendEquations, prop + '.rgb')\n check.commandParameter(\n value.alpha, blendEquations, prop + '.alpha')\n return [\n blendEquations[value.rgb],\n blendEquations[value.alpha]\n ]\n } else {\n check.commandRaise('invalid blend.equation')\n }\n },\n function (env, scope, value) {\n var BLEND_EQUATIONS = env.constants.blendEquations\n\n var RGB = scope.def()\n var ALPHA = scope.def()\n\n var ifte = env.cond('typeof ', value, '===\"string\"')\n\n check.optional(function () {\n function checkProp (block, name, value) {\n env.assert(block,\n value + ' in ' + BLEND_EQUATIONS,\n 'invalid ' + name + ', must be one of ' + Object.keys(blendEquations))\n }\n checkProp(ifte.then, prop, value)\n\n env.assert(ifte.else,\n value + '&&typeof ' + value + '===\"object\"',\n 'invalid ' + prop)\n checkProp(ifte.else, prop + '.rgb', value + '.rgb')\n checkProp(ifte.else, prop + '.alpha', value + '.alpha')\n })\n\n ifte.then(\n RGB, '=', ALPHA, '=', BLEND_EQUATIONS, '[', value, '];')\n ifte.else(\n RGB, '=', BLEND_EQUATIONS, '[', value, '.rgb];',\n ALPHA, '=', BLEND_EQUATIONS, '[', value, '.alpha];')\n\n scope(ifte)\n\n return [RGB, ALPHA]\n })\n\n case S_BLEND_COLOR:\n return parseParam(\n function (value) {\n check.command(\n isArrayLike(value) &&\n value.length === 4,\n 'blend.color must be a 4d array')\n return loop(4, function (i) {\n return +value[i]\n })\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n env.shared.isArrayLike + '(' + value + ')&&' +\n value + '.length===4',\n 'blend.color must be a 4d array')\n })\n return loop(4, function (i) {\n return scope.def('+', value, '[', i, ']')\n })\n })\n\n case S_STENCIL_MASK:\n return parseParam(\n function (value) {\n check.commandType(value, 'number', param)\n return value | 0\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n 'typeof ' + value + '===\"number\"',\n 'invalid stencil.mask')\n })\n return scope.def(value, '|0')\n })\n\n case S_STENCIL_FUNC:\n return parseParam(\n function (value) {\n check.commandType(value, 'object', param)\n var cmp = value.cmp || 'keep'\n var ref = value.ref || 0\n var mask = 'mask' in value ? value.mask : -1\n check.commandParameter(cmp, compareFuncs, prop + '.cmp')\n check.commandType(ref, 'number', prop + '.ref')\n check.commandType(mask, 'number', prop + '.mask')\n return [\n compareFuncs[cmp],\n ref,\n mask\n ]\n },\n function (env, scope, value) {\n var COMPARE_FUNCS = env.constants.compareFuncs\n check.optional(function () {\n function assert () {\n env.assert(scope,\n Array.prototype.join.call(arguments, ''),\n 'invalid stencil.func')\n }\n assert(value + '&&typeof ', value, '===\"object\"')\n assert('!(\"cmp\" in ', value, ')||(',\n value, '.cmp in ', COMPARE_FUNCS, ')')\n })\n var cmp = scope.def(\n '\"cmp\" in ', value,\n '?', COMPARE_FUNCS, '[', value, '.cmp]',\n ':', GL_KEEP)\n var ref = scope.def(value, '.ref|0')\n var mask = scope.def(\n '\"mask\" in ', value,\n '?', value, '.mask|0:-1')\n return [cmp, ref, mask]\n })\n\n case S_STENCIL_OPFRONT:\n case S_STENCIL_OPBACK:\n return parseParam(\n function (value) {\n check.commandType(value, 'object', param)\n var fail = value.fail || 'keep'\n var zfail = value.zfail || 'keep'\n var pass = value.pass || 'keep'\n check.commandParameter(fail, stencilOps, prop + '.fail')\n check.commandParameter(zfail, stencilOps, prop + '.zfail')\n check.commandParameter(pass, stencilOps, prop + '.pass')\n return [\n prop === S_STENCIL_OPBACK ? GL_BACK : GL_FRONT,\n stencilOps[fail],\n stencilOps[zfail],\n stencilOps[pass]\n ]\n },\n function (env, scope, value) {\n var STENCIL_OPS = env.constants.stencilOps\n\n check.optional(function () {\n env.assert(scope,\n value + '&&typeof ' + value + '===\"object\"',\n 'invalid ' + prop)\n })\n\n function read (name) {\n check.optional(function () {\n env.assert(scope,\n '!(\"' + name + '\" in ' + value + ')||' +\n '(' + value + '.' + name + ' in ' + STENCIL_OPS + ')',\n 'invalid ' + prop + '.' + name + ', must be one of ' + Object.keys(stencilOps))\n })\n\n return scope.def(\n '\"', name, '\" in ', value,\n '?', STENCIL_OPS, '[', value, '.', name, ']:',\n GL_KEEP)\n }\n\n return [\n prop === S_STENCIL_OPBACK ? GL_BACK : GL_FRONT,\n read('fail'),\n read('zfail'),\n read('pass')\n ]\n })\n\n case S_POLYGON_OFFSET_OFFSET:\n return parseParam(\n function (value) {\n check.commandType(value, 'object', param)\n var factor = value.factor | 0\n var units = value.units | 0\n check.commandType(factor, 'number', param + '.factor')\n check.commandType(units, 'number', param + '.units')\n return [factor, units]\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n value + '&&typeof ' + value + '===\"object\"',\n 'invalid ' + prop)\n })\n\n var FACTOR = scope.def(value, '.factor|0')\n var UNITS = scope.def(value, '.units|0')\n\n return [FACTOR, UNITS]\n })\n\n case S_CULL_FACE:\n return parseParam(\n function (value) {\n var face = 0\n if (value === 'front') {\n face = GL_FRONT\n } else if (value === 'back') {\n face = GL_BACK\n }\n check.command(!!face, param)\n return face\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n value + '===\"front\"||' +\n value + '===\"back\"',\n 'invalid cull.face')\n })\n return scope.def(value, '===\"front\"?', GL_FRONT, ':', GL_BACK)\n })\n\n case S_LINE_WIDTH:\n return parseParam(\n function (value) {\n check.command(\n typeof value === 'number' &&\n value >= limits.lineWidthDims[0] &&\n value <= limits.lineWidthDims[1],\n 'invalid line width, must positive number between ' +\n limits.lineWidthDims[0] + ' and ' + limits.lineWidthDims[1])\n return value\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n 'typeof ' + value + '===\"number\"&&' +\n value + '>=' + limits.lineWidthDims[0] + '&&' +\n value + '<=' + limits.lineWidthDims[1],\n 'invalid line width')\n })\n\n return value\n })\n\n case S_FRONT_FACE:\n return parseParam(\n function (value) {\n check.commandParameter(value, orientationType, param)\n return orientationType[value]\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n value + '===\"cw\"||' +\n value + '===\"ccw\"',\n 'invalid frontFace, must be one of cw,ccw')\n })\n return scope.def(value + '===\"cw\"?' + GL_CW + ':' + GL_CCW)\n })\n\n case S_COLOR_MASK:\n return parseParam(\n function (value) {\n check.command(\n isArrayLike(value) && value.length === 4,\n 'color.mask must be length 4 array')\n return value.map(function (v) { return !!v })\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n env.shared.isArrayLike + '(' + value + ')&&' +\n value + '.length===4',\n 'invalid color.mask')\n })\n return loop(4, function (i) {\n return '!!' + value + '[' + i + ']'\n })\n })\n\n case S_SAMPLE_COVERAGE:\n return parseParam(\n function (value) {\n check.command(typeof value === 'object' && value, param)\n var sampleValue = 'value' in value ? value.value : 1\n var sampleInvert = !!value.invert\n check.command(\n typeof sampleValue === 'number' &&\n sampleValue >= 0 && sampleValue <= 1,\n 'sample.coverage.value must be a number between 0 and 1')\n return [sampleValue, sampleInvert]\n },\n function (env, scope, value) {\n check.optional(function () {\n env.assert(scope,\n value + '&&typeof ' + value + '===\"object\"',\n 'invalid sample.coverage')\n })\n var VALUE = scope.def(\n '\"value\" in ', value, '?+', value, '.value:1')\n var INVERT = scope.def('!!', value, '.invert')\n return [VALUE, INVERT]\n })\n }\n })\n\n return STATE\n }\n\n function parseOptions (options) {\n var staticOptions = options.static\n var dynamicOptions = options.dynamic\n\n check.optional(function () {\n var command = check.guessCommand()\n\n var KEY_NAMES = [\n S_FRAMEBUFFER,\n S_VERT,\n S_FRAG,\n S_ELEMENTS,\n S_PRIMITIVE,\n S_OFFSET,\n S_COUNT,\n S_INSTANCES,\n S_PROFILE\n ].concat(GL_STATE_NAMES)\n\n function checkKeys (dict) {\n Object.keys(dict).forEach(function (key) {\n check.command(\n KEY_NAMES.indexOf(key) >= 0,\n 'unknown parameter \"' + key + '\"',\n command)\n })\n }\n\n checkKeys(staticOptions)\n checkKeys(dynamicOptions)\n })\n\n var framebuffer = parseFramebuffer(options)\n var viewportAndScissor = parseViewportScissor(options, framebuffer)\n var draw = parseDraw(options)\n var state = parseGLState(options)\n var shader = parseProgram(options)\n\n function copyBox (name) {\n var defn = viewportAndScissor[name]\n if (defn) {\n state[name] = defn\n }\n }\n copyBox(S_VIEWPORT)\n copyBox(propName(S_SCISSOR_BOX))\n\n var dirty = Object.keys(state).length > 0\n\n return {\n framebuffer: framebuffer,\n draw: draw,\n shader: shader,\n state: state,\n dirty: dirty\n }\n }\n\n function parseUniforms (uniforms) {\n var staticUniforms = uniforms.static\n var dynamicUniforms = uniforms.dynamic\n\n var UNIFORMS = {}\n\n Object.keys(staticUniforms).forEach(function (name) {\n var value = staticUniforms[name]\n var result\n if (typeof value === 'number' ||\n typeof value === 'boolean') {\n result = createStaticDecl(function () {\n return value\n })\n } else if (typeof value === 'function') {\n var reglType = value._reglType\n if (reglType === 'texture2d' ||\n reglType === 'textureCube') {\n result = createStaticDecl(function (env) {\n return env.link(value)\n })\n } else if (reglType === 'framebuffer' ||\n reglType === 'framebufferCube') {\n check(value.color.length > 0,\n 'missing color attachment for framebuffer sent to uniform \"' + name + '\"')\n result = createStaticDecl(function (env) {\n return env.link(value.color[0])\n })\n } else {\n check.raise('invalid data for uniform \"' + name + '\"')\n }\n } else if (isArrayLike(value)) {\n result = createStaticDecl(function (env) {\n var ITEM = env.global.def('[',\n loop(value.length, function (i) {\n check.command(\n typeof value[i] === 'number' ||\n typeof value[i] === 'boolean',\n 'invalid uniform ' + name)\n return value[i]\n }), ']')\n return ITEM\n })\n } else {\n check.commandRaise('invalid or missing data for uniform \"' + name + '\"')\n }\n result.value = value\n UNIFORMS[name] = result\n })\n\n Object.keys(dynamicUniforms).forEach(function (key) {\n var dyn = dynamicUniforms[key]\n UNIFORMS[key] = createDynamicDecl(dyn, function (env, scope) {\n return env.invoke(scope, dyn)\n })\n })\n\n return UNIFORMS\n }\n\n function parseAttributes (attributes) {\n var staticAttributes = attributes.static\n var dynamicAttributes = attributes.dynamic\n\n var attributeDefs = {}\n\n Object.keys(staticAttributes).forEach(function (attribute) {\n var value = staticAttributes[attribute]\n var id = stringStore.id(attribute)\n\n var record = new AttributeRecord()\n if (isBufferArgs(value)) {\n record.state = ATTRIB_STATE_POINTER\n record.buffer = bufferState.getBuffer(\n bufferState.create(value, GL_ARRAY_BUFFER, false))\n record.type = record.buffer.dtype\n } else {\n var buffer = bufferState.getBuffer(value)\n if (buffer) {\n record.state = ATTRIB_STATE_POINTER\n record.buffer = buffer\n record.type = buffer.dtype\n } else {\n check.command(typeof value === 'object' && value,\n 'invalid data for attribute ' + attribute)\n if (value.constant) {\n var constant = value.constant\n record.buffer = 'null'\n record.state = ATTRIB_STATE_CONSTANT\n if (typeof constant === 'number') {\n record.x = constant\n } else {\n check.command(\n isArrayLike(constant) &&\n constant.length > 0 &&\n constant.length <= 4,\n 'invalid constant for attribute ' + attribute)\n CUTE_COMPONENTS.forEach(function (c, i) {\n if (i < constant.length) {\n record[c] = constant[i]\n }\n })\n }\n } else {\n buffer = bufferState.getBuffer(value.buffer)\n check.command(!!buffer, 'missing buffer for attribute \"' + attribute + '\"')\n\n var offset = value.offset | 0\n check.command(offset >= 0,\n 'invalid offset for attribute \"' + attribute + '\"')\n\n var stride = value.stride | 0\n check.command(stride >= 0 && stride < 256,\n 'invalid stride for attribute \"' + attribute + '\", must be integer betweeen [0, 255]')\n\n var size = value.size | 0\n check.command(!('size' in value) || (size > 0 && size <= 4),\n 'invalid size for attribute \"' + attribute + '\", must be 1,2,3,4')\n\n var normalized = !!value.normalized\n\n var type = 0\n if ('type' in value) {\n check.commandParameter(\n value.type, glTypes,\n 'invalid type for attribute ' + attribute)\n type = glTypes[value.type]\n }\n\n var divisor = value.divisor | 0\n if ('divisor' in value) {\n check.command(divisor === 0 || extInstancing,\n 'cannot specify divisor for attribute \"' + attribute + '\", instancing not supported')\n check.command(divisor >= 0,\n 'invalid divisor for attribute \"' + attribute + '\"')\n }\n\n check.optional(function () {\n var command = check.guessCommand()\n\n var VALID_KEYS = [\n 'buffer',\n 'offset',\n 'divisor',\n 'normalized',\n 'type',\n 'size',\n 'stride'\n ]\n\n Object.keys(value).forEach(function (prop) {\n check.command(\n VALID_KEYS.indexOf(prop) >= 0,\n 'unknown parameter \"' + prop + '\" for attribute pointer \"' + attribute + '\" (valid parameters are ' + VALID_KEYS + ')',\n command)\n })\n })\n\n record.buffer = buffer\n record.state = ATTRIB_STATE_POINTER\n record.size = size\n record.normalized = normalized\n record.type = type || buffer.dtype\n record.offset = offset\n record.stride = stride\n record.divisor = divisor\n }\n }\n }\n\n attributeDefs[attribute] = createStaticDecl(function (env, scope) {\n var cache = env.attribCache\n if (id in cache) {\n return cache[id]\n }\n var result = {\n isStream: false\n }\n Object.keys(record).forEach(function (key) {\n result[key] = record[key]\n })\n if (record.buffer) {\n result.buffer = env.link(record.buffer)\n }\n cache[id] = result\n return result\n })\n })\n\n Object.keys(dynamicAttributes).forEach(function (attribute) {\n var dyn = dynamicAttributes[attribute]\n\n function appendAttributeCode (env, block) {\n var VALUE = env.invoke(block, dyn)\n\n var shared = env.shared\n\n var IS_BUFFER_ARGS = shared.isBufferArgs\n var BUFFER_STATE = shared.buffer\n\n // Perform validation on attribute\n check.optional(function () {\n env.assert(block,\n VALUE + '&&(typeof ' + VALUE + '===\"object\"||typeof ' +\n VALUE + '===\"function\")&&(' +\n IS_BUFFER_ARGS + '(' + VALUE + ')||' +\n BUFFER_STATE + '.getBuffer(' + VALUE + ')||' +\n BUFFER_STATE + '.getBuffer(' + VALUE + '.buffer)||' +\n '(\"constant\" in ' + VALUE +\n '&&(typeof ' + VALUE + '.constant===\"number\"||' +\n shared.isArrayLike + '(' + VALUE + '.constant))))',\n 'invalid dynamic attribute \"' + attribute + '\"')\n })\n\n // allocate names for result\n var result = {\n isStream: block.def(false)\n }\n var defaultRecord = new AttributeRecord()\n defaultRecord.state = ATTRIB_STATE_POINTER\n Object.keys(defaultRecord).forEach(function (key) {\n result[key] = block.def('' + defaultRecord[key])\n })\n\n var BUFFER = result.buffer\n var TYPE = result.type\n block(\n 'if(', IS_BUFFER_ARGS, '(', VALUE, ')){',\n result.isStream, '=true;',\n BUFFER, '=', BUFFER_STATE, '.createStream(', GL_ARRAY_BUFFER, ',', VALUE, ');',\n TYPE, '=', BUFFER, '.dtype;',\n '}else{',\n BUFFER, '=', BUFFER_STATE, '.getBuffer(', VALUE, ');',\n 'if(', BUFFER, '){',\n TYPE, '=', BUFFER, '.dtype;',\n '}else if(\"constant\" in ', VALUE, '){',\n result.state, '=', ATTRIB_STATE_CONSTANT, ';',\n 'if(typeof ' + VALUE + '.constant === \"number\"){',\n result[CUTE_COMPONENTS[0]], '=', VALUE, '.constant;',\n CUTE_COMPONENTS.slice(1).map(function (n) {\n return result[n]\n }).join('='), '=0;',\n '}else{',\n CUTE_COMPONENTS.map(function (name, i) {\n return (\n result[name] + '=' + VALUE + '.constant.length>=' + i +\n '?' + VALUE + '.constant[' + i + ']:0;'\n )\n }).join(''),\n '}}else{',\n BUFFER, '=', BUFFER_STATE, '.getBuffer(', VALUE, '.buffer);',\n TYPE, '=\"type\" in ', VALUE, '?',\n shared.glTypes, '[', VALUE, '.type]:', BUFFER, '.dtype;',\n result.normalized, '=!!', VALUE, '.normalized;')\n function emitReadRecord (name) {\n block(result[name], '=', VALUE, '.', name, '|0;')\n }\n emitReadRecord('size')\n emitReadRecord('offset')\n emitReadRecord('stride')\n emitReadRecord('divisor')\n\n block('}}')\n\n block.exit(\n 'if(', result.isStream, '){',\n BUFFER_STATE, '.destroyStream(', BUFFER, ');',\n '}')\n\n return result\n }\n\n attributeDefs[attribute] = createDynamicDecl(dyn, appendAttributeCode)\n })\n\n return attributeDefs\n }\n\n function parseContext (context) {\n var staticContext = context.static\n var dynamicContext = context.dynamic\n var result = {}\n\n Object.keys(staticContext).forEach(function (name) {\n var value = staticContext[name]\n result[name] = createStaticDecl(function (env, scope) {\n if (typeof value === 'number' || typeof value === 'boolean') {\n return '' + value\n } else {\n return env.link(value)\n }\n })\n })\n\n Object.keys(dynamicContext).forEach(function (name) {\n var dyn = dynamicContext[name]\n result[name] = createDynamicDecl(dyn, function (env, scope) {\n return env.invoke(scope, dyn)\n })\n })\n\n return result\n }\n\n function parseArguments (options, attributes, uniforms, context) {\n var result = parseOptions(options)\n\n result.profile = parseProfile(options)\n result.uniforms = parseUniforms(uniforms)\n result.attributes = parseAttributes(attributes)\n result.context = parseContext(context)\n return result\n }\n\n // ===================================================\n // ===================================================\n // COMMON UPDATE FUNCTIONS\n // ===================================================\n // ===================================================\n function emitContext (env, scope, context) {\n var shared = env.shared\n var CONTEXT = shared.context\n\n var contextEnter = env.scope()\n\n Object.keys(context).forEach(function (name) {\n scope.save(CONTEXT, '.' + name)\n var defn = context[name]\n contextEnter(CONTEXT, '.', name, '=', defn.append(env, scope), ';')\n })\n\n scope(contextEnter)\n }\n\n // ===================================================\n // ===================================================\n // COMMON DRAWING FUNCTIONS\n // ===================================================\n // ===================================================\n function emitPollFramebuffer (env, scope, framebuffer, skipCheck) {\n var shared = env.shared\n\n var GL = shared.gl\n var FRAMEBUFFER_STATE = shared.framebuffer\n var EXT_DRAW_BUFFERS\n if (extDrawBuffers) {\n EXT_DRAW_BUFFERS = scope.def(shared.extensions, '.webgl_draw_buffers')\n }\n\n var constants = env.constants\n\n var DRAW_BUFFERS = constants.drawBuffer\n var BACK_BUFFER = constants.backBuffer\n\n var NEXT\n if (framebuffer) {\n NEXT = framebuffer.append(env, scope)\n } else {\n NEXT = scope.def(FRAMEBUFFER_STATE, '.next')\n }\n\n if (!skipCheck) {\n scope('if(', NEXT, '!==', FRAMEBUFFER_STATE, '.cur){')\n }\n scope(\n 'if(', NEXT, '){',\n GL, '.bindFramebuffer(', GL_FRAMEBUFFER, ',', NEXT, '.framebuffer);')\n if (extDrawBuffers) {\n scope(EXT_DRAW_BUFFERS, '.drawBuffersWEBGL(',\n DRAW_BUFFERS, '[', NEXT, '.colorAttachments.length]);')\n }\n scope('}else{',\n GL, '.bindFramebuffer(', GL_FRAMEBUFFER, ',null);')\n if (extDrawBuffers) {\n scope(EXT_DRAW_BUFFERS, '.drawBuffersWEBGL(', BACK_BUFFER, ');')\n }\n scope(\n '}',\n FRAMEBUFFER_STATE, '.cur=', NEXT, ';')\n if (!skipCheck) {\n scope('}')\n }\n }\n\n function emitPollState (env, scope, args) {\n var shared = env.shared\n\n var GL = shared.gl\n\n var CURRENT_VARS = env.current\n var NEXT_VARS = env.next\n var CURRENT_STATE = shared.current\n var NEXT_STATE = shared.next\n\n var block = env.cond(CURRENT_STATE, '.dirty')\n\n GL_STATE_NAMES.forEach(function (prop) {\n var param = propName(prop)\n if (param in args.state) {\n return\n }\n\n var NEXT, CURRENT\n if (param in NEXT_VARS) {\n NEXT = NEXT_VARS[param]\n CURRENT = CURRENT_VARS[param]\n var parts = loop(currentState[param].length, function (i) {\n return block.def(NEXT, '[', i, ']')\n })\n block(env.cond(parts.map(function (p, i) {\n return p + '!==' + CURRENT + '[' + i + ']'\n }).join('||'))\n .then(\n GL, '.', GL_VARIABLES[param], '(', parts, ');',\n parts.map(function (p, i) {\n return CURRENT + '[' + i + ']=' + p\n }).join(';'), ';'))\n } else {\n NEXT = block.def(NEXT_STATE, '.', param)\n var ifte = env.cond(NEXT, '!==', CURRENT_STATE, '.', param)\n block(ifte)\n if (param in GL_FLAGS) {\n ifte(\n env.cond(NEXT)\n .then(GL, '.enable(', GL_FLAGS[param], ');')\n .else(GL, '.disable(', GL_FLAGS[param], ');'),\n CURRENT_STATE, '.', param, '=', NEXT, ';')\n } else {\n ifte(\n GL, '.', GL_VARIABLES[param], '(', NEXT, ');',\n CURRENT_STATE, '.', param, '=', NEXT, ';')\n }\n }\n })\n if (Object.keys(args.state).length === 0) {\n block(CURRENT_STATE, '.dirty=false;')\n }\n scope(block)\n }\n\n function emitSetOptions (env, scope, options, filter) {\n var shared = env.shared\n var CURRENT_VARS = env.current\n var CURRENT_STATE = shared.current\n var GL = shared.gl\n sortState(Object.keys(options)).forEach(function (param) {\n var defn = options[param]\n if (filter && !filter(defn)) {\n return\n }\n var variable = defn.append(env, scope)\n if (GL_FLAGS[param]) {\n var flag = GL_FLAGS[param]\n if (isStatic(defn)) {\n if (variable) {\n scope(GL, '.enable(', flag, ');')\n } else {\n scope(GL, '.disable(', flag, ');')\n }\n } else {\n scope(env.cond(variable)\n .then(GL, '.enable(', flag, ');')\n .else(GL, '.disable(', flag, ');'))\n }\n scope(CURRENT_STATE, '.', param, '=', variable, ';')\n } else if (isArrayLike(variable)) {\n var CURRENT = CURRENT_VARS[param]\n scope(\n GL, '.', GL_VARIABLES[param], '(', variable, ');',\n variable.map(function (v, i) {\n return CURRENT + '[' + i + ']=' + v\n }).join(';'), ';')\n } else {\n scope(\n GL, '.', GL_VARIABLES[param], '(', variable, ');',\n CURRENT_STATE, '.', param, '=', variable, ';')\n }\n })\n }\n\n function injectExtensions (env, scope) {\n if (extInstancing && !env.instancing) {\n env.instancing = scope.def(\n env.shared.extensions, '.angle_instanced_arrays')\n }\n }\n\n function emitProfile (env, scope, args, useScope, incrementCounter) {\n var shared = env.shared\n var STATS = env.stats\n var CURRENT_STATE = shared.current\n var TIMER = shared.timer\n var profileArg = args.profile\n\n function perfCounter () {\n if (typeof performance === 'undefined') {\n return 'Date.now()'\n } else {\n return 'performance.now()'\n }\n }\n\n var CPU_START, QUERY_COUNTER\n function emitProfileStart (block) {\n CPU_START = scope.def()\n block(CPU_START, '=', perfCounter(), ';')\n if (typeof incrementCounter === 'string') {\n block(STATS, '.count+=', incrementCounter, ';')\n } else {\n block(STATS, '.count++;')\n }\n if (timer) {\n if (useScope) {\n QUERY_COUNTER = scope.def()\n block(QUERY_COUNTER, '=', TIMER, '.getNumPendingQueries();')\n } else {\n block(TIMER, '.beginQuery(', STATS, ');')\n }\n }\n }\n\n function emitProfileEnd (block) {\n block(STATS, '.cpuTime+=', perfCounter(), '-', CPU_START, ';')\n if (timer) {\n if (useScope) {\n block(TIMER, '.pushScopeStats(',\n QUERY_COUNTER, ',',\n TIMER, '.getNumPendingQueries(),',\n STATS, ');')\n } else {\n block(TIMER, '.endQuery();')\n }\n }\n }\n\n function scopeProfile (value) {\n var prev = scope.def(CURRENT_STATE, '.profile')\n scope(CURRENT_STATE, '.profile=', value, ';')\n scope.exit(CURRENT_STATE, '.profile=', prev, ';')\n }\n\n var USE_PROFILE\n if (profileArg) {\n if (isStatic(profileArg)) {\n if (profileArg.enable) {\n emitProfileStart(scope)\n emitProfileEnd(scope.exit)\n scopeProfile('true')\n } else {\n scopeProfile('false')\n }\n return\n }\n USE_PROFILE = profileArg.append(env, scope)\n scopeProfile(USE_PROFILE)\n } else {\n USE_PROFILE = scope.def(CURRENT_STATE, '.profile')\n }\n\n var start = env.block()\n emitProfileStart(start)\n scope('if(', USE_PROFILE, '){', start, '}')\n var end = env.block()\n emitProfileEnd(end)\n scope.exit('if(', USE_PROFILE, '){', end, '}')\n }\n\n function emitAttributes (env, scope, args, attributes, filter) {\n var shared = env.shared\n\n function typeLength (x) {\n switch (x) {\n case GL_FLOAT_VEC2:\n case GL_INT_VEC2:\n case GL_BOOL_VEC2:\n return 2\n case GL_FLOAT_VEC3:\n case GL_INT_VEC3:\n case GL_BOOL_VEC3:\n return 3\n case GL_FLOAT_VEC4:\n case GL_INT_VEC4:\n case GL_BOOL_VEC4:\n return 4\n default:\n return 1\n }\n }\n\n function emitBindAttribute (ATTRIBUTE, size, record) {\n var GL = shared.gl\n\n var LOCATION = scope.def(ATTRIBUTE, '.location')\n var BINDING = scope.def(shared.attributes, '[', LOCATION, ']')\n\n var STATE = record.state\n var BUFFER = record.buffer\n var CONST_COMPONENTS = [\n record.x,\n record.y,\n record.z,\n record.w\n ]\n\n var COMMON_KEYS = [\n 'buffer',\n 'normalized',\n 'offset',\n 'stride'\n ]\n\n function emitBuffer () {\n scope(\n 'if(!', BINDING, '.buffer){',\n GL, '.enableVertexAttribArray(', LOCATION, ');}')\n\n var TYPE = record.type\n var SIZE\n if (!record.size) {\n SIZE = size\n } else {\n SIZE = scope.def(record.size, '||', size)\n }\n\n scope('if(',\n BINDING, '.type!==', TYPE, '||',\n BINDING, '.size!==', SIZE, '||',\n COMMON_KEYS.map(function (key) {\n return BINDING + '.' + key + '!==' + record[key]\n }).join('||'),\n '){',\n GL, '.bindBuffer(', GL_ARRAY_BUFFER, ',', BUFFER, '.buffer);',\n GL, '.vertexAttribPointer(', [\n LOCATION,\n SIZE,\n TYPE,\n record.normalized,\n record.stride,\n record.offset\n ], ');',\n BINDING, '.type=', TYPE, ';',\n BINDING, '.size=', SIZE, ';',\n COMMON_KEYS.map(function (key) {\n return BINDING + '.' + key + '=' + record[key] + ';'\n }).join(''),\n '}')\n\n if (extInstancing) {\n var DIVISOR = record.divisor\n scope(\n 'if(', BINDING, '.divisor!==', DIVISOR, '){',\n env.instancing, '.vertexAttribDivisorANGLE(', [LOCATION, DIVISOR], ');',\n BINDING, '.divisor=', DIVISOR, ';}')\n }\n }\n\n function emitConstant () {\n scope(\n 'if(', BINDING, '.buffer){',\n GL, '.disableVertexAttribArray(', LOCATION, ');',\n '}if(', CUTE_COMPONENTS.map(function (c, i) {\n return BINDING + '.' + c + '!==' + CONST_COMPONENTS[i]\n }).join('||'), '){',\n GL, '.vertexAttrib4f(', LOCATION, ',', CONST_COMPONENTS, ');',\n CUTE_COMPONENTS.map(function (c, i) {\n return BINDING + '.' + c + '=' + CONST_COMPONENTS[i] + ';'\n }).join(''),\n '}')\n }\n\n if (STATE === ATTRIB_STATE_POINTER) {\n emitBuffer()\n } else if (STATE === ATTRIB_STATE_CONSTANT) {\n emitConstant()\n } else {\n scope('if(', STATE, '===', ATTRIB_STATE_POINTER, '){')\n emitBuffer()\n scope('}else{')\n emitConstant()\n scope('}')\n }\n }\n\n attributes.forEach(function (attribute) {\n var name = attribute.name\n var arg = args.attributes[name]\n var record\n if (arg) {\n if (!filter(arg)) {\n return\n }\n record = arg.append(env, scope)\n } else {\n if (!filter(SCOPE_DECL)) {\n return\n }\n var scopeAttrib = env.scopeAttrib(name)\n check.optional(function () {\n env.assert(scope,\n scopeAttrib + '.state',\n 'missing attribute ' + name)\n })\n record = {}\n Object.keys(new AttributeRecord()).forEach(function (key) {\n record[key] = scope.def(scopeAttrib, '.', key)\n })\n }\n emitBindAttribute(\n env.link(attribute), typeLength(attribute.info.type), record)\n })\n }\n\n function emitUniforms (env, scope, args, uniforms, filter) {\n var shared = env.shared\n var GL = shared.gl\n\n var infix\n for (var i = 0; i < uniforms.length; ++i) {\n var uniform = uniforms[i]\n var name = uniform.name\n var type = uniform.info.type\n var arg = args.uniforms[name]\n var UNIFORM = env.link(uniform)\n var LOCATION = UNIFORM + '.location'\n\n var VALUE\n if (arg) {\n if (!filter(arg)) {\n continue\n }\n if (isStatic(arg)) {\n var value = arg.value\n check.command(\n value !== null && typeof value !== 'undefined',\n 'missing uniform \"' + name + '\"')\n if (type === GL_SAMPLER_2D || type === GL_SAMPLER_CUBE) {\n check.command(\n typeof value === 'function' &&\n ((type === GL_SAMPLER_2D &&\n (value._reglType === 'texture2d' ||\n value._reglType === 'framebuffer')) ||\n (type === GL_SAMPLER_CUBE &&\n (value._reglType === 'textureCube' ||\n value._reglType === 'framebufferCube'))),\n 'invalid texture for uniform ' + name)\n var TEX_VALUE = env.link(value._texture || value.color[0]._texture)\n scope(GL, '.uniform1i(', LOCATION, ',', TEX_VALUE + '.bind());')\n scope.exit(TEX_VALUE, '.unbind();')\n } else if (\n type === GL_FLOAT_MAT2 ||\n type === GL_FLOAT_MAT3 ||\n type === GL_FLOAT_MAT4) {\n check.optional(function () {\n check.command(isArrayLike(value),\n 'invalid matrix for uniform ' + name)\n check.command(\n (type === GL_FLOAT_MAT2 && value.length === 4) ||\n (type === GL_FLOAT_MAT3 && value.length === 9) ||\n (type === GL_FLOAT_MAT4 && value.length === 16),\n 'invalid length for matrix uniform ' + name)\n })\n var MAT_VALUE = env.global.def('new Float32Array([' +\n Array.prototype.slice.call(value) + '])')\n var dim = 2\n if (type === GL_FLOAT_MAT3) {\n dim = 3\n } else if (type === GL_FLOAT_MAT4) {\n dim = 4\n }\n scope(\n GL, '.uniformMatrix', dim, 'fv(',\n LOCATION, ',false,', MAT_VALUE, ');')\n } else {\n switch (type) {\n case GL_FLOAT:\n check.commandType(value, 'number', 'uniform ' + name)\n infix = '1f'\n break\n case GL_FLOAT_VEC2:\n check.command(\n isArrayLike(value) && value.length === 2,\n 'uniform ' + name)\n infix = '2f'\n break\n case GL_FLOAT_VEC3:\n check.command(\n isArrayLike(value) && value.length === 3,\n 'uniform ' + name)\n infix = '3f'\n break\n case GL_FLOAT_VEC4:\n check.command(\n isArrayLike(value) && value.length === 4,\n 'uniform ' + name)\n infix = '4f'\n break\n case GL_BOOL:\n check.commandType(value, 'boolean', 'uniform ' + name)\n infix = '1i'\n break\n case GL_INT:\n check.commandType(value, 'number', 'uniform ' + name)\n infix = '1i'\n break\n case GL_BOOL_VEC2:\n check.command(\n isArrayLike(value) && value.length === 2,\n 'uniform ' + name)\n infix = '2i'\n break\n case GL_INT_VEC2:\n check.command(\n isArrayLike(value) && value.length === 2,\n 'uniform ' + name)\n infix = '2i'\n break\n case GL_BOOL_VEC3:\n check.command(\n isArrayLike(value) && value.length === 3,\n 'uniform ' + name)\n infix = '3i'\n break\n case GL_INT_VEC3:\n check.command(\n isArrayLike(value) && value.length === 3,\n 'uniform ' + name)\n infix = '3i'\n break\n case GL_BOOL_VEC4:\n check.command(\n isArrayLike(value) && value.length === 4,\n 'uniform ' + name)\n infix = '4i'\n break\n case GL_INT_VEC4:\n check.command(\n isArrayLike(value) && value.length === 4,\n 'uniform ' + name)\n infix = '4i'\n break\n }\n scope(GL, '.uniform', infix, '(', LOCATION, ',',\n isArrayLike(value) ? Array.prototype.slice.call(value) : value,\n ');')\n }\n continue\n } else {\n VALUE = arg.append(env, scope)\n }\n } else {\n if (!filter(SCOPE_DECL)) {\n continue\n }\n VALUE = scope.def(shared.uniforms, '[', stringStore.id(name), ']')\n }\n\n if (type === GL_SAMPLER_2D) {\n scope(\n 'if(', VALUE, '&&', VALUE, '._reglType===\"framebuffer\"){',\n VALUE, '=', VALUE, '.color[0];',\n '}')\n } else if (type === GL_SAMPLER_CUBE) {\n scope(\n 'if(', VALUE, '&&', VALUE, '._reglType===\"framebufferCube\"){',\n VALUE, '=', VALUE, '.color[0];',\n '}')\n }\n\n // perform type validation\n check.optional(function () {\n function check (pred, message) {\n env.assert(scope, pred,\n 'bad data for uniform \"' + name + '\". ' + message)\n }\n\n function checkType (type) {\n check(\n 'typeof ' + VALUE + '===\"' + type + '\"',\n 'invalid type, expected ' + type)\n }\n\n function checkVector (n, type) {\n check(\n shared.isArrayLike + '(' + VALUE + ')&&' + VALUE + '.length===' + n,\n 'invalid vector, should have length ' + n)\n }\n\n function checkTexture (target) {\n check(\n 'typeof ' + VALUE + '===\"function\"&&' +\n VALUE + '._reglType===\"texture' +\n (target === GL_TEXTURE_2D ? '2d' : 'Cube') + '\"',\n 'invalid texture type')\n }\n\n switch (type) {\n case GL_INT:\n checkType('number')\n break\n case GL_INT_VEC2:\n checkVector(2, 'number')\n break\n case GL_INT_VEC3:\n checkVector(3, 'number')\n break\n case GL_INT_VEC4:\n checkVector(4, 'number')\n break\n case GL_FLOAT:\n checkType('number')\n break\n case GL_FLOAT_VEC2:\n checkVector(2, 'number')\n break\n case GL_FLOAT_VEC3:\n checkVector(3, 'number')\n break\n case GL_FLOAT_VEC4:\n checkVector(4, 'number')\n break\n case GL_BOOL:\n checkType('boolean')\n break\n case GL_BOOL_VEC2:\n checkVector(2, 'boolean')\n break\n case GL_BOOL_VEC3:\n checkVector(3, 'boolean')\n break\n case GL_BOOL_VEC4:\n checkVector(4, 'boolean')\n break\n case GL_FLOAT_MAT2:\n checkVector(4, 'number')\n break\n case GL_FLOAT_MAT3:\n checkVector(9, 'number')\n break\n case GL_FLOAT_MAT4:\n checkVector(16, 'number')\n break\n case GL_SAMPLER_2D:\n checkTexture(GL_TEXTURE_2D)\n break\n case GL_SAMPLER_CUBE:\n checkTexture(GL_TEXTURE_CUBE_MAP)\n break\n }\n })\n\n var unroll = 1\n switch (type) {\n case GL_SAMPLER_2D:\n case GL_SAMPLER_CUBE:\n var TEX = scope.def(VALUE, '._texture')\n scope(GL, '.uniform1i(', LOCATION, ',', TEX, '.bind());')\n scope.exit(TEX, '.unbind();')\n continue\n\n case GL_INT:\n case GL_BOOL:\n infix = '1i'\n break\n\n case GL_INT_VEC2:\n case GL_BOOL_VEC2:\n infix = '2i'\n unroll = 2\n break\n\n case GL_INT_VEC3:\n case GL_BOOL_VEC3:\n infix = '3i'\n unroll = 3\n break\n\n case GL_INT_VEC4:\n case GL_BOOL_VEC4:\n infix = '4i'\n unroll = 4\n break\n\n case GL_FLOAT:\n infix = '1f'\n break\n\n case GL_FLOAT_VEC2:\n infix = '2f'\n unroll = 2\n break\n\n case GL_FLOAT_VEC3:\n infix = '3f'\n unroll = 3\n break\n\n case GL_FLOAT_VEC4:\n infix = '4f'\n unroll = 4\n break\n\n case GL_FLOAT_MAT2:\n infix = 'Matrix2fv'\n break\n\n case GL_FLOAT_MAT3:\n infix = 'Matrix3fv'\n break\n\n case GL_FLOAT_MAT4:\n infix = 'Matrix4fv'\n break\n }\n\n scope(GL, '.uniform', infix, '(', LOCATION, ',')\n if (infix.charAt(0) === 'M') {\n var matSize = Math.pow(type - GL_FLOAT_MAT2 + 2, 2)\n var STORAGE = env.global.def('new Float32Array(', matSize, ')')\n scope(\n 'false,(Array.isArray(', VALUE, ')||', VALUE, ' instanceof Float32Array)?', VALUE, ':(',\n loop(matSize, function (i) {\n return STORAGE + '[' + i + ']=' + VALUE + '[' + i + ']'\n }), ',', STORAGE, ')')\n } else if (unroll > 1) {\n scope(loop(unroll, function (i) {\n return VALUE + '[' + i + ']'\n }))\n } else {\n scope(VALUE)\n }\n scope(');')\n }\n }\n\n function emitDraw (env, outer, inner, args) {\n var shared = env.shared\n var GL = shared.gl\n var DRAW_STATE = shared.draw\n\n var drawOptions = args.draw\n\n function emitElements () {\n var defn = drawOptions.elements\n var ELEMENTS\n var scope = outer\n if (defn) {\n if ((defn.contextDep && args.contextDynamic) || defn.propDep) {\n scope = inner\n }\n ELEMENTS = defn.append(env, scope)\n } else {\n ELEMENTS = scope.def(DRAW_STATE, '.', S_ELEMENTS)\n }\n if (ELEMENTS) {\n scope(\n 'if(' + ELEMENTS + ')' +\n GL + '.bindBuffer(' + GL_ELEMENT_ARRAY_BUFFER + ',' + ELEMENTS + '.buffer.buffer);')\n }\n return ELEMENTS\n }\n\n function emitCount () {\n var defn = drawOptions.count\n var COUNT\n var scope = outer\n if (defn) {\n if ((defn.contextDep && args.contextDynamic) || defn.propDep) {\n scope = inner\n }\n COUNT = defn.append(env, scope)\n check.optional(function () {\n if (defn.MISSING) {\n env.assert(outer, 'false', 'missing vertex count')\n }\n if (defn.DYNAMIC) {\n env.assert(scope, COUNT + '>=0', 'missing vertex count')\n }\n })\n } else {\n COUNT = scope.def(DRAW_STATE, '.', S_COUNT)\n check.optional(function () {\n env.assert(scope, COUNT + '>=0', 'missing vertex count')\n })\n }\n return COUNT\n }\n\n var ELEMENTS = emitElements()\n function emitValue (name) {\n var defn = drawOptions[name]\n if (defn) {\n if ((defn.contextDep && args.contextDynamic) || defn.propDep) {\n return defn.append(env, inner)\n } else {\n return defn.append(env, outer)\n }\n } else {\n return outer.def(DRAW_STATE, '.', name)\n }\n }\n\n var PRIMITIVE = emitValue(S_PRIMITIVE)\n var OFFSET = emitValue(S_OFFSET)\n\n var COUNT = emitCount()\n if (typeof COUNT === 'number') {\n if (COUNT === 0) {\n return\n }\n } else {\n inner('if(', COUNT, '){')\n inner.exit('}')\n }\n\n var INSTANCES, EXT_INSTANCING\n if (extInstancing) {\n INSTANCES = emitValue(S_INSTANCES)\n EXT_INSTANCING = env.instancing\n }\n\n var ELEMENT_TYPE = ELEMENTS + '.type'\n\n var elementsStatic = drawOptions.elements && isStatic(drawOptions.elements)\n\n function emitInstancing () {\n function drawElements () {\n inner(EXT_INSTANCING, '.drawElementsInstancedANGLE(', [\n PRIMITIVE,\n COUNT,\n ELEMENT_TYPE,\n OFFSET + '<<((' + ELEMENT_TYPE + '-' + GL_UNSIGNED_BYTE + ')>>1)',\n INSTANCES\n ], ');')\n }\n\n function drawArrays () {\n inner(EXT_INSTANCING, '.drawArraysInstancedANGLE(',\n [PRIMITIVE, OFFSET, COUNT, INSTANCES], ');')\n }\n\n if (ELEMENTS) {\n if (!elementsStatic) {\n inner('if(', ELEMENTS, '){')\n drawElements()\n inner('}else{')\n drawArrays()\n inner('}')\n } else {\n drawElements()\n }\n } else {\n drawArrays()\n }\n }\n\n function emitRegular () {\n function drawElements () {\n inner(GL + '.drawElements(' + [\n PRIMITIVE,\n COUNT,\n ELEMENT_TYPE,\n OFFSET + '<<((' + ELEMENT_TYPE + '-' + GL_UNSIGNED_BYTE + ')>>1)'\n ] + ');')\n }\n\n function drawArrays () {\n inner(GL + '.drawArrays(' + [PRIMITIVE, OFFSET, COUNT] + ');')\n }\n\n if (ELEMENTS) {\n if (!elementsStatic) {\n inner('if(', ELEMENTS, '){')\n drawElements()\n inner('}else{')\n drawArrays()\n inner('}')\n } else {\n drawElements()\n }\n } else {\n drawArrays()\n }\n }\n\n if (extInstancing && (typeof INSTANCES !== 'number' || INSTANCES >= 0)) {\n if (typeof INSTANCES === 'string') {\n inner('if(', INSTANCES, '>0){')\n emitInstancing()\n inner('}else if(', INSTANCES, '<0){')\n emitRegular()\n inner('}')\n } else {\n emitInstancing()\n }\n } else {\n emitRegular()\n }\n }\n\n function createBody (emitBody, parentEnv, args, program, count) {\n var env = createREGLEnvironment()\n var scope = env.proc('body', count)\n check.optional(function () {\n env.commandStr = parentEnv.commandStr\n env.command = env.link(parentEnv.commandStr)\n })\n if (extInstancing) {\n env.instancing = scope.def(\n env.shared.extensions, '.angle_instanced_arrays')\n }\n emitBody(env, scope, args, program)\n return env.compile().body\n }\n\n // ===================================================\n // ===================================================\n // DRAW PROC\n // ===================================================\n // ===================================================\n function emitDrawBody (env, draw, args, program) {\n injectExtensions(env, draw)\n emitAttributes(env, draw, args, program.attributes, function () {\n return true\n })\n emitUniforms(env, draw, args, program.uniforms, function () {\n return true\n })\n emitDraw(env, draw, draw, args)\n }\n\n function emitDrawProc (env, args) {\n var draw = env.proc('draw', 1)\n\n injectExtensions(env, draw)\n\n emitContext(env, draw, args.context)\n emitPollFramebuffer(env, draw, args.framebuffer)\n\n emitPollState(env, draw, args)\n emitSetOptions(env, draw, args.state)\n\n emitProfile(env, draw, args, false, true)\n\n var program = args.shader.progVar.append(env, draw)\n draw(env.shared.gl, '.useProgram(', program, '.program);')\n\n if (args.shader.program) {\n emitDrawBody(env, draw, args, args.shader.program)\n } else {\n var drawCache = env.global.def('{}')\n var PROG_ID = draw.def(program, '.id')\n var CACHED_PROC = draw.def(drawCache, '[', PROG_ID, ']')\n draw(\n env.cond(CACHED_PROC)\n .then(CACHED_PROC, '.call(this,a0);')\n .else(\n CACHED_PROC, '=', drawCache, '[', PROG_ID, ']=',\n env.link(function (program) {\n return createBody(emitDrawBody, env, args, program, 1)\n }), '(', program, ');',\n CACHED_PROC, '.call(this,a0);'))\n }\n\n if (Object.keys(args.state).length > 0) {\n draw(env.shared.current, '.dirty=true;')\n }\n }\n\n // ===================================================\n // ===================================================\n // BATCH PROC\n // ===================================================\n // ===================================================\n\n function emitBatchDynamicShaderBody (env, scope, args, program) {\n env.batchId = 'a1'\n\n injectExtensions(env, scope)\n\n function all () {\n return true\n }\n\n emitAttributes(env, scope, args, program.attributes, all)\n emitUniforms(env, scope, args, program.uniforms, all)\n emitDraw(env, scope, scope, args)\n }\n\n function emitBatchBody (env, scope, args, program) {\n injectExtensions(env, scope)\n\n var contextDynamic = args.contextDep\n\n var BATCH_ID = scope.def()\n var PROP_LIST = 'a0'\n var NUM_PROPS = 'a1'\n var PROPS = scope.def()\n env.shared.props = PROPS\n env.batchId = BATCH_ID\n\n var outer = env.scope()\n var inner = env.scope()\n\n scope(\n outer.entry,\n 'for(', BATCH_ID, '=0;', BATCH_ID, '<', NUM_PROPS, ';++', BATCH_ID, '){',\n PROPS, '=', PROP_LIST, '[', BATCH_ID, '];',\n inner,\n '}',\n outer.exit)\n\n function isInnerDefn (defn) {\n return ((defn.contextDep && contextDynamic) || defn.propDep)\n }\n\n function isOuterDefn (defn) {\n return !isInnerDefn(defn)\n }\n\n if (args.needsContext) {\n emitContext(env, inner, args.context)\n }\n if (args.needsFramebuffer) {\n emitPollFramebuffer(env, inner, args.framebuffer)\n }\n emitSetOptions(env, inner, args.state, isInnerDefn)\n\n if (args.profile && isInnerDefn(args.profile)) {\n emitProfile(env, inner, args, false, true)\n }\n\n if (!program) {\n var progCache = env.global.def('{}')\n var PROGRAM = args.shader.progVar.append(env, inner)\n var PROG_ID = inner.def(PROGRAM, '.id')\n var CACHED_PROC = inner.def(progCache, '[', PROG_ID, ']')\n inner(\n env.shared.gl, '.useProgram(', PROGRAM, '.program);',\n 'if(!', CACHED_PROC, '){',\n CACHED_PROC, '=', progCache, '[', PROG_ID, ']=',\n env.link(function (program) {\n return createBody(\n emitBatchDynamicShaderBody, env, args, program, 2)\n }), '(', PROGRAM, ');}',\n CACHED_PROC, '.call(this,a0[', BATCH_ID, '],', BATCH_ID, ');')\n } else {\n emitAttributes(env, outer, args, program.attributes, isOuterDefn)\n emitAttributes(env, inner, args, program.attributes, isInnerDefn)\n emitUniforms(env, outer, args, program.uniforms, isOuterDefn)\n emitUniforms(env, inner, args, program.uniforms, isInnerDefn)\n emitDraw(env, outer, inner, args)\n }\n }\n\n function emitBatchProc (env, args) {\n var batch = env.proc('batch', 2)\n env.batchId = '0'\n\n injectExtensions(env, batch)\n\n // Check if any context variables depend on props\n var contextDynamic = false\n var needsContext = true\n Object.keys(args.context).forEach(function (name) {\n contextDynamic = contextDynamic || args.context[name].propDep\n })\n if (!contextDynamic) {\n emitContext(env, batch, args.context)\n needsContext = false\n }\n\n // framebuffer state affects framebufferWidth/height context vars\n var framebuffer = args.framebuffer\n var needsFramebuffer = false\n if (framebuffer) {\n if (framebuffer.propDep) {\n contextDynamic = needsFramebuffer = true\n } else if (framebuffer.contextDep && contextDynamic) {\n needsFramebuffer = true\n }\n if (!needsFramebuffer) {\n emitPollFramebuffer(env, batch, framebuffer)\n }\n } else {\n emitPollFramebuffer(env, batch, null)\n }\n\n // viewport is weird because it can affect context vars\n if (args.state.viewport && args.state.viewport.propDep) {\n contextDynamic = true\n }\n\n function isInnerDefn (defn) {\n return (defn.contextDep && contextDynamic) || defn.propDep\n }\n\n // set webgl options\n emitPollState(env, batch, args)\n emitSetOptions(env, batch, args.state, function (defn) {\n return !isInnerDefn(defn)\n })\n\n if (!args.profile || !isInnerDefn(args.profile)) {\n emitProfile(env, batch, args, false, 'a1')\n }\n\n // Save these values to args so that the batch body routine can use them\n args.contextDep = contextDynamic\n args.needsContext = needsContext\n args.needsFramebuffer = needsFramebuffer\n\n // determine if shader is dynamic\n var progDefn = args.shader.progVar\n if ((progDefn.contextDep && contextDynamic) || progDefn.propDep) {\n emitBatchBody(\n env,\n batch,\n args,\n null)\n } else {\n var PROGRAM = progDefn.append(env, batch)\n batch(env.shared.gl, '.useProgram(', PROGRAM, '.program);')\n if (args.shader.program) {\n emitBatchBody(\n env,\n batch,\n args,\n args.shader.program)\n } else {\n var batchCache = env.global.def('{}')\n var PROG_ID = batch.def(PROGRAM, '.id')\n var CACHED_PROC = batch.def(batchCache, '[', PROG_ID, ']')\n batch(\n env.cond(CACHED_PROC)\n .then(CACHED_PROC, '.call(this,a0,a1);')\n .else(\n CACHED_PROC, '=', batchCache, '[', PROG_ID, ']=',\n env.link(function (program) {\n return createBody(emitBatchBody, env, args, program, 2)\n }), '(', PROGRAM, ');',\n CACHED_PROC, '.call(this,a0,a1);'))\n }\n }\n\n if (Object.keys(args.state).length > 0) {\n batch(env.shared.current, '.dirty=true;')\n }\n }\n\n // ===================================================\n // ===================================================\n // SCOPE COMMAND\n // ===================================================\n // ===================================================\n function emitScopeProc (env, args) {\n var scope = env.proc('scope', 3)\n env.batchId = 'a2'\n\n var shared = env.shared\n var CURRENT_STATE = shared.current\n\n emitContext(env, scope, args.context)\n\n if (args.framebuffer) {\n args.framebuffer.append(env, scope)\n }\n\n sortState(Object.keys(args.state)).forEach(function (name) {\n var defn = args.state[name]\n var value = defn.append(env, scope)\n if (isArrayLike(value)) {\n value.forEach(function (v, i) {\n scope.set(env.next[name], '[' + i + ']', v)\n })\n } else {\n scope.set(shared.next, '.' + name, value)\n }\n })\n\n emitProfile(env, scope, args, true, true)\n\n ;[S_ELEMENTS, S_OFFSET, S_COUNT, S_INSTANCES, S_PRIMITIVE].forEach(\n function (opt) {\n var variable = args.draw[opt]\n if (!variable) {\n return\n }\n scope.set(shared.draw, '.' + opt, '' + variable.append(env, scope))\n })\n\n Object.keys(args.uniforms).forEach(function (opt) {\n scope.set(\n shared.uniforms,\n '[' + stringStore.id(opt) + ']',\n args.uniforms[opt].append(env, scope))\n })\n\n Object.keys(args.attributes).forEach(function (name) {\n var record = args.attributes[name].append(env, scope)\n var scopeAttrib = env.scopeAttrib(name)\n Object.keys(new AttributeRecord()).forEach(function (prop) {\n scope.set(scopeAttrib, '.' + prop, record[prop])\n })\n })\n\n function saveShader (name) {\n var shader = args.shader[name]\n if (shader) {\n scope.set(shared.shader, '.' + name, shader.append(env, scope))\n }\n }\n saveShader(S_VERT)\n saveShader(S_FRAG)\n\n if (Object.keys(args.state).length > 0) {\n scope(CURRENT_STATE, '.dirty=true;')\n scope.exit(CURRENT_STATE, '.dirty=true;')\n }\n\n scope('a1(', env.shared.context, ',a0,', env.batchId, ');')\n }\n\n function isDynamicObject (object) {\n if (typeof object !== 'object' || isArrayLike(object)) {\n return\n }\n var props = Object.keys(object)\n for (var i = 0; i < props.length; ++i) {\n if (dynamic.isDynamic(object[props[i]])) {\n return true\n }\n }\n return false\n }\n\n function splatObject (env, options, name) {\n var object = options.static[name]\n if (!object || !isDynamicObject(object)) {\n return\n }\n\n var globals = env.global\n var keys = Object.keys(object)\n var thisDep = false\n var contextDep = false\n var propDep = false\n var objectRef = env.global.def('{}')\n keys.forEach(function (key) {\n var value = object[key]\n if (dynamic.isDynamic(value)) {\n if (typeof value === 'function') {\n value = object[key] = dynamic.unbox(value)\n }\n var deps = createDynamicDecl(value, null)\n thisDep = thisDep || deps.thisDep\n propDep = propDep || deps.propDep\n contextDep = contextDep || deps.contextDep\n } else {\n globals(objectRef, '.', key, '=')\n switch (typeof value) {\n case 'number':\n globals(value)\n break\n case 'string':\n globals('\"', value, '\"')\n break\n case 'object':\n if (Array.isArray(value)) {\n globals('[', value.join(), ']')\n }\n break\n default:\n globals(env.link(value))\n break\n }\n globals(';')\n }\n })\n\n function appendBlock (env, block) {\n keys.forEach(function (key) {\n var value = object[key]\n if (!dynamic.isDynamic(value)) {\n return\n }\n var ref = env.invoke(block, value)\n block(objectRef, '.', key, '=', ref, ';')\n })\n }\n\n options.dynamic[name] = new dynamic.DynamicVariable(DYN_THUNK, {\n thisDep: thisDep,\n contextDep: contextDep,\n propDep: propDep,\n ref: objectRef,\n append: appendBlock\n })\n delete options.static[name]\n }\n\n // ===========================================================================\n // ===========================================================================\n // MAIN DRAW COMMAND\n // ===========================================================================\n // ===========================================================================\n function compileCommand (options, attributes, uniforms, context, stats) {\n var env = createREGLEnvironment()\n\n // link stats, so that we can easily access it in the program.\n env.stats = env.link(stats)\n\n // splat options and attributes to allow for dynamic nested properties\n Object.keys(attributes.static).forEach(function (key) {\n splatObject(env, attributes, key)\n })\n NESTED_OPTIONS.forEach(function (name) {\n splatObject(env, options, name)\n })\n\n var args = parseArguments(options, attributes, uniforms, context)\n\n emitDrawProc(env, args)\n emitScopeProc(env, args)\n emitBatchProc(env, args)\n\n return env.compile()\n }\n\n // ===========================================================================\n // ===========================================================================\n // POLL / REFRESH\n // ===========================================================================\n // ===========================================================================\n return {\n next: nextState,\n current: currentState,\n procs: (function () {\n var env = createREGLEnvironment()\n var poll = env.proc('poll')\n var refresh = env.proc('refresh')\n var common = env.block()\n poll(common)\n refresh(common)\n\n var shared = env.shared\n var GL = shared.gl\n var NEXT_STATE = shared.next\n var CURRENT_STATE = shared.current\n\n common(CURRENT_STATE, '.dirty=false;')\n\n emitPollFramebuffer(env, poll)\n emitPollFramebuffer(env, refresh, null, true)\n\n // Refresh updates all attribute state changes\n var extInstancing = gl.getExtension('angle_instanced_arrays')\n var INSTANCING\n if (extInstancing) {\n INSTANCING = env.link(extInstancing)\n }\n for (var i = 0; i < limits.maxAttributes; ++i) {\n var BINDING = refresh.def(shared.attributes, '[', i, ']')\n var ifte = env.cond(BINDING, '.buffer')\n ifte.then(\n GL, '.enableVertexAttribArray(', i, ');',\n GL, '.bindBuffer(',\n GL_ARRAY_BUFFER, ',',\n BINDING, '.buffer.buffer);',\n GL, '.vertexAttribPointer(',\n i, ',',\n BINDING, '.size,',\n BINDING, '.type,',\n BINDING, '.normalized,',\n BINDING, '.stride,',\n BINDING, '.offset);'\n ).else(\n GL, '.disableVertexAttribArray(', i, ');',\n GL, '.vertexAttrib4f(',\n i, ',',\n BINDING, '.x,',\n BINDING, '.y,',\n BINDING, '.z,',\n BINDING, '.w);',\n BINDING, '.buffer=null;')\n refresh(ifte)\n if (extInstancing) {\n refresh(\n INSTANCING, '.vertexAttribDivisorANGLE(',\n i, ',',\n BINDING, '.divisor);')\n }\n }\n\n Object.keys(GL_FLAGS).forEach(function (flag) {\n var cap = GL_FLAGS[flag]\n var NEXT = common.def(NEXT_STATE, '.', flag)\n var block = env.block()\n block('if(', NEXT, '){',\n GL, '.enable(', cap, ')}else{',\n GL, '.disable(', cap, ')}',\n CURRENT_STATE, '.', flag, '=', NEXT, ';')\n refresh(block)\n poll(\n 'if(', NEXT, '!==', CURRENT_STATE, '.', flag, '){',\n block,\n '}')\n })\n\n Object.keys(GL_VARIABLES).forEach(function (name) {\n var func = GL_VARIABLES[name]\n var init = currentState[name]\n var NEXT, CURRENT\n var block = env.block()\n block(GL, '.', func, '(')\n if (isArrayLike(init)) {\n var n = init.length\n NEXT = env.global.def(NEXT_STATE, '.', name)\n CURRENT = env.global.def(CURRENT_STATE, '.', name)\n block(\n loop(n, function (i) {\n return NEXT + '[' + i + ']'\n }), ');',\n loop(n, function (i) {\n return CURRENT + '[' + i + ']=' + NEXT + '[' + i + '];'\n }).join(''))\n poll(\n 'if(', loop(n, function (i) {\n return NEXT + '[' + i + ']!==' + CURRENT + '[' + i + ']'\n }).join('||'), '){',\n block,\n '}')\n } else {\n NEXT = common.def(NEXT_STATE, '.', name)\n CURRENT = common.def(CURRENT_STATE, '.', name)\n block(\n NEXT, ');',\n CURRENT_STATE, '.', name, '=', NEXT, ';')\n poll(\n 'if(', NEXT, '!==', CURRENT, '){',\n block,\n '}')\n }\n refresh(block)\n })\n\n return env.compile()\n })(),\n compile: compileCommand\n }\n}\n",
"var VARIABLE_COUNTER = 0\n\nvar DYN_FUNC = 0\n\nfunction DynamicVariable (type, data) {\n this.id = (VARIABLE_COUNTER++)\n this.type = type\n this.data = data\n}\n\nfunction escapeStr (str) {\n return str.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')\n}\n\nfunction splitParts (str) {\n if (str.length === 0) {\n return []\n }\n\n var firstChar = str.charAt(0)\n var lastChar = str.charAt(str.length - 1)\n\n if (str.length > 1 &&\n firstChar === lastChar &&\n (firstChar === '\"' || firstChar === \"'\")) {\n return ['\"' + escapeStr(str.substr(1, str.length - 2)) + '\"']\n }\n\n var parts = /\\[(false|true|null|\\d+|'[^']*'|\"[^\"]*\")\\]/.exec(str)\n if (parts) {\n return (\n splitParts(str.substr(0, parts.index))\n .concat(splitParts(parts[1]))\n .concat(splitParts(str.substr(parts.index + parts[0].length)))\n )\n }\n\n var subparts = str.split('.')\n if (subparts.length === 1) {\n return ['\"' + escapeStr(str) + '\"']\n }\n\n var result = []\n for (var i = 0; i < subparts.length; ++i) {\n result = result.concat(splitParts(subparts[i]))\n }\n return result\n}\n\nfunction toAccessorString (str) {\n return '[' + splitParts(str).join('][') + ']'\n}\n\nfunction defineDynamic (type, data) {\n return new DynamicVariable(type, toAccessorString(data + ''))\n}\n\nfunction isDynamic (x) {\n return (typeof x === 'function' && !x._reglType) ||\n x instanceof DynamicVariable\n}\n\nfunction unbox (x, path) {\n if (typeof x === 'function') {\n return new DynamicVariable(DYN_FUNC, x)\n }\n return x\n}\n\nmodule.exports = {\n DynamicVariable: DynamicVariable,\n define: defineDynamic,\n isDynamic: isDynamic,\n unbox: unbox,\n accessor: toAccessorString\n}\n",
"var check = require('./util/check')\nvar isTypedArray = require('./util/is-typed-array')\nvar isNDArrayLike = require('./util/is-ndarray')\nvar values = require('./util/values')\n\nvar primTypes = require('./constants/primitives.json')\nvar usageTypes = require('./constants/usage.json')\n\nvar GL_POINTS = 0\nvar GL_LINES = 1\nvar GL_TRIANGLES = 4\n\nvar GL_BYTE = 5120\nvar GL_UNSIGNED_BYTE = 5121\nvar GL_SHORT = 5122\nvar GL_UNSIGNED_SHORT = 5123\nvar GL_INT = 5124\nvar GL_UNSIGNED_INT = 5125\n\nvar GL_ELEMENT_ARRAY_BUFFER = 34963\n\nvar GL_STREAM_DRAW = 0x88E0\nvar GL_STATIC_DRAW = 0x88E4\n\nmodule.exports = function wrapElementsState (gl, extensions, bufferState, stats) {\n var elementSet = {}\n var elementCount = 0\n\n var elementTypes = {\n 'uint8': GL_UNSIGNED_BYTE,\n 'uint16': GL_UNSIGNED_SHORT\n }\n\n if (extensions.oes_element_index_uint) {\n elementTypes.uint32 = GL_UNSIGNED_INT\n }\n\n function REGLElementBuffer (buffer) {\n this.id = elementCount++\n elementSet[this.id] = this\n this.buffer = buffer\n this.primType = GL_TRIANGLES\n this.vertCount = 0\n this.type = 0\n }\n\n REGLElementBuffer.prototype.bind = function () {\n this.buffer.bind()\n }\n\n var bufferPool = []\n\n function createElementStream (data) {\n var result = bufferPool.pop()\n if (!result) {\n result = new REGLElementBuffer(bufferState.create(\n null,\n GL_ELEMENT_ARRAY_BUFFER,\n true)._buffer)\n }\n initElements(result, data, GL_STREAM_DRAW, -1, -1, 0, 0)\n return result\n }\n\n function destroyElementStream (elements) {\n bufferPool.push(elements)\n }\n\n function initElements (\n elements,\n data,\n usage,\n prim,\n count,\n byteLength,\n type) {\n var predictedType = type\n if (!type && (\n !isTypedArray(data) ||\n (isNDArrayLike(data) && !isTypedArray(data.data)))) {\n predictedType = extensions.oes_element_index_uint\n ? GL_UNSIGNED_INT\n : GL_UNSIGNED_SHORT\n }\n elements.buffer.bind()\n bufferState._initBuffer(\n elements.buffer,\n data,\n usage,\n predictedType,\n 3)\n\n var dtype = type\n if (!type) {\n switch (elements.buffer.dtype) {\n case GL_UNSIGNED_BYTE:\n case GL_BYTE:\n dtype = GL_UNSIGNED_BYTE\n break\n\n case GL_UNSIGNED_SHORT:\n case GL_SHORT:\n dtype = GL_UNSIGNED_SHORT\n break\n\n case GL_UNSIGNED_INT:\n case GL_INT:\n dtype = GL_UNSIGNED_INT\n break\n\n default:\n check.raise('unsupported type for element array')\n }\n elements.buffer.dtype = dtype\n }\n elements.type = dtype\n\n // Check oes_element_index_uint extension\n check(\n dtype !== GL_UNSIGNED_INT ||\n !!extensions.oes_element_index_uint,\n '32 bit element buffers not supported, enable oes_element_index_uint first')\n\n // try to guess default primitive type and arguments\n var vertCount = count\n if (vertCount < 0) {\n vertCount = elements.buffer.byteLength\n if (dtype === GL_UNSIGNED_SHORT) {\n vertCount >>= 1\n } else if (dtype === GL_UNSIGNED_INT) {\n vertCount >>= 2\n }\n }\n elements.vertCount = vertCount\n\n // try to guess primitive type from cell dimension\n var primType = prim\n if (prim < 0) {\n primType = GL_TRIANGLES\n var dimension = elements.buffer.dimension\n if (dimension === 1) primType = GL_POINTS\n if (dimension === 2) primType = GL_LINES\n if (dimension === 3) primType = GL_TRIANGLES\n }\n elements.primType = primType\n }\n\n function destroyElements (elements) {\n stats.elementsCount--\n\n check(elements.buffer !== null, 'must not double destroy elements')\n delete elementSet[elements.id]\n elements.buffer.destroy()\n elements.buffer = null\n }\n\n function createElements (options) {\n var buffer = bufferState.create(null, GL_ELEMENT_ARRAY_BUFFER, true)\n var elements = new REGLElementBuffer(buffer._buffer)\n stats.elementsCount++\n\n function reglElements (options) {\n if (!options) {\n buffer()\n elements.primType = GL_TRIANGLES\n elements.vertCount = 0\n elements.type = GL_UNSIGNED_BYTE\n } else if (typeof options === 'number') {\n buffer(options)\n elements.primType = GL_TRIANGLES\n elements.vertCount = options | 0\n elements.type = GL_UNSIGNED_BYTE\n } else {\n var data = null\n var usage = GL_STATIC_DRAW\n var primType = -1\n var vertCount = -1\n var byteLength = 0\n var dtype = 0\n if (Array.isArray(options) ||\n isTypedArray(options) ||\n isNDArrayLike(options)) {\n data = options\n } else {\n check.type(options, 'object', 'invalid arguments for elements')\n if ('data' in options) {\n data = options.data\n check(\n Array.isArray(data) ||\n isTypedArray(data) ||\n isNDArrayLike(data),\n 'invalid data for element buffer')\n }\n if ('usage' in options) {\n check.parameter(\n options.usage,\n usageTypes,\n 'invalid element buffer usage')\n usage = usageTypes[options.usage]\n }\n if ('primitive' in options) {\n check.parameter(\n options.primitive,\n primTypes,\n 'invalid element buffer primitive')\n primType = primTypes[options.primitive]\n }\n if ('count' in options) {\n check(\n typeof options.count === 'number' && options.count >= 0,\n 'invalid vertex count for elements')\n vertCount = options.count | 0\n }\n if ('length' in options) {\n byteLength = options.length | 0\n }\n if ('type' in options) {\n check.parameter(\n options.type,\n elementTypes,\n 'invalid buffer type')\n dtype = elementTypes[options.type]\n }\n }\n if (data) {\n initElements(\n elements,\n data,\n usage,\n primType,\n vertCount,\n byteLength,\n dtype)\n } else {\n var _buffer = elements.buffer\n _buffer.bind()\n gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, byteLength, usage)\n _buffer.dtype = dtype || GL_UNSIGNED_BYTE\n _buffer.usage = usage\n _buffer.dimension = 3\n _buffer.byteLength = byteLength\n elements.primType = primType < 0 ? GL_TRIANGLES : primType\n elements.vertCount = vertCount < 0 ? 0 : vertCount\n elements.type = _buffer.dtype\n }\n }\n\n return reglElements\n }\n\n reglElements(options)\n\n reglElements._reglType = 'elements'\n reglElements._elements = elements\n reglElements.subdata = function (data, offset) {\n buffer.subdata(data, offset)\n return reglElements\n }\n reglElements.destroy = function () {\n destroyElements(elements)\n }\n\n return reglElements\n }\n\n return {\n create: createElements,\n createStream: createElementStream,\n destroyStream: destroyElementStream,\n getElements: function (elements) {\n if (typeof elements === 'function' &&\n elements._elements instanceof REGLElementBuffer) {\n return elements._elements\n }\n return null\n },\n clear: function () {\n values(elementSet).forEach(destroyElements)\n }\n }\n}\n",
"var check = require('./util/check')\n\nmodule.exports = function createExtensionCache (gl, config) {\n var extensions = {}\n\n function tryLoadExtension (name_) {\n check.type(name_, 'string', 'extension name must be string')\n var name = name_.toLowerCase()\n var ext\n try {\n ext = extensions[name] = gl.getExtension(name)\n } catch (e) {}\n return !!ext\n }\n\n for (var i = 0; i < config.extensions.length; ++i) {\n var name = config.extensions[i]\n if (!tryLoadExtension(name)) {\n config.onDestroy()\n config.onDone('\"' + name + '\" extension is not supported by the current WebGL context, try upgrading your system or a different browser')\n return null\n }\n }\n\n config.optionalExtensions.forEach(tryLoadExtension)\n\n return {\n extensions: extensions\n }\n}\n",
"var check = require('./util/check')\nvar values = require('./util/values')\nvar extend = require('./util/extend')\n\n// We store these constants so that the minifier can inline them\nvar GL_FRAMEBUFFER = 0x8D40\nvar GL_RENDERBUFFER = 0x8D41\n\nvar GL_TEXTURE_2D = 0x0DE1\nvar GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515\n\nvar GL_COLOR_ATTACHMENT0 = 0x8CE0\nvar GL_DEPTH_ATTACHMENT = 0x8D00\nvar GL_STENCIL_ATTACHMENT = 0x8D20\nvar GL_DEPTH_STENCIL_ATTACHMENT = 0x821A\n\nvar GL_FRAMEBUFFER_COMPLETE = 0x8CD5\nvar GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6\nvar GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7\nvar GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9\nvar GL_FRAMEBUFFER_UNSUPPORTED = 0x8CDD\n\nvar GL_HALF_FLOAT_OES = 0x8D61\nvar GL_UNSIGNED_BYTE = 0x1401\nvar GL_FLOAT = 0x1406\n\nvar GL_RGBA = 0x1908\n\nvar GL_DEPTH_COMPONENT = 0x1902\n\nvar colorTextureFormatEnums = [\n GL_RGBA\n]\n\n// for every texture format, store\n// the number of channels\nvar textureFormatChannels = []\ntextureFormatChannels[GL_RGBA] = 4\n\n// for every texture type, store\n// the size in bytes.\nvar textureTypeSizes = []\ntextureTypeSizes[GL_UNSIGNED_BYTE] = 1\ntextureTypeSizes[GL_FLOAT] = 4\ntextureTypeSizes[GL_HALF_FLOAT_OES] = 2\n\nvar GL_RGBA4 = 0x8056\nvar GL_RGB5_A1 = 0x8057\nvar GL_RGB565 = 0x8D62\nvar GL_DEPTH_COMPONENT16 = 0x81A5\nvar GL_STENCIL_INDEX8 = 0x8D48\nvar GL_DEPTH_STENCIL = 0x84F9\n\nvar GL_SRGB8_ALPHA8_EXT = 0x8C43\n\nvar GL_RGBA32F_EXT = 0x8814\n\nvar GL_RGBA16F_EXT = 0x881A\nvar GL_RGB16F_EXT = 0x881B\n\nvar colorRenderbufferFormatEnums = [\n GL_RGBA4,\n GL_RGB5_A1,\n GL_RGB565,\n GL_SRGB8_ALPHA8_EXT,\n GL_RGBA16F_EXT,\n GL_RGB16F_EXT,\n GL_RGBA32F_EXT\n]\n\nvar statusCode = {}\nstatusCode[GL_FRAMEBUFFER_COMPLETE] = 'complete'\nstatusCode[GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT] = 'incomplete attachment'\nstatusCode[GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS] = 'incomplete dimensions'\nstatusCode[GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT] = 'incomplete, missing attachment'\nstatusCode[GL_FRAMEBUFFER_UNSUPPORTED] = 'unsupported'\n\nmodule.exports = function wrapFBOState (\n gl,\n extensions,\n limits,\n textureState,\n renderbufferState,\n stats) {\n var framebufferState = {\n cur: null,\n next: null,\n dirty: false\n }\n\n var colorTextureFormats = ['rgba']\n var colorRenderbufferFormats = ['rgba4', 'rgb565', 'rgb5 a1']\n\n if (extensions.ext_srgb) {\n colorRenderbufferFormats.push('srgba')\n }\n\n if (extensions.ext_color_buffer_half_float) {\n colorRenderbufferFormats.push('rgba16f', 'rgb16f')\n }\n\n if (extensions.webgl_color_buffer_float) {\n colorRenderbufferFormats.push('rgba32f')\n }\n\n var colorTypes = ['uint8']\n if (extensions.oes_texture_half_float) {\n colorTypes.push('half float', 'float16')\n }\n if (extensions.oes_texture_float) {\n colorTypes.push('float', 'float32')\n }\n\n function FramebufferAttachment (target, texture, renderbuffer) {\n this.target = target\n this.texture = texture\n this.renderbuffer = renderbuffer\n\n var w = 0\n var h = 0\n if (texture) {\n w = texture.width\n h = texture.height\n } else if (renderbuffer) {\n w = renderbuffer.width\n h = renderbuffer.height\n }\n this.width = w\n this.height = h\n }\n\n function decRef (attachment) {\n if (attachment) {\n if (attachment.texture) {\n attachment.texture._texture.decRef()\n }\n if (attachment.renderbuffer) {\n attachment.renderbuffer._renderbuffer.decRef()\n }\n }\n }\n\n function incRefAndCheckShape (attachment, width, height) {\n if (!attachment) {\n return\n }\n if (attachment.texture) {\n var texture = attachment.texture._texture\n var tw = Math.max(1, texture.width)\n var th = Math.max(1, texture.height)\n check(tw === width && th === height,\n 'inconsistent width/height for supplied texture')\n texture.refCount += 1\n } else {\n var renderbuffer = attachment.renderbuffer._renderbuffer\n check(\n renderbuffer.width === width && renderbuffer.height === height,\n 'inconsistent width/height for renderbuffer')\n renderbuffer.refCount += 1\n }\n }\n\n function attach (location, attachment) {\n if (attachment) {\n if (attachment.texture) {\n gl.framebufferTexture2D(\n GL_FRAMEBUFFER,\n location,\n attachment.target,\n attachment.texture._texture.texture,\n 0)\n } else {\n gl.framebufferRenderbuffer(\n GL_FRAMEBUFFER,\n location,\n GL_RENDERBUFFER,\n attachment.renderbuffer._renderbuffer.renderbuffer)\n }\n } else {\n gl.framebufferTexture2D(\n GL_FRAMEBUFFER,\n location,\n GL_TEXTURE_2D,\n null,\n 0)\n }\n }\n\n function parseAttachment (attachment) {\n var target = GL_TEXTURE_2D\n var texture = null\n var renderbuffer = null\n\n var data = attachment\n if (typeof attachment === 'object') {\n data = attachment.data\n if ('target' in attachment) {\n target = attachment.target | 0\n }\n }\n\n check.type(data, 'function', 'invalid attachment data')\n\n var type = data._reglType\n if (type === 'texture2d') {\n texture = data\n check(target === GL_TEXTURE_2D)\n } else if (type === 'textureCube') {\n texture = data\n check(\n target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&\n target < GL_TEXTURE_CUBE_MAP_POSITIVE_X + 6,\n 'invalid cube map target')\n } else if (type === 'renderbuffer') {\n renderbuffer = data\n target = GL_RENDERBUFFER\n } else {\n check.raise('invalid regl object for attachment')\n }\n\n return new FramebufferAttachment(target, texture, renderbuffer)\n }\n\n function allocAttachment (\n width,\n height,\n isTexture,\n format,\n type) {\n if (isTexture) {\n var texture = textureState.create2D({\n width: width,\n height: height,\n format: format,\n type: type\n })\n texture._texture.refCount = 0\n return new FramebufferAttachment(GL_TEXTURE_2D, texture, null)\n } else {\n var rb = renderbufferState.create({\n width: width,\n height: height,\n format: format\n })\n rb._renderbuffer.refCount = 0\n return new FramebufferAttachment(GL_RENDERBUFFER, null, rb)\n }\n }\n\n function unwrapAttachment (attachment) {\n return attachment && (attachment.texture || attachment.renderbuffer)\n }\n\n function resizeAttachment (attachment, w, h) {\n if (attachment) {\n if (attachment.texture) {\n attachment.texture.resize(w, h)\n } else if (attachment.renderbuffer) {\n attachment.renderbuffer.resize(w, h)\n }\n }\n }\n\n var framebufferCount = 0\n var framebufferSet = {}\n\n function REGLFramebuffer () {\n this.id = framebufferCount++\n framebufferSet[this.id] = this\n\n this.framebuffer = gl.createFramebuffer()\n this.width = 0\n this.height = 0\n\n this.colorAttachments = []\n this.depthAttachment = null\n this.stencilAttachment = null\n this.depthStencilAttachment = null\n }\n\n function decFBORefs (framebuffer) {\n framebuffer.colorAttachments.forEach(decRef)\n decRef(framebuffer.depthAttachment)\n decRef(framebuffer.stencilAttachment)\n decRef(framebuffer.depthStencilAttachment)\n }\n\n function destroy (framebuffer) {\n var handle = framebuffer.framebuffer\n check(handle, 'must not double destroy framebuffer')\n gl.deleteFramebuffer(handle)\n framebuffer.framebuffer = null\n stats.framebufferCount--\n delete framebufferSet[framebuffer.id]\n }\n\n function updateFramebuffer (framebuffer) {\n var i\n\n gl.bindFramebuffer(GL_FRAMEBUFFER, framebuffer.framebuffer)\n var colorAttachments = framebuffer.colorAttachments\n for (i = 0; i < colorAttachments.length; ++i) {\n attach(GL_COLOR_ATTACHMENT0 + i, colorAttachments[i])\n }\n for (i = colorAttachments.length; i < limits.maxColorAttachments; ++i) {\n attach(GL_COLOR_ATTACHMENT0 + i, null)\n }\n attach(GL_DEPTH_ATTACHMENT, framebuffer.depthAttachment)\n attach(GL_STENCIL_ATTACHMENT, framebuffer.stencilAttachment)\n attach(GL_DEPTH_STENCIL_ATTACHMENT, framebuffer.depthStencilAttachment)\n\n // Check status code\n var status = gl.checkFramebufferStatus(GL_FRAMEBUFFER)\n if (status !== GL_FRAMEBUFFER_COMPLETE) {\n check.raise('framebuffer configuration not supported, status = ' +\n statusCode[status])\n }\n\n gl.bindFramebuffer(GL_FRAMEBUFFER, framebufferState.next)\n framebufferState.cur = framebufferState.next\n\n // FIXME: Clear error code here. This is a work around for a bug in\n // headless-gl\n gl.getError()\n }\n\n function createFBO (a0, a1) {\n var framebuffer = new REGLFramebuffer()\n stats.framebufferCount++\n\n function reglFramebuffer (a, b) {\n var i\n\n check(framebufferState.next !== framebuffer,\n 'can not update framebuffer which is currently in use')\n\n var extDrawBuffers = extensions.webgl_draw_buffers\n\n var width = 0\n var height = 0\n\n var needsDepth = true\n var needsStencil = true\n\n var colorBuffer = null\n var colorTexture = true\n var colorFormat = 'rgba'\n var colorType = 'uint8'\n var colorCount = 1\n\n var depthBuffer = null\n var stencilBuffer = null\n var depthStencilBuffer = null\n var depthStencilTexture = false\n\n if (typeof a === 'number') {\n width = a | 0\n height = (b | 0) || width\n } else if (!a) {\n width = height = 1\n } else {\n check.type(a, 'object', 'invalid arguments for framebuffer')\n var options = a\n\n if ('shape' in options) {\n var shape = options.shape\n check(Array.isArray(shape) && shape.length >= 2,\n 'invalid shape for framebuffer')\n width = shape[0]\n height = shape[1]\n } else {\n if ('radius' in options) {\n width = height = options.radius\n }\n if ('width' in options) {\n width = options.width\n }\n if ('height' in options) {\n height = options.height\n }\n }\n\n if ('color' in options ||\n 'colors' in options) {\n colorBuffer =\n options.color ||\n options.colors\n if (Array.isArray(colorBuffer)) {\n check(\n colorBuffer.length === 1 || extDrawBuffers,\n 'multiple render targets not supported')\n }\n }\n\n if (!colorBuffer) {\n if ('colorCount' in options) {\n colorCount = options.colorCount | 0\n check(colorCount > 0, 'invalid color buffer count')\n }\n\n if ('colorTexture' in options) {\n colorTexture = !!options.colorTexture\n colorFormat = 'rgba4'\n }\n\n if ('colorType' in options) {\n colorType = options.colorType\n if (!colorTexture) {\n if (colorType === 'half float' || colorType === 'float16') {\n check(extensions.ext_color_buffer_half_float,\n 'you must enable EXT_color_buffer_half_float to use 16-bit render buffers')\n colorFormat = 'rgba16f'\n } else if (colorType === 'float' || colorType === 'float32') {\n check(extensions.webgl_color_buffer_float,\n 'you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers')\n colorFormat = 'rgba32f'\n }\n } else {\n check(extensions.oes_texture_float ||\n !(colorType === 'float' || colorType === 'float32'),\n 'you must enable OES_texture_float in order to use floating point framebuffer objects')\n check(extensions.oes_texture_half_float ||\n !(colorType === 'half float' || colorType === 'float16'),\n 'you must enable OES_texture_half_float in order to use 16-bit floating point framebuffer objects')\n }\n check.oneOf(colorType, colorTypes, 'invalid color type')\n }\n\n if ('colorFormat' in options) {\n colorFormat = options.colorFormat\n if (colorTextureFormats.indexOf(colorFormat) >= 0) {\n colorTexture = true\n } else if (colorRenderbufferFormats.indexOf(colorFormat) >= 0) {\n colorTexture = false\n } else {\n if (colorTexture) {\n check.oneOf(\n options.colorFormat, colorTextureFormats,\n 'invalid color format for texture')\n } else {\n check.oneOf(\n options.colorFormat, colorRenderbufferFormats,\n 'invalid color format for renderbuffer')\n }\n }\n }\n }\n\n if ('depthTexture' in options || 'depthStencilTexture' in options) {\n depthStencilTexture = !!(options.depthTexture ||\n options.depthStencilTexture)\n check(!depthStencilTexture || extensions.webgl_depth_texture,\n 'webgl_depth_texture extension not supported')\n }\n\n if ('depth' in options) {\n if (typeof options.depth === 'boolean') {\n needsDepth = options.depth\n } else {\n depthBuffer = options.depth\n needsStencil = false\n }\n }\n\n if ('stencil' in options) {\n if (typeof options.stencil === 'boolean') {\n needsStencil = options.stencil\n } else {\n stencilBuffer = options.stencil\n needsDepth = false\n }\n }\n\n if ('depthStencil' in options) {\n if (typeof options.depthStencil === 'boolean') {\n needsDepth = needsStencil = options.depthStencil\n } else {\n depthStencilBuffer = options.depthStencil\n needsDepth = false\n needsStencil = false\n }\n }\n }\n\n // parse attachments\n var colorAttachments = null\n var depthAttachment = null\n var stencilAttachment = null\n var depthStencilAttachment = null\n\n // Set up color attachments\n if (Array.isArray(colorBuffer)) {\n colorAttachments = colorBuffer.map(parseAttachment)\n } else if (colorBuffer) {\n colorAttachments = [parseAttachment(colorBuffer)]\n } else {\n colorAttachments = new Array(colorCount)\n for (i = 0; i < colorCount; ++i) {\n colorAttachments[i] = allocAttachment(\n width,\n height,\n colorTexture,\n colorFormat,\n colorType)\n }\n }\n\n check(extensions.webgl_draw_buffers || colorAttachments.length <= 1,\n 'you must enable the WEBGL_draw_buffers extension in order to use multiple color buffers.')\n check(colorAttachments.length <= limits.maxColorAttachments,\n 'too many color attachments, not supported')\n\n width = width || colorAttachments[0].width\n height = height || colorAttachments[0].height\n\n if (depthBuffer) {\n depthAttachment = parseAttachment(depthBuffer)\n } else if (needsDepth && !needsStencil) {\n depthAttachment = allocAttachment(\n width,\n height,\n depthStencilTexture,\n 'depth',\n 'uint32')\n }\n\n if (stencilBuffer) {\n stencilAttachment = parseAttachment(stencilBuffer)\n } else if (needsStencil && !needsDepth) {\n stencilAttachment = allocAttachment(\n width,\n height,\n false,\n 'stencil',\n 'uint8')\n }\n\n if (depthStencilBuffer) {\n depthStencilAttachment = parseAttachment(depthStencilBuffer)\n } else if (!depthBuffer && !stencilBuffer && needsStencil && needsDepth) {\n depthStencilAttachment = allocAttachment(\n width,\n height,\n depthStencilTexture,\n 'depth stencil',\n 'depth stencil')\n }\n\n check(\n (!!depthBuffer) + (!!stencilBuffer) + (!!depthStencilBuffer) <= 1,\n 'invalid framebuffer configuration, can specify exactly one depth/stencil attachment')\n\n var commonColorAttachmentSize = null\n\n for (i = 0; i < colorAttachments.length; ++i) {\n incRefAndCheckShape(colorAttachments[i], width, height)\n check(!colorAttachments[i] ||\n (colorAttachments[i].texture &&\n colorTextureFormatEnums.indexOf(colorAttachments[i].texture._texture.format) >= 0) ||\n (colorAttachments[i].renderbuffer &&\n colorRenderbufferFormatEnums.indexOf(colorAttachments[i].renderbuffer._renderbuffer.format) >= 0),\n 'framebuffer color attachment ' + i + ' is invalid')\n\n if (colorAttachments[i] && colorAttachments[i].texture) {\n var colorAttachmentSize =\n textureFormatChannels[colorAttachments[i].texture._texture.format] *\n textureTypeSizes[colorAttachments[i].texture._texture.type]\n\n if (commonColorAttachmentSize === null) {\n commonColorAttachmentSize = colorAttachmentSize\n } else {\n // We need to make sure that all color attachments have the same number of bitplanes\n // (that is, the same numer of bits per pixel)\n // This is required by the GLES2.0 standard. See the beginning of Chapter 4 in that document.\n check(commonColorAttachmentSize === colorAttachmentSize,\n 'all color attachments much have the same number of bits per pixel.')\n }\n }\n }\n incRefAndCheckShape(depthAttachment, width, height)\n check(!depthAttachment ||\n (depthAttachment.texture &&\n depthAttachment.texture._texture.format === GL_DEPTH_COMPONENT) ||\n (depthAttachment.renderbuffer &&\n depthAttachment.renderbuffer._renderbuffer.format === GL_DEPTH_COMPONENT16),\n 'invalid depth attachment for framebuffer object')\n incRefAndCheckShape(stencilAttachment, width, height)\n check(!stencilAttachment ||\n (stencilAttachment.renderbuffer &&\n stencilAttachment.renderbuffer._renderbuffer.format === GL_STENCIL_INDEX8),\n 'invalid stencil attachment for framebuffer object')\n incRefAndCheckShape(depthStencilAttachment, width, height)\n check(!depthStencilAttachment ||\n (depthStencilAttachment.texture &&\n depthStencilAttachment.texture._texture.format === GL_DEPTH_STENCIL) ||\n (depthStencilAttachment.renderbuffer &&\n depthStencilAttachment.renderbuffer._renderbuffer.format === GL_DEPTH_STENCIL),\n 'invalid depth-stencil attachment for framebuffer object')\n\n // decrement references\n decFBORefs(framebuffer)\n\n framebuffer.width = width\n framebuffer.height = height\n\n framebuffer.colorAttachments = colorAttachments\n framebuffer.depthAttachment = depthAttachment\n framebuffer.stencilAttachment = stencilAttachment\n framebuffer.depthStencilAttachment = depthStencilAttachment\n\n reglFramebuffer.color = colorAttachments.map(unwrapAttachment)\n reglFramebuffer.depth = unwrapAttachment(depthAttachment)\n reglFramebuffer.stencil = unwrapAttachment(stencilAttachment)\n reglFramebuffer.depthStencil = unwrapAttachment(depthStencilAttachment)\n\n reglFramebuffer.width = framebuffer.width\n reglFramebuffer.height = framebuffer.height\n\n updateFramebuffer(framebuffer)\n\n return reglFramebuffer\n }\n\n function resize (w_, h_) {\n check(framebufferState.next !== framebuffer,\n 'can not resize a framebuffer which is currently in use')\n\n var w = w_ | 0\n var h = (h_ | 0) || w\n if (w === framebuffer.width && h === framebuffer.height) {\n return reglFramebuffer\n }\n\n // resize all buffers\n var colorAttachments = framebuffer.colorAttachments\n for (var i = 0; i < colorAttachments.length; ++i) {\n resizeAttachment(colorAttachments[i], w, h)\n }\n resizeAttachment(framebuffer.depthAttachment, w, h)\n resizeAttachment(framebuffer.stencilAttachment, w, h)\n resizeAttachment(framebuffer.depthStencilAttachment, w, h)\n\n framebuffer.width = reglFramebuffer.width = w\n framebuffer.height = reglFramebuffer.height = h\n\n updateFramebuffer(framebuffer)\n\n return reglFramebuffer\n }\n\n reglFramebuffer(a0, a1)\n\n return extend(reglFramebuffer, {\n resize: resize,\n _reglType: 'framebuffer',\n _framebuffer: framebuffer,\n destroy: function () {\n destroy(framebuffer)\n decFBORefs(framebuffer)\n }\n })\n }\n\n function createCubeFBO (options) {\n var faces = Array(6)\n\n function reglFramebufferCube (a) {\n var i\n\n check(faces.indexOf(framebufferState.next) < 0,\n 'can not update framebuffer which is currently in use')\n\n var extDrawBuffers = extensions.webgl_draw_buffers\n\n var params = {\n color: null\n }\n\n var radius = 0\n\n var colorBuffer = null\n var colorFormat = 'rgba'\n var colorType = 'uint8'\n var colorCount = 1\n\n if (typeof a === 'number') {\n radius = a | 0\n } else if (!a) {\n radius = 1\n } else {\n check.type(a, 'object', 'invalid arguments for framebuffer')\n var options = a\n\n if ('shape' in options) {\n var shape = options.shape\n check(\n Array.isArray(shape) && shape.length >= 2,\n 'invalid shape for framebuffer')\n check(\n shape[0] === shape[1],\n 'cube framebuffer must be square')\n radius = shape[0]\n } else {\n if ('radius' in options) {\n radius = options.radius | 0\n }\n if ('width' in options) {\n radius = options.width | 0\n if ('height' in options) {\n check(options.height === radius, 'must be square')\n }\n } else if ('height' in options) {\n radius = options.height | 0\n }\n }\n\n if ('color' in options ||\n 'colors' in options) {\n colorBuffer =\n options.color ||\n options.colors\n if (Array.isArray(colorBuffer)) {\n check(\n colorBuffer.length === 1 || extDrawBuffers,\n 'multiple render targets not supported')\n }\n }\n\n if (!colorBuffer) {\n if ('colorCount' in options) {\n colorCount = options.colorCount | 0\n check(colorCount > 0, 'invalid color buffer count')\n }\n\n if ('colorType' in options) {\n check.oneOf(\n options.colorType, colorTypes,\n 'invalid color type')\n colorType = options.colorType\n }\n\n if ('colorFormat' in options) {\n colorFormat = options.colorFormat\n check.oneOf(\n options.colorFormat, colorTextureFormats,\n 'invalid color format for texture')\n }\n }\n\n if ('depth' in options) {\n params.depth = options.depth\n }\n\n if ('stencil' in options) {\n params.stencil = options.stencil\n }\n\n if ('depthStencil' in options) {\n params.depthStencil = options.depthStencil\n }\n }\n\n var colorCubes\n if (colorBuffer) {\n if (Array.isArray(colorBuffer)) {\n colorCubes = []\n for (i = 0; i < colorBuffer.length; ++i) {\n colorCubes[i] = colorBuffer[i]\n }\n } else {\n colorCubes = [ colorBuffer ]\n }\n } else {\n colorCubes = Array(colorCount)\n var cubeMapParams = {\n radius: radius,\n format: colorFormat,\n type: colorType\n }\n for (i = 0; i < colorCount; ++i) {\n colorCubes[i] = textureState.createCube(cubeMapParams)\n }\n }\n\n // Check color cubes\n params.color = Array(colorCubes.length)\n for (i = 0; i < colorCubes.length; ++i) {\n var cube = colorCubes[i]\n check(\n typeof cube === 'function' && cube._reglType === 'textureCube',\n 'invalid cube map')\n radius = radius || cube.width\n check(\n cube.width === radius && cube.height === radius,\n 'invalid cube map shape')\n params.color[i] = {\n target: GL_TEXTURE_CUBE_MAP_POSITIVE_X,\n data: colorCubes[i]\n }\n }\n\n for (i = 0; i < 6; ++i) {\n for (var j = 0; j < colorCubes.length; ++j) {\n params.color[j].target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i\n }\n // reuse depth-stencil attachments across all cube maps\n if (i > 0) {\n params.depth = faces[0].depth\n params.stencil = faces[0].stencil\n params.depthStencil = faces[0].depthStencil\n }\n if (faces[i]) {\n (faces[i])(params)\n } else {\n faces[i] = createFBO(params)\n }\n }\n\n return extend(reglFramebufferCube, {\n width: radius,\n height: radius,\n color: colorCubes\n })\n }\n\n function resize (radius_) {\n var i\n var radius = radius_ | 0\n check(radius > 0 && radius <= limits.maxCubeMapSize,\n 'invalid radius for cube fbo')\n\n if (radius === reglFramebufferCube.width) {\n return reglFramebufferCube\n }\n\n var colors = reglFramebufferCube.color\n for (i = 0; i < colors.length; ++i) {\n colors[i].resize(radius)\n }\n\n for (i = 0; i < 6; ++i) {\n faces[i].resize(radius)\n }\n\n reglFramebufferCube.width = reglFramebufferCube.height = radius\n\n return reglFramebufferCube\n }\n\n reglFramebufferCube(options)\n\n return extend(reglFramebufferCube, {\n faces: faces,\n resize: resize,\n _reglType: 'framebufferCube',\n destroy: function () {\n faces.forEach(function (f) {\n f.destroy()\n })\n }\n })\n }\n\n return extend(framebufferState, {\n getFramebuffer: function (object) {\n if (typeof object === 'function' && object._reglType === 'framebuffer') {\n var fbo = object._framebuffer\n if (fbo instanceof REGLFramebuffer) {\n return fbo\n }\n }\n return null\n },\n create: createFBO,\n createCube: createCubeFBO,\n clear: function () {\n values(framebufferSet).forEach(destroy)\n }\n })\n}\n",
"var GL_SUBPIXEL_BITS = 0x0D50\nvar GL_RED_BITS = 0x0D52\nvar GL_GREEN_BITS = 0x0D53\nvar GL_BLUE_BITS = 0x0D54\nvar GL_ALPHA_BITS = 0x0D55\nvar GL_DEPTH_BITS = 0x0D56\nvar GL_STENCIL_BITS = 0x0D57\n\nvar GL_ALIASED_POINT_SIZE_RANGE = 0x846D\nvar GL_ALIASED_LINE_WIDTH_RANGE = 0x846E\n\nvar GL_MAX_TEXTURE_SIZE = 0x0D33\nvar GL_MAX_VIEWPORT_DIMS = 0x0D3A\nvar GL_MAX_VERTEX_ATTRIBS = 0x8869\nvar GL_MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB\nvar GL_MAX_VARYING_VECTORS = 0x8DFC\nvar GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D\nvar GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C\nvar GL_MAX_TEXTURE_IMAGE_UNITS = 0x8872\nvar GL_MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD\nvar GL_MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C\nvar GL_MAX_RENDERBUFFER_SIZE = 0x84E8\n\nvar GL_VENDOR = 0x1F00\nvar GL_RENDERER = 0x1F01\nvar GL_VERSION = 0x1F02\nvar GL_SHADING_LANGUAGE_VERSION = 0x8B8C\n\nvar GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF\n\nvar GL_MAX_COLOR_ATTACHMENTS_WEBGL = 0x8CDF\nvar GL_MAX_DRAW_BUFFERS_WEBGL = 0x8824\n\nmodule.exports = function (gl, extensions) {\n var maxAnisotropic = 1\n if (extensions.ext_texture_filter_anisotropic) {\n maxAnisotropic = gl.getParameter(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)\n }\n\n var maxDrawbuffers = 1\n var maxColorAttachments = 1\n if (extensions.webgl_draw_buffers) {\n maxDrawbuffers = gl.getParameter(GL_MAX_DRAW_BUFFERS_WEBGL)\n maxColorAttachments = gl.getParameter(GL_MAX_COLOR_ATTACHMENTS_WEBGL)\n }\n\n return {\n // drawing buffer bit depth\n colorBits: [\n gl.getParameter(GL_RED_BITS),\n gl.getParameter(GL_GREEN_BITS),\n gl.getParameter(GL_BLUE_BITS),\n gl.getParameter(GL_ALPHA_BITS)\n ],\n depthBits: gl.getParameter(GL_DEPTH_BITS),\n stencilBits: gl.getParameter(GL_STENCIL_BITS),\n subpixelBits: gl.getParameter(GL_SUBPIXEL_BITS),\n\n // supported extensions\n extensions: Object.keys(extensions).filter(function (ext) {\n return !!extensions[ext]\n }),\n\n // max aniso samples\n maxAnisotropic: maxAnisotropic,\n\n // max draw buffers\n maxDrawbuffers: maxDrawbuffers,\n maxColorAttachments: maxColorAttachments,\n\n // point and line size ranges\n pointSizeDims: gl.getParameter(GL_ALIASED_POINT_SIZE_RANGE),\n lineWidthDims: gl.getParameter(GL_ALIASED_LINE_WIDTH_RANGE),\n maxViewportDims: gl.getParameter(GL_MAX_VIEWPORT_DIMS),\n maxCombinedTextureUnits: gl.getParameter(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS),\n maxCubeMapSize: gl.getParameter(GL_MAX_CUBE_MAP_TEXTURE_SIZE),\n maxRenderbufferSize: gl.getParameter(GL_MAX_RENDERBUFFER_SIZE),\n maxTextureUnits: gl.getParameter(GL_MAX_TEXTURE_IMAGE_UNITS),\n maxTextureSize: gl.getParameter(GL_MAX_TEXTURE_SIZE),\n maxAttributes: gl.getParameter(GL_MAX_VERTEX_ATTRIBS),\n maxVertexUniforms: gl.getParameter(GL_MAX_VERTEX_UNIFORM_VECTORS),\n maxVertexTextureUnits: gl.getParameter(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS),\n maxVaryingVectors: gl.getParameter(GL_MAX_VARYING_VECTORS),\n maxFragmentUniforms: gl.getParameter(GL_MAX_FRAGMENT_UNIFORM_VECTORS),\n\n // vendor info\n glsl: gl.getParameter(GL_SHADING_LANGUAGE_VERSION),\n renderer: gl.getParameter(GL_RENDERER),\n vendor: gl.getParameter(GL_VENDOR),\n version: gl.getParameter(GL_VERSION)\n }\n}\n",
"var check = require('./util/check')\nvar isTypedArray = require('./util/is-typed-array')\n\nvar GL_RGBA = 6408\nvar GL_UNSIGNED_BYTE = 5121\nvar GL_PACK_ALIGNMENT = 0x0D05\nvar GL_FLOAT = 0x1406 // 5126\n\nmodule.exports = function wrapReadPixels (\n gl,\n framebufferState,\n reglPoll,\n context,\n glAttributes,\n extensions) {\n function readPixels (input) {\n var type\n if (framebufferState.next === null) {\n check(\n glAttributes.preserveDrawingBuffer,\n 'you must create a webgl context with \"preserveDrawingBuffer\":true in order to read pixels from the drawing buffer')\n type = GL_UNSIGNED_BYTE\n } else {\n check(\n framebufferState.next.colorAttachments[0].texture !== null,\n 'You cannot read from a renderbuffer')\n type = framebufferState.next.colorAttachments[0].texture._texture.type\n\n if (extensions.oes_texture_float) {\n check(\n type === GL_UNSIGNED_BYTE || type === GL_FLOAT,\n 'Reading from a framebuffer is only allowed for the types \\'uint8\\' and \\'float\\'')\n } else {\n check(\n type === GL_UNSIGNED_BYTE,\n 'Reading from a framebuffer is only allowed for the type \\'uint8\\'')\n }\n }\n\n var x = 0\n var y = 0\n var width = context.framebufferWidth\n var height = context.framebufferHeight\n var data = null\n\n if (isTypedArray(input)) {\n data = input\n } else if (input) {\n check.type(input, 'object', 'invalid arguments to regl.read()')\n x = input.x | 0\n y = input.y | 0\n check(\n x >= 0 && x < context.framebufferWidth,\n 'invalid x offset for regl.read')\n check(\n y >= 0 && y < context.framebufferHeight,\n 'invalid y offset for regl.read')\n width = (input.width || (context.framebufferWidth - x)) | 0\n height = (input.height || (context.framebufferHeight - y)) | 0\n data = input.data || null\n }\n\n // sanity check input.data\n if (data) {\n if (type === GL_UNSIGNED_BYTE) {\n check(\n data instanceof Uint8Array,\n 'buffer must be \\'Uint8Array\\' when reading from a framebuffer of type \\'uint8\\'')\n } else if (type === GL_FLOAT) {\n check(\n data instanceof Float32Array,\n 'buffer must be \\'Float32Array\\' when reading from a framebuffer of type \\'float\\'')\n }\n }\n\n check(\n width > 0 && width + x <= context.framebufferWidth,\n 'invalid width for read pixels')\n check(\n height > 0 && height + y <= context.framebufferHeight,\n 'invalid height for read pixels')\n\n // Update WebGL state\n reglPoll()\n\n // Compute size\n var size = width * height * 4\n\n // Allocate data\n if (!data) {\n if (type === GL_UNSIGNED_BYTE) {\n data = new Uint8Array(size)\n } else if (type === GL_FLOAT) {\n data = data || new Float32Array(size)\n }\n }\n\n // Type check\n check.isTypedArray(data, 'data buffer for regl.read() must be a typedarray')\n check(data.byteLength >= size, 'data buffer for regl.read() too small')\n\n // Run read pixels\n gl.pixelStorei(GL_PACK_ALIGNMENT, 4)\n gl.readPixels(x, y, width, height, GL_RGBA,\n type,\n data)\n\n return data\n }\n\n return readPixels\n}\n",
"var check = require('./util/check')\nvar values = require('./util/values')\n\nvar GL_RENDERBUFFER = 0x8D41\n\nvar GL_RGBA4 = 0x8056\nvar GL_RGB5_A1 = 0x8057\nvar GL_RGB565 = 0x8D62\nvar GL_DEPTH_COMPONENT16 = 0x81A5\nvar GL_STENCIL_INDEX8 = 0x8D48\nvar GL_DEPTH_STENCIL = 0x84F9\n\nvar GL_SRGB8_ALPHA8_EXT = 0x8C43\n\nvar GL_RGBA32F_EXT = 0x8814\n\nvar GL_RGBA16F_EXT = 0x881A\nvar GL_RGB16F_EXT = 0x881B\n\nvar FORMAT_SIZES = []\n\nFORMAT_SIZES[GL_RGBA4] = 2\nFORMAT_SIZES[GL_RGB5_A1] = 2\nFORMAT_SIZES[GL_RGB565] = 2\n\nFORMAT_SIZES[GL_DEPTH_COMPONENT16] = 2\nFORMAT_SIZES[GL_STENCIL_INDEX8] = 1\nFORMAT_SIZES[GL_DEPTH_STENCIL] = 4\n\nFORMAT_SIZES[GL_SRGB8_ALPHA8_EXT] = 4\nFORMAT_SIZES[GL_RGBA32F_EXT] = 16\nFORMAT_SIZES[GL_RGBA16F_EXT] = 8\nFORMAT_SIZES[GL_RGB16F_EXT] = 6\n\nfunction getRenderbufferSize (format, width, height) {\n return FORMAT_SIZES[format] * width * height\n}\n\nmodule.exports = function (gl, extensions, limits, stats, config) {\n var formatTypes = {\n 'rgba4': GL_RGBA4,\n 'rgb565': GL_RGB565,\n 'rgb5 a1': GL_RGB5_A1,\n 'depth': GL_DEPTH_COMPONENT16,\n 'stencil': GL_STENCIL_INDEX8,\n 'depth stencil': GL_DEPTH_STENCIL\n }\n\n if (extensions.ext_srgb) {\n formatTypes['srgba'] = GL_SRGB8_ALPHA8_EXT\n }\n\n if (extensions.ext_color_buffer_half_float) {\n formatTypes['rgba16f'] = GL_RGBA16F_EXT\n formatTypes['rgb16f'] = GL_RGB16F_EXT\n }\n\n if (extensions.webgl_color_buffer_float) {\n formatTypes['rgba32f'] = GL_RGBA32F_EXT\n }\n\n var renderbufferCount = 0\n var renderbufferSet = {}\n\n function REGLRenderbuffer (renderbuffer) {\n this.id = renderbufferCount++\n this.refCount = 1\n\n this.renderbuffer = renderbuffer\n\n this.format = GL_RGBA4\n this.width = 0\n this.height = 0\n\n if (config.profile) {\n this.stats = {size: 0}\n }\n }\n\n REGLRenderbuffer.prototype.decRef = function () {\n if (--this.refCount <= 0) {\n destroy(this)\n }\n }\n\n function destroy (rb) {\n var handle = rb.renderbuffer\n check(handle, 'must not double destroy renderbuffer')\n gl.bindRenderbuffer(GL_RENDERBUFFER, null)\n gl.deleteRenderbuffer(handle)\n rb.renderbuffer = null\n rb.refCount = 0\n delete renderbufferSet[rb.id]\n stats.renderbufferCount--\n }\n\n function createRenderbuffer (a, b) {\n var renderbuffer = new REGLRenderbuffer(gl.createRenderbuffer())\n renderbufferSet[renderbuffer.id] = renderbuffer\n stats.renderbufferCount++\n\n function reglRenderbuffer (a, b) {\n var w = 0\n var h = 0\n var format = GL_RGBA4\n\n if (typeof a === 'object' && a) {\n var options = a\n if ('shape' in options) {\n var shape = options.shape\n check(Array.isArray(shape) && shape.length >= 2,\n 'invalid renderbuffer shape')\n w = shape[0] | 0\n h = shape[1] | 0\n } else {\n if ('radius' in options) {\n w = h = options.radius | 0\n }\n if ('width' in options) {\n w = options.width | 0\n }\n if ('height' in options) {\n h = options.height | 0\n }\n }\n if ('format' in options) {\n check.parameter(options.format, formatTypes,\n 'invalid renderbuffer format')\n format = formatTypes[options.format]\n }\n } else if (typeof a === 'number') {\n w = a | 0\n if (typeof b === 'number') {\n h = b | 0\n } else {\n h = w\n }\n } else if (!a) {\n w = h = 1\n } else {\n check.raise('invalid arguments to renderbuffer constructor')\n }\n\n // check shape\n check(\n w > 0 && h > 0 &&\n w <= limits.maxRenderbufferSize && h <= limits.maxRenderbufferSize,\n 'invalid renderbuffer size')\n\n if (w === renderbuffer.width &&\n h === renderbuffer.height &&\n format === renderbuffer.format) {\n return\n }\n\n reglRenderbuffer.width = renderbuffer.width = w\n reglRenderbuffer.height = renderbuffer.height = h\n renderbuffer.format = format\n\n gl.bindRenderbuffer(GL_RENDERBUFFER, renderbuffer.renderbuffer)\n gl.renderbufferStorage(GL_RENDERBUFFER, format, w, h)\n\n if (config.profile) {\n renderbuffer.stats.size = getRenderbufferSize(renderbuffer.format, renderbuffer.width, renderbuffer.height)\n }\n\n return reglRenderbuffer\n }\n\n function resize (w_, h_) {\n var w = w_ | 0\n var h = (h_ | 0) || w\n\n if (w === renderbuffer.width && h === renderbuffer.height) {\n return reglRenderbuffer\n }\n\n // check shape\n check(\n w > 0 && h > 0 &&\n w <= limits.maxRenderbufferSize && h <= limits.maxRenderbufferSize,\n 'invalid renderbuffer size')\n\n reglRenderbuffer.width = renderbuffer.width = w\n reglRenderbuffer.height = renderbuffer.height = h\n\n gl.bindRenderbuffer(GL_RENDERBUFFER, renderbuffer.renderbuffer)\n gl.renderbufferStorage(GL_RENDERBUFFER, renderbuffer.format, w, h)\n\n // also, recompute size.\n if (config.profile) {\n renderbuffer.stats.size = getRenderbufferSize(\n renderbuffer.format, renderbuffer.width, renderbuffer.height)\n }\n\n return reglRenderbuffer\n }\n\n reglRenderbuffer(a, b)\n\n reglRenderbuffer.resize = resize\n reglRenderbuffer._reglType = 'renderbuffer'\n reglRenderbuffer._renderbuffer = renderbuffer\n if (config.profile) {\n reglRenderbuffer.stats = renderbuffer.stats\n }\n reglRenderbuffer.destroy = function () {\n renderbuffer.decRef()\n }\n\n return reglRenderbuffer\n }\n\n if (config.profile) {\n stats.getTotalRenderbufferSize = function () {\n var total = 0\n Object.keys(renderbufferSet).forEach(function (key) {\n total += renderbufferSet[key].stats.size\n })\n return total\n }\n }\n\n return {\n create: createRenderbuffer,\n clear: function () {\n values(renderbufferSet).forEach(destroy)\n }\n }\n}\n",
"var check = require('./util/check')\nvar values = require('./util/values')\n\nvar GL_FRAGMENT_SHADER = 35632\nvar GL_VERTEX_SHADER = 35633\n\nvar GL_ACTIVE_UNIFORMS = 0x8B86\nvar GL_ACTIVE_ATTRIBUTES = 0x8B89\n\nmodule.exports = function wrapShaderState (gl, stringStore, stats, config) {\n // ===================================================\n // glsl compilation and linking\n // ===================================================\n var fragShaders = {}\n var vertShaders = {}\n\n function ActiveInfo (name, id, location, info) {\n this.name = name\n this.id = id\n this.location = location\n this.info = info\n }\n\n function insertActiveInfo (list, info) {\n for (var i = 0; i < list.length; ++i) {\n if (list[i].id === info.id) {\n list[i].location = info.location\n return\n }\n }\n list.push(info)\n }\n\n function getShader (type, id, command) {\n var cache = type === GL_FRAGMENT_SHADER ? fragShaders : vertShaders\n var shader = cache[id]\n\n if (!shader) {\n var source = stringStore.str(id)\n shader = gl.createShader(type)\n gl.shaderSource(shader, source)\n gl.compileShader(shader)\n check.shaderError(gl, shader, source, type, command)\n cache[id] = shader\n }\n\n return shader\n }\n\n // ===================================================\n // program linking\n // ===================================================\n var programCache = {}\n var programList = []\n\n var PROGRAM_COUNTER = 0\n\n function REGLProgram (fragId, vertId) {\n this.id = PROGRAM_COUNTER++\n this.fragId = fragId\n this.vertId = vertId\n this.program = null\n this.uniforms = []\n this.attributes = []\n\n if (config.profile) {\n this.stats = {\n uniformsCount: 0,\n attributesCount: 0\n }\n }\n }\n\n function linkProgram (desc, command) {\n var i, info\n\n // -------------------------------\n // compile & link\n // -------------------------------\n var fragShader = getShader(GL_FRAGMENT_SHADER, desc.fragId)\n var vertShader = getShader(GL_VERTEX_SHADER, desc.vertId)\n\n var program = desc.program = gl.createProgram()\n gl.attachShader(program, fragShader)\n gl.attachShader(program, vertShader)\n gl.linkProgram(program)\n check.linkError(\n gl,\n program,\n stringStore.str(desc.fragId),\n stringStore.str(desc.vertId),\n command)\n\n // -------------------------------\n // grab uniforms\n // -------------------------------\n var numUniforms = gl.getProgramParameter(program, GL_ACTIVE_UNIFORMS)\n if (config.profile) {\n desc.stats.uniformsCount = numUniforms\n }\n var uniforms = desc.uniforms\n for (i = 0; i < numUniforms; ++i) {\n info = gl.getActiveUniform(program, i)\n if (info) {\n if (info.size > 1) {\n for (var j = 0; j < info.size; ++j) {\n var name = info.name.replace('[0]', '[' + j + ']')\n insertActiveInfo(uniforms, new ActiveInfo(\n name,\n stringStore.id(name),\n gl.getUniformLocation(program, name),\n info))\n }\n } else {\n insertActiveInfo(uniforms, new ActiveInfo(\n info.name,\n stringStore.id(info.name),\n gl.getUniformLocation(program, info.name),\n info))\n }\n }\n }\n\n // -------------------------------\n // grab attributes\n // -------------------------------\n var numAttributes = gl.getProgramParameter(program, GL_ACTIVE_ATTRIBUTES)\n if (config.profile) {\n desc.stats.attributesCount = numAttributes\n }\n\n var attributes = desc.attributes\n for (i = 0; i < numAttributes; ++i) {\n info = gl.getActiveAttrib(program, i)\n if (info) {\n insertActiveInfo(attributes, new ActiveInfo(\n info.name,\n stringStore.id(info.name),\n gl.getAttribLocation(program, info.name),\n info))\n }\n }\n }\n\n if (config.profile) {\n stats.getMaxUniformsCount = function () {\n var m = 0\n programList.forEach(function (desc) {\n if (desc.stats.uniformsCount > m) {\n m = desc.stats.uniformsCount\n }\n })\n return m\n }\n\n stats.getMaxAttributesCount = function () {\n var m = 0\n programList.forEach(function (desc) {\n if (desc.stats.attributesCount > m) {\n m = desc.stats.attributesCount\n }\n })\n return m\n }\n }\n\n return {\n clear: function () {\n var deleteShader = gl.deleteShader.bind(gl)\n values(fragShaders).forEach(deleteShader)\n fragShaders = {}\n values(vertShaders).forEach(deleteShader)\n vertShaders = {}\n\n programList.forEach(function (desc) {\n gl.deleteProgram(desc.program)\n })\n programList.length = 0\n programCache = {}\n\n stats.shaderCount = 0\n },\n\n program: function (vertId, fragId, command) {\n check.command(vertId >= 0, 'missing vertex shader', command)\n check.command(fragId >= 0, 'missing fragment shader', command)\n\n stats.shaderCount++\n\n var cache = programCache[fragId]\n if (!cache) {\n cache = programCache[fragId] = {}\n }\n var program = cache[vertId]\n if (!program) {\n program = new REGLProgram(fragId, vertId)\n linkProgram(program, command)\n cache[vertId] = program\n programList.push(program)\n }\n return program\n },\n\n shader: getShader,\n\n frag: -1,\n vert: -1\n }\n}\n",
"\nmodule.exports = function stats () {\n return {\n bufferCount: 0,\n elementsCount: 0,\n framebufferCount: 0,\n shaderCount: 0,\n textureCount: 0,\n cubeCount: 0,\n renderbufferCount: 0,\n\n maxTextureUnits: 0\n }\n}\n",
"module.exports = function createStringStore () {\n var stringIds = {'': 0}\n var stringValues = ['']\n return {\n id: function (str) {\n var result = stringIds[str]\n if (result) {\n return result\n }\n result = stringIds[str] = stringValues.length\n stringValues.push(str)\n return result\n },\n\n str: function (id) {\n return stringValues[id]\n }\n }\n}\n",
"var check = require('./util/check')\nvar extend = require('./util/extend')\nvar values = require('./util/values')\nvar isTypedArray = require('./util/is-typed-array')\nvar isNDArrayLike = require('./util/is-ndarray')\nvar pool = require('./util/pool')\nvar convertToHalfFloat = require('./util/to-half-float')\nvar isArrayLike = require('./util/is-array-like')\n\nvar dtypes = require('./constants/arraytypes.json')\nvar arrayTypes = require('./constants/arraytypes.json')\n\nvar GL_COMPRESSED_TEXTURE_FORMATS = 0x86A3\n\nvar GL_TEXTURE_2D = 0x0DE1\nvar GL_TEXTURE_CUBE_MAP = 0x8513\nvar GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515\n\nvar GL_RGBA = 0x1908\nvar GL_ALPHA = 0x1906\nvar GL_RGB = 0x1907\nvar GL_LUMINANCE = 0x1909\nvar GL_LUMINANCE_ALPHA = 0x190A\n\nvar GL_RGBA4 = 0x8056\nvar GL_RGB5_A1 = 0x8057\nvar GL_RGB565 = 0x8D62\n\nvar GL_UNSIGNED_SHORT_4_4_4_4 = 0x8033\nvar GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034\nvar GL_UNSIGNED_SHORT_5_6_5 = 0x8363\nvar GL_UNSIGNED_INT_24_8_WEBGL = 0x84FA\n\nvar GL_DEPTH_COMPONENT = 0x1902\nvar GL_DEPTH_STENCIL = 0x84F9\n\nvar GL_SRGB_EXT = 0x8C40\nvar GL_SRGB_ALPHA_EXT = 0x8C42\n\nvar GL_HALF_FLOAT_OES = 0x8D61\n\nvar GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0\nvar GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1\nvar GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2\nvar GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3\n\nvar GL_COMPRESSED_RGB_ATC_WEBGL = 0x8C92\nvar GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL = 0x8C93\nvar GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 0x87EE\n\nvar GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00\nvar GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01\nvar GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02\nvar GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03\n\nvar GL_COMPRESSED_RGB_ETC1_WEBGL = 0x8D64\n\nvar GL_UNSIGNED_BYTE = 0x1401\nvar GL_UNSIGNED_SHORT = 0x1403\nvar GL_UNSIGNED_INT = 0x1405\nvar GL_FLOAT = 0x1406\n\nvar GL_TEXTURE_WRAP_S = 0x2802\nvar GL_TEXTURE_WRAP_T = 0x2803\n\nvar GL_REPEAT = 0x2901\nvar GL_CLAMP_TO_EDGE = 0x812F\nvar GL_MIRRORED_REPEAT = 0x8370\n\nvar GL_TEXTURE_MAG_FILTER = 0x2800\nvar GL_TEXTURE_MIN_FILTER = 0x2801\n\nvar GL_NEAREST = 0x2600\nvar GL_LINEAR = 0x2601\nvar GL_NEAREST_MIPMAP_NEAREST = 0x2700\nvar GL_LINEAR_MIPMAP_NEAREST = 0x2701\nvar GL_NEAREST_MIPMAP_LINEAR = 0x2702\nvar GL_LINEAR_MIPMAP_LINEAR = 0x2703\n\nvar GL_GENERATE_MIPMAP_HINT = 0x8192\nvar GL_DONT_CARE = 0x1100\nvar GL_FASTEST = 0x1101\nvar GL_NICEST = 0x1102\n\nvar GL_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE\n\nvar GL_UNPACK_ALIGNMENT = 0x0CF5\nvar GL_UNPACK_FLIP_Y_WEBGL = 0x9240\nvar GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241\nvar GL_UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243\n\nvar GL_BROWSER_DEFAULT_WEBGL = 0x9244\n\nvar GL_TEXTURE0 = 0x84C0\n\nvar MIPMAP_FILTERS = [\n GL_NEAREST_MIPMAP_NEAREST,\n GL_NEAREST_MIPMAP_LINEAR,\n GL_LINEAR_MIPMAP_NEAREST,\n GL_LINEAR_MIPMAP_LINEAR\n]\n\nvar CHANNELS_FORMAT = [\n 0,\n GL_LUMINANCE,\n GL_LUMINANCE_ALPHA,\n GL_RGB,\n GL_RGBA\n]\n\nvar FORMAT_CHANNELS = {}\nFORMAT_CHANNELS[GL_LUMINANCE] =\nFORMAT_CHANNELS[GL_ALPHA] =\nFORMAT_CHANNELS[GL_DEPTH_COMPONENT] = 1\nFORMAT_CHANNELS[GL_DEPTH_STENCIL] =\nFORMAT_CHANNELS[GL_LUMINANCE_ALPHA] = 2\nFORMAT_CHANNELS[GL_RGB] =\nFORMAT_CHANNELS[GL_SRGB_EXT] = 3\nFORMAT_CHANNELS[GL_RGBA] =\nFORMAT_CHANNELS[GL_SRGB_ALPHA_EXT] = 4\n\nvar formatTypes = {}\nformatTypes[GL_RGBA4] = GL_UNSIGNED_SHORT_4_4_4_4\nformatTypes[GL_RGB565] = GL_UNSIGNED_SHORT_5_6_5\nformatTypes[GL_RGB5_A1] = GL_UNSIGNED_SHORT_5_5_5_1\nformatTypes[GL_DEPTH_COMPONENT] = GL_UNSIGNED_INT\nformatTypes[GL_DEPTH_STENCIL] = GL_UNSIGNED_INT_24_8_WEBGL\n\nfunction objectName (str) {\n return '[object ' + str + ']'\n}\n\nvar CANVAS_CLASS = objectName('HTMLCanvasElement')\nvar CONTEXT2D_CLASS = objectName('CanvasRenderingContext2D')\nvar IMAGE_CLASS = objectName('HTMLImageElement')\nvar VIDEO_CLASS = objectName('HTMLVideoElement')\n\nvar PIXEL_CLASSES = Object.keys(dtypes).concat([\n CANVAS_CLASS,\n CONTEXT2D_CLASS,\n IMAGE_CLASS,\n VIDEO_CLASS\n])\n\n// for every texture type, store\n// the size in bytes.\nvar TYPE_SIZES = []\nTYPE_SIZES[GL_UNSIGNED_BYTE] = 1\nTYPE_SIZES[GL_FLOAT] = 4\nTYPE_SIZES[GL_HALF_FLOAT_OES] = 2\n\nTYPE_SIZES[GL_UNSIGNED_SHORT] = 2\nTYPE_SIZES[GL_UNSIGNED_INT] = 4\n\nvar FORMAT_SIZES_SPECIAL = []\nFORMAT_SIZES_SPECIAL[GL_RGBA4] = 2\nFORMAT_SIZES_SPECIAL[GL_RGB5_A1] = 2\nFORMAT_SIZES_SPECIAL[GL_RGB565] = 2\nFORMAT_SIZES_SPECIAL[GL_DEPTH_STENCIL] = 4\n\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGB_S3TC_DXT1_EXT] = 0.5\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGBA_S3TC_DXT1_EXT] = 0.5\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGBA_S3TC_DXT3_EXT] = 1\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGBA_S3TC_DXT5_EXT] = 1\n\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGB_ATC_WEBGL] = 0.5\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL] = 1\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL] = 1\n\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = 0.5\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = 0.25\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = 0.5\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = 0.25\n\nFORMAT_SIZES_SPECIAL[GL_COMPRESSED_RGB_ETC1_WEBGL] = 0.5\n\nfunction isNumericArray (arr) {\n return (\n Array.isArray(arr) &&\n (arr.length === 0 ||\n typeof arr[0] === 'number'))\n}\n\nfunction isRectArray (arr) {\n if (!Array.isArray(arr)) {\n return false\n }\n var width = arr.length\n if (width === 0 || !isArrayLike(arr[0])) {\n return false\n }\n return true\n}\n\nfunction classString (x) {\n return Object.prototype.toString.call(x)\n}\n\nfunction isCanvasElement (object) {\n return classString(object) === CANVAS_CLASS\n}\n\nfunction isContext2D (object) {\n return classString(object) === CONTEXT2D_CLASS\n}\n\nfunction isImageElement (object) {\n return classString(object) === IMAGE_CLASS\n}\n\nfunction isVideoElement (object) {\n return classString(object) === VIDEO_CLASS\n}\n\nfunction isPixelData (object) {\n if (!object) {\n return false\n }\n var className = classString(object)\n if (PIXEL_CLASSES.indexOf(className) >= 0) {\n return true\n }\n return (\n isNumericArray(object) ||\n isRectArray(object) ||\n isNDArrayLike(object))\n}\n\nfunction typedArrayCode (data) {\n return arrayTypes[Object.prototype.toString.call(data)] | 0\n}\n\nfunction convertData (result, data) {\n var n = result.width * result.height * result.channels\n check(data.length === n, 'inconsistent array length for texture')\n\n switch (result.type) {\n case GL_UNSIGNED_BYTE:\n case GL_UNSIGNED_SHORT:\n case GL_UNSIGNED_INT:\n case GL_FLOAT:\n var converted = pool.allocType(result.type, n)\n converted.set(data)\n result.data = converted\n break\n\n case GL_HALF_FLOAT_OES:\n result.data = convertToHalfFloat(data)\n break\n\n default:\n check.raise('unsupported texture type, must specify a typed array')\n }\n}\n\nfunction preConvert (image, n) {\n return pool.allocType(\n image.type === GL_HALF_FLOAT_OES\n ? GL_FLOAT\n : image.type, n)\n}\n\nfunction postConvert (image, data) {\n if (image.type === GL_HALF_FLOAT_OES) {\n image.data = convertToHalfFloat(data)\n pool.freeType(data)\n } else {\n image.data = data\n }\n}\n\nfunction transposeData (image, array, strideX, strideY, strideC, offset) {\n var w = image.width\n var h = image.height\n var c = image.channels\n var n = w * h * c\n var data = preConvert(image, n)\n\n var p = 0\n for (var i = 0; i < h; ++i) {\n for (var j = 0; j < w; ++j) {\n for (var k = 0; k < c; ++k) {\n data[p++] = array[strideX * j + strideY * i + strideC * k + offset]\n }\n }\n }\n\n postConvert(image, data)\n}\n\nfunction flatten2DData (image, array, w, h) {\n var n = w * h\n var data = preConvert(image, n)\n\n var p = 0\n for (var i = 0; i < h; ++i) {\n var row = array[i]\n for (var j = 0; j < w; ++j) {\n data[p++] = row[j]\n }\n }\n\n postConvert(image, data)\n}\n\nfunction flatten3DData (image, array, w, h, c) {\n var n = w * h * c\n var data = preConvert(image, n)\n\n var p = 0\n for (var i = 0; i < h; ++i) {\n var row = array[i]\n for (var j = 0; j < w; ++j) {\n var pixel = row[j]\n for (var k = 0; k < c; ++k) {\n data[p++] = pixel[k]\n }\n }\n }\n\n postConvert(image, data)\n}\n\nfunction getTextureSize (format, type, width, height, isMipmap, isCube) {\n var s\n if (typeof FORMAT_SIZES_SPECIAL[format] !== 'undefined') {\n // we have a special array for dealing with weird color formats such as RGB5A1\n s = FORMAT_SIZES_SPECIAL[format]\n } else {\n s = FORMAT_CHANNELS[format] * TYPE_SIZES[type]\n }\n\n if (isCube) {\n s *= 6\n }\n\n if (isMipmap) {\n // compute the total size of all the mipmaps.\n var total = 0\n\n var w = width\n while (w >= 1) {\n // we can only use mipmaps on a square image,\n // so we can simply use the width and ignore the height:\n total += s * w * w\n w /= 2\n }\n return total\n } else {\n return s * width * height\n }\n}\n\nmodule.exports = function createTextureSet (\n gl, extensions, limits, reglPoll, contextState, stats, config) {\n // -------------------------------------------------------\n // Initialize constants and parameter tables here\n // -------------------------------------------------------\n var mipmapHint = {\n \"don't care\": GL_DONT_CARE,\n 'dont care': GL_DONT_CARE,\n 'nice': GL_NICEST,\n 'fast': GL_FASTEST\n }\n\n var wrapModes = {\n 'repeat': GL_REPEAT,\n 'clamp': GL_CLAMP_TO_EDGE,\n 'mirror': GL_MIRRORED_REPEAT\n }\n\n var magFilters = {\n 'nearest': GL_NEAREST,\n 'linear': GL_LINEAR\n }\n\n var minFilters = extend({\n 'nearest mipmap nearest': GL_NEAREST_MIPMAP_NEAREST,\n 'linear mipmap nearest': GL_LINEAR_MIPMAP_NEAREST,\n 'nearest mipmap linear': GL_NEAREST_MIPMAP_LINEAR,\n 'linear mipmap linear': GL_LINEAR_MIPMAP_LINEAR,\n 'mipmap': GL_LINEAR_MIPMAP_LINEAR\n }, magFilters)\n\n var colorSpace = {\n 'none': 0,\n 'browser': GL_BROWSER_DEFAULT_WEBGL\n }\n\n var textureTypes = {\n 'uint8': GL_UNSIGNED_BYTE,\n 'rgba4': GL_UNSIGNED_SHORT_4_4_4_4,\n 'rgb565': GL_UNSIGNED_SHORT_5_6_5,\n 'rgb5 a1': GL_UNSIGNED_SHORT_5_5_5_1\n }\n\n var textureFormats = {\n 'alpha': GL_ALPHA,\n 'luminance': GL_LUMINANCE,\n 'luminance alpha': GL_LUMINANCE_ALPHA,\n 'rgb': GL_RGB,\n 'rgba': GL_RGBA,\n 'rgba4': GL_RGBA4,\n 'rgb5 a1': GL_RGB5_A1,\n 'rgb565': GL_RGB565\n }\n\n var compressedTextureFormats = {}\n\n if (extensions.ext_srgb) {\n textureFormats.srgb = GL_SRGB_EXT\n textureFormats.srgba = GL_SRGB_ALPHA_EXT\n }\n\n if (extensions.oes_texture_float) {\n textureTypes.float32 = textureTypes.float = GL_FLOAT\n }\n\n if (extensions.oes_texture_half_float) {\n textureTypes['float16'] = textureTypes['half float'] = GL_HALF_FLOAT_OES\n }\n\n if (extensions.webgl_depth_texture) {\n extend(textureFormats, {\n 'depth': GL_DEPTH_COMPONENT,\n 'depth stencil': GL_DEPTH_STENCIL\n })\n\n extend(textureTypes, {\n 'uint16': GL_UNSIGNED_SHORT,\n 'uint32': GL_UNSIGNED_INT,\n 'depth stencil': GL_UNSIGNED_INT_24_8_WEBGL\n })\n }\n\n if (extensions.webgl_compressed_texture_s3tc) {\n extend(compressedTextureFormats, {\n 'rgb s3tc dxt1': GL_COMPRESSED_RGB_S3TC_DXT1_EXT,\n 'rgba s3tc dxt1': GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,\n 'rgba s3tc dxt3': GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,\n 'rgba s3tc dxt5': GL_COMPRESSED_RGBA_S3TC_DXT5_EXT\n })\n }\n\n if (extensions.webgl_compressed_texture_atc) {\n extend(compressedTextureFormats, {\n 'rgb atc': GL_COMPRESSED_RGB_ATC_WEBGL,\n 'rgba atc explicit alpha': GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,\n 'rgba atc interpolated alpha': GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL\n })\n }\n\n if (extensions.webgl_compressed_texture_pvrtc) {\n extend(compressedTextureFormats, {\n 'rgb pvrtc 4bppv1': GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\n 'rgb pvrtc 2bppv1': GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,\n 'rgba pvrtc 4bppv1': GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\n 'rgba pvrtc 2bppv1': GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG\n })\n }\n\n if (extensions.webgl_compressed_texture_etc1) {\n compressedTextureFormats['rgb etc1'] = GL_COMPRESSED_RGB_ETC1_WEBGL\n }\n\n // Copy over all texture formats\n var supportedCompressedFormats = Array.prototype.slice.call(\n gl.getParameter(GL_COMPRESSED_TEXTURE_FORMATS))\n Object.keys(compressedTextureFormats).forEach(function (name) {\n var format = compressedTextureFormats[name]\n if (supportedCompressedFormats.indexOf(format) >= 0) {\n textureFormats[name] = format\n }\n })\n\n var supportedFormats = Object.keys(textureFormats)\n limits.textureFormats = supportedFormats\n\n // colorFormats[] gives the format (channels) associated to an\n // internalformat\n var colorFormats = supportedFormats.reduce(function (color, key) {\n var glenum = textureFormats[key]\n if (glenum === GL_LUMINANCE ||\n glenum === GL_ALPHA ||\n glenum === GL_LUMINANCE ||\n glenum === GL_LUMINANCE_ALPHA ||\n glenum === GL_DEPTH_COMPONENT ||\n glenum === GL_DEPTH_STENCIL) {\n color[glenum] = glenum\n } else if (glenum === GL_RGB5_A1 || key.indexOf('rgba') >= 0) {\n color[glenum] = GL_RGBA\n } else {\n color[glenum] = GL_RGB\n }\n return color\n }, {})\n\n function TexFlags () {\n // format info\n this.internalformat = GL_RGBA\n this.format = GL_RGBA\n this.type = GL_UNSIGNED_BYTE\n this.compressed = false\n\n // pixel storage\n this.premultiplyAlpha = false\n this.flipY = false\n this.unpackAlignment = 1\n this.colorSpace = 0\n\n // shape info\n this.width = 0\n this.height = 0\n this.channels = 4\n }\n\n function copyFlags (result, other) {\n result.internalformat = other.internalformat\n result.format = other.format\n result.type = other.type\n result.compressed = other.compressed\n\n result.premultiplyAlpha = other.premultiplyAlpha\n result.flipY = other.flipY\n result.unpackAlignment = other.unpackAlignment\n result.colorSpace = other.colorSpace\n\n result.width = other.width\n result.height = other.height\n result.channels = other.channels\n }\n\n function parseFlags (flags, options) {\n if (typeof options !== 'object' || !options) {\n return\n }\n\n if ('premultiplyAlpha' in options) {\n check.type(options.premultiplyAlpha, 'boolean',\n 'invalid premultiplyAlpha')\n flags.premultiplyAlpha = options.premultiplyAlpha\n }\n\n if ('flipY' in options) {\n check.type(options.flipY, 'boolean',\n 'invalid texture flip')\n flags.flipY = options.flipY\n }\n\n if ('alignment' in options) {\n check.oneOf(options.alignment, [1, 2, 4, 8],\n 'invalid texture unpack alignment')\n flags.unpackAlignment = options.alignment\n }\n\n if ('colorSpace' in options) {\n check.parameter(options.colorSpace, colorSpace,\n 'invalid colorSpace')\n flags.colorSpace = colorSpace[options.colorSpace]\n }\n\n if ('type' in options) {\n var type = options.type\n check(extensions.oes_texture_float ||\n !(type === 'float' || type === 'float32'),\n 'you must enable the OES_texture_float extension in order to use floating point textures.')\n check(extensions.oes_texture_half_float ||\n !(type === 'half float' || type === 'float16'),\n 'you must enable the OES_texture_half_float extension in order to use 16-bit floating point textures.')\n check(extensions.webgl_depth_texture ||\n !(type === 'depth' || type === 'depth stencil'),\n 'you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures.')\n check.parameter(type, textureTypes,\n 'invalid texture type')\n flags.type = textureTypes[type]\n }\n\n var w = flags.width\n var h = flags.height\n var c = flags.channels\n var hasChannels = false\n if ('shape' in options) {\n check(Array.isArray(options.shape) && options.shape.length >= 2,\n 'shape must be an array')\n w = options.shape[0]\n h = options.shape[1]\n if (options.shape.length === 3) {\n c = options.shape[2]\n check(c > 0 && c <= 4, 'invalid number of channels')\n hasChannels = true\n }\n check(w >= 0 && w <= limits.maxTextureSize, 'invalid width')\n check(h >= 0 && h <= limits.maxTextureSize, 'invalid height')\n } else {\n if ('radius' in options) {\n w = h = options.radius\n check(w >= 0 && w <= limits.maxTextureSize, 'invalid radius')\n }\n if ('width' in options) {\n w = options.width\n check(w >= 0 && w <= limits.maxTextureSize, 'invalid width')\n }\n if ('height' in options) {\n h = options.height\n check(h >= 0 && h <= limits.maxTextureSize, 'invalid height')\n }\n if ('channels' in options) {\n c = options.channels\n check(c > 0 && c <= 4, 'invalid number of channels')\n hasChannels = true\n }\n }\n flags.width = w | 0\n flags.height = h | 0\n flags.channels = c | 0\n\n var hasFormat = false\n if ('format' in options) {\n var formatStr = options.format\n check(extensions.webgl_depth_texture ||\n !(formatStr === 'depth' || formatStr === 'depth stencil'),\n 'you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures.')\n check.parameter(formatStr, textureFormats,\n 'invalid texture format')\n var internalformat = flags.internalformat = textureFormats[formatStr]\n flags.format = colorFormats[internalformat]\n if (formatStr in textureTypes) {\n if (!('type' in options)) {\n flags.type = textureTypes[formatStr]\n }\n }\n if (formatStr in compressedTextureFormats) {\n flags.compressed = true\n }\n hasFormat = true\n }\n\n // Reconcile channels and format\n if (!hasChannels && hasFormat) {\n flags.channels = FORMAT_CHANNELS[flags.format]\n } else if (hasChannels && !hasFormat) {\n if (flags.channels !== CHANNELS_FORMAT[flags.format]) {\n flags.format = flags.internalformat = CHANNELS_FORMAT[flags.channels]\n }\n } else if (hasFormat && hasChannels) {\n check(\n flags.channels === FORMAT_CHANNELS[flags.format],\n 'number of channels inconsistent with specified format')\n }\n }\n\n function setFlags (flags) {\n gl.pixelStorei(GL_UNPACK_FLIP_Y_WEBGL, flags.flipY)\n gl.pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL, flags.premultiplyAlpha)\n gl.pixelStorei(GL_UNPACK_COLORSPACE_CONVERSION_WEBGL, flags.colorSpace)\n gl.pixelStorei(GL_UNPACK_ALIGNMENT, flags.unpackAlignment)\n }\n\n // -------------------------------------------------------\n // Tex image data\n // -------------------------------------------------------\n function TexImage () {\n TexFlags.call(this)\n\n this.xOffset = 0\n this.yOffset = 0\n\n // data\n this.data = null\n this.needsFree = false\n\n // html element\n this.element = null\n\n // copyTexImage info\n this.needsCopy = false\n }\n\n function parseImage (image, options) {\n var data = null\n if (isPixelData(options)) {\n data = options\n } else if (options) {\n check.type(options, 'object', 'invalid pixel data type')\n parseFlags(image, options)\n if ('x' in options) {\n image.xOffset = options.x | 0\n }\n if ('y' in options) {\n image.yOffset = options.y | 0\n }\n if (isPixelData(options.data)) {\n data = options.data\n }\n }\n\n check(\n !image.compressed ||\n data instanceof Uint8Array,\n 'compressed texture data must be stored in a uint8array')\n\n if (options.copy) {\n check(!data, 'can not specify copy and data field for the same texture')\n var viewW = contextState.viewportWidth\n var viewH = contextState.viewportHeight\n image.width = image.width || (viewW - image.xOffset)\n image.height = image.height || (viewH - image.yOffset)\n image.needsCopy = true\n check(image.xOffset >= 0 && image.xOffset < viewW &&\n image.yOffset >= 0 && image.yOffset < viewH &&\n image.width > 0 && image.width <= viewW &&\n image.height > 0 && image.height <= viewH,\n 'copy texture read out of bounds')\n } else if (!data) {\n image.width = image.width || 1\n image.height = image.height || 1\n } else if (isTypedArray(data)) {\n image.data = data\n if (!('type' in options) && image.type === GL_UNSIGNED_BYTE) {\n image.type = typedArrayCode(data)\n }\n } else if (isNumericArray(data)) {\n convertData(image, data)\n image.alignment = 1\n image.needsFree = true\n } else if (isNDArrayLike(data)) {\n var array = data.data\n if (!Array.isArray(array) && image.type === GL_UNSIGNED_BYTE) {\n image.type = typedArrayCode(array)\n }\n var shape = data.shape\n var stride = data.stride\n var shapeX, shapeY, shapeC, strideX, strideY, strideC\n if (shape.length === 3) {\n shapeC = shape[2]\n strideC = stride[2]\n } else {\n check(shape.length === 2, 'invalid ndarray pixel data, must be 2 or 3D')\n shapeC = 1\n strideC = 1\n }\n shapeX = shape[0]\n shapeY = shape[1]\n strideX = stride[0]\n strideY = stride[1]\n image.alignment = 1\n image.width = shapeX\n image.height = shapeY\n image.channels = shapeC\n image.format = image.internalformat = CHANNELS_FORMAT[shapeC]\n image.needsFree = true\n transposeData(image, array, strideX, strideY, strideC, data.offset)\n } else if (isCanvasElement(data) || isContext2D(data)) {\n if (isCanvasElement(data)) {\n image.element = data\n } else {\n image.element = data.canvas\n }\n image.width = image.element.width\n image.height = image.element.height\n } else if (isImageElement(data)) {\n image.element = data\n image.width = data.naturalWidth\n image.height = data.naturalHeight\n } else if (isVideoElement(data)) {\n image.element = data\n image.width = data.videoWidth\n image.height = data.videoHeight\n image.needsPoll = true\n } else if (isRectArray(data)) {\n var w = data[0].length\n var h = data.length\n var c = 1\n if (isArrayLike(data[0][0])) {\n c = data[0][0].length\n flatten3DData(image, data, w, h, c)\n } else {\n flatten2DData(image, data, w, h)\n }\n image.alignment = 1\n image.width = w\n image.height = h\n image.channels = c\n image.format = image.internalformat = CHANNELS_FORMAT[c]\n image.needsFree = true\n }\n\n if (image.type === GL_FLOAT) {\n check(limits.extensions.indexOf('oes_texture_float') >= 0,\n 'oes_texture_float extension not enabled')\n } else if (image.type === GL_HALF_FLOAT_OES) {\n check(limits.extensions.indexOf('oes_texture_half_float') >= 0,\n 'oes_texture_half_float extension not enabled')\n }\n\n // do compressed texture validation here.\n }\n\n function setImage (info, target, miplevel) {\n var element = info.element\n var data = info.data\n var internalformat = info.internalformat\n var format = info.format\n var type = info.type\n var width = info.width\n var height = info.height\n\n setFlags(info)\n\n if (element) {\n gl.texImage2D(target, miplevel, format, format, type, element)\n } else if (info.compressed) {\n gl.compressedTexImage2D(target, miplevel, internalformat, width, height, 0, data)\n } else if (info.needsCopy) {\n reglPoll()\n gl.copyTexImage2D(\n target, miplevel, format, info.xOffset, info.yOffset, width, height, 0)\n } else {\n gl.texImage2D(\n target, miplevel, format, width, height, 0, format, type, data)\n }\n }\n\n function setSubImage (info, target, x, y, miplevel) {\n var element = info.element\n var data = info.data\n var internalformat = info.internalformat\n var format = info.format\n var type = info.type\n var width = info.width\n var height = info.height\n\n setFlags(info)\n\n if (element) {\n gl.texSubImage2D(\n target, miplevel, x, y, format, type, element)\n } else if (info.compressed) {\n gl.compressedTexSubImage2D(\n target, miplevel, x, y, internalformat, width, height, data)\n } else if (info.needsCopy) {\n reglPoll()\n gl.copyTexSubImage2D(\n target, miplevel, x, y, info.xOffset, info.yOffset, width, height)\n } else {\n gl.texSubImage2D(\n target, miplevel, x, y, width, height, format, type, data)\n }\n }\n\n // texImage pool\n var imagePool = []\n\n function allocImage () {\n return imagePool.pop() || new TexImage()\n }\n\n function freeImage (image) {\n if (image.needsFree) {\n pool.freeType(image.data)\n }\n TexImage.call(image)\n imagePool.push(image)\n }\n\n // -------------------------------------------------------\n // Mip map\n // -------------------------------------------------------\n function MipMap () {\n TexFlags.call(this)\n\n this.genMipmaps = false\n this.mipmapHint = GL_DONT_CARE\n this.mipmask = 0\n this.images = Array(16)\n }\n\n function parseMipMapFromShape (mipmap, width, height) {\n var img = mipmap.images[0] = allocImage()\n mipmap.mipmask = 1\n img.width = mipmap.width = width\n img.height = mipmap.height = height\n }\n\n function parseMipMapFromObject (mipmap, options) {\n var imgData = null\n if (isPixelData(options)) {\n imgData = mipmap.images[0] = allocImage()\n copyFlags(imgData, mipmap)\n parseImage(imgData, options)\n mipmap.mipmask = 1\n } else {\n parseFlags(mipmap, options)\n if (Array.isArray(options.mipmap)) {\n var mipData = options.mipmap\n for (var i = 0; i < mipData.length; ++i) {\n imgData = mipmap.images[i] = allocImage()\n copyFlags(imgData, mipmap)\n imgData.width >>= i\n imgData.height >>= i\n parseImage(imgData, mipData[i])\n mipmap.mipmask |= (1 << i)\n }\n } else {\n imgData = mipmap.images[0] = allocImage()\n copyFlags(imgData, mipmap)\n parseImage(imgData, options)\n mipmap.mipmask = 1\n }\n }\n copyFlags(mipmap, mipmap.images[0])\n\n // For textures of the compressed format WEBGL_compressed_texture_s3tc\n // we must have that\n //\n // \"When level equals zero width and height must be a multiple of 4.\n // When level is greater than 0 width and height must be 0, 1, 2 or a multiple of 4. \"\n //\n // but we do not yet support having multiple mipmap levels for compressed textures,\n // so we only test for level zero.\n\n if (mipmap.compressed &&\n (mipmap.internalformat === GL_COMPRESSED_RGB_S3TC_DXT1_EXT) ||\n (mipmap.internalformat === GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ||\n (mipmap.internalformat === GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) ||\n (mipmap.internalformat === GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)) {\n check(mipmap.width % 4 === 0 &&\n mipmap.height % 4 === 0,\n 'for compressed texture formats, mipmap level 0 must have width and height that are a multiple of 4')\n }\n }\n\n function setMipMap (mipmap, target) {\n var images = mipmap.images\n for (var i = 0; i < images.length; ++i) {\n if (!images[i]) {\n return\n }\n setImage(images[i], target, i)\n }\n }\n\n var mipPool = []\n\n function allocMipMap () {\n var result = mipPool.pop() || new MipMap()\n TexFlags.call(result)\n result.mipmask = 0\n for (var i = 0; i < 16; ++i) {\n result.images[i] = null\n }\n return result\n }\n\n function freeMipMap (mipmap) {\n var images = mipmap.images\n for (var i = 0; i < images.length; ++i) {\n if (images[i]) {\n freeImage(images[i])\n }\n images[i] = null\n }\n mipPool.push(mipmap)\n }\n\n // -------------------------------------------------------\n // Tex info\n // -------------------------------------------------------\n function TexInfo () {\n this.minFilter = GL_NEAREST\n this.magFilter = GL_NEAREST\n\n this.wrapS = GL_CLAMP_TO_EDGE\n this.wrapT = GL_CLAMP_TO_EDGE\n\n this.anisotropic = 1\n\n this.genMipmaps = false\n this.mipmapHint = GL_DONT_CARE\n }\n\n function parseTexInfo (info, options) {\n if ('min' in options) {\n var minFilter = options.min\n check.parameter(minFilter, minFilters)\n info.minFilter = minFilters[minFilter]\n if (MIPMAP_FILTERS.indexOf(info.minFilter) >= 0) {\n info.genMipmaps = true\n }\n }\n\n if ('mag' in options) {\n var magFilter = options.mag\n check.parameter(magFilter, magFilters)\n info.magFilter = magFilters[magFilter]\n }\n\n var wrapS = info.wrapS\n var wrapT = info.wrapT\n if ('wrap' in options) {\n var wrap = options.wrap\n if (typeof wrap === 'string') {\n check.parameter(wrap, wrapModes)\n wrapS = wrapT = wrapModes[wrap]\n } else if (Array.isArray(wrap)) {\n check.parameter(wrap[0], wrapModes)\n check.parameter(wrap[1], wrapModes)\n wrapS = wrapModes[wrap[0]]\n wrapT = wrapModes[wrap[1]]\n }\n } else {\n if ('wrapS' in options) {\n var optWrapS = options.wrapS\n check.parameter(optWrapS, wrapModes)\n wrapS = wrapModes[optWrapS]\n }\n if ('wrapT' in options) {\n var optWrapT = options.wrapT\n check.parameter(optWrapT, wrapModes)\n wrapT = wrapModes[optWrapT]\n }\n }\n info.wrapS = wrapS\n info.wrapT = wrapT\n\n if ('anisotropic' in options) {\n var anisotropic = options.anisotropic\n check(typeof anisotropic === 'number' &&\n anisotropic >= 1 && anisotropic <= limits.maxAnisotropic,\n 'aniso samples must be between 1 and ')\n info.anisotropic = options.anisotropic\n }\n\n if ('mipmap' in options) {\n var hasMipMap = false\n switch (typeof options.mipmap) {\n case 'string':\n check.parameter(options.mipmap, mipmapHint,\n 'invalid mipmap hint')\n info.mipmapHint = mipmapHint[options.mipmap]\n info.genMipmaps = true\n hasMipMap = true\n break\n\n case 'boolean':\n hasMipMap = info.genMipmaps = options.mipmap\n break\n\n case 'object':\n check(Array.isArray(options.mipmap), 'invalid mipmap type')\n info.genMipmaps = false\n hasMipMap = true\n break\n\n default:\n check.raise('invalid mipmap type')\n }\n if (hasMipMap && !('min' in options)) {\n info.minFilter = GL_NEAREST_MIPMAP_NEAREST\n }\n }\n }\n\n function setTexInfo (info, target) {\n gl.texParameteri(target, GL_TEXTURE_MIN_FILTER, info.minFilter)\n gl.texParameteri(target, GL_TEXTURE_MAG_FILTER, info.magFilter)\n gl.texParameteri(target, GL_TEXTURE_WRAP_S, info.wrapS)\n gl.texParameteri(target, GL_TEXTURE_WRAP_T, info.wrapT)\n if (extensions.ext_texture_filter_anisotropic) {\n gl.texParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, info.anisotropic)\n }\n if (info.genMipmaps) {\n gl.hint(GL_GENERATE_MIPMAP_HINT, info.mipmapHint)\n gl.generateMipmap(target)\n }\n }\n\n var infoPool = []\n\n function allocInfo () {\n var result = infoPool.pop() || new TexInfo()\n TexInfo.call(result)\n return result\n }\n\n function freeInfo (info) {\n infoPool.push(info)\n }\n\n // -------------------------------------------------------\n // Full texture object\n // -------------------------------------------------------\n var textureCount = 0\n var textureSet = {}\n var numTexUnits = limits.maxTextureUnits\n var textureUnits = Array(numTexUnits).map(function () {\n return null\n })\n\n function REGLTexture (target) {\n TexFlags.call(this)\n this.mipmask = 0\n this.internalformat = GL_RGBA\n\n this.id = textureCount++\n\n this.refCount = 1\n\n this.target = target\n this.texture = gl.createTexture()\n\n this.unit = -1\n this.bindCount = 0\n\n if (config.profile) {\n this.stats = {size: 0}\n }\n }\n\n function tempBind (texture) {\n gl.activeTexture(GL_TEXTURE0)\n gl.bindTexture(texture.target, texture.texture)\n }\n\n function tempRestore () {\n var prev = textureUnits[0]\n if (prev) {\n gl.bindTexture(prev.target, prev.texture)\n } else {\n gl.bindTexture(GL_TEXTURE_2D, null)\n }\n }\n\n function destroy (texture) {\n var handle = texture.texture\n check(handle, 'must not double destroy texture')\n var unit = texture.unit\n var target = texture.target\n if (unit >= 0) {\n gl.activeTexture(GL_TEXTURE0 + unit)\n gl.bindTexture(target, null)\n textureUnits[unit] = null\n }\n gl.deleteTexture(handle)\n texture.texture = null\n texture.params = null\n texture.pixels = null\n texture.refCount = 0\n delete textureSet[texture.id]\n stats.textureCount--\n }\n\n extend(REGLTexture.prototype, {\n bind: function () {\n var texture = this\n texture.bindCount += 1\n var unit = texture.unit\n if (unit < 0) {\n for (var i = 0; i < numTexUnits; ++i) {\n var other = textureUnits[i]\n if (other) {\n if (other.bindCount > 0) {\n continue\n }\n other.unit = -1\n }\n textureUnits[i] = texture\n unit = i\n break\n }\n if (unit >= numTexUnits) {\n check.raise('insufficient number of texture units')\n }\n if (config.profile && stats.maxTextureUnits < (unit + 1)) {\n stats.maxTextureUnits = unit + 1 // +1, since the units are zero-based\n }\n texture.unit = unit\n gl.activeTexture(GL_TEXTURE0 + unit)\n gl.bindTexture(texture.target, texture.texture)\n }\n return unit\n },\n\n unbind: function () {\n this.bindCount -= 1\n },\n\n decRef: function () {\n if (--this.refCount <= 0) {\n destroy(this)\n }\n }\n })\n\n function createTexture2D (a, b) {\n var texture = new REGLTexture(GL_TEXTURE_2D)\n textureSet[texture.id] = texture\n stats.textureCount++\n\n function reglTexture2D (a, b) {\n var texInfo = allocInfo()\n var mipData = allocMipMap()\n\n if (typeof a === 'number') {\n if (typeof b === 'number') {\n parseMipMapFromShape(mipData, a | 0, b | 0)\n } else {\n parseMipMapFromShape(mipData, a | 0, a | 0)\n }\n } else if (a) {\n check.type(a, 'object', 'invalid arguments to regl.texture')\n parseTexInfo(texInfo, a)\n parseMipMapFromObject(mipData, a)\n } else {\n // empty textures get assigned a default shape of 1x1\n parseMipMapFromShape(mipData, 1, 1)\n }\n\n if (texInfo.genMipmaps) {\n mipData.mipmask = (mipData.width << 1) - 1\n }\n texture.mipmask = mipData.mipmask\n\n copyFlags(texture, mipData)\n\n check.texture2D(texInfo, mipData, limits)\n texture.internalformat = mipData.internalformat\n\n reglTexture2D.width = mipData.width\n reglTexture2D.height = mipData.height\n\n tempBind(texture)\n setMipMap(mipData, GL_TEXTURE_2D)\n setTexInfo(texInfo, GL_TEXTURE_2D)\n tempRestore()\n\n freeInfo(texInfo)\n freeMipMap(mipData)\n\n if (config.profile) {\n texture.stats.size = getTextureSize(\n texture.internalformat,\n texture.type,\n mipData.width,\n mipData.height,\n texInfo.genMipmaps,\n false)\n }\n\n return reglTexture2D\n }\n\n function subimage (image, x_, y_, level_) {\n check(!!image, 'must specify image data')\n\n var x = x_ | 0\n var y = y_ | 0\n var level = level_ | 0\n\n var imageData = allocImage()\n copyFlags(imageData, texture)\n imageData.width >>= level\n imageData.height >>= level\n imageData.width -= x\n imageData.height -= y\n parseImage(imageData, image)\n\n check(\n texture.type === imageData.type &&\n texture.format === imageData.format &&\n texture.internalformat === imageData.internalformat,\n 'incompatible format for texture.subimage')\n check(\n x >= 0 && y >= 0 &&\n x + imageData.width <= texture.width &&\n y + imageData.height <= texture.height,\n 'texture.subimage write out of bounds')\n check(\n texture.mipmask & (1 << level),\n 'missing mipmap data')\n check(\n imageData.data || imageData.element || imageData.needsCopy,\n 'missing image data')\n\n tempBind(texture)\n setSubImage(imageData, GL_TEXTURE_2D, x, y, level)\n tempRestore()\n\n freeImage(imageData)\n\n return reglTexture2D\n }\n\n function resize (w_, h_) {\n var w = w_ | 0\n var h = (h_ | 0) || w\n if (w === texture.width && h === texture.height) {\n return reglTexture2D\n }\n\n reglTexture2D.width = texture.width = w\n reglTexture2D.height = texture.height = h\n\n tempBind(texture)\n for (var i = 0; texture.mipmask >> i; ++i) {\n gl.texImage2D(\n GL_TEXTURE_2D,\n i,\n texture.format,\n w >> i,\n h >> i,\n 0,\n texture.format,\n texture.type,\n null)\n }\n tempRestore()\n\n // also, recompute the texture size.\n if (config.profile) {\n texture.stats.size = getTextureSize(\n texture.internalformat,\n texture.type,\n w,\n h,\n false,\n false)\n }\n\n return reglTexture2D\n }\n\n reglTexture2D(a, b)\n\n reglTexture2D.subimage = subimage\n reglTexture2D.resize = resize\n reglTexture2D._reglType = 'texture2d'\n reglTexture2D._texture = texture\n if (config.profile) {\n reglTexture2D.stats = texture.stats\n }\n reglTexture2D.destroy = function () {\n texture.decRef()\n }\n\n return reglTexture2D\n }\n\n function createTextureCube (a0, a1, a2, a3, a4, a5) {\n var texture = new REGLTexture(GL_TEXTURE_CUBE_MAP)\n textureSet[texture.id] = texture\n stats.cubeCount++\n\n var faces = new Array(6)\n\n function reglTextureCube (a0, a1, a2, a3, a4, a5) {\n var i\n var texInfo = allocInfo()\n for (i = 0; i < 6; ++i) {\n faces[i] = allocMipMap()\n }\n\n if (typeof a0 === 'number' || !a0) {\n var s = (a0 | 0) || 1\n for (i = 0; i < 6; ++i) {\n parseMipMapFromShape(faces[i], s, s)\n }\n } else if (typeof a0 === 'object') {\n if (a1) {\n parseMipMapFromObject(faces[0], a0)\n parseMipMapFromObject(faces[1], a1)\n parseMipMapFromObject(faces[2], a2)\n parseMipMapFromObject(faces[3], a3)\n parseMipMapFromObject(faces[4], a4)\n parseMipMapFromObject(faces[5], a5)\n } else {\n parseTexInfo(texInfo, a0)\n parseFlags(texture, a0)\n if ('faces' in a0) {\n var face_input = a0.faces\n check(Array.isArray(face_input) && face_input.length === 6,\n 'cube faces must be a length 6 array')\n for (i = 0; i < 6; ++i) {\n check(typeof face_input[i] === 'object' && !!face_input[i],\n 'invalid input for cube map face')\n copyFlags(faces[i], texture)\n parseMipMapFromObject(faces[i], face_input[i])\n }\n } else {\n for (i = 0; i < 6; ++i) {\n parseMipMapFromObject(faces[i], a0)\n }\n }\n }\n } else {\n check.raise('invalid arguments to cube map')\n }\n\n copyFlags(texture, faces[0])\n if (texInfo.genMipmaps) {\n texture.mipmask = (faces[0].width << 1) - 1\n } else {\n texture.mipmask = faces[0].mipmask\n }\n\n check.textureCube(texture, texInfo, faces, limits)\n texture.internalformat = faces[0].internalformat\n\n reglTextureCube.width = faces[0].width\n reglTextureCube.height = faces[0].height\n\n tempBind(texture)\n for (i = 0; i < 6; ++i) {\n setMipMap(faces[i], GL_TEXTURE_CUBE_MAP_POSITIVE_X + i)\n }\n setTexInfo(texInfo, GL_TEXTURE_CUBE_MAP)\n tempRestore()\n\n if (config.profile) {\n texture.stats.size = getTextureSize(\n texture.internalformat,\n texture.type,\n reglTextureCube.width,\n reglTextureCube.height,\n texInfo.genMipmaps,\n true)\n }\n\n freeInfo(texInfo)\n\n for (i = 0; i < 6; ++i) {\n freeMipMap(faces[i])\n }\n\n return reglTextureCube\n }\n\n function subimage (face, image, x_, y_, level_) {\n check(!!image, 'must specify image data')\n check(typeof face === 'number' && face === (face | 0) &&\n face >= 0 && face < 6, 'invalid face')\n\n var x = x_ | 0\n var y = y_ | 0\n var level = level_ | 0\n\n var imageData = allocImage()\n copyFlags(imageData, texture)\n imageData.width >>= level\n imageData.height >>= level\n imageData.width -= x\n imageData.height -= y\n parseImage(imageData, image)\n\n check(\n texture.type === imageData.type &&\n texture.format === imageData.format &&\n texture.internalformat === imageData.internalformat,\n 'incompatible format for texture.subimage')\n check(\n x >= 0 && y >= 0 &&\n x + imageData.width <= texture.width &&\n y + imageData.height <= texture.height,\n 'texture.subimage write out of bounds')\n check(\n texture.mipmask & (1 << level),\n 'missing mipmap data')\n check(\n imageData.data || imageData.element || imageData.needsCopy,\n 'missing image data')\n\n tempBind(texture)\n setSubImage(imageData, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, x, y, level)\n tempRestore()\n\n freeImage(imageData)\n\n return reglTextureCube\n }\n\n function resize (radius_) {\n var radius = radius_ | 0\n if (radius === texture.width) {\n return\n }\n\n reglTextureCube.width = texture.width = radius\n reglTextureCube.height = texture.height = radius\n\n tempBind(texture)\n for (var i = 0; i < 6; ++i) {\n for (var j = 0; texture.mipmask >> j; ++j) {\n gl.texImage2D(\n GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,\n j,\n texture.format,\n radius >> j,\n radius >> j,\n 0,\n texture.format,\n texture.type,\n null)\n }\n }\n tempRestore()\n\n if (config.profile) {\n texture.stats.size = getTextureSize(\n texture.internalformat,\n texture.type,\n reglTextureCube.width,\n reglTextureCube.height,\n false,\n true)\n }\n\n return reglTextureCube\n }\n\n reglTextureCube(a0, a1, a2, a3, a4, a5)\n\n reglTextureCube.subimage = subimage\n reglTextureCube.resize = resize\n reglTextureCube._reglType = 'textureCube'\n reglTextureCube._texture = texture\n if (config.profile) {\n reglTextureCube.stats = texture.stats\n }\n reglTextureCube.destroy = function () {\n texture.decRef()\n }\n\n return reglTextureCube\n }\n\n // Called when regl is destroyed\n function destroyTextures () {\n for (var i = 0; i < numTexUnits; ++i) {\n gl.activeTexture(GL_TEXTURE0 + i)\n gl.bindTexture(GL_TEXTURE_2D, null)\n textureUnits[i] = null\n }\n values(textureSet).forEach(destroy)\n\n stats.cubeCount = 0\n stats.textureCount = 0\n }\n\n if (config.profile) {\n stats.getTotalTextureSize = function () {\n var total = 0\n Object.keys(textureSet).forEach(function (key) {\n total += textureSet[key].stats.size\n })\n return total\n }\n }\n\n return {\n create2D: createTexture2D,\n createCube: createTextureCube,\n clear: destroyTextures,\n getTexture: function (wrapper) {\n return null\n }\n }\n}\n",
"var GL_QUERY_RESULT_EXT = 0x8866\nvar GL_QUERY_RESULT_AVAILABLE_EXT = 0x8867\nvar GL_TIME_ELAPSED_EXT = 0x88BF\n\nmodule.exports = function (gl, extensions) {\n var extTimer = extensions.ext_disjoint_timer_query\n\n if (!extTimer) {\n return null\n }\n\n // QUERY POOL BEGIN\n var queryPool = []\n function allocQuery () {\n return queryPool.pop() || extTimer.createQueryEXT()\n }\n function freeQuery (query) {\n queryPool.push(query)\n }\n // QUERY POOL END\n\n var pendingQueries = []\n function beginQuery (stats) {\n var query = allocQuery()\n extTimer.beginQueryEXT(GL_TIME_ELAPSED_EXT, query)\n pendingQueries.push(query)\n pushScopeStats(pendingQueries.length - 1, pendingQueries.length, stats)\n }\n\n function endQuery () {\n extTimer.endQueryEXT(GL_TIME_ELAPSED_EXT)\n }\n\n //\n // Pending stats pool.\n //\n function PendingStats () {\n this.startQueryIndex = -1\n this.endQueryIndex = -1\n this.sum = 0\n this.stats = null\n }\n var pendingStatsPool = []\n function allocPendingStats () {\n return pendingStatsPool.pop() || new PendingStats()\n }\n function freePendingStats (pendingStats) {\n pendingStatsPool.push(pendingStats)\n }\n // Pending stats pool end\n\n var pendingStats = []\n function pushScopeStats (start, end, stats) {\n var ps = allocPendingStats()\n ps.startQueryIndex = start\n ps.endQueryIndex = end\n ps.sum = 0\n ps.stats = stats\n pendingStats.push(ps)\n }\n\n // we should call this at the beginning of the frame,\n // in order to update gpuTime\n var timeSum = []\n var queryPtr = []\n function update () {\n var ptr, i\n\n var n = pendingQueries.length\n if (n === 0) {\n return\n }\n\n // Reserve space\n queryPtr.length = Math.max(queryPtr.length, n + 1)\n timeSum.length = Math.max(timeSum.length, n + 1)\n timeSum[0] = 0\n queryPtr[0] = 0\n\n // Update all pending timer queries\n var queryTime = 0\n ptr = 0\n for (i = 0; i < pendingQueries.length; ++i) {\n var query = pendingQueries[i]\n if (extTimer.getQueryObjectEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT)) {\n queryTime += extTimer.getQueryObjectEXT(query, GL_QUERY_RESULT_EXT)\n freeQuery(query)\n } else {\n pendingQueries[ptr++] = query\n }\n timeSum[i + 1] = queryTime\n queryPtr[i + 1] = ptr\n }\n pendingQueries.length = ptr\n\n // Update all pending stat queries\n ptr = 0\n for (i = 0; i < pendingStats.length; ++i) {\n var stats = pendingStats[i]\n var start = stats.startQueryIndex\n var end = stats.endQueryIndex\n stats.sum += timeSum[end] - timeSum[start]\n var startPtr = queryPtr[start]\n var endPtr = queryPtr[end]\n if (endPtr === startPtr) {\n stats.stats.gpuTime += stats.sum / 1e6\n freePendingStats(stats)\n } else {\n stats.startQueryIndex = startPtr\n stats.endQueryIndex = endPtr\n pendingStats[ptr++] = stats\n }\n }\n pendingStats.length = ptr\n }\n\n return {\n beginQuery: beginQuery,\n endQuery: endQuery,\n pushScopeStats: pushScopeStats,\n update: update,\n getNumPendingQueries: function () {\n return pendingQueries.length\n },\n clear: function () {\n queryPool.push.apply(queryPool, pendingQueries)\n for (var i = 0; i < queryPool.length; i++) {\n extTimer.deleteQueryEXT(queryPool[i])\n }\n pendingQueries.length = 0\n queryPool.length = 0\n }\n }\n}\n",
"// Error checking and parameter validation.\n//\n// Statements for the form `check.someProcedure(...)` get removed by\n// a browserify transform for optimized/minified bundles.\n//\n/* globals btoa */\nvar isTypedArray = require('./is-typed-array')\nvar extend = require('./extend')\n\n// only used for extracting shader names. if btoa not present, then errors\n// will be slightly crappier\nfunction decodeB64 (str) {\n if (typeof btoa !== 'undefined') {\n return btoa(str)\n }\n return 'base64:' + str\n}\n\nfunction raise (message) {\n var error = new Error('(regl) ' + message)\n console.error(error)\n throw error\n}\n\nfunction check (pred, message) {\n if (!pred) {\n raise(message)\n }\n}\n\nfunction encolon (message) {\n if (message) {\n return ': ' + message\n }\n return ''\n}\n\nfunction checkParameter (param, possibilities, message) {\n if (!(param in possibilities)) {\n raise('unknown parameter (' + param + ')' + encolon(message) +\n '. possible values: ' + Object.keys(possibilities).join())\n }\n}\n\nfunction checkIsTypedArray (data, message) {\n if (!isTypedArray(data)) {\n raise(\n 'invalid parameter type' + encolon(message) +\n '. must be a typed array')\n }\n}\n\nfunction checkTypeOf (value, type, message) {\n if (typeof value !== type) {\n raise(\n 'invalid parameter type' + encolon(message) +\n '. expected ' + type + ', got ' + (typeof value))\n }\n}\n\nfunction checkNonNegativeInt (value, message) {\n if (!((value >= 0) &&\n ((value | 0) === value))) {\n raise('invalid parameter type, (' + value + ')' + encolon(message) +\n '. must be a nonnegative integer')\n }\n}\n\nfunction checkOneOf (value, list, message) {\n if (list.indexOf(value) < 0) {\n raise('invalid value' + encolon(message) + '. must be one of: ' + list)\n }\n}\n\nvar constructorKeys = [\n 'gl',\n 'canvas',\n 'container',\n 'attributes',\n 'pixelRatio',\n 'extensions',\n 'optionalExtensions',\n 'profile',\n 'onDone'\n]\n\nfunction checkConstructor (obj) {\n Object.keys(obj).forEach(function (key) {\n if (constructorKeys.indexOf(key) < 0) {\n raise('invalid regl constructor argument \"' + key + '\". must be one of ' + constructorKeys)\n }\n })\n}\n\nfunction leftPad (str, n) {\n str = str + ''\n while (str.length < n) {\n str = ' ' + str\n }\n return str\n}\n\nfunction ShaderFile () {\n this.name = 'unknown'\n this.lines = []\n this.index = {}\n this.hasErrors = false\n}\n\nfunction ShaderLine (number, line) {\n this.number = number\n this.line = line\n this.errors = []\n}\n\nfunction ShaderError (fileNumber, lineNumber, message) {\n this.file = fileNumber\n this.line = lineNumber\n this.message = message\n}\n\nfunction guessCommand () {\n var error = new Error()\n var stack = (error.stack || error).toString()\n var pat = /compileProcedure.*\\n\\s*at.*\\((.*)\\)/.exec(stack)\n if (pat) {\n return pat[1]\n }\n var pat2 = /compileProcedure.*\\n\\s*at\\s+(.*)(\\n|$)/.exec(stack)\n if (pat2) {\n return pat2[1]\n }\n return 'unknown'\n}\n\nfunction guessCallSite () {\n var error = new Error()\n var stack = (error.stack || error).toString()\n var pat = /at REGLCommand.*\\n\\s+at.*\\((.*)\\)/.exec(stack)\n if (pat) {\n return pat[1]\n }\n var pat2 = /at REGLCommand.*\\n\\s+at\\s+(.*)\\n/.exec(stack)\n if (pat2) {\n return pat2[1]\n }\n return 'unknown'\n}\n\nfunction parseSource (source, command) {\n var lines = source.split('\\n')\n var lineNumber = 1\n var fileNumber = 0\n var files = {\n unknown: new ShaderFile(),\n 0: new ShaderFile()\n }\n files.unknown.name = files[0].name = command || guessCommand()\n files.unknown.lines.push(new ShaderLine(0, ''))\n for (var i = 0; i < lines.length; ++i) {\n var line = lines[i]\n var parts = /^\\s*\\#\\s*(\\w+)\\s+(.+)\\s*$/.exec(line)\n if (parts) {\n switch (parts[1]) {\n case 'line':\n var lineNumberInfo = /(\\d+)(\\s+\\d+)?/.exec(parts[2])\n if (lineNumberInfo) {\n lineNumber = lineNumberInfo[1] | 0\n if (lineNumberInfo[2]) {\n fileNumber = lineNumberInfo[2] | 0\n if (!(fileNumber in files)) {\n files[fileNumber] = new ShaderFile()\n }\n }\n }\n break\n case 'define':\n var nameInfo = /SHADER_NAME(_B64)?\\s+(.*)$/.exec(parts[2])\n if (nameInfo) {\n files[fileNumber].name = (nameInfo[1]\n ? decodeB64(nameInfo[2])\n : nameInfo[2])\n }\n break\n }\n }\n files[fileNumber].lines.push(new ShaderLine(lineNumber++, line))\n }\n Object.keys(files).forEach(function (fileNumber) {\n var file = files[fileNumber]\n file.lines.forEach(function (line) {\n file.index[line.number] = line\n })\n })\n return files\n}\n\nfunction parseErrorLog (errLog) {\n var result = []\n errLog.split('\\n').forEach(function (errMsg) {\n if (errMsg.length < 5) {\n return\n }\n var parts = /^ERROR\\:\\s+(\\d+)\\:(\\d+)\\:\\s*(.*)$/.exec(errMsg)\n if (parts) {\n result.push(new ShaderError(\n parts[1] | 0,\n parts[2] | 0,\n parts[3].trim()))\n } else if (errMsg.length > 0) {\n result.push(new ShaderError('unknown', 0, errMsg))\n }\n })\n return result\n}\n\nfunction annotateFiles (files, errors) {\n errors.forEach(function (error) {\n var file = files[error.file]\n if (file) {\n var line = file.index[error.line]\n if (line) {\n line.errors.push(error)\n file.hasErrors = true\n return\n }\n }\n files.unknown.hasErrors = true\n files.unknown.lines[0].errors.push(error)\n })\n}\n\nfunction checkShaderError (gl, shader, source, type, command) {\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n var errLog = gl.getShaderInfoLog(shader)\n var typeName = type === gl.FRAGMENT_SHADER ? 'fragment' : 'vertex'\n var files = parseSource(source, command)\n var errors = parseErrorLog(errLog)\n annotateFiles(files, errors)\n\n Object.keys(files).forEach(function (fileNumber) {\n var file = files[fileNumber]\n if (!file.hasErrors) {\n return\n }\n\n var strings = ['']\n var styles = ['']\n\n function push (str, style) {\n strings.push(str)\n styles.push(style || '')\n }\n\n push('file number ' + fileNumber + ': ' + file.name + '\\n', 'color:red;text-decoration:underline;font-weight:bold')\n\n file.lines.forEach(function (line) {\n if (line.errors.length > 0) {\n push(leftPad(line.number, 4) + '| ', 'background-color:yellow; font-weight:bold')\n push(line.line + '\\n', 'color:red; background-color:yellow; font-weight:bold')\n\n // try to guess token\n var offset = 0\n line.errors.forEach(function (error) {\n var message = error.message\n var token = /^\\s*\\'(.*)\\'\\s*\\:\\s*(.*)$/.exec(message)\n if (token) {\n var tokenPat = token[1]\n message = token[2]\n switch (tokenPat) {\n case 'assign':\n tokenPat = '='\n break\n }\n offset = Math.max(line.line.indexOf(tokenPat, offset), 0)\n } else {\n offset = 0\n }\n\n push(leftPad('| ', 6))\n push(leftPad('^^^', offset + 3) + '\\n', 'font-weight:bold')\n push(leftPad('| ', 6))\n push(message + '\\n', 'font-weight:bold')\n })\n push(leftPad('| ', 6) + '\\n')\n } else {\n push(leftPad(line.number, 4) + '| ')\n push(line.line + '\\n', 'color:red')\n }\n })\n if (typeof document !== 'undefined') {\n styles[0] = strings.join('%c')\n console.log.apply(console, styles)\n } else {\n console.log(strings.join(''))\n }\n })\n\n check.raise('Error compiling ' + typeName + ' shader, ' + files[0].name)\n }\n}\n\nfunction checkLinkError (gl, program, fragShader, vertShader, command) {\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n var errLog = gl.getProgramInfoLog(program)\n var fragParse = parseSource(fragShader, command)\n var vertParse = parseSource(vertShader, command)\n\n var header = 'Error linking program with vertex shader, \"' +\n vertParse[0].name + '\", and fragment shader \"' + fragParse[0].name + '\"'\n\n if (typeof document !== 'undefined') {\n console.log('%c' + header + '\\n%c' + errLog,\n 'color:red;text-decoration:underline;font-weight:bold',\n 'color:red')\n } else {\n console.log(header + '\\n' + errLog)\n }\n check.raise(header)\n }\n}\n\nfunction saveCommandRef (object) {\n object._commandRef = guessCommand()\n}\n\nfunction saveDrawCommandInfo (opts, uniforms, attributes, stringStore) {\n saveCommandRef(opts)\n\n function id (str) {\n if (str) {\n return stringStore.id(str)\n }\n return 0\n }\n opts._fragId = id(opts.static.frag)\n opts._vertId = id(opts.static.vert)\n\n function addProps (dict, set) {\n Object.keys(set).forEach(function (u) {\n dict[stringStore.id(u)] = true\n })\n }\n\n var uniformSet = opts._uniformSet = {}\n addProps(uniformSet, uniforms.static)\n addProps(uniformSet, uniforms.dynamic)\n\n var attributeSet = opts._attributeSet = {}\n addProps(attributeSet, attributes.static)\n addProps(attributeSet, attributes.dynamic)\n\n opts._hasCount = (\n 'count' in opts.static ||\n 'count' in opts.dynamic ||\n 'elements' in opts.static ||\n 'elements' in opts.dynamic)\n}\n\nfunction commandRaise (message, command) {\n var callSite = guessCallSite()\n raise(message +\n ' in command ' + (command || guessCommand()) +\n (callSite === 'unknown' ? '' : ' called from ' + callSite))\n}\n\nfunction checkCommand (pred, message, command) {\n if (!pred) {\n commandRaise(message, command || guessCommand())\n }\n}\n\nfunction checkParameterCommand (param, possibilities, message, command) {\n if (!(param in possibilities)) {\n commandRaise(\n 'unknown parameter (' + param + ')' + encolon(message) +\n '. possible values: ' + Object.keys(possibilities).join(),\n command || guessCommand())\n }\n}\n\nfunction checkCommandType (value, type, message, command) {\n if (typeof value !== type) {\n commandRaise(\n 'invalid parameter type' + encolon(message) +\n '. expected ' + type + ', got ' + (typeof value),\n command || guessCommand())\n }\n}\n\nfunction checkOptional (block) {\n block()\n}\n\nfunction checkFramebufferFormat (attachment, texFormats, rbFormats) {\n if (attachment.texture) {\n checkOneOf(\n attachment.texture._texture.internalformat,\n texFormats,\n 'unsupported texture format for attachment')\n } else {\n checkOneOf(\n attachment.renderbuffer._renderbuffer.format,\n rbFormats,\n 'unsupported renderbuffer format for attachment')\n }\n}\n\nvar GL_CLAMP_TO_EDGE = 0x812F\n\nvar GL_NEAREST = 0x2600\nvar GL_NEAREST_MIPMAP_NEAREST = 0x2700\nvar GL_LINEAR_MIPMAP_NEAREST = 0x2701\nvar GL_NEAREST_MIPMAP_LINEAR = 0x2702\nvar GL_LINEAR_MIPMAP_LINEAR = 0x2703\n\nvar GL_BYTE = 5120\nvar GL_UNSIGNED_BYTE = 5121\nvar GL_SHORT = 5122\nvar GL_UNSIGNED_SHORT = 5123\nvar GL_INT = 5124\nvar GL_UNSIGNED_INT = 5125\nvar GL_FLOAT = 5126\n\nvar GL_UNSIGNED_SHORT_4_4_4_4 = 0x8033\nvar GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034\nvar GL_UNSIGNED_SHORT_5_6_5 = 0x8363\nvar GL_UNSIGNED_INT_24_8_WEBGL = 0x84FA\n\nvar GL_HALF_FLOAT_OES = 0x8D61\n\nvar TYPE_SIZE = {}\n\nTYPE_SIZE[GL_BYTE] =\nTYPE_SIZE[GL_UNSIGNED_BYTE] = 1\n\nTYPE_SIZE[GL_SHORT] =\nTYPE_SIZE[GL_UNSIGNED_SHORT] =\nTYPE_SIZE[GL_HALF_FLOAT_OES] =\nTYPE_SIZE[GL_UNSIGNED_SHORT_5_6_5] =\nTYPE_SIZE[GL_UNSIGNED_SHORT_4_4_4_4] =\nTYPE_SIZE[GL_UNSIGNED_SHORT_5_5_5_1] = 2\n\nTYPE_SIZE[GL_INT] =\nTYPE_SIZE[GL_UNSIGNED_INT] =\nTYPE_SIZE[GL_FLOAT] =\nTYPE_SIZE[GL_UNSIGNED_INT_24_8_WEBGL] = 4\n\nfunction pixelSize (type, channels) {\n if (type === GL_UNSIGNED_SHORT_5_5_5_1 ||\n type === GL_UNSIGNED_SHORT_4_4_4_4 ||\n type === GL_UNSIGNED_SHORT_5_6_5) {\n return 2\n } else if (type === GL_UNSIGNED_INT_24_8_WEBGL) {\n return 4\n } else {\n return TYPE_SIZE[type] * channels\n }\n}\n\nfunction isPow2 (v) {\n return !(v & (v - 1)) && (!!v)\n}\n\nfunction checkTexture2D (info, mipData, limits) {\n var i\n var w = mipData.width\n var h = mipData.height\n var c = mipData.channels\n\n // Check texture shape\n check(w > 0 && w <= limits.maxTextureSize &&\n h > 0 && h <= limits.maxTextureSize,\n 'invalid texture shape')\n\n // check wrap mode\n if (info.wrapS !== GL_CLAMP_TO_EDGE || info.wrapT !== GL_CLAMP_TO_EDGE) {\n check(isPow2(w) && isPow2(h),\n 'incompatible wrap mode for texture, both width and height must be power of 2')\n }\n\n if (mipData.mipmask === 1) {\n if (w !== 1 && h !== 1) {\n check(\n info.minFilter !== GL_NEAREST_MIPMAP_NEAREST &&\n info.minFilter !== GL_NEAREST_MIPMAP_LINEAR &&\n info.minFilter !== GL_LINEAR_MIPMAP_NEAREST &&\n info.minFilter !== GL_LINEAR_MIPMAP_LINEAR,\n 'min filter requires mipmap')\n }\n } else {\n // texture must be power of 2\n check(isPow2(w) && isPow2(h),\n 'texture must be a square power of 2 to support mipmapping')\n check(mipData.mipmask === (w << 1) - 1,\n 'missing or incomplete mipmap data')\n }\n\n if (mipData.type === GL_FLOAT) {\n if (limits.extensions.indexOf('oes_texture_float_linear') < 0) {\n check(info.minFilter === GL_NEAREST && info.magFilter === GL_NEAREST,\n 'filter not supported, must enable oes_texture_float_linear')\n }\n check(!info.genMipmaps,\n 'mipmap generation not supported with float textures')\n }\n\n // check image complete\n var mipimages = mipData.images\n for (i = 0; i < 16; ++i) {\n if (mipimages[i]) {\n var mw = w >> i\n var mh = h >> i\n check(mipData.mipmask & (1 << i), 'missing mipmap data')\n\n var img = mipimages[i]\n\n check(\n img.width === mw &&\n img.height === mh,\n 'invalid shape for mip images')\n\n check(\n img.format === mipData.format &&\n img.internalformat === mipData.internalformat &&\n img.type === mipData.type,\n 'incompatible type for mip image')\n\n if (img.compressed) {\n // TODO: check size for compressed images\n } else if (img.data) {\n check(img.data.byteLength === mw * mh *\n Math.max(pixelSize(img.type, c), img.unpackAlignment),\n 'invalid data for image, buffer size is inconsistent with image format')\n } else if (img.element) {\n // TODO: check element can be loaded\n } else if (img.copy) {\n // TODO: check compatible format and type\n }\n } else if (!info.genMipmaps) {\n check((mipData.mipmask & (1 << i)) === 0, 'extra mipmap data')\n }\n }\n\n if (mipData.compressed) {\n check(!info.genMipmaps,\n 'mipmap generation for compressed images not supported')\n }\n}\n\nfunction checkTextureCube (texture, info, faces, limits) {\n var w = texture.width\n var h = texture.height\n var c = texture.channels\n\n // Check texture shape\n check(\n w > 0 && w <= limits.maxTextureSize && h > 0 && h <= limits.maxTextureSize,\n 'invalid texture shape')\n check(\n w === h,\n 'cube map must be square')\n check(\n info.wrapS === GL_CLAMP_TO_EDGE && info.wrapT === GL_CLAMP_TO_EDGE,\n 'wrap mode not supported by cube map')\n\n for (var i = 0; i < faces.length; ++i) {\n var face = faces[i]\n check(\n face.width === w && face.height === h,\n 'inconsistent cube map face shape')\n\n if (info.genMipmaps) {\n check(!face.compressed,\n 'can not generate mipmap for compressed textures')\n check(face.mipmask === 1,\n 'can not specify mipmaps and generate mipmaps')\n } else {\n // TODO: check mip and filter mode\n }\n\n var mipmaps = face.images\n for (var j = 0; j < 16; ++j) {\n var img = mipmaps[j]\n if (img) {\n var mw = w >> j\n var mh = h >> j\n check(face.mipmask & (1 << j), 'missing mipmap data')\n check(\n img.width === mw &&\n img.height === mh,\n 'invalid shape for mip images')\n check(\n img.format === texture.format &&\n img.internalformat === texture.internalformat &&\n img.type === texture.type,\n 'incompatible type for mip image')\n\n if (img.compressed) {\n // TODO: check size for compressed images\n } else if (img.data) {\n check(img.data.byteLength === mw * mh *\n Math.max(pixelSize(img.type, c), img.unpackAlignment),\n 'invalid data for image, buffer size is inconsistent with image format')\n } else if (img.element) {\n // TODO: check element can be loaded\n } else if (img.copy) {\n // TODO: check compatible format and type\n }\n }\n }\n }\n}\n\nmodule.exports = extend(check, {\n optional: checkOptional,\n raise: raise,\n commandRaise: commandRaise,\n command: checkCommand,\n parameter: checkParameter,\n commandParameter: checkParameterCommand,\n constructor: checkConstructor,\n type: checkTypeOf,\n commandType: checkCommandType,\n isTypedArray: checkIsTypedArray,\n nni: checkNonNegativeInt,\n oneOf: checkOneOf,\n shaderError: checkShaderError,\n linkError: checkLinkError,\n callSite: guessCallSite,\n saveCommandRef: saveCommandRef,\n saveDrawInfo: saveDrawCommandInfo,\n framebufferFormat: checkFramebufferFormat,\n guessCommand: guessCommand,\n texture2D: checkTexture2D,\n textureCube: checkTextureCube\n})\n",
"/* globals performance */\nmodule.exports =\n (typeof performance !== 'undefined' && performance.now)\n ? function () { return performance.now() }\n : function () { return +(new Date()) }\n",
"var extend = require('./extend')\n\nfunction slice (x) {\n return Array.prototype.slice.call(x)\n}\n\nfunction join (x) {\n return slice(x).join('')\n}\n\nmodule.exports = function createEnvironment () {\n // Unique variable id counter\n var varCounter = 0\n\n // Linked values are passed from this scope into the generated code block\n // Calling link() passes a value into the generated scope and returns\n // the variable name which it is bound to\n var linkedNames = []\n var linkedValues = []\n function link (value) {\n for (var i = 0; i < linkedValues.length; ++i) {\n if (linkedValues[i] === value) {\n return linkedNames[i]\n }\n }\n\n var name = 'g' + (varCounter++)\n linkedNames.push(name)\n linkedValues.push(value)\n return name\n }\n\n // create a code block\n function block () {\n var code = []\n function push () {\n code.push.apply(code, slice(arguments))\n }\n\n var vars = []\n function def () {\n var name = 'v' + (varCounter++)\n vars.push(name)\n\n if (arguments.length > 0) {\n code.push(name, '=')\n code.push.apply(code, slice(arguments))\n code.push(';')\n }\n\n return name\n }\n\n return extend(push, {\n def: def,\n toString: function () {\n return join([\n (vars.length > 0 ? 'var ' + vars + ';' : ''),\n join(code)\n ])\n }\n })\n }\n\n function scope () {\n var entry = block()\n var exit = block()\n\n var entryToString = entry.toString\n var exitToString = exit.toString\n\n function save (object, prop) {\n exit(object, prop, '=', entry.def(object, prop), ';')\n }\n\n return extend(function () {\n entry.apply(entry, slice(arguments))\n }, {\n def: entry.def,\n entry: entry,\n exit: exit,\n save: save,\n set: function (object, prop, value) {\n save(object, prop)\n entry(object, prop, '=', value, ';')\n },\n toString: function () {\n return entryToString() + exitToString()\n }\n })\n }\n\n function conditional () {\n var pred = join(arguments)\n var thenBlock = scope()\n var elseBlock = scope()\n\n var thenToString = thenBlock.toString\n var elseToString = elseBlock.toString\n\n return extend(thenBlock, {\n then: function () {\n thenBlock.apply(thenBlock, slice(arguments))\n return this\n },\n else: function () {\n elseBlock.apply(elseBlock, slice(arguments))\n return this\n },\n toString: function () {\n var elseClause = elseToString()\n if (elseClause) {\n elseClause = 'else{' + elseClause + '}'\n }\n return join([\n 'if(', pred, '){',\n thenToString(),\n '}', elseClause\n ])\n }\n })\n }\n\n // procedure list\n var globalBlock = block()\n var procedures = {}\n function proc (name, count) {\n var args = []\n function arg () {\n var name = 'a' + args.length\n args.push(name)\n return name\n }\n\n count = count || 0\n for (var i = 0; i < count; ++i) {\n arg()\n }\n\n var body = scope()\n var bodyToString = body.toString\n\n var result = procedures[name] = extend(body, {\n arg: arg,\n toString: function () {\n return join([\n 'function(', args.join(), '){',\n bodyToString(),\n '}'\n ])\n }\n })\n\n return result\n }\n\n function compile () {\n var code = ['\"use strict\";',\n globalBlock,\n 'return {']\n Object.keys(procedures).forEach(function (name) {\n code.push('\"', name, '\":', procedures[name].toString(), ',')\n })\n code.push('}')\n var src = join(code)\n .replace(/;/g, ';\\n')\n .replace(/}/g, '}\\n')\n .replace(/{/g, '{\\n')\n var proc = Function.apply(null, linkedNames.concat(src))\n return proc.apply(null, linkedValues)\n }\n\n return {\n global: globalBlock,\n link: link,\n block: block,\n proc: proc,\n scope: scope,\n cond: conditional,\n compile: compile\n }\n}\n",
"module.exports = function (base, opts) {\n var keys = Object.keys(opts)\n for (var i = 0; i < keys.length; ++i) {\n base[keys[i]] = opts[keys[i]]\n }\n return base\n}\n",
"var isTypedArray = require('./is-typed-array')\nmodule.exports = function isArrayLike (s) {\n return Array.isArray(s) || isTypedArray(s)\n}\n",
"var isTypedArray = require('./is-typed-array')\n\nmodule.exports = function isNDArrayLike (obj) {\n return (\n !!obj &&\n typeof obj === 'object' &&\n Array.isArray(obj.shape) &&\n Array.isArray(obj.stride) &&\n typeof obj.offset === 'number' &&\n obj.shape.length === obj.stride.length &&\n (Array.isArray(obj.data) ||\n isTypedArray(obj.data)))\n}\n",
"var dtypes = require('../constants/arraytypes.json')\nmodule.exports = function (x) {\n return Object.prototype.toString.call(x) in dtypes\n}\n",
"module.exports = function loop (n, f) {\n var result = Array(n)\n for (var i = 0; i < n; ++i) {\n result[i] = f(i)\n }\n return result\n}\n",
"var loop = require('./loop')\n\nvar GL_BYTE = 5120\nvar GL_UNSIGNED_BYTE = 5121\nvar GL_SHORT = 5122\nvar GL_UNSIGNED_SHORT = 5123\nvar GL_INT = 5124\nvar GL_UNSIGNED_INT = 5125\nvar GL_FLOAT = 5126\n\nvar bufferPool = loop(8, function () {\n return []\n})\n\nfunction nextPow16 (v) {\n for (var i = 16; i <= (1 << 28); i *= 16) {\n if (v <= i) {\n return i\n }\n }\n return 0\n}\n\nfunction log2 (v) {\n var r, shift\n r = (v > 0xFFFF) << 4\n v >>>= r\n shift = (v > 0xFF) << 3\n v >>>= shift; r |= shift\n shift = (v > 0xF) << 2\n v >>>= shift; r |= shift\n shift = (v > 0x3) << 1\n v >>>= shift; r |= shift\n return r | (v >> 1)\n}\n\nfunction alloc (n) {\n var sz = nextPow16(n)\n var bin = bufferPool[log2(sz) >> 2]\n if (bin.length > 0) {\n return bin.pop()\n }\n return new ArrayBuffer(sz)\n}\n\nfunction free (buf) {\n bufferPool[log2(buf.byteLength) >> 2].push(buf)\n}\n\nfunction allocType (type, n) {\n var result = null\n switch (type) {\n case GL_BYTE:\n result = new Int8Array(alloc(n), 0, n)\n break\n case GL_UNSIGNED_BYTE:\n result = new Uint8Array(alloc(n), 0, n)\n break\n case GL_SHORT:\n result = new Int16Array(alloc(2 * n), 0, n)\n break\n case GL_UNSIGNED_SHORT:\n result = new Uint16Array(alloc(2 * n), 0, n)\n break\n case GL_INT:\n result = new Int32Array(alloc(4 * n), 0, n)\n break\n case GL_UNSIGNED_INT:\n result = new Uint32Array(alloc(4 * n), 0, n)\n break\n case GL_FLOAT:\n result = new Float32Array(alloc(4 * n), 0, n)\n break\n default:\n return null\n }\n if (result.length !== n) {\n return result.subarray(0, n)\n }\n return result\n}\n\nfunction freeType (array) {\n free(array.buffer)\n}\n\nmodule.exports = {\n alloc: alloc,\n free: free,\n allocType: allocType,\n freeType: freeType\n}\n",
"/* globals requestAnimationFrame, cancelAnimationFrame */\nif (typeof requestAnimationFrame === 'function' &&\n typeof cancelAnimationFrame === 'function') {\n module.exports = {\n next: function (x) { return requestAnimationFrame(x) },\n cancel: function (x) { return cancelAnimationFrame(x) }\n }\n} else {\n module.exports = {\n next: function (cb) {\n return setTimeout(cb, 16)\n },\n cancel: clearTimeout\n }\n}\n",
"var pool = require('./pool')\n\nvar FLOAT = new Float32Array(1)\nvar INT = new Uint32Array(FLOAT.buffer)\n\nvar GL_UNSIGNED_SHORT = 5123\n\nmodule.exports = function convertToHalfFloat (array) {\n var ushorts = pool.allocType(GL_UNSIGNED_SHORT, array.length)\n\n for (var i = 0; i < array.length; ++i) {\n if (isNaN(array[i])) {\n ushorts[i] = 0xffff\n } else if (array[i] === Infinity) {\n ushorts[i] = 0x7c00\n } else if (array[i] === -Infinity) {\n ushorts[i] = 0xfc00\n } else {\n FLOAT[0] = array[i]\n var x = INT[0]\n\n var sgn = (x >>> 31) << 15\n var exp = ((x << 1) >>> 24) - 127\n var frac = (x >> 13) & ((1 << 10) - 1)\n\n if (exp < -24) {\n // round non-representable denormals to 0\n ushorts[i] = sgn\n } else if (exp < -14) {\n // handle denormals\n var s = -14 - exp\n ushorts[i] = sgn + ((frac + (1 << 10)) >> s)\n } else if (exp > 15) {\n // round overflow to +/- Infinity\n ushorts[i] = sgn + 0x7c00\n } else {\n // otherwise convert directly\n ushorts[i] = sgn + ((exp + 15) << 10) + frac\n }\n }\n }\n\n return ushorts\n}\n",
"module.exports = function (obj) {\n return Object.keys(obj).map(function (key) { return obj[key] })\n}\n",
"// Context and canvas creation helper functions\nvar check = require('./util/check')\nvar extend = require('./util/extend')\n\nfunction createCanvas (element, onDone, pixelRatio) {\n var canvas = document.createElement('canvas')\n extend(canvas.style, {\n border: 0,\n margin: 0,\n padding: 0,\n top: 0,\n left: 0\n })\n element.appendChild(canvas)\n\n if (element === document.body) {\n canvas.style.position = 'absolute'\n extend(element.style, {\n margin: 0,\n padding: 0\n })\n }\n\n function resize () {\n var w = window.innerWidth\n var h = window.innerHeight\n if (element !== document.body) {\n var bounds = element.getBoundingClientRect()\n w = bounds.right - bounds.left\n h = bounds.top - bounds.bottom\n }\n canvas.width = pixelRatio * w\n canvas.height = pixelRatio * h\n extend(canvas.style, {\n width: w + 'px',\n height: h + 'px'\n })\n }\n\n window.addEventListener('resize', resize, false)\n\n function onDestroy () {\n window.removeEventListener('resize', resize)\n element.removeChild(canvas)\n }\n\n resize()\n\n return {\n canvas: canvas,\n onDestroy: onDestroy\n }\n}\n\nfunction createContext (canvas, contexAttributes) {\n function get (name) {\n try {\n return canvas.getContext(name, contexAttributes)\n } catch (e) {\n return null\n }\n }\n return (\n get('webgl') ||\n get('experimental-webgl') ||\n get('webgl-experimental')\n )\n}\n\nfunction isHTMLElement (obj) {\n return (\n typeof obj.nodeName === 'string' &&\n typeof obj.appendChild === 'function' &&\n typeof obj.getBoundingClientRect === 'function'\n )\n}\n\nfunction isWebGLContext (obj) {\n return (\n typeof obj.drawArrays === 'function' ||\n typeof obj.drawElements === 'function'\n )\n}\n\nfunction parseExtensions (input) {\n if (typeof input === 'string') {\n return input.split()\n }\n check(Array.isArray(input), 'invalid extension array')\n return input\n}\n\nfunction getElement (desc) {\n if (typeof desc === 'string') {\n check(typeof document !== 'undefined', 'not supported outside of DOM')\n return document.querySelector(desc)\n }\n return desc\n}\n\nmodule.exports = function parseArgs (args_) {\n var args = args_ || {}\n var element, container, canvas, gl\n var contextAttributes = {}\n var extensions = []\n var optionalExtensions = []\n var pixelRatio = (typeof window === 'undefined' ? 1 : window.devicePixelRatio)\n var profile = false\n var onDone = function (err) {\n if (err) {\n check.raise(err)\n }\n }\n var onDestroy = function () {}\n if (typeof args === 'string') {\n check(\n typeof document !== 'undefined',\n 'selector queries only supported in DOM enviroments')\n element = document.querySelector(args)\n check(element, 'invalid query string for element')\n } else if (typeof args === 'object') {\n if (isHTMLElement(args)) {\n element = args\n } else if (isWebGLContext(args)) {\n gl = args\n canvas = gl.canvas\n } else {\n check.constructor(args)\n if ('gl' in args) {\n gl = args.gl\n } else if ('canvas' in args) {\n canvas = getElement(args.canvas)\n } else if ('container' in args) {\n container = getElement(args.container)\n }\n if ('attributes' in args) {\n contextAttributes = args.attributes\n check.type(contextAttributes, 'object', 'invalid context attributes')\n }\n if ('extensions' in args) {\n extensions = parseExtensions(args.extensions)\n }\n if ('optionalExtensions' in args) {\n optionalExtensions = parseExtensions(args.optionalExtensions)\n }\n if ('onDone' in args) {\n check.type(\n args.onDone, 'function',\n 'invalid or missing onDone callback')\n onDone = args.onDone\n }\n if ('profile' in args) {\n profile = !!args.profile\n }\n if ('pixelRatio' in args) {\n pixelRatio = +args.pixelRatio\n check(pixelRatio > 0, 'invalid pixel ratio')\n }\n }\n } else {\n check.raise('invalid arguments to regl')\n }\n\n if (element) {\n if (element.nodeName.toLowerCase() === 'canvas') {\n canvas = element\n } else {\n container = element\n }\n }\n\n if (!gl) {\n if (!canvas) {\n check(\n typeof document !== 'undefined',\n 'must manually specify webgl context outside of DOM environments')\n var result = createCanvas(container || document.body, onDone, pixelRatio)\n if (!result) {\n return null\n }\n canvas = result.canvas\n onDestroy = result.onDestroy\n }\n gl = createContext(canvas, contextAttributes)\n }\n\n if (!gl) {\n onDestroy()\n onDone('webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org')\n return null\n }\n\n return {\n gl: gl,\n canvas: canvas,\n container: container,\n extensions: extensions,\n optionalExtensions: optionalExtensions,\n pixelRatio: pixelRatio,\n profile: profile,\n onDone: onDone,\n onDestroy: onDestroy\n }\n}\n",
"var check = require('./lib/util/check')\nvar extend = require('./lib/util/extend')\nvar dynamic = require('./lib/dynamic')\nvar raf = require('./lib/util/raf')\nvar clock = require('./lib/util/clock')\nvar createStringStore = require('./lib/strings')\nvar initWebGL = require('./lib/webgl')\nvar wrapExtensions = require('./lib/extension')\nvar wrapLimits = require('./lib/limits')\nvar wrapBuffers = require('./lib/buffer')\nvar wrapElements = require('./lib/elements')\nvar wrapTextures = require('./lib/texture')\nvar wrapRenderbuffers = require('./lib/renderbuffer')\nvar wrapFramebuffers = require('./lib/framebuffer')\nvar wrapAttributes = require('./lib/attribute')\nvar wrapShaders = require('./lib/shader')\nvar wrapRead = require('./lib/read')\nvar createCore = require('./lib/core')\nvar createStats = require('./lib/stats')\nvar createTimer = require('./lib/timer')\n\nvar GL_COLOR_BUFFER_BIT = 16384\nvar GL_DEPTH_BUFFER_BIT = 256\nvar GL_STENCIL_BUFFER_BIT = 1024\n\nvar GL_ARRAY_BUFFER = 34962\n\nvar CONTEXT_LOST_EVENT = 'webglcontextlost'\nvar CONTEXT_RESTORED_EVENT = 'webglcontextrestored'\n\nvar DYN_PROP = 1\nvar DYN_CONTEXT = 2\nvar DYN_STATE = 3\n\nfunction find (haystack, needle) {\n for (var i = 0; i < haystack.length; ++i) {\n if (haystack[i] === needle) {\n return i\n }\n }\n return -1\n}\n\nmodule.exports = function wrapREGL (args) {\n var config = initWebGL(args)\n if (!config) {\n return null\n }\n\n // Modified by Pepe Becker <http://pepebecker.com>\n window.gl = config.gl\n // var gl = config.gl\n var glAttributes = gl.getContextAttributes()\n\n var extensionState = wrapExtensions(gl, config)\n if (!extensionState) {\n return null\n }\n\n var stringStore = createStringStore()\n var stats = createStats()\n var extensions = extensionState.extensions\n var timer = createTimer(gl, extensions)\n\n var START_TIME = clock()\n var WIDTH = gl.drawingBufferWidth\n var HEIGHT = gl.drawingBufferHeight\n\n var contextState = {\n tick: 0,\n time: 0,\n viewportWidth: WIDTH,\n viewportHeight: HEIGHT,\n framebufferWidth: WIDTH,\n framebufferHeight: HEIGHT,\n drawingBufferWidth: WIDTH,\n drawingBufferHeight: HEIGHT,\n pixelRatio: config.pixelRatio\n }\n var uniformState = {}\n var drawState = {\n elements: null,\n primitive: 4, // GL_TRIANGLES\n count: -1,\n offset: 0,\n instances: -1\n }\n\n var limits = wrapLimits(gl, extensions)\n var bufferState = wrapBuffers(gl, stats, config)\n var elementState = wrapElements(gl, extensions, bufferState, stats)\n var attributeState = wrapAttributes(\n gl,\n extensions,\n limits,\n bufferState,\n stringStore)\n var shaderState = wrapShaders(gl, stringStore, stats, config)\n var textureState = wrapTextures(\n gl,\n extensions,\n limits,\n function () { core.procs.poll() },\n contextState,\n stats,\n config)\n var renderbufferState = wrapRenderbuffers(gl, extensions, limits, stats, config)\n var framebufferState = wrapFramebuffers(\n gl,\n extensions,\n limits,\n textureState,\n renderbufferState,\n stats)\n var core = createCore(\n gl,\n stringStore,\n extensions,\n limits,\n bufferState,\n elementState,\n textureState,\n framebufferState,\n uniformState,\n attributeState,\n shaderState,\n drawState,\n contextState,\n timer,\n config)\n var readPixels = wrapRead(\n gl,\n framebufferState,\n core.procs.poll,\n contextState,\n glAttributes, extensions)\n\n var nextState = core.next\n var canvas = gl.canvas\n\n var rafCallbacks = []\n var activeRAF = null\n function handleRAF () {\n if (rafCallbacks.length === 0) {\n if (timer) {\n timer.update()\n }\n activeRAF = null\n return\n }\n\n // schedule next animation frame\n activeRAF = raf.next(handleRAF)\n\n // poll for changes\n poll()\n\n // fire a callback for all pending rafs\n for (var i = rafCallbacks.length - 1; i >= 0; --i) {\n var cb = rafCallbacks[i]\n if (cb) {\n cb(contextState, null, 0)\n }\n }\n\n // flush all pending webgl calls\n gl.flush()\n\n // poll GPU timers *after* gl.flush so we don't delay command dispatch\n if (timer) {\n timer.update()\n }\n }\n\n function startRAF () {\n if (!activeRAF && rafCallbacks.length > 0) {\n activeRAF = raf.next(handleRAF)\n }\n }\n\n function stopRAF () {\n if (activeRAF) {\n raf.cancel(handleRAF)\n activeRAF = null\n }\n }\n\n function handleContextLoss (event) {\n // TODO\n }\n\n function handleContextRestored (event) {\n // TODO\n }\n\n if (canvas) {\n canvas.addEventListener(CONTEXT_LOST_EVENT, handleContextLoss, false)\n canvas.addEventListener(CONTEXT_RESTORED_EVENT, handleContextRestored, false)\n }\n\n function destroy () {\n rafCallbacks.length = 0\n stopRAF()\n\n if (canvas) {\n canvas.removeEventListener(CONTEXT_LOST_EVENT, handleContextLoss)\n canvas.removeEventListener(CONTEXT_RESTORED_EVENT, handleContextRestored)\n }\n\n shaderState.clear()\n framebufferState.clear()\n renderbufferState.clear()\n textureState.clear()\n elementState.clear()\n bufferState.clear()\n\n if (timer) {\n timer.clear()\n }\n\n config.onDestroy()\n }\n\n function compileProcedure (options) {\n check(!!options, 'invalid args to regl({...})')\n check.type(options, 'object', 'invalid args to regl({...})')\n\n function flattenNestedOptions (options) {\n var result = extend({}, options)\n delete result.uniforms\n delete result.attributes\n delete result.context\n\n function merge (name) {\n if (name in result) {\n var child = result[name]\n delete result[name]\n Object.keys(child).forEach(function (prop) {\n result[name + '.' + prop] = child[prop]\n })\n }\n }\n merge('blend')\n merge('depth')\n merge('cull')\n merge('stencil')\n merge('polygonOffset')\n merge('scissor')\n merge('sample')\n\n return result\n }\n\n function separateDynamic (object) {\n var staticItems = {}\n var dynamicItems = {}\n Object.keys(object).forEach(function (option) {\n var value = object[option]\n if (dynamic.isDynamic(value)) {\n dynamicItems[option] = dynamic.unbox(value, option)\n } else {\n staticItems[option] = value\n }\n })\n return {\n dynamic: dynamicItems,\n static: staticItems\n }\n }\n\n // Treat context variables separate from other dynamic variables\n var context = separateDynamic(options.context || {})\n var uniforms = separateDynamic(options.uniforms || {})\n var attributes = separateDynamic(options.attributes || {})\n var opts = separateDynamic(flattenNestedOptions(options))\n\n var stats = {\n gpuTime: 0.0,\n cpuTime: 0.0,\n count: 0\n }\n\n var compiled = core.compile(opts, attributes, uniforms, context, stats)\n\n var draw = compiled.draw\n var batch = compiled.batch\n var scope = compiled.scope\n\n // FIXME: we should modify code generation for batch commands so this\n // isn't necessary\n var EMPTY_ARRAY = []\n function reserve (count) {\n while (EMPTY_ARRAY.length < count) {\n EMPTY_ARRAY.push(null)\n }\n return EMPTY_ARRAY\n }\n\n function REGLCommand (args, body) {\n var i\n if (typeof args === 'function') {\n return scope.call(this, null, args, 0)\n } else if (typeof body === 'function') {\n if (typeof args === 'number') {\n for (i = 0; i < args; ++i) {\n scope.call(this, null, body, i)\n }\n return\n } else if (Array.isArray(args)) {\n for (i = 0; i < args.length; ++i) {\n scope.call(this, args[i], body, i)\n }\n return\n } else {\n return scope.call(this, args, body, 0)\n }\n } else if (typeof args === 'number') {\n if (args > 0) {\n return batch.call(this, reserve(args | 0), args | 0)\n }\n } else if (Array.isArray(args)) {\n if (args.length) {\n return batch.call(this, args, args.length)\n }\n } else {\n return draw.call(this, args)\n }\n }\n\n return extend(REGLCommand, {\n stats: stats\n })\n }\n\n function clear (options) {\n check(\n typeof options === 'object' && options,\n 'regl.clear() takes an object as input')\n\n var clearFlags = 0\n core.procs.poll()\n\n var c = options.color\n if (c) {\n gl.clearColor(+c[0] || 0, +c[1] || 0, +c[2] || 0, +c[3] || 0)\n clearFlags |= GL_COLOR_BUFFER_BIT\n }\n if ('depth' in options) {\n gl.clearDepth(+options.depth)\n clearFlags |= GL_DEPTH_BUFFER_BIT\n }\n if ('stencil' in options) {\n gl.clearStencil(options.stencil | 0)\n clearFlags |= GL_STENCIL_BUFFER_BIT\n }\n\n check(!!clearFlags, 'called regl.clear with no buffer specified')\n gl.clear(clearFlags)\n }\n\n function frame (cb) {\n check.type(cb, 'function', 'regl.frame() callback must be a function')\n rafCallbacks.push(cb)\n\n function cancel () {\n // FIXME: should we check something other than equals cb here?\n // what if a user calls frame twice with the same callback...\n //\n var i = find(rafCallbacks, cb)\n check(i >= 0, 'cannot cancel a frame twice')\n function pendingCancel () {\n var index = find(rafCallbacks, pendingCancel)\n rafCallbacks[index] = rafCallbacks[rafCallbacks.length - 1]\n rafCallbacks.length -= 1\n if (rafCallbacks.length <= 0) {\n stopRAF()\n }\n }\n rafCallbacks[i] = pendingCancel\n }\n\n startRAF()\n\n return {\n cancel: cancel\n }\n }\n\n // poll viewport\n function pollViewport () {\n var viewport = nextState.viewport\n var scissorBox = nextState.scissor_box\n viewport[0] = viewport[1] = scissorBox[0] = scissorBox[1] = 0\n contextState.viewportWidth =\n contextState.framebufferWidth =\n contextState.drawingBufferWidth =\n viewport[2] =\n scissorBox[2] = gl.drawingBufferWidth\n contextState.viewportHeight =\n contextState.framebufferHeight =\n contextState.drawingBufferHeight =\n viewport[3] =\n scissorBox[3] = gl.drawingBufferHeight\n }\n\n function poll () {\n contextState.tick += 1\n contextState.time = (clock() - START_TIME) / 1000.0\n pollViewport()\n core.procs.poll()\n }\n\n function refresh () {\n pollViewport()\n core.procs.refresh()\n if (timer) {\n timer.update()\n }\n }\n\n refresh()\n\n var regl = extend(compileProcedure, {\n // Clear current FBO\n clear: clear,\n\n // Short cuts for dynamic variables\n prop: dynamic.define.bind(null, DYN_PROP),\n context: dynamic.define.bind(null, DYN_CONTEXT),\n this: dynamic.define.bind(null, DYN_STATE),\n\n // executes an empty draw command\n draw: compileProcedure({}),\n\n // Resources\n buffer: function (options) {\n return bufferState.create(options, GL_ARRAY_BUFFER)\n },\n elements: elementState.create,\n texture: textureState.create2D,\n cube: textureState.createCube,\n renderbuffer: renderbufferState.create,\n framebuffer: framebufferState.create,\n framebufferCube: framebufferState.createCube,\n\n // Expose context attributes\n attributes: glAttributes,\n\n // Frame rendering\n frame: frame,\n\n // System limits\n limits: limits,\n hasExtension: function (name) {\n return limits.extensions.indexOf(name.toLowerCase()) >= 0\n },\n\n // Read pixels\n read: readPixels,\n\n // Destroy regl and all associated resources\n destroy: destroy,\n\n // Direct GL state manipulation\n _gl: gl,\n _refresh: refresh,\n\n poll: function () {\n poll()\n if (timer) {\n timer.update()\n }\n },\n\n // regl Statistics Information\n stats: stats\n })\n\n config.onDone(null, regl)\n\n return regl\n}\n",
"/* global XMLHttpRequest */\nvar configParameters = [\n 'manifest',\n 'onDone',\n 'onProgress',\n 'onError'\n]\n\nvar manifestParameters = [\n 'type',\n 'src',\n 'stream',\n 'credentials',\n 'parser'\n]\n\nvar parserParameters = [\n 'onData',\n 'onDone'\n]\n\nvar STATE_ERROR = -1\nvar STATE_DATA = 0\nvar STATE_COMPLETE = 1\n\nfunction raise (message) {\n throw new Error('resl: ' + message)\n}\n\nfunction checkType (object, parameters, name) {\n Object.keys(object).forEach(function (param) {\n if (parameters.indexOf(param) < 0) {\n raise('invalid parameter \"' + param + '\" in ' + name)\n }\n })\n}\n\nfunction Loader (name, cancel) {\n this.state = STATE_DATA\n this.ready = false\n this.progress = 0\n this.name = name\n this.cancel = cancel\n}\n\nmodule.exports = function resl (config) {\n if (typeof config !== 'object' || !config) {\n raise('invalid or missing configuration')\n }\n\n checkType(config, configParameters, 'config')\n\n var manifest = config.manifest\n if (typeof manifest !== 'object' || !manifest) {\n raise('missing manifest')\n }\n\n function getFunction (name, dflt) {\n if (name in config) {\n var func = config[name]\n if (typeof func !== 'function') {\n raise('invalid callback \"' + name + '\"')\n }\n return func\n }\n return null\n }\n\n var onDone = getFunction('onDone')\n if (!onDone) {\n raise('missing onDone() callback')\n }\n\n var onProgress = getFunction('onProgress')\n var onError = getFunction('onError')\n\n var assets = {}\n\n var state = STATE_DATA\n\n function loadXHR (request) {\n var name = request.name\n var stream = request.stream\n var binary = request.type === 'binary'\n var parser = request.parser\n\n var xhr = new XMLHttpRequest()\n var asset = null\n\n var loader = new Loader(name, cancel)\n\n if (stream) {\n xhr.onreadystatechange = onReadyStateChange\n } else {\n xhr.onreadystatechange = function () {\n if (xhr.readyState === 4) {\n onReadyStateChange()\n }\n }\n }\n\n if (binary) {\n xhr.responseType = 'arraybuffer'\n }\n\n function onReadyStateChange () {\n if (xhr.readyState < 2 ||\n loader.state === STATE_COMPLETE ||\n loader.state === STATE_ERROR) {\n return\n }\n if (xhr.status !== 200) {\n return abort('error loading resource \"' + request.name + '\"')\n }\n if (xhr.readyState > 2 && loader.state === STATE_DATA) {\n var response\n if (request.type === 'binary') {\n response = xhr.response\n } else {\n response = xhr.responseText\n }\n if (parser.data) {\n try {\n asset = parser.data(response)\n } catch (e) {\n return abort(e)\n }\n } else {\n asset = response\n }\n }\n if (xhr.readyState > 3 && loader.state === STATE_DATA) {\n if (parser.done) {\n try {\n asset = parser.done()\n } catch (e) {\n return abort(e)\n }\n }\n loader.state = STATE_COMPLETE\n }\n assets[name] = asset\n loader.progress = 0.75 * loader.progress + 0.25\n loader.ready =\n (request.stream && !!asset) ||\n loader.state === STATE_COMPLETE\n notifyProgress()\n }\n\n function cancel () {\n if (loader.state === STATE_COMPLETE || loader.state === STATE_ERROR) {\n return\n }\n xhr.onreadystatechange = null\n xhr.abort()\n loader.state = STATE_ERROR\n }\n\n // set up request\n if (request.credentials) {\n xhr.withCredentials = true\n }\n xhr.open('GET', request.src, true)\n xhr.send()\n\n return loader\n }\n\n function loadElement (request, element) {\n var name = request.name\n var parser = request.parser\n\n var loader = new Loader(name, cancel)\n var asset = element\n\n function handleProgress () {\n if (loader.state === STATE_DATA) {\n if (parser.data) {\n try {\n asset = parser.data(element)\n } catch (e) {\n return abort(e)\n }\n } else {\n asset = element\n }\n }\n }\n\n function onProgress (e) {\n handleProgress()\n assets[name] = asset\n if (e.lengthComputable) {\n loader.progress = Math.max(loader.progress, e.loaded / e.total)\n } else {\n loader.progress = 0.75 * loader.progress + 0.25\n }\n loader.ready = request.stream\n notifyProgress(name)\n }\n\n function onComplete () {\n handleProgress()\n if (loader.state === STATE_DATA) {\n if (parser.done) {\n try {\n asset = parser.done()\n } catch (e) {\n return abort(e)\n }\n }\n loader.state = STATE_COMPLETE\n }\n loader.progress = 1\n loader.ready = true\n assets[name] = asset\n removeListeners()\n notifyProgress('finish ' + name)\n }\n\n function onError () {\n abort('error loading asset \"' + name + '\"')\n }\n\n if (request.stream) {\n element.addEventListener('progress', onProgress)\n }\n if (request.type === 'image') {\n element.addEventListener('load', onComplete)\n } else {\n var canPlay = false\n var loadedMetaData = false\n element.addEventListener('loadedmetadata', function () {\n loadedMetaData = true\n if (canPlay) {\n onComplete()\n }\n })\n element.addEventListener('canplay', function () {\n canPlay = true\n if (loadedMetaData) {\n onComplete()\n }\n })\n }\n element.addEventListener('error', onError)\n\n function removeListeners () {\n if (request.stream) {\n element.removeEventListener('progress', onProgress)\n }\n if (request.type === 'image') {\n element.addEventListener('load', onComplete)\n } else {\n element.addEventListener('canplay', onComplete)\n }\n element.removeEventListener('error', onError)\n }\n\n function cancel () {\n if (loader.state === STATE_COMPLETE || loader.state === STATE_ERROR) {\n return\n }\n loader.state = STATE_ERROR\n removeListeners()\n element.src = ''\n }\n\n // set up request\n if (request.credentials) {\n element.crossOrigin = 'use-credentials'\n } else {\n element.crossOrigin = 'anonymous'\n }\n element.src = request.src\n\n return loader\n }\n\n var loaders = {\n text: loadXHR,\n binary: function (request) {\n // TODO use fetch API for streaming if supported\n return loadXHR(request)\n },\n image: function (request) {\n return loadElement(request, document.createElement('img'))\n },\n video: function (request) {\n return loadElement(request, document.createElement('video'))\n },\n audio: function (request) {\n return loadElement(request, document.createElement('audio'))\n }\n }\n\n // First we parse all objects in order to verify that all type information\n // is correct\n var pending = Object.keys(manifest).map(function (name) {\n var request = manifest[name]\n if (typeof request === 'string') {\n request = {\n src: request\n }\n } else if (typeof request !== 'object' || !request) {\n raise('invalid asset definition \"' + name + '\"')\n }\n\n checkType(request, manifestParameters, 'asset \"' + name + '\"')\n\n function getParameter (prop, accepted, init) {\n var value = init\n if (prop in request) {\n value = request[prop]\n }\n if (accepted.indexOf(value) < 0) {\n raise('invalid ' + prop + ' \"' + value + '\" for asset \"' + name + '\", possible values: ' + accepted)\n }\n return value\n }\n\n function getString (prop, required, init) {\n var value = init\n if (prop in request) {\n value = request[prop]\n } else if (required) {\n raise('missing ' + prop + ' for asset \"' + name + '\"')\n }\n if (typeof value !== 'string') {\n raise('invalid ' + prop + ' for asset \"' + name + '\", must be a string')\n }\n return value\n }\n\n function getParseFunc (name, dflt) {\n if (name in request.parser) {\n var result = request.parser[name]\n if (typeof result !== 'function') {\n raise('invalid parser callback ' + name + ' for asset \"' + name + '\"')\n }\n return result\n } else {\n return dflt\n }\n }\n\n var parser = {}\n if ('parser' in request) {\n if (typeof request.parser === 'function') {\n parser = {\n data: request.parser\n }\n } else if (typeof request.parser === 'object' && request.parser) {\n checkType(parser, parserParameters, 'parser for asset \"' + name + '\"')\n if (!('onData' in parser)) {\n raise('missing onData callback for parser in asset \"' + name + '\"')\n }\n parser = {\n data: getParseFunc('onData'),\n done: getParseFunc('onDone')\n }\n } else {\n raise('invalid parser for asset \"' + name + '\"')\n }\n }\n\n return {\n name: name,\n type: getParameter('type', Object.keys(loaders), 'text'),\n stream: !!request.stream,\n credentials: !!request.credentials,\n src: getString('src', true, ''),\n parser: parser\n }\n }).map(function (request) {\n return (loaders[request.type])(request)\n })\n\n function abort (message) {\n if (state === STATE_ERROR || state === STATE_COMPLETE) {\n return\n }\n state = STATE_ERROR\n pending.forEach(function (loader) {\n loader.cancel()\n })\n if (onError) {\n if (typeof message === 'string') {\n onError(new Error('resl: ' + message))\n } else {\n onError(message)\n }\n } else {\n console.error('resl error:', message)\n }\n }\n\n function notifyProgress (message) {\n if (state === STATE_ERROR || state === STATE_COMPLETE) {\n return\n }\n\n var progress = 0\n var numReady = 0\n pending.forEach(function (loader) {\n if (loader.ready) {\n numReady += 1\n }\n progress += loader.progress\n })\n\n if (numReady === pending.length) {\n state = STATE_COMPLETE\n onDone(assets)\n } else {\n if (onProgress) {\n onProgress(progress / pending.length, message)\n }\n }\n }\n}\n",
"(function (undefined) {\n 'use strict';\n\n var OBJ = {};\n\n if (typeof module !== 'undefined') {\n module.exports = OBJ;\n } else {\n window.OBJ = OBJ;\n }\n\n /**\n * The main Mesh class. The constructor will parse through the OBJ file data\n * and collect the vertex, vertex normal, texture, and face information. This\n * information can then be used later on when creating your VBOs. See\n * OBJ.initMeshBuffers for an example of how to use the newly created Mesh\n *\n * @class Mesh\n * @constructor\n *\n * @param {String} objectData a string representation of an OBJ file with newlines preserved.\n */\n OBJ.Mesh = function (objectData) {\n /*\n The OBJ file format does a sort of compression when saving a model in a\n program like Blender. There are at least 3 sections (4 including textures)\n within the file. Each line in a section begins with the same string:\n * 'v': indicates vertex section\n * 'vn': indicates vertex normal section\n * 'f': indicates the faces section\n * 'vt': indicates vertex texture section (if textures were used on the model)\n Each of the above sections (except for the faces section) is a list/set of\n unique vertices.\n\n Each line of the faces section contains a list of\n (vertex, [texture], normal) groups\n Some examples:\n // the texture index is optional, both formats are possible for models\n // without a texture applied\n f 1/25 18/46 12/31\n f 1//25 18//46 12//31\n\n // A 3 vertex face with texture indices\n f 16/92/11 14/101/22 1/69/1\n\n // A 4 vertex face\n f 16/92/11 40/109/40 38/114/38 14/101/22\n\n The first two lines are examples of a 3 vertex face without a texture applied.\n The second is an example of a 3 vertex face with a texture applied.\n The third is an example of a 4 vertex face. Note: a face can contain N\n number of vertices.\n\n Each number that appears in one of the groups is a 1-based index\n corresponding to an item from the other sections (meaning that indexing\n starts at one and *not* zero).\n\n For example:\n `f 16/92/11` is saying to\n - take the 16th element from the [v] vertex array\n - take the 92nd element from the [vt] texture array\n - take the 11th element from the [vn] normal array\n and together they make a unique vertex.\n Using all 3+ unique Vertices from the face line will produce a polygon.\n\n Now, you could just go through the OBJ file and create a new vertex for\n each face line and WebGL will draw what appears to be the same model.\n However, vertices will be overlapped and duplicated all over the place.\n\n Consider a cube in 3D space centered about the origin and each side is\n 2 units long. The front face (with the positive Z-axis pointing towards\n you) would have a Top Right vertex (looking orthogonal to its normal)\n mapped at (1,1,1) The right face would have a Top Left vertex (looking\n orthogonal to its normal) at (1,1,1) and the top face would have a Bottom\n Right vertex (looking orthogonal to its normal) at (1,1,1). Each face\n has a vertex at the same coordinates, however, three distinct vertices\n will be drawn at the same spot.\n\n To solve the issue of duplicate Vertices (the `(vertex, [texture], normal)`\n groups), while iterating through the face lines, when a group is encountered\n the whole group string ('16/92/11') is checked to see if it exists in the\n packed.hashindices object, and if it doesn't, the indices it specifies\n are used to look up each attribute in the corresponding attribute arrays\n already created. The values are then copied to the corresponding unpacked\n array (flattened to play nice with WebGL's ELEMENT_ARRAY_BUFFER indexing),\n the group string is added to the hashindices set and the current unpacked\n index is used as this hashindices value so that the group of elements can\n be reused. The unpacked index is incremented. If the group string already\n exists in the hashindices object, its corresponding value is the index of\n that group and is appended to the unpacked indices array.\n */\n var verts = [], vertNormals = [], textures = [], unpacked = {};\n // unpacking stuff\n unpacked.verts = [];\n unpacked.norms = [];\n unpacked.textures = [];\n unpacked.hashindices = {};\n unpacked.indices = [];\n unpacked.index = 0;\n // array of lines separated by the newline\n var lines = objectData.split('\\n');\n \n var VERTEX_RE = /^v\\s/;\n var NORMAL_RE = /^vn\\s/;\n var TEXTURE_RE = /^vt\\s/;\n var FACE_RE = /^f\\s/;\n var WHITESPACE_RE = /\\s+/;\n \n for (var i = 0; i < lines.length; i++) {\n var line = lines[i].trim();\n var elements = line.split(WHITESPACE_RE);\n elements.shift();\n \n if (VERTEX_RE.test(line)) {\n // if this is a vertex\n verts.push.apply(verts, elements);\n } else if (NORMAL_RE.test(line)) {\n // if this is a vertex normal\n vertNormals.push.apply(vertNormals, elements);\n } else if (TEXTURE_RE.test(line)) {\n // if this is a texture\n textures.push.apply(textures, elements);\n } else if (FACE_RE.test(line)) {\n // if this is a face\n /*\n split this face into an array of vertex groups\n for example:\n f 16/92/11 14/101/22 1/69/1\n becomes:\n ['16/92/11', '14/101/22', '1/69/1'];\n */\n var quad = false;\n for (var j = 0, eleLen = elements.length; j < eleLen; j++){\n // Triangulating quads\n // quad: 'f v0/t0/vn0 v1/t1/vn1 v2/t2/vn2 v3/t3/vn3/'\n // corresponding triangles:\n // 'f v0/t0/vn0 v1/t1/vn1 v2/t2/vn2'\n // 'f v2/t2/vn2 v3/t3/vn3 v0/t0/vn0'\n if(j === 3 && !quad) {\n // add v2/t2/vn2 in again before continuing to 3\n j = 2;\n quad = true;\n }\n if(elements[j] in unpacked.hashindices){\n unpacked.indices.push(unpacked.hashindices[elements[j]]);\n }\n else{\n /*\n Each element of the face line array is a vertex which has its\n attributes delimited by a forward slash. This will separate\n each attribute into another array:\n '19/92/11'\n becomes:\n vertex = ['19', '92', '11'];\n where\n vertex[0] is the vertex index\n vertex[1] is the texture index\n vertex[2] is the normal index\n Think of faces having Vertices which are comprised of the\n attributes location (v), texture (vt), and normal (vn).\n */\n var vertex = elements[ j ].split( '/' );\n /*\n The verts, textures, and vertNormals arrays each contain a\n flattend array of coordinates.\n\n Because it gets confusing by referring to vertex and then\n vertex (both are different in my descriptions) I will explain\n what's going on using the vertexNormals array:\n\n vertex[2] will contain the one-based index of the vertexNormals\n section (vn). One is subtracted from this index number to play\n nice with javascript's zero-based array indexing.\n\n Because vertexNormal is a flattened array of x, y, z values,\n simple pointer arithmetic is used to skip to the start of the\n vertexNormal, then the offset is added to get the correct\n component: +0 is x, +1 is y, +2 is z.\n\n This same process is repeated for verts and textures.\n */\n // vertex position\n unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + 0]);\n unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + 1]);\n unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + 2]);\n // vertex textures\n if (textures.length) {\n unpacked.textures.push(+textures[(vertex[1] - 1) * 2 + 0]);\n unpacked.textures.push(+textures[(vertex[1] - 1) * 2 + 1]);\n }\n // vertex normals\n unpacked.norms.push(+vertNormals[(vertex[2] - 1) * 3 + 0]);\n unpacked.norms.push(+vertNormals[(vertex[2] - 1) * 3 + 1]);\n unpacked.norms.push(+vertNormals[(vertex[2] - 1) * 3 + 2]);\n // add the newly created vertex to the list of indices\n unpacked.hashindices[elements[j]] = unpacked.index;\n unpacked.indices.push(unpacked.index);\n // increment the counter\n unpacked.index += 1;\n }\n if(j === 3 && quad) {\n // add v0/t0/vn0 onto the second triangle\n unpacked.indices.push( unpacked.hashindices[elements[0]]);\n }\n }\n }\n }\n this.vertices = unpacked.verts;\n this.vertexNormals = unpacked.norms;\n this.textures = unpacked.textures;\n this.indices = unpacked.indices;\n }\n\n var Ajax = function(){\n // this is just a helper class to ease ajax calls\n var _this = this;\n this.xmlhttp = new XMLHttpRequest();\n\n this.get = function(url, callback){\n _this.xmlhttp.onreadystatechange = function(){\n if(_this.xmlhttp.readyState === 4){\n callback(_this.xmlhttp.responseText, _this.xmlhttp.status);\n }\n };\n _this.xmlhttp.open('GET', url, true);\n _this.xmlhttp.send();\n }\n };\n\n /**\n * Takes in an object of `mesh_name`, `'/url/to/OBJ/file'` pairs and a callback\n * function. Each OBJ file will be ajaxed in and automatically converted to\n * an OBJ.Mesh. When all files have successfully downloaded the callback\n * function provided will be called and passed in an object containing\n * the newly created meshes.\n *\n * **Note:** In order to use this function as a way to download meshes, a\n * webserver of some sort must be used.\n *\n * @param {Object} nameAndURLs an object where the key is the name of the mesh and the value is the url to that mesh's OBJ file\n *\n * @param {Function} completionCallback should contain a function that will take one parameter: an object array where the keys will be the unique object name and the value will be a Mesh object\n *\n * @param {Object} meshes In case other meshes are loaded separately or if a previously declared variable is desired to be used, pass in a (possibly empty) json object of the pattern: { '<mesh_name>': OBJ.Mesh }\n *\n */\n OBJ.downloadMeshes = function (nameAndURLs, completionCallback, meshes){\n // the total number of meshes. this is used to implement \"blocking\"\n var semaphore = Object.keys(nameAndURLs).length;\n // if error is true, an alert will given\n var error = false;\n // this is used to check if all meshes have been downloaded\n // if meshes is supplied, then it will be populated, otherwise\n // a new object is created. this will be passed into the completionCallback\n if(meshes === undefined) meshes = {};\n // loop over the mesh_name,url key,value pairs\n for(var mesh_name in nameAndURLs){\n if(nameAndURLs.hasOwnProperty(mesh_name)){\n new Ajax().get(nameAndURLs[mesh_name], (function(name) {\n return function (data, status) {\n if (status === 200) {\n meshes[name] = new OBJ.Mesh(data);\n }\n else {\n error = true;\n console.error('An error has occurred and the mesh \"' +\n name + '\" could not be downloaded.');\n }\n // the request has finished, decrement the counter\n semaphore--;\n if (semaphore === 0) {\n if (error) {\n // if an error has occurred, the user is notified here and the\n // callback is not called\n console.error('An error has occurred and one or meshes has not been ' +\n 'downloaded. The execution of the script has terminated.');\n throw '';\n }\n // there haven't been any errors in retrieving the meshes\n // call the callback\n completionCallback(meshes);\n }\n }\n })(mesh_name));\n }\n }\n };\n\n var _buildBuffer = function( gl, type, data, itemSize ){\n var buffer = gl.createBuffer();\n var arrayView = type === gl.ARRAY_BUFFER ? Float32Array : Uint16Array;\n gl.bindBuffer(type, buffer);\n gl.bufferData(type, new arrayView(data), gl.STATIC_DRAW);\n buffer.itemSize = itemSize;\n buffer.numItems = data.length / itemSize;\n return buffer;\n }\n\n /**\n * Takes in the WebGL context and a Mesh, then creates and appends the buffers\n * to the mesh object as attributes.\n *\n * @param {WebGLRenderingContext} gl the `canvas.getContext('webgl')` context instance\n * @param {Mesh} mesh a single `OBJ.Mesh` instance\n *\n * The newly created mesh attributes are:\n *\n * Attrbute | Description\n * :--- | ---\n * **normalBuffer** |contains the model's Vertex Normals\n * normalBuffer.itemSize |set to 3 items\n * normalBuffer.numItems |the total number of vertex normals\n * |\n * **textureBuffer** |contains the model's Texture Coordinates\n * textureBuffer.itemSize |set to 2 items\n * textureBuffer.numItems |the number of texture coordinates\n * |\n * **vertexBuffer** |contains the model's Vertex Position Coordinates (does not include w)\n * vertexBuffer.itemSize |set to 3 items\n * vertexBuffer.numItems |the total number of vertices\n * |\n * **indexBuffer** |contains the indices of the faces\n * indexBuffer.itemSize |is set to 1\n * indexBuffer.numItems |the total number of indices\n *\n * A simple example (a lot of steps are missing, so don't copy and paste):\n *\n * var gl = canvas.getContext('webgl'),\n * mesh = OBJ.Mesh(obj_file_data);\n * // compile the shaders and create a shader program\n * var shaderProgram = gl.createProgram();\n * // compilation stuff here\n * ...\n * // make sure you have vertex, vertex normal, and texture coordinate\n * // attributes located in your shaders and attach them to the shader program\n * shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, \"aVertexPosition\");\n * gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);\n *\n * shaderProgram.vertexNormalAttribute = gl.getAttribLocation(shaderProgram, \"aVertexNormal\");\n * gl.enableVertexAttribArray(shaderProgram.vertexNormalAttribute);\n *\n * shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, \"aTextureCoord\");\n * gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);\n *\n * // create and initialize the vertex, vertex normal, and texture coordinate buffers\n * // and save on to the mesh object\n * OBJ.initMeshBuffers(gl, mesh);\n *\n * // now to render the mesh\n * gl.bindBuffer(gl.ARRAY_BUFFER, mesh.vertexBuffer);\n * gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, mesh.vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);\n *\n * gl.bindBuffer(gl.ARRAY_BUFFER, mesh.textureBuffer);\n * gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, mesh.textureBuffer.itemSize, gl.FLOAT, false, 0, 0);\n *\n * gl.bindBuffer(gl.ARRAY_BUFFER, mesh.normalBuffer);\n * gl.vertexAttribPointer(shaderProgram.vertexNormalAttribute, mesh.normalBuffer.itemSize, gl.FLOAT, false, 0, 0);\n *\n * gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, model.mesh.indexBuffer);\n * gl.drawElements(gl.TRIANGLES, model.mesh.indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);\n */\n OBJ.initMeshBuffers = function( gl, mesh ){\n mesh.normalBuffer = _buildBuffer(gl, gl.ARRAY_BUFFER, mesh.vertexNormals, 3);\n mesh.textureBuffer = _buildBuffer(gl, gl.ARRAY_BUFFER, mesh.textures, 2);\n mesh.vertexBuffer = _buildBuffer(gl, gl.ARRAY_BUFFER, mesh.vertices, 3);\n mesh.indexBuffer = _buildBuffer(gl, gl.ELEMENT_ARRAY_BUFFER, mesh.indices, 1);\n }\n\n OBJ.deleteMeshBuffers = function( gl, mesh ){\n gl.deleteBuffer(mesh.normalBuffer);\n gl.deleteBuffer(mesh.textureBuffer);\n gl.deleteBuffer(mesh.vertexBuffer);\n gl.deleteBuffer(mesh.indexBuffer);\n }\n})();\n\n",
"const glm = require('gl-matrix')\n\nvar position = { x: 0, y: 0, z: 0 }\nvar rotation = { x: 0, y: 0, z: 0 }\n\nconst getPosition = (a) => (!a?position:[position.x, position.y, position.z])\nconst setPosition = (x, y, z) => position = { x, y, z }\n\nconst getRotation = () => rotation\nconst setRotation = (x, y, z) => rotation = { x, y, z }\n\nconst move = (x, y, z) => {\n var dx = x, dy = y, dz = z\n\n if (dx !== 0) dx /= dx\n if (dy !== 0) dy /= dy\n if (dz !== 0) dz /= dz\n\n var distance = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2) + Math.pow(dz, 2)) || 1\n\n position.x += dx / distance * x\n position.y += dy / distance * y\n position.z += dz / distance * z\n}\n\nconst rotate = (x, y, z) => {\n rotation.x += x\n rotation.y += y\n rotation.z += z\n}\n\nconst viewMatrix = () => {\n var matrix = new Float32Array(16)\n glm.mat4.identity(matrix)\n glm.mat4.rotate(matrix, matrix, glm.glMatrix.toRadian(getRotation().x), [1, 0, 0])\n glm.mat4.rotate(matrix, matrix, glm.glMatrix.toRadian(getRotation().y), [0, 1, 0])\n glm.mat4.rotate(matrix, matrix, glm.glMatrix.toRadian(getRotation().z), [0, 0, 1])\n glm.mat4.translate(matrix, matrix, [-getPosition().x, -getPosition().y, -getPosition().z])\n return matrix\n}\n\nmodule.exports = {getPosition, setPosition, getRotation, setRotation, move, rotate, viewMatrix}\n",
"const glm = require('gl-matrix')\nconst ray = require('./projection.js')\n\nmodule.exports = (regl) => (mesh, shader, texture, camera, position, rotation, scale) => {\n var color = [1, 1, 1, 1]\n var tiling = [1, 1]\n\n const getFlippedUVs = () => {\n var uvs = []\n for (let i = 0; i < mesh.textures.length; i ++) {\n if (i % 2 === 0) {\n uvs.push(mesh.textures[i])\n } else {\n uvs.push(1 - mesh.textures[i])\n }\n }\n return uvs\n }\n\n const getPosition = () => position\n const setPosition = (x, y, z) => position = { x, y, z }\n\n const getColor = () => color\n const setColor = (r, g, b, a) => color = [r, g, b, a]\n\n const getTexture = () => texture\n const setTexture = (value) => texture = texture\n\n const getTiling = () => tiling\n const setTiling = (x, y) => tiling = [x, y]\n\n const getTransform = () => {\n var matrix = new Float32Array(16)\n glm.mat4.identity(matrix)\n glm.mat4.translate(matrix, matrix, [position.x, position.y, position.z])\n glm.mat4.rotate(matrix, matrix, glm.glMatrix.toRadian(rotation.x), [1, 0, 0])\n glm.mat4.rotate(matrix, matrix, glm.glMatrix.toRadian(rotation.y), [0, 1, 0])\n glm.mat4.rotate(matrix, matrix, glm.glMatrix.toRadian(rotation.z), [0, 0, 1])\n glm.mat4.scale(matrix, matrix, [scale, scale, scale])\n return matrix\n }\n\n const draw = regl({\n frag: shader.fragment,\n vert: shader.vertex,\n attributes: {\n position: mesh.vertices,\n uv: getFlippedUVs\n },\n elements: mesh.indices,\n uniforms: {\n transform: getTransform,\n view: camera.viewMatrix,\n projection: projection,\n ambientlight: [.2, .2, .2],\n light_pos: [5, 3, 5],\n light_color: [.5, .5, 0],\n light_radius: 2,\n light_intensity: 2,\n sampler: getTexture,\n color: getColor,\n tiling: getTiling\n },\n cull: {\n enable: true,\n face: 'back'\n }\n })\n return { getPosition, setPosition, getColor, setColor, getTiling, setTiling, draw }\n}\n",
"window.regl = require('regl')()\nwindow.glm = require('gl-matrix')\nwindow.obj = require('webgl-obj-loader')\n\n// My Modules\nwindow.screen = require('./screen.js')\nwindow.projection = require('./projection.js')\nwindow.camera = require('./camera.js')\nwindow.ray = require('./ray.js')\nwindow.picker = require('./picker.js')\nwindow.createEntity = require('./entity.js')(regl)\nwindow.createShader = require('./shader.js')\n\nconst width = 11\nconst height = 5\nconst length = 11\n\nconst map = [...Array(width)].map(x => [...Array(height)].map( x => Array(length)))\n\nlet zoom = 10\n\nlet player\n\nvar cubeModel\nvar cubeShader\nvar cubeTexture\n\nfor (let x = 0; x < width; x++) {\n for (let y = 0; y < height; y++) {\n for (let z = 0; z < length; z++) {\n var type = 0\n\n if (x === 7 && y === 1 && z === 5) type = 1\n\n if (x === 3 && y === 1 && z === 1) type = 1\n\n if (x === 2 && y === 1 && z === 1) type = 1\n\n if (x === 2 && y === 2 && z === 1) type = 1\n\n if (x === 2 && y === 1 && z === 2) type = 1\n\n if (x === 5 && y === 1 && z === 5) type = 2\n\n if (x === 2 && y === 1 && z === 7) type = 3\n\n if (x === 8 && y === 1 && z === 7) type = 3\n\n if (x === 9 && y === 1 && z === 7) type = 3\n\n map[x][y][z] = type\n }\n }\n}\n\nrequire('resl')({\n manifest: {\n atlas: {\n type: 'image',\n src: 'textures/Atlas.png',\n parser: (data) => regl.texture({\n data: data,\n mag: 'linear',\n min: 'linear',\n wrapS: 'repeat',\n wrapT: 'repeat'\n })\n },\n cubeObj: {\n \ttype: \"text\",\n \tsrc: 'models/cube.obj',\n \tparser: (data) => new obj.Mesh(data)\n },\n entityShader: {\n type: \"text\",\n src: 'shaders/entity.glsl',\n parser: (data) => createShader(data)\n },\n lampObj: {\n type: \"text\",\n src: 'models/Lamp.obj',\n parser: (data) => new obj.Mesh(data)\n },\n lampTex: {\n type: 'image',\n src: 'textures/Lamp.png',\n parser: (data) => regl.texture({\n data: data,\n mag: 'linear',\n min: 'linear'\n })\n },\n planeObj: {\n type: \"text\",\n src: 'models/plane.obj',\n parser: (data) => new obj.Mesh(data)\n },\n planeTex: {\n type: 'image',\n src: 'textures/Mud.png',\n parser: (data) => regl.texture({\n data: data,\n mag: 'linear',\n min: 'linear',\n wrapS: 'repeat',\n wrapT: 'repeat'\n })\n },\n treeObj: {\n type: \"text\",\n src: 'models/Tree.obj',\n parser: (data) => new obj.Mesh(data)\n },\n treeTex: {\n type: 'image',\n src: 'textures/Tree.png',\n parser: (data) => regl.texture({\n data: data,\n mag: 'linear',\n min: 'linear'\n })\n },\n },\n onDone: ({atlas, cubeObj, entityShader, planeObj, planeTex, lampObj, lampTex, treeObj, treeTex}) => {\n window.entities = []\n\n cubeModel = cubeObj\n cubeTexture = atlas\n cubeShader = entityShader\n\n camera.setPosition(width / 2, 5, length * 2)\n camera.setRotation(10, 0, 0)\n\n { // Creating the ground plane\n const position = { x: width / 2, y: .5, z: length / 2 }\n const rotation = { x: 0, y: 0, z: 0 }\n const scale = 15\n const plane = createEntity(planeObj, entityShader, planeTex, camera, position, rotation, scale)\n plane.setTiling(6, 6)\n entities.push(plane)\n }\n\n { // Creating the Player\n const position = { x: 5, y: 1, z: 10 }\n const rotation = { x: 0, y: 0, z: 0 }\n const scale = 1\n player = createEntity(cubeObj, entityShader, treeTex, camera, position, rotation, scale)\n player.setColor(100, 0, 0, .5)\n entities.push(player)\n }\n\n for (let x = 0; x < width; x++) {\n for (let y = 0; y < height; y++) {\n for (let z = 0; z < length; z++) {\n var type = map[x][y][z]\n if (type > 0) {\n let model = cubeObj\n let shader = entityShader\n let texture = atlas\n let scale = 1\n const position = { x: x, y: y, z: z }\n const rotation = { x: 0, y: 0, z: 0}\n\n if (type === 2) {\n model = lampObj\n texture = lampTex\n position.y -= 0.5\n scale = .2\n }\n\n if (type === 3) {\n model = treeObj\n texture = treeTex\n position.y -= .5\n }\n\n var entity = createEntity(model, shader, texture, camera, position, rotation, scale)\n entities.push(entity)\n }\n }\n }\n }\n\n regl.frame(() => {\n regl.clear({\n color: [.2, .2, .2, 255],\n depth: 1\n })\n\n {\n var rotation = camera.getRotation()\n\n var input = { x: 0, y: 0, z: 0 }\n\n if (screen.iskeypressed('ArrowRight')) input.x += 0.05\n if (screen.iskeypressed('ArrowLeft')) input.x -= 0.05\n if (screen.iskeypressed('Space')) input.y += 0.05\n if (screen.iskeypressed('ShiftLeft')) input.y -= 0.05\n if (screen.iskeypressed('ShiftRight')) input.y -= 0.05\n if (screen.iskeypressed('ArrowUp')) input.z -= 0.05\n if (screen.iskeypressed('ArrowDown')) input.z += 0.05\n\n var movement = { x: 0, y: 0, z: 0 }\n\n movement.x += input.x * Math.sin(glm.glMatrix.toRadian(rotation.y + 90));\n movement.z -= input.x * Math.cos(glm.glMatrix.toRadian(rotation.y + 90));\n\n movement.y = input.y;\n\n movement.x -= input.z * Math.sin(glm.glMatrix.toRadian(rotation.y));\n movement.z += input.z * Math.cos(glm.glMatrix.toRadian(rotation.y));\n\n camera.move(movement.x, movement.y, movement.z)\n }\n\n {\n let screenX = window.innerWidth / 2\n let screenY = window.innerHeight / 2\n\n let camPos = [\n camera.getPosition().x,\n camera.getPosition().y,\n camera.getPosition().z\n ]\n\n let worldRay = picker.screenToWorldRay(camPos, screenX, screenY, 20)\n\n let pos = {\n x: Math.round(worldRay.getOrigin()[0] + worldRay.getPoint(zoom)[0]),\n y: Math.round(worldRay.getOrigin()[1] + worldRay.getPoint(zoom)[1]),\n z: Math.round(worldRay.getOrigin()[2] + worldRay.getPoint(zoom)[2])\n }\n\n player.setPosition(pos.x, pos.y, pos.z)\n }\n\n for (let i = 0; i < entities.length; i++) {\n entities[i].draw()\n }\n })\n }\n})\n\nscreen.onmousemove((event) => {\n camera.rotate(event.movementY * 0.1, event.movementX * 0.1, 0)\n})\n\nscreen.onwheel((event) => {\n zoom += event.deltaY * 0.05\n if (zoom < 5) zoom = 5\n if (zoom > 20) zoom = 20\n})\n\nscreen.onclick((event) => {\n\n let screenX = window.innerWidth / 2\n let screenY = window.innerHeight / 2\n\n let camPos = [\n camera.getPosition().x,\n camera.getPosition().y,\n camera.getPosition().z\n ]\n\n let worldRay = picker.screenToWorldRay(camPos, screenX, screenY, 20)\n\n let pos = {\n x: Math.round(worldRay.getOrigin()[0] + worldRay.getPoint(zoom)[0]),\n y: Math.round(worldRay.getOrigin()[1] + worldRay.getPoint(zoom)[1]),\n z: Math.round(worldRay.getOrigin()[2] + worldRay.getPoint(zoom)[2])\n }\n\n\n const rotation = { x: 0, y: 0, z: 0}\n let scale = 1\n var entity = createEntity(cubeModel, cubeShader, cubeTexture, camera, pos, rotation, scale)\n entities.push(entity)\n})\n",
"const glm = require('gl-matrix')\nconst ray = require('./ray.js')\n\nconst toNormailizedDeviceSpace = (x, y) => {\n var w = window.innerWidth\n var h = window.innerHeight\n let normalizedDeviceCoords = glm.vec3.create()\n normalizedDeviceCoords[0] = x / w * 2 - 1\n normalizedDeviceCoords[1] = y / h * 2 - 1\n normalizedDeviceCoords[2] = -1\n return normalizedDeviceCoords\n}\n\nconst toClipSpace = (normalizedDeviceCoords) => {\n let clipCoords = glm.vec4.create()\n clipCoords[0] = normalizedDeviceCoords[0]\n clipCoords[1] = normalizedDeviceCoords[1]\n clipCoords[2] = normalizedDeviceCoords[2]\n clipCoords[3] = -normalizedDeviceCoords[2]\n return clipCoords\n}\n\nconst toEyeSpace = (clipCoords) => {\n let eyeCoords = glm.vec4.create()\n let invertedProjection = glm.mat4.create()\n glm.mat4.invert(invertedProjection, projection())\n glm.mat4.multiply(eyeCoords, invertedProjection, clipCoords)\n eyeCoords[3] = 0\n return eyeCoords\n}\n\nconst toWorldSpace = (eyeCoords) => {\n let worldCoords = glm.vec4.create()\n let invertedView = glm.mat4.create()\n glm.mat4.invert(invertedView, camera.viewMatrix())\n glm.mat4.multiply(worldCoords, invertedView, eyeCoords)\n return worldCoords\n}\n\nconst screenToWorldVector = (x, y) => {\n let normalizedCoords = toNormailizedDeviceSpace(x, y)\n let clipCoords = toClipSpace(normalizedCoords)\n let eyeCoords = toEyeSpace(clipCoords)\n let worldCoords = toWorldSpace(eyeCoords)\n\n let worldVector = glm.vec3.create()\n worldVector[0] = worldCoords[0]\n worldVector[1] = worldCoords[1]\n worldVector[2] = worldCoords[2]\n glm.vec3.normalize(worldVector, worldVector)\n return worldVector\n}\n\nconst screenToWorldRay = (camPos, x, y, length) => {\n let worldVector = screenToWorldVector(x, y)\n\n let worldRay = ray.create(camPos, worldVector, length)\n\n return worldRay\n}\n\nmodule.exports = { screenToWorldVector, screenToWorldRay }\n",
"const glm = require('gl-matrix')\n\nmodule.exports = () => {\n var matrix = new Float32Array(16)\n var fovy = glm.glMatrix.toRadian(45)\n var aspect = window.innerWidth / window.innerHeight\n var near = 0.1\n var far = 1000.0\n glm.mat4.perspective(matrix, fovy, aspect, near, far)\n return matrix\n}\n",
"const glm = require('gl-matrix')\n\nconst create = (origin, direction, distance) => {\n const getOrigin = () => origin\n const getDirection = () => direction\n const getDistance = () => distance\n\n const getPoint = (m) => {\n return [\n direction[0] * m,\n direction[1] * m,\n direction[2] * m\n ]\n }\n\n const getX = (x) => {\n var d = x / direction[0]\n return [\n direction[0] * d,\n direction[1] * d,\n direction[2] * d\n ]\n }\n\n const getY = (y) => {\n var d = y / direction[1]\n return [\n direction[0] * d,\n direction[1] * d,\n direction[2] * d\n ]\n }\n\n const getZ = (z) => {\n var d = z / direction[2]\n return [\n direction[0] * d,\n direction[1] * d,\n direction[2] * d\n ]\n }\n\n return { getOrigin, getDirection, getDistance, getPoint, getX, getY, getZ }\n}\n\nconst textRayOBBIntersection = (ray, aabb_min, aabb_max, transformMatrix) => {\n var tMin = 0.0\n var tMax = ray.getDistance()\n\n var OBBposition_worldspace = glm.vec3.create()\n glm.mat4.getTranslation(OBBposition_worldspace, transformMatrix)\n\n var delta = glm.vec3.create()\n glm.vec3.substract(delta, OBBposition_worldspace, ray.getOrigin())\n\n// // Test intersection with the 2 planes perpendicular to the OBB's X axis\n// {\n// glm::vec3 xaxis(ModelMatrix[0].x, ModelMatrix[0].y, ModelMatrix[0].z);\n// float e = glm::dot(xaxis, delta);\n// float f = glm::dot(ray.getDirection(), xaxis);\n//\n// if ( fabs(f) > 0.001f ){ // Standard case\n//\n// float t1 = (e+aabb_min.x)/f; // Intersection with the \"left\" plane\n// float t2 = (e+aabb_max.x)/f; // Intersection with the \"right\" plane\n// // t1 and t2 now contain distances betwen ray origin and ray-plane intersections\n//\n// // We want t1 to represent the nearest intersection,\n// // so if it's not the case, invert t1 and t2\n// if (t1>t2){\n// float w=t1;t1=t2;t2=w; // swap t1 and t2\n// }\n//\n// // tMax is the nearest \"far\" intersection (amongst the X,Y and Z planes pairs)\n// if ( t2 < tMax )\n// tMax = t2;\n// // tMin is the farthest \"near\" intersection (amongst the X,Y and Z planes pairs)\n// if ( t1 > tMin )\n// tMin = t1;\n//\n// // And here's the trick :\n// // If \"far\" is closer than \"near\", then there is NO intersection.\n// // See the images in the tutorials for the visual explanation.\n// if (tMax < tMin )\n// return false;\n//\n// }else{ // Rare case : the ray is almost parallel to the planes, so they don't have any \"intersection\"\n// if(-e+aabb_min.x > 0.0f || -e+aabb_max.x < 0.0f)\n// return false;\n// }\n// }\n//\n//\n// // Test intersection with the 2 planes perpendicular to the OBB's Y axis\n// // Exactly the same thing than above.\n// {\n// glm::vec3 yaxis(ModelMatrix[1].x, ModelMatrix[1].y, ModelMatrix[1].z);\n// float e = glm::dot(yaxis, delta);\n// float f = glm::dot(ray.getDirection(), yaxis);\n//\n// if ( fabs(f) > 0.001f ){\n//\n// float t1 = (e+aabb_min.y)/f;\n// float t2 = (e+aabb_max.y)/f;\n//\n// if (t1>t2){float w=t1;t1=t2;t2=w;}\n//\n// if ( t2 < tMax )\n// tMax = t2;\n// if ( t1 > tMin )\n// tMin = t1;\n// if (tMin > tMax)\n// return false;\n//\n// }else{\n// if(-e+aabb_min.y > 0.0f || -e+aabb_max.y < 0.0f)\n// return false;\n// }\n// }\n//\n//\n// // Test intersection with the 2 planes perpendicular to the OBB's Z axis\n// // Exactly the same thing than above.\n// {\n// glm::vec3 zaxis(ModelMatrix[2].x, ModelMatrix[2].y, ModelMatrix[2].z);\n// float e = glm::dot(zaxis, delta);\n// float f = glm::dot(ray.getDirection(), zaxis);\n//\n// if ( fabs(f) > 0.001f ){\n//\n// float t1 = (e+aabb_min.z)/f;\n// float t2 = (e+aabb_max.z)/f;\n//\n// if (t1>t2){float w=t1;t1=t2;t2=w;}\n//\n// if ( t2 < tMax )\n// tMax = t2;\n// if ( t1 > tMin )\n// tMin = t1;\n// if (tMin > tMax)\n// return false;\n//\n// }else{\n// if(-e+aabb_min.z > 0.0f || -e+aabb_max.z < 0.0f)\n// return false;\n// }\n// }\n//\n// // intersection_distance = tMin;\n return true;\n}\n\nmodule.exports = { create, textRayOBBIntersection }\n",
"const canvas = document.querySelector('canvas')\n\nconst pointerIsLocked = function () {\n var element = document.pointerLockElement || document.mozPointerLockElement\n return element === canvas\n}\n\nconst lockPointer = function () {\n canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock\n document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock\n canvas.requestPointerLock()\n}\n\ncanvas.onclick = function() {\n lockPointer()\n}\n\nvar keys = []\n\ndocument.onkeydown = function (event) {\n if (pointerIsLocked()) {\n if (keys.indexOf(event.code) === -1) {\n keys.push(event.code)\n }\n }\n}\n\ndocument.onkeyup = function (event) {\n if (pointerIsLocked()) {\n if (keys.indexOf(event.code) > -1) {\n keys.splice(keys.indexOf(event.code), 1)\n }\n }\n}\n\nconst iskeypressed = function (keyCode) {\n if (pointerIsLocked()) {\n return (keys.indexOf(keyCode) > -1)\n } else {\n keys = []\n }\n}\n\nconst onmousemove = function (callback) {\n document.onmousemove = function (event) {\n if (pointerIsLocked()) {\n callback(event)\n }\n }\n}\n\nconst onclick = function (callback) {\n document.onclick = function (event) {\n if (pointerIsLocked()) {\n callback(event)\n } else {\n lockPointer()\n }\n }\n}\n\nconst onwheel = function (callback) {\n document.onwheel = function (event) {\n if (pointerIsLocked()) {\n callback(event)\n }\n event.preventDefault()\n }\n}\n\nmodule.exports = {\n canvas: canvas,\n pointerIsLocked: pointerIsLocked,\n lockPointer: lockPointer,\n iskeypressed: iskeypressed,\n onmousemove: onmousemove,\n onclick: onclick,\n onwheel: onwheel\n}\n",
"module.exports = (data) => {\n const vertex = data.split('[vertex]\\n')[1].split('\\n[fragment]')[0]\n const fragment = data.split('[fragment]\\n')[1]\n return { vertex, fragment }\n}\n"
]
}