@fonsecabarreto/genesis-gl-react 0.1.0
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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/chunk-4H2GKYMT.js +4056 -0
- package/dist/chunk-4H2GKYMT.js.map +1 -0
- package/dist/chunk-5CACF6RI.js +71 -0
- package/dist/chunk-5CACF6RI.js.map +1 -0
- package/dist/chunk-6ZAB2GPA.js +46 -0
- package/dist/chunk-6ZAB2GPA.js.map +1 -0
- package/dist/chunk-E6LIWNSH.js +46 -0
- package/dist/chunk-E6LIWNSH.js.map +1 -0
- package/dist/chunk-OJF67RNM.js +1 -0
- package/dist/chunk-OJF67RNM.js.map +1 -0
- package/dist/components/index.js +8 -0
- package/dist/components/index.js.map +1 -0
- package/dist/hooks/index.js +10 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,4056 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/hooks/useGenesisGL.ts
|
|
8
|
+
import { useRef, useEffect } from "react";
|
|
9
|
+
|
|
10
|
+
// ../GenesisGL/src/Core/shaders/index.ts
|
|
11
|
+
var vsSource = (
|
|
12
|
+
/* glsl */
|
|
13
|
+
`
|
|
14
|
+
#define MAX_JOINTS 128
|
|
15
|
+
|
|
16
|
+
attribute vec3 aPosition;
|
|
17
|
+
attribute vec3 aNormal;
|
|
18
|
+
attribute vec2 aTexCoord;
|
|
19
|
+
|
|
20
|
+
// \u2500\u2500 Skinning attributes (vec4: up to 4 joint influences per vertex) \u2500\u2500
|
|
21
|
+
attribute vec4 aJointIndices;
|
|
22
|
+
attribute vec4 aJointWeights;
|
|
23
|
+
|
|
24
|
+
uniform mat4 uModel;
|
|
25
|
+
uniform mat4 uView;
|
|
26
|
+
uniform mat4 uProjection;
|
|
27
|
+
|
|
28
|
+
// \u2500\u2500 Skinning uniforms \u2500\u2500
|
|
29
|
+
uniform bool uUseSkinning;
|
|
30
|
+
uniform mat4 uJointMatrices[MAX_JOINTS];
|
|
31
|
+
|
|
32
|
+
varying vec3 vNormal;
|
|
33
|
+
varying vec3 vPosition;
|
|
34
|
+
varying vec2 vTexCoord;
|
|
35
|
+
|
|
36
|
+
void main() {
|
|
37
|
+
vTexCoord = aTexCoord;
|
|
38
|
+
|
|
39
|
+
vec4 pos = vec4(aPosition, 1.0);
|
|
40
|
+
vec3 norm = aNormal;
|
|
41
|
+
|
|
42
|
+
if (uUseSkinning) {
|
|
43
|
+
mat4 skinMat =
|
|
44
|
+
aJointWeights.x * uJointMatrices[int(aJointIndices.x)] +
|
|
45
|
+
aJointWeights.y * uJointMatrices[int(aJointIndices.y)] +
|
|
46
|
+
aJointWeights.z * uJointMatrices[int(aJointIndices.z)] +
|
|
47
|
+
aJointWeights.w * uJointMatrices[int(aJointIndices.w)];
|
|
48
|
+
pos = skinMat * pos;
|
|
49
|
+
norm = mat3(skinMat) * norm;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
vNormal = mat3(uModel) * norm;
|
|
53
|
+
|
|
54
|
+
vec4 worldPosition = uModel * pos;
|
|
55
|
+
vPosition = worldPosition.xyz;
|
|
56
|
+
gl_Position = uProjection * uView * worldPosition;
|
|
57
|
+
}
|
|
58
|
+
`
|
|
59
|
+
);
|
|
60
|
+
var fsSource = (
|
|
61
|
+
/* glsl */
|
|
62
|
+
`
|
|
63
|
+
precision mediump float;
|
|
64
|
+
|
|
65
|
+
#define MAX_LIGHTS 5
|
|
66
|
+
|
|
67
|
+
varying vec3 vNormal;
|
|
68
|
+
varying vec3 vPosition;
|
|
69
|
+
varying vec2 vTexCoord;
|
|
70
|
+
|
|
71
|
+
uniform vec3 uLightDirection[MAX_LIGHTS];
|
|
72
|
+
uniform vec3 uLightColor[MAX_LIGHTS];
|
|
73
|
+
uniform float uLightIntensity[MAX_LIGHTS];
|
|
74
|
+
uniform int uLightType[MAX_LIGHTS]; // 0=directional, 1=point, 2=ambient
|
|
75
|
+
uniform int uLightCount;
|
|
76
|
+
uniform vec3 uLightPosition[MAX_LIGHTS];
|
|
77
|
+
uniform float uLightConstant[MAX_LIGHTS];
|
|
78
|
+
uniform float uLightLinear[MAX_LIGHTS];
|
|
79
|
+
uniform float uLightQuadratic[MAX_LIGHTS];
|
|
80
|
+
|
|
81
|
+
uniform vec4 uColor;
|
|
82
|
+
uniform bool uUnlit;
|
|
83
|
+
uniform bool uUseTexture;
|
|
84
|
+
uniform sampler2D uTexture;
|
|
85
|
+
|
|
86
|
+
uniform vec3 uViewPosition;
|
|
87
|
+
uniform float uShininess;
|
|
88
|
+
uniform vec3 uSpecularColor;
|
|
89
|
+
|
|
90
|
+
void main() {
|
|
91
|
+
vec4 baseColor = uColor;
|
|
92
|
+
if (uUseTexture) {
|
|
93
|
+
baseColor *= texture2D(uTexture, vTexCoord);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (uUnlit) {
|
|
97
|
+
gl_FragColor = baseColor;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
vec3 norm = normalize(vNormal);
|
|
102
|
+
vec3 totalDiffuse = vec3(0.0);
|
|
103
|
+
vec3 totalAmbient = vec3(0.0);
|
|
104
|
+
vec3 totalSpecular = vec3(0.0);
|
|
105
|
+
|
|
106
|
+
vec3 viewDir = normalize(uViewPosition - vPosition);
|
|
107
|
+
|
|
108
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
109
|
+
if (i >= uLightCount) break;
|
|
110
|
+
|
|
111
|
+
if (uLightType[i] == 2) {
|
|
112
|
+
totalAmbient += uLightColor[i] * uLightIntensity[i];
|
|
113
|
+
} else {
|
|
114
|
+
vec3 lightDir;
|
|
115
|
+
float attenuation = 1.0;
|
|
116
|
+
|
|
117
|
+
if (uLightType[i] == 0) {
|
|
118
|
+
// Directional light
|
|
119
|
+
lightDir = normalize(-uLightDirection[i]);
|
|
120
|
+
} else {
|
|
121
|
+
// Point light
|
|
122
|
+
vec3 lightVec = uLightPosition[i] - vPosition;
|
|
123
|
+
float distance = length(lightVec);
|
|
124
|
+
lightDir = normalize(lightVec);
|
|
125
|
+
attenuation = 1.0 / (
|
|
126
|
+
uLightConstant[i] +
|
|
127
|
+
uLightLinear[i] * distance +
|
|
128
|
+
uLightQuadratic[i] * distance * distance
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Diffuse
|
|
133
|
+
float diff = max(dot(norm, lightDir), 0.0);
|
|
134
|
+
totalDiffuse += diff * uLightColor[i] * uLightIntensity[i] * attenuation;
|
|
135
|
+
|
|
136
|
+
// Specular (Blinn-Phong) \u2014 softer, more natural highlights
|
|
137
|
+
vec3 halfDir = normalize(lightDir + viewDir);
|
|
138
|
+
float spec = pow(max(dot(norm, halfDir), 0.0), uShininess);
|
|
139
|
+
totalSpecular += spec * uSpecularColor * uLightIntensity[i] * attenuation;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
vec3 lightingResult =
|
|
144
|
+
totalAmbient * baseColor.rgb +
|
|
145
|
+
totalDiffuse * baseColor.rgb +
|
|
146
|
+
totalSpecular;
|
|
147
|
+
|
|
148
|
+
gl_FragColor = vec4(lightingResult, baseColor.a);
|
|
149
|
+
}
|
|
150
|
+
`
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// ../GenesisGL/src/Core/classes/WebGLCore.ts
|
|
154
|
+
var WebGLCore = class {
|
|
155
|
+
gl;
|
|
156
|
+
program;
|
|
157
|
+
canvas;
|
|
158
|
+
isWebGL2;
|
|
159
|
+
/**
|
|
160
|
+
* Initialise the WebGL rendering core.
|
|
161
|
+
*
|
|
162
|
+
* @param canvasOrId - An `HTMLCanvasElement` or the DOM `id` of one.
|
|
163
|
+
* Defaults to `'glcanvas'`.
|
|
164
|
+
*/
|
|
165
|
+
constructor(canvasOrId = "glcanvas") {
|
|
166
|
+
const canvas = typeof canvasOrId === "string" ? document.getElementById(canvasOrId) : canvasOrId;
|
|
167
|
+
if (!canvas) throw new Error("Canvas not found");
|
|
168
|
+
this.canvas = canvas;
|
|
169
|
+
canvas.width = window.innerWidth;
|
|
170
|
+
canvas.height = window.innerHeight;
|
|
171
|
+
this.gl = canvas.getContext("webgl2") ?? canvas.getContext("webgl");
|
|
172
|
+
if (!this.gl) throw new Error("WebGL not supported in this browser!");
|
|
173
|
+
this.isWebGL2 = this.gl instanceof WebGL2RenderingContext;
|
|
174
|
+
this.gl.viewport(0, 0, canvas.width, canvas.height);
|
|
175
|
+
const program = this.createProgram(this.gl);
|
|
176
|
+
if (!program) throw new Error("Failed to create program");
|
|
177
|
+
this.program = program;
|
|
178
|
+
}
|
|
179
|
+
getProgram() {
|
|
180
|
+
return this.program;
|
|
181
|
+
}
|
|
182
|
+
getRenderingContext() {
|
|
183
|
+
return this.gl;
|
|
184
|
+
}
|
|
185
|
+
createProgram(gl) {
|
|
186
|
+
const vertexShader = this.compileShader(gl, gl.VERTEX_SHADER, vsSource);
|
|
187
|
+
const fragmentShader = this.compileShader(gl, gl.FRAGMENT_SHADER, fsSource);
|
|
188
|
+
if (!vertexShader || !fragmentShader)
|
|
189
|
+
throw new Error("Failed to create shaders");
|
|
190
|
+
const program = gl.createProgram();
|
|
191
|
+
if (!program) return null;
|
|
192
|
+
gl.attachShader(program, vertexShader);
|
|
193
|
+
gl.attachShader(program, fragmentShader);
|
|
194
|
+
gl.linkProgram(program);
|
|
195
|
+
gl.deleteShader(vertexShader);
|
|
196
|
+
gl.deleteShader(fragmentShader);
|
|
197
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
198
|
+
console.error(gl.getProgramInfoLog(program));
|
|
199
|
+
throw new Error(gl.getProgramInfoLog(program) || "Program link error");
|
|
200
|
+
}
|
|
201
|
+
return program;
|
|
202
|
+
}
|
|
203
|
+
compileShader(gl, type, source) {
|
|
204
|
+
const shader = gl.createShader(type);
|
|
205
|
+
if (!shader) return null;
|
|
206
|
+
gl.shaderSource(shader, source);
|
|
207
|
+
gl.compileShader(shader);
|
|
208
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
209
|
+
console.error(gl.getShaderInfoLog(shader));
|
|
210
|
+
gl.deleteShader(shader);
|
|
211
|
+
throw new Error(gl.getShaderInfoLog(shader) || "Shader compile error");
|
|
212
|
+
}
|
|
213
|
+
return shader;
|
|
214
|
+
}
|
|
215
|
+
resize(width, height) {
|
|
216
|
+
this.canvas.width = width;
|
|
217
|
+
this.canvas.height = height;
|
|
218
|
+
this.gl.viewport(0, 0, width, height);
|
|
219
|
+
}
|
|
220
|
+
dispose() {
|
|
221
|
+
const { gl, program } = this;
|
|
222
|
+
if (program) gl.deleteProgram(program);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// ../../node_modules/gl-matrix/esm/common.js
|
|
227
|
+
var EPSILON = 1e-6;
|
|
228
|
+
var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
|
|
229
|
+
var RANDOM = Math.random;
|
|
230
|
+
var ANGLE_ORDER = "zyx";
|
|
231
|
+
function round(a) {
|
|
232
|
+
if (a >= 0) return Math.round(a);
|
|
233
|
+
return a % 0.5 === 0 ? Math.floor(a) : Math.round(a);
|
|
234
|
+
}
|
|
235
|
+
var degree = Math.PI / 180;
|
|
236
|
+
var radian = 180 / Math.PI;
|
|
237
|
+
|
|
238
|
+
// ../../node_modules/gl-matrix/esm/mat3.js
|
|
239
|
+
function create() {
|
|
240
|
+
var out = new ARRAY_TYPE(9);
|
|
241
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
242
|
+
out[1] = 0;
|
|
243
|
+
out[2] = 0;
|
|
244
|
+
out[3] = 0;
|
|
245
|
+
out[5] = 0;
|
|
246
|
+
out[6] = 0;
|
|
247
|
+
out[7] = 0;
|
|
248
|
+
}
|
|
249
|
+
out[0] = 1;
|
|
250
|
+
out[4] = 1;
|
|
251
|
+
out[8] = 1;
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ../../node_modules/gl-matrix/esm/mat4.js
|
|
256
|
+
var mat4_exports = {};
|
|
257
|
+
__export(mat4_exports, {
|
|
258
|
+
add: () => add,
|
|
259
|
+
adjoint: () => adjoint,
|
|
260
|
+
clone: () => clone,
|
|
261
|
+
copy: () => copy,
|
|
262
|
+
create: () => create2,
|
|
263
|
+
decompose: () => decompose,
|
|
264
|
+
determinant: () => determinant,
|
|
265
|
+
equals: () => equals,
|
|
266
|
+
exactEquals: () => exactEquals,
|
|
267
|
+
frob: () => frob,
|
|
268
|
+
fromQuat: () => fromQuat,
|
|
269
|
+
fromQuat2: () => fromQuat2,
|
|
270
|
+
fromRotation: () => fromRotation,
|
|
271
|
+
fromRotationTranslation: () => fromRotationTranslation,
|
|
272
|
+
fromRotationTranslationScale: () => fromRotationTranslationScale,
|
|
273
|
+
fromRotationTranslationScaleOrigin: () => fromRotationTranslationScaleOrigin,
|
|
274
|
+
fromScaling: () => fromScaling,
|
|
275
|
+
fromTranslation: () => fromTranslation,
|
|
276
|
+
fromValues: () => fromValues,
|
|
277
|
+
fromXRotation: () => fromXRotation,
|
|
278
|
+
fromYRotation: () => fromYRotation,
|
|
279
|
+
fromZRotation: () => fromZRotation,
|
|
280
|
+
frustum: () => frustum,
|
|
281
|
+
getRotation: () => getRotation,
|
|
282
|
+
getScaling: () => getScaling,
|
|
283
|
+
getTranslation: () => getTranslation,
|
|
284
|
+
identity: () => identity,
|
|
285
|
+
invert: () => invert,
|
|
286
|
+
lookAt: () => lookAt,
|
|
287
|
+
mul: () => mul,
|
|
288
|
+
multiply: () => multiply,
|
|
289
|
+
multiplyScalar: () => multiplyScalar,
|
|
290
|
+
multiplyScalarAndAdd: () => multiplyScalarAndAdd,
|
|
291
|
+
ortho: () => ortho,
|
|
292
|
+
orthoNO: () => orthoNO,
|
|
293
|
+
orthoZO: () => orthoZO,
|
|
294
|
+
perspective: () => perspective,
|
|
295
|
+
perspectiveFromFieldOfView: () => perspectiveFromFieldOfView,
|
|
296
|
+
perspectiveNO: () => perspectiveNO,
|
|
297
|
+
perspectiveZO: () => perspectiveZO,
|
|
298
|
+
rotate: () => rotate,
|
|
299
|
+
rotateX: () => rotateX,
|
|
300
|
+
rotateY: () => rotateY,
|
|
301
|
+
rotateZ: () => rotateZ,
|
|
302
|
+
scale: () => scale,
|
|
303
|
+
set: () => set,
|
|
304
|
+
str: () => str,
|
|
305
|
+
sub: () => sub,
|
|
306
|
+
subtract: () => subtract,
|
|
307
|
+
targetTo: () => targetTo,
|
|
308
|
+
translate: () => translate,
|
|
309
|
+
transpose: () => transpose
|
|
310
|
+
});
|
|
311
|
+
function create2() {
|
|
312
|
+
var out = new ARRAY_TYPE(16);
|
|
313
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
314
|
+
out[1] = 0;
|
|
315
|
+
out[2] = 0;
|
|
316
|
+
out[3] = 0;
|
|
317
|
+
out[4] = 0;
|
|
318
|
+
out[6] = 0;
|
|
319
|
+
out[7] = 0;
|
|
320
|
+
out[8] = 0;
|
|
321
|
+
out[9] = 0;
|
|
322
|
+
out[11] = 0;
|
|
323
|
+
out[12] = 0;
|
|
324
|
+
out[13] = 0;
|
|
325
|
+
out[14] = 0;
|
|
326
|
+
}
|
|
327
|
+
out[0] = 1;
|
|
328
|
+
out[5] = 1;
|
|
329
|
+
out[10] = 1;
|
|
330
|
+
out[15] = 1;
|
|
331
|
+
return out;
|
|
332
|
+
}
|
|
333
|
+
function clone(a) {
|
|
334
|
+
var out = new ARRAY_TYPE(16);
|
|
335
|
+
out[0] = a[0];
|
|
336
|
+
out[1] = a[1];
|
|
337
|
+
out[2] = a[2];
|
|
338
|
+
out[3] = a[3];
|
|
339
|
+
out[4] = a[4];
|
|
340
|
+
out[5] = a[5];
|
|
341
|
+
out[6] = a[6];
|
|
342
|
+
out[7] = a[7];
|
|
343
|
+
out[8] = a[8];
|
|
344
|
+
out[9] = a[9];
|
|
345
|
+
out[10] = a[10];
|
|
346
|
+
out[11] = a[11];
|
|
347
|
+
out[12] = a[12];
|
|
348
|
+
out[13] = a[13];
|
|
349
|
+
out[14] = a[14];
|
|
350
|
+
out[15] = a[15];
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
function copy(out, a) {
|
|
354
|
+
out[0] = a[0];
|
|
355
|
+
out[1] = a[1];
|
|
356
|
+
out[2] = a[2];
|
|
357
|
+
out[3] = a[3];
|
|
358
|
+
out[4] = a[4];
|
|
359
|
+
out[5] = a[5];
|
|
360
|
+
out[6] = a[6];
|
|
361
|
+
out[7] = a[7];
|
|
362
|
+
out[8] = a[8];
|
|
363
|
+
out[9] = a[9];
|
|
364
|
+
out[10] = a[10];
|
|
365
|
+
out[11] = a[11];
|
|
366
|
+
out[12] = a[12];
|
|
367
|
+
out[13] = a[13];
|
|
368
|
+
out[14] = a[14];
|
|
369
|
+
out[15] = a[15];
|
|
370
|
+
return out;
|
|
371
|
+
}
|
|
372
|
+
function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
373
|
+
var out = new ARRAY_TYPE(16);
|
|
374
|
+
out[0] = m00;
|
|
375
|
+
out[1] = m01;
|
|
376
|
+
out[2] = m02;
|
|
377
|
+
out[3] = m03;
|
|
378
|
+
out[4] = m10;
|
|
379
|
+
out[5] = m11;
|
|
380
|
+
out[6] = m12;
|
|
381
|
+
out[7] = m13;
|
|
382
|
+
out[8] = m20;
|
|
383
|
+
out[9] = m21;
|
|
384
|
+
out[10] = m22;
|
|
385
|
+
out[11] = m23;
|
|
386
|
+
out[12] = m30;
|
|
387
|
+
out[13] = m31;
|
|
388
|
+
out[14] = m32;
|
|
389
|
+
out[15] = m33;
|
|
390
|
+
return out;
|
|
391
|
+
}
|
|
392
|
+
function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
393
|
+
out[0] = m00;
|
|
394
|
+
out[1] = m01;
|
|
395
|
+
out[2] = m02;
|
|
396
|
+
out[3] = m03;
|
|
397
|
+
out[4] = m10;
|
|
398
|
+
out[5] = m11;
|
|
399
|
+
out[6] = m12;
|
|
400
|
+
out[7] = m13;
|
|
401
|
+
out[8] = m20;
|
|
402
|
+
out[9] = m21;
|
|
403
|
+
out[10] = m22;
|
|
404
|
+
out[11] = m23;
|
|
405
|
+
out[12] = m30;
|
|
406
|
+
out[13] = m31;
|
|
407
|
+
out[14] = m32;
|
|
408
|
+
out[15] = m33;
|
|
409
|
+
return out;
|
|
410
|
+
}
|
|
411
|
+
function identity(out) {
|
|
412
|
+
out[0] = 1;
|
|
413
|
+
out[1] = 0;
|
|
414
|
+
out[2] = 0;
|
|
415
|
+
out[3] = 0;
|
|
416
|
+
out[4] = 0;
|
|
417
|
+
out[5] = 1;
|
|
418
|
+
out[6] = 0;
|
|
419
|
+
out[7] = 0;
|
|
420
|
+
out[8] = 0;
|
|
421
|
+
out[9] = 0;
|
|
422
|
+
out[10] = 1;
|
|
423
|
+
out[11] = 0;
|
|
424
|
+
out[12] = 0;
|
|
425
|
+
out[13] = 0;
|
|
426
|
+
out[14] = 0;
|
|
427
|
+
out[15] = 1;
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
function transpose(out, a) {
|
|
431
|
+
if (out === a) {
|
|
432
|
+
var a01 = a[1], a02 = a[2], a03 = a[3];
|
|
433
|
+
var a12 = a[6], a13 = a[7];
|
|
434
|
+
var a23 = a[11];
|
|
435
|
+
out[1] = a[4];
|
|
436
|
+
out[2] = a[8];
|
|
437
|
+
out[3] = a[12];
|
|
438
|
+
out[4] = a01;
|
|
439
|
+
out[6] = a[9];
|
|
440
|
+
out[7] = a[13];
|
|
441
|
+
out[8] = a02;
|
|
442
|
+
out[9] = a12;
|
|
443
|
+
out[11] = a[14];
|
|
444
|
+
out[12] = a03;
|
|
445
|
+
out[13] = a13;
|
|
446
|
+
out[14] = a23;
|
|
447
|
+
} else {
|
|
448
|
+
out[0] = a[0];
|
|
449
|
+
out[1] = a[4];
|
|
450
|
+
out[2] = a[8];
|
|
451
|
+
out[3] = a[12];
|
|
452
|
+
out[4] = a[1];
|
|
453
|
+
out[5] = a[5];
|
|
454
|
+
out[6] = a[9];
|
|
455
|
+
out[7] = a[13];
|
|
456
|
+
out[8] = a[2];
|
|
457
|
+
out[9] = a[6];
|
|
458
|
+
out[10] = a[10];
|
|
459
|
+
out[11] = a[14];
|
|
460
|
+
out[12] = a[3];
|
|
461
|
+
out[13] = a[7];
|
|
462
|
+
out[14] = a[11];
|
|
463
|
+
out[15] = a[15];
|
|
464
|
+
}
|
|
465
|
+
return out;
|
|
466
|
+
}
|
|
467
|
+
function invert(out, a) {
|
|
468
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
|
|
469
|
+
var a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
470
|
+
var a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
|
|
471
|
+
var a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
|
472
|
+
var b00 = a00 * a11 - a01 * a10;
|
|
473
|
+
var b01 = a00 * a12 - a02 * a10;
|
|
474
|
+
var b02 = a00 * a13 - a03 * a10;
|
|
475
|
+
var b03 = a01 * a12 - a02 * a11;
|
|
476
|
+
var b04 = a01 * a13 - a03 * a11;
|
|
477
|
+
var b05 = a02 * a13 - a03 * a12;
|
|
478
|
+
var b06 = a20 * a31 - a21 * a30;
|
|
479
|
+
var b07 = a20 * a32 - a22 * a30;
|
|
480
|
+
var b08 = a20 * a33 - a23 * a30;
|
|
481
|
+
var b09 = a21 * a32 - a22 * a31;
|
|
482
|
+
var b10 = a21 * a33 - a23 * a31;
|
|
483
|
+
var b11 = a22 * a33 - a23 * a32;
|
|
484
|
+
var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
485
|
+
if (!det) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
det = 1 / det;
|
|
489
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
|
490
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
|
491
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
|
492
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
|
493
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
|
494
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
|
495
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
496
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
|
497
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
|
498
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
|
499
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
500
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
|
501
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
|
502
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
|
503
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
|
504
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
|
505
|
+
return out;
|
|
506
|
+
}
|
|
507
|
+
function adjoint(out, a) {
|
|
508
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
|
|
509
|
+
var a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
510
|
+
var a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
|
|
511
|
+
var a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
|
512
|
+
var b00 = a00 * a11 - a01 * a10;
|
|
513
|
+
var b01 = a00 * a12 - a02 * a10;
|
|
514
|
+
var b02 = a00 * a13 - a03 * a10;
|
|
515
|
+
var b03 = a01 * a12 - a02 * a11;
|
|
516
|
+
var b04 = a01 * a13 - a03 * a11;
|
|
517
|
+
var b05 = a02 * a13 - a03 * a12;
|
|
518
|
+
var b06 = a20 * a31 - a21 * a30;
|
|
519
|
+
var b07 = a20 * a32 - a22 * a30;
|
|
520
|
+
var b08 = a20 * a33 - a23 * a30;
|
|
521
|
+
var b09 = a21 * a32 - a22 * a31;
|
|
522
|
+
var b10 = a21 * a33 - a23 * a31;
|
|
523
|
+
var b11 = a22 * a33 - a23 * a32;
|
|
524
|
+
out[0] = a11 * b11 - a12 * b10 + a13 * b09;
|
|
525
|
+
out[1] = a02 * b10 - a01 * b11 - a03 * b09;
|
|
526
|
+
out[2] = a31 * b05 - a32 * b04 + a33 * b03;
|
|
527
|
+
out[3] = a22 * b04 - a21 * b05 - a23 * b03;
|
|
528
|
+
out[4] = a12 * b08 - a10 * b11 - a13 * b07;
|
|
529
|
+
out[5] = a00 * b11 - a02 * b08 + a03 * b07;
|
|
530
|
+
out[6] = a32 * b02 - a30 * b05 - a33 * b01;
|
|
531
|
+
out[7] = a20 * b05 - a22 * b02 + a23 * b01;
|
|
532
|
+
out[8] = a10 * b10 - a11 * b08 + a13 * b06;
|
|
533
|
+
out[9] = a01 * b08 - a00 * b10 - a03 * b06;
|
|
534
|
+
out[10] = a30 * b04 - a31 * b02 + a33 * b00;
|
|
535
|
+
out[11] = a21 * b02 - a20 * b04 - a23 * b00;
|
|
536
|
+
out[12] = a11 * b07 - a10 * b09 - a12 * b06;
|
|
537
|
+
out[13] = a00 * b09 - a01 * b07 + a02 * b06;
|
|
538
|
+
out[14] = a31 * b01 - a30 * b03 - a32 * b00;
|
|
539
|
+
out[15] = a20 * b03 - a21 * b01 + a22 * b00;
|
|
540
|
+
return out;
|
|
541
|
+
}
|
|
542
|
+
function determinant(a) {
|
|
543
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
|
|
544
|
+
var a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
545
|
+
var a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
|
|
546
|
+
var a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
|
547
|
+
var b0 = a00 * a11 - a01 * a10;
|
|
548
|
+
var b1 = a00 * a12 - a02 * a10;
|
|
549
|
+
var b2 = a01 * a12 - a02 * a11;
|
|
550
|
+
var b3 = a20 * a31 - a21 * a30;
|
|
551
|
+
var b4 = a20 * a32 - a22 * a30;
|
|
552
|
+
var b5 = a21 * a32 - a22 * a31;
|
|
553
|
+
var b6 = a00 * b5 - a01 * b4 + a02 * b3;
|
|
554
|
+
var b7 = a10 * b5 - a11 * b4 + a12 * b3;
|
|
555
|
+
var b8 = a20 * b2 - a21 * b1 + a22 * b0;
|
|
556
|
+
var b9 = a30 * b2 - a31 * b1 + a32 * b0;
|
|
557
|
+
return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
|
|
558
|
+
}
|
|
559
|
+
function multiply(out, a, b) {
|
|
560
|
+
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
|
|
561
|
+
var a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
562
|
+
var a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
|
|
563
|
+
var a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
|
564
|
+
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
|
565
|
+
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
566
|
+
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
567
|
+
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
568
|
+
out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
569
|
+
b0 = b[4];
|
|
570
|
+
b1 = b[5];
|
|
571
|
+
b2 = b[6];
|
|
572
|
+
b3 = b[7];
|
|
573
|
+
out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
574
|
+
out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
575
|
+
out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
576
|
+
out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
577
|
+
b0 = b[8];
|
|
578
|
+
b1 = b[9];
|
|
579
|
+
b2 = b[10];
|
|
580
|
+
b3 = b[11];
|
|
581
|
+
out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
582
|
+
out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
583
|
+
out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
584
|
+
out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
585
|
+
b0 = b[12];
|
|
586
|
+
b1 = b[13];
|
|
587
|
+
b2 = b[14];
|
|
588
|
+
b3 = b[15];
|
|
589
|
+
out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
590
|
+
out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
591
|
+
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
592
|
+
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
593
|
+
return out;
|
|
594
|
+
}
|
|
595
|
+
function translate(out, a, v) {
|
|
596
|
+
var x = v[0], y = v[1], z = v[2];
|
|
597
|
+
var a00, a01, a02, a03;
|
|
598
|
+
var a10, a11, a12, a13;
|
|
599
|
+
var a20, a21, a22, a23;
|
|
600
|
+
if (a === out) {
|
|
601
|
+
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
|
602
|
+
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
|
603
|
+
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
|
604
|
+
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
|
605
|
+
} else {
|
|
606
|
+
a00 = a[0];
|
|
607
|
+
a01 = a[1];
|
|
608
|
+
a02 = a[2];
|
|
609
|
+
a03 = a[3];
|
|
610
|
+
a10 = a[4];
|
|
611
|
+
a11 = a[5];
|
|
612
|
+
a12 = a[6];
|
|
613
|
+
a13 = a[7];
|
|
614
|
+
a20 = a[8];
|
|
615
|
+
a21 = a[9];
|
|
616
|
+
a22 = a[10];
|
|
617
|
+
a23 = a[11];
|
|
618
|
+
out[0] = a00;
|
|
619
|
+
out[1] = a01;
|
|
620
|
+
out[2] = a02;
|
|
621
|
+
out[3] = a03;
|
|
622
|
+
out[4] = a10;
|
|
623
|
+
out[5] = a11;
|
|
624
|
+
out[6] = a12;
|
|
625
|
+
out[7] = a13;
|
|
626
|
+
out[8] = a20;
|
|
627
|
+
out[9] = a21;
|
|
628
|
+
out[10] = a22;
|
|
629
|
+
out[11] = a23;
|
|
630
|
+
out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
|
631
|
+
out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
|
632
|
+
out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
|
633
|
+
out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
|
634
|
+
}
|
|
635
|
+
return out;
|
|
636
|
+
}
|
|
637
|
+
function scale(out, a, v) {
|
|
638
|
+
var x = v[0], y = v[1], z = v[2];
|
|
639
|
+
out[0] = a[0] * x;
|
|
640
|
+
out[1] = a[1] * x;
|
|
641
|
+
out[2] = a[2] * x;
|
|
642
|
+
out[3] = a[3] * x;
|
|
643
|
+
out[4] = a[4] * y;
|
|
644
|
+
out[5] = a[5] * y;
|
|
645
|
+
out[6] = a[6] * y;
|
|
646
|
+
out[7] = a[7] * y;
|
|
647
|
+
out[8] = a[8] * z;
|
|
648
|
+
out[9] = a[9] * z;
|
|
649
|
+
out[10] = a[10] * z;
|
|
650
|
+
out[11] = a[11] * z;
|
|
651
|
+
out[12] = a[12];
|
|
652
|
+
out[13] = a[13];
|
|
653
|
+
out[14] = a[14];
|
|
654
|
+
out[15] = a[15];
|
|
655
|
+
return out;
|
|
656
|
+
}
|
|
657
|
+
function rotate(out, a, rad, axis) {
|
|
658
|
+
var x = axis[0], y = axis[1], z = axis[2];
|
|
659
|
+
var len4 = Math.sqrt(x * x + y * y + z * z);
|
|
660
|
+
var s, c, t;
|
|
661
|
+
var a00, a01, a02, a03;
|
|
662
|
+
var a10, a11, a12, a13;
|
|
663
|
+
var a20, a21, a22, a23;
|
|
664
|
+
var b00, b01, b02;
|
|
665
|
+
var b10, b11, b12;
|
|
666
|
+
var b20, b21, b22;
|
|
667
|
+
if (len4 < EPSILON) {
|
|
668
|
+
return null;
|
|
669
|
+
}
|
|
670
|
+
len4 = 1 / len4;
|
|
671
|
+
x *= len4;
|
|
672
|
+
y *= len4;
|
|
673
|
+
z *= len4;
|
|
674
|
+
s = Math.sin(rad);
|
|
675
|
+
c = Math.cos(rad);
|
|
676
|
+
t = 1 - c;
|
|
677
|
+
a00 = a[0];
|
|
678
|
+
a01 = a[1];
|
|
679
|
+
a02 = a[2];
|
|
680
|
+
a03 = a[3];
|
|
681
|
+
a10 = a[4];
|
|
682
|
+
a11 = a[5];
|
|
683
|
+
a12 = a[6];
|
|
684
|
+
a13 = a[7];
|
|
685
|
+
a20 = a[8];
|
|
686
|
+
a21 = a[9];
|
|
687
|
+
a22 = a[10];
|
|
688
|
+
a23 = a[11];
|
|
689
|
+
b00 = x * x * t + c;
|
|
690
|
+
b01 = y * x * t + z * s;
|
|
691
|
+
b02 = z * x * t - y * s;
|
|
692
|
+
b10 = x * y * t - z * s;
|
|
693
|
+
b11 = y * y * t + c;
|
|
694
|
+
b12 = z * y * t + x * s;
|
|
695
|
+
b20 = x * z * t + y * s;
|
|
696
|
+
b21 = y * z * t - x * s;
|
|
697
|
+
b22 = z * z * t + c;
|
|
698
|
+
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
699
|
+
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
700
|
+
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
701
|
+
out[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
|
702
|
+
out[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
|
703
|
+
out[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
|
704
|
+
out[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
|
705
|
+
out[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
|
706
|
+
out[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
|
707
|
+
out[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
|
708
|
+
out[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
|
709
|
+
out[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
|
710
|
+
if (a !== out) {
|
|
711
|
+
out[12] = a[12];
|
|
712
|
+
out[13] = a[13];
|
|
713
|
+
out[14] = a[14];
|
|
714
|
+
out[15] = a[15];
|
|
715
|
+
}
|
|
716
|
+
return out;
|
|
717
|
+
}
|
|
718
|
+
function rotateX(out, a, rad) {
|
|
719
|
+
var s = Math.sin(rad);
|
|
720
|
+
var c = Math.cos(rad);
|
|
721
|
+
var a10 = a[4];
|
|
722
|
+
var a11 = a[5];
|
|
723
|
+
var a12 = a[6];
|
|
724
|
+
var a13 = a[7];
|
|
725
|
+
var a20 = a[8];
|
|
726
|
+
var a21 = a[9];
|
|
727
|
+
var a22 = a[10];
|
|
728
|
+
var a23 = a[11];
|
|
729
|
+
if (a !== out) {
|
|
730
|
+
out[0] = a[0];
|
|
731
|
+
out[1] = a[1];
|
|
732
|
+
out[2] = a[2];
|
|
733
|
+
out[3] = a[3];
|
|
734
|
+
out[12] = a[12];
|
|
735
|
+
out[13] = a[13];
|
|
736
|
+
out[14] = a[14];
|
|
737
|
+
out[15] = a[15];
|
|
738
|
+
}
|
|
739
|
+
out[4] = a10 * c + a20 * s;
|
|
740
|
+
out[5] = a11 * c + a21 * s;
|
|
741
|
+
out[6] = a12 * c + a22 * s;
|
|
742
|
+
out[7] = a13 * c + a23 * s;
|
|
743
|
+
out[8] = a20 * c - a10 * s;
|
|
744
|
+
out[9] = a21 * c - a11 * s;
|
|
745
|
+
out[10] = a22 * c - a12 * s;
|
|
746
|
+
out[11] = a23 * c - a13 * s;
|
|
747
|
+
return out;
|
|
748
|
+
}
|
|
749
|
+
function rotateY(out, a, rad) {
|
|
750
|
+
var s = Math.sin(rad);
|
|
751
|
+
var c = Math.cos(rad);
|
|
752
|
+
var a00 = a[0];
|
|
753
|
+
var a01 = a[1];
|
|
754
|
+
var a02 = a[2];
|
|
755
|
+
var a03 = a[3];
|
|
756
|
+
var a20 = a[8];
|
|
757
|
+
var a21 = a[9];
|
|
758
|
+
var a22 = a[10];
|
|
759
|
+
var a23 = a[11];
|
|
760
|
+
if (a !== out) {
|
|
761
|
+
out[4] = a[4];
|
|
762
|
+
out[5] = a[5];
|
|
763
|
+
out[6] = a[6];
|
|
764
|
+
out[7] = a[7];
|
|
765
|
+
out[12] = a[12];
|
|
766
|
+
out[13] = a[13];
|
|
767
|
+
out[14] = a[14];
|
|
768
|
+
out[15] = a[15];
|
|
769
|
+
}
|
|
770
|
+
out[0] = a00 * c - a20 * s;
|
|
771
|
+
out[1] = a01 * c - a21 * s;
|
|
772
|
+
out[2] = a02 * c - a22 * s;
|
|
773
|
+
out[3] = a03 * c - a23 * s;
|
|
774
|
+
out[8] = a00 * s + a20 * c;
|
|
775
|
+
out[9] = a01 * s + a21 * c;
|
|
776
|
+
out[10] = a02 * s + a22 * c;
|
|
777
|
+
out[11] = a03 * s + a23 * c;
|
|
778
|
+
return out;
|
|
779
|
+
}
|
|
780
|
+
function rotateZ(out, a, rad) {
|
|
781
|
+
var s = Math.sin(rad);
|
|
782
|
+
var c = Math.cos(rad);
|
|
783
|
+
var a00 = a[0];
|
|
784
|
+
var a01 = a[1];
|
|
785
|
+
var a02 = a[2];
|
|
786
|
+
var a03 = a[3];
|
|
787
|
+
var a10 = a[4];
|
|
788
|
+
var a11 = a[5];
|
|
789
|
+
var a12 = a[6];
|
|
790
|
+
var a13 = a[7];
|
|
791
|
+
if (a !== out) {
|
|
792
|
+
out[8] = a[8];
|
|
793
|
+
out[9] = a[9];
|
|
794
|
+
out[10] = a[10];
|
|
795
|
+
out[11] = a[11];
|
|
796
|
+
out[12] = a[12];
|
|
797
|
+
out[13] = a[13];
|
|
798
|
+
out[14] = a[14];
|
|
799
|
+
out[15] = a[15];
|
|
800
|
+
}
|
|
801
|
+
out[0] = a00 * c + a10 * s;
|
|
802
|
+
out[1] = a01 * c + a11 * s;
|
|
803
|
+
out[2] = a02 * c + a12 * s;
|
|
804
|
+
out[3] = a03 * c + a13 * s;
|
|
805
|
+
out[4] = a10 * c - a00 * s;
|
|
806
|
+
out[5] = a11 * c - a01 * s;
|
|
807
|
+
out[6] = a12 * c - a02 * s;
|
|
808
|
+
out[7] = a13 * c - a03 * s;
|
|
809
|
+
return out;
|
|
810
|
+
}
|
|
811
|
+
function fromTranslation(out, v) {
|
|
812
|
+
out[0] = 1;
|
|
813
|
+
out[1] = 0;
|
|
814
|
+
out[2] = 0;
|
|
815
|
+
out[3] = 0;
|
|
816
|
+
out[4] = 0;
|
|
817
|
+
out[5] = 1;
|
|
818
|
+
out[6] = 0;
|
|
819
|
+
out[7] = 0;
|
|
820
|
+
out[8] = 0;
|
|
821
|
+
out[9] = 0;
|
|
822
|
+
out[10] = 1;
|
|
823
|
+
out[11] = 0;
|
|
824
|
+
out[12] = v[0];
|
|
825
|
+
out[13] = v[1];
|
|
826
|
+
out[14] = v[2];
|
|
827
|
+
out[15] = 1;
|
|
828
|
+
return out;
|
|
829
|
+
}
|
|
830
|
+
function fromScaling(out, v) {
|
|
831
|
+
out[0] = v[0];
|
|
832
|
+
out[1] = 0;
|
|
833
|
+
out[2] = 0;
|
|
834
|
+
out[3] = 0;
|
|
835
|
+
out[4] = 0;
|
|
836
|
+
out[5] = v[1];
|
|
837
|
+
out[6] = 0;
|
|
838
|
+
out[7] = 0;
|
|
839
|
+
out[8] = 0;
|
|
840
|
+
out[9] = 0;
|
|
841
|
+
out[10] = v[2];
|
|
842
|
+
out[11] = 0;
|
|
843
|
+
out[12] = 0;
|
|
844
|
+
out[13] = 0;
|
|
845
|
+
out[14] = 0;
|
|
846
|
+
out[15] = 1;
|
|
847
|
+
return out;
|
|
848
|
+
}
|
|
849
|
+
function fromRotation(out, rad, axis) {
|
|
850
|
+
var x = axis[0], y = axis[1], z = axis[2];
|
|
851
|
+
var len4 = Math.sqrt(x * x + y * y + z * z);
|
|
852
|
+
var s, c, t;
|
|
853
|
+
if (len4 < EPSILON) {
|
|
854
|
+
return null;
|
|
855
|
+
}
|
|
856
|
+
len4 = 1 / len4;
|
|
857
|
+
x *= len4;
|
|
858
|
+
y *= len4;
|
|
859
|
+
z *= len4;
|
|
860
|
+
s = Math.sin(rad);
|
|
861
|
+
c = Math.cos(rad);
|
|
862
|
+
t = 1 - c;
|
|
863
|
+
out[0] = x * x * t + c;
|
|
864
|
+
out[1] = y * x * t + z * s;
|
|
865
|
+
out[2] = z * x * t - y * s;
|
|
866
|
+
out[3] = 0;
|
|
867
|
+
out[4] = x * y * t - z * s;
|
|
868
|
+
out[5] = y * y * t + c;
|
|
869
|
+
out[6] = z * y * t + x * s;
|
|
870
|
+
out[7] = 0;
|
|
871
|
+
out[8] = x * z * t + y * s;
|
|
872
|
+
out[9] = y * z * t - x * s;
|
|
873
|
+
out[10] = z * z * t + c;
|
|
874
|
+
out[11] = 0;
|
|
875
|
+
out[12] = 0;
|
|
876
|
+
out[13] = 0;
|
|
877
|
+
out[14] = 0;
|
|
878
|
+
out[15] = 1;
|
|
879
|
+
return out;
|
|
880
|
+
}
|
|
881
|
+
function fromXRotation(out, rad) {
|
|
882
|
+
var s = Math.sin(rad);
|
|
883
|
+
var c = Math.cos(rad);
|
|
884
|
+
out[0] = 1;
|
|
885
|
+
out[1] = 0;
|
|
886
|
+
out[2] = 0;
|
|
887
|
+
out[3] = 0;
|
|
888
|
+
out[4] = 0;
|
|
889
|
+
out[5] = c;
|
|
890
|
+
out[6] = s;
|
|
891
|
+
out[7] = 0;
|
|
892
|
+
out[8] = 0;
|
|
893
|
+
out[9] = -s;
|
|
894
|
+
out[10] = c;
|
|
895
|
+
out[11] = 0;
|
|
896
|
+
out[12] = 0;
|
|
897
|
+
out[13] = 0;
|
|
898
|
+
out[14] = 0;
|
|
899
|
+
out[15] = 1;
|
|
900
|
+
return out;
|
|
901
|
+
}
|
|
902
|
+
function fromYRotation(out, rad) {
|
|
903
|
+
var s = Math.sin(rad);
|
|
904
|
+
var c = Math.cos(rad);
|
|
905
|
+
out[0] = c;
|
|
906
|
+
out[1] = 0;
|
|
907
|
+
out[2] = -s;
|
|
908
|
+
out[3] = 0;
|
|
909
|
+
out[4] = 0;
|
|
910
|
+
out[5] = 1;
|
|
911
|
+
out[6] = 0;
|
|
912
|
+
out[7] = 0;
|
|
913
|
+
out[8] = s;
|
|
914
|
+
out[9] = 0;
|
|
915
|
+
out[10] = c;
|
|
916
|
+
out[11] = 0;
|
|
917
|
+
out[12] = 0;
|
|
918
|
+
out[13] = 0;
|
|
919
|
+
out[14] = 0;
|
|
920
|
+
out[15] = 1;
|
|
921
|
+
return out;
|
|
922
|
+
}
|
|
923
|
+
function fromZRotation(out, rad) {
|
|
924
|
+
var s = Math.sin(rad);
|
|
925
|
+
var c = Math.cos(rad);
|
|
926
|
+
out[0] = c;
|
|
927
|
+
out[1] = s;
|
|
928
|
+
out[2] = 0;
|
|
929
|
+
out[3] = 0;
|
|
930
|
+
out[4] = -s;
|
|
931
|
+
out[5] = c;
|
|
932
|
+
out[6] = 0;
|
|
933
|
+
out[7] = 0;
|
|
934
|
+
out[8] = 0;
|
|
935
|
+
out[9] = 0;
|
|
936
|
+
out[10] = 1;
|
|
937
|
+
out[11] = 0;
|
|
938
|
+
out[12] = 0;
|
|
939
|
+
out[13] = 0;
|
|
940
|
+
out[14] = 0;
|
|
941
|
+
out[15] = 1;
|
|
942
|
+
return out;
|
|
943
|
+
}
|
|
944
|
+
function fromRotationTranslation(out, q, v) {
|
|
945
|
+
var x = q[0], y = q[1], z = q[2], w = q[3];
|
|
946
|
+
var x2 = x + x;
|
|
947
|
+
var y2 = y + y;
|
|
948
|
+
var z2 = z + z;
|
|
949
|
+
var xx = x * x2;
|
|
950
|
+
var xy = x * y2;
|
|
951
|
+
var xz = x * z2;
|
|
952
|
+
var yy = y * y2;
|
|
953
|
+
var yz = y * z2;
|
|
954
|
+
var zz = z * z2;
|
|
955
|
+
var wx = w * x2;
|
|
956
|
+
var wy = w * y2;
|
|
957
|
+
var wz = w * z2;
|
|
958
|
+
out[0] = 1 - (yy + zz);
|
|
959
|
+
out[1] = xy + wz;
|
|
960
|
+
out[2] = xz - wy;
|
|
961
|
+
out[3] = 0;
|
|
962
|
+
out[4] = xy - wz;
|
|
963
|
+
out[5] = 1 - (xx + zz);
|
|
964
|
+
out[6] = yz + wx;
|
|
965
|
+
out[7] = 0;
|
|
966
|
+
out[8] = xz + wy;
|
|
967
|
+
out[9] = yz - wx;
|
|
968
|
+
out[10] = 1 - (xx + yy);
|
|
969
|
+
out[11] = 0;
|
|
970
|
+
out[12] = v[0];
|
|
971
|
+
out[13] = v[1];
|
|
972
|
+
out[14] = v[2];
|
|
973
|
+
out[15] = 1;
|
|
974
|
+
return out;
|
|
975
|
+
}
|
|
976
|
+
function fromQuat2(out, a) {
|
|
977
|
+
var translation = new ARRAY_TYPE(3);
|
|
978
|
+
var bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7];
|
|
979
|
+
var magnitude = bx * bx + by * by + bz * bz + bw * bw;
|
|
980
|
+
if (magnitude > 0) {
|
|
981
|
+
translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;
|
|
982
|
+
translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;
|
|
983
|
+
translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;
|
|
984
|
+
} else {
|
|
985
|
+
translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
|
|
986
|
+
translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
|
|
987
|
+
translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
|
|
988
|
+
}
|
|
989
|
+
fromRotationTranslation(out, a, translation);
|
|
990
|
+
return out;
|
|
991
|
+
}
|
|
992
|
+
function getTranslation(out, mat) {
|
|
993
|
+
out[0] = mat[12];
|
|
994
|
+
out[1] = mat[13];
|
|
995
|
+
out[2] = mat[14];
|
|
996
|
+
return out;
|
|
997
|
+
}
|
|
998
|
+
function getScaling(out, mat) {
|
|
999
|
+
var m11 = mat[0];
|
|
1000
|
+
var m12 = mat[1];
|
|
1001
|
+
var m13 = mat[2];
|
|
1002
|
+
var m21 = mat[4];
|
|
1003
|
+
var m22 = mat[5];
|
|
1004
|
+
var m23 = mat[6];
|
|
1005
|
+
var m31 = mat[8];
|
|
1006
|
+
var m32 = mat[9];
|
|
1007
|
+
var m33 = mat[10];
|
|
1008
|
+
out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
|
|
1009
|
+
out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
|
|
1010
|
+
out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
|
|
1011
|
+
return out;
|
|
1012
|
+
}
|
|
1013
|
+
function getRotation(out, mat) {
|
|
1014
|
+
var scaling = new ARRAY_TYPE(3);
|
|
1015
|
+
getScaling(scaling, mat);
|
|
1016
|
+
var is1 = 1 / scaling[0];
|
|
1017
|
+
var is2 = 1 / scaling[1];
|
|
1018
|
+
var is3 = 1 / scaling[2];
|
|
1019
|
+
var sm11 = mat[0] * is1;
|
|
1020
|
+
var sm12 = mat[1] * is2;
|
|
1021
|
+
var sm13 = mat[2] * is3;
|
|
1022
|
+
var sm21 = mat[4] * is1;
|
|
1023
|
+
var sm22 = mat[5] * is2;
|
|
1024
|
+
var sm23 = mat[6] * is3;
|
|
1025
|
+
var sm31 = mat[8] * is1;
|
|
1026
|
+
var sm32 = mat[9] * is2;
|
|
1027
|
+
var sm33 = mat[10] * is3;
|
|
1028
|
+
var trace = sm11 + sm22 + sm33;
|
|
1029
|
+
var S = 0;
|
|
1030
|
+
if (trace > 0) {
|
|
1031
|
+
S = Math.sqrt(trace + 1) * 2;
|
|
1032
|
+
out[3] = 0.25 * S;
|
|
1033
|
+
out[0] = (sm23 - sm32) / S;
|
|
1034
|
+
out[1] = (sm31 - sm13) / S;
|
|
1035
|
+
out[2] = (sm12 - sm21) / S;
|
|
1036
|
+
} else if (sm11 > sm22 && sm11 > sm33) {
|
|
1037
|
+
S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
|
|
1038
|
+
out[3] = (sm23 - sm32) / S;
|
|
1039
|
+
out[0] = 0.25 * S;
|
|
1040
|
+
out[1] = (sm12 + sm21) / S;
|
|
1041
|
+
out[2] = (sm31 + sm13) / S;
|
|
1042
|
+
} else if (sm22 > sm33) {
|
|
1043
|
+
S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
|
|
1044
|
+
out[3] = (sm31 - sm13) / S;
|
|
1045
|
+
out[0] = (sm12 + sm21) / S;
|
|
1046
|
+
out[1] = 0.25 * S;
|
|
1047
|
+
out[2] = (sm23 + sm32) / S;
|
|
1048
|
+
} else {
|
|
1049
|
+
S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
|
|
1050
|
+
out[3] = (sm12 - sm21) / S;
|
|
1051
|
+
out[0] = (sm31 + sm13) / S;
|
|
1052
|
+
out[1] = (sm23 + sm32) / S;
|
|
1053
|
+
out[2] = 0.25 * S;
|
|
1054
|
+
}
|
|
1055
|
+
return out;
|
|
1056
|
+
}
|
|
1057
|
+
function decompose(out_r, out_t, out_s, mat) {
|
|
1058
|
+
out_t[0] = mat[12];
|
|
1059
|
+
out_t[1] = mat[13];
|
|
1060
|
+
out_t[2] = mat[14];
|
|
1061
|
+
var m11 = mat[0];
|
|
1062
|
+
var m12 = mat[1];
|
|
1063
|
+
var m13 = mat[2];
|
|
1064
|
+
var m21 = mat[4];
|
|
1065
|
+
var m22 = mat[5];
|
|
1066
|
+
var m23 = mat[6];
|
|
1067
|
+
var m31 = mat[8];
|
|
1068
|
+
var m32 = mat[9];
|
|
1069
|
+
var m33 = mat[10];
|
|
1070
|
+
out_s[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
|
|
1071
|
+
out_s[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
|
|
1072
|
+
out_s[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
|
|
1073
|
+
var is1 = 1 / out_s[0];
|
|
1074
|
+
var is2 = 1 / out_s[1];
|
|
1075
|
+
var is3 = 1 / out_s[2];
|
|
1076
|
+
var sm11 = m11 * is1;
|
|
1077
|
+
var sm12 = m12 * is2;
|
|
1078
|
+
var sm13 = m13 * is3;
|
|
1079
|
+
var sm21 = m21 * is1;
|
|
1080
|
+
var sm22 = m22 * is2;
|
|
1081
|
+
var sm23 = m23 * is3;
|
|
1082
|
+
var sm31 = m31 * is1;
|
|
1083
|
+
var sm32 = m32 * is2;
|
|
1084
|
+
var sm33 = m33 * is3;
|
|
1085
|
+
var trace = sm11 + sm22 + sm33;
|
|
1086
|
+
var S = 0;
|
|
1087
|
+
if (trace > 0) {
|
|
1088
|
+
S = Math.sqrt(trace + 1) * 2;
|
|
1089
|
+
out_r[3] = 0.25 * S;
|
|
1090
|
+
out_r[0] = (sm23 - sm32) / S;
|
|
1091
|
+
out_r[1] = (sm31 - sm13) / S;
|
|
1092
|
+
out_r[2] = (sm12 - sm21) / S;
|
|
1093
|
+
} else if (sm11 > sm22 && sm11 > sm33) {
|
|
1094
|
+
S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
|
|
1095
|
+
out_r[3] = (sm23 - sm32) / S;
|
|
1096
|
+
out_r[0] = 0.25 * S;
|
|
1097
|
+
out_r[1] = (sm12 + sm21) / S;
|
|
1098
|
+
out_r[2] = (sm31 + sm13) / S;
|
|
1099
|
+
} else if (sm22 > sm33) {
|
|
1100
|
+
S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
|
|
1101
|
+
out_r[3] = (sm31 - sm13) / S;
|
|
1102
|
+
out_r[0] = (sm12 + sm21) / S;
|
|
1103
|
+
out_r[1] = 0.25 * S;
|
|
1104
|
+
out_r[2] = (sm23 + sm32) / S;
|
|
1105
|
+
} else {
|
|
1106
|
+
S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
|
|
1107
|
+
out_r[3] = (sm12 - sm21) / S;
|
|
1108
|
+
out_r[0] = (sm31 + sm13) / S;
|
|
1109
|
+
out_r[1] = (sm23 + sm32) / S;
|
|
1110
|
+
out_r[2] = 0.25 * S;
|
|
1111
|
+
}
|
|
1112
|
+
return out_r;
|
|
1113
|
+
}
|
|
1114
|
+
function fromRotationTranslationScale(out, q, v, s) {
|
|
1115
|
+
var x = q[0], y = q[1], z = q[2], w = q[3];
|
|
1116
|
+
var x2 = x + x;
|
|
1117
|
+
var y2 = y + y;
|
|
1118
|
+
var z2 = z + z;
|
|
1119
|
+
var xx = x * x2;
|
|
1120
|
+
var xy = x * y2;
|
|
1121
|
+
var xz = x * z2;
|
|
1122
|
+
var yy = y * y2;
|
|
1123
|
+
var yz = y * z2;
|
|
1124
|
+
var zz = z * z2;
|
|
1125
|
+
var wx = w * x2;
|
|
1126
|
+
var wy = w * y2;
|
|
1127
|
+
var wz = w * z2;
|
|
1128
|
+
var sx = s[0];
|
|
1129
|
+
var sy = s[1];
|
|
1130
|
+
var sz = s[2];
|
|
1131
|
+
out[0] = (1 - (yy + zz)) * sx;
|
|
1132
|
+
out[1] = (xy + wz) * sx;
|
|
1133
|
+
out[2] = (xz - wy) * sx;
|
|
1134
|
+
out[3] = 0;
|
|
1135
|
+
out[4] = (xy - wz) * sy;
|
|
1136
|
+
out[5] = (1 - (xx + zz)) * sy;
|
|
1137
|
+
out[6] = (yz + wx) * sy;
|
|
1138
|
+
out[7] = 0;
|
|
1139
|
+
out[8] = (xz + wy) * sz;
|
|
1140
|
+
out[9] = (yz - wx) * sz;
|
|
1141
|
+
out[10] = (1 - (xx + yy)) * sz;
|
|
1142
|
+
out[11] = 0;
|
|
1143
|
+
out[12] = v[0];
|
|
1144
|
+
out[13] = v[1];
|
|
1145
|
+
out[14] = v[2];
|
|
1146
|
+
out[15] = 1;
|
|
1147
|
+
return out;
|
|
1148
|
+
}
|
|
1149
|
+
function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
|
|
1150
|
+
var x = q[0], y = q[1], z = q[2], w = q[3];
|
|
1151
|
+
var x2 = x + x;
|
|
1152
|
+
var y2 = y + y;
|
|
1153
|
+
var z2 = z + z;
|
|
1154
|
+
var xx = x * x2;
|
|
1155
|
+
var xy = x * y2;
|
|
1156
|
+
var xz = x * z2;
|
|
1157
|
+
var yy = y * y2;
|
|
1158
|
+
var yz = y * z2;
|
|
1159
|
+
var zz = z * z2;
|
|
1160
|
+
var wx = w * x2;
|
|
1161
|
+
var wy = w * y2;
|
|
1162
|
+
var wz = w * z2;
|
|
1163
|
+
var sx = s[0];
|
|
1164
|
+
var sy = s[1];
|
|
1165
|
+
var sz = s[2];
|
|
1166
|
+
var ox = o[0];
|
|
1167
|
+
var oy = o[1];
|
|
1168
|
+
var oz = o[2];
|
|
1169
|
+
var out0 = (1 - (yy + zz)) * sx;
|
|
1170
|
+
var out1 = (xy + wz) * sx;
|
|
1171
|
+
var out2 = (xz - wy) * sx;
|
|
1172
|
+
var out4 = (xy - wz) * sy;
|
|
1173
|
+
var out5 = (1 - (xx + zz)) * sy;
|
|
1174
|
+
var out6 = (yz + wx) * sy;
|
|
1175
|
+
var out8 = (xz + wy) * sz;
|
|
1176
|
+
var out9 = (yz - wx) * sz;
|
|
1177
|
+
var out10 = (1 - (xx + yy)) * sz;
|
|
1178
|
+
out[0] = out0;
|
|
1179
|
+
out[1] = out1;
|
|
1180
|
+
out[2] = out2;
|
|
1181
|
+
out[3] = 0;
|
|
1182
|
+
out[4] = out4;
|
|
1183
|
+
out[5] = out5;
|
|
1184
|
+
out[6] = out6;
|
|
1185
|
+
out[7] = 0;
|
|
1186
|
+
out[8] = out8;
|
|
1187
|
+
out[9] = out9;
|
|
1188
|
+
out[10] = out10;
|
|
1189
|
+
out[11] = 0;
|
|
1190
|
+
out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
|
|
1191
|
+
out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
|
|
1192
|
+
out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
|
|
1193
|
+
out[15] = 1;
|
|
1194
|
+
return out;
|
|
1195
|
+
}
|
|
1196
|
+
function fromQuat(out, q) {
|
|
1197
|
+
var x = q[0], y = q[1], z = q[2], w = q[3];
|
|
1198
|
+
var x2 = x + x;
|
|
1199
|
+
var y2 = y + y;
|
|
1200
|
+
var z2 = z + z;
|
|
1201
|
+
var xx = x * x2;
|
|
1202
|
+
var yx = y * x2;
|
|
1203
|
+
var yy = y * y2;
|
|
1204
|
+
var zx = z * x2;
|
|
1205
|
+
var zy = z * y2;
|
|
1206
|
+
var zz = z * z2;
|
|
1207
|
+
var wx = w * x2;
|
|
1208
|
+
var wy = w * y2;
|
|
1209
|
+
var wz = w * z2;
|
|
1210
|
+
out[0] = 1 - yy - zz;
|
|
1211
|
+
out[1] = yx + wz;
|
|
1212
|
+
out[2] = zx - wy;
|
|
1213
|
+
out[3] = 0;
|
|
1214
|
+
out[4] = yx - wz;
|
|
1215
|
+
out[5] = 1 - xx - zz;
|
|
1216
|
+
out[6] = zy + wx;
|
|
1217
|
+
out[7] = 0;
|
|
1218
|
+
out[8] = zx + wy;
|
|
1219
|
+
out[9] = zy - wx;
|
|
1220
|
+
out[10] = 1 - xx - yy;
|
|
1221
|
+
out[11] = 0;
|
|
1222
|
+
out[12] = 0;
|
|
1223
|
+
out[13] = 0;
|
|
1224
|
+
out[14] = 0;
|
|
1225
|
+
out[15] = 1;
|
|
1226
|
+
return out;
|
|
1227
|
+
}
|
|
1228
|
+
function frustum(out, left, right, bottom, top, near, far) {
|
|
1229
|
+
var rl = 1 / (right - left);
|
|
1230
|
+
var tb = 1 / (top - bottom);
|
|
1231
|
+
var nf = 1 / (near - far);
|
|
1232
|
+
out[0] = near * 2 * rl;
|
|
1233
|
+
out[1] = 0;
|
|
1234
|
+
out[2] = 0;
|
|
1235
|
+
out[3] = 0;
|
|
1236
|
+
out[4] = 0;
|
|
1237
|
+
out[5] = near * 2 * tb;
|
|
1238
|
+
out[6] = 0;
|
|
1239
|
+
out[7] = 0;
|
|
1240
|
+
out[8] = (right + left) * rl;
|
|
1241
|
+
out[9] = (top + bottom) * tb;
|
|
1242
|
+
out[10] = (far + near) * nf;
|
|
1243
|
+
out[11] = -1;
|
|
1244
|
+
out[12] = 0;
|
|
1245
|
+
out[13] = 0;
|
|
1246
|
+
out[14] = far * near * 2 * nf;
|
|
1247
|
+
out[15] = 0;
|
|
1248
|
+
return out;
|
|
1249
|
+
}
|
|
1250
|
+
function perspectiveNO(out, fovy, aspect, near, far) {
|
|
1251
|
+
var f = 1 / Math.tan(fovy / 2);
|
|
1252
|
+
out[0] = f / aspect;
|
|
1253
|
+
out[1] = 0;
|
|
1254
|
+
out[2] = 0;
|
|
1255
|
+
out[3] = 0;
|
|
1256
|
+
out[4] = 0;
|
|
1257
|
+
out[5] = f;
|
|
1258
|
+
out[6] = 0;
|
|
1259
|
+
out[7] = 0;
|
|
1260
|
+
out[8] = 0;
|
|
1261
|
+
out[9] = 0;
|
|
1262
|
+
out[11] = -1;
|
|
1263
|
+
out[12] = 0;
|
|
1264
|
+
out[13] = 0;
|
|
1265
|
+
out[15] = 0;
|
|
1266
|
+
if (far != null && far !== Infinity) {
|
|
1267
|
+
var nf = 1 / (near - far);
|
|
1268
|
+
out[10] = (far + near) * nf;
|
|
1269
|
+
out[14] = 2 * far * near * nf;
|
|
1270
|
+
} else {
|
|
1271
|
+
out[10] = -1;
|
|
1272
|
+
out[14] = -2 * near;
|
|
1273
|
+
}
|
|
1274
|
+
return out;
|
|
1275
|
+
}
|
|
1276
|
+
var perspective = perspectiveNO;
|
|
1277
|
+
function perspectiveZO(out, fovy, aspect, near, far) {
|
|
1278
|
+
var f = 1 / Math.tan(fovy / 2);
|
|
1279
|
+
out[0] = f / aspect;
|
|
1280
|
+
out[1] = 0;
|
|
1281
|
+
out[2] = 0;
|
|
1282
|
+
out[3] = 0;
|
|
1283
|
+
out[4] = 0;
|
|
1284
|
+
out[5] = f;
|
|
1285
|
+
out[6] = 0;
|
|
1286
|
+
out[7] = 0;
|
|
1287
|
+
out[8] = 0;
|
|
1288
|
+
out[9] = 0;
|
|
1289
|
+
out[11] = -1;
|
|
1290
|
+
out[12] = 0;
|
|
1291
|
+
out[13] = 0;
|
|
1292
|
+
out[15] = 0;
|
|
1293
|
+
if (far != null && far !== Infinity) {
|
|
1294
|
+
var nf = 1 / (near - far);
|
|
1295
|
+
out[10] = far * nf;
|
|
1296
|
+
out[14] = far * near * nf;
|
|
1297
|
+
} else {
|
|
1298
|
+
out[10] = -1;
|
|
1299
|
+
out[14] = -near;
|
|
1300
|
+
}
|
|
1301
|
+
return out;
|
|
1302
|
+
}
|
|
1303
|
+
function perspectiveFromFieldOfView(out, fov, near, far) {
|
|
1304
|
+
var upTan = Math.tan(fov.upDegrees * Math.PI / 180);
|
|
1305
|
+
var downTan = Math.tan(fov.downDegrees * Math.PI / 180);
|
|
1306
|
+
var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180);
|
|
1307
|
+
var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180);
|
|
1308
|
+
var xScale = 2 / (leftTan + rightTan);
|
|
1309
|
+
var yScale = 2 / (upTan + downTan);
|
|
1310
|
+
out[0] = xScale;
|
|
1311
|
+
out[1] = 0;
|
|
1312
|
+
out[2] = 0;
|
|
1313
|
+
out[3] = 0;
|
|
1314
|
+
out[4] = 0;
|
|
1315
|
+
out[5] = yScale;
|
|
1316
|
+
out[6] = 0;
|
|
1317
|
+
out[7] = 0;
|
|
1318
|
+
out[8] = -((leftTan - rightTan) * xScale * 0.5);
|
|
1319
|
+
out[9] = (upTan - downTan) * yScale * 0.5;
|
|
1320
|
+
out[10] = far / (near - far);
|
|
1321
|
+
out[11] = -1;
|
|
1322
|
+
out[12] = 0;
|
|
1323
|
+
out[13] = 0;
|
|
1324
|
+
out[14] = far * near / (near - far);
|
|
1325
|
+
out[15] = 0;
|
|
1326
|
+
return out;
|
|
1327
|
+
}
|
|
1328
|
+
function orthoNO(out, left, right, bottom, top, near, far) {
|
|
1329
|
+
var lr = 1 / (left - right);
|
|
1330
|
+
var bt = 1 / (bottom - top);
|
|
1331
|
+
var nf = 1 / (near - far);
|
|
1332
|
+
out[0] = -2 * lr;
|
|
1333
|
+
out[1] = 0;
|
|
1334
|
+
out[2] = 0;
|
|
1335
|
+
out[3] = 0;
|
|
1336
|
+
out[4] = 0;
|
|
1337
|
+
out[5] = -2 * bt;
|
|
1338
|
+
out[6] = 0;
|
|
1339
|
+
out[7] = 0;
|
|
1340
|
+
out[8] = 0;
|
|
1341
|
+
out[9] = 0;
|
|
1342
|
+
out[10] = 2 * nf;
|
|
1343
|
+
out[11] = 0;
|
|
1344
|
+
out[12] = (left + right) * lr;
|
|
1345
|
+
out[13] = (top + bottom) * bt;
|
|
1346
|
+
out[14] = (far + near) * nf;
|
|
1347
|
+
out[15] = 1;
|
|
1348
|
+
return out;
|
|
1349
|
+
}
|
|
1350
|
+
var ortho = orthoNO;
|
|
1351
|
+
function orthoZO(out, left, right, bottom, top, near, far) {
|
|
1352
|
+
var lr = 1 / (left - right);
|
|
1353
|
+
var bt = 1 / (bottom - top);
|
|
1354
|
+
var nf = 1 / (near - far);
|
|
1355
|
+
out[0] = -2 * lr;
|
|
1356
|
+
out[1] = 0;
|
|
1357
|
+
out[2] = 0;
|
|
1358
|
+
out[3] = 0;
|
|
1359
|
+
out[4] = 0;
|
|
1360
|
+
out[5] = -2 * bt;
|
|
1361
|
+
out[6] = 0;
|
|
1362
|
+
out[7] = 0;
|
|
1363
|
+
out[8] = 0;
|
|
1364
|
+
out[9] = 0;
|
|
1365
|
+
out[10] = nf;
|
|
1366
|
+
out[11] = 0;
|
|
1367
|
+
out[12] = (left + right) * lr;
|
|
1368
|
+
out[13] = (top + bottom) * bt;
|
|
1369
|
+
out[14] = near * nf;
|
|
1370
|
+
out[15] = 1;
|
|
1371
|
+
return out;
|
|
1372
|
+
}
|
|
1373
|
+
function lookAt(out, eye, center, up) {
|
|
1374
|
+
var x0, x1, x2, y0, y1, y2, z0, z1, z2, len4;
|
|
1375
|
+
var eyex = eye[0];
|
|
1376
|
+
var eyey = eye[1];
|
|
1377
|
+
var eyez = eye[2];
|
|
1378
|
+
var upx = up[0];
|
|
1379
|
+
var upy = up[1];
|
|
1380
|
+
var upz = up[2];
|
|
1381
|
+
var centerx = center[0];
|
|
1382
|
+
var centery = center[1];
|
|
1383
|
+
var centerz = center[2];
|
|
1384
|
+
if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {
|
|
1385
|
+
return identity(out);
|
|
1386
|
+
}
|
|
1387
|
+
z0 = eyex - centerx;
|
|
1388
|
+
z1 = eyey - centery;
|
|
1389
|
+
z2 = eyez - centerz;
|
|
1390
|
+
len4 = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
|
|
1391
|
+
z0 *= len4;
|
|
1392
|
+
z1 *= len4;
|
|
1393
|
+
z2 *= len4;
|
|
1394
|
+
x0 = upy * z2 - upz * z1;
|
|
1395
|
+
x1 = upz * z0 - upx * z2;
|
|
1396
|
+
x2 = upx * z1 - upy * z0;
|
|
1397
|
+
len4 = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
|
|
1398
|
+
if (!len4) {
|
|
1399
|
+
x0 = 0;
|
|
1400
|
+
x1 = 0;
|
|
1401
|
+
x2 = 0;
|
|
1402
|
+
} else {
|
|
1403
|
+
len4 = 1 / len4;
|
|
1404
|
+
x0 *= len4;
|
|
1405
|
+
x1 *= len4;
|
|
1406
|
+
x2 *= len4;
|
|
1407
|
+
}
|
|
1408
|
+
y0 = z1 * x2 - z2 * x1;
|
|
1409
|
+
y1 = z2 * x0 - z0 * x2;
|
|
1410
|
+
y2 = z0 * x1 - z1 * x0;
|
|
1411
|
+
len4 = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
|
|
1412
|
+
if (!len4) {
|
|
1413
|
+
y0 = 0;
|
|
1414
|
+
y1 = 0;
|
|
1415
|
+
y2 = 0;
|
|
1416
|
+
} else {
|
|
1417
|
+
len4 = 1 / len4;
|
|
1418
|
+
y0 *= len4;
|
|
1419
|
+
y1 *= len4;
|
|
1420
|
+
y2 *= len4;
|
|
1421
|
+
}
|
|
1422
|
+
out[0] = x0;
|
|
1423
|
+
out[1] = y0;
|
|
1424
|
+
out[2] = z0;
|
|
1425
|
+
out[3] = 0;
|
|
1426
|
+
out[4] = x1;
|
|
1427
|
+
out[5] = y1;
|
|
1428
|
+
out[6] = z1;
|
|
1429
|
+
out[7] = 0;
|
|
1430
|
+
out[8] = x2;
|
|
1431
|
+
out[9] = y2;
|
|
1432
|
+
out[10] = z2;
|
|
1433
|
+
out[11] = 0;
|
|
1434
|
+
out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
|
|
1435
|
+
out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
|
|
1436
|
+
out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
|
|
1437
|
+
out[15] = 1;
|
|
1438
|
+
return out;
|
|
1439
|
+
}
|
|
1440
|
+
function targetTo(out, eye, target, up) {
|
|
1441
|
+
var eyex = eye[0], eyey = eye[1], eyez = eye[2], upx = up[0], upy = up[1], upz = up[2];
|
|
1442
|
+
var z0 = eyex - target[0], z1 = eyey - target[1], z2 = eyez - target[2];
|
|
1443
|
+
var len4 = z0 * z0 + z1 * z1 + z2 * z2;
|
|
1444
|
+
if (len4 > 0) {
|
|
1445
|
+
len4 = 1 / Math.sqrt(len4);
|
|
1446
|
+
z0 *= len4;
|
|
1447
|
+
z1 *= len4;
|
|
1448
|
+
z2 *= len4;
|
|
1449
|
+
}
|
|
1450
|
+
var x0 = upy * z2 - upz * z1, x1 = upz * z0 - upx * z2, x2 = upx * z1 - upy * z0;
|
|
1451
|
+
len4 = x0 * x0 + x1 * x1 + x2 * x2;
|
|
1452
|
+
if (len4 > 0) {
|
|
1453
|
+
len4 = 1 / Math.sqrt(len4);
|
|
1454
|
+
x0 *= len4;
|
|
1455
|
+
x1 *= len4;
|
|
1456
|
+
x2 *= len4;
|
|
1457
|
+
}
|
|
1458
|
+
out[0] = x0;
|
|
1459
|
+
out[1] = x1;
|
|
1460
|
+
out[2] = x2;
|
|
1461
|
+
out[3] = 0;
|
|
1462
|
+
out[4] = z1 * x2 - z2 * x1;
|
|
1463
|
+
out[5] = z2 * x0 - z0 * x2;
|
|
1464
|
+
out[6] = z0 * x1 - z1 * x0;
|
|
1465
|
+
out[7] = 0;
|
|
1466
|
+
out[8] = z0;
|
|
1467
|
+
out[9] = z1;
|
|
1468
|
+
out[10] = z2;
|
|
1469
|
+
out[11] = 0;
|
|
1470
|
+
out[12] = eyex;
|
|
1471
|
+
out[13] = eyey;
|
|
1472
|
+
out[14] = eyez;
|
|
1473
|
+
out[15] = 1;
|
|
1474
|
+
return out;
|
|
1475
|
+
}
|
|
1476
|
+
function str(a) {
|
|
1477
|
+
return "mat4(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ", " + a[4] + ", " + a[5] + ", " + a[6] + ", " + a[7] + ", " + a[8] + ", " + a[9] + ", " + a[10] + ", " + a[11] + ", " + a[12] + ", " + a[13] + ", " + a[14] + ", " + a[15] + ")";
|
|
1478
|
+
}
|
|
1479
|
+
function frob(a) {
|
|
1480
|
+
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3] + a[4] * a[4] + a[5] * a[5] + a[6] * a[6] + a[7] * a[7] + a[8] * a[8] + a[9] * a[9] + a[10] * a[10] + a[11] * a[11] + a[12] * a[12] + a[13] * a[13] + a[14] * a[14] + a[15] * a[15]);
|
|
1481
|
+
}
|
|
1482
|
+
function add(out, a, b) {
|
|
1483
|
+
out[0] = a[0] + b[0];
|
|
1484
|
+
out[1] = a[1] + b[1];
|
|
1485
|
+
out[2] = a[2] + b[2];
|
|
1486
|
+
out[3] = a[3] + b[3];
|
|
1487
|
+
out[4] = a[4] + b[4];
|
|
1488
|
+
out[5] = a[5] + b[5];
|
|
1489
|
+
out[6] = a[6] + b[6];
|
|
1490
|
+
out[7] = a[7] + b[7];
|
|
1491
|
+
out[8] = a[8] + b[8];
|
|
1492
|
+
out[9] = a[9] + b[9];
|
|
1493
|
+
out[10] = a[10] + b[10];
|
|
1494
|
+
out[11] = a[11] + b[11];
|
|
1495
|
+
out[12] = a[12] + b[12];
|
|
1496
|
+
out[13] = a[13] + b[13];
|
|
1497
|
+
out[14] = a[14] + b[14];
|
|
1498
|
+
out[15] = a[15] + b[15];
|
|
1499
|
+
return out;
|
|
1500
|
+
}
|
|
1501
|
+
function subtract(out, a, b) {
|
|
1502
|
+
out[0] = a[0] - b[0];
|
|
1503
|
+
out[1] = a[1] - b[1];
|
|
1504
|
+
out[2] = a[2] - b[2];
|
|
1505
|
+
out[3] = a[3] - b[3];
|
|
1506
|
+
out[4] = a[4] - b[4];
|
|
1507
|
+
out[5] = a[5] - b[5];
|
|
1508
|
+
out[6] = a[6] - b[6];
|
|
1509
|
+
out[7] = a[7] - b[7];
|
|
1510
|
+
out[8] = a[8] - b[8];
|
|
1511
|
+
out[9] = a[9] - b[9];
|
|
1512
|
+
out[10] = a[10] - b[10];
|
|
1513
|
+
out[11] = a[11] - b[11];
|
|
1514
|
+
out[12] = a[12] - b[12];
|
|
1515
|
+
out[13] = a[13] - b[13];
|
|
1516
|
+
out[14] = a[14] - b[14];
|
|
1517
|
+
out[15] = a[15] - b[15];
|
|
1518
|
+
return out;
|
|
1519
|
+
}
|
|
1520
|
+
function multiplyScalar(out, a, b) {
|
|
1521
|
+
out[0] = a[0] * b;
|
|
1522
|
+
out[1] = a[1] * b;
|
|
1523
|
+
out[2] = a[2] * b;
|
|
1524
|
+
out[3] = a[3] * b;
|
|
1525
|
+
out[4] = a[4] * b;
|
|
1526
|
+
out[5] = a[5] * b;
|
|
1527
|
+
out[6] = a[6] * b;
|
|
1528
|
+
out[7] = a[7] * b;
|
|
1529
|
+
out[8] = a[8] * b;
|
|
1530
|
+
out[9] = a[9] * b;
|
|
1531
|
+
out[10] = a[10] * b;
|
|
1532
|
+
out[11] = a[11] * b;
|
|
1533
|
+
out[12] = a[12] * b;
|
|
1534
|
+
out[13] = a[13] * b;
|
|
1535
|
+
out[14] = a[14] * b;
|
|
1536
|
+
out[15] = a[15] * b;
|
|
1537
|
+
return out;
|
|
1538
|
+
}
|
|
1539
|
+
function multiplyScalarAndAdd(out, a, b, scale5) {
|
|
1540
|
+
out[0] = a[0] + b[0] * scale5;
|
|
1541
|
+
out[1] = a[1] + b[1] * scale5;
|
|
1542
|
+
out[2] = a[2] + b[2] * scale5;
|
|
1543
|
+
out[3] = a[3] + b[3] * scale5;
|
|
1544
|
+
out[4] = a[4] + b[4] * scale5;
|
|
1545
|
+
out[5] = a[5] + b[5] * scale5;
|
|
1546
|
+
out[6] = a[6] + b[6] * scale5;
|
|
1547
|
+
out[7] = a[7] + b[7] * scale5;
|
|
1548
|
+
out[8] = a[8] + b[8] * scale5;
|
|
1549
|
+
out[9] = a[9] + b[9] * scale5;
|
|
1550
|
+
out[10] = a[10] + b[10] * scale5;
|
|
1551
|
+
out[11] = a[11] + b[11] * scale5;
|
|
1552
|
+
out[12] = a[12] + b[12] * scale5;
|
|
1553
|
+
out[13] = a[13] + b[13] * scale5;
|
|
1554
|
+
out[14] = a[14] + b[14] * scale5;
|
|
1555
|
+
out[15] = a[15] + b[15] * scale5;
|
|
1556
|
+
return out;
|
|
1557
|
+
}
|
|
1558
|
+
function exactEquals(a, b) {
|
|
1559
|
+
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] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];
|
|
1560
|
+
}
|
|
1561
|
+
function equals(a, b) {
|
|
1562
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
|
|
1563
|
+
var a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7];
|
|
1564
|
+
var a8 = a[8], a9 = a[9], a10 = a[10], a11 = a[11];
|
|
1565
|
+
var a12 = a[12], a13 = a[13], a14 = a[14], a15 = a[15];
|
|
1566
|
+
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
|
1567
|
+
var b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7];
|
|
1568
|
+
var b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11];
|
|
1569
|
+
var b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
|
|
1570
|
+
return Math.abs(a0 - b0) <= EPSILON * Math.max(1, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= EPSILON * Math.max(1, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= EPSILON * Math.max(1, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= EPSILON * Math.max(1, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= EPSILON * Math.max(1, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= EPSILON * Math.max(1, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= EPSILON * Math.max(1, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= EPSILON * Math.max(1, Math.abs(a15), Math.abs(b15));
|
|
1571
|
+
}
|
|
1572
|
+
var mul = multiply;
|
|
1573
|
+
var sub = subtract;
|
|
1574
|
+
|
|
1575
|
+
// ../../node_modules/gl-matrix/esm/quat.js
|
|
1576
|
+
var quat_exports = {};
|
|
1577
|
+
__export(quat_exports, {
|
|
1578
|
+
add: () => add4,
|
|
1579
|
+
calculateW: () => calculateW,
|
|
1580
|
+
clone: () => clone4,
|
|
1581
|
+
conjugate: () => conjugate,
|
|
1582
|
+
copy: () => copy4,
|
|
1583
|
+
create: () => create5,
|
|
1584
|
+
dot: () => dot3,
|
|
1585
|
+
equals: () => equals4,
|
|
1586
|
+
exactEquals: () => exactEquals4,
|
|
1587
|
+
exp: () => exp,
|
|
1588
|
+
fromEuler: () => fromEuler,
|
|
1589
|
+
fromMat3: () => fromMat3,
|
|
1590
|
+
fromValues: () => fromValues4,
|
|
1591
|
+
getAngle: () => getAngle,
|
|
1592
|
+
getAxisAngle: () => getAxisAngle,
|
|
1593
|
+
identity: () => identity2,
|
|
1594
|
+
invert: () => invert2,
|
|
1595
|
+
len: () => len3,
|
|
1596
|
+
length: () => length3,
|
|
1597
|
+
lerp: () => lerp3,
|
|
1598
|
+
ln: () => ln,
|
|
1599
|
+
mul: () => mul4,
|
|
1600
|
+
multiply: () => multiply4,
|
|
1601
|
+
normalize: () => normalize3,
|
|
1602
|
+
pow: () => pow,
|
|
1603
|
+
random: () => random3,
|
|
1604
|
+
rotateX: () => rotateX3,
|
|
1605
|
+
rotateY: () => rotateY3,
|
|
1606
|
+
rotateZ: () => rotateZ3,
|
|
1607
|
+
rotationTo: () => rotationTo,
|
|
1608
|
+
scale: () => scale4,
|
|
1609
|
+
set: () => set4,
|
|
1610
|
+
setAxes: () => setAxes,
|
|
1611
|
+
setAxisAngle: () => setAxisAngle,
|
|
1612
|
+
slerp: () => slerp2,
|
|
1613
|
+
sqlerp: () => sqlerp,
|
|
1614
|
+
sqrLen: () => sqrLen3,
|
|
1615
|
+
squaredLength: () => squaredLength3,
|
|
1616
|
+
str: () => str4
|
|
1617
|
+
});
|
|
1618
|
+
|
|
1619
|
+
// ../../node_modules/gl-matrix/esm/vec3.js
|
|
1620
|
+
var vec3_exports = {};
|
|
1621
|
+
__export(vec3_exports, {
|
|
1622
|
+
add: () => add2,
|
|
1623
|
+
angle: () => angle,
|
|
1624
|
+
bezier: () => bezier,
|
|
1625
|
+
ceil: () => ceil,
|
|
1626
|
+
clone: () => clone2,
|
|
1627
|
+
copy: () => copy2,
|
|
1628
|
+
create: () => create3,
|
|
1629
|
+
cross: () => cross,
|
|
1630
|
+
dist: () => dist,
|
|
1631
|
+
distance: () => distance,
|
|
1632
|
+
div: () => div,
|
|
1633
|
+
divide: () => divide,
|
|
1634
|
+
dot: () => dot,
|
|
1635
|
+
equals: () => equals2,
|
|
1636
|
+
exactEquals: () => exactEquals2,
|
|
1637
|
+
floor: () => floor,
|
|
1638
|
+
forEach: () => forEach,
|
|
1639
|
+
fromValues: () => fromValues2,
|
|
1640
|
+
hermite: () => hermite,
|
|
1641
|
+
inverse: () => inverse,
|
|
1642
|
+
len: () => len,
|
|
1643
|
+
length: () => length,
|
|
1644
|
+
lerp: () => lerp,
|
|
1645
|
+
max: () => max,
|
|
1646
|
+
min: () => min,
|
|
1647
|
+
mul: () => mul2,
|
|
1648
|
+
multiply: () => multiply2,
|
|
1649
|
+
negate: () => negate,
|
|
1650
|
+
normalize: () => normalize,
|
|
1651
|
+
random: () => random,
|
|
1652
|
+
rotateX: () => rotateX2,
|
|
1653
|
+
rotateY: () => rotateY2,
|
|
1654
|
+
rotateZ: () => rotateZ2,
|
|
1655
|
+
round: () => round2,
|
|
1656
|
+
scale: () => scale2,
|
|
1657
|
+
scaleAndAdd: () => scaleAndAdd,
|
|
1658
|
+
set: () => set2,
|
|
1659
|
+
slerp: () => slerp,
|
|
1660
|
+
sqrDist: () => sqrDist,
|
|
1661
|
+
sqrLen: () => sqrLen,
|
|
1662
|
+
squaredDistance: () => squaredDistance,
|
|
1663
|
+
squaredLength: () => squaredLength,
|
|
1664
|
+
str: () => str2,
|
|
1665
|
+
sub: () => sub2,
|
|
1666
|
+
subtract: () => subtract2,
|
|
1667
|
+
transformMat3: () => transformMat3,
|
|
1668
|
+
transformMat4: () => transformMat4,
|
|
1669
|
+
transformQuat: () => transformQuat,
|
|
1670
|
+
zero: () => zero
|
|
1671
|
+
});
|
|
1672
|
+
function create3() {
|
|
1673
|
+
var out = new ARRAY_TYPE(3);
|
|
1674
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
1675
|
+
out[0] = 0;
|
|
1676
|
+
out[1] = 0;
|
|
1677
|
+
out[2] = 0;
|
|
1678
|
+
}
|
|
1679
|
+
return out;
|
|
1680
|
+
}
|
|
1681
|
+
function clone2(a) {
|
|
1682
|
+
var out = new ARRAY_TYPE(3);
|
|
1683
|
+
out[0] = a[0];
|
|
1684
|
+
out[1] = a[1];
|
|
1685
|
+
out[2] = a[2];
|
|
1686
|
+
return out;
|
|
1687
|
+
}
|
|
1688
|
+
function length(a) {
|
|
1689
|
+
var x = a[0];
|
|
1690
|
+
var y = a[1];
|
|
1691
|
+
var z = a[2];
|
|
1692
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
1693
|
+
}
|
|
1694
|
+
function fromValues2(x, y, z) {
|
|
1695
|
+
var out = new ARRAY_TYPE(3);
|
|
1696
|
+
out[0] = x;
|
|
1697
|
+
out[1] = y;
|
|
1698
|
+
out[2] = z;
|
|
1699
|
+
return out;
|
|
1700
|
+
}
|
|
1701
|
+
function copy2(out, a) {
|
|
1702
|
+
out[0] = a[0];
|
|
1703
|
+
out[1] = a[1];
|
|
1704
|
+
out[2] = a[2];
|
|
1705
|
+
return out;
|
|
1706
|
+
}
|
|
1707
|
+
function set2(out, x, y, z) {
|
|
1708
|
+
out[0] = x;
|
|
1709
|
+
out[1] = y;
|
|
1710
|
+
out[2] = z;
|
|
1711
|
+
return out;
|
|
1712
|
+
}
|
|
1713
|
+
function add2(out, a, b) {
|
|
1714
|
+
out[0] = a[0] + b[0];
|
|
1715
|
+
out[1] = a[1] + b[1];
|
|
1716
|
+
out[2] = a[2] + b[2];
|
|
1717
|
+
return out;
|
|
1718
|
+
}
|
|
1719
|
+
function subtract2(out, a, b) {
|
|
1720
|
+
out[0] = a[0] - b[0];
|
|
1721
|
+
out[1] = a[1] - b[1];
|
|
1722
|
+
out[2] = a[2] - b[2];
|
|
1723
|
+
return out;
|
|
1724
|
+
}
|
|
1725
|
+
function multiply2(out, a, b) {
|
|
1726
|
+
out[0] = a[0] * b[0];
|
|
1727
|
+
out[1] = a[1] * b[1];
|
|
1728
|
+
out[2] = a[2] * b[2];
|
|
1729
|
+
return out;
|
|
1730
|
+
}
|
|
1731
|
+
function divide(out, a, b) {
|
|
1732
|
+
out[0] = a[0] / b[0];
|
|
1733
|
+
out[1] = a[1] / b[1];
|
|
1734
|
+
out[2] = a[2] / b[2];
|
|
1735
|
+
return out;
|
|
1736
|
+
}
|
|
1737
|
+
function ceil(out, a) {
|
|
1738
|
+
out[0] = Math.ceil(a[0]);
|
|
1739
|
+
out[1] = Math.ceil(a[1]);
|
|
1740
|
+
out[2] = Math.ceil(a[2]);
|
|
1741
|
+
return out;
|
|
1742
|
+
}
|
|
1743
|
+
function floor(out, a) {
|
|
1744
|
+
out[0] = Math.floor(a[0]);
|
|
1745
|
+
out[1] = Math.floor(a[1]);
|
|
1746
|
+
out[2] = Math.floor(a[2]);
|
|
1747
|
+
return out;
|
|
1748
|
+
}
|
|
1749
|
+
function min(out, a, b) {
|
|
1750
|
+
out[0] = Math.min(a[0], b[0]);
|
|
1751
|
+
out[1] = Math.min(a[1], b[1]);
|
|
1752
|
+
out[2] = Math.min(a[2], b[2]);
|
|
1753
|
+
return out;
|
|
1754
|
+
}
|
|
1755
|
+
function max(out, a, b) {
|
|
1756
|
+
out[0] = Math.max(a[0], b[0]);
|
|
1757
|
+
out[1] = Math.max(a[1], b[1]);
|
|
1758
|
+
out[2] = Math.max(a[2], b[2]);
|
|
1759
|
+
return out;
|
|
1760
|
+
}
|
|
1761
|
+
function round2(out, a) {
|
|
1762
|
+
out[0] = round(a[0]);
|
|
1763
|
+
out[1] = round(a[1]);
|
|
1764
|
+
out[2] = round(a[2]);
|
|
1765
|
+
return out;
|
|
1766
|
+
}
|
|
1767
|
+
function scale2(out, a, b) {
|
|
1768
|
+
out[0] = a[0] * b;
|
|
1769
|
+
out[1] = a[1] * b;
|
|
1770
|
+
out[2] = a[2] * b;
|
|
1771
|
+
return out;
|
|
1772
|
+
}
|
|
1773
|
+
function scaleAndAdd(out, a, b, scale5) {
|
|
1774
|
+
out[0] = a[0] + b[0] * scale5;
|
|
1775
|
+
out[1] = a[1] + b[1] * scale5;
|
|
1776
|
+
out[2] = a[2] + b[2] * scale5;
|
|
1777
|
+
return out;
|
|
1778
|
+
}
|
|
1779
|
+
function distance(a, b) {
|
|
1780
|
+
var x = b[0] - a[0];
|
|
1781
|
+
var y = b[1] - a[1];
|
|
1782
|
+
var z = b[2] - a[2];
|
|
1783
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
1784
|
+
}
|
|
1785
|
+
function squaredDistance(a, b) {
|
|
1786
|
+
var x = b[0] - a[0];
|
|
1787
|
+
var y = b[1] - a[1];
|
|
1788
|
+
var z = b[2] - a[2];
|
|
1789
|
+
return x * x + y * y + z * z;
|
|
1790
|
+
}
|
|
1791
|
+
function squaredLength(a) {
|
|
1792
|
+
var x = a[0];
|
|
1793
|
+
var y = a[1];
|
|
1794
|
+
var z = a[2];
|
|
1795
|
+
return x * x + y * y + z * z;
|
|
1796
|
+
}
|
|
1797
|
+
function negate(out, a) {
|
|
1798
|
+
out[0] = -a[0];
|
|
1799
|
+
out[1] = -a[1];
|
|
1800
|
+
out[2] = -a[2];
|
|
1801
|
+
return out;
|
|
1802
|
+
}
|
|
1803
|
+
function inverse(out, a) {
|
|
1804
|
+
out[0] = 1 / a[0];
|
|
1805
|
+
out[1] = 1 / a[1];
|
|
1806
|
+
out[2] = 1 / a[2];
|
|
1807
|
+
return out;
|
|
1808
|
+
}
|
|
1809
|
+
function normalize(out, a) {
|
|
1810
|
+
var x = a[0];
|
|
1811
|
+
var y = a[1];
|
|
1812
|
+
var z = a[2];
|
|
1813
|
+
var len4 = x * x + y * y + z * z;
|
|
1814
|
+
if (len4 > 0) {
|
|
1815
|
+
len4 = 1 / Math.sqrt(len4);
|
|
1816
|
+
}
|
|
1817
|
+
out[0] = a[0] * len4;
|
|
1818
|
+
out[1] = a[1] * len4;
|
|
1819
|
+
out[2] = a[2] * len4;
|
|
1820
|
+
return out;
|
|
1821
|
+
}
|
|
1822
|
+
function dot(a, b) {
|
|
1823
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
1824
|
+
}
|
|
1825
|
+
function cross(out, a, b) {
|
|
1826
|
+
var ax = a[0], ay = a[1], az = a[2];
|
|
1827
|
+
var bx = b[0], by = b[1], bz = b[2];
|
|
1828
|
+
out[0] = ay * bz - az * by;
|
|
1829
|
+
out[1] = az * bx - ax * bz;
|
|
1830
|
+
out[2] = ax * by - ay * bx;
|
|
1831
|
+
return out;
|
|
1832
|
+
}
|
|
1833
|
+
function lerp(out, a, b, t) {
|
|
1834
|
+
var ax = a[0];
|
|
1835
|
+
var ay = a[1];
|
|
1836
|
+
var az = a[2];
|
|
1837
|
+
out[0] = ax + t * (b[0] - ax);
|
|
1838
|
+
out[1] = ay + t * (b[1] - ay);
|
|
1839
|
+
out[2] = az + t * (b[2] - az);
|
|
1840
|
+
return out;
|
|
1841
|
+
}
|
|
1842
|
+
function slerp(out, a, b, t) {
|
|
1843
|
+
var angle2 = Math.acos(Math.min(Math.max(dot(a, b), -1), 1));
|
|
1844
|
+
var sinTotal = Math.sin(angle2);
|
|
1845
|
+
var ratioA = Math.sin((1 - t) * angle2) / sinTotal;
|
|
1846
|
+
var ratioB = Math.sin(t * angle2) / sinTotal;
|
|
1847
|
+
out[0] = ratioA * a[0] + ratioB * b[0];
|
|
1848
|
+
out[1] = ratioA * a[1] + ratioB * b[1];
|
|
1849
|
+
out[2] = ratioA * a[2] + ratioB * b[2];
|
|
1850
|
+
return out;
|
|
1851
|
+
}
|
|
1852
|
+
function hermite(out, a, b, c, d, t) {
|
|
1853
|
+
var factorTimes2 = t * t;
|
|
1854
|
+
var factor1 = factorTimes2 * (2 * t - 3) + 1;
|
|
1855
|
+
var factor2 = factorTimes2 * (t - 2) + t;
|
|
1856
|
+
var factor3 = factorTimes2 * (t - 1);
|
|
1857
|
+
var factor4 = factorTimes2 * (3 - 2 * t);
|
|
1858
|
+
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
1859
|
+
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
1860
|
+
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
1861
|
+
return out;
|
|
1862
|
+
}
|
|
1863
|
+
function bezier(out, a, b, c, d, t) {
|
|
1864
|
+
var inverseFactor = 1 - t;
|
|
1865
|
+
var inverseFactorTimesTwo = inverseFactor * inverseFactor;
|
|
1866
|
+
var factorTimes2 = t * t;
|
|
1867
|
+
var factor1 = inverseFactorTimesTwo * inverseFactor;
|
|
1868
|
+
var factor2 = 3 * t * inverseFactorTimesTwo;
|
|
1869
|
+
var factor3 = 3 * factorTimes2 * inverseFactor;
|
|
1870
|
+
var factor4 = factorTimes2 * t;
|
|
1871
|
+
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
1872
|
+
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
1873
|
+
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
1874
|
+
return out;
|
|
1875
|
+
}
|
|
1876
|
+
function random(out, scale5) {
|
|
1877
|
+
scale5 = scale5 === void 0 ? 1 : scale5;
|
|
1878
|
+
var r = RANDOM() * 2 * Math.PI;
|
|
1879
|
+
var z = RANDOM() * 2 - 1;
|
|
1880
|
+
var zScale = Math.sqrt(1 - z * z) * scale5;
|
|
1881
|
+
out[0] = Math.cos(r) * zScale;
|
|
1882
|
+
out[1] = Math.sin(r) * zScale;
|
|
1883
|
+
out[2] = z * scale5;
|
|
1884
|
+
return out;
|
|
1885
|
+
}
|
|
1886
|
+
function transformMat4(out, a, m) {
|
|
1887
|
+
var x = a[0], y = a[1], z = a[2];
|
|
1888
|
+
var w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
1889
|
+
w = w || 1;
|
|
1890
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
|
|
1891
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
|
|
1892
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
|
|
1893
|
+
return out;
|
|
1894
|
+
}
|
|
1895
|
+
function transformMat3(out, a, m) {
|
|
1896
|
+
var x = a[0], y = a[1], z = a[2];
|
|
1897
|
+
out[0] = x * m[0] + y * m[3] + z * m[6];
|
|
1898
|
+
out[1] = x * m[1] + y * m[4] + z * m[7];
|
|
1899
|
+
out[2] = x * m[2] + y * m[5] + z * m[8];
|
|
1900
|
+
return out;
|
|
1901
|
+
}
|
|
1902
|
+
function transformQuat(out, a, q) {
|
|
1903
|
+
var qx = q[0], qy = q[1], qz = q[2], qw = q[3];
|
|
1904
|
+
var vx = a[0], vy = a[1], vz = a[2];
|
|
1905
|
+
var tx = qy * vz - qz * vy;
|
|
1906
|
+
var ty = qz * vx - qx * vz;
|
|
1907
|
+
var tz = qx * vy - qy * vx;
|
|
1908
|
+
tx = tx + tx;
|
|
1909
|
+
ty = ty + ty;
|
|
1910
|
+
tz = tz + tz;
|
|
1911
|
+
out[0] = vx + qw * tx + qy * tz - qz * ty;
|
|
1912
|
+
out[1] = vy + qw * ty + qz * tx - qx * tz;
|
|
1913
|
+
out[2] = vz + qw * tz + qx * ty - qy * tx;
|
|
1914
|
+
return out;
|
|
1915
|
+
}
|
|
1916
|
+
function rotateX2(out, a, b, rad) {
|
|
1917
|
+
var p = [], r = [];
|
|
1918
|
+
p[0] = a[0] - b[0];
|
|
1919
|
+
p[1] = a[1] - b[1];
|
|
1920
|
+
p[2] = a[2] - b[2];
|
|
1921
|
+
r[0] = p[0];
|
|
1922
|
+
r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
|
|
1923
|
+
r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);
|
|
1924
|
+
out[0] = r[0] + b[0];
|
|
1925
|
+
out[1] = r[1] + b[1];
|
|
1926
|
+
out[2] = r[2] + b[2];
|
|
1927
|
+
return out;
|
|
1928
|
+
}
|
|
1929
|
+
function rotateY2(out, a, b, rad) {
|
|
1930
|
+
var p = [], r = [];
|
|
1931
|
+
p[0] = a[0] - b[0];
|
|
1932
|
+
p[1] = a[1] - b[1];
|
|
1933
|
+
p[2] = a[2] - b[2];
|
|
1934
|
+
r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
|
|
1935
|
+
r[1] = p[1];
|
|
1936
|
+
r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);
|
|
1937
|
+
out[0] = r[0] + b[0];
|
|
1938
|
+
out[1] = r[1] + b[1];
|
|
1939
|
+
out[2] = r[2] + b[2];
|
|
1940
|
+
return out;
|
|
1941
|
+
}
|
|
1942
|
+
function rotateZ2(out, a, b, rad) {
|
|
1943
|
+
var p = [], r = [];
|
|
1944
|
+
p[0] = a[0] - b[0];
|
|
1945
|
+
p[1] = a[1] - b[1];
|
|
1946
|
+
p[2] = a[2] - b[2];
|
|
1947
|
+
r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
|
|
1948
|
+
r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
|
|
1949
|
+
r[2] = p[2];
|
|
1950
|
+
out[0] = r[0] + b[0];
|
|
1951
|
+
out[1] = r[1] + b[1];
|
|
1952
|
+
out[2] = r[2] + b[2];
|
|
1953
|
+
return out;
|
|
1954
|
+
}
|
|
1955
|
+
function angle(a, b) {
|
|
1956
|
+
var ax = a[0], ay = a[1], az = a[2], bx = b[0], by = b[1], bz = b[2], mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz)), cosine = mag && dot(a, b) / mag;
|
|
1957
|
+
return Math.acos(Math.min(Math.max(cosine, -1), 1));
|
|
1958
|
+
}
|
|
1959
|
+
function zero(out) {
|
|
1960
|
+
out[0] = 0;
|
|
1961
|
+
out[1] = 0;
|
|
1962
|
+
out[2] = 0;
|
|
1963
|
+
return out;
|
|
1964
|
+
}
|
|
1965
|
+
function str2(a) {
|
|
1966
|
+
return "vec3(" + a[0] + ", " + a[1] + ", " + a[2] + ")";
|
|
1967
|
+
}
|
|
1968
|
+
function exactEquals2(a, b) {
|
|
1969
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
1970
|
+
}
|
|
1971
|
+
function equals2(a, b) {
|
|
1972
|
+
var a0 = a[0], a1 = a[1], a2 = a[2];
|
|
1973
|
+
var b0 = b[0], b1 = b[1], b2 = b[2];
|
|
1974
|
+
return Math.abs(a0 - b0) <= EPSILON * Math.max(1, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1, Math.abs(a2), Math.abs(b2));
|
|
1975
|
+
}
|
|
1976
|
+
var sub2 = subtract2;
|
|
1977
|
+
var mul2 = multiply2;
|
|
1978
|
+
var div = divide;
|
|
1979
|
+
var dist = distance;
|
|
1980
|
+
var sqrDist = squaredDistance;
|
|
1981
|
+
var len = length;
|
|
1982
|
+
var sqrLen = squaredLength;
|
|
1983
|
+
var forEach = (function() {
|
|
1984
|
+
var vec = create3();
|
|
1985
|
+
return function(a, stride, offset, count, fn, arg) {
|
|
1986
|
+
var i, l;
|
|
1987
|
+
if (!stride) {
|
|
1988
|
+
stride = 3;
|
|
1989
|
+
}
|
|
1990
|
+
if (!offset) {
|
|
1991
|
+
offset = 0;
|
|
1992
|
+
}
|
|
1993
|
+
if (count) {
|
|
1994
|
+
l = Math.min(count * stride + offset, a.length);
|
|
1995
|
+
} else {
|
|
1996
|
+
l = a.length;
|
|
1997
|
+
}
|
|
1998
|
+
for (i = offset; i < l; i += stride) {
|
|
1999
|
+
vec[0] = a[i];
|
|
2000
|
+
vec[1] = a[i + 1];
|
|
2001
|
+
vec[2] = a[i + 2];
|
|
2002
|
+
fn(vec, vec, arg);
|
|
2003
|
+
a[i] = vec[0];
|
|
2004
|
+
a[i + 1] = vec[1];
|
|
2005
|
+
a[i + 2] = vec[2];
|
|
2006
|
+
}
|
|
2007
|
+
return a;
|
|
2008
|
+
};
|
|
2009
|
+
})();
|
|
2010
|
+
|
|
2011
|
+
// ../../node_modules/gl-matrix/esm/vec4.js
|
|
2012
|
+
var vec4_exports = {};
|
|
2013
|
+
__export(vec4_exports, {
|
|
2014
|
+
add: () => add3,
|
|
2015
|
+
ceil: () => ceil2,
|
|
2016
|
+
clone: () => clone3,
|
|
2017
|
+
copy: () => copy3,
|
|
2018
|
+
create: () => create4,
|
|
2019
|
+
cross: () => cross2,
|
|
2020
|
+
dist: () => dist2,
|
|
2021
|
+
distance: () => distance2,
|
|
2022
|
+
div: () => div2,
|
|
2023
|
+
divide: () => divide2,
|
|
2024
|
+
dot: () => dot2,
|
|
2025
|
+
equals: () => equals3,
|
|
2026
|
+
exactEquals: () => exactEquals3,
|
|
2027
|
+
floor: () => floor2,
|
|
2028
|
+
forEach: () => forEach2,
|
|
2029
|
+
fromValues: () => fromValues3,
|
|
2030
|
+
inverse: () => inverse2,
|
|
2031
|
+
len: () => len2,
|
|
2032
|
+
length: () => length2,
|
|
2033
|
+
lerp: () => lerp2,
|
|
2034
|
+
max: () => max2,
|
|
2035
|
+
min: () => min2,
|
|
2036
|
+
mul: () => mul3,
|
|
2037
|
+
multiply: () => multiply3,
|
|
2038
|
+
negate: () => negate2,
|
|
2039
|
+
normalize: () => normalize2,
|
|
2040
|
+
random: () => random2,
|
|
2041
|
+
round: () => round3,
|
|
2042
|
+
scale: () => scale3,
|
|
2043
|
+
scaleAndAdd: () => scaleAndAdd2,
|
|
2044
|
+
set: () => set3,
|
|
2045
|
+
sqrDist: () => sqrDist2,
|
|
2046
|
+
sqrLen: () => sqrLen2,
|
|
2047
|
+
squaredDistance: () => squaredDistance2,
|
|
2048
|
+
squaredLength: () => squaredLength2,
|
|
2049
|
+
str: () => str3,
|
|
2050
|
+
sub: () => sub3,
|
|
2051
|
+
subtract: () => subtract3,
|
|
2052
|
+
transformMat4: () => transformMat42,
|
|
2053
|
+
transformQuat: () => transformQuat2,
|
|
2054
|
+
zero: () => zero2
|
|
2055
|
+
});
|
|
2056
|
+
function create4() {
|
|
2057
|
+
var out = new ARRAY_TYPE(4);
|
|
2058
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
2059
|
+
out[0] = 0;
|
|
2060
|
+
out[1] = 0;
|
|
2061
|
+
out[2] = 0;
|
|
2062
|
+
out[3] = 0;
|
|
2063
|
+
}
|
|
2064
|
+
return out;
|
|
2065
|
+
}
|
|
2066
|
+
function clone3(a) {
|
|
2067
|
+
var out = new ARRAY_TYPE(4);
|
|
2068
|
+
out[0] = a[0];
|
|
2069
|
+
out[1] = a[1];
|
|
2070
|
+
out[2] = a[2];
|
|
2071
|
+
out[3] = a[3];
|
|
2072
|
+
return out;
|
|
2073
|
+
}
|
|
2074
|
+
function fromValues3(x, y, z, w) {
|
|
2075
|
+
var out = new ARRAY_TYPE(4);
|
|
2076
|
+
out[0] = x;
|
|
2077
|
+
out[1] = y;
|
|
2078
|
+
out[2] = z;
|
|
2079
|
+
out[3] = w;
|
|
2080
|
+
return out;
|
|
2081
|
+
}
|
|
2082
|
+
function copy3(out, a) {
|
|
2083
|
+
out[0] = a[0];
|
|
2084
|
+
out[1] = a[1];
|
|
2085
|
+
out[2] = a[2];
|
|
2086
|
+
out[3] = a[3];
|
|
2087
|
+
return out;
|
|
2088
|
+
}
|
|
2089
|
+
function set3(out, x, y, z, w) {
|
|
2090
|
+
out[0] = x;
|
|
2091
|
+
out[1] = y;
|
|
2092
|
+
out[2] = z;
|
|
2093
|
+
out[3] = w;
|
|
2094
|
+
return out;
|
|
2095
|
+
}
|
|
2096
|
+
function add3(out, a, b) {
|
|
2097
|
+
out[0] = a[0] + b[0];
|
|
2098
|
+
out[1] = a[1] + b[1];
|
|
2099
|
+
out[2] = a[2] + b[2];
|
|
2100
|
+
out[3] = a[3] + b[3];
|
|
2101
|
+
return out;
|
|
2102
|
+
}
|
|
2103
|
+
function subtract3(out, a, b) {
|
|
2104
|
+
out[0] = a[0] - b[0];
|
|
2105
|
+
out[1] = a[1] - b[1];
|
|
2106
|
+
out[2] = a[2] - b[2];
|
|
2107
|
+
out[3] = a[3] - b[3];
|
|
2108
|
+
return out;
|
|
2109
|
+
}
|
|
2110
|
+
function multiply3(out, a, b) {
|
|
2111
|
+
out[0] = a[0] * b[0];
|
|
2112
|
+
out[1] = a[1] * b[1];
|
|
2113
|
+
out[2] = a[2] * b[2];
|
|
2114
|
+
out[3] = a[3] * b[3];
|
|
2115
|
+
return out;
|
|
2116
|
+
}
|
|
2117
|
+
function divide2(out, a, b) {
|
|
2118
|
+
out[0] = a[0] / b[0];
|
|
2119
|
+
out[1] = a[1] / b[1];
|
|
2120
|
+
out[2] = a[2] / b[2];
|
|
2121
|
+
out[3] = a[3] / b[3];
|
|
2122
|
+
return out;
|
|
2123
|
+
}
|
|
2124
|
+
function ceil2(out, a) {
|
|
2125
|
+
out[0] = Math.ceil(a[0]);
|
|
2126
|
+
out[1] = Math.ceil(a[1]);
|
|
2127
|
+
out[2] = Math.ceil(a[2]);
|
|
2128
|
+
out[3] = Math.ceil(a[3]);
|
|
2129
|
+
return out;
|
|
2130
|
+
}
|
|
2131
|
+
function floor2(out, a) {
|
|
2132
|
+
out[0] = Math.floor(a[0]);
|
|
2133
|
+
out[1] = Math.floor(a[1]);
|
|
2134
|
+
out[2] = Math.floor(a[2]);
|
|
2135
|
+
out[3] = Math.floor(a[3]);
|
|
2136
|
+
return out;
|
|
2137
|
+
}
|
|
2138
|
+
function min2(out, a, b) {
|
|
2139
|
+
out[0] = Math.min(a[0], b[0]);
|
|
2140
|
+
out[1] = Math.min(a[1], b[1]);
|
|
2141
|
+
out[2] = Math.min(a[2], b[2]);
|
|
2142
|
+
out[3] = Math.min(a[3], b[3]);
|
|
2143
|
+
return out;
|
|
2144
|
+
}
|
|
2145
|
+
function max2(out, a, b) {
|
|
2146
|
+
out[0] = Math.max(a[0], b[0]);
|
|
2147
|
+
out[1] = Math.max(a[1], b[1]);
|
|
2148
|
+
out[2] = Math.max(a[2], b[2]);
|
|
2149
|
+
out[3] = Math.max(a[3], b[3]);
|
|
2150
|
+
return out;
|
|
2151
|
+
}
|
|
2152
|
+
function round3(out, a) {
|
|
2153
|
+
out[0] = round(a[0]);
|
|
2154
|
+
out[1] = round(a[1]);
|
|
2155
|
+
out[2] = round(a[2]);
|
|
2156
|
+
out[3] = round(a[3]);
|
|
2157
|
+
return out;
|
|
2158
|
+
}
|
|
2159
|
+
function scale3(out, a, b) {
|
|
2160
|
+
out[0] = a[0] * b;
|
|
2161
|
+
out[1] = a[1] * b;
|
|
2162
|
+
out[2] = a[2] * b;
|
|
2163
|
+
out[3] = a[3] * b;
|
|
2164
|
+
return out;
|
|
2165
|
+
}
|
|
2166
|
+
function scaleAndAdd2(out, a, b, scale5) {
|
|
2167
|
+
out[0] = a[0] + b[0] * scale5;
|
|
2168
|
+
out[1] = a[1] + b[1] * scale5;
|
|
2169
|
+
out[2] = a[2] + b[2] * scale5;
|
|
2170
|
+
out[3] = a[3] + b[3] * scale5;
|
|
2171
|
+
return out;
|
|
2172
|
+
}
|
|
2173
|
+
function distance2(a, b) {
|
|
2174
|
+
var x = b[0] - a[0];
|
|
2175
|
+
var y = b[1] - a[1];
|
|
2176
|
+
var z = b[2] - a[2];
|
|
2177
|
+
var w = b[3] - a[3];
|
|
2178
|
+
return Math.sqrt(x * x + y * y + z * z + w * w);
|
|
2179
|
+
}
|
|
2180
|
+
function squaredDistance2(a, b) {
|
|
2181
|
+
var x = b[0] - a[0];
|
|
2182
|
+
var y = b[1] - a[1];
|
|
2183
|
+
var z = b[2] - a[2];
|
|
2184
|
+
var w = b[3] - a[3];
|
|
2185
|
+
return x * x + y * y + z * z + w * w;
|
|
2186
|
+
}
|
|
2187
|
+
function length2(a) {
|
|
2188
|
+
var x = a[0];
|
|
2189
|
+
var y = a[1];
|
|
2190
|
+
var z = a[2];
|
|
2191
|
+
var w = a[3];
|
|
2192
|
+
return Math.sqrt(x * x + y * y + z * z + w * w);
|
|
2193
|
+
}
|
|
2194
|
+
function squaredLength2(a) {
|
|
2195
|
+
var x = a[0];
|
|
2196
|
+
var y = a[1];
|
|
2197
|
+
var z = a[2];
|
|
2198
|
+
var w = a[3];
|
|
2199
|
+
return x * x + y * y + z * z + w * w;
|
|
2200
|
+
}
|
|
2201
|
+
function negate2(out, a) {
|
|
2202
|
+
out[0] = -a[0];
|
|
2203
|
+
out[1] = -a[1];
|
|
2204
|
+
out[2] = -a[2];
|
|
2205
|
+
out[3] = -a[3];
|
|
2206
|
+
return out;
|
|
2207
|
+
}
|
|
2208
|
+
function inverse2(out, a) {
|
|
2209
|
+
out[0] = 1 / a[0];
|
|
2210
|
+
out[1] = 1 / a[1];
|
|
2211
|
+
out[2] = 1 / a[2];
|
|
2212
|
+
out[3] = 1 / a[3];
|
|
2213
|
+
return out;
|
|
2214
|
+
}
|
|
2215
|
+
function normalize2(out, a) {
|
|
2216
|
+
var x = a[0];
|
|
2217
|
+
var y = a[1];
|
|
2218
|
+
var z = a[2];
|
|
2219
|
+
var w = a[3];
|
|
2220
|
+
var len4 = x * x + y * y + z * z + w * w;
|
|
2221
|
+
if (len4 > 0) {
|
|
2222
|
+
len4 = 1 / Math.sqrt(len4);
|
|
2223
|
+
}
|
|
2224
|
+
out[0] = x * len4;
|
|
2225
|
+
out[1] = y * len4;
|
|
2226
|
+
out[2] = z * len4;
|
|
2227
|
+
out[3] = w * len4;
|
|
2228
|
+
return out;
|
|
2229
|
+
}
|
|
2230
|
+
function dot2(a, b) {
|
|
2231
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
2232
|
+
}
|
|
2233
|
+
function cross2(out, u, v, w) {
|
|
2234
|
+
var A = v[0] * w[1] - v[1] * w[0], B = v[0] * w[2] - v[2] * w[0], C = v[0] * w[3] - v[3] * w[0], D = v[1] * w[2] - v[2] * w[1], E = v[1] * w[3] - v[3] * w[1], F = v[2] * w[3] - v[3] * w[2];
|
|
2235
|
+
var G = u[0];
|
|
2236
|
+
var H = u[1];
|
|
2237
|
+
var I = u[2];
|
|
2238
|
+
var J = u[3];
|
|
2239
|
+
out[0] = H * F - I * E + J * D;
|
|
2240
|
+
out[1] = -(G * F) + I * C - J * B;
|
|
2241
|
+
out[2] = G * E - H * C + J * A;
|
|
2242
|
+
out[3] = -(G * D) + H * B - I * A;
|
|
2243
|
+
return out;
|
|
2244
|
+
}
|
|
2245
|
+
function lerp2(out, a, b, t) {
|
|
2246
|
+
var ax = a[0];
|
|
2247
|
+
var ay = a[1];
|
|
2248
|
+
var az = a[2];
|
|
2249
|
+
var aw = a[3];
|
|
2250
|
+
out[0] = ax + t * (b[0] - ax);
|
|
2251
|
+
out[1] = ay + t * (b[1] - ay);
|
|
2252
|
+
out[2] = az + t * (b[2] - az);
|
|
2253
|
+
out[3] = aw + t * (b[3] - aw);
|
|
2254
|
+
return out;
|
|
2255
|
+
}
|
|
2256
|
+
function random2(out, scale5) {
|
|
2257
|
+
scale5 = scale5 === void 0 ? 1 : scale5;
|
|
2258
|
+
var v1, v2, v3, v4;
|
|
2259
|
+
var s1, s2;
|
|
2260
|
+
var rand;
|
|
2261
|
+
rand = RANDOM();
|
|
2262
|
+
v1 = rand * 2 - 1;
|
|
2263
|
+
v2 = (4 * RANDOM() - 2) * Math.sqrt(rand * -rand + rand);
|
|
2264
|
+
s1 = v1 * v1 + v2 * v2;
|
|
2265
|
+
rand = RANDOM();
|
|
2266
|
+
v3 = rand * 2 - 1;
|
|
2267
|
+
v4 = (4 * RANDOM() - 2) * Math.sqrt(rand * -rand + rand);
|
|
2268
|
+
s2 = v3 * v3 + v4 * v4;
|
|
2269
|
+
var d = Math.sqrt((1 - s1) / s2);
|
|
2270
|
+
out[0] = scale5 * v1;
|
|
2271
|
+
out[1] = scale5 * v2;
|
|
2272
|
+
out[2] = scale5 * v3 * d;
|
|
2273
|
+
out[3] = scale5 * v4 * d;
|
|
2274
|
+
return out;
|
|
2275
|
+
}
|
|
2276
|
+
function transformMat42(out, a, m) {
|
|
2277
|
+
var x = a[0], y = a[1], z = a[2], w = a[3];
|
|
2278
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
|
|
2279
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
|
|
2280
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
|
|
2281
|
+
out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
|
|
2282
|
+
return out;
|
|
2283
|
+
}
|
|
2284
|
+
function transformQuat2(out, a, q) {
|
|
2285
|
+
var qx = q[0], qy = q[1], qz = q[2], qw = q[3];
|
|
2286
|
+
var vx = a[0], vy = a[1], vz = a[2];
|
|
2287
|
+
var tx = qy * vz - qz * vy;
|
|
2288
|
+
var ty = qz * vx - qx * vz;
|
|
2289
|
+
var tz = qx * vy - qy * vx;
|
|
2290
|
+
tx = tx + tx;
|
|
2291
|
+
ty = ty + ty;
|
|
2292
|
+
tz = tz + tz;
|
|
2293
|
+
out[0] = vx + qw * tx + qy * tz - qz * ty;
|
|
2294
|
+
out[1] = vy + qw * ty + qz * tx - qx * tz;
|
|
2295
|
+
out[2] = vz + qw * tz + qx * ty - qy * tx;
|
|
2296
|
+
out[3] = a[3];
|
|
2297
|
+
return out;
|
|
2298
|
+
}
|
|
2299
|
+
function zero2(out) {
|
|
2300
|
+
out[0] = 0;
|
|
2301
|
+
out[1] = 0;
|
|
2302
|
+
out[2] = 0;
|
|
2303
|
+
out[3] = 0;
|
|
2304
|
+
return out;
|
|
2305
|
+
}
|
|
2306
|
+
function str3(a) {
|
|
2307
|
+
return "vec4(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";
|
|
2308
|
+
}
|
|
2309
|
+
function exactEquals3(a, b) {
|
|
2310
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
2311
|
+
}
|
|
2312
|
+
function equals3(a, b) {
|
|
2313
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
|
|
2314
|
+
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
|
2315
|
+
return Math.abs(a0 - b0) <= EPSILON * Math.max(1, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1, Math.abs(a3), Math.abs(b3));
|
|
2316
|
+
}
|
|
2317
|
+
var sub3 = subtract3;
|
|
2318
|
+
var mul3 = multiply3;
|
|
2319
|
+
var div2 = divide2;
|
|
2320
|
+
var dist2 = distance2;
|
|
2321
|
+
var sqrDist2 = squaredDistance2;
|
|
2322
|
+
var len2 = length2;
|
|
2323
|
+
var sqrLen2 = squaredLength2;
|
|
2324
|
+
var forEach2 = (function() {
|
|
2325
|
+
var vec = create4();
|
|
2326
|
+
return function(a, stride, offset, count, fn, arg) {
|
|
2327
|
+
var i, l;
|
|
2328
|
+
if (!stride) {
|
|
2329
|
+
stride = 4;
|
|
2330
|
+
}
|
|
2331
|
+
if (!offset) {
|
|
2332
|
+
offset = 0;
|
|
2333
|
+
}
|
|
2334
|
+
if (count) {
|
|
2335
|
+
l = Math.min(count * stride + offset, a.length);
|
|
2336
|
+
} else {
|
|
2337
|
+
l = a.length;
|
|
2338
|
+
}
|
|
2339
|
+
for (i = offset; i < l; i += stride) {
|
|
2340
|
+
vec[0] = a[i];
|
|
2341
|
+
vec[1] = a[i + 1];
|
|
2342
|
+
vec[2] = a[i + 2];
|
|
2343
|
+
vec[3] = a[i + 3];
|
|
2344
|
+
fn(vec, vec, arg);
|
|
2345
|
+
a[i] = vec[0];
|
|
2346
|
+
a[i + 1] = vec[1];
|
|
2347
|
+
a[i + 2] = vec[2];
|
|
2348
|
+
a[i + 3] = vec[3];
|
|
2349
|
+
}
|
|
2350
|
+
return a;
|
|
2351
|
+
};
|
|
2352
|
+
})();
|
|
2353
|
+
|
|
2354
|
+
// ../../node_modules/gl-matrix/esm/quat.js
|
|
2355
|
+
function create5() {
|
|
2356
|
+
var out = new ARRAY_TYPE(4);
|
|
2357
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
2358
|
+
out[0] = 0;
|
|
2359
|
+
out[1] = 0;
|
|
2360
|
+
out[2] = 0;
|
|
2361
|
+
}
|
|
2362
|
+
out[3] = 1;
|
|
2363
|
+
return out;
|
|
2364
|
+
}
|
|
2365
|
+
function identity2(out) {
|
|
2366
|
+
out[0] = 0;
|
|
2367
|
+
out[1] = 0;
|
|
2368
|
+
out[2] = 0;
|
|
2369
|
+
out[3] = 1;
|
|
2370
|
+
return out;
|
|
2371
|
+
}
|
|
2372
|
+
function setAxisAngle(out, axis, rad) {
|
|
2373
|
+
rad = rad * 0.5;
|
|
2374
|
+
var s = Math.sin(rad);
|
|
2375
|
+
out[0] = s * axis[0];
|
|
2376
|
+
out[1] = s * axis[1];
|
|
2377
|
+
out[2] = s * axis[2];
|
|
2378
|
+
out[3] = Math.cos(rad);
|
|
2379
|
+
return out;
|
|
2380
|
+
}
|
|
2381
|
+
function getAxisAngle(out_axis, q) {
|
|
2382
|
+
var rad = Math.acos(q[3]) * 2;
|
|
2383
|
+
var s = Math.sin(rad / 2);
|
|
2384
|
+
if (s > EPSILON) {
|
|
2385
|
+
out_axis[0] = q[0] / s;
|
|
2386
|
+
out_axis[1] = q[1] / s;
|
|
2387
|
+
out_axis[2] = q[2] / s;
|
|
2388
|
+
} else {
|
|
2389
|
+
out_axis[0] = 1;
|
|
2390
|
+
out_axis[1] = 0;
|
|
2391
|
+
out_axis[2] = 0;
|
|
2392
|
+
}
|
|
2393
|
+
return rad;
|
|
2394
|
+
}
|
|
2395
|
+
function getAngle(a, b) {
|
|
2396
|
+
var dotproduct = dot3(a, b);
|
|
2397
|
+
return Math.acos(2 * dotproduct * dotproduct - 1);
|
|
2398
|
+
}
|
|
2399
|
+
function multiply4(out, a, b) {
|
|
2400
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
2401
|
+
var bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
2402
|
+
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
|
2403
|
+
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
|
2404
|
+
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
2405
|
+
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
2406
|
+
return out;
|
|
2407
|
+
}
|
|
2408
|
+
function rotateX3(out, a, rad) {
|
|
2409
|
+
rad *= 0.5;
|
|
2410
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
2411
|
+
var bx = Math.sin(rad), bw = Math.cos(rad);
|
|
2412
|
+
out[0] = ax * bw + aw * bx;
|
|
2413
|
+
out[1] = ay * bw + az * bx;
|
|
2414
|
+
out[2] = az * bw - ay * bx;
|
|
2415
|
+
out[3] = aw * bw - ax * bx;
|
|
2416
|
+
return out;
|
|
2417
|
+
}
|
|
2418
|
+
function rotateY3(out, a, rad) {
|
|
2419
|
+
rad *= 0.5;
|
|
2420
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
2421
|
+
var by = Math.sin(rad), bw = Math.cos(rad);
|
|
2422
|
+
out[0] = ax * bw - az * by;
|
|
2423
|
+
out[1] = ay * bw + aw * by;
|
|
2424
|
+
out[2] = az * bw + ax * by;
|
|
2425
|
+
out[3] = aw * bw - ay * by;
|
|
2426
|
+
return out;
|
|
2427
|
+
}
|
|
2428
|
+
function rotateZ3(out, a, rad) {
|
|
2429
|
+
rad *= 0.5;
|
|
2430
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
2431
|
+
var bz = Math.sin(rad), bw = Math.cos(rad);
|
|
2432
|
+
out[0] = ax * bw + ay * bz;
|
|
2433
|
+
out[1] = ay * bw - ax * bz;
|
|
2434
|
+
out[2] = az * bw + aw * bz;
|
|
2435
|
+
out[3] = aw * bw - az * bz;
|
|
2436
|
+
return out;
|
|
2437
|
+
}
|
|
2438
|
+
function calculateW(out, a) {
|
|
2439
|
+
var x = a[0], y = a[1], z = a[2];
|
|
2440
|
+
out[0] = x;
|
|
2441
|
+
out[1] = y;
|
|
2442
|
+
out[2] = z;
|
|
2443
|
+
out[3] = Math.sqrt(Math.abs(1 - x * x - y * y - z * z));
|
|
2444
|
+
return out;
|
|
2445
|
+
}
|
|
2446
|
+
function exp(out, a) {
|
|
2447
|
+
var x = a[0], y = a[1], z = a[2], w = a[3];
|
|
2448
|
+
var r = Math.sqrt(x * x + y * y + z * z);
|
|
2449
|
+
var et = Math.exp(w);
|
|
2450
|
+
var s = r > 0 ? et * Math.sin(r) / r : 0;
|
|
2451
|
+
out[0] = x * s;
|
|
2452
|
+
out[1] = y * s;
|
|
2453
|
+
out[2] = z * s;
|
|
2454
|
+
out[3] = et * Math.cos(r);
|
|
2455
|
+
return out;
|
|
2456
|
+
}
|
|
2457
|
+
function ln(out, a) {
|
|
2458
|
+
var x = a[0], y = a[1], z = a[2], w = a[3];
|
|
2459
|
+
var r = Math.sqrt(x * x + y * y + z * z);
|
|
2460
|
+
var t = r > 0 ? Math.atan2(r, w) / r : 0;
|
|
2461
|
+
out[0] = x * t;
|
|
2462
|
+
out[1] = y * t;
|
|
2463
|
+
out[2] = z * t;
|
|
2464
|
+
out[3] = 0.5 * Math.log(x * x + y * y + z * z + w * w);
|
|
2465
|
+
return out;
|
|
2466
|
+
}
|
|
2467
|
+
function pow(out, a, b) {
|
|
2468
|
+
ln(out, a);
|
|
2469
|
+
scale4(out, out, b);
|
|
2470
|
+
exp(out, out);
|
|
2471
|
+
return out;
|
|
2472
|
+
}
|
|
2473
|
+
function slerp2(out, a, b, t) {
|
|
2474
|
+
var ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
2475
|
+
var bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
2476
|
+
var omega, cosom, sinom, scale0, scale1;
|
|
2477
|
+
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
2478
|
+
if (cosom < 0) {
|
|
2479
|
+
cosom = -cosom;
|
|
2480
|
+
bx = -bx;
|
|
2481
|
+
by = -by;
|
|
2482
|
+
bz = -bz;
|
|
2483
|
+
bw = -bw;
|
|
2484
|
+
}
|
|
2485
|
+
if (1 - cosom > EPSILON) {
|
|
2486
|
+
omega = Math.acos(cosom);
|
|
2487
|
+
sinom = Math.sin(omega);
|
|
2488
|
+
scale0 = Math.sin((1 - t) * omega) / sinom;
|
|
2489
|
+
scale1 = Math.sin(t * omega) / sinom;
|
|
2490
|
+
} else {
|
|
2491
|
+
scale0 = 1 - t;
|
|
2492
|
+
scale1 = t;
|
|
2493
|
+
}
|
|
2494
|
+
out[0] = scale0 * ax + scale1 * bx;
|
|
2495
|
+
out[1] = scale0 * ay + scale1 * by;
|
|
2496
|
+
out[2] = scale0 * az + scale1 * bz;
|
|
2497
|
+
out[3] = scale0 * aw + scale1 * bw;
|
|
2498
|
+
return out;
|
|
2499
|
+
}
|
|
2500
|
+
function random3(out) {
|
|
2501
|
+
var u1 = RANDOM();
|
|
2502
|
+
var u2 = RANDOM();
|
|
2503
|
+
var u3 = RANDOM();
|
|
2504
|
+
var sqrt1MinusU1 = Math.sqrt(1 - u1);
|
|
2505
|
+
var sqrtU1 = Math.sqrt(u1);
|
|
2506
|
+
out[0] = sqrt1MinusU1 * Math.sin(2 * Math.PI * u2);
|
|
2507
|
+
out[1] = sqrt1MinusU1 * Math.cos(2 * Math.PI * u2);
|
|
2508
|
+
out[2] = sqrtU1 * Math.sin(2 * Math.PI * u3);
|
|
2509
|
+
out[3] = sqrtU1 * Math.cos(2 * Math.PI * u3);
|
|
2510
|
+
return out;
|
|
2511
|
+
}
|
|
2512
|
+
function invert2(out, a) {
|
|
2513
|
+
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
|
|
2514
|
+
var dot4 = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
|
|
2515
|
+
var invDot = dot4 ? 1 / dot4 : 0;
|
|
2516
|
+
out[0] = -a0 * invDot;
|
|
2517
|
+
out[1] = -a1 * invDot;
|
|
2518
|
+
out[2] = -a2 * invDot;
|
|
2519
|
+
out[3] = a3 * invDot;
|
|
2520
|
+
return out;
|
|
2521
|
+
}
|
|
2522
|
+
function conjugate(out, a) {
|
|
2523
|
+
out[0] = -a[0];
|
|
2524
|
+
out[1] = -a[1];
|
|
2525
|
+
out[2] = -a[2];
|
|
2526
|
+
out[3] = a[3];
|
|
2527
|
+
return out;
|
|
2528
|
+
}
|
|
2529
|
+
function fromMat3(out, m) {
|
|
2530
|
+
var fTrace = m[0] + m[4] + m[8];
|
|
2531
|
+
var fRoot;
|
|
2532
|
+
if (fTrace > 0) {
|
|
2533
|
+
fRoot = Math.sqrt(fTrace + 1);
|
|
2534
|
+
out[3] = 0.5 * fRoot;
|
|
2535
|
+
fRoot = 0.5 / fRoot;
|
|
2536
|
+
out[0] = (m[5] - m[7]) * fRoot;
|
|
2537
|
+
out[1] = (m[6] - m[2]) * fRoot;
|
|
2538
|
+
out[2] = (m[1] - m[3]) * fRoot;
|
|
2539
|
+
} else {
|
|
2540
|
+
var i = 0;
|
|
2541
|
+
if (m[4] > m[0]) i = 1;
|
|
2542
|
+
if (m[8] > m[i * 3 + i]) i = 2;
|
|
2543
|
+
var j = (i + 1) % 3;
|
|
2544
|
+
var k = (i + 2) % 3;
|
|
2545
|
+
fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1);
|
|
2546
|
+
out[i] = 0.5 * fRoot;
|
|
2547
|
+
fRoot = 0.5 / fRoot;
|
|
2548
|
+
out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
|
|
2549
|
+
out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
|
|
2550
|
+
out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
|
|
2551
|
+
}
|
|
2552
|
+
return out;
|
|
2553
|
+
}
|
|
2554
|
+
function fromEuler(out, x, y, z) {
|
|
2555
|
+
var order = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : ANGLE_ORDER;
|
|
2556
|
+
var halfToRad = Math.PI / 360;
|
|
2557
|
+
x *= halfToRad;
|
|
2558
|
+
z *= halfToRad;
|
|
2559
|
+
y *= halfToRad;
|
|
2560
|
+
var sx = Math.sin(x);
|
|
2561
|
+
var cx = Math.cos(x);
|
|
2562
|
+
var sy = Math.sin(y);
|
|
2563
|
+
var cy = Math.cos(y);
|
|
2564
|
+
var sz = Math.sin(z);
|
|
2565
|
+
var cz = Math.cos(z);
|
|
2566
|
+
switch (order) {
|
|
2567
|
+
case "xyz":
|
|
2568
|
+
out[0] = sx * cy * cz + cx * sy * sz;
|
|
2569
|
+
out[1] = cx * sy * cz - sx * cy * sz;
|
|
2570
|
+
out[2] = cx * cy * sz + sx * sy * cz;
|
|
2571
|
+
out[3] = cx * cy * cz - sx * sy * sz;
|
|
2572
|
+
break;
|
|
2573
|
+
case "xzy":
|
|
2574
|
+
out[0] = sx * cy * cz - cx * sy * sz;
|
|
2575
|
+
out[1] = cx * sy * cz - sx * cy * sz;
|
|
2576
|
+
out[2] = cx * cy * sz + sx * sy * cz;
|
|
2577
|
+
out[3] = cx * cy * cz + sx * sy * sz;
|
|
2578
|
+
break;
|
|
2579
|
+
case "yxz":
|
|
2580
|
+
out[0] = sx * cy * cz + cx * sy * sz;
|
|
2581
|
+
out[1] = cx * sy * cz - sx * cy * sz;
|
|
2582
|
+
out[2] = cx * cy * sz - sx * sy * cz;
|
|
2583
|
+
out[3] = cx * cy * cz + sx * sy * sz;
|
|
2584
|
+
break;
|
|
2585
|
+
case "yzx":
|
|
2586
|
+
out[0] = sx * cy * cz + cx * sy * sz;
|
|
2587
|
+
out[1] = cx * sy * cz + sx * cy * sz;
|
|
2588
|
+
out[2] = cx * cy * sz - sx * sy * cz;
|
|
2589
|
+
out[3] = cx * cy * cz - sx * sy * sz;
|
|
2590
|
+
break;
|
|
2591
|
+
case "zxy":
|
|
2592
|
+
out[0] = sx * cy * cz - cx * sy * sz;
|
|
2593
|
+
out[1] = cx * sy * cz + sx * cy * sz;
|
|
2594
|
+
out[2] = cx * cy * sz + sx * sy * cz;
|
|
2595
|
+
out[3] = cx * cy * cz - sx * sy * sz;
|
|
2596
|
+
break;
|
|
2597
|
+
case "zyx":
|
|
2598
|
+
out[0] = sx * cy * cz - cx * sy * sz;
|
|
2599
|
+
out[1] = cx * sy * cz + sx * cy * sz;
|
|
2600
|
+
out[2] = cx * cy * sz - sx * sy * cz;
|
|
2601
|
+
out[3] = cx * cy * cz + sx * sy * sz;
|
|
2602
|
+
break;
|
|
2603
|
+
default:
|
|
2604
|
+
throw new Error("Unknown angle order " + order);
|
|
2605
|
+
}
|
|
2606
|
+
return out;
|
|
2607
|
+
}
|
|
2608
|
+
function str4(a) {
|
|
2609
|
+
return "quat(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";
|
|
2610
|
+
}
|
|
2611
|
+
var clone4 = clone3;
|
|
2612
|
+
var fromValues4 = fromValues3;
|
|
2613
|
+
var copy4 = copy3;
|
|
2614
|
+
var set4 = set3;
|
|
2615
|
+
var add4 = add3;
|
|
2616
|
+
var mul4 = multiply4;
|
|
2617
|
+
var scale4 = scale3;
|
|
2618
|
+
var dot3 = dot2;
|
|
2619
|
+
var lerp3 = lerp2;
|
|
2620
|
+
var length3 = length2;
|
|
2621
|
+
var len3 = length3;
|
|
2622
|
+
var squaredLength3 = squaredLength2;
|
|
2623
|
+
var sqrLen3 = squaredLength3;
|
|
2624
|
+
var normalize3 = normalize2;
|
|
2625
|
+
var exactEquals4 = exactEquals3;
|
|
2626
|
+
function equals4(a, b) {
|
|
2627
|
+
return Math.abs(dot2(a, b)) >= 1 - EPSILON;
|
|
2628
|
+
}
|
|
2629
|
+
var rotationTo = (function() {
|
|
2630
|
+
var tmpvec3 = create3();
|
|
2631
|
+
var xUnitVec3 = fromValues2(1, 0, 0);
|
|
2632
|
+
var yUnitVec3 = fromValues2(0, 1, 0);
|
|
2633
|
+
return function(out, a, b) {
|
|
2634
|
+
var dot4 = dot(a, b);
|
|
2635
|
+
if (dot4 < -0.999999) {
|
|
2636
|
+
cross(tmpvec3, xUnitVec3, a);
|
|
2637
|
+
if (len(tmpvec3) < 1e-6) cross(tmpvec3, yUnitVec3, a);
|
|
2638
|
+
normalize(tmpvec3, tmpvec3);
|
|
2639
|
+
setAxisAngle(out, tmpvec3, Math.PI);
|
|
2640
|
+
return out;
|
|
2641
|
+
} else if (dot4 > 0.999999) {
|
|
2642
|
+
out[0] = 0;
|
|
2643
|
+
out[1] = 0;
|
|
2644
|
+
out[2] = 0;
|
|
2645
|
+
out[3] = 1;
|
|
2646
|
+
return out;
|
|
2647
|
+
} else {
|
|
2648
|
+
cross(tmpvec3, a, b);
|
|
2649
|
+
out[0] = tmpvec3[0];
|
|
2650
|
+
out[1] = tmpvec3[1];
|
|
2651
|
+
out[2] = tmpvec3[2];
|
|
2652
|
+
out[3] = 1 + dot4;
|
|
2653
|
+
return normalize3(out, out);
|
|
2654
|
+
}
|
|
2655
|
+
};
|
|
2656
|
+
})();
|
|
2657
|
+
var sqlerp = (function() {
|
|
2658
|
+
var temp1 = create5();
|
|
2659
|
+
var temp2 = create5();
|
|
2660
|
+
return function(out, a, b, c, d, t) {
|
|
2661
|
+
slerp2(temp1, a, d, t);
|
|
2662
|
+
slerp2(temp2, b, c, t);
|
|
2663
|
+
slerp2(out, temp1, temp2, 2 * t * (1 - t));
|
|
2664
|
+
return out;
|
|
2665
|
+
};
|
|
2666
|
+
})();
|
|
2667
|
+
var setAxes = (function() {
|
|
2668
|
+
var matr = create();
|
|
2669
|
+
return function(out, view, right, up) {
|
|
2670
|
+
matr[0] = right[0];
|
|
2671
|
+
matr[3] = right[1];
|
|
2672
|
+
matr[6] = right[2];
|
|
2673
|
+
matr[1] = up[0];
|
|
2674
|
+
matr[4] = up[1];
|
|
2675
|
+
matr[7] = up[2];
|
|
2676
|
+
matr[2] = -view[0];
|
|
2677
|
+
matr[5] = -view[1];
|
|
2678
|
+
matr[8] = -view[2];
|
|
2679
|
+
return normalize3(out, fromMat3(out, matr));
|
|
2680
|
+
};
|
|
2681
|
+
})();
|
|
2682
|
+
|
|
2683
|
+
// ../GenesisGL/src/Core/classes/Camera.ts
|
|
2684
|
+
var Camera = class {
|
|
2685
|
+
constructor(viewportWidth, viewportHeight) {
|
|
2686
|
+
this.viewportWidth = viewportWidth;
|
|
2687
|
+
this.viewportHeight = viewportHeight;
|
|
2688
|
+
}
|
|
2689
|
+
viewportWidth;
|
|
2690
|
+
viewportHeight;
|
|
2691
|
+
target = [0, 0, 0];
|
|
2692
|
+
// camera looks at this
|
|
2693
|
+
/* Translation */
|
|
2694
|
+
position = [0, 0, 0];
|
|
2695
|
+
// 3D position
|
|
2696
|
+
/* Zoom */
|
|
2697
|
+
zoom = 0.89;
|
|
2698
|
+
minZoom = 0.5;
|
|
2699
|
+
maxZoom = 1;
|
|
2700
|
+
zoomSpeed = 0.06;
|
|
2701
|
+
/* Rotation */
|
|
2702
|
+
yaw = 0;
|
|
2703
|
+
// horizontal rotation
|
|
2704
|
+
pitch = 0.5;
|
|
2705
|
+
// vertical rotation
|
|
2706
|
+
near = 0.01;
|
|
2707
|
+
far = 1e3;
|
|
2708
|
+
/* Render Utils */
|
|
2709
|
+
lastViewMatrix;
|
|
2710
|
+
lastProjectionMatrix;
|
|
2711
|
+
// ── Cached matrices (rebuilt only when camera state changes) ──
|
|
2712
|
+
_view = mat4_exports.create();
|
|
2713
|
+
_proj = mat4_exports.create();
|
|
2714
|
+
_mvp = mat4_exports.create();
|
|
2715
|
+
_viewDirty = true;
|
|
2716
|
+
_projDirty = true;
|
|
2717
|
+
/** Translate the camera by a delta. */
|
|
2718
|
+
move(dx, dy, dz = 0) {
|
|
2719
|
+
this.position[0] += dx;
|
|
2720
|
+
this.position[1] += dy;
|
|
2721
|
+
this.position[2] += dz;
|
|
2722
|
+
this._viewDirty = true;
|
|
2723
|
+
}
|
|
2724
|
+
/** Clamp-set the zoom level. */
|
|
2725
|
+
setZoom(zoom) {
|
|
2726
|
+
this.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, zoom));
|
|
2727
|
+
this._viewDirty = true;
|
|
2728
|
+
this._projDirty = true;
|
|
2729
|
+
}
|
|
2730
|
+
/**
|
|
2731
|
+
* Mark the view matrix as dirty so it is rebuilt on the next
|
|
2732
|
+
* {@link getViewMatrix} call. Call this after directly mutating
|
|
2733
|
+
* {@link target} or {@link position} (e.g. from a follow-camera update).
|
|
2734
|
+
*/
|
|
2735
|
+
invalidate() {
|
|
2736
|
+
this._viewDirty = true;
|
|
2737
|
+
}
|
|
2738
|
+
/** Zoom by a signed delta (positive = zoom in). */
|
|
2739
|
+
zoomBy(delta) {
|
|
2740
|
+
const factor = Math.exp(delta * this.zoomSpeed);
|
|
2741
|
+
this.setZoom(this.zoom * factor);
|
|
2742
|
+
}
|
|
2743
|
+
worldToNDC(x, y) {
|
|
2744
|
+
const ndcX = (x - this.position[0]) / this.viewportWidth * 2 * this.zoom;
|
|
2745
|
+
const ndcY = (y - this.position[1]) / this.viewportHeight * 2 * this.zoom;
|
|
2746
|
+
return [ndcX, ndcY];
|
|
2747
|
+
}
|
|
2748
|
+
worldScale(scale5) {
|
|
2749
|
+
return [
|
|
2750
|
+
scale5[0] / this.viewportWidth * 2 * this.zoom,
|
|
2751
|
+
scale5[1] / this.viewportHeight * 2 * this.zoom
|
|
2752
|
+
];
|
|
2753
|
+
}
|
|
2754
|
+
setViewport(width, height) {
|
|
2755
|
+
this.viewportWidth = width;
|
|
2756
|
+
this.viewportHeight = height;
|
|
2757
|
+
this._projDirty = true;
|
|
2758
|
+
}
|
|
2759
|
+
/** Compute the eye position from yaw/pitch/distance to target. */
|
|
2760
|
+
getComputedPosition() {
|
|
2761
|
+
const radius = vec3_exports.distance(this.position, this.target);
|
|
2762
|
+
const camX = this.target[0] + radius * Math.cos(this.pitch) * Math.sin(this.yaw);
|
|
2763
|
+
const camY = this.target[1] + radius * Math.sin(this.pitch);
|
|
2764
|
+
const camZ = this.target[2] + radius * Math.cos(this.pitch) * Math.cos(this.yaw);
|
|
2765
|
+
return vec3_exports.fromValues(camX, camY, camZ);
|
|
2766
|
+
}
|
|
2767
|
+
/** Build the view matrix (lookAt). Returns a cached matrix rebuilt only when the camera moves. */
|
|
2768
|
+
getViewMatrix() {
|
|
2769
|
+
if (this._viewDirty) {
|
|
2770
|
+
const eye = this.getComputedPosition();
|
|
2771
|
+
mat4_exports.lookAt(this._view, eye, this.target, vec3_exports.fromValues(0, 1, 0));
|
|
2772
|
+
this._viewDirty = false;
|
|
2773
|
+
this.lastViewMatrix = this._view;
|
|
2774
|
+
}
|
|
2775
|
+
return this._view;
|
|
2776
|
+
}
|
|
2777
|
+
/** Build the perspective projection matrix. Returns a cached matrix rebuilt only when viewport/zoom changes. */
|
|
2778
|
+
getProjectionMatrix() {
|
|
2779
|
+
if (this._projDirty) {
|
|
2780
|
+
const aspect = this.viewportWidth / this.viewportHeight;
|
|
2781
|
+
const fov = Math.PI / 4 / this.zoom;
|
|
2782
|
+
mat4_exports.perspective(this._proj, fov, aspect, this.near, this.far);
|
|
2783
|
+
this._projDirty = false;
|
|
2784
|
+
this.lastProjectionMatrix = this._proj;
|
|
2785
|
+
}
|
|
2786
|
+
return this._proj;
|
|
2787
|
+
}
|
|
2788
|
+
worldToNDC3D(x, y, z = 0) {
|
|
2789
|
+
const world = vec4_exports.fromValues(x, y, z, 1);
|
|
2790
|
+
mat4_exports.multiply(this._mvp, this.getProjectionMatrix(), this.getViewMatrix());
|
|
2791
|
+
vec4_exports.transformMat4(world, world, this._mvp);
|
|
2792
|
+
return [world[0] / world[3], world[1] / world[3], world[2] / world[3]];
|
|
2793
|
+
}
|
|
2794
|
+
worldScale3D(scale5) {
|
|
2795
|
+
return [
|
|
2796
|
+
scale5[0] / this.viewportWidth * 2 * this.zoom,
|
|
2797
|
+
scale5[1] / this.viewportHeight * 2 * this.zoom,
|
|
2798
|
+
scale5[2] / ((this.viewportWidth + this.viewportHeight) / 2) * 2 * this.zoom
|
|
2799
|
+
];
|
|
2800
|
+
}
|
|
2801
|
+
minPitch = -Math.PI / 2 + 1.49;
|
|
2802
|
+
maxPitch = Math.PI / 2 - 0.01;
|
|
2803
|
+
rotate(deltaYaw, deltaPitch) {
|
|
2804
|
+
this.yaw += deltaYaw;
|
|
2805
|
+
this.pitch -= deltaPitch;
|
|
2806
|
+
this.pitch = Math.max(this.minPitch, Math.min(this.maxPitch, this.pitch));
|
|
2807
|
+
this._viewDirty = true;
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2810
|
+
|
|
2811
|
+
// ../GenesisGL/src/Core/controls/Mouse/MouseWheelControl.ts
|
|
2812
|
+
var MouseWheelControl = class {
|
|
2813
|
+
listeners = [];
|
|
2814
|
+
wheelHandler;
|
|
2815
|
+
enable() {
|
|
2816
|
+
if (this.wheelHandler) return;
|
|
2817
|
+
this.wheelHandler = (e) => {
|
|
2818
|
+
const direction = e.deltaY < 0 ? "up" : "down";
|
|
2819
|
+
this.notify(direction, e.deltaY);
|
|
2820
|
+
};
|
|
2821
|
+
window.addEventListener("wheel", this.wheelHandler, { passive: true });
|
|
2822
|
+
}
|
|
2823
|
+
disable() {
|
|
2824
|
+
if (this.wheelHandler) {
|
|
2825
|
+
window.removeEventListener("wheel", this.wheelHandler);
|
|
2826
|
+
this.wheelHandler = void 0;
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
onChange(listener) {
|
|
2830
|
+
this.listeners.push(listener);
|
|
2831
|
+
}
|
|
2832
|
+
/** Remove a previously registered listener. */
|
|
2833
|
+
removeListener(listener) {
|
|
2834
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
2835
|
+
}
|
|
2836
|
+
notify(direction, delta) {
|
|
2837
|
+
for (const listener of this.listeners) listener(direction, delta);
|
|
2838
|
+
}
|
|
2839
|
+
};
|
|
2840
|
+
|
|
2841
|
+
// ../GenesisGL/src/Core/controls/Mouse/MouseDragControl.ts
|
|
2842
|
+
var MouseDragControl = class {
|
|
2843
|
+
constructor(element) {
|
|
2844
|
+
this.element = element;
|
|
2845
|
+
}
|
|
2846
|
+
element;
|
|
2847
|
+
listeners = [];
|
|
2848
|
+
isDragging = false;
|
|
2849
|
+
dragButton = 0;
|
|
2850
|
+
// 0 = left, 2 = right
|
|
2851
|
+
lastX = 0;
|
|
2852
|
+
lastY = 0;
|
|
2853
|
+
enable() {
|
|
2854
|
+
this.element.addEventListener("mousedown", this.onMouseDown);
|
|
2855
|
+
window.addEventListener("mouseup", this.onMouseUp);
|
|
2856
|
+
window.addEventListener("mousemove", this.onMouseMove);
|
|
2857
|
+
}
|
|
2858
|
+
disable() {
|
|
2859
|
+
this.element.removeEventListener("mousedown", this.onMouseDown);
|
|
2860
|
+
window.removeEventListener("mouseup", this.onMouseUp);
|
|
2861
|
+
window.removeEventListener("mousemove", this.onMouseMove);
|
|
2862
|
+
}
|
|
2863
|
+
onChange(listener) {
|
|
2864
|
+
this.listeners.push(listener);
|
|
2865
|
+
}
|
|
2866
|
+
/** Remove a previously registered listener. */
|
|
2867
|
+
removeListener(listener) {
|
|
2868
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
2869
|
+
}
|
|
2870
|
+
onMouseDown = (e) => {
|
|
2871
|
+
this.isDragging = true;
|
|
2872
|
+
this.dragButton = e.button;
|
|
2873
|
+
this.lastX = e.clientX;
|
|
2874
|
+
this.lastY = e.clientY;
|
|
2875
|
+
};
|
|
2876
|
+
onMouseUp = () => {
|
|
2877
|
+
this.isDragging = false;
|
|
2878
|
+
};
|
|
2879
|
+
onMouseMove = (e) => {
|
|
2880
|
+
if (!this.isDragging) return;
|
|
2881
|
+
const dx = e.clientX - this.lastX;
|
|
2882
|
+
const dy = e.clientY - this.lastY;
|
|
2883
|
+
this.lastX = e.clientX;
|
|
2884
|
+
this.lastY = e.clientY;
|
|
2885
|
+
for (const listener of this.listeners) listener(dx, dy, this.dragButton);
|
|
2886
|
+
};
|
|
2887
|
+
};
|
|
2888
|
+
|
|
2889
|
+
// ../GenesisGL/src/Core/controls/Mouse/MousePointerLockControl.ts
|
|
2890
|
+
var MousePointerLockControl = class {
|
|
2891
|
+
constructor(element, sensitivity = 1) {
|
|
2892
|
+
this.element = element;
|
|
2893
|
+
this.sensitivity = sensitivity;
|
|
2894
|
+
}
|
|
2895
|
+
element;
|
|
2896
|
+
sensitivity;
|
|
2897
|
+
listeners = [];
|
|
2898
|
+
isEnabled = false;
|
|
2899
|
+
isPointerLocked = false;
|
|
2900
|
+
enable() {
|
|
2901
|
+
if (this.isEnabled) return;
|
|
2902
|
+
this.isEnabled = true;
|
|
2903
|
+
this.element.addEventListener("click", this.requestPointerLock);
|
|
2904
|
+
document.addEventListener("pointerlockchange", this.onPointerLockChange);
|
|
2905
|
+
document.addEventListener("mousemove", this.onMouseMove);
|
|
2906
|
+
}
|
|
2907
|
+
disable() {
|
|
2908
|
+
if (!this.isEnabled) return;
|
|
2909
|
+
this.isEnabled = false;
|
|
2910
|
+
this.element.removeEventListener("click", this.requestPointerLock);
|
|
2911
|
+
document.removeEventListener("pointerlockchange", this.onPointerLockChange);
|
|
2912
|
+
document.removeEventListener("mousemove", this.onMouseMove);
|
|
2913
|
+
if (this.isPointerLocked) document.exitPointerLock();
|
|
2914
|
+
}
|
|
2915
|
+
onChange(listener) {
|
|
2916
|
+
this.listeners.push(listener);
|
|
2917
|
+
}
|
|
2918
|
+
/** Remove a previously registered listener. */
|
|
2919
|
+
removeListener(listener) {
|
|
2920
|
+
this.listeners = this.listeners.filter((l) => l !== listener);
|
|
2921
|
+
}
|
|
2922
|
+
setSensitivity(value) {
|
|
2923
|
+
this.sensitivity = value;
|
|
2924
|
+
}
|
|
2925
|
+
requestPointerLock = () => {
|
|
2926
|
+
this.element.requestPointerLock();
|
|
2927
|
+
};
|
|
2928
|
+
onPointerLockChange = () => {
|
|
2929
|
+
this.isPointerLocked = document.pointerLockElement === this.element;
|
|
2930
|
+
};
|
|
2931
|
+
onMouseMove = (e) => {
|
|
2932
|
+
if (!this.isPointerLocked) return;
|
|
2933
|
+
const dx = e.movementX * this.sensitivity;
|
|
2934
|
+
const dy = e.movementY * this.sensitivity;
|
|
2935
|
+
for (const listener of this.listeners) listener(dx, dy);
|
|
2936
|
+
};
|
|
2937
|
+
};
|
|
2938
|
+
|
|
2939
|
+
// ../GenesisGL/src/Core/classes/Viewport.ts
|
|
2940
|
+
var Viewport = class _Viewport {
|
|
2941
|
+
/**
|
|
2942
|
+
* @param canvasOrId - An HTMLCanvasElement or the `id` attribute of one.
|
|
2943
|
+
* @param width - Logical viewport width.
|
|
2944
|
+
* @param height - Logical viewport height.
|
|
2945
|
+
* @param webglCore - Optional WebGLCore instance. When provided, the existing
|
|
2946
|
+
* GL context is reused for viewport resize instead of
|
|
2947
|
+
* requesting a new one.
|
|
2948
|
+
*/
|
|
2949
|
+
constructor(canvasOrId, width, height, webglCore) {
|
|
2950
|
+
this.width = width;
|
|
2951
|
+
this.height = height;
|
|
2952
|
+
this.canvas = typeof canvasOrId === "string" ? document.getElementById(canvasOrId) : canvasOrId;
|
|
2953
|
+
if (!this.canvas) throw new Error("Canvas not found");
|
|
2954
|
+
this.webglCore = webglCore ?? null;
|
|
2955
|
+
this.camera = new Camera(width, height);
|
|
2956
|
+
this.dragControl = new MouseDragControl(this.canvas);
|
|
2957
|
+
this.moveControl = new MousePointerLockControl(this.canvas, 0.25);
|
|
2958
|
+
this.resizeCanvas();
|
|
2959
|
+
this.setupControls();
|
|
2960
|
+
window.addEventListener("resize", this.resizeHandler);
|
|
2961
|
+
}
|
|
2962
|
+
width;
|
|
2963
|
+
height;
|
|
2964
|
+
static zoomInterval = 25;
|
|
2965
|
+
wheelControl = new MouseWheelControl();
|
|
2966
|
+
dragControl;
|
|
2967
|
+
moveControl;
|
|
2968
|
+
lastZoomTime = 0;
|
|
2969
|
+
canvas;
|
|
2970
|
+
scale = 1;
|
|
2971
|
+
webglCore = null;
|
|
2972
|
+
resizeHandler = () => this.resizeCanvas();
|
|
2973
|
+
camera;
|
|
2974
|
+
setupControls() {
|
|
2975
|
+
const zoomInterval = _Viewport.zoomInterval;
|
|
2976
|
+
this.wheelControl.onChange((direction) => {
|
|
2977
|
+
const now = performance.now();
|
|
2978
|
+
if (now - this.lastZoomTime < zoomInterval) return;
|
|
2979
|
+
const zoomDelta = direction === "up" ? 1 : -1;
|
|
2980
|
+
this.camera.zoomBy(zoomDelta);
|
|
2981
|
+
this.lastZoomTime = now;
|
|
2982
|
+
});
|
|
2983
|
+
this.wheelControl.enable();
|
|
2984
|
+
this.moveControl.onChange((dx, dy) => {
|
|
2985
|
+
const factor = 0.01 * this.camera.zoom;
|
|
2986
|
+
this.camera.rotate(-dx * factor, -dy * factor);
|
|
2987
|
+
});
|
|
2988
|
+
this.moveControl.enable();
|
|
2989
|
+
this.canvas.addEventListener("contextmenu", (e) => e.preventDefault());
|
|
2990
|
+
}
|
|
2991
|
+
isDraggingCamera() {
|
|
2992
|
+
return this.dragControl.isDragging;
|
|
2993
|
+
}
|
|
2994
|
+
resizeCanvas() {
|
|
2995
|
+
const screenWidth = window.innerWidth;
|
|
2996
|
+
const screenHeight = window.innerHeight;
|
|
2997
|
+
const aspectViewport = this.width / this.height;
|
|
2998
|
+
const aspectScreen = screenWidth / screenHeight;
|
|
2999
|
+
let canvasWidth, canvasHeight;
|
|
3000
|
+
if (aspectScreen > aspectViewport) {
|
|
3001
|
+
canvasHeight = screenHeight;
|
|
3002
|
+
canvasWidth = canvasHeight * aspectViewport;
|
|
3003
|
+
} else {
|
|
3004
|
+
canvasWidth = screenWidth;
|
|
3005
|
+
canvasHeight = canvasWidth / aspectViewport;
|
|
3006
|
+
}
|
|
3007
|
+
this.canvas.width = canvasWidth;
|
|
3008
|
+
this.canvas.height = canvasHeight;
|
|
3009
|
+
this.scale = canvasWidth / this.width;
|
|
3010
|
+
const gl = this.webglCore ? this.webglCore.getRenderingContext() : this.canvas.getContext("webgl2") ?? this.canvas.getContext("webgl");
|
|
3011
|
+
if (!gl) throw new Error("WebGL not supported");
|
|
3012
|
+
gl.viewport(0, 0, canvasWidth, canvasHeight);
|
|
3013
|
+
this.camera.setViewport(canvasWidth, canvasHeight);
|
|
3014
|
+
}
|
|
3015
|
+
getCanvas() {
|
|
3016
|
+
return this.canvas;
|
|
3017
|
+
}
|
|
3018
|
+
getScale() {
|
|
3019
|
+
return this.scale;
|
|
3020
|
+
}
|
|
3021
|
+
/** Release event listeners. Call when the viewport is no longer needed. */
|
|
3022
|
+
dispose() {
|
|
3023
|
+
window.removeEventListener("resize", this.resizeHandler);
|
|
3024
|
+
this.wheelControl.disable();
|
|
3025
|
+
this.dragControl.disable();
|
|
3026
|
+
this.moveControl.disable();
|
|
3027
|
+
}
|
|
3028
|
+
};
|
|
3029
|
+
|
|
3030
|
+
// ../GenesisGL/src/Core/utils/compute-bounds.ts
|
|
3031
|
+
function computeVertexBounds(vertices) {
|
|
3032
|
+
if (!vertices || vertices.length === 0) {
|
|
3033
|
+
return { min: [0, 0, 0], max: [0, 0, 0] };
|
|
3034
|
+
}
|
|
3035
|
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
|
3036
|
+
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
3037
|
+
for (let i = 0; i < vertices.length; i += 3) {
|
|
3038
|
+
const x = vertices[i];
|
|
3039
|
+
const y = vertices[i + 1];
|
|
3040
|
+
const z = vertices[i + 2];
|
|
3041
|
+
if (x < minX) minX = x;
|
|
3042
|
+
if (y < minY) minY = y;
|
|
3043
|
+
if (z < minZ) minZ = z;
|
|
3044
|
+
if (x > maxX) maxX = x;
|
|
3045
|
+
if (y > maxY) maxY = y;
|
|
3046
|
+
if (z > maxZ) maxZ = z;
|
|
3047
|
+
}
|
|
3048
|
+
return {
|
|
3049
|
+
min: [minX, minY, minZ],
|
|
3050
|
+
max: [maxX, maxY, maxZ]
|
|
3051
|
+
};
|
|
3052
|
+
}
|
|
3053
|
+
|
|
3054
|
+
// ../GenesisGL/src/Core/classes/Mesh.ts
|
|
3055
|
+
var GL_LINES = 1;
|
|
3056
|
+
var GL_TRIANGLES = 4;
|
|
3057
|
+
var INITIAL_BOUNDING_BOX = { min: [0, 0, 0], max: [0, 0, 0] };
|
|
3058
|
+
var Mesh = class _Mesh {
|
|
3059
|
+
name;
|
|
3060
|
+
vertices;
|
|
3061
|
+
normals;
|
|
3062
|
+
texCoords;
|
|
3063
|
+
indices;
|
|
3064
|
+
mode;
|
|
3065
|
+
material;
|
|
3066
|
+
// ── Skinning data (optional) ─────────────────────────────────
|
|
3067
|
+
/** Per-vertex joint indices (vec4 per vertex, 4 influences). */
|
|
3068
|
+
jointIndices = null;
|
|
3069
|
+
/** Per-vertex joint weights (vec4 per vertex, 4 influences). */
|
|
3070
|
+
jointWeights = null;
|
|
3071
|
+
// WebGL buffers aggregate
|
|
3072
|
+
buffers = null;
|
|
3073
|
+
boundingBox = INITIAL_BOUNDING_BOX;
|
|
3074
|
+
isCollidable = true;
|
|
3075
|
+
isInitialized = false;
|
|
3076
|
+
constructor(name, vertices, normals, material, texCoords = new Float32Array(), indices = null) {
|
|
3077
|
+
this.mode = GL_TRIANGLES;
|
|
3078
|
+
this.name = name;
|
|
3079
|
+
this.normals = normals;
|
|
3080
|
+
this.indices = indices;
|
|
3081
|
+
this.vertices = vertices;
|
|
3082
|
+
this.texCoords = texCoords;
|
|
3083
|
+
this.material = material;
|
|
3084
|
+
this.computeBounds();
|
|
3085
|
+
}
|
|
3086
|
+
setMode(newMode) {
|
|
3087
|
+
this.mode = newMode;
|
|
3088
|
+
}
|
|
3089
|
+
/** Whether this mesh has skinning data for skeletal animation. */
|
|
3090
|
+
get isSkinned() {
|
|
3091
|
+
return this.jointIndices !== null && this.jointWeights !== null;
|
|
3092
|
+
}
|
|
3093
|
+
computeBounds() {
|
|
3094
|
+
this.boundingBox = computeVertexBounds(this.vertices);
|
|
3095
|
+
}
|
|
3096
|
+
clone() {
|
|
3097
|
+
const clonedMesh = new _Mesh(
|
|
3098
|
+
this.name,
|
|
3099
|
+
new Float32Array(this.vertices),
|
|
3100
|
+
new Float32Array(this.normals),
|
|
3101
|
+
this.material,
|
|
3102
|
+
// shallow ref — call Material.clone() if independent material is needed
|
|
3103
|
+
new Float32Array(this.texCoords),
|
|
3104
|
+
this.indices ? this.indices instanceof Uint16Array ? new Uint16Array(this.indices) : new Uint32Array(this.indices) : null
|
|
3105
|
+
);
|
|
3106
|
+
clonedMesh.setMode(this.mode);
|
|
3107
|
+
clonedMesh.isCollidable = this.isCollidable;
|
|
3108
|
+
if (this.jointIndices)
|
|
3109
|
+
clonedMesh.jointIndices = new Float32Array(this.jointIndices);
|
|
3110
|
+
if (this.jointWeights)
|
|
3111
|
+
clonedMesh.jointWeights = new Float32Array(this.jointWeights);
|
|
3112
|
+
return clonedMesh;
|
|
3113
|
+
}
|
|
3114
|
+
/** Initialize GPU buffers safely */
|
|
3115
|
+
initBuffer(webglCore) {
|
|
3116
|
+
const gl = webglCore.getRenderingContext();
|
|
3117
|
+
if (!gl) {
|
|
3118
|
+
console.warn(
|
|
3119
|
+
`[Mesh:${this.name}] GL context not available, skipping buffer init.`
|
|
3120
|
+
);
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
if (this.isInitialized) return;
|
|
3124
|
+
this.buffers = new MeshBuffers();
|
|
3125
|
+
this.buffers.init(gl, this);
|
|
3126
|
+
this.isInitialized = true;
|
|
3127
|
+
}
|
|
3128
|
+
/** Dispose of GPU buffers safely */
|
|
3129
|
+
dispose(webglCore) {
|
|
3130
|
+
const gl = webglCore.getRenderingContext();
|
|
3131
|
+
if (!gl || !this.buffers) return;
|
|
3132
|
+
this.buffers.dispose(gl);
|
|
3133
|
+
this.buffers = null;
|
|
3134
|
+
this.isInitialized = false;
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3137
|
+
var MeshBuffers = class {
|
|
3138
|
+
vao = null;
|
|
3139
|
+
vertexBuffer = null;
|
|
3140
|
+
normalBuffer = null;
|
|
3141
|
+
texCoordBuffer = null;
|
|
3142
|
+
indexBuffer = null;
|
|
3143
|
+
jointIndexBuffer = null;
|
|
3144
|
+
jointWeightBuffer = null;
|
|
3145
|
+
init(gl, mesh) {
|
|
3146
|
+
if (!gl) throw new Error("Cannot init MeshBuffers: invalid GL context");
|
|
3147
|
+
const isWebGL2 = gl instanceof WebGL2RenderingContext;
|
|
3148
|
+
const gl2 = isWebGL2 ? gl : null;
|
|
3149
|
+
if (gl2) {
|
|
3150
|
+
this.vao = gl2.createVertexArray();
|
|
3151
|
+
gl2.bindVertexArray(this.vao);
|
|
3152
|
+
}
|
|
3153
|
+
const program = mesh.material?.program;
|
|
3154
|
+
const aPosition = program ? gl.getAttribLocation(program, "aPosition") : 0;
|
|
3155
|
+
const aNormal = program ? gl.getAttribLocation(program, "aNormal") : 1;
|
|
3156
|
+
const aTexCoord = program ? gl.getAttribLocation(program, "aTexCoord") : 2;
|
|
3157
|
+
this.vertexBuffer = gl.createBuffer();
|
|
3158
|
+
if (!this.vertexBuffer) throw new Error("Failed to create vertex buffer");
|
|
3159
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
3160
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.vertices, gl.STATIC_DRAW);
|
|
3161
|
+
if (aPosition !== -1) {
|
|
3162
|
+
gl.enableVertexAttribArray(aPosition);
|
|
3163
|
+
gl.vertexAttribPointer(aPosition, 3, gl.FLOAT, false, 0, 0);
|
|
3164
|
+
}
|
|
3165
|
+
this.normalBuffer = gl.createBuffer();
|
|
3166
|
+
if (!this.normalBuffer) throw new Error("Failed to create normal buffer");
|
|
3167
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
|
|
3168
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.normals, gl.STATIC_DRAW);
|
|
3169
|
+
if (aNormal !== -1) {
|
|
3170
|
+
gl.enableVertexAttribArray(aNormal);
|
|
3171
|
+
gl.vertexAttribPointer(aNormal, 3, gl.FLOAT, false, 0, 0);
|
|
3172
|
+
}
|
|
3173
|
+
if (mesh.texCoords.length > 0) {
|
|
3174
|
+
this.texCoordBuffer = gl.createBuffer();
|
|
3175
|
+
if (!this.texCoordBuffer)
|
|
3176
|
+
throw new Error("Failed to create texCoord buffer");
|
|
3177
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
|
|
3178
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.texCoords, gl.STATIC_DRAW);
|
|
3179
|
+
if (aTexCoord !== -1) {
|
|
3180
|
+
gl.enableVertexAttribArray(aTexCoord);
|
|
3181
|
+
gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, 0, 0);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
if (mesh.indices && mesh.indices.length > 0) {
|
|
3185
|
+
this.indexBuffer = gl.createBuffer();
|
|
3186
|
+
if (!this.indexBuffer) throw new Error("Failed to create index buffer");
|
|
3187
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
|
3188
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, mesh.indices, gl.STATIC_DRAW);
|
|
3189
|
+
}
|
|
3190
|
+
const aJointIndices = program ? gl.getAttribLocation(program, "aJointIndices") : -1;
|
|
3191
|
+
if (mesh.jointIndices && mesh.jointIndices.length > 0 && aJointIndices !== -1) {
|
|
3192
|
+
this.jointIndexBuffer = gl.createBuffer();
|
|
3193
|
+
if (!this.jointIndexBuffer)
|
|
3194
|
+
throw new Error("Failed to create joint index buffer");
|
|
3195
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.jointIndexBuffer);
|
|
3196
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.jointIndices, gl.STATIC_DRAW);
|
|
3197
|
+
gl.enableVertexAttribArray(aJointIndices);
|
|
3198
|
+
gl.vertexAttribPointer(aJointIndices, 4, gl.FLOAT, false, 0, 0);
|
|
3199
|
+
}
|
|
3200
|
+
const aJointWeights = program ? gl.getAttribLocation(program, "aJointWeights") : -1;
|
|
3201
|
+
if (mesh.jointWeights && mesh.jointWeights.length > 0 && aJointWeights !== -1) {
|
|
3202
|
+
this.jointWeightBuffer = gl.createBuffer();
|
|
3203
|
+
if (!this.jointWeightBuffer)
|
|
3204
|
+
throw new Error("Failed to create joint weight buffer");
|
|
3205
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.jointWeightBuffer);
|
|
3206
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.jointWeights, gl.STATIC_DRAW);
|
|
3207
|
+
gl.enableVertexAttribArray(aJointWeights);
|
|
3208
|
+
gl.vertexAttribPointer(aJointWeights, 4, gl.FLOAT, false, 0, 0);
|
|
3209
|
+
}
|
|
3210
|
+
if (gl2) {
|
|
3211
|
+
gl2.bindVertexArray(null);
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
dispose(gl) {
|
|
3215
|
+
if (!gl) {
|
|
3216
|
+
console.warn("Cannot dispose MeshBuffers: invalid GL context");
|
|
3217
|
+
return;
|
|
3218
|
+
}
|
|
3219
|
+
const isWebGL2 = gl instanceof WebGL2RenderingContext;
|
|
3220
|
+
if (this.vertexBuffer) gl.deleteBuffer(this.vertexBuffer);
|
|
3221
|
+
if (this.normalBuffer) gl.deleteBuffer(this.normalBuffer);
|
|
3222
|
+
if (this.texCoordBuffer) gl.deleteBuffer(this.texCoordBuffer);
|
|
3223
|
+
if (this.indexBuffer) gl.deleteBuffer(this.indexBuffer);
|
|
3224
|
+
if (this.jointIndexBuffer) gl.deleteBuffer(this.jointIndexBuffer);
|
|
3225
|
+
if (this.jointWeightBuffer) gl.deleteBuffer(this.jointWeightBuffer);
|
|
3226
|
+
if (isWebGL2 && this.vao) {
|
|
3227
|
+
gl.deleteVertexArray(this.vao);
|
|
3228
|
+
}
|
|
3229
|
+
this.vertexBuffer = this.normalBuffer = this.texCoordBuffer = this.indexBuffer = this.jointIndexBuffer = this.jointWeightBuffer = this.vao = null;
|
|
3230
|
+
}
|
|
3231
|
+
};
|
|
3232
|
+
|
|
3233
|
+
// ../GenesisGL/src/Core/utils/load-texture.ts
|
|
3234
|
+
async function loadWebGlTexture(gl, url, options = {}) {
|
|
3235
|
+
return new Promise((resolve, reject) => {
|
|
3236
|
+
const texture = gl.createTexture();
|
|
3237
|
+
if (!texture) return reject(new Error("Failed to create texture"));
|
|
3238
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
3239
|
+
const level = 0;
|
|
3240
|
+
const internalFormat = gl.RGBA;
|
|
3241
|
+
const width = 1;
|
|
3242
|
+
const height = 1;
|
|
3243
|
+
const border = 0;
|
|
3244
|
+
const srcFormat = gl.RGBA;
|
|
3245
|
+
const srcType = gl.UNSIGNED_BYTE;
|
|
3246
|
+
const pixel = new Uint8Array([128, 128, 128, 255]);
|
|
3247
|
+
gl.texImage2D(
|
|
3248
|
+
gl.TEXTURE_2D,
|
|
3249
|
+
level,
|
|
3250
|
+
internalFormat,
|
|
3251
|
+
width,
|
|
3252
|
+
height,
|
|
3253
|
+
border,
|
|
3254
|
+
srcFormat,
|
|
3255
|
+
srcType,
|
|
3256
|
+
pixel
|
|
3257
|
+
);
|
|
3258
|
+
const image = new Image();
|
|
3259
|
+
image.crossOrigin = "anonymous";
|
|
3260
|
+
image.onload = () => {
|
|
3261
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
3262
|
+
gl.texImage2D(
|
|
3263
|
+
gl.TEXTURE_2D,
|
|
3264
|
+
level,
|
|
3265
|
+
internalFormat,
|
|
3266
|
+
srcFormat,
|
|
3267
|
+
srcType,
|
|
3268
|
+
image
|
|
3269
|
+
);
|
|
3270
|
+
if (isPowerOf2(image.width) && isPowerOf2(image.height)) {
|
|
3271
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
3272
|
+
gl.texParameteri(
|
|
3273
|
+
gl.TEXTURE_2D,
|
|
3274
|
+
gl.TEXTURE_MIN_FILTER,
|
|
3275
|
+
gl.LINEAR_MIPMAP_LINEAR
|
|
3276
|
+
);
|
|
3277
|
+
if (options.repeat) {
|
|
3278
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
|
|
3279
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
|
|
3280
|
+
}
|
|
3281
|
+
} else {
|
|
3282
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
3283
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
3284
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
3285
|
+
}
|
|
3286
|
+
resolve(texture);
|
|
3287
|
+
};
|
|
3288
|
+
image.onerror = reject;
|
|
3289
|
+
image.src = url;
|
|
3290
|
+
});
|
|
3291
|
+
}
|
|
3292
|
+
function isPowerOf2(value) {
|
|
3293
|
+
return (value & value - 1) === 0;
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
// ../GenesisGL/src/Core/utils/parse-hex-to-rgb.ts
|
|
3297
|
+
function parseHexToRgbArray(hex) {
|
|
3298
|
+
if (hex.startsWith("#")) hex = hex.slice(1);
|
|
3299
|
+
let r = 1, g = 1, b = 1, a = 1;
|
|
3300
|
+
if (hex.length === 6) {
|
|
3301
|
+
r = parseInt(hex.slice(0, 2), 16) / 255;
|
|
3302
|
+
g = parseInt(hex.slice(2, 4), 16) / 255;
|
|
3303
|
+
b = parseInt(hex.slice(4, 6), 16) / 255;
|
|
3304
|
+
a = 1;
|
|
3305
|
+
} else if (hex.length === 8) {
|
|
3306
|
+
r = parseInt(hex.slice(0, 2), 16) / 255;
|
|
3307
|
+
g = parseInt(hex.slice(2, 4), 16) / 255;
|
|
3308
|
+
b = parseInt(hex.slice(4, 6), 16) / 255;
|
|
3309
|
+
a = parseInt(hex.slice(6, 8), 16) / 255;
|
|
3310
|
+
} else {
|
|
3311
|
+
throw new Error("Invalid hex color format. Use #RRGGBB or #RRGGBBAA.");
|
|
3312
|
+
}
|
|
3313
|
+
return [r, g, b, a];
|
|
3314
|
+
}
|
|
3315
|
+
|
|
3316
|
+
// ../GenesisGL/src/Core/classes/Material.ts
|
|
3317
|
+
var MAX_LIGHTS = 5;
|
|
3318
|
+
var Material = class _Material {
|
|
3319
|
+
constructor(webglCore, options = {}) {
|
|
3320
|
+
this.webglCore = webglCore;
|
|
3321
|
+
this.program = webglCore.getProgram();
|
|
3322
|
+
const { gl } = webglCore;
|
|
3323
|
+
const names = [
|
|
3324
|
+
"uColor",
|
|
3325
|
+
"uUnlit",
|
|
3326
|
+
"uModel",
|
|
3327
|
+
"uView",
|
|
3328
|
+
"uProjection",
|
|
3329
|
+
"uLightCount",
|
|
3330
|
+
"uUseTexture",
|
|
3331
|
+
"uTexture",
|
|
3332
|
+
// --- LIGHTING UNIFORMS ---
|
|
3333
|
+
"uViewPosition",
|
|
3334
|
+
// Camera position for specular light
|
|
3335
|
+
"uShininess",
|
|
3336
|
+
"uSpecularColor",
|
|
3337
|
+
"uAmbientColor",
|
|
3338
|
+
"uDissolve",
|
|
3339
|
+
"uDiffuseColor",
|
|
3340
|
+
"uLightDirection[0]",
|
|
3341
|
+
"uLightColor[0]",
|
|
3342
|
+
"uLightIntensity[0]",
|
|
3343
|
+
"uLightType[0]",
|
|
3344
|
+
"uLightPosition[0]",
|
|
3345
|
+
// NEW: For Point Lights
|
|
3346
|
+
"uLightConstant[0]",
|
|
3347
|
+
// NEW: Attenuation
|
|
3348
|
+
"uLightLinear[0]",
|
|
3349
|
+
// NEW: Attenuation
|
|
3350
|
+
"uLightQuadratic[0]",
|
|
3351
|
+
// NEW: Attenuation
|
|
3352
|
+
// --- SKINNING UNIFORMS ---
|
|
3353
|
+
"uUseSkinning",
|
|
3354
|
+
"uJointMatrices[0]"
|
|
3355
|
+
];
|
|
3356
|
+
for (const name of names) {
|
|
3357
|
+
this.uniformLocations[name] = gl.getUniformLocation(this.program, name);
|
|
3358
|
+
}
|
|
3359
|
+
const attribs = [
|
|
3360
|
+
"aPosition",
|
|
3361
|
+
"aNormal",
|
|
3362
|
+
"aTexCoord",
|
|
3363
|
+
"aJointIndices",
|
|
3364
|
+
"aJointWeights"
|
|
3365
|
+
];
|
|
3366
|
+
for (const name of attribs) {
|
|
3367
|
+
this.attribLocations[name] = gl.getAttribLocation(this.program, name);
|
|
3368
|
+
}
|
|
3369
|
+
Object.assign(this, options);
|
|
3370
|
+
}
|
|
3371
|
+
webglCore;
|
|
3372
|
+
// cache
|
|
3373
|
+
program;
|
|
3374
|
+
uniformLocations = {};
|
|
3375
|
+
attribLocations = {};
|
|
3376
|
+
// Attributes
|
|
3377
|
+
albedoColor = [1, 1, 1, 1];
|
|
3378
|
+
unlit = false;
|
|
3379
|
+
texture;
|
|
3380
|
+
specular = [0.3, 0.3, 0.3];
|
|
3381
|
+
shininess = 64;
|
|
3382
|
+
doubleSided = false;
|
|
3383
|
+
//others
|
|
3384
|
+
ambientColor = [0.1, 0.1, 0.1];
|
|
3385
|
+
// Ka
|
|
3386
|
+
dissolve = 1;
|
|
3387
|
+
// d or Tr
|
|
3388
|
+
diffuse = [1, 1, 1];
|
|
3389
|
+
// Kd
|
|
3390
|
+
/** Physics friction coefficient [0–1]. 0 = no resistance (ice), 1 = instant stop. */
|
|
3391
|
+
friction = 0.3;
|
|
3392
|
+
// ── Pre-allocated light uniform buffers (reused every frame, zero GC pressure) ──
|
|
3393
|
+
_lightDirs = new Float32Array(MAX_LIGHTS * 3);
|
|
3394
|
+
_lightColors = new Float32Array(MAX_LIGHTS * 3);
|
|
3395
|
+
_lightIntensities = new Float32Array(MAX_LIGHTS);
|
|
3396
|
+
_lightTypes = new Int32Array(MAX_LIGHTS);
|
|
3397
|
+
_lightPositions = new Float32Array(MAX_LIGHTS * 3);
|
|
3398
|
+
_lightConstants = new Float32Array(MAX_LIGHTS);
|
|
3399
|
+
_lightLinears = new Float32Array(MAX_LIGHTS);
|
|
3400
|
+
_lightQuadratics = new Float32Array(MAX_LIGHTS);
|
|
3401
|
+
setColorHex(hex) {
|
|
3402
|
+
this.albedoColor = parseHexToRgbArray(hex);
|
|
3403
|
+
}
|
|
3404
|
+
setColor(rgba) {
|
|
3405
|
+
this.albedoColor = rgba;
|
|
3406
|
+
this.dissolve = rgba[3];
|
|
3407
|
+
this.diffuse = [rgba[0], rgba[1], rgba[2]];
|
|
3408
|
+
}
|
|
3409
|
+
/**
|
|
3410
|
+
* Load an image from URL and create a WebGL texture.
|
|
3411
|
+
*/
|
|
3412
|
+
async loadTexture(url, options) {
|
|
3413
|
+
const { gl } = this.webglCore;
|
|
3414
|
+
this.texture = await loadWebGlTexture(gl, url, options);
|
|
3415
|
+
}
|
|
3416
|
+
/**
|
|
3417
|
+
* Create an independent copy of this material.
|
|
3418
|
+
* Shares the same WebGL program but copies all mutable properties.
|
|
3419
|
+
* The texture reference is shared (immutable GPU resource).
|
|
3420
|
+
*/
|
|
3421
|
+
clone() {
|
|
3422
|
+
const copy5 = new _Material(this.webglCore);
|
|
3423
|
+
copy5.albedoColor = [...this.albedoColor];
|
|
3424
|
+
copy5.specular = [...this.specular];
|
|
3425
|
+
copy5.ambientColor = [...this.ambientColor];
|
|
3426
|
+
copy5.diffuse = [...this.diffuse];
|
|
3427
|
+
copy5.shininess = this.shininess;
|
|
3428
|
+
copy5.dissolve = this.dissolve;
|
|
3429
|
+
copy5.unlit = this.unlit;
|
|
3430
|
+
copy5.doubleSided = this.doubleSided;
|
|
3431
|
+
copy5.friction = this.friction;
|
|
3432
|
+
copy5.texture = this.texture;
|
|
3433
|
+
return copy5;
|
|
3434
|
+
}
|
|
3435
|
+
apply(gl, lights, viewPosition) {
|
|
3436
|
+
if (this.uniformLocations["uColor"])
|
|
3437
|
+
gl.uniform4fv(this.uniformLocations["uColor"], this.albedoColor);
|
|
3438
|
+
if (this.uniformLocations["uUnlit"])
|
|
3439
|
+
gl.uniform1i(this.uniformLocations["uUnlit"], this.unlit ? 1 : 0);
|
|
3440
|
+
if (this.uniformLocations["uShininess"])
|
|
3441
|
+
gl.uniform1f(this.uniformLocations["uShininess"], this.shininess);
|
|
3442
|
+
if (this.uniformLocations["uSpecularColor"])
|
|
3443
|
+
gl.uniform3fv(this.uniformLocations["uSpecularColor"], this.specular);
|
|
3444
|
+
if (this.uniformLocations["uDissolve"])
|
|
3445
|
+
gl.uniform1f(this.uniformLocations["uDissolve"], this.dissolve);
|
|
3446
|
+
if (this.uniformLocations["uAmbientColor"])
|
|
3447
|
+
gl.uniform3fv(this.uniformLocations["uAmbientColor"], this.ambientColor);
|
|
3448
|
+
if (this.uniformLocations["uDiffuseColor"])
|
|
3449
|
+
gl.uniform3fv(this.uniformLocations["uDiffuseColor"], this.diffuse);
|
|
3450
|
+
if (viewPosition && this.uniformLocations["uViewPosition"]) {
|
|
3451
|
+
gl.uniform3fv(this.uniformLocations["uViewPosition"], viewPosition);
|
|
3452
|
+
}
|
|
3453
|
+
const hasTexture = !!this.texture;
|
|
3454
|
+
if (this.uniformLocations["uUseTexture"])
|
|
3455
|
+
gl.uniform1i(this.uniformLocations["uUseTexture"], hasTexture ? 1 : 0);
|
|
3456
|
+
if (hasTexture && this.texture) {
|
|
3457
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
3458
|
+
gl.bindTexture(gl.TEXTURE_2D, this.texture);
|
|
3459
|
+
if (this.uniformLocations["uTexture"])
|
|
3460
|
+
gl.uniform1i(this.uniformLocations["uTexture"], 0);
|
|
3461
|
+
}
|
|
3462
|
+
if (!this.unlit && lights?.length) {
|
|
3463
|
+
const count = Math.min(lights.length, MAX_LIGHTS);
|
|
3464
|
+
if (this.uniformLocations["uLightCount"])
|
|
3465
|
+
gl.uniform1i(this.uniformLocations["uLightCount"], count);
|
|
3466
|
+
for (let i = 0; i < count; i++) {
|
|
3467
|
+
const light = lights[i];
|
|
3468
|
+
const i3 = i * 3;
|
|
3469
|
+
let typeInt = 0;
|
|
3470
|
+
if (light.type === "point") typeInt = 1;
|
|
3471
|
+
else if (light.type === "ambient") typeInt = 2;
|
|
3472
|
+
this._lightTypes[i] = typeInt;
|
|
3473
|
+
const dir = light.direction ?? [0, 0, 0];
|
|
3474
|
+
this._lightDirs[i3] = dir[0];
|
|
3475
|
+
this._lightDirs[i3 + 1] = dir[1];
|
|
3476
|
+
this._lightDirs[i3 + 2] = dir[2];
|
|
3477
|
+
const pos = light.position ?? [0, 0, 0];
|
|
3478
|
+
this._lightPositions[i3] = pos[0];
|
|
3479
|
+
this._lightPositions[i3 + 1] = pos[1];
|
|
3480
|
+
this._lightPositions[i3 + 2] = pos[2];
|
|
3481
|
+
this._lightColors[i3] = light.color[0];
|
|
3482
|
+
this._lightColors[i3 + 1] = light.color[1];
|
|
3483
|
+
this._lightColors[i3 + 2] = light.color[2];
|
|
3484
|
+
this._lightIntensities[i] = light.intensity;
|
|
3485
|
+
this._lightConstants[i] = light.constant;
|
|
3486
|
+
this._lightLinears[i] = light.linear;
|
|
3487
|
+
this._lightQuadratics[i] = light.quadratic;
|
|
3488
|
+
}
|
|
3489
|
+
if (this.uniformLocations["uLightDirection[0]"])
|
|
3490
|
+
gl.uniform3fv(
|
|
3491
|
+
this.uniformLocations["uLightDirection[0]"],
|
|
3492
|
+
this._lightDirs
|
|
3493
|
+
);
|
|
3494
|
+
if (this.uniformLocations["uLightColor[0]"])
|
|
3495
|
+
gl.uniform3fv(
|
|
3496
|
+
this.uniformLocations["uLightColor[0]"],
|
|
3497
|
+
this._lightColors
|
|
3498
|
+
);
|
|
3499
|
+
if (this.uniformLocations["uLightIntensity[0]"])
|
|
3500
|
+
gl.uniform1fv(
|
|
3501
|
+
this.uniformLocations["uLightIntensity[0]"],
|
|
3502
|
+
this._lightIntensities
|
|
3503
|
+
);
|
|
3504
|
+
if (this.uniformLocations["uLightType[0]"])
|
|
3505
|
+
gl.uniform1iv(this.uniformLocations["uLightType[0]"], this._lightTypes);
|
|
3506
|
+
if (this.uniformLocations["uLightPosition[0]"])
|
|
3507
|
+
gl.uniform3fv(
|
|
3508
|
+
this.uniformLocations["uLightPosition[0]"],
|
|
3509
|
+
this._lightPositions
|
|
3510
|
+
);
|
|
3511
|
+
if (this.uniformLocations["uLightConstant[0]"])
|
|
3512
|
+
gl.uniform1fv(
|
|
3513
|
+
this.uniformLocations["uLightConstant[0]"],
|
|
3514
|
+
this._lightConstants
|
|
3515
|
+
);
|
|
3516
|
+
if (this.uniformLocations["uLightLinear[0]"])
|
|
3517
|
+
gl.uniform1fv(
|
|
3518
|
+
this.uniformLocations["uLightLinear[0]"],
|
|
3519
|
+
this._lightLinears
|
|
3520
|
+
);
|
|
3521
|
+
if (this.uniformLocations["uLightQuadratic[0]"])
|
|
3522
|
+
gl.uniform1fv(
|
|
3523
|
+
this.uniformLocations["uLightQuadratic[0]"],
|
|
3524
|
+
this._lightQuadratics
|
|
3525
|
+
);
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
};
|
|
3529
|
+
|
|
3530
|
+
// ../GenesisGL/src/Core/classes/Light.ts
|
|
3531
|
+
var Light = class {
|
|
3532
|
+
constructor(type = "directional", position = [0, 10, 0], direction = [0, -1, -1], color = [1, 1, 1], intensity = 1, constant = 1, linear = 0, quadratic = 0) {
|
|
3533
|
+
this.type = type;
|
|
3534
|
+
this.position = position;
|
|
3535
|
+
this.direction = direction;
|
|
3536
|
+
this.color = color;
|
|
3537
|
+
this.intensity = intensity;
|
|
3538
|
+
this.constant = constant;
|
|
3539
|
+
this.linear = linear;
|
|
3540
|
+
this.quadratic = quadratic;
|
|
3541
|
+
}
|
|
3542
|
+
type;
|
|
3543
|
+
position;
|
|
3544
|
+
direction;
|
|
3545
|
+
color;
|
|
3546
|
+
intensity;
|
|
3547
|
+
// Attenuation factors are initialized to standard values (no falloff)
|
|
3548
|
+
constant = 1;
|
|
3549
|
+
linear = 0;
|
|
3550
|
+
quadratic = 0;
|
|
3551
|
+
move(dx, dy, dz) {
|
|
3552
|
+
this.position[0] += dx;
|
|
3553
|
+
this.position[1] += dy;
|
|
3554
|
+
this.position[2] += dz;
|
|
3555
|
+
}
|
|
3556
|
+
rotateY(delta) {
|
|
3557
|
+
if (this.type === "directional") {
|
|
3558
|
+
const cos = Math.cos(delta);
|
|
3559
|
+
const sin = Math.sin(delta);
|
|
3560
|
+
const [x, y, z] = this.direction;
|
|
3561
|
+
this.direction[0] = x * cos - z * sin;
|
|
3562
|
+
this.direction[2] = x * sin + z * cos;
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
};
|
|
3566
|
+
|
|
3567
|
+
// ../GenesisGL/src/Core/classes/Scene.ts
|
|
3568
|
+
var Scene = class _Scene {
|
|
3569
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3570
|
+
constructor(webglCore) {
|
|
3571
|
+
this.webglCore = webglCore;
|
|
3572
|
+
}
|
|
3573
|
+
webglCore;
|
|
3574
|
+
models = [];
|
|
3575
|
+
modelsMap = /* @__PURE__ */ new Map();
|
|
3576
|
+
lights = [];
|
|
3577
|
+
// ─────────────────────────────────────────────
|
|
3578
|
+
// ░░░ Factory: pre-configured 3-point lighting ░░░
|
|
3579
|
+
// ─────────────────────────────────────────────
|
|
3580
|
+
/**
|
|
3581
|
+
* Create a Scene pre-loaded with a classic **3-point lighting** rig
|
|
3582
|
+
* (ambient + key + fill + back).
|
|
3583
|
+
*
|
|
3584
|
+
* Use this for quick prototyping; for production, create a plain Scene and
|
|
3585
|
+
* add your own lights.
|
|
3586
|
+
*/
|
|
3587
|
+
static withDefaultLights(webglCore) {
|
|
3588
|
+
const scene = new _Scene(webglCore);
|
|
3589
|
+
scene.addLight(
|
|
3590
|
+
"ambient_base",
|
|
3591
|
+
new Light("ambient", [0, 0, 0], [0, 0, 0], [0.3, 0.3, 0.35], 0.5)
|
|
3592
|
+
);
|
|
3593
|
+
scene.addLight(
|
|
3594
|
+
"directional_key",
|
|
3595
|
+
new Light(
|
|
3596
|
+
"directional",
|
|
3597
|
+
[5, 10, 5],
|
|
3598
|
+
[-0.5, -1, -0.5],
|
|
3599
|
+
[1, 0.95, 0.9],
|
|
3600
|
+
1.2
|
|
3601
|
+
)
|
|
3602
|
+
);
|
|
3603
|
+
scene.addLight(
|
|
3604
|
+
"directional_fill",
|
|
3605
|
+
new Light(
|
|
3606
|
+
"directional",
|
|
3607
|
+
[-10, 5, 10],
|
|
3608
|
+
[0.5, -0.2, -0.7],
|
|
3609
|
+
[0.8, 0.8, 1],
|
|
3610
|
+
0.5
|
|
3611
|
+
)
|
|
3612
|
+
);
|
|
3613
|
+
scene.addLight(
|
|
3614
|
+
"directional_back",
|
|
3615
|
+
new Light(
|
|
3616
|
+
"directional",
|
|
3617
|
+
[0, 15, -10],
|
|
3618
|
+
[0, -0.8, 1],
|
|
3619
|
+
[1, 1, 1],
|
|
3620
|
+
0.7
|
|
3621
|
+
)
|
|
3622
|
+
);
|
|
3623
|
+
return scene;
|
|
3624
|
+
}
|
|
3625
|
+
/** Register a light source in the scene. */
|
|
3626
|
+
addLight(id, light) {
|
|
3627
|
+
this.lights.push(light);
|
|
3628
|
+
}
|
|
3629
|
+
/** Add a model to the scene with a unique key. */
|
|
3630
|
+
add(id, model) {
|
|
3631
|
+
this.models.push(model);
|
|
3632
|
+
this.modelsMap.set(id, model);
|
|
3633
|
+
}
|
|
3634
|
+
/** Remove a model from the scene by key. */
|
|
3635
|
+
remove(key) {
|
|
3636
|
+
const mesh = this.modelsMap.get(key);
|
|
3637
|
+
if (!mesh) return;
|
|
3638
|
+
this.models = this.models.filter((m) => m !== mesh);
|
|
3639
|
+
this.modelsMap.delete(key);
|
|
3640
|
+
}
|
|
3641
|
+
getModels() {
|
|
3642
|
+
return this.models;
|
|
3643
|
+
}
|
|
3644
|
+
getLights() {
|
|
3645
|
+
return this.lights;
|
|
3646
|
+
}
|
|
3647
|
+
/** Retrieve a model by its key. */
|
|
3648
|
+
getModel(key) {
|
|
3649
|
+
const mesh = this.modelsMap.get(key);
|
|
3650
|
+
return mesh;
|
|
3651
|
+
}
|
|
3652
|
+
hasMesh(key) {
|
|
3653
|
+
return this.modelsMap.has(key);
|
|
3654
|
+
}
|
|
3655
|
+
/** Returns all [id, model] pairs — useful for debug/inspector tools. */
|
|
3656
|
+
getEntries() {
|
|
3657
|
+
return [...this.modelsMap.entries()];
|
|
3658
|
+
}
|
|
3659
|
+
dispose(webglCore) {
|
|
3660
|
+
for (const model of this.models) {
|
|
3661
|
+
model.dispose(webglCore);
|
|
3662
|
+
}
|
|
3663
|
+
this.models.length = 0;
|
|
3664
|
+
this.modelsMap.clear();
|
|
3665
|
+
this.lights.length = 0;
|
|
3666
|
+
}
|
|
3667
|
+
};
|
|
3668
|
+
|
|
3669
|
+
// ../GenesisGL/src/Core/classes/AnimationClip.ts
|
|
3670
|
+
var _sv0Vec3 = vec3_exports.create();
|
|
3671
|
+
var _sv1Vec3 = vec3_exports.create();
|
|
3672
|
+
var _sOutVec3 = vec3_exports.create();
|
|
3673
|
+
var _sv0Quat = quat_exports.create();
|
|
3674
|
+
var _sv1Quat = quat_exports.create();
|
|
3675
|
+
var _sOutQuat = quat_exports.create();
|
|
3676
|
+
|
|
3677
|
+
// ../GenesisGL/src/Core/utils/create-wire-box.ts
|
|
3678
|
+
function createWireBox(min3, max3, material) {
|
|
3679
|
+
const [minX, minY, minZ] = min3;
|
|
3680
|
+
const [maxX, maxY, maxZ] = max3;
|
|
3681
|
+
const vertices = [
|
|
3682
|
+
minX,
|
|
3683
|
+
minY,
|
|
3684
|
+
minZ,
|
|
3685
|
+
maxX,
|
|
3686
|
+
minY,
|
|
3687
|
+
minZ,
|
|
3688
|
+
maxX,
|
|
3689
|
+
maxY,
|
|
3690
|
+
minZ,
|
|
3691
|
+
minX,
|
|
3692
|
+
maxY,
|
|
3693
|
+
minZ,
|
|
3694
|
+
minX,
|
|
3695
|
+
minY,
|
|
3696
|
+
maxZ,
|
|
3697
|
+
maxX,
|
|
3698
|
+
minY,
|
|
3699
|
+
maxZ,
|
|
3700
|
+
maxX,
|
|
3701
|
+
maxY,
|
|
3702
|
+
maxZ,
|
|
3703
|
+
minX,
|
|
3704
|
+
maxY,
|
|
3705
|
+
maxZ
|
|
3706
|
+
];
|
|
3707
|
+
const indices = [
|
|
3708
|
+
0,
|
|
3709
|
+
1,
|
|
3710
|
+
1,
|
|
3711
|
+
2,
|
|
3712
|
+
2,
|
|
3713
|
+
3,
|
|
3714
|
+
3,
|
|
3715
|
+
0,
|
|
3716
|
+
// bottom face
|
|
3717
|
+
4,
|
|
3718
|
+
5,
|
|
3719
|
+
5,
|
|
3720
|
+
6,
|
|
3721
|
+
6,
|
|
3722
|
+
7,
|
|
3723
|
+
7,
|
|
3724
|
+
4,
|
|
3725
|
+
// top face
|
|
3726
|
+
0,
|
|
3727
|
+
4,
|
|
3728
|
+
1,
|
|
3729
|
+
5,
|
|
3730
|
+
2,
|
|
3731
|
+
6,
|
|
3732
|
+
3,
|
|
3733
|
+
7
|
|
3734
|
+
// vertical edges
|
|
3735
|
+
];
|
|
3736
|
+
const lineVertices = [];
|
|
3737
|
+
for (let i = 0; i < indices.length; i++) {
|
|
3738
|
+
const idx = indices[i];
|
|
3739
|
+
lineVertices.push(
|
|
3740
|
+
vertices[idx * 3],
|
|
3741
|
+
vertices[idx * 3 + 1],
|
|
3742
|
+
vertices[idx * 3 + 2]
|
|
3743
|
+
);
|
|
3744
|
+
}
|
|
3745
|
+
const normals = new Float32Array(lineVertices.length);
|
|
3746
|
+
const mesh = new Mesh(
|
|
3747
|
+
"hitbox",
|
|
3748
|
+
new Float32Array(lineVertices),
|
|
3749
|
+
normals,
|
|
3750
|
+
material,
|
|
3751
|
+
new Float32Array(),
|
|
3752
|
+
null
|
|
3753
|
+
);
|
|
3754
|
+
mesh.setMode(GL_LINES);
|
|
3755
|
+
return mesh;
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3758
|
+
// ../GenesisGL/src/Core/classes/Renderer.ts
|
|
3759
|
+
var Renderer = class {
|
|
3760
|
+
constructor(webglCore, viewport) {
|
|
3761
|
+
this.webglCore = webglCore;
|
|
3762
|
+
this.viewport = viewport;
|
|
3763
|
+
const gl = webglCore.getRenderingContext();
|
|
3764
|
+
this._isWebGL2 = gl instanceof WebGL2RenderingContext;
|
|
3765
|
+
if (gl) gl.enable(gl.DEPTH_TEST);
|
|
3766
|
+
}
|
|
3767
|
+
webglCore;
|
|
3768
|
+
viewport;
|
|
3769
|
+
/** Set to `true` to render wireframe bounding boxes for debugging. */
|
|
3770
|
+
debug = false;
|
|
3771
|
+
// Cached debug materials to avoid per-frame GPU allocations
|
|
3772
|
+
_modelHitboxMaterial = null;
|
|
3773
|
+
_meshHitboxMaterial = null;
|
|
3774
|
+
// Cache wire-box debug meshes: recreated only when the bounding box changes.
|
|
3775
|
+
_modelWireBoxCache = /* @__PURE__ */ new WeakMap();
|
|
3776
|
+
_meshWireBoxCache = /* @__PURE__ */ new WeakMap();
|
|
3777
|
+
/** Pre-allocated identity matrix for world-space hitbox draws. */
|
|
3778
|
+
_identity = mat4_exports.create();
|
|
3779
|
+
/** Cached `gl instanceof WebGL2RenderingContext` — computed once at construction. */
|
|
3780
|
+
_isWebGL2;
|
|
3781
|
+
/** Lazily-created material for model-level hitboxes (red). */
|
|
3782
|
+
get modelHitboxMaterial() {
|
|
3783
|
+
if (!this._modelHitboxMaterial) {
|
|
3784
|
+
this._modelHitboxMaterial = new Material(this.webglCore);
|
|
3785
|
+
this._modelHitboxMaterial.setColorHex("#ff0404ff");
|
|
3786
|
+
this._modelHitboxMaterial.unlit = true;
|
|
3787
|
+
}
|
|
3788
|
+
return this._modelHitboxMaterial;
|
|
3789
|
+
}
|
|
3790
|
+
/** Lazily-created material for mesh-level hitboxes (green). */
|
|
3791
|
+
get meshHitboxMaterial() {
|
|
3792
|
+
if (!this._meshHitboxMaterial) {
|
|
3793
|
+
this._meshHitboxMaterial = new Material(this.webglCore);
|
|
3794
|
+
this._meshHitboxMaterial.setColorHex("#04ff0cff");
|
|
3795
|
+
this._meshHitboxMaterial.unlit = true;
|
|
3796
|
+
}
|
|
3797
|
+
return this._meshHitboxMaterial;
|
|
3798
|
+
}
|
|
3799
|
+
clearFrame(color = [0.2, 0.5, 0.95, 1]) {
|
|
3800
|
+
const gl = this.webglCore.getRenderingContext();
|
|
3801
|
+
if (!gl) return;
|
|
3802
|
+
gl.clearColor(...color);
|
|
3803
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
3804
|
+
}
|
|
3805
|
+
render(scene) {
|
|
3806
|
+
const gl = this.webglCore.getRenderingContext();
|
|
3807
|
+
if (!gl) return;
|
|
3808
|
+
const models = scene.getModels();
|
|
3809
|
+
const lights = scene.getLights();
|
|
3810
|
+
const camera = this.viewport.camera;
|
|
3811
|
+
const viewPosition = camera.getComputedPosition();
|
|
3812
|
+
this.clearFrame();
|
|
3813
|
+
const viewMatrix = camera.getViewMatrix();
|
|
3814
|
+
const projMatrix = camera.getProjectionMatrix();
|
|
3815
|
+
let activeProgram = null;
|
|
3816
|
+
for (const model of models) {
|
|
3817
|
+
activeProgram = this.drawModel(
|
|
3818
|
+
gl,
|
|
3819
|
+
model,
|
|
3820
|
+
lights,
|
|
3821
|
+
viewPosition,
|
|
3822
|
+
viewMatrix,
|
|
3823
|
+
projMatrix,
|
|
3824
|
+
activeProgram
|
|
3825
|
+
);
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
drawModel(gl, model, lights, viewPosition, viewMatrix, projMatrix, activeProgram) {
|
|
3829
|
+
const modelMatrix = model.getModelMatrix();
|
|
3830
|
+
const hasSkeleton = model.skeleton !== null;
|
|
3831
|
+
for (const mesh of model.meshes) {
|
|
3832
|
+
activeProgram = this.drawMesh(
|
|
3833
|
+
mesh,
|
|
3834
|
+
lights,
|
|
3835
|
+
viewPosition,
|
|
3836
|
+
modelMatrix,
|
|
3837
|
+
viewMatrix,
|
|
3838
|
+
projMatrix,
|
|
3839
|
+
activeProgram,
|
|
3840
|
+
hasSkeleton && mesh.isSkinned ? model : null
|
|
3841
|
+
);
|
|
3842
|
+
if (this.debug) {
|
|
3843
|
+
this.drawHitBoxForMesh(
|
|
3844
|
+
mesh,
|
|
3845
|
+
modelMatrix,
|
|
3846
|
+
viewMatrix,
|
|
3847
|
+
projMatrix,
|
|
3848
|
+
activeProgram
|
|
3849
|
+
);
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
if (this.debug) {
|
|
3853
|
+
this.drawHitBox(model, activeProgram);
|
|
3854
|
+
}
|
|
3855
|
+
return activeProgram;
|
|
3856
|
+
}
|
|
3857
|
+
drawMesh(mesh, lights, viewPosition, modelMatrix, viewMatrix, projMatrix, activeProgram, skinnedModel = null) {
|
|
3858
|
+
const gl = this.webglCore.getRenderingContext();
|
|
3859
|
+
if (!gl) return activeProgram;
|
|
3860
|
+
if (!mesh.material) return activeProgram;
|
|
3861
|
+
mesh.initBuffer(this.webglCore);
|
|
3862
|
+
const { program, uniformLocations } = mesh.material;
|
|
3863
|
+
if (program !== activeProgram) {
|
|
3864
|
+
gl.useProgram(program);
|
|
3865
|
+
activeProgram = program;
|
|
3866
|
+
if (uniformLocations["uView"])
|
|
3867
|
+
gl.uniformMatrix4fv(uniformLocations["uView"], false, viewMatrix);
|
|
3868
|
+
if (uniformLocations["uProjection"])
|
|
3869
|
+
gl.uniformMatrix4fv(uniformLocations["uProjection"], false, projMatrix);
|
|
3870
|
+
}
|
|
3871
|
+
const isWebGL2 = this._isWebGL2;
|
|
3872
|
+
if (isWebGL2 && mesh.buffers?.vao) {
|
|
3873
|
+
gl.bindVertexArray(
|
|
3874
|
+
mesh.buffers.vao
|
|
3875
|
+
);
|
|
3876
|
+
} else {
|
|
3877
|
+
const aPosition = mesh.material.attribLocations["aPosition"];
|
|
3878
|
+
if (aPosition !== -1 && mesh.buffers?.vertexBuffer) {
|
|
3879
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.vertexBuffer);
|
|
3880
|
+
gl.enableVertexAttribArray(aPosition);
|
|
3881
|
+
gl.vertexAttribPointer(aPosition, 3, gl.FLOAT, false, 0, 0);
|
|
3882
|
+
}
|
|
3883
|
+
const aNormal = mesh.material.attribLocations["aNormal"];
|
|
3884
|
+
if (aNormal !== -1 && mesh.buffers?.normalBuffer) {
|
|
3885
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.normalBuffer);
|
|
3886
|
+
gl.enableVertexAttribArray(aNormal);
|
|
3887
|
+
gl.vertexAttribPointer(aNormal, 3, gl.FLOAT, false, 0, 0);
|
|
3888
|
+
}
|
|
3889
|
+
const aTexCoord = mesh.material.attribLocations["aTexCoord"];
|
|
3890
|
+
if (aTexCoord !== -1 && mesh.buffers?.texCoordBuffer) {
|
|
3891
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.texCoordBuffer);
|
|
3892
|
+
gl.enableVertexAttribArray(aTexCoord);
|
|
3893
|
+
gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, 0, 0);
|
|
3894
|
+
}
|
|
3895
|
+
const aJointIndices = mesh.material.attribLocations["aJointIndices"];
|
|
3896
|
+
if (aJointIndices !== -1 && mesh.buffers?.jointIndexBuffer) {
|
|
3897
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.jointIndexBuffer);
|
|
3898
|
+
gl.enableVertexAttribArray(aJointIndices);
|
|
3899
|
+
gl.vertexAttribPointer(aJointIndices, 4, gl.FLOAT, false, 0, 0);
|
|
3900
|
+
}
|
|
3901
|
+
const aJointWeights = mesh.material.attribLocations["aJointWeights"];
|
|
3902
|
+
if (aJointWeights !== -1 && mesh.buffers?.jointWeightBuffer) {
|
|
3903
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.jointWeightBuffer);
|
|
3904
|
+
gl.enableVertexAttribArray(aJointWeights);
|
|
3905
|
+
gl.vertexAttribPointer(aJointWeights, 4, gl.FLOAT, false, 0, 0);
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
mesh.material.apply(gl, lights, viewPosition);
|
|
3909
|
+
const uUseSkinning = uniformLocations["uUseSkinning"];
|
|
3910
|
+
const skeleton = skinnedModel?.skeleton ?? null;
|
|
3911
|
+
if (skeleton && mesh.isSkinned) {
|
|
3912
|
+
if (uUseSkinning) gl.uniform1i(uUseSkinning, 1);
|
|
3913
|
+
const uJointMatrices = uniformLocations["uJointMatrices[0]"];
|
|
3914
|
+
if (uJointMatrices) {
|
|
3915
|
+
gl.uniformMatrix4fv(uJointMatrices, false, skeleton.jointMatrices);
|
|
3916
|
+
}
|
|
3917
|
+
} else {
|
|
3918
|
+
if (uUseSkinning) gl.uniform1i(uUseSkinning, 0);
|
|
3919
|
+
}
|
|
3920
|
+
const uModel = mesh.material.uniformLocations["uModel"];
|
|
3921
|
+
if (uModel) gl.uniformMatrix4fv(uModel, false, modelMatrix);
|
|
3922
|
+
if (mesh.buffers?.indexBuffer && mesh.indices) {
|
|
3923
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, mesh.buffers.indexBuffer);
|
|
3924
|
+
const type = mesh.indices instanceof Uint32Array ? gl.UNSIGNED_INT : gl.UNSIGNED_SHORT;
|
|
3925
|
+
gl.drawElements(mesh.mode, mesh.indices.length, type, 0);
|
|
3926
|
+
} else {
|
|
3927
|
+
gl.drawArrays(mesh.mode, 0, mesh.vertices.length / 3);
|
|
3928
|
+
}
|
|
3929
|
+
if (isWebGL2 && mesh.buffers?.vao) {
|
|
3930
|
+
gl.bindVertexArray(null);
|
|
3931
|
+
} else {
|
|
3932
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
3933
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
3934
|
+
}
|
|
3935
|
+
return activeProgram;
|
|
3936
|
+
}
|
|
3937
|
+
drawHitBox(model, activeProgram) {
|
|
3938
|
+
const bbox = model.boundingBox;
|
|
3939
|
+
const key = `${bbox.min[0]},${bbox.min[1]},${bbox.min[2]},${bbox.max[0]},${bbox.max[1]},${bbox.max[2]}`;
|
|
3940
|
+
const cached = this._modelWireBoxCache.get(model);
|
|
3941
|
+
let hitboxMesh;
|
|
3942
|
+
if (!cached || cached.key !== key) {
|
|
3943
|
+
hitboxMesh = createWireBox(bbox.min, bbox.max, this.modelHitboxMaterial);
|
|
3944
|
+
hitboxMesh.isCollidable = false;
|
|
3945
|
+
this._modelWireBoxCache.set(model, { mesh: hitboxMesh, key });
|
|
3946
|
+
} else {
|
|
3947
|
+
hitboxMesh = cached.mesh;
|
|
3948
|
+
}
|
|
3949
|
+
const camera = this.viewport.camera;
|
|
3950
|
+
const viewMatrix = camera.getViewMatrix();
|
|
3951
|
+
const projMatrix = camera.getProjectionMatrix();
|
|
3952
|
+
this.drawMesh(
|
|
3953
|
+
hitboxMesh,
|
|
3954
|
+
[],
|
|
3955
|
+
camera.position,
|
|
3956
|
+
this._identity,
|
|
3957
|
+
viewMatrix,
|
|
3958
|
+
projMatrix,
|
|
3959
|
+
activeProgram
|
|
3960
|
+
);
|
|
3961
|
+
}
|
|
3962
|
+
drawHitBoxForMesh(mesh, modelMatrix, viewMatrix, projMatrix, activeProgram) {
|
|
3963
|
+
if (!mesh.boundingBox) return;
|
|
3964
|
+
const { min: min3, max: max3 } = mesh.boundingBox;
|
|
3965
|
+
const key = `${min3[0]},${min3[1]},${min3[2]},${max3[0]},${max3[1]},${max3[2]}`;
|
|
3966
|
+
const cached = this._meshWireBoxCache.get(mesh);
|
|
3967
|
+
let wireBox;
|
|
3968
|
+
if (!cached || cached.key !== key) {
|
|
3969
|
+
wireBox = createWireBox(min3, max3, this.meshHitboxMaterial);
|
|
3970
|
+
wireBox.isCollidable = false;
|
|
3971
|
+
this._meshWireBoxCache.set(mesh, { mesh: wireBox, key });
|
|
3972
|
+
} else {
|
|
3973
|
+
wireBox = cached.mesh;
|
|
3974
|
+
}
|
|
3975
|
+
const camera = this.viewport.camera;
|
|
3976
|
+
this.drawMesh(
|
|
3977
|
+
wireBox,
|
|
3978
|
+
[],
|
|
3979
|
+
camera.position,
|
|
3980
|
+
modelMatrix,
|
|
3981
|
+
viewMatrix,
|
|
3982
|
+
projMatrix,
|
|
3983
|
+
activeProgram
|
|
3984
|
+
);
|
|
3985
|
+
}
|
|
3986
|
+
};
|
|
3987
|
+
|
|
3988
|
+
// src/hooks/useGenesisGL.ts
|
|
3989
|
+
function useGenesisGL(options) {
|
|
3990
|
+
const contextRef = useRef({
|
|
3991
|
+
renderer: null,
|
|
3992
|
+
scene: null,
|
|
3993
|
+
viewport: null,
|
|
3994
|
+
webglCore: null
|
|
3995
|
+
});
|
|
3996
|
+
useEffect(() => {
|
|
3997
|
+
const { canvasRef, onReady, onError } = options;
|
|
3998
|
+
if (!canvasRef.current) return;
|
|
3999
|
+
try {
|
|
4000
|
+
const canvas = canvasRef.current;
|
|
4001
|
+
const webglCore = new WebGLCore(canvas);
|
|
4002
|
+
const viewport = new Viewport(
|
|
4003
|
+
canvas,
|
|
4004
|
+
window.innerWidth,
|
|
4005
|
+
window.innerHeight,
|
|
4006
|
+
webglCore
|
|
4007
|
+
);
|
|
4008
|
+
const renderer = new Renderer(webglCore, viewport);
|
|
4009
|
+
const scene = Scene.withDefaultLights(webglCore);
|
|
4010
|
+
contextRef.current = { renderer, scene, viewport, webglCore };
|
|
4011
|
+
viewport.camera.target = [0, 0, 0];
|
|
4012
|
+
viewport.camera.position = [4, 2, 8];
|
|
4013
|
+
viewport.camera.invalidate();
|
|
4014
|
+
if (onReady) {
|
|
4015
|
+
onReady(scene, viewport, renderer);
|
|
4016
|
+
}
|
|
4017
|
+
} catch (error) {
|
|
4018
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
4019
|
+
console.error("Failed to initialize GenesisGL:", err);
|
|
4020
|
+
if (onError) onError(err);
|
|
4021
|
+
}
|
|
4022
|
+
return () => {
|
|
4023
|
+
const { scene, viewport, webglCore } = contextRef.current;
|
|
4024
|
+
if (scene && webglCore) scene.dispose(webglCore);
|
|
4025
|
+
if (viewport) viewport.dispose();
|
|
4026
|
+
if (webglCore) webglCore.dispose();
|
|
4027
|
+
};
|
|
4028
|
+
}, [options]);
|
|
4029
|
+
return contextRef.current;
|
|
4030
|
+
}
|
|
4031
|
+
|
|
4032
|
+
// src/hooks/useRenderer.ts
|
|
4033
|
+
import { useRef as useRef2, useEffect as useEffect2 } from "react";
|
|
4034
|
+
function useRenderer(options) {
|
|
4035
|
+
const { renderer, onFrame, enabled = true } = options;
|
|
4036
|
+
const animationIdRef = useRef2(null);
|
|
4037
|
+
useEffect2(() => {
|
|
4038
|
+
if (!renderer || !enabled) return;
|
|
4039
|
+
const animate = (time) => {
|
|
4040
|
+
if (onFrame) onFrame(time);
|
|
4041
|
+
animationIdRef.current = requestAnimationFrame(animate);
|
|
4042
|
+
};
|
|
4043
|
+
animationIdRef.current = requestAnimationFrame(animate);
|
|
4044
|
+
return () => {
|
|
4045
|
+
if (animationIdRef.current !== null) {
|
|
4046
|
+
cancelAnimationFrame(animationIdRef.current);
|
|
4047
|
+
}
|
|
4048
|
+
};
|
|
4049
|
+
}, [renderer, onFrame, enabled]);
|
|
4050
|
+
}
|
|
4051
|
+
|
|
4052
|
+
export {
|
|
4053
|
+
useGenesisGL,
|
|
4054
|
+
useRenderer
|
|
4055
|
+
};
|
|
4056
|
+
//# sourceMappingURL=chunk-4H2GKYMT.js.map
|