matrix-engine-wgpu 1.3.13 → 1.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/readme.md +23 -0
- package/src/engine/ball.js +0 -482
- package/src/engine/cube.js +0 -496
- package/src/engine/engine.js +0 -476
- package/src/engine/final/adaptJSON1.js +0 -53
- package/src/engine/final/utils2.js +0 -63
- package/src/engine/lights.js +0 -126
- package/src/engine/loader-obj.js +0 -473
- package/src/engine/materials.js +0 -307
- package/src/engine/matrix-class.js +0 -252
- package/src/engine/mesh-obj.js +0 -553
- package/src/engine/mesh.js +0 -475
- package/src/engine/raycast.js +0 -219
- package/src/engine/utils.js +0 -881
- package/src/libs/mat.js +0 -0
- package/src/multilang/lang.js +0 -35
- package/src/physics/matrix-ammo.js +0 -361
- package/src/shaders/fragment.video.wgsl.js +0 -83
- package/src/shaders/fragment.wgsl.js +0 -75
- package/src/shaders/shaders.js +0 -51
- package/src/shaders/standard-matrix-engine-shaders/standard-matrix-engine-fs.glsl +0 -56
- package/src/shaders/standard-matrix-engine-shaders/standard-matrix-engine-vs.glsl +0 -75
- package/src/shaders/vertex.wgsl.js +0 -49
- package/src/shaders/vertexShadow.wgsl.js +0 -20
- package/src/sounds/sounds.js +0 -69
- package/src/world.js +0 -427
package/src/engine/utils.js
DELETED
|
@@ -1,881 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export const vec3 = {
|
|
3
|
-
cross(a, b, dst) {
|
|
4
|
-
dst = dst || new Float32Array(3);
|
|
5
|
-
|
|
6
|
-
const t0 = a[1] * b[2] - a[2] * b[1];
|
|
7
|
-
const t1 = a[2] * b[0] - a[0] * b[2];
|
|
8
|
-
const t2 = a[0] * b[1] - a[1] * b[0];
|
|
9
|
-
|
|
10
|
-
dst[0] = t0;
|
|
11
|
-
dst[1] = t1;
|
|
12
|
-
dst[2] = t2;
|
|
13
|
-
|
|
14
|
-
return dst;
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
subtract(a, b, dst) {
|
|
18
|
-
dst = dst || new Float32Array(3);
|
|
19
|
-
|
|
20
|
-
dst[0] = a[0] - b[0];
|
|
21
|
-
dst[1] = a[1] - b[1];
|
|
22
|
-
dst[2] = a[2] - b[2];
|
|
23
|
-
|
|
24
|
-
return dst;
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
normalize(v, dst) {
|
|
28
|
-
dst = dst || new Float32Array(3);
|
|
29
|
-
|
|
30
|
-
const length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
|
31
|
-
// make sure we don't divide by 0.
|
|
32
|
-
if(length > 0.00001) {
|
|
33
|
-
dst[0] = v[0] / length;
|
|
34
|
-
dst[1] = v[1] / length;
|
|
35
|
-
dst[2] = v[2] / length;
|
|
36
|
-
} else {
|
|
37
|
-
dst[0] = 0;
|
|
38
|
-
dst[1] = 0;
|
|
39
|
-
dst[2] = 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return dst;
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const mat4 = {
|
|
47
|
-
projection(width, height, depth, dst) {
|
|
48
|
-
// Note: This matrix flips the Y axis so that 0 is at the top.
|
|
49
|
-
return mat4.ortho(0, width, height, 0, depth, -depth, dst);
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {
|
|
53
|
-
dst = dst || new Float32Array(16);
|
|
54
|
-
|
|
55
|
-
const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);
|
|
56
|
-
const rangeInv = 1 / (zNear - zFar);
|
|
57
|
-
|
|
58
|
-
dst[0] = f / aspect;
|
|
59
|
-
dst[1] = 0;
|
|
60
|
-
dst[2] = 0;
|
|
61
|
-
dst[3] = 0;
|
|
62
|
-
|
|
63
|
-
dst[4] = 0;
|
|
64
|
-
dst[5] = f;
|
|
65
|
-
dst[6] = 0;
|
|
66
|
-
dst[7] = 0;
|
|
67
|
-
|
|
68
|
-
dst[8] = 0;
|
|
69
|
-
dst[9] = 0;
|
|
70
|
-
dst[10] = zFar * rangeInv;
|
|
71
|
-
dst[11] = -1;
|
|
72
|
-
|
|
73
|
-
dst[12] = 0;
|
|
74
|
-
dst[13] = 0;
|
|
75
|
-
dst[14] = zNear * zFar * rangeInv;
|
|
76
|
-
dst[15] = 0;
|
|
77
|
-
|
|
78
|
-
return dst;
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
ortho(left, right, bottom, top, near, far, dst) {
|
|
82
|
-
dst = dst || new Float32Array(16);
|
|
83
|
-
|
|
84
|
-
dst[0] = 2 / (right - left);
|
|
85
|
-
dst[1] = 0;
|
|
86
|
-
dst[2] = 0;
|
|
87
|
-
dst[3] = 0;
|
|
88
|
-
|
|
89
|
-
dst[4] = 0;
|
|
90
|
-
dst[5] = 2 / (top - bottom);
|
|
91
|
-
dst[6] = 0;
|
|
92
|
-
dst[7] = 0;
|
|
93
|
-
|
|
94
|
-
dst[8] = 0;
|
|
95
|
-
dst[9] = 0;
|
|
96
|
-
dst[10] = 1 / (near - far);
|
|
97
|
-
dst[11] = 0;
|
|
98
|
-
|
|
99
|
-
dst[12] = (right + left) / (left - right);
|
|
100
|
-
dst[13] = (top + bottom) / (bottom - top);
|
|
101
|
-
dst[14] = near / (near - far);
|
|
102
|
-
dst[15] = 1;
|
|
103
|
-
|
|
104
|
-
return dst;
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
identity(dst) {
|
|
108
|
-
dst = dst || new Float32Array(16);
|
|
109
|
-
dst[0] = 1; dst[1] = 0; dst[2] = 0; dst[3] = 0;
|
|
110
|
-
dst[4] = 0; dst[5] = 1; dst[6] = 0; dst[7] = 0;
|
|
111
|
-
dst[8] = 0; dst[9] = 0; dst[10] = 1; dst[11] = 0;
|
|
112
|
-
dst[12] = 0; dst[13] = 0; dst[14] = 0; dst[15] = 1;
|
|
113
|
-
return dst;
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
multiply(a, b, dst) {
|
|
117
|
-
dst = dst || new Float32Array(16);
|
|
118
|
-
const b00 = b[0 * 4 + 0];
|
|
119
|
-
const b01 = b[0 * 4 + 1];
|
|
120
|
-
const b02 = b[0 * 4 + 2];
|
|
121
|
-
const b03 = b[0 * 4 + 3];
|
|
122
|
-
const b10 = b[1 * 4 + 0];
|
|
123
|
-
const b11 = b[1 * 4 + 1];
|
|
124
|
-
const b12 = b[1 * 4 + 2];
|
|
125
|
-
const b13 = b[1 * 4 + 3];
|
|
126
|
-
const b20 = b[2 * 4 + 0];
|
|
127
|
-
const b21 = b[2 * 4 + 1];
|
|
128
|
-
const b22 = b[2 * 4 + 2];
|
|
129
|
-
const b23 = b[2 * 4 + 3];
|
|
130
|
-
const b30 = b[3 * 4 + 0];
|
|
131
|
-
const b31 = b[3 * 4 + 1];
|
|
132
|
-
const b32 = b[3 * 4 + 2];
|
|
133
|
-
const b33 = b[3 * 4 + 3];
|
|
134
|
-
const a00 = a[0 * 4 + 0];
|
|
135
|
-
const a01 = a[0 * 4 + 1];
|
|
136
|
-
const a02 = a[0 * 4 + 2];
|
|
137
|
-
const a03 = a[0 * 4 + 3];
|
|
138
|
-
const a10 = a[1 * 4 + 0];
|
|
139
|
-
const a11 = a[1 * 4 + 1];
|
|
140
|
-
const a12 = a[1 * 4 + 2];
|
|
141
|
-
const a13 = a[1 * 4 + 3];
|
|
142
|
-
const a20 = a[2 * 4 + 0];
|
|
143
|
-
const a21 = a[2 * 4 + 1];
|
|
144
|
-
const a22 = a[2 * 4 + 2];
|
|
145
|
-
const a23 = a[2 * 4 + 3];
|
|
146
|
-
const a30 = a[3 * 4 + 0];
|
|
147
|
-
const a31 = a[3 * 4 + 1];
|
|
148
|
-
const a32 = a[3 * 4 + 2];
|
|
149
|
-
const a33 = a[3 * 4 + 3];
|
|
150
|
-
|
|
151
|
-
dst[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30;
|
|
152
|
-
dst[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31;
|
|
153
|
-
dst[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32;
|
|
154
|
-
dst[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33;
|
|
155
|
-
|
|
156
|
-
dst[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30;
|
|
157
|
-
dst[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31;
|
|
158
|
-
dst[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32;
|
|
159
|
-
dst[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33;
|
|
160
|
-
|
|
161
|
-
dst[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30;
|
|
162
|
-
dst[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31;
|
|
163
|
-
dst[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32;
|
|
164
|
-
dst[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33;
|
|
165
|
-
|
|
166
|
-
dst[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30;
|
|
167
|
-
dst[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31;
|
|
168
|
-
dst[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32;
|
|
169
|
-
dst[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33;
|
|
170
|
-
|
|
171
|
-
return dst;
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
cameraAim(eye, target, up, dst) {
|
|
175
|
-
dst = dst || new Float32Array(16);
|
|
176
|
-
|
|
177
|
-
const zAxis = vec3.normalize(vec3.subtract(eye, target));
|
|
178
|
-
const xAxis = vec3.normalize(vec3.cross(up, zAxis));
|
|
179
|
-
const yAxis = vec3.normalize(vec3.cross(zAxis, xAxis));
|
|
180
|
-
|
|
181
|
-
dst[0] = xAxis[0]; dst[1] = xAxis[1]; dst[2] = xAxis[2]; dst[3] = 0;
|
|
182
|
-
dst[4] = yAxis[0]; dst[5] = yAxis[1]; dst[6] = yAxis[2]; dst[7] = 0;
|
|
183
|
-
dst[8] = zAxis[0]; dst[9] = zAxis[1]; dst[10] = zAxis[2]; dst[11] = 0;
|
|
184
|
-
dst[12] = eye[0]; dst[13] = eye[1]; dst[14] = eye[2]; dst[15] = 1;
|
|
185
|
-
|
|
186
|
-
return dst;
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
inverse(m, dst) {
|
|
190
|
-
dst = dst || new Float32Array(16);
|
|
191
|
-
|
|
192
|
-
const m00 = m[0 * 4 + 0];
|
|
193
|
-
const m01 = m[0 * 4 + 1];
|
|
194
|
-
const m02 = m[0 * 4 + 2];
|
|
195
|
-
const m03 = m[0 * 4 + 3];
|
|
196
|
-
const m10 = m[1 * 4 + 0];
|
|
197
|
-
const m11 = m[1 * 4 + 1];
|
|
198
|
-
const m12 = m[1 * 4 + 2];
|
|
199
|
-
const m13 = m[1 * 4 + 3];
|
|
200
|
-
const m20 = m[2 * 4 + 0];
|
|
201
|
-
const m21 = m[2 * 4 + 1];
|
|
202
|
-
const m22 = m[2 * 4 + 2];
|
|
203
|
-
const m23 = m[2 * 4 + 3];
|
|
204
|
-
const m30 = m[3 * 4 + 0];
|
|
205
|
-
const m31 = m[3 * 4 + 1];
|
|
206
|
-
const m32 = m[3 * 4 + 2];
|
|
207
|
-
const m33 = m[3 * 4 + 3];
|
|
208
|
-
|
|
209
|
-
const tmp0 = m22 * m33;
|
|
210
|
-
const tmp1 = m32 * m23;
|
|
211
|
-
const tmp2 = m12 * m33;
|
|
212
|
-
const tmp3 = m32 * m13;
|
|
213
|
-
const tmp4 = m12 * m23;
|
|
214
|
-
const tmp5 = m22 * m13;
|
|
215
|
-
const tmp6 = m02 * m33;
|
|
216
|
-
const tmp7 = m32 * m03;
|
|
217
|
-
const tmp8 = m02 * m23;
|
|
218
|
-
const tmp9 = m22 * m03;
|
|
219
|
-
const tmp10 = m02 * m13;
|
|
220
|
-
const tmp11 = m12 * m03;
|
|
221
|
-
const tmp12 = m20 * m31;
|
|
222
|
-
const tmp13 = m30 * m21;
|
|
223
|
-
const tmp14 = m10 * m31;
|
|
224
|
-
const tmp15 = m30 * m11;
|
|
225
|
-
const tmp16 = m10 * m21;
|
|
226
|
-
const tmp17 = m20 * m11;
|
|
227
|
-
const tmp18 = m00 * m31;
|
|
228
|
-
const tmp19 = m30 * m01;
|
|
229
|
-
const tmp20 = m00 * m21;
|
|
230
|
-
const tmp21 = m20 * m01;
|
|
231
|
-
const tmp22 = m00 * m11;
|
|
232
|
-
const tmp23 = m10 * m01;
|
|
233
|
-
|
|
234
|
-
const t0 = (tmp0 * m11 + tmp3 * m21 + tmp4 * m31) -
|
|
235
|
-
(tmp1 * m11 + tmp2 * m21 + tmp5 * m31);
|
|
236
|
-
const t1 = (tmp1 * m01 + tmp6 * m21 + tmp9 * m31) -
|
|
237
|
-
(tmp0 * m01 + tmp7 * m21 + tmp8 * m31);
|
|
238
|
-
const t2 = (tmp2 * m01 + tmp7 * m11 + tmp10 * m31) -
|
|
239
|
-
(tmp3 * m01 + tmp6 * m11 + tmp11 * m31);
|
|
240
|
-
const t3 = (tmp5 * m01 + tmp8 * m11 + tmp11 * m21) -
|
|
241
|
-
(tmp4 * m01 + tmp9 * m11 + tmp10 * m21);
|
|
242
|
-
|
|
243
|
-
const d = 1 / (m00 * t0 + m10 * t1 + m20 * t2 + m30 * t3);
|
|
244
|
-
|
|
245
|
-
dst[0] = d * t0;
|
|
246
|
-
dst[1] = d * t1;
|
|
247
|
-
dst[2] = d * t2;
|
|
248
|
-
dst[3] = d * t3;
|
|
249
|
-
|
|
250
|
-
dst[4] = d * ((tmp1 * m10 + tmp2 * m20 + tmp5 * m30) -
|
|
251
|
-
(tmp0 * m10 + tmp3 * m20 + tmp4 * m30));
|
|
252
|
-
dst[5] = d * ((tmp0 * m00 + tmp7 * m20 + tmp8 * m30) -
|
|
253
|
-
(tmp1 * m00 + tmp6 * m20 + tmp9 * m30));
|
|
254
|
-
dst[6] = d * ((tmp3 * m00 + tmp6 * m10 + tmp11 * m30) -
|
|
255
|
-
(tmp2 * m00 + tmp7 * m10 + tmp10 * m30));
|
|
256
|
-
dst[7] = d * ((tmp4 * m00 + tmp9 * m10 + tmp10 * m20) -
|
|
257
|
-
(tmp5 * m00 + tmp8 * m10 + tmp11 * m20));
|
|
258
|
-
|
|
259
|
-
dst[8] = d * ((tmp12 * m13 + tmp15 * m23 + tmp16 * m33) -
|
|
260
|
-
(tmp13 * m13 + tmp14 * m23 + tmp17 * m33));
|
|
261
|
-
dst[9] = d * ((tmp13 * m03 + tmp18 * m23 + tmp21 * m33) -
|
|
262
|
-
(tmp12 * m03 + tmp19 * m23 + tmp20 * m33));
|
|
263
|
-
dst[10] = d * ((tmp14 * m03 + tmp19 * m13 + tmp22 * m33) -
|
|
264
|
-
(tmp15 * m03 + tmp18 * m13 + tmp23 * m33));
|
|
265
|
-
dst[11] = d * ((tmp17 * m03 + tmp20 * m13 + tmp23 * m23) -
|
|
266
|
-
(tmp16 * m03 + tmp21 * m13 + tmp22 * m23));
|
|
267
|
-
|
|
268
|
-
dst[12] = d * ((tmp14 * m22 + tmp17 * m32 + tmp13 * m12) -
|
|
269
|
-
(tmp16 * m32 + tmp12 * m12 + tmp15 * m22));
|
|
270
|
-
dst[13] = d * ((tmp20 * m32 + tmp12 * m02 + tmp19 * m22) -
|
|
271
|
-
(tmp18 * m22 + tmp21 * m32 + tmp13 * m02));
|
|
272
|
-
dst[14] = d * ((tmp18 * m12 + tmp23 * m32 + tmp15 * m02) -
|
|
273
|
-
(tmp22 * m32 + tmp14 * m02 + tmp19 * m12));
|
|
274
|
-
dst[15] = d * ((tmp22 * m22 + tmp16 * m02 + tmp21 * m12) -
|
|
275
|
-
(tmp20 * m12 + tmp23 * m22 + tmp17 * m02));
|
|
276
|
-
return dst;
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
lookAt(eye, target, up, dst) {
|
|
280
|
-
return mat4.inverse(mat4.cameraAim(eye, target, up, dst), dst);
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
translation([tx, ty, tz], dst) {
|
|
284
|
-
dst = dst || new Float32Array(16);
|
|
285
|
-
dst[0] = 1; dst[1] = 0; dst[2] = 0; dst[3] = 0;
|
|
286
|
-
dst[4] = 0; dst[5] = 1; dst[6] = 0; dst[7] = 0;
|
|
287
|
-
dst[8] = 0; dst[9] = 0; dst[10] = 1; dst[11] = 0;
|
|
288
|
-
dst[12] = tx; dst[13] = ty; dst[14] = tz; dst[15] = 1;
|
|
289
|
-
return dst;
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
rotationX(angleInRadians, dst) {
|
|
293
|
-
const c = Math.cos(angleInRadians);
|
|
294
|
-
const s = Math.sin(angleInRadians);
|
|
295
|
-
dst = dst || new Float32Array(16);
|
|
296
|
-
dst[0] = 1; dst[1] = 0; dst[2] = 0; dst[3] = 0;
|
|
297
|
-
dst[4] = 0; dst[5] = c; dst[6] = s; dst[7] = 0;
|
|
298
|
-
dst[8] = 0; dst[9] = -s; dst[10] = c; dst[11] = 0;
|
|
299
|
-
dst[12] = 0; dst[13] = 0; dst[14] = 0; dst[15] = 1;
|
|
300
|
-
return dst;
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
rotationY(angleInRadians, dst) {
|
|
304
|
-
const c = Math.cos(angleInRadians);
|
|
305
|
-
const s = Math.sin(angleInRadians);
|
|
306
|
-
dst = dst || new Float32Array(16);
|
|
307
|
-
dst[0] = c; dst[1] = 0; dst[2] = -s; dst[3] = 0;
|
|
308
|
-
dst[4] = 0; dst[5] = 1; dst[6] = 0; dst[7] = 0;
|
|
309
|
-
dst[8] = s; dst[9] = 0; dst[10] = c; dst[11] = 0;
|
|
310
|
-
dst[12] = 0; dst[13] = 0; dst[14] = 0; dst[15] = 1;
|
|
311
|
-
return dst;
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
rotationZ(angleInRadians, dst) {
|
|
315
|
-
const c = Math.cos(angleInRadians);
|
|
316
|
-
const s = Math.sin(angleInRadians);
|
|
317
|
-
dst = dst || new Float32Array(16);
|
|
318
|
-
dst[0] = c; dst[1] = s; dst[2] = 0; dst[3] = 0;
|
|
319
|
-
dst[4] = -s; dst[5] = c; dst[6] = 0; dst[7] = 0;
|
|
320
|
-
dst[8] = 0; dst[9] = 0; dst[10] = 1; dst[11] = 0;
|
|
321
|
-
dst[12] = 0; dst[13] = 0; dst[14] = 0; dst[15] = 1;
|
|
322
|
-
return dst;
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
scaling([sx, sy, sz], dst) {
|
|
326
|
-
dst = dst || new Float32Array(16);
|
|
327
|
-
dst[0] = sx; dst[1] = 0; dst[2] = 0; dst[3] = 0;
|
|
328
|
-
dst[4] = 0; dst[5] = sy; dst[6] = 0; dst[7] = 0;
|
|
329
|
-
dst[8] = 0; dst[9] = 0; dst[10] = sz; dst[11] = 0;
|
|
330
|
-
dst[12] = 0; dst[13] = 0; dst[14] = 0; dst[15] = 1;
|
|
331
|
-
return dst;
|
|
332
|
-
},
|
|
333
|
-
|
|
334
|
-
translate(m, translation, dst) {
|
|
335
|
-
return mat4.multiply(m, mat4.translation(translation), dst);
|
|
336
|
-
},
|
|
337
|
-
|
|
338
|
-
rotateX(m, angleInRadians, dst) {
|
|
339
|
-
return mat4.multiply(m, mat4.rotationX(angleInRadians), dst);
|
|
340
|
-
},
|
|
341
|
-
|
|
342
|
-
rotateY(m, angleInRadians, dst) {
|
|
343
|
-
return mat4.multiply(m, mat4.rotationY(angleInRadians), dst);
|
|
344
|
-
},
|
|
345
|
-
|
|
346
|
-
rotateZ(m, angleInRadians, dst) {
|
|
347
|
-
return mat4.multiply(m, mat4.rotationZ(angleInRadians), dst);
|
|
348
|
-
},
|
|
349
|
-
|
|
350
|
-
scale(m, scale, dst) {
|
|
351
|
-
return mat4.multiply(m, mat4.scaling(scale), dst);
|
|
352
|
-
},
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
export function degToRad(degrees) {return (degrees * Math.PI) / 180};
|
|
356
|
-
|
|
357
|
-
export function radToDeg(r) {var pi = Math.PI; return r * (180 / pi)};
|
|
358
|
-
|
|
359
|
-
export function createAppEvent(name, myDetails) {
|
|
360
|
-
return new CustomEvent(name, {
|
|
361
|
-
detail: {
|
|
362
|
-
eventName: name,
|
|
363
|
-
data: myDetails,
|
|
364
|
-
},
|
|
365
|
-
bubbles: true,
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* @description
|
|
371
|
-
* Load script in runtime.
|
|
372
|
-
*/
|
|
373
|
-
export var scriptManager = {
|
|
374
|
-
SCRIPT_ID: 0,
|
|
375
|
-
LOAD: function addScript(src, id, type, parent, callback) {
|
|
376
|
-
var s = document.createElement('script');
|
|
377
|
-
s.onload = function() {
|
|
378
|
-
// console.log('Script id loaded [src]: ' + this.src);
|
|
379
|
-
if(typeof callback != 'undefined') callback();
|
|
380
|
-
};
|
|
381
|
-
if(typeof type !== 'undefined') {
|
|
382
|
-
s.setAttribute('type', type);
|
|
383
|
-
s.innerHTML = src;
|
|
384
|
-
} else {s.setAttribute('src', src)}
|
|
385
|
-
if(typeof id !== 'undefined') {s.setAttribute('id', id)}
|
|
386
|
-
if(typeof parent !== 'undefined') {
|
|
387
|
-
document.getElementById(parent).appendChild(s);
|
|
388
|
-
if(typeof callback != 'undefined') callback();
|
|
389
|
-
} else {
|
|
390
|
-
document.body.appendChild(s);
|
|
391
|
-
}
|
|
392
|
-
},
|
|
393
|
-
loadModule: function addScript(src, id, type, parent) {
|
|
394
|
-
console.log('Script id load called ');
|
|
395
|
-
var s = document.createElement('script');
|
|
396
|
-
s.onload = function() {
|
|
397
|
-
scriptManager.SCRIPT_ID++;
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
if(typeof type === 'undefined') {
|
|
401
|
-
s.setAttribute('type', 'module');
|
|
402
|
-
s.setAttribute('src', src);
|
|
403
|
-
} else {
|
|
404
|
-
s.setAttribute('type', type);
|
|
405
|
-
s.innerHTML = src;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
s.setAttribute('src', src);
|
|
409
|
-
if(typeof id !== 'undefined') {
|
|
410
|
-
s.setAttribute('id', id);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if(typeof parent !== 'undefined') {
|
|
414
|
-
document.getElementById(parent).appendChild(s);
|
|
415
|
-
} else {
|
|
416
|
-
document.body.appendChild(s);
|
|
417
|
-
}
|
|
418
|
-
},
|
|
419
|
-
loadGLSL: function(src) {
|
|
420
|
-
return new Promise((resolve) => {
|
|
421
|
-
fetch(src).then((data) => {
|
|
422
|
-
resolve(data.text())
|
|
423
|
-
})
|
|
424
|
-
})
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
// GET PULSE VALUES IN REAL TIME
|
|
429
|
-
export function OSCILLATOR(min, max, step) {
|
|
430
|
-
if((typeof min === 'string' || typeof min === 'number') && (typeof max === 'string' || typeof max === 'number') && (typeof step === 'string' || typeof step === 'number')) {
|
|
431
|
-
var ROOT = this;
|
|
432
|
-
this.min = parseFloat(min);
|
|
433
|
-
this.max = parseFloat(max);
|
|
434
|
-
this.step = parseFloat(step);
|
|
435
|
-
this.value_ = parseFloat(min);
|
|
436
|
-
this.status = 0;
|
|
437
|
-
this.on_maximum_value = function() {};
|
|
438
|
-
this.on_minimum_value = function() {};
|
|
439
|
-
this.UPDATE = function(STATUS_) {
|
|
440
|
-
if(STATUS_ === undefined) {
|
|
441
|
-
if(this.status == 0 && this.value_ < this.max) {
|
|
442
|
-
this.value_ = this.value_ + this.step;
|
|
443
|
-
if(this.value_ >= this.max) {
|
|
444
|
-
this.value_ = this.max;
|
|
445
|
-
this.status = 1;
|
|
446
|
-
ROOT.on_maximum_value();
|
|
447
|
-
}
|
|
448
|
-
return this.value_;
|
|
449
|
-
} else if(this.status == 1 && this.value_ > this.min) {
|
|
450
|
-
this.value_ = this.value_ - this.step;
|
|
451
|
-
if(this.value_ <= this.min) {
|
|
452
|
-
this.value_ = this.min;
|
|
453
|
-
this.status = 0;
|
|
454
|
-
ROOT.on_minimum_value();
|
|
455
|
-
}
|
|
456
|
-
return this.value_;
|
|
457
|
-
}
|
|
458
|
-
} else {
|
|
459
|
-
return this.value_;
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
} else {
|
|
463
|
-
console.log(
|
|
464
|
-
"SYS : warning for procedure 'SYS.MATH.OSCILLATOR' Desciption : Replace object with string or number, min >> " +
|
|
465
|
-
typeof min +
|
|
466
|
-
' and max >>' +
|
|
467
|
-
typeof max +
|
|
468
|
-
' and step >>' +
|
|
469
|
-
typeof step +
|
|
470
|
-
' << must be string or number.'
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// this is class not func ecma5
|
|
476
|
-
export function SWITCHER() {
|
|
477
|
-
var ROOT = this;
|
|
478
|
-
ROOT.VALUE = 1;
|
|
479
|
-
ROOT.GET = function() {
|
|
480
|
-
ROOT.VALUE = ROOT.VALUE * -1;
|
|
481
|
-
return ROOT.VALUE;
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
export function ORBIT(cx, cy, angle, p) {
|
|
486
|
-
var s = Math.sin(angle);
|
|
487
|
-
var c = Math.cos(angle);
|
|
488
|
-
p.x -= cx;
|
|
489
|
-
p.y -= cy;
|
|
490
|
-
var xnew = p.x * c - p.y * s;
|
|
491
|
-
var ynew = p.x * s + p.y * c;
|
|
492
|
-
p.x = xnew + cx;
|
|
493
|
-
p.y = ynew + cy;
|
|
494
|
-
return p;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
export function ORBIT_FROM_ARRAY(cx, cy, angle, p, byIndexs) {
|
|
498
|
-
var s = Math.sin(angle);
|
|
499
|
-
var c = Math.cos(angle);
|
|
500
|
-
p[byIndexs[0]] -= cx;
|
|
501
|
-
p[byIndexs[1]] -= cy;
|
|
502
|
-
var xnew = p[byIndexs[0]] * c - p[byIndexs[1]] * s;
|
|
503
|
-
var ynew = p[byIndexs[0]] * s + p[byIndexs[1]] * c;
|
|
504
|
-
p[byIndexs[0]] = xnew + cx;
|
|
505
|
-
p[byIndexs[1]] = ynew + cy;
|
|
506
|
-
return p;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
export var byId = function(id) {return document.getElementById(id)};
|
|
510
|
-
export function randomFloatFromTo(min, max) {return Math.random() * (max - min) + min;}
|
|
511
|
-
|
|
512
|
-
export function randomIntFromTo(min, max) {
|
|
513
|
-
if(typeof min === 'object' || typeof max === 'object') {
|
|
514
|
-
console.log(
|
|
515
|
-
"SYS : warning Desciption : Replace object with string , this >> " + typeof min + ' and ' + typeof min + ' << must be string or number.'
|
|
516
|
-
);
|
|
517
|
-
} else if(typeof min === 'undefined' || typeof max === 'undefined') {
|
|
518
|
-
console.log(
|
|
519
|
-
"SYS : warning Desciption : arguments (min, max) cant be undefined , this >> " + typeof min + ' and ' + typeof min + ' << must be string or number.'
|
|
520
|
-
);
|
|
521
|
-
} else {
|
|
522
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
export var urlQuery = (function() {
|
|
527
|
-
var query_string = {};
|
|
528
|
-
var query = window.location.search.substring(1);
|
|
529
|
-
var vars = query.split('&');
|
|
530
|
-
for(var i = 0;i < vars.length;i++) {
|
|
531
|
-
var pair = vars[i].split('=');
|
|
532
|
-
if(typeof query_string[pair[0]] === 'undefined') {
|
|
533
|
-
query_string[pair[0]] = decodeURIComponent(pair[1]);
|
|
534
|
-
} else if(typeof query_string[pair[0]] === 'string') {
|
|
535
|
-
var arr = [query_string[pair[0]], decodeURIComponent(pair[1])];
|
|
536
|
-
query_string[pair[0]] = arr;
|
|
537
|
-
} else {
|
|
538
|
-
query_string[pair[0]].push(decodeURIComponent(pair[1]));
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
return query_string;
|
|
542
|
-
})();
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
export function getAxisRot(q1) {
|
|
546
|
-
var x, y, z;
|
|
547
|
-
|
|
548
|
-
// if w>1 acos and sqrt will produce errors, this cant happen if quaternion is normalised
|
|
549
|
-
if(q1.w > 1) q1.normalise();
|
|
550
|
-
var angle = 2 * Math.acos(q1.w);
|
|
551
|
-
// assuming quaternion normalised then w is less than 1, so term always positive.
|
|
552
|
-
var s = Math.sqrt(1 - q1.w * q1.w);
|
|
553
|
-
// test to avoid divide by zero, s is always positive due to sqrt
|
|
554
|
-
if(s < 0.001) {
|
|
555
|
-
// if s close to zero then direction of axis not important
|
|
556
|
-
// if it is important that axis is normalised then replace with x=1; y=z=0;
|
|
557
|
-
|
|
558
|
-
x = q1.x;
|
|
559
|
-
y = q1.y;
|
|
560
|
-
z = q1.z;
|
|
561
|
-
} else {
|
|
562
|
-
x = q1.x / s; // normalise axis
|
|
563
|
-
y = q1.y / s;
|
|
564
|
-
z = q1.z / s;
|
|
565
|
-
}
|
|
566
|
-
return [radToDeg(x), radToDeg(y), radToDeg(z)]
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
export function getAxisRot2(targetAxis, Q) {
|
|
570
|
-
Q.normalize(); // if w>1 acos and sqrt will produce errors, this cant happen if quaternion is normalised
|
|
571
|
-
var angle = 2 * Math.acos(Q.w());
|
|
572
|
-
var s = Math.sqrt(1 - Q.w() * Q.w()); // assuming quaternion normalised then w is less than 1, so term always positive.
|
|
573
|
-
if(s < 0.001) { // test to avoid divide by zero, s is always positive due to sqrt
|
|
574
|
-
// if s close to zero then direction of axis not important
|
|
575
|
-
// if it is important that axis is normalised then replace with x=1; y=z=0;
|
|
576
|
-
// targetAxis.x = 1;
|
|
577
|
-
// targetAxis.y = 0;
|
|
578
|
-
// targetAxis.z = 0;
|
|
579
|
-
targetAxis.x = Q.x();
|
|
580
|
-
targetAxis.y = Q.y();
|
|
581
|
-
targetAxis.z = Q.z();
|
|
582
|
-
} else {
|
|
583
|
-
targetAxis.x = Q.x() / s; // normalise axis
|
|
584
|
-
targetAxis.y = Q.y() / s;
|
|
585
|
-
targetAxis.z = Q.z() / s;
|
|
586
|
-
}
|
|
587
|
-
return [targetAxis, angle];
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
export function getAxisRot3(Q) {
|
|
591
|
-
|
|
592
|
-
var angle = Math.acos(Q.w) * 2;
|
|
593
|
-
var axis = {};
|
|
594
|
-
|
|
595
|
-
if(Math.sin(Math.acos(angle)) > 0) {
|
|
596
|
-
|
|
597
|
-
axis.x = Q.x / Math.sin(Math.acos(angle / 2));
|
|
598
|
-
axis.y = Q.y / Math.sin(Math.acos(angle / 2));
|
|
599
|
-
axis.z = Q.z / Math.sin(Math.acos(angle / 2));
|
|
600
|
-
|
|
601
|
-
} else {
|
|
602
|
-
axis.x = 0;
|
|
603
|
-
axis.y = 0;
|
|
604
|
-
axis.z = 0;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
return axis;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
// NTO TESTED
|
|
611
|
-
export function quaternion_rotation_matrix(Q) {
|
|
612
|
-
|
|
613
|
-
// Covert a quaternion into a full three-dimensional rotation matrix.
|
|
614
|
-
|
|
615
|
-
// Input
|
|
616
|
-
// :param Q: A 4 element array representing the quaternion (q0,q1,q2,q3)
|
|
617
|
-
|
|
618
|
-
// Output
|
|
619
|
-
// :return: A 3x3 element matrix representing the full 3D rotation matrix.
|
|
620
|
-
// This rotation matrix converts a point in the local reference
|
|
621
|
-
// frame to a point in the global reference frame.
|
|
622
|
-
// """
|
|
623
|
-
// # Extract the values from Q
|
|
624
|
-
var q0 = Q[0]
|
|
625
|
-
var q1 = Q[1]
|
|
626
|
-
var q2 = Q[2]
|
|
627
|
-
var q3 = Q[3]
|
|
628
|
-
|
|
629
|
-
// # First row of the rotation matrix
|
|
630
|
-
var r00 = 2 * (q0 * q0 + q1 * q1) - 1
|
|
631
|
-
var r01 = 2 * (q1 * q2 - q0 * q3)
|
|
632
|
-
var r02 = 2 * (q1 * q3 + q0 * q2)
|
|
633
|
-
|
|
634
|
-
// # Second row of the rotation matrix
|
|
635
|
-
var r10 = 2 * (q1 * q2 + q0 * q3)
|
|
636
|
-
var r11 = 2 * (q0 * q0 + q2 * q2) - 1
|
|
637
|
-
var r12 = 2 * (q2 * q3 - q0 * q1)
|
|
638
|
-
|
|
639
|
-
// # Third row of the rotation matrix
|
|
640
|
-
var r20 = 2 * (q1 * q3 - q0 * q2)
|
|
641
|
-
var r21 = 2 * (q2 * q3 + q0 * q1)
|
|
642
|
-
var r22 = 2 * (q0 * q0 + q3 * q3) - 1
|
|
643
|
-
|
|
644
|
-
// # 3x3 rotation matrix
|
|
645
|
-
var rot_matrix = [[r00, r01, r02],
|
|
646
|
-
[r10, r11, r12],
|
|
647
|
-
[r20, r21, r22]]
|
|
648
|
-
|
|
649
|
-
return rot_matrix;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// copnsole log graphics
|
|
653
|
-
export const LOG_WARN = 'background: gray; color: yellow; font-size:10px';
|
|
654
|
-
export const LOG_INFO = 'background: green; color: white; font-size:11px';
|
|
655
|
-
export const LOG_MATRIX = "font-family: stormfaze;color: #lime; font-size:11px;text-shadow: 2px 2px 4px orangered;background: black;";
|
|
656
|
-
export const LOG_FUNNY = "font-family: stormfaze;color: #f1f033; font-size:14px;text-shadow: 2px 2px 4px #f335f4, 4px 4px 4px #d64444, 2px 2px 4px #c160a6, 6px 2px 0px #123de3;background: black;";
|
|
657
|
-
export const LOG_FUNNY_SMALL = "font-family: stormfaze;color: #f1f033; font-size:10px;text-shadow: 2px 2px 4px #f335f4, 4px 4px 4px #d64444, 1px 1px 2px #c160a6, 3px 1px 0px #123de3;background: black;";
|
|
658
|
-
|
|
659
|
-
export function genName(length) {
|
|
660
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
661
|
-
let result = "";
|
|
662
|
-
for(let i = 0;i < length;i++) {
|
|
663
|
-
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
664
|
-
}
|
|
665
|
-
return result;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
export let mb = {
|
|
669
|
-
root: () => byId('msgBox'),
|
|
670
|
-
pContent: () => byId('not-content'),
|
|
671
|
-
copy: function() {
|
|
672
|
-
navigator.clipboard.writeText(mb.root().children[0].innerText);
|
|
673
|
-
},
|
|
674
|
-
c: 0, ic: 0, t: {},
|
|
675
|
-
setContent: function(content, t) {
|
|
676
|
-
var iMsg = document.createElement('div');
|
|
677
|
-
iMsg.innerHTML = content;
|
|
678
|
-
iMsg.id = `msgbox-loc-${mb.c}`;
|
|
679
|
-
mb.root().appendChild(iMsg);
|
|
680
|
-
iMsg.classList.add('animate1')
|
|
681
|
-
if(t == 'ok') {
|
|
682
|
-
iMsg.style = 'font-family: stormfaze;color:white;padding:7px;margin:2px';
|
|
683
|
-
} else {
|
|
684
|
-
iMsg.style = 'font-family: stormfaze;color:white;padding:7px;margin:2px';
|
|
685
|
-
}
|
|
686
|
-
},
|
|
687
|
-
kill: function() {
|
|
688
|
-
mb.root().remove();
|
|
689
|
-
},
|
|
690
|
-
show: function(content, t) {
|
|
691
|
-
mb.setContent(content, t);
|
|
692
|
-
mb.root().style.display = "block";
|
|
693
|
-
var loc2 = mb.c;
|
|
694
|
-
setTimeout(function() {
|
|
695
|
-
byId(`msgbox-loc-${loc2}`).classList.remove("fadeInDown");
|
|
696
|
-
byId(`msgbox-loc-${loc2}`).classList.add("fadeOut");
|
|
697
|
-
setTimeout(function() {
|
|
698
|
-
byId(`msgbox-loc-${loc2}`).style.display = "none";
|
|
699
|
-
byId(`msgbox-loc-${loc2}`).classList.remove("fadeOut");
|
|
700
|
-
|
|
701
|
-
byId(`msgbox-loc-${loc2}`).remove();
|
|
702
|
-
mb.ic++;
|
|
703
|
-
if(mb.c == mb.ic) {
|
|
704
|
-
mb.root().style.display = 'none';
|
|
705
|
-
}
|
|
706
|
-
}, 1000)
|
|
707
|
-
}, 3000);
|
|
708
|
-
mb.c++;
|
|
709
|
-
},
|
|
710
|
-
error: function(content) {
|
|
711
|
-
if (mb.root()== null) return;
|
|
712
|
-
mb.root().classList.remove("success")
|
|
713
|
-
mb.root().classList.add("error")
|
|
714
|
-
mb.root().classList.add("fadeInDown");
|
|
715
|
-
mb.show(content, 'err');
|
|
716
|
-
},
|
|
717
|
-
success: function(content) {
|
|
718
|
-
if (mb.root()== null) return;
|
|
719
|
-
mb.root().classList.remove("error")
|
|
720
|
-
mb.root().classList.add("success")
|
|
721
|
-
mb.root().classList.add("fadeInDown");
|
|
722
|
-
mb.show(content, 'ok');
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// Registry to track running animations per element
|
|
727
|
-
const typingStates = new Map();
|
|
728
|
-
|
|
729
|
-
export function typeText(elementId, htmlString, delay = 50) {
|
|
730
|
-
const el = document.getElementById(elementId);
|
|
731
|
-
if (!el) return;
|
|
732
|
-
|
|
733
|
-
// If an existing typing is running for this element, cancel it
|
|
734
|
-
if (typingStates.has(elementId)) {
|
|
735
|
-
clearTimeout(typingStates.get(elementId).timeoutId);
|
|
736
|
-
typingStates.delete(elementId);
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
el.innerHTML = ''; // Clear previous content
|
|
740
|
-
|
|
741
|
-
const tempEl = document.createElement('div');
|
|
742
|
-
tempEl.innerHTML = htmlString;
|
|
743
|
-
|
|
744
|
-
const queue = [];
|
|
745
|
-
|
|
746
|
-
function flatten(node) {
|
|
747
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
748
|
-
queue.push({ type: 'text', text: node.textContent });
|
|
749
|
-
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
750
|
-
if (node.tagName.toLowerCase() === 'img') {
|
|
751
|
-
queue.push({
|
|
752
|
-
type: 'img',
|
|
753
|
-
src: node.getAttribute('src'),
|
|
754
|
-
alt: node.getAttribute('alt') || ''
|
|
755
|
-
});
|
|
756
|
-
} else {
|
|
757
|
-
queue.push({
|
|
758
|
-
type: 'element',
|
|
759
|
-
tag: node.tagName.toLowerCase(),
|
|
760
|
-
attributes: Object.fromEntries([...node.attributes].map(attr => [attr.name, attr.value]))
|
|
761
|
-
});
|
|
762
|
-
for (const child of node.childNodes) flatten(child);
|
|
763
|
-
queue.push({ type: 'end' });
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
for (const node of tempEl.childNodes) flatten(node);
|
|
769
|
-
|
|
770
|
-
let stack = [];
|
|
771
|
-
let currentElement = el;
|
|
772
|
-
|
|
773
|
-
function typeNextChar() {
|
|
774
|
-
if (queue.length === 0) {
|
|
775
|
-
typingStates.delete(elementId); // Cleanup after finish
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
const item = queue[0];
|
|
780
|
-
|
|
781
|
-
if (item.type === 'text') {
|
|
782
|
-
if (!item.index) item.index = 0;
|
|
783
|
-
|
|
784
|
-
const ch = item.text[item.index];
|
|
785
|
-
if (ch === '\n') {
|
|
786
|
-
currentElement.appendChild(document.createElement('br'));
|
|
787
|
-
} else {
|
|
788
|
-
currentElement.appendChild(document.createTextNode(ch));
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
item.index++;
|
|
792
|
-
if (item.index >= item.text.length) queue.shift();
|
|
793
|
-
|
|
794
|
-
} else if (item.type === 'element') {
|
|
795
|
-
const newEl = document.createElement(item.tag);
|
|
796
|
-
if (item.attributes) {
|
|
797
|
-
for (let [key, val] of Object.entries(item.attributes)) {
|
|
798
|
-
newEl.setAttribute(key, val);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
currentElement.appendChild(newEl);
|
|
802
|
-
stack.push(currentElement);
|
|
803
|
-
currentElement = newEl;
|
|
804
|
-
queue.shift();
|
|
805
|
-
|
|
806
|
-
} else if (item.type === 'end') {
|
|
807
|
-
currentElement = stack.pop();
|
|
808
|
-
queue.shift();
|
|
809
|
-
|
|
810
|
-
} else if (item.type === 'img') {
|
|
811
|
-
const img = document.createElement('img');
|
|
812
|
-
img.src = item.src;
|
|
813
|
-
img.alt = item.alt;
|
|
814
|
-
img.style.maxWidth = '100px';
|
|
815
|
-
img.style.verticalAlign = 'middle';
|
|
816
|
-
currentElement.appendChild(img);
|
|
817
|
-
queue.shift();
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
// Schedule next step and store timeoutId for control
|
|
821
|
-
const timeoutId = setTimeout(typeNextChar, delay);
|
|
822
|
-
typingStates.set(elementId, { timeoutId });
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
typeNextChar();
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
export function setupCanvasFilters(canvasId) {
|
|
830
|
-
let canvas = document.getElementById(canvasId);
|
|
831
|
-
if(canvas == null) {
|
|
832
|
-
canvas = document.getElementsByTagName('canvas')[0];
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
const filterState = {
|
|
836
|
-
blur: "0px",
|
|
837
|
-
grayscale: "0%",
|
|
838
|
-
brightness: "100%",
|
|
839
|
-
contrast: "100%",
|
|
840
|
-
saturate: "100%",
|
|
841
|
-
sepia: "0%",
|
|
842
|
-
invert: "0%",
|
|
843
|
-
hueRotate: "0deg"
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
function updateFilter() {
|
|
847
|
-
const filterString = `
|
|
848
|
-
blur(${filterState.blur})
|
|
849
|
-
grayscale(${filterState.grayscale})
|
|
850
|
-
brightness(${filterState.brightness})
|
|
851
|
-
contrast(${filterState.contrast})
|
|
852
|
-
saturate(${filterState.saturate})
|
|
853
|
-
sepia(${filterState.sepia})
|
|
854
|
-
invert(${filterState.invert})
|
|
855
|
-
hue-rotate(${filterState.hueRotate})
|
|
856
|
-
`.trim();
|
|
857
|
-
|
|
858
|
-
canvas.style.filter = filterString;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
const bindings = {
|
|
862
|
-
blurControl: "blur",
|
|
863
|
-
grayscaleControl: "grayscale",
|
|
864
|
-
brightnessControl: "brightness",
|
|
865
|
-
contrastControl: "contrast",
|
|
866
|
-
saturateControl: "saturate",
|
|
867
|
-
sepiaControl: "sepia",
|
|
868
|
-
invertControl: "invert",
|
|
869
|
-
hueControl: "hueRotate"
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
Object.entries(bindings).forEach(([selectId, key]) => {
|
|
873
|
-
const el = document.getElementById(selectId);
|
|
874
|
-
el.addEventListener("change", (e) => {
|
|
875
|
-
filterState[key] = e.target.value;
|
|
876
|
-
updateFilter();
|
|
877
|
-
});
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
updateFilter(); // Initial
|
|
881
|
-
}
|