@fonsecabarreto/genesis-gl-react 0.1.1 → 0.1.31
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/dist/chunk-7BVTZKWZ.js +394 -0
- package/dist/chunk-7BVTZKWZ.js.map +1 -0
- package/dist/chunk-GDDOUPFO.js +66 -0
- package/dist/chunk-GDDOUPFO.js.map +1 -0
- package/dist/chunk-MINHVZ2M.js +267 -0
- package/dist/chunk-MINHVZ2M.js.map +1 -0
- package/dist/chunk-PJM4LJXC.js +394 -0
- package/dist/chunk-PJM4LJXC.js.map +1 -0
- package/dist/chunk-QXHXGH2T.js +4733 -0
- package/dist/chunk-QXHXGH2T.js.map +1 -0
- package/dist/chunk-UVQX6HJJ.js +394 -0
- package/dist/chunk-UVQX6HJJ.js.map +1 -0
- package/dist/chunk-VAMVRTC4.js +66 -0
- package/dist/chunk-VAMVRTC4.js.map +1 -0
- package/dist/chunk-XJKE4L2D.js +267 -0
- package/dist/chunk-XJKE4L2D.js.map +1 -0
- package/dist/components/index.d.ts +60 -0
- package/dist/components/index.js +2 -2
- package/dist/hooks/index.d.ts +64 -0
- package/dist/hooks/index.js +4 -2
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/useGenesisGL-VdB4J3Hl.d.ts +27 -0
- package/package.json +1 -1
|
@@ -0,0 +1,4733 @@
|
|
|
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, useState } 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 = 1;
|
|
2698
|
+
minZoom = 0.5;
|
|
2699
|
+
maxZoom = 10;
|
|
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, options = {}) {
|
|
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(options.pointerLock ?? true);
|
|
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(pointerLock) {
|
|
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
|
+
if (pointerLock) {
|
|
2985
|
+
this.moveControl.onChange((dx, dy) => {
|
|
2986
|
+
const factor = 0.01 * this.camera.zoom;
|
|
2987
|
+
this.camera.rotate(-dx * factor, -dy * factor);
|
|
2988
|
+
});
|
|
2989
|
+
this.moveControl.enable();
|
|
2990
|
+
}
|
|
2991
|
+
this.canvas.addEventListener("contextmenu", (e) => e.preventDefault());
|
|
2992
|
+
}
|
|
2993
|
+
isDraggingCamera() {
|
|
2994
|
+
return this.dragControl.isDragging;
|
|
2995
|
+
}
|
|
2996
|
+
resizeCanvas() {
|
|
2997
|
+
const screenWidth = window.innerWidth;
|
|
2998
|
+
const screenHeight = window.innerHeight;
|
|
2999
|
+
const aspectViewport = this.width / this.height;
|
|
3000
|
+
const aspectScreen = screenWidth / screenHeight;
|
|
3001
|
+
let canvasWidth, canvasHeight;
|
|
3002
|
+
if (aspectScreen > aspectViewport) {
|
|
3003
|
+
canvasHeight = screenHeight;
|
|
3004
|
+
canvasWidth = canvasHeight * aspectViewport;
|
|
3005
|
+
} else {
|
|
3006
|
+
canvasWidth = screenWidth;
|
|
3007
|
+
canvasHeight = canvasWidth / aspectViewport;
|
|
3008
|
+
}
|
|
3009
|
+
this.canvas.width = canvasWidth;
|
|
3010
|
+
this.canvas.height = canvasHeight;
|
|
3011
|
+
this.scale = canvasWidth / this.width;
|
|
3012
|
+
const gl = this.webglCore ? this.webglCore.getRenderingContext() : this.canvas.getContext("webgl2") ?? this.canvas.getContext("webgl");
|
|
3013
|
+
if (!gl) throw new Error("WebGL not supported");
|
|
3014
|
+
gl.viewport(0, 0, canvasWidth, canvasHeight);
|
|
3015
|
+
this.camera.setViewport(canvasWidth, canvasHeight);
|
|
3016
|
+
}
|
|
3017
|
+
getCanvas() {
|
|
3018
|
+
return this.canvas;
|
|
3019
|
+
}
|
|
3020
|
+
getWebGLCore() {
|
|
3021
|
+
return this.webglCore;
|
|
3022
|
+
}
|
|
3023
|
+
getScale() {
|
|
3024
|
+
return this.scale;
|
|
3025
|
+
}
|
|
3026
|
+
/** Release event listeners. Call when the viewport is no longer needed. */
|
|
3027
|
+
dispose() {
|
|
3028
|
+
window.removeEventListener("resize", this.resizeHandler);
|
|
3029
|
+
this.wheelControl.disable();
|
|
3030
|
+
this.dragControl.disable();
|
|
3031
|
+
this.moveControl.disable();
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
|
|
3035
|
+
// ../GenesisGL/src/Core/utils/compute-bounds.ts
|
|
3036
|
+
function computeVertexBounds(vertices) {
|
|
3037
|
+
if (!vertices || vertices.length === 0) {
|
|
3038
|
+
return { min: [0, 0, 0], max: [0, 0, 0] };
|
|
3039
|
+
}
|
|
3040
|
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
|
3041
|
+
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
3042
|
+
for (let i = 0; i < vertices.length; i += 3) {
|
|
3043
|
+
const x = vertices[i];
|
|
3044
|
+
const y = vertices[i + 1];
|
|
3045
|
+
const z = vertices[i + 2];
|
|
3046
|
+
if (x < minX) minX = x;
|
|
3047
|
+
if (y < minY) minY = y;
|
|
3048
|
+
if (z < minZ) minZ = z;
|
|
3049
|
+
if (x > maxX) maxX = x;
|
|
3050
|
+
if (y > maxY) maxY = y;
|
|
3051
|
+
if (z > maxZ) maxZ = z;
|
|
3052
|
+
}
|
|
3053
|
+
return {
|
|
3054
|
+
min: [minX, minY, minZ],
|
|
3055
|
+
max: [maxX, maxY, maxZ]
|
|
3056
|
+
};
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
// ../GenesisGL/src/Core/classes/Mesh.ts
|
|
3060
|
+
var GL_LINES = 1;
|
|
3061
|
+
var GL_TRIANGLES = 4;
|
|
3062
|
+
var INITIAL_BOUNDING_BOX = { min: [0, 0, 0], max: [0, 0, 0] };
|
|
3063
|
+
var Mesh = class _Mesh {
|
|
3064
|
+
name;
|
|
3065
|
+
vertices;
|
|
3066
|
+
normals;
|
|
3067
|
+
texCoords;
|
|
3068
|
+
indices;
|
|
3069
|
+
mode;
|
|
3070
|
+
material;
|
|
3071
|
+
// ── Skinning data (optional) ─────────────────────────────────
|
|
3072
|
+
/** Per-vertex joint indices (vec4 per vertex, 4 influences). */
|
|
3073
|
+
jointIndices = null;
|
|
3074
|
+
/** Per-vertex joint weights (vec4 per vertex, 4 influences). */
|
|
3075
|
+
jointWeights = null;
|
|
3076
|
+
// WebGL buffers aggregate
|
|
3077
|
+
buffers = null;
|
|
3078
|
+
boundingBox = INITIAL_BOUNDING_BOX;
|
|
3079
|
+
isCollidable = true;
|
|
3080
|
+
isInitialized = false;
|
|
3081
|
+
constructor(name, vertices, normals, material, texCoords = new Float32Array(), indices = null) {
|
|
3082
|
+
this.mode = GL_TRIANGLES;
|
|
3083
|
+
this.name = name;
|
|
3084
|
+
this.normals = normals;
|
|
3085
|
+
this.indices = indices;
|
|
3086
|
+
this.vertices = vertices;
|
|
3087
|
+
this.texCoords = texCoords;
|
|
3088
|
+
this.material = material;
|
|
3089
|
+
this.computeBounds();
|
|
3090
|
+
}
|
|
3091
|
+
setMode(newMode) {
|
|
3092
|
+
this.mode = newMode;
|
|
3093
|
+
}
|
|
3094
|
+
/** Whether this mesh has skinning data for skeletal animation. */
|
|
3095
|
+
get isSkinned() {
|
|
3096
|
+
return this.jointIndices !== null && this.jointWeights !== null;
|
|
3097
|
+
}
|
|
3098
|
+
computeBounds() {
|
|
3099
|
+
this.boundingBox = computeVertexBounds(this.vertices);
|
|
3100
|
+
}
|
|
3101
|
+
clone() {
|
|
3102
|
+
const clonedMesh = new _Mesh(
|
|
3103
|
+
this.name,
|
|
3104
|
+
new Float32Array(this.vertices),
|
|
3105
|
+
new Float32Array(this.normals),
|
|
3106
|
+
this.material,
|
|
3107
|
+
// shallow ref — call Material.clone() if independent material is needed
|
|
3108
|
+
new Float32Array(this.texCoords),
|
|
3109
|
+
this.indices ? this.indices instanceof Uint16Array ? new Uint16Array(this.indices) : new Uint32Array(this.indices) : null
|
|
3110
|
+
);
|
|
3111
|
+
clonedMesh.setMode(this.mode);
|
|
3112
|
+
clonedMesh.isCollidable = this.isCollidable;
|
|
3113
|
+
if (this.jointIndices)
|
|
3114
|
+
clonedMesh.jointIndices = new Float32Array(this.jointIndices);
|
|
3115
|
+
if (this.jointWeights)
|
|
3116
|
+
clonedMesh.jointWeights = new Float32Array(this.jointWeights);
|
|
3117
|
+
return clonedMesh;
|
|
3118
|
+
}
|
|
3119
|
+
/** Initialize GPU buffers safely */
|
|
3120
|
+
initBuffer(webglCore) {
|
|
3121
|
+
const gl = webglCore.getRenderingContext();
|
|
3122
|
+
if (!gl) {
|
|
3123
|
+
console.warn(
|
|
3124
|
+
`[Mesh:${this.name}] GL context not available, skipping buffer init.`
|
|
3125
|
+
);
|
|
3126
|
+
return;
|
|
3127
|
+
}
|
|
3128
|
+
if (this.isInitialized) return;
|
|
3129
|
+
this.buffers = new MeshBuffers();
|
|
3130
|
+
this.buffers.init(gl, this);
|
|
3131
|
+
this.isInitialized = true;
|
|
3132
|
+
}
|
|
3133
|
+
/** Dispose of GPU buffers safely */
|
|
3134
|
+
dispose(webglCore) {
|
|
3135
|
+
const gl = webglCore.getRenderingContext();
|
|
3136
|
+
if (!gl || !this.buffers) return;
|
|
3137
|
+
this.buffers.dispose(gl);
|
|
3138
|
+
this.buffers = null;
|
|
3139
|
+
this.isInitialized = false;
|
|
3140
|
+
}
|
|
3141
|
+
};
|
|
3142
|
+
var MeshBuffers = class {
|
|
3143
|
+
vao = null;
|
|
3144
|
+
vertexBuffer = null;
|
|
3145
|
+
normalBuffer = null;
|
|
3146
|
+
texCoordBuffer = null;
|
|
3147
|
+
indexBuffer = null;
|
|
3148
|
+
jointIndexBuffer = null;
|
|
3149
|
+
jointWeightBuffer = null;
|
|
3150
|
+
init(gl, mesh) {
|
|
3151
|
+
if (!gl) throw new Error("Cannot init MeshBuffers: invalid GL context");
|
|
3152
|
+
const isWebGL2 = gl instanceof WebGL2RenderingContext;
|
|
3153
|
+
const gl2 = isWebGL2 ? gl : null;
|
|
3154
|
+
if (gl2) {
|
|
3155
|
+
this.vao = gl2.createVertexArray();
|
|
3156
|
+
gl2.bindVertexArray(this.vao);
|
|
3157
|
+
}
|
|
3158
|
+
const program = mesh.material?.program;
|
|
3159
|
+
const aPosition = program ? gl.getAttribLocation(program, "aPosition") : 0;
|
|
3160
|
+
const aNormal = program ? gl.getAttribLocation(program, "aNormal") : 1;
|
|
3161
|
+
const aTexCoord = program ? gl.getAttribLocation(program, "aTexCoord") : 2;
|
|
3162
|
+
this.vertexBuffer = gl.createBuffer();
|
|
3163
|
+
if (!this.vertexBuffer) throw new Error("Failed to create vertex buffer");
|
|
3164
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
3165
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.vertices, gl.STATIC_DRAW);
|
|
3166
|
+
if (aPosition !== -1) {
|
|
3167
|
+
gl.enableVertexAttribArray(aPosition);
|
|
3168
|
+
gl.vertexAttribPointer(aPosition, 3, gl.FLOAT, false, 0, 0);
|
|
3169
|
+
}
|
|
3170
|
+
this.normalBuffer = gl.createBuffer();
|
|
3171
|
+
if (!this.normalBuffer) throw new Error("Failed to create normal buffer");
|
|
3172
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
|
|
3173
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.normals, gl.STATIC_DRAW);
|
|
3174
|
+
if (aNormal !== -1) {
|
|
3175
|
+
gl.enableVertexAttribArray(aNormal);
|
|
3176
|
+
gl.vertexAttribPointer(aNormal, 3, gl.FLOAT, false, 0, 0);
|
|
3177
|
+
}
|
|
3178
|
+
if (mesh.texCoords.length > 0) {
|
|
3179
|
+
this.texCoordBuffer = gl.createBuffer();
|
|
3180
|
+
if (!this.texCoordBuffer)
|
|
3181
|
+
throw new Error("Failed to create texCoord buffer");
|
|
3182
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer);
|
|
3183
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.texCoords, gl.STATIC_DRAW);
|
|
3184
|
+
if (aTexCoord !== -1) {
|
|
3185
|
+
gl.enableVertexAttribArray(aTexCoord);
|
|
3186
|
+
gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, 0, 0);
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
if (mesh.indices && mesh.indices.length > 0) {
|
|
3190
|
+
this.indexBuffer = gl.createBuffer();
|
|
3191
|
+
if (!this.indexBuffer) throw new Error("Failed to create index buffer");
|
|
3192
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
|
3193
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, mesh.indices, gl.STATIC_DRAW);
|
|
3194
|
+
}
|
|
3195
|
+
const aJointIndices = program ? gl.getAttribLocation(program, "aJointIndices") : -1;
|
|
3196
|
+
if (mesh.jointIndices && mesh.jointIndices.length > 0 && aJointIndices !== -1) {
|
|
3197
|
+
this.jointIndexBuffer = gl.createBuffer();
|
|
3198
|
+
if (!this.jointIndexBuffer)
|
|
3199
|
+
throw new Error("Failed to create joint index buffer");
|
|
3200
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.jointIndexBuffer);
|
|
3201
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.jointIndices, gl.STATIC_DRAW);
|
|
3202
|
+
gl.enableVertexAttribArray(aJointIndices);
|
|
3203
|
+
gl.vertexAttribPointer(aJointIndices, 4, gl.FLOAT, false, 0, 0);
|
|
3204
|
+
}
|
|
3205
|
+
const aJointWeights = program ? gl.getAttribLocation(program, "aJointWeights") : -1;
|
|
3206
|
+
if (mesh.jointWeights && mesh.jointWeights.length > 0 && aJointWeights !== -1) {
|
|
3207
|
+
this.jointWeightBuffer = gl.createBuffer();
|
|
3208
|
+
if (!this.jointWeightBuffer)
|
|
3209
|
+
throw new Error("Failed to create joint weight buffer");
|
|
3210
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.jointWeightBuffer);
|
|
3211
|
+
gl.bufferData(gl.ARRAY_BUFFER, mesh.jointWeights, gl.STATIC_DRAW);
|
|
3212
|
+
gl.enableVertexAttribArray(aJointWeights);
|
|
3213
|
+
gl.vertexAttribPointer(aJointWeights, 4, gl.FLOAT, false, 0, 0);
|
|
3214
|
+
}
|
|
3215
|
+
if (gl2) {
|
|
3216
|
+
gl2.bindVertexArray(null);
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
dispose(gl) {
|
|
3220
|
+
if (!gl) {
|
|
3221
|
+
console.warn("Cannot dispose MeshBuffers: invalid GL context");
|
|
3222
|
+
return;
|
|
3223
|
+
}
|
|
3224
|
+
const isWebGL2 = gl instanceof WebGL2RenderingContext;
|
|
3225
|
+
if (this.vertexBuffer) gl.deleteBuffer(this.vertexBuffer);
|
|
3226
|
+
if (this.normalBuffer) gl.deleteBuffer(this.normalBuffer);
|
|
3227
|
+
if (this.texCoordBuffer) gl.deleteBuffer(this.texCoordBuffer);
|
|
3228
|
+
if (this.indexBuffer) gl.deleteBuffer(this.indexBuffer);
|
|
3229
|
+
if (this.jointIndexBuffer) gl.deleteBuffer(this.jointIndexBuffer);
|
|
3230
|
+
if (this.jointWeightBuffer) gl.deleteBuffer(this.jointWeightBuffer);
|
|
3231
|
+
if (isWebGL2 && this.vao) {
|
|
3232
|
+
gl.deleteVertexArray(this.vao);
|
|
3233
|
+
}
|
|
3234
|
+
this.vertexBuffer = this.normalBuffer = this.texCoordBuffer = this.indexBuffer = this.jointIndexBuffer = this.jointWeightBuffer = this.vao = null;
|
|
3235
|
+
}
|
|
3236
|
+
};
|
|
3237
|
+
|
|
3238
|
+
// ../GenesisGL/src/Core/utils/load-texture.ts
|
|
3239
|
+
async function loadWebGlTexture(gl, url, options = {}) {
|
|
3240
|
+
return new Promise((resolve, reject) => {
|
|
3241
|
+
const texture = gl.createTexture();
|
|
3242
|
+
if (!texture) return reject(new Error("Failed to create texture"));
|
|
3243
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
3244
|
+
const level = 0;
|
|
3245
|
+
const internalFormat = gl.RGBA;
|
|
3246
|
+
const width = 1;
|
|
3247
|
+
const height = 1;
|
|
3248
|
+
const border = 0;
|
|
3249
|
+
const srcFormat = gl.RGBA;
|
|
3250
|
+
const srcType = gl.UNSIGNED_BYTE;
|
|
3251
|
+
const pixel = new Uint8Array([128, 128, 128, 255]);
|
|
3252
|
+
gl.texImage2D(
|
|
3253
|
+
gl.TEXTURE_2D,
|
|
3254
|
+
level,
|
|
3255
|
+
internalFormat,
|
|
3256
|
+
width,
|
|
3257
|
+
height,
|
|
3258
|
+
border,
|
|
3259
|
+
srcFormat,
|
|
3260
|
+
srcType,
|
|
3261
|
+
pixel
|
|
3262
|
+
);
|
|
3263
|
+
const image = new Image();
|
|
3264
|
+
image.crossOrigin = "anonymous";
|
|
3265
|
+
image.onload = () => {
|
|
3266
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
3267
|
+
gl.texImage2D(
|
|
3268
|
+
gl.TEXTURE_2D,
|
|
3269
|
+
level,
|
|
3270
|
+
internalFormat,
|
|
3271
|
+
srcFormat,
|
|
3272
|
+
srcType,
|
|
3273
|
+
image
|
|
3274
|
+
);
|
|
3275
|
+
if (isPowerOf2(image.width) && isPowerOf2(image.height)) {
|
|
3276
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
3277
|
+
gl.texParameteri(
|
|
3278
|
+
gl.TEXTURE_2D,
|
|
3279
|
+
gl.TEXTURE_MIN_FILTER,
|
|
3280
|
+
gl.LINEAR_MIPMAP_LINEAR
|
|
3281
|
+
);
|
|
3282
|
+
if (options.repeat) {
|
|
3283
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
|
|
3284
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
|
|
3285
|
+
}
|
|
3286
|
+
} else {
|
|
3287
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
3288
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
3289
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
3290
|
+
}
|
|
3291
|
+
resolve(texture);
|
|
3292
|
+
};
|
|
3293
|
+
image.onerror = reject;
|
|
3294
|
+
image.src = url;
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
function isPowerOf2(value) {
|
|
3298
|
+
return (value & value - 1) === 0;
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
// ../GenesisGL/src/Core/utils/parse-hex-to-rgb.ts
|
|
3302
|
+
function parseHexToRgbArray(hex) {
|
|
3303
|
+
if (hex.startsWith("#")) hex = hex.slice(1);
|
|
3304
|
+
let r = 1, g = 1, b = 1, a = 1;
|
|
3305
|
+
if (hex.length === 6) {
|
|
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 = 1;
|
|
3310
|
+
} else if (hex.length === 8) {
|
|
3311
|
+
r = parseInt(hex.slice(0, 2), 16) / 255;
|
|
3312
|
+
g = parseInt(hex.slice(2, 4), 16) / 255;
|
|
3313
|
+
b = parseInt(hex.slice(4, 6), 16) / 255;
|
|
3314
|
+
a = parseInt(hex.slice(6, 8), 16) / 255;
|
|
3315
|
+
} else {
|
|
3316
|
+
throw new Error("Invalid hex color format. Use #RRGGBB or #RRGGBBAA.");
|
|
3317
|
+
}
|
|
3318
|
+
return [r, g, b, a];
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3321
|
+
// ../GenesisGL/src/Core/classes/Material.ts
|
|
3322
|
+
var MAX_LIGHTS = 5;
|
|
3323
|
+
var Material = class _Material {
|
|
3324
|
+
constructor(webglCore, options = {}) {
|
|
3325
|
+
this.webglCore = webglCore;
|
|
3326
|
+
this.program = webglCore.getProgram();
|
|
3327
|
+
const { gl } = webglCore;
|
|
3328
|
+
const names = [
|
|
3329
|
+
"uColor",
|
|
3330
|
+
"uUnlit",
|
|
3331
|
+
"uModel",
|
|
3332
|
+
"uView",
|
|
3333
|
+
"uProjection",
|
|
3334
|
+
"uLightCount",
|
|
3335
|
+
"uUseTexture",
|
|
3336
|
+
"uTexture",
|
|
3337
|
+
// --- LIGHTING UNIFORMS ---
|
|
3338
|
+
"uViewPosition",
|
|
3339
|
+
// Camera position for specular light
|
|
3340
|
+
"uShininess",
|
|
3341
|
+
"uSpecularColor",
|
|
3342
|
+
"uAmbientColor",
|
|
3343
|
+
"uDissolve",
|
|
3344
|
+
"uDiffuseColor",
|
|
3345
|
+
"uLightDirection[0]",
|
|
3346
|
+
"uLightColor[0]",
|
|
3347
|
+
"uLightIntensity[0]",
|
|
3348
|
+
"uLightType[0]",
|
|
3349
|
+
"uLightPosition[0]",
|
|
3350
|
+
// NEW: For Point Lights
|
|
3351
|
+
"uLightConstant[0]",
|
|
3352
|
+
// NEW: Attenuation
|
|
3353
|
+
"uLightLinear[0]",
|
|
3354
|
+
// NEW: Attenuation
|
|
3355
|
+
"uLightQuadratic[0]",
|
|
3356
|
+
// NEW: Attenuation
|
|
3357
|
+
// --- SKINNING UNIFORMS ---
|
|
3358
|
+
"uUseSkinning",
|
|
3359
|
+
"uJointMatrices[0]"
|
|
3360
|
+
];
|
|
3361
|
+
for (const name of names) {
|
|
3362
|
+
this.uniformLocations[name] = gl.getUniformLocation(this.program, name);
|
|
3363
|
+
}
|
|
3364
|
+
const attribs = [
|
|
3365
|
+
"aPosition",
|
|
3366
|
+
"aNormal",
|
|
3367
|
+
"aTexCoord",
|
|
3368
|
+
"aJointIndices",
|
|
3369
|
+
"aJointWeights"
|
|
3370
|
+
];
|
|
3371
|
+
for (const name of attribs) {
|
|
3372
|
+
this.attribLocations[name] = gl.getAttribLocation(this.program, name);
|
|
3373
|
+
}
|
|
3374
|
+
Object.assign(this, options);
|
|
3375
|
+
}
|
|
3376
|
+
webglCore;
|
|
3377
|
+
// cache
|
|
3378
|
+
program;
|
|
3379
|
+
uniformLocations = {};
|
|
3380
|
+
attribLocations = {};
|
|
3381
|
+
// Attributes
|
|
3382
|
+
albedoColor = [1, 1, 1, 1];
|
|
3383
|
+
unlit = false;
|
|
3384
|
+
texture;
|
|
3385
|
+
specular = [0.3, 0.3, 0.3];
|
|
3386
|
+
shininess = 64;
|
|
3387
|
+
doubleSided = false;
|
|
3388
|
+
//others
|
|
3389
|
+
ambientColor = [0.1, 0.1, 0.1];
|
|
3390
|
+
// Ka
|
|
3391
|
+
dissolve = 1;
|
|
3392
|
+
// d or Tr
|
|
3393
|
+
diffuse = [1, 1, 1];
|
|
3394
|
+
// Kd
|
|
3395
|
+
/** Physics friction coefficient [0–1]. 0 = no resistance (ice), 1 = instant stop. */
|
|
3396
|
+
friction = 0.3;
|
|
3397
|
+
// ── Pre-allocated light uniform buffers (reused every frame, zero GC pressure) ──
|
|
3398
|
+
_lightDirs = new Float32Array(MAX_LIGHTS * 3);
|
|
3399
|
+
_lightColors = new Float32Array(MAX_LIGHTS * 3);
|
|
3400
|
+
_lightIntensities = new Float32Array(MAX_LIGHTS);
|
|
3401
|
+
_lightTypes = new Int32Array(MAX_LIGHTS);
|
|
3402
|
+
_lightPositions = new Float32Array(MAX_LIGHTS * 3);
|
|
3403
|
+
_lightConstants = new Float32Array(MAX_LIGHTS);
|
|
3404
|
+
_lightLinears = new Float32Array(MAX_LIGHTS);
|
|
3405
|
+
_lightQuadratics = new Float32Array(MAX_LIGHTS);
|
|
3406
|
+
setColorHex(hex) {
|
|
3407
|
+
this.albedoColor = parseHexToRgbArray(hex);
|
|
3408
|
+
}
|
|
3409
|
+
setColor(rgba) {
|
|
3410
|
+
this.albedoColor = rgba;
|
|
3411
|
+
this.dissolve = rgba[3];
|
|
3412
|
+
this.diffuse = [rgba[0], rgba[1], rgba[2]];
|
|
3413
|
+
}
|
|
3414
|
+
/**
|
|
3415
|
+
* Load an image from URL and create a WebGL texture.
|
|
3416
|
+
*/
|
|
3417
|
+
async loadTexture(url, options) {
|
|
3418
|
+
const { gl } = this.webglCore;
|
|
3419
|
+
this.texture = await loadWebGlTexture(gl, url, options);
|
|
3420
|
+
}
|
|
3421
|
+
/**
|
|
3422
|
+
* Create an independent copy of this material.
|
|
3423
|
+
* Shares the same WebGL program but copies all mutable properties.
|
|
3424
|
+
* The texture reference is shared (immutable GPU resource).
|
|
3425
|
+
*/
|
|
3426
|
+
clone() {
|
|
3427
|
+
const copy5 = new _Material(this.webglCore);
|
|
3428
|
+
copy5.albedoColor = [...this.albedoColor];
|
|
3429
|
+
copy5.specular = [...this.specular];
|
|
3430
|
+
copy5.ambientColor = [...this.ambientColor];
|
|
3431
|
+
copy5.diffuse = [...this.diffuse];
|
|
3432
|
+
copy5.shininess = this.shininess;
|
|
3433
|
+
copy5.dissolve = this.dissolve;
|
|
3434
|
+
copy5.unlit = this.unlit;
|
|
3435
|
+
copy5.doubleSided = this.doubleSided;
|
|
3436
|
+
copy5.friction = this.friction;
|
|
3437
|
+
copy5.texture = this.texture;
|
|
3438
|
+
return copy5;
|
|
3439
|
+
}
|
|
3440
|
+
apply(gl, lights, viewPosition) {
|
|
3441
|
+
if (this.uniformLocations["uColor"])
|
|
3442
|
+
gl.uniform4fv(this.uniformLocations["uColor"], this.albedoColor);
|
|
3443
|
+
if (this.uniformLocations["uUnlit"])
|
|
3444
|
+
gl.uniform1i(this.uniformLocations["uUnlit"], this.unlit ? 1 : 0);
|
|
3445
|
+
if (this.uniformLocations["uShininess"])
|
|
3446
|
+
gl.uniform1f(this.uniformLocations["uShininess"], this.shininess);
|
|
3447
|
+
if (this.uniformLocations["uSpecularColor"])
|
|
3448
|
+
gl.uniform3fv(this.uniformLocations["uSpecularColor"], this.specular);
|
|
3449
|
+
if (this.uniformLocations["uDissolve"])
|
|
3450
|
+
gl.uniform1f(this.uniformLocations["uDissolve"], this.dissolve);
|
|
3451
|
+
if (this.uniformLocations["uAmbientColor"])
|
|
3452
|
+
gl.uniform3fv(this.uniformLocations["uAmbientColor"], this.ambientColor);
|
|
3453
|
+
if (this.uniformLocations["uDiffuseColor"])
|
|
3454
|
+
gl.uniform3fv(this.uniformLocations["uDiffuseColor"], this.diffuse);
|
|
3455
|
+
if (viewPosition && this.uniformLocations["uViewPosition"]) {
|
|
3456
|
+
gl.uniform3fv(this.uniformLocations["uViewPosition"], viewPosition);
|
|
3457
|
+
}
|
|
3458
|
+
const hasTexture = !!this.texture;
|
|
3459
|
+
if (this.uniformLocations["uUseTexture"])
|
|
3460
|
+
gl.uniform1i(this.uniformLocations["uUseTexture"], hasTexture ? 1 : 0);
|
|
3461
|
+
if (hasTexture && this.texture) {
|
|
3462
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
3463
|
+
gl.bindTexture(gl.TEXTURE_2D, this.texture);
|
|
3464
|
+
if (this.uniformLocations["uTexture"])
|
|
3465
|
+
gl.uniform1i(this.uniformLocations["uTexture"], 0);
|
|
3466
|
+
}
|
|
3467
|
+
if (!this.unlit && lights?.length) {
|
|
3468
|
+
const count = Math.min(lights.length, MAX_LIGHTS);
|
|
3469
|
+
if (this.uniformLocations["uLightCount"])
|
|
3470
|
+
gl.uniform1i(this.uniformLocations["uLightCount"], count);
|
|
3471
|
+
for (let i = 0; i < count; i++) {
|
|
3472
|
+
const light = lights[i];
|
|
3473
|
+
const i3 = i * 3;
|
|
3474
|
+
let typeInt = 0;
|
|
3475
|
+
if (light.type === "point") typeInt = 1;
|
|
3476
|
+
else if (light.type === "ambient") typeInt = 2;
|
|
3477
|
+
this._lightTypes[i] = typeInt;
|
|
3478
|
+
const dir = light.direction ?? [0, 0, 0];
|
|
3479
|
+
this._lightDirs[i3] = dir[0];
|
|
3480
|
+
this._lightDirs[i3 + 1] = dir[1];
|
|
3481
|
+
this._lightDirs[i3 + 2] = dir[2];
|
|
3482
|
+
const pos = light.position ?? [0, 0, 0];
|
|
3483
|
+
this._lightPositions[i3] = pos[0];
|
|
3484
|
+
this._lightPositions[i3 + 1] = pos[1];
|
|
3485
|
+
this._lightPositions[i3 + 2] = pos[2];
|
|
3486
|
+
this._lightColors[i3] = light.color[0];
|
|
3487
|
+
this._lightColors[i3 + 1] = light.color[1];
|
|
3488
|
+
this._lightColors[i3 + 2] = light.color[2];
|
|
3489
|
+
this._lightIntensities[i] = light.intensity;
|
|
3490
|
+
this._lightConstants[i] = light.constant;
|
|
3491
|
+
this._lightLinears[i] = light.linear;
|
|
3492
|
+
this._lightQuadratics[i] = light.quadratic;
|
|
3493
|
+
}
|
|
3494
|
+
if (this.uniformLocations["uLightDirection[0]"])
|
|
3495
|
+
gl.uniform3fv(
|
|
3496
|
+
this.uniformLocations["uLightDirection[0]"],
|
|
3497
|
+
this._lightDirs
|
|
3498
|
+
);
|
|
3499
|
+
if (this.uniformLocations["uLightColor[0]"])
|
|
3500
|
+
gl.uniform3fv(
|
|
3501
|
+
this.uniformLocations["uLightColor[0]"],
|
|
3502
|
+
this._lightColors
|
|
3503
|
+
);
|
|
3504
|
+
if (this.uniformLocations["uLightIntensity[0]"])
|
|
3505
|
+
gl.uniform1fv(
|
|
3506
|
+
this.uniformLocations["uLightIntensity[0]"],
|
|
3507
|
+
this._lightIntensities
|
|
3508
|
+
);
|
|
3509
|
+
if (this.uniformLocations["uLightType[0]"])
|
|
3510
|
+
gl.uniform1iv(this.uniformLocations["uLightType[0]"], this._lightTypes);
|
|
3511
|
+
if (this.uniformLocations["uLightPosition[0]"])
|
|
3512
|
+
gl.uniform3fv(
|
|
3513
|
+
this.uniformLocations["uLightPosition[0]"],
|
|
3514
|
+
this._lightPositions
|
|
3515
|
+
);
|
|
3516
|
+
if (this.uniformLocations["uLightConstant[0]"])
|
|
3517
|
+
gl.uniform1fv(
|
|
3518
|
+
this.uniformLocations["uLightConstant[0]"],
|
|
3519
|
+
this._lightConstants
|
|
3520
|
+
);
|
|
3521
|
+
if (this.uniformLocations["uLightLinear[0]"])
|
|
3522
|
+
gl.uniform1fv(
|
|
3523
|
+
this.uniformLocations["uLightLinear[0]"],
|
|
3524
|
+
this._lightLinears
|
|
3525
|
+
);
|
|
3526
|
+
if (this.uniformLocations["uLightQuadratic[0]"])
|
|
3527
|
+
gl.uniform1fv(
|
|
3528
|
+
this.uniformLocations["uLightQuadratic[0]"],
|
|
3529
|
+
this._lightQuadratics
|
|
3530
|
+
);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
};
|
|
3534
|
+
|
|
3535
|
+
// ../GenesisGL/src/Core/classes/Light.ts
|
|
3536
|
+
var Light = class {
|
|
3537
|
+
constructor(type = "directional", position = [0, 10, 0], direction = [0, -1, -1], color = [1, 1, 1], intensity = 1, constant = 1, linear = 0, quadratic = 0) {
|
|
3538
|
+
this.type = type;
|
|
3539
|
+
this.position = position;
|
|
3540
|
+
this.direction = direction;
|
|
3541
|
+
this.color = color;
|
|
3542
|
+
this.intensity = intensity;
|
|
3543
|
+
this.constant = constant;
|
|
3544
|
+
this.linear = linear;
|
|
3545
|
+
this.quadratic = quadratic;
|
|
3546
|
+
}
|
|
3547
|
+
type;
|
|
3548
|
+
position;
|
|
3549
|
+
direction;
|
|
3550
|
+
color;
|
|
3551
|
+
intensity;
|
|
3552
|
+
// Attenuation factors are initialized to standard values (no falloff)
|
|
3553
|
+
constant = 1;
|
|
3554
|
+
linear = 0;
|
|
3555
|
+
quadratic = 0;
|
|
3556
|
+
move(dx, dy, dz) {
|
|
3557
|
+
this.position[0] += dx;
|
|
3558
|
+
this.position[1] += dy;
|
|
3559
|
+
this.position[2] += dz;
|
|
3560
|
+
}
|
|
3561
|
+
rotateY(delta) {
|
|
3562
|
+
if (this.type === "directional") {
|
|
3563
|
+
const cos = Math.cos(delta);
|
|
3564
|
+
const sin = Math.sin(delta);
|
|
3565
|
+
const [x, y, z] = this.direction;
|
|
3566
|
+
this.direction[0] = x * cos - z * sin;
|
|
3567
|
+
this.direction[2] = x * sin + z * cos;
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
|
+
};
|
|
3571
|
+
|
|
3572
|
+
// ../GenesisGL/src/Core/classes/Scene.ts
|
|
3573
|
+
var Scene = class _Scene {
|
|
3574
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3575
|
+
constructor(webglCore) {
|
|
3576
|
+
this.webglCore = webglCore;
|
|
3577
|
+
}
|
|
3578
|
+
webglCore;
|
|
3579
|
+
models = [];
|
|
3580
|
+
modelsMap = /* @__PURE__ */ new Map();
|
|
3581
|
+
lights = [];
|
|
3582
|
+
// ─────────────────────────────────────────────
|
|
3583
|
+
// ░░░ Factory: pre-configured 3-point lighting ░░░
|
|
3584
|
+
// ─────────────────────────────────────────────
|
|
3585
|
+
/**
|
|
3586
|
+
* Create a Scene pre-loaded with a classic **3-point lighting** rig
|
|
3587
|
+
* (ambient + key + fill + back).
|
|
3588
|
+
*
|
|
3589
|
+
* Use this for quick prototyping; for production, create a plain Scene and
|
|
3590
|
+
* add your own lights.
|
|
3591
|
+
*/
|
|
3592
|
+
static withDefaultLights(webglCore) {
|
|
3593
|
+
const scene = new _Scene(webglCore);
|
|
3594
|
+
scene.addLight(
|
|
3595
|
+
"ambient_base",
|
|
3596
|
+
new Light("ambient", [0, 0, 0], [0, 0, 0], [0.3, 0.3, 0.35], 0.5)
|
|
3597
|
+
);
|
|
3598
|
+
scene.addLight(
|
|
3599
|
+
"directional_key",
|
|
3600
|
+
new Light(
|
|
3601
|
+
"directional",
|
|
3602
|
+
[5, 10, 5],
|
|
3603
|
+
[-0.5, -1, -0.5],
|
|
3604
|
+
[1, 0.95, 0.9],
|
|
3605
|
+
1.2
|
|
3606
|
+
)
|
|
3607
|
+
);
|
|
3608
|
+
scene.addLight(
|
|
3609
|
+
"directional_fill",
|
|
3610
|
+
new Light(
|
|
3611
|
+
"directional",
|
|
3612
|
+
[-10, 5, 10],
|
|
3613
|
+
[0.5, -0.2, -0.7],
|
|
3614
|
+
[0.8, 0.8, 1],
|
|
3615
|
+
0.5
|
|
3616
|
+
)
|
|
3617
|
+
);
|
|
3618
|
+
scene.addLight(
|
|
3619
|
+
"directional_back",
|
|
3620
|
+
new Light(
|
|
3621
|
+
"directional",
|
|
3622
|
+
[0, 15, -10],
|
|
3623
|
+
[0, -0.8, 1],
|
|
3624
|
+
[1, 1, 1],
|
|
3625
|
+
0.7
|
|
3626
|
+
)
|
|
3627
|
+
);
|
|
3628
|
+
return scene;
|
|
3629
|
+
}
|
|
3630
|
+
/** Register a light source in the scene. */
|
|
3631
|
+
addLight(id, light) {
|
|
3632
|
+
this.lights.push(light);
|
|
3633
|
+
}
|
|
3634
|
+
/** Add a model to the scene with a unique key. */
|
|
3635
|
+
add(id, model) {
|
|
3636
|
+
this.models.push(model);
|
|
3637
|
+
this.modelsMap.set(id, model);
|
|
3638
|
+
}
|
|
3639
|
+
/** Remove a model from the scene by key. */
|
|
3640
|
+
remove(key) {
|
|
3641
|
+
const mesh = this.modelsMap.get(key);
|
|
3642
|
+
if (!mesh) return;
|
|
3643
|
+
this.models = this.models.filter((m) => m !== mesh);
|
|
3644
|
+
this.modelsMap.delete(key);
|
|
3645
|
+
}
|
|
3646
|
+
getModels() {
|
|
3647
|
+
return this.models;
|
|
3648
|
+
}
|
|
3649
|
+
getLights() {
|
|
3650
|
+
return this.lights;
|
|
3651
|
+
}
|
|
3652
|
+
/** Retrieve a model by its key. */
|
|
3653
|
+
getModel(key) {
|
|
3654
|
+
const mesh = this.modelsMap.get(key);
|
|
3655
|
+
return mesh;
|
|
3656
|
+
}
|
|
3657
|
+
hasMesh(key) {
|
|
3658
|
+
return this.modelsMap.has(key);
|
|
3659
|
+
}
|
|
3660
|
+
/** Returns all [id, model] pairs — useful for debug/inspector tools. */
|
|
3661
|
+
getEntries() {
|
|
3662
|
+
return [...this.modelsMap.entries()];
|
|
3663
|
+
}
|
|
3664
|
+
dispose(webglCore) {
|
|
3665
|
+
for (const model of this.models) {
|
|
3666
|
+
model.dispose(webglCore);
|
|
3667
|
+
}
|
|
3668
|
+
this.models.length = 0;
|
|
3669
|
+
this.modelsMap.clear();
|
|
3670
|
+
this.lights.length = 0;
|
|
3671
|
+
}
|
|
3672
|
+
};
|
|
3673
|
+
|
|
3674
|
+
// ../GenesisGL/src/Core/domain/value-objects/Collider.ts
|
|
3675
|
+
var Collider = class {
|
|
3676
|
+
type;
|
|
3677
|
+
offset;
|
|
3678
|
+
size;
|
|
3679
|
+
constructor(type, offset = [0, 0, 0], size = [1, 1, 1]) {
|
|
3680
|
+
this.type = type;
|
|
3681
|
+
this.offset = offset;
|
|
3682
|
+
this.size = size;
|
|
3683
|
+
}
|
|
3684
|
+
};
|
|
3685
|
+
|
|
3686
|
+
// ../GenesisGL/src/Core/utils/gltf-utils.ts
|
|
3687
|
+
function transformPoint(out, m, p) {
|
|
3688
|
+
const v = vec3_exports.fromValues(p[0], p[1], p[2]);
|
|
3689
|
+
vec3_exports.transformMat4(v, v, m);
|
|
3690
|
+
out[0] = v[0];
|
|
3691
|
+
out[1] = v[1];
|
|
3692
|
+
out[2] = v[2];
|
|
3693
|
+
}
|
|
3694
|
+
function transformAABB(min3, max3, m) {
|
|
3695
|
+
const corners = [
|
|
3696
|
+
[min3[0], min3[1], min3[2]],
|
|
3697
|
+
[min3[0], min3[1], max3[2]],
|
|
3698
|
+
[min3[0], max3[1], min3[2]],
|
|
3699
|
+
[min3[0], max3[1], max3[2]],
|
|
3700
|
+
[max3[0], min3[1], min3[2]],
|
|
3701
|
+
[max3[0], min3[1], max3[2]],
|
|
3702
|
+
[max3[0], max3[1], min3[2]],
|
|
3703
|
+
[max3[0], max3[1], max3[2]]
|
|
3704
|
+
];
|
|
3705
|
+
const outMin = [Infinity, Infinity, Infinity];
|
|
3706
|
+
const outMax = [-Infinity, -Infinity, -Infinity];
|
|
3707
|
+
const t = [0, 0, 0];
|
|
3708
|
+
for (const c of corners) {
|
|
3709
|
+
transformPoint(t, m, c);
|
|
3710
|
+
for (let i = 0; i < 3; i++) {
|
|
3711
|
+
outMin[i] = Math.min(outMin[i], t[i]);
|
|
3712
|
+
outMax[i] = Math.max(outMax[i], t[i]);
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
return { min: outMin, max: outMax };
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3718
|
+
// ../GenesisGL/src/Core/classes/Model.ts
|
|
3719
|
+
var Model = class _Model {
|
|
3720
|
+
name;
|
|
3721
|
+
meshes;
|
|
3722
|
+
collider;
|
|
3723
|
+
translation;
|
|
3724
|
+
rotation;
|
|
3725
|
+
scale;
|
|
3726
|
+
// ── Skeletal animation ──────────────────────────────────────
|
|
3727
|
+
/** The skeleton driving skinned meshes (set after GLB load if present). */
|
|
3728
|
+
skeleton = null;
|
|
3729
|
+
/** Named animation clips available on this model. */
|
|
3730
|
+
animations = /* @__PURE__ */ new Map();
|
|
3731
|
+
/** The currently playing animation clip (if any). */
|
|
3732
|
+
activeAnimation = null;
|
|
3733
|
+
_boundingBox = { min: [0, 0, 0], max: [0, 0, 0] };
|
|
3734
|
+
_bboxDirty = false;
|
|
3735
|
+
_boundsDefinedManually = false;
|
|
3736
|
+
_modelMatrix = mat4_exports.create();
|
|
3737
|
+
_matrixDirty = true;
|
|
3738
|
+
_poseMap = /* @__PURE__ */ new Map();
|
|
3739
|
+
/** World-space AABB, lazily recomputed after any transform change. */
|
|
3740
|
+
get boundingBox() {
|
|
3741
|
+
if (this._bboxDirty && !this._boundsDefinedManually) {
|
|
3742
|
+
this._boundingBox = this.computeBoundingBox();
|
|
3743
|
+
this._bboxDirty = false;
|
|
3744
|
+
}
|
|
3745
|
+
return this._boundingBox;
|
|
3746
|
+
}
|
|
3747
|
+
set boundingBox(value) {
|
|
3748
|
+
this._boundingBox = value;
|
|
3749
|
+
this._bboxDirty = false;
|
|
3750
|
+
}
|
|
3751
|
+
/** When `false` the model is excluded from collision detection. */
|
|
3752
|
+
collidable = true;
|
|
3753
|
+
constructor(meshes, translation = [0, 0, 0], scale5 = [1, 1, 1], _name = "model", skeleton = null) {
|
|
3754
|
+
this.meshes = meshes;
|
|
3755
|
+
this.translation = translation;
|
|
3756
|
+
this.scale = scale5;
|
|
3757
|
+
this.rotation = [0, 0, 0];
|
|
3758
|
+
this.collider = new Collider("box");
|
|
3759
|
+
this.name = _name;
|
|
3760
|
+
this.skeleton = skeleton;
|
|
3761
|
+
this._boundingBox = this.computeBoundingBox();
|
|
3762
|
+
this.translation[1] -= this._boundingBox.min[1];
|
|
3763
|
+
this._matrixDirty = true;
|
|
3764
|
+
this._bboxDirty = true;
|
|
3765
|
+
}
|
|
3766
|
+
// ─────────────────────────────────────────────
|
|
3767
|
+
// ░░░ Transform API ░░░
|
|
3768
|
+
// ─────────────────────────────────────────────
|
|
3769
|
+
/** Set absolute position. Marks matrix and bounding box dirty. */
|
|
3770
|
+
setTranslation(x, y, z) {
|
|
3771
|
+
this.translation = [x, y, z];
|
|
3772
|
+
this._matrixDirty = true;
|
|
3773
|
+
this._bboxDirty = true;
|
|
3774
|
+
}
|
|
3775
|
+
/** Set absolute rotation (radians per axis). */
|
|
3776
|
+
setRotation(x, y, z) {
|
|
3777
|
+
this.rotation = [x, y, z];
|
|
3778
|
+
this._matrixDirty = true;
|
|
3779
|
+
this._bboxDirty = true;
|
|
3780
|
+
}
|
|
3781
|
+
/** Set absolute scale. */
|
|
3782
|
+
setScale(x, y, z) {
|
|
3783
|
+
this.scale = [x, y, z];
|
|
3784
|
+
this._matrixDirty = true;
|
|
3785
|
+
this._bboxDirty = true;
|
|
3786
|
+
}
|
|
3787
|
+
/** Translate the model by a delta. */
|
|
3788
|
+
move(dx, dy, dz = 0) {
|
|
3789
|
+
this.translation[0] += dx;
|
|
3790
|
+
this.translation[1] += dy;
|
|
3791
|
+
this.translation[2] += dz;
|
|
3792
|
+
this._matrixDirty = true;
|
|
3793
|
+
this._bboxDirty = true;
|
|
3794
|
+
}
|
|
3795
|
+
// ─────────────────────────────────────────────
|
|
3796
|
+
// ░░░ Matrix Handling ░░░
|
|
3797
|
+
// ─────────────────────────────────────────────
|
|
3798
|
+
getModelMatrix() {
|
|
3799
|
+
if (this._matrixDirty) {
|
|
3800
|
+
mat4_exports.identity(this._modelMatrix);
|
|
3801
|
+
mat4_exports.translate(this._modelMatrix, this._modelMatrix, this.translation);
|
|
3802
|
+
mat4_exports.rotateX(this._modelMatrix, this._modelMatrix, this.rotation[0]);
|
|
3803
|
+
mat4_exports.rotateY(this._modelMatrix, this._modelMatrix, this.rotation[1]);
|
|
3804
|
+
mat4_exports.rotateZ(this._modelMatrix, this._modelMatrix, this.rotation[2]);
|
|
3805
|
+
mat4_exports.scale(this._modelMatrix, this._modelMatrix, this.scale);
|
|
3806
|
+
this._matrixDirty = false;
|
|
3807
|
+
}
|
|
3808
|
+
return this._modelMatrix;
|
|
3809
|
+
}
|
|
3810
|
+
// ─────────────────────────────────────────────
|
|
3811
|
+
// ░░░ Bounding Box & Collider ░░░
|
|
3812
|
+
// ─────────────────────────────────────────────
|
|
3813
|
+
/**
|
|
3814
|
+
* Manually define the collision bounding box relative to the model's
|
|
3815
|
+
* current translation.
|
|
3816
|
+
*/
|
|
3817
|
+
setBounds(xOffset, yOffset, zOffset, width, height, depth) {
|
|
3818
|
+
this.boundingBox.min = [
|
|
3819
|
+
this.translation[0] + xOffset,
|
|
3820
|
+
this.translation[1] + yOffset,
|
|
3821
|
+
this.translation[2] + zOffset
|
|
3822
|
+
];
|
|
3823
|
+
this.boundingBox.max = [
|
|
3824
|
+
this.boundingBox.min[0] + width,
|
|
3825
|
+
this.boundingBox.min[1] + height,
|
|
3826
|
+
this.boundingBox.min[2] + depth
|
|
3827
|
+
];
|
|
3828
|
+
this._boundsDefinedManually = true;
|
|
3829
|
+
}
|
|
3830
|
+
computeBoundingBox() {
|
|
3831
|
+
if (this.meshes.length === 0) {
|
|
3832
|
+
return { min: [...this.translation], max: [...this.translation] };
|
|
3833
|
+
}
|
|
3834
|
+
const modelMat = this.getModelMatrix();
|
|
3835
|
+
let effectiveMat = modelMat;
|
|
3836
|
+
if (this.skeleton) {
|
|
3837
|
+
effectiveMat = mat4_exports.create();
|
|
3838
|
+
mat4_exports.multiply(effectiveMat, modelMat, this.skeleton.rootTransform);
|
|
3839
|
+
}
|
|
3840
|
+
const min3 = [Infinity, Infinity, Infinity];
|
|
3841
|
+
const max3 = [-Infinity, -Infinity, -Infinity];
|
|
3842
|
+
for (const mesh of this.meshes) {
|
|
3843
|
+
if (!mesh.isCollidable) continue;
|
|
3844
|
+
mesh.computeBounds();
|
|
3845
|
+
const mb = mesh.boundingBox;
|
|
3846
|
+
const isDegenerate = mb.min[0] === mb.max[0] && mb.min[1] === mb.max[1] && mb.min[2] === mb.max[2];
|
|
3847
|
+
if (isDegenerate) continue;
|
|
3848
|
+
const transformed = transformAABB(
|
|
3849
|
+
mesh.boundingBox.min,
|
|
3850
|
+
mesh.boundingBox.max,
|
|
3851
|
+
effectiveMat
|
|
3852
|
+
);
|
|
3853
|
+
for (let i = 0; i < 3; i++) {
|
|
3854
|
+
min3[i] = Math.min(min3[i], transformed.min[i]);
|
|
3855
|
+
max3[i] = Math.max(max3[i], transformed.max[i]);
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
if (!isFinite(min3[0])) {
|
|
3859
|
+
const t = effectiveMat;
|
|
3860
|
+
const tx = t[12];
|
|
3861
|
+
const ty = t[13];
|
|
3862
|
+
const tz = t[14];
|
|
3863
|
+
return {
|
|
3864
|
+
min: [tx - 0.5, ty, tz - 0.5],
|
|
3865
|
+
max: [tx + 0.5, ty + 1, tz + 0.5]
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
return { min: min3, max: max3 };
|
|
3869
|
+
}
|
|
3870
|
+
/** Recompute the world-space AABB from mesh data (unless manually set). */
|
|
3871
|
+
updateBoundingBox() {
|
|
3872
|
+
if (this._boundsDefinedManually) return;
|
|
3873
|
+
this.boundingBox = this.computeBoundingBox();
|
|
3874
|
+
}
|
|
3875
|
+
/** World-space centre of the bounding box. */
|
|
3876
|
+
getCenter() {
|
|
3877
|
+
const { min: min3, max: max3 } = this.boundingBox;
|
|
3878
|
+
return [
|
|
3879
|
+
(min3[0] + max3[0]) / 2,
|
|
3880
|
+
(min3[1] + max3[1]) / 2,
|
|
3881
|
+
(min3[2] + max3[2]) / 2
|
|
3882
|
+
];
|
|
3883
|
+
}
|
|
3884
|
+
/** Extents of the bounding box in each axis. */
|
|
3885
|
+
getSize() {
|
|
3886
|
+
const { min: min3, max: max3 } = this.boundingBox;
|
|
3887
|
+
return [max3[0] - min3[0], max3[1] - min3[1], max3[2] - min3[2]];
|
|
3888
|
+
}
|
|
3889
|
+
/** Test for intersection with another model using their colliders. */
|
|
3890
|
+
intersects(other) {
|
|
3891
|
+
const a = this.collider;
|
|
3892
|
+
const b = other.collider;
|
|
3893
|
+
if (a.type !== "box" || b.type !== "box") {
|
|
3894
|
+
console.warn(
|
|
3895
|
+
`[Model] Collider types '${a.type}' / '${b.type}' not yet implemented \u2014 falling back to AABB.`
|
|
3896
|
+
);
|
|
3897
|
+
}
|
|
3898
|
+
return this.intersectAABB(other);
|
|
3899
|
+
}
|
|
3900
|
+
intersectAABB(other) {
|
|
3901
|
+
const a = this.boundingBox;
|
|
3902
|
+
const b = other.boundingBox;
|
|
3903
|
+
return !(a.max[0] < b.min[0] || a.min[0] > b.max[0] || a.max[1] < b.min[1] || a.min[1] > b.max[1] || a.max[2] < b.min[2] || a.min[2] > b.max[2]);
|
|
3904
|
+
}
|
|
3905
|
+
// ─────────────────────────────────────────────
|
|
3906
|
+
// ░░░ Resource Management ░░░
|
|
3907
|
+
// ─────────────────────────────────────────────
|
|
3908
|
+
/** Release all GPU resources held by this model's meshes. */
|
|
3909
|
+
dispose(glCore) {
|
|
3910
|
+
for (const mesh of this.meshes) {
|
|
3911
|
+
mesh.dispose?.(glCore);
|
|
3912
|
+
}
|
|
3913
|
+
this.meshes = [];
|
|
3914
|
+
}
|
|
3915
|
+
// ─────────────────────────────────────────────
|
|
3916
|
+
// ░░░ Cloning ░░░
|
|
3917
|
+
// ─────────────────────────────────────────────
|
|
3918
|
+
/** Deep-clone the model including all meshes. Materials are shared. */
|
|
3919
|
+
clone() {
|
|
3920
|
+
const clonedMeshes = this.meshes.map((m) => m.clone ? m.clone() : m);
|
|
3921
|
+
const c = new _Model(
|
|
3922
|
+
clonedMeshes,
|
|
3923
|
+
[...this.translation],
|
|
3924
|
+
[...this.scale],
|
|
3925
|
+
this.name,
|
|
3926
|
+
this.skeleton?.clone() ?? null
|
|
3927
|
+
);
|
|
3928
|
+
c.rotation = [...this.rotation];
|
|
3929
|
+
c.collider = new Collider(this.collider.type);
|
|
3930
|
+
c.boundingBox = {
|
|
3931
|
+
min: [...this.boundingBox.min],
|
|
3932
|
+
max: [...this.boundingBox.max]
|
|
3933
|
+
};
|
|
3934
|
+
for (const [name, clip] of this.animations) {
|
|
3935
|
+
c.animations.set(name, clip.clone());
|
|
3936
|
+
}
|
|
3937
|
+
return c;
|
|
3938
|
+
}
|
|
3939
|
+
// ─────────────────────────────────────────────
|
|
3940
|
+
// ░░░ Animation ░░░
|
|
3941
|
+
// ─────────────────────────────────────────────
|
|
3942
|
+
/**
|
|
3943
|
+
* Start playing a named animation clip.
|
|
3944
|
+
* @param name - Must match a key in {@link animations}.
|
|
3945
|
+
* @param loop - Whether the clip should loop (default `true`).
|
|
3946
|
+
*/
|
|
3947
|
+
playAnimation(name, loop = true) {
|
|
3948
|
+
const clip = this.animations.get(name);
|
|
3949
|
+
if (!clip) {
|
|
3950
|
+
console.warn(`[Model:${this.name}] Animation "${name}" not found`);
|
|
3951
|
+
return;
|
|
3952
|
+
}
|
|
3953
|
+
this.activeAnimation = clip;
|
|
3954
|
+
clip.loop = loop;
|
|
3955
|
+
clip.reset();
|
|
3956
|
+
clip.play();
|
|
3957
|
+
}
|
|
3958
|
+
/** Pause the active animation without rewinding. */
|
|
3959
|
+
pauseAnimation() {
|
|
3960
|
+
this.activeAnimation?.pause();
|
|
3961
|
+
}
|
|
3962
|
+
/** Stop the active animation and rewind. */
|
|
3963
|
+
stopAnimation() {
|
|
3964
|
+
if (this.activeAnimation) {
|
|
3965
|
+
this.activeAnimation.stop();
|
|
3966
|
+
this.activeAnimation = null;
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
/** List the names of all available animations. */
|
|
3970
|
+
getAnimationNames() {
|
|
3971
|
+
return [...this.animations.keys()];
|
|
3972
|
+
}
|
|
3973
|
+
/**
|
|
3974
|
+
* Advance animation and recompute joint matrices.
|
|
3975
|
+
* Call this every frame from your game loop.
|
|
3976
|
+
*
|
|
3977
|
+
* @param deltaTime - Elapsed time in seconds since the last frame.
|
|
3978
|
+
*/
|
|
3979
|
+
update(deltaTime) {
|
|
3980
|
+
if (!this.activeAnimation || !this.skeleton) return;
|
|
3981
|
+
this.activeAnimation.update(deltaTime);
|
|
3982
|
+
this.activeAnimation.sample(this._poseMap);
|
|
3983
|
+
this.skeleton.computeJointMatrices(this._poseMap);
|
|
3984
|
+
}
|
|
3985
|
+
};
|
|
3986
|
+
|
|
3987
|
+
// ../GenesisGL/src/Core/classes/AnimationClip.ts
|
|
3988
|
+
var _sv0Vec3 = vec3_exports.create();
|
|
3989
|
+
var _sv1Vec3 = vec3_exports.create();
|
|
3990
|
+
var _sOutVec3 = vec3_exports.create();
|
|
3991
|
+
var _sv0Quat = quat_exports.create();
|
|
3992
|
+
var _sv1Quat = quat_exports.create();
|
|
3993
|
+
var _sOutQuat = quat_exports.create();
|
|
3994
|
+
|
|
3995
|
+
// ../GenesisGL/src/Core/utils/create-wire-box.ts
|
|
3996
|
+
function createWireBox(min3, max3, material) {
|
|
3997
|
+
const [minX, minY, minZ] = min3;
|
|
3998
|
+
const [maxX, maxY, maxZ] = max3;
|
|
3999
|
+
const vertices = [
|
|
4000
|
+
minX,
|
|
4001
|
+
minY,
|
|
4002
|
+
minZ,
|
|
4003
|
+
maxX,
|
|
4004
|
+
minY,
|
|
4005
|
+
minZ,
|
|
4006
|
+
maxX,
|
|
4007
|
+
maxY,
|
|
4008
|
+
minZ,
|
|
4009
|
+
minX,
|
|
4010
|
+
maxY,
|
|
4011
|
+
minZ,
|
|
4012
|
+
minX,
|
|
4013
|
+
minY,
|
|
4014
|
+
maxZ,
|
|
4015
|
+
maxX,
|
|
4016
|
+
minY,
|
|
4017
|
+
maxZ,
|
|
4018
|
+
maxX,
|
|
4019
|
+
maxY,
|
|
4020
|
+
maxZ,
|
|
4021
|
+
minX,
|
|
4022
|
+
maxY,
|
|
4023
|
+
maxZ
|
|
4024
|
+
];
|
|
4025
|
+
const indices = [
|
|
4026
|
+
0,
|
|
4027
|
+
1,
|
|
4028
|
+
1,
|
|
4029
|
+
2,
|
|
4030
|
+
2,
|
|
4031
|
+
3,
|
|
4032
|
+
3,
|
|
4033
|
+
0,
|
|
4034
|
+
// bottom face
|
|
4035
|
+
4,
|
|
4036
|
+
5,
|
|
4037
|
+
5,
|
|
4038
|
+
6,
|
|
4039
|
+
6,
|
|
4040
|
+
7,
|
|
4041
|
+
7,
|
|
4042
|
+
4,
|
|
4043
|
+
// top face
|
|
4044
|
+
0,
|
|
4045
|
+
4,
|
|
4046
|
+
1,
|
|
4047
|
+
5,
|
|
4048
|
+
2,
|
|
4049
|
+
6,
|
|
4050
|
+
3,
|
|
4051
|
+
7
|
|
4052
|
+
// vertical edges
|
|
4053
|
+
];
|
|
4054
|
+
const lineVertices = [];
|
|
4055
|
+
for (let i = 0; i < indices.length; i++) {
|
|
4056
|
+
const idx = indices[i];
|
|
4057
|
+
lineVertices.push(
|
|
4058
|
+
vertices[idx * 3],
|
|
4059
|
+
vertices[idx * 3 + 1],
|
|
4060
|
+
vertices[idx * 3 + 2]
|
|
4061
|
+
);
|
|
4062
|
+
}
|
|
4063
|
+
const normals = new Float32Array(lineVertices.length);
|
|
4064
|
+
const mesh = new Mesh(
|
|
4065
|
+
"hitbox",
|
|
4066
|
+
new Float32Array(lineVertices),
|
|
4067
|
+
normals,
|
|
4068
|
+
material,
|
|
4069
|
+
new Float32Array(),
|
|
4070
|
+
null
|
|
4071
|
+
);
|
|
4072
|
+
mesh.setMode(GL_LINES);
|
|
4073
|
+
return mesh;
|
|
4074
|
+
}
|
|
4075
|
+
|
|
4076
|
+
// ../GenesisGL/src/Core/classes/Renderer.ts
|
|
4077
|
+
var Renderer = class {
|
|
4078
|
+
constructor(webglCore, viewport) {
|
|
4079
|
+
this.webglCore = webglCore;
|
|
4080
|
+
this.viewport = viewport;
|
|
4081
|
+
const gl = webglCore.getRenderingContext();
|
|
4082
|
+
this._isWebGL2 = gl instanceof WebGL2RenderingContext;
|
|
4083
|
+
if (gl) gl.enable(gl.DEPTH_TEST);
|
|
4084
|
+
}
|
|
4085
|
+
webglCore;
|
|
4086
|
+
viewport;
|
|
4087
|
+
/** Set to `true` to render wireframe bounding boxes for debugging. */
|
|
4088
|
+
debug = false;
|
|
4089
|
+
// Cached debug materials to avoid per-frame GPU allocations
|
|
4090
|
+
_modelHitboxMaterial = null;
|
|
4091
|
+
_meshHitboxMaterial = null;
|
|
4092
|
+
// Cache wire-box debug meshes: recreated only when the bounding box changes.
|
|
4093
|
+
_modelWireBoxCache = /* @__PURE__ */ new WeakMap();
|
|
4094
|
+
_meshWireBoxCache = /* @__PURE__ */ new WeakMap();
|
|
4095
|
+
/** Pre-allocated identity matrix for world-space hitbox draws. */
|
|
4096
|
+
_identity = mat4_exports.create();
|
|
4097
|
+
/** Cached `gl instanceof WebGL2RenderingContext` — computed once at construction. */
|
|
4098
|
+
_isWebGL2;
|
|
4099
|
+
/** Lazily-created material for model-level hitboxes (red). */
|
|
4100
|
+
get modelHitboxMaterial() {
|
|
4101
|
+
if (!this._modelHitboxMaterial) {
|
|
4102
|
+
this._modelHitboxMaterial = new Material(this.webglCore);
|
|
4103
|
+
this._modelHitboxMaterial.setColorHex("#ff0404ff");
|
|
4104
|
+
this._modelHitboxMaterial.unlit = true;
|
|
4105
|
+
}
|
|
4106
|
+
return this._modelHitboxMaterial;
|
|
4107
|
+
}
|
|
4108
|
+
/** Lazily-created material for mesh-level hitboxes (green). */
|
|
4109
|
+
get meshHitboxMaterial() {
|
|
4110
|
+
if (!this._meshHitboxMaterial) {
|
|
4111
|
+
this._meshHitboxMaterial = new Material(this.webglCore);
|
|
4112
|
+
this._meshHitboxMaterial.setColorHex("#04ff0cff");
|
|
4113
|
+
this._meshHitboxMaterial.unlit = true;
|
|
4114
|
+
}
|
|
4115
|
+
return this._meshHitboxMaterial;
|
|
4116
|
+
}
|
|
4117
|
+
clearFrame(color = [0.2, 0.5, 0.95, 1]) {
|
|
4118
|
+
const gl = this.webglCore.getRenderingContext();
|
|
4119
|
+
if (!gl) return;
|
|
4120
|
+
gl.clearColor(...color);
|
|
4121
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
4122
|
+
}
|
|
4123
|
+
render(scene) {
|
|
4124
|
+
const gl = this.webglCore.getRenderingContext();
|
|
4125
|
+
if (!gl) return;
|
|
4126
|
+
const models = scene.getModels();
|
|
4127
|
+
const lights = scene.getLights();
|
|
4128
|
+
const camera = this.viewport.camera;
|
|
4129
|
+
const viewPosition = camera.getComputedPosition();
|
|
4130
|
+
this.clearFrame();
|
|
4131
|
+
const viewMatrix = camera.getViewMatrix();
|
|
4132
|
+
const projMatrix = camera.getProjectionMatrix();
|
|
4133
|
+
let activeProgram = null;
|
|
4134
|
+
for (const model of models) {
|
|
4135
|
+
activeProgram = this.drawModel(
|
|
4136
|
+
gl,
|
|
4137
|
+
model,
|
|
4138
|
+
lights,
|
|
4139
|
+
viewPosition,
|
|
4140
|
+
viewMatrix,
|
|
4141
|
+
projMatrix,
|
|
4142
|
+
activeProgram
|
|
4143
|
+
);
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
drawModel(gl, model, lights, viewPosition, viewMatrix, projMatrix, activeProgram) {
|
|
4147
|
+
const modelMatrix = model.getModelMatrix();
|
|
4148
|
+
const hasSkeleton = model.skeleton !== null;
|
|
4149
|
+
for (const mesh of model.meshes) {
|
|
4150
|
+
activeProgram = this.drawMesh(
|
|
4151
|
+
mesh,
|
|
4152
|
+
lights,
|
|
4153
|
+
viewPosition,
|
|
4154
|
+
modelMatrix,
|
|
4155
|
+
viewMatrix,
|
|
4156
|
+
projMatrix,
|
|
4157
|
+
activeProgram,
|
|
4158
|
+
hasSkeleton && mesh.isSkinned ? model : null
|
|
4159
|
+
);
|
|
4160
|
+
if (this.debug) {
|
|
4161
|
+
this.drawHitBoxForMesh(
|
|
4162
|
+
mesh,
|
|
4163
|
+
modelMatrix,
|
|
4164
|
+
viewMatrix,
|
|
4165
|
+
projMatrix,
|
|
4166
|
+
activeProgram
|
|
4167
|
+
);
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
if (this.debug) {
|
|
4171
|
+
this.drawHitBox(model, activeProgram);
|
|
4172
|
+
}
|
|
4173
|
+
return activeProgram;
|
|
4174
|
+
}
|
|
4175
|
+
drawMesh(mesh, lights, viewPosition, modelMatrix, viewMatrix, projMatrix, activeProgram, skinnedModel = null) {
|
|
4176
|
+
const gl = this.webglCore.getRenderingContext();
|
|
4177
|
+
if (!gl) return activeProgram;
|
|
4178
|
+
if (!mesh.material) return activeProgram;
|
|
4179
|
+
mesh.initBuffer(this.webglCore);
|
|
4180
|
+
const { program, uniformLocations } = mesh.material;
|
|
4181
|
+
if (program !== activeProgram) {
|
|
4182
|
+
gl.useProgram(program);
|
|
4183
|
+
activeProgram = program;
|
|
4184
|
+
if (uniformLocations["uView"])
|
|
4185
|
+
gl.uniformMatrix4fv(uniformLocations["uView"], false, viewMatrix);
|
|
4186
|
+
if (uniformLocations["uProjection"])
|
|
4187
|
+
gl.uniformMatrix4fv(uniformLocations["uProjection"], false, projMatrix);
|
|
4188
|
+
}
|
|
4189
|
+
const isWebGL2 = this._isWebGL2;
|
|
4190
|
+
if (isWebGL2 && mesh.buffers?.vao) {
|
|
4191
|
+
gl.bindVertexArray(
|
|
4192
|
+
mesh.buffers.vao
|
|
4193
|
+
);
|
|
4194
|
+
} else {
|
|
4195
|
+
const aPosition = mesh.material.attribLocations["aPosition"];
|
|
4196
|
+
if (aPosition !== -1 && mesh.buffers?.vertexBuffer) {
|
|
4197
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.vertexBuffer);
|
|
4198
|
+
gl.enableVertexAttribArray(aPosition);
|
|
4199
|
+
gl.vertexAttribPointer(aPosition, 3, gl.FLOAT, false, 0, 0);
|
|
4200
|
+
}
|
|
4201
|
+
const aNormal = mesh.material.attribLocations["aNormal"];
|
|
4202
|
+
if (aNormal !== -1 && mesh.buffers?.normalBuffer) {
|
|
4203
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.normalBuffer);
|
|
4204
|
+
gl.enableVertexAttribArray(aNormal);
|
|
4205
|
+
gl.vertexAttribPointer(aNormal, 3, gl.FLOAT, false, 0, 0);
|
|
4206
|
+
}
|
|
4207
|
+
const aTexCoord = mesh.material.attribLocations["aTexCoord"];
|
|
4208
|
+
if (aTexCoord !== -1 && mesh.buffers?.texCoordBuffer) {
|
|
4209
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.texCoordBuffer);
|
|
4210
|
+
gl.enableVertexAttribArray(aTexCoord);
|
|
4211
|
+
gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, 0, 0);
|
|
4212
|
+
}
|
|
4213
|
+
const aJointIndices = mesh.material.attribLocations["aJointIndices"];
|
|
4214
|
+
if (aJointIndices !== -1 && mesh.buffers?.jointIndexBuffer) {
|
|
4215
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.jointIndexBuffer);
|
|
4216
|
+
gl.enableVertexAttribArray(aJointIndices);
|
|
4217
|
+
gl.vertexAttribPointer(aJointIndices, 4, gl.FLOAT, false, 0, 0);
|
|
4218
|
+
}
|
|
4219
|
+
const aJointWeights = mesh.material.attribLocations["aJointWeights"];
|
|
4220
|
+
if (aJointWeights !== -1 && mesh.buffers?.jointWeightBuffer) {
|
|
4221
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffers.jointWeightBuffer);
|
|
4222
|
+
gl.enableVertexAttribArray(aJointWeights);
|
|
4223
|
+
gl.vertexAttribPointer(aJointWeights, 4, gl.FLOAT, false, 0, 0);
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
mesh.material.apply(gl, lights, viewPosition);
|
|
4227
|
+
const uUseSkinning = uniformLocations["uUseSkinning"];
|
|
4228
|
+
const skeleton = skinnedModel?.skeleton ?? null;
|
|
4229
|
+
if (skeleton && mesh.isSkinned) {
|
|
4230
|
+
if (uUseSkinning) gl.uniform1i(uUseSkinning, 1);
|
|
4231
|
+
const uJointMatrices = uniformLocations["uJointMatrices[0]"];
|
|
4232
|
+
if (uJointMatrices) {
|
|
4233
|
+
gl.uniformMatrix4fv(uJointMatrices, false, skeleton.jointMatrices);
|
|
4234
|
+
}
|
|
4235
|
+
} else {
|
|
4236
|
+
if (uUseSkinning) gl.uniform1i(uUseSkinning, 0);
|
|
4237
|
+
}
|
|
4238
|
+
const uModel = mesh.material.uniformLocations["uModel"];
|
|
4239
|
+
if (uModel) gl.uniformMatrix4fv(uModel, false, modelMatrix);
|
|
4240
|
+
if (mesh.buffers?.indexBuffer && mesh.indices) {
|
|
4241
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, mesh.buffers.indexBuffer);
|
|
4242
|
+
const type = mesh.indices instanceof Uint32Array ? gl.UNSIGNED_INT : gl.UNSIGNED_SHORT;
|
|
4243
|
+
gl.drawElements(mesh.mode, mesh.indices.length, type, 0);
|
|
4244
|
+
} else {
|
|
4245
|
+
gl.drawArrays(mesh.mode, 0, mesh.vertices.length / 3);
|
|
4246
|
+
}
|
|
4247
|
+
if (isWebGL2 && mesh.buffers?.vao) {
|
|
4248
|
+
gl.bindVertexArray(null);
|
|
4249
|
+
} else {
|
|
4250
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
4251
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
4252
|
+
}
|
|
4253
|
+
return activeProgram;
|
|
4254
|
+
}
|
|
4255
|
+
drawHitBox(model, activeProgram) {
|
|
4256
|
+
const bbox = model.boundingBox;
|
|
4257
|
+
const key = `${bbox.min[0]},${bbox.min[1]},${bbox.min[2]},${bbox.max[0]},${bbox.max[1]},${bbox.max[2]}`;
|
|
4258
|
+
const cached = this._modelWireBoxCache.get(model);
|
|
4259
|
+
let hitboxMesh;
|
|
4260
|
+
if (!cached || cached.key !== key) {
|
|
4261
|
+
hitboxMesh = createWireBox(bbox.min, bbox.max, this.modelHitboxMaterial);
|
|
4262
|
+
hitboxMesh.isCollidable = false;
|
|
4263
|
+
this._modelWireBoxCache.set(model, { mesh: hitboxMesh, key });
|
|
4264
|
+
} else {
|
|
4265
|
+
hitboxMesh = cached.mesh;
|
|
4266
|
+
}
|
|
4267
|
+
const camera = this.viewport.camera;
|
|
4268
|
+
const viewMatrix = camera.getViewMatrix();
|
|
4269
|
+
const projMatrix = camera.getProjectionMatrix();
|
|
4270
|
+
this.drawMesh(
|
|
4271
|
+
hitboxMesh,
|
|
4272
|
+
[],
|
|
4273
|
+
camera.position,
|
|
4274
|
+
this._identity,
|
|
4275
|
+
viewMatrix,
|
|
4276
|
+
projMatrix,
|
|
4277
|
+
activeProgram
|
|
4278
|
+
);
|
|
4279
|
+
}
|
|
4280
|
+
drawHitBoxForMesh(mesh, modelMatrix, viewMatrix, projMatrix, activeProgram) {
|
|
4281
|
+
if (!mesh.boundingBox) return;
|
|
4282
|
+
const { min: min3, max: max3 } = mesh.boundingBox;
|
|
4283
|
+
const key = `${min3[0]},${min3[1]},${min3[2]},${max3[0]},${max3[1]},${max3[2]}`;
|
|
4284
|
+
const cached = this._meshWireBoxCache.get(mesh);
|
|
4285
|
+
let wireBox;
|
|
4286
|
+
if (!cached || cached.key !== key) {
|
|
4287
|
+
wireBox = createWireBox(min3, max3, this.meshHitboxMaterial);
|
|
4288
|
+
wireBox.isCollidable = false;
|
|
4289
|
+
this._meshWireBoxCache.set(mesh, { mesh: wireBox, key });
|
|
4290
|
+
} else {
|
|
4291
|
+
wireBox = cached.mesh;
|
|
4292
|
+
}
|
|
4293
|
+
const camera = this.viewport.camera;
|
|
4294
|
+
this.drawMesh(
|
|
4295
|
+
wireBox,
|
|
4296
|
+
[],
|
|
4297
|
+
camera.position,
|
|
4298
|
+
modelMatrix,
|
|
4299
|
+
viewMatrix,
|
|
4300
|
+
projMatrix,
|
|
4301
|
+
activeProgram
|
|
4302
|
+
);
|
|
4303
|
+
}
|
|
4304
|
+
};
|
|
4305
|
+
|
|
4306
|
+
// ../GenesisGL/src/Core/utils/parse-obj.ts
|
|
4307
|
+
function computeNormal(p1, p2, p3) {
|
|
4308
|
+
const u = [p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]];
|
|
4309
|
+
const v = [p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]];
|
|
4310
|
+
return [
|
|
4311
|
+
u[1] * v[2] - u[2] * v[1],
|
|
4312
|
+
u[2] * v[0] - u[0] * v[2],
|
|
4313
|
+
u[0] * v[1] - u[1] * v[0]
|
|
4314
|
+
];
|
|
4315
|
+
}
|
|
4316
|
+
async function loadMTL(url, webglCore) {
|
|
4317
|
+
const response = await fetch(url);
|
|
4318
|
+
if (!response.ok) throw new Error(`Failed to load MTL: ${url}`);
|
|
4319
|
+
const text = await response.text();
|
|
4320
|
+
const materials = {};
|
|
4321
|
+
let current = null;
|
|
4322
|
+
const basePath = url.split("/").slice(0, -1).join("/") + "/";
|
|
4323
|
+
const lines = text.split("\n");
|
|
4324
|
+
for (const line of lines) {
|
|
4325
|
+
const trimmed = line.trim();
|
|
4326
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
4327
|
+
const parts = trimmed.split(/\s+/);
|
|
4328
|
+
switch (parts[0].toLowerCase()) {
|
|
4329
|
+
case "newmtl":
|
|
4330
|
+
current = new Material(webglCore, { albedoColor: [1, 1, 1, 1] });
|
|
4331
|
+
materials[parts[1]] = current;
|
|
4332
|
+
break;
|
|
4333
|
+
case "kd":
|
|
4334
|
+
if (!current) continue;
|
|
4335
|
+
current.diffuse = [
|
|
4336
|
+
parseFloat(parts[1]),
|
|
4337
|
+
parseFloat(parts[2]),
|
|
4338
|
+
parseFloat(parts[3])
|
|
4339
|
+
];
|
|
4340
|
+
current.albedoColor = [...current.diffuse, 1];
|
|
4341
|
+
break;
|
|
4342
|
+
case "ks":
|
|
4343
|
+
if (!current) continue;
|
|
4344
|
+
current.specular = [
|
|
4345
|
+
parseFloat(parts[1]),
|
|
4346
|
+
parseFloat(parts[2]),
|
|
4347
|
+
parseFloat(parts[3])
|
|
4348
|
+
];
|
|
4349
|
+
break;
|
|
4350
|
+
case "ns":
|
|
4351
|
+
if (!current) continue;
|
|
4352
|
+
current.shininess = parseFloat(parts[1]);
|
|
4353
|
+
break;
|
|
4354
|
+
case "map_kd":
|
|
4355
|
+
if (!current) continue;
|
|
4356
|
+
await current.loadTexture(basePath + parts[1]);
|
|
4357
|
+
break;
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
return materials;
|
|
4361
|
+
}
|
|
4362
|
+
async function loadOBJWithMTL(webglCore, objUrl, mtlUrl, translation = [0, 0, 0], scale5 = [1, 1, 1], defaultMaterial = new Material(webglCore, { albedoColor: [1, 1, 1, 1] })) {
|
|
4363
|
+
const materials = mtlUrl ? await loadMTL(mtlUrl, webglCore) : {};
|
|
4364
|
+
const response = await fetch(objUrl);
|
|
4365
|
+
if (!response.ok) throw new Error(`Failed to load OBJ: ${objUrl}`);
|
|
4366
|
+
const objText = await response.text();
|
|
4367
|
+
const positions = [];
|
|
4368
|
+
const texCoords = [];
|
|
4369
|
+
const vertexNormals = [];
|
|
4370
|
+
const meshesData = {};
|
|
4371
|
+
let currentMaterialName = null;
|
|
4372
|
+
const lines = objText.split("\n");
|
|
4373
|
+
for (const line of lines) {
|
|
4374
|
+
const trimmed = line.trim();
|
|
4375
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
4376
|
+
const parts = trimmed.split(/\s+/);
|
|
4377
|
+
switch (parts[0]) {
|
|
4378
|
+
case "v":
|
|
4379
|
+
positions.push([
|
|
4380
|
+
parseFloat(parts[1]),
|
|
4381
|
+
parseFloat(parts[2]),
|
|
4382
|
+
parseFloat(parts[3])
|
|
4383
|
+
]);
|
|
4384
|
+
break;
|
|
4385
|
+
case "vt":
|
|
4386
|
+
texCoords.push([
|
|
4387
|
+
parseFloat(parts[1]),
|
|
4388
|
+
1 - parseFloat(parts[2])
|
|
4389
|
+
// flip V for WebGL
|
|
4390
|
+
]);
|
|
4391
|
+
break;
|
|
4392
|
+
case "vn":
|
|
4393
|
+
vertexNormals.push([
|
|
4394
|
+
parseFloat(parts[1]),
|
|
4395
|
+
parseFloat(parts[2]),
|
|
4396
|
+
parseFloat(parts[3])
|
|
4397
|
+
]);
|
|
4398
|
+
break;
|
|
4399
|
+
case "usemtl":
|
|
4400
|
+
currentMaterialName = parts[1];
|
|
4401
|
+
if (!meshesData[currentMaterialName])
|
|
4402
|
+
meshesData[currentMaterialName] = {
|
|
4403
|
+
vertices: [],
|
|
4404
|
+
normals: [],
|
|
4405
|
+
uvs: []
|
|
4406
|
+
};
|
|
4407
|
+
break;
|
|
4408
|
+
case "f": {
|
|
4409
|
+
if (!currentMaterialName) currentMaterialName = "default";
|
|
4410
|
+
if (!meshesData[currentMaterialName])
|
|
4411
|
+
meshesData[currentMaterialName] = {
|
|
4412
|
+
vertices: [],
|
|
4413
|
+
normals: [],
|
|
4414
|
+
uvs: []
|
|
4415
|
+
};
|
|
4416
|
+
const faceVertices = parts.slice(1).map((token) => {
|
|
4417
|
+
const [v, vt, vn] = token.split("/");
|
|
4418
|
+
let vIdx = parseInt(v);
|
|
4419
|
+
let tIdx = vt ? parseInt(vt) : null;
|
|
4420
|
+
let nIdx = vn ? parseInt(vn) : null;
|
|
4421
|
+
if (vIdx < 0) vIdx = positions.length + vIdx;
|
|
4422
|
+
else vIdx--;
|
|
4423
|
+
if (tIdx !== null) {
|
|
4424
|
+
if (tIdx < 0) tIdx = texCoords.length + tIdx;
|
|
4425
|
+
else tIdx--;
|
|
4426
|
+
}
|
|
4427
|
+
if (nIdx !== null) {
|
|
4428
|
+
if (nIdx < 0) nIdx = vertexNormals.length + nIdx;
|
|
4429
|
+
else nIdx--;
|
|
4430
|
+
}
|
|
4431
|
+
return { vIdx, tIdx, nIdx };
|
|
4432
|
+
});
|
|
4433
|
+
const { vertices, normals, uvs } = meshesData[currentMaterialName];
|
|
4434
|
+
for (let i = 1; i < faceVertices.length - 1; i++) {
|
|
4435
|
+
const tri = [faceVertices[0], faceVertices[i], faceVertices[i + 1]];
|
|
4436
|
+
const p = tri.map((v) => positions[v.vIdx]);
|
|
4437
|
+
let n;
|
|
4438
|
+
if (tri.every((v) => v.nIdx !== null)) {
|
|
4439
|
+
n = tri.map((v) => vertexNormals[v.nIdx]);
|
|
4440
|
+
} else {
|
|
4441
|
+
const normal = computeNormal(p[0], p[1], p[2]);
|
|
4442
|
+
n = [normal, normal, normal];
|
|
4443
|
+
}
|
|
4444
|
+
for (let j = 0; j < 3; j++) {
|
|
4445
|
+
vertices.push(...p[j]);
|
|
4446
|
+
normals.push(...n[j]);
|
|
4447
|
+
const tIdx = tri[j].tIdx;
|
|
4448
|
+
const uv = tIdx !== null ? texCoords[tIdx] : [0, 0];
|
|
4449
|
+
uvs.push(...uv);
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
break;
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
const meshes = [];
|
|
4457
|
+
for (const [matName, data] of Object.entries(meshesData)) {
|
|
4458
|
+
const material = materials[matName] || defaultMaterial || new Material(webglCore, { albedoColor: [1, 1, 1, 1] });
|
|
4459
|
+
const mesh = new Mesh(
|
|
4460
|
+
matName,
|
|
4461
|
+
new Float32Array(data.vertices),
|
|
4462
|
+
new Float32Array(data.normals),
|
|
4463
|
+
material,
|
|
4464
|
+
new Float32Array(data.uvs),
|
|
4465
|
+
null
|
|
4466
|
+
);
|
|
4467
|
+
meshes.push(mesh);
|
|
4468
|
+
}
|
|
4469
|
+
const modelName = objUrl.split("/").pop().replace(".obj", "");
|
|
4470
|
+
return new Model(meshes, translation, scale5, modelName);
|
|
4471
|
+
}
|
|
4472
|
+
|
|
4473
|
+
// src/hooks/useGenesisGL.ts
|
|
4474
|
+
var nullLoadOBJ = () => Promise.reject(new Error("GenesisGL not initialized"));
|
|
4475
|
+
function useGenesisGL(options) {
|
|
4476
|
+
const [context, setContext] = useState({
|
|
4477
|
+
renderer: null,
|
|
4478
|
+
scene: null,
|
|
4479
|
+
viewport: null,
|
|
4480
|
+
webglCore: null,
|
|
4481
|
+
loadOBJ: nullLoadOBJ
|
|
4482
|
+
});
|
|
4483
|
+
const contextRef = useRef(context);
|
|
4484
|
+
useEffect(() => {
|
|
4485
|
+
const {
|
|
4486
|
+
canvasRef,
|
|
4487
|
+
onReady,
|
|
4488
|
+
onError,
|
|
4489
|
+
width,
|
|
4490
|
+
height,
|
|
4491
|
+
initialYaw,
|
|
4492
|
+
initialPitch,
|
|
4493
|
+
initialZoom
|
|
4494
|
+
} = options;
|
|
4495
|
+
if (!canvasRef.current) return;
|
|
4496
|
+
try {
|
|
4497
|
+
const canvas = canvasRef.current;
|
|
4498
|
+
const vpWidth = width ?? window.innerWidth;
|
|
4499
|
+
const vpHeight = height ?? window.innerHeight;
|
|
4500
|
+
const webglCore = new WebGLCore(canvas);
|
|
4501
|
+
const viewport = new Viewport(canvas, vpWidth, vpHeight, webglCore, {
|
|
4502
|
+
pointerLock: false
|
|
4503
|
+
});
|
|
4504
|
+
const renderer = new Renderer(webglCore, viewport);
|
|
4505
|
+
const scene = Scene.withDefaultLights(webglCore);
|
|
4506
|
+
viewport.camera.target = [0, 0, 0];
|
|
4507
|
+
viewport.camera.position = [4, 2, 8];
|
|
4508
|
+
if (initialYaw !== void 0) viewport.camera.yaw = initialYaw;
|
|
4509
|
+
if (initialPitch !== void 0) viewport.camera.pitch = initialPitch;
|
|
4510
|
+
if (initialZoom !== void 0) viewport.camera.setZoom(initialZoom);
|
|
4511
|
+
viewport.camera.invalidate();
|
|
4512
|
+
const loadOBJ = (objUrl, opts = {}) => loadOBJWithMTL(
|
|
4513
|
+
webglCore,
|
|
4514
|
+
objUrl,
|
|
4515
|
+
opts.mtlUrl ?? null,
|
|
4516
|
+
opts.translation,
|
|
4517
|
+
opts.scale
|
|
4518
|
+
);
|
|
4519
|
+
const ctx = {
|
|
4520
|
+
renderer,
|
|
4521
|
+
scene,
|
|
4522
|
+
viewport,
|
|
4523
|
+
webglCore,
|
|
4524
|
+
loadOBJ
|
|
4525
|
+
};
|
|
4526
|
+
contextRef.current = ctx;
|
|
4527
|
+
setContext(ctx);
|
|
4528
|
+
if (onReady) onReady(ctx);
|
|
4529
|
+
} catch (error) {
|
|
4530
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
4531
|
+
console.error("Failed to initialize GenesisGL:", err);
|
|
4532
|
+
if (onError) onError(err);
|
|
4533
|
+
}
|
|
4534
|
+
return () => {
|
|
4535
|
+
const { scene, viewport, webglCore } = contextRef.current;
|
|
4536
|
+
if (scene && webglCore) scene.dispose(webglCore);
|
|
4537
|
+
if (viewport) viewport.dispose();
|
|
4538
|
+
if (webglCore) webglCore.dispose();
|
|
4539
|
+
};
|
|
4540
|
+
}, []);
|
|
4541
|
+
return context;
|
|
4542
|
+
}
|
|
4543
|
+
|
|
4544
|
+
// src/hooks/useRenderer.ts
|
|
4545
|
+
import { useRef as useRef2, useEffect as useEffect2 } from "react";
|
|
4546
|
+
function useRenderer(options) {
|
|
4547
|
+
const { renderer, onFrame, enabled = true } = options;
|
|
4548
|
+
const animationIdRef = useRef2(null);
|
|
4549
|
+
useEffect2(() => {
|
|
4550
|
+
if (!renderer || !enabled) return;
|
|
4551
|
+
const animate = (time) => {
|
|
4552
|
+
if (onFrame) onFrame(time);
|
|
4553
|
+
animationIdRef.current = requestAnimationFrame(animate);
|
|
4554
|
+
};
|
|
4555
|
+
animationIdRef.current = requestAnimationFrame(animate);
|
|
4556
|
+
return () => {
|
|
4557
|
+
if (animationIdRef.current !== null) {
|
|
4558
|
+
cancelAnimationFrame(animationIdRef.current);
|
|
4559
|
+
}
|
|
4560
|
+
};
|
|
4561
|
+
}, [renderer, onFrame, enabled]);
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
// src/hooks/useWorldToScreen.ts
|
|
4565
|
+
import { useState as useState2, useCallback } from "react";
|
|
4566
|
+
function mat4TransformVec4(m, x, y, z, w) {
|
|
4567
|
+
return {
|
|
4568
|
+
x: m[0] * x + m[4] * y + m[8] * z + m[12] * w,
|
|
4569
|
+
y: m[1] * x + m[5] * y + m[9] * z + m[13] * w,
|
|
4570
|
+
z: m[2] * x + m[6] * y + m[10] * z + m[14] * w,
|
|
4571
|
+
w: m[3] * x + m[7] * y + m[11] * z + m[15] * w
|
|
4572
|
+
};
|
|
4573
|
+
}
|
|
4574
|
+
function useWorldToScreen(context) {
|
|
4575
|
+
const [, forceUpdate] = useState2(0);
|
|
4576
|
+
const project = useCallback(
|
|
4577
|
+
(worldX, worldY, worldZ) => {
|
|
4578
|
+
if (!context?.viewport) return { x: 0, y: 0, visible: false };
|
|
4579
|
+
const { viewport } = context;
|
|
4580
|
+
const camera = viewport.camera;
|
|
4581
|
+
const canvas = viewport.getCanvas();
|
|
4582
|
+
const view = camera.getViewMatrix();
|
|
4583
|
+
const proj = camera.getProjectionMatrix();
|
|
4584
|
+
const v = mat4TransformVec4(view, worldX, worldY, worldZ, 1);
|
|
4585
|
+
const c = mat4TransformVec4(proj, v.x, v.y, v.z, v.w);
|
|
4586
|
+
if (Math.abs(c.w) < 1e-6) return { x: 0, y: 0, visible: false };
|
|
4587
|
+
const ndcX = c.x / c.w;
|
|
4588
|
+
const ndcY = c.y / c.w;
|
|
4589
|
+
const ndcZ = c.z / c.w;
|
|
4590
|
+
const visible = ndcZ > -1 && ndcZ < 1 && Math.abs(ndcX) < 1.2 && Math.abs(ndcY) < 1.2;
|
|
4591
|
+
return {
|
|
4592
|
+
x: (ndcX + 1) * 0.5 * canvas.clientWidth,
|
|
4593
|
+
y: (1 - ndcY) * 0.5 * canvas.clientHeight,
|
|
4594
|
+
visible
|
|
4595
|
+
};
|
|
4596
|
+
},
|
|
4597
|
+
[context]
|
|
4598
|
+
);
|
|
4599
|
+
const tick = useCallback(() => forceUpdate((n) => n + 1), []);
|
|
4600
|
+
return { project, tick };
|
|
4601
|
+
}
|
|
4602
|
+
|
|
4603
|
+
// src/hooks/useCameraControls.ts
|
|
4604
|
+
import { useCallback as useCallback2, useState as useState3 } from "react";
|
|
4605
|
+
var DEFAULT_YAW = 0;
|
|
4606
|
+
var DEFAULT_PITCH = 0;
|
|
4607
|
+
var DEFAULT_ZOOM = 1;
|
|
4608
|
+
function useCameraControls(ctx) {
|
|
4609
|
+
const [camera, setCameraState] = useState3({
|
|
4610
|
+
yaw: DEFAULT_YAW,
|
|
4611
|
+
pitch: DEFAULT_PITCH,
|
|
4612
|
+
zoom: DEFAULT_ZOOM
|
|
4613
|
+
});
|
|
4614
|
+
const sync = useCallback2((c) => {
|
|
4615
|
+
setCameraState({ yaw: c.yaw, pitch: c.pitch, zoom: c.zoom });
|
|
4616
|
+
}, []);
|
|
4617
|
+
const rotate2 = useCallback2(
|
|
4618
|
+
(deltaYaw, deltaPitch) => {
|
|
4619
|
+
const c = ctx?.viewport?.camera;
|
|
4620
|
+
if (!c) return;
|
|
4621
|
+
c.rotate(deltaYaw, deltaPitch);
|
|
4622
|
+
sync(c);
|
|
4623
|
+
},
|
|
4624
|
+
[ctx, sync]
|
|
4625
|
+
);
|
|
4626
|
+
const zoomBy = useCallback2(
|
|
4627
|
+
(delta) => {
|
|
4628
|
+
const c = ctx?.viewport?.camera;
|
|
4629
|
+
if (!c) return;
|
|
4630
|
+
c.zoomBy(delta);
|
|
4631
|
+
sync(c);
|
|
4632
|
+
},
|
|
4633
|
+
[ctx, sync]
|
|
4634
|
+
);
|
|
4635
|
+
const setZoom = useCallback2(
|
|
4636
|
+
(zoom) => {
|
|
4637
|
+
const c = ctx?.viewport?.camera;
|
|
4638
|
+
if (!c) return;
|
|
4639
|
+
c.setZoom(zoom);
|
|
4640
|
+
sync(c);
|
|
4641
|
+
},
|
|
4642
|
+
[ctx, sync]
|
|
4643
|
+
);
|
|
4644
|
+
const setYaw = useCallback2(
|
|
4645
|
+
(yaw) => {
|
|
4646
|
+
const c = ctx?.viewport?.camera;
|
|
4647
|
+
if (!c) return;
|
|
4648
|
+
c.yaw = yaw;
|
|
4649
|
+
c.invalidate();
|
|
4650
|
+
sync(c);
|
|
4651
|
+
},
|
|
4652
|
+
[ctx, sync]
|
|
4653
|
+
);
|
|
4654
|
+
const setPitch = useCallback2(
|
|
4655
|
+
(pitch) => {
|
|
4656
|
+
const c = ctx?.viewport?.camera;
|
|
4657
|
+
if (!c) return;
|
|
4658
|
+
c.pitch = pitch;
|
|
4659
|
+
c.invalidate();
|
|
4660
|
+
sync(c);
|
|
4661
|
+
},
|
|
4662
|
+
[ctx, sync]
|
|
4663
|
+
);
|
|
4664
|
+
const reset = useCallback2(() => {
|
|
4665
|
+
const c = ctx?.viewport?.camera;
|
|
4666
|
+
if (!c) return;
|
|
4667
|
+
c.yaw = DEFAULT_YAW;
|
|
4668
|
+
c.pitch = DEFAULT_PITCH;
|
|
4669
|
+
c.invalidate();
|
|
4670
|
+
c.setZoom(DEFAULT_ZOOM);
|
|
4671
|
+
sync(c);
|
|
4672
|
+
}, [ctx, sync]);
|
|
4673
|
+
return { camera, rotate: rotate2, setYaw, setPitch, zoomBy, setZoom, reset };
|
|
4674
|
+
}
|
|
4675
|
+
|
|
4676
|
+
// src/hooks/useCameraMouseDrag.ts
|
|
4677
|
+
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
4678
|
+
import { MouseDragControl as MouseDragControl2 } from "@fonsecabarreto/genesis-gl-core/Core";
|
|
4679
|
+
var SENSITIVITY = 8e-3;
|
|
4680
|
+
function useCameraMouseDrag(ctx, canvasRef) {
|
|
4681
|
+
const { rotate: rotate2 } = useCameraControls(ctx);
|
|
4682
|
+
const rotateRef = useRef3(rotate2);
|
|
4683
|
+
rotateRef.current = rotate2;
|
|
4684
|
+
useEffect3(() => {
|
|
4685
|
+
const el = canvasRef.current;
|
|
4686
|
+
if (!el || !ctx) return;
|
|
4687
|
+
const drag = new MouseDragControl2(el);
|
|
4688
|
+
const onDrag = (dx, dy, button) => {
|
|
4689
|
+
if (button !== 2) return;
|
|
4690
|
+
rotateRef.current(-dx * SENSITIVITY, dy * SENSITIVITY);
|
|
4691
|
+
};
|
|
4692
|
+
drag.onChange(onDrag);
|
|
4693
|
+
drag.enable();
|
|
4694
|
+
const onMouseDown = (e) => {
|
|
4695
|
+
if (e.button !== 2) return;
|
|
4696
|
+
el.style.cursor = "grabbing";
|
|
4697
|
+
};
|
|
4698
|
+
const onMouseUp = (e) => {
|
|
4699
|
+
if (e.button !== 2) return;
|
|
4700
|
+
el.style.cursor = "grab";
|
|
4701
|
+
};
|
|
4702
|
+
const onMouseEnter = () => {
|
|
4703
|
+
el.style.cursor = "grab";
|
|
4704
|
+
};
|
|
4705
|
+
const onMouseLeave = () => {
|
|
4706
|
+
el.style.cursor = "";
|
|
4707
|
+
};
|
|
4708
|
+
const onContextMenu = (e) => e.preventDefault();
|
|
4709
|
+
el.addEventListener("mousedown", onMouseDown);
|
|
4710
|
+
el.addEventListener("mouseenter", onMouseEnter);
|
|
4711
|
+
el.addEventListener("mouseleave", onMouseLeave);
|
|
4712
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
4713
|
+
el.addEventListener("contextmenu", onContextMenu);
|
|
4714
|
+
return () => {
|
|
4715
|
+
drag.disable();
|
|
4716
|
+
el.removeEventListener("mousedown", onMouseDown);
|
|
4717
|
+
el.removeEventListener("mouseenter", onMouseEnter);
|
|
4718
|
+
el.removeEventListener("mouseleave", onMouseLeave);
|
|
4719
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
4720
|
+
el.removeEventListener("contextmenu", onContextMenu);
|
|
4721
|
+
el.style.cursor = "";
|
|
4722
|
+
};
|
|
4723
|
+
}, [ctx]);
|
|
4724
|
+
}
|
|
4725
|
+
|
|
4726
|
+
export {
|
|
4727
|
+
useGenesisGL,
|
|
4728
|
+
useRenderer,
|
|
4729
|
+
useWorldToScreen,
|
|
4730
|
+
useCameraControls,
|
|
4731
|
+
useCameraMouseDrag
|
|
4732
|
+
};
|
|
4733
|
+
//# sourceMappingURL=chunk-QXHXGH2T.js.map
|