@carbonenginejs/runtime-utils 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/NOTICE +23 -23
- package/README.md +69 -69
- package/THIRD-PARTY-NOTICES.md +64 -64
- package/docs/README.md +74 -73
- package/docs/architecture.md +101 -101
- package/docs/concepts/foundation-consolidation.md +85 -85
- package/docs/concepts/model-lifecycle.md +111 -0
- package/docs/const-kb.md +85 -87
- package/docs/core-types/DECORATOR-TODOS.md +25 -25
- package/docs/core-types/README.md +229 -168
- package/docs/reference/api.md +105 -102
- package/docs/reference/classes/README.md +135 -135
- package/package.json +139 -139
- package/src/arrays.js +5 -5
- package/src/audio/audioFormats.js +34 -34
- package/src/audio/index.js +1 -1
- package/src/box3.js +331 -331
- package/src/bytes.js +56 -56
- package/src/compression.js +56 -56
- package/src/constants/index.js +7 -7
- package/src/constants/trinity.js +13 -13
- package/src/constants.js +15 -15
- package/src/curve.js +79 -79
- package/src/d3d/dxgiFormats.js +46 -46
- package/src/d3d/index.js +2 -2
- package/src/d3d/primitiveTopology.js +11 -11
- package/src/document/CjsCarbonDocument.js +212 -212
- package/src/document/CjsClassRegistry.js +373 -373
- package/src/document/CjsDocumentDehydrator.js +142 -142
- package/src/document/CjsDocumentHydrator.js +156 -156
- package/src/document/CjsStructRegistry.js +348 -348
- package/src/document/hydrationAdapter.js +129 -129
- package/src/document/index.js +6 -6
- package/src/errors/CjsError.js +286 -286
- package/src/errors/index.js +5 -5
- package/src/geometry/box.js +22 -22
- package/src/geometry/cylinder.js +22 -22
- package/src/geometry/helpers/earcut.js +1 -1
- package/src/geometry/helpers/misc.js +3 -3
- package/src/geometry/index.js +8 -8
- package/src/geometry/json.js +67 -67
- package/src/geometry/lathe.js +44 -44
- package/src/geometry/plane.js +14 -14
- package/src/geometry/shape.js +4 -4
- package/src/geometry/sphere.js +24 -24
- package/src/geometry/torus.js +14 -14
- package/src/graphics/colorSpaces.js +22 -22
- package/src/graphics/index.js +4 -4
- package/src/graphics/pixelFormats.js +158 -158
- package/src/graphics/textureDimensions.js +22 -22
- package/src/graphics/trinityEnums.js +87 -87
- package/src/index.js +62 -62
- package/src/is.js +108 -46
- package/src/json.js +23 -23
- package/src/lifecycle/CjsLifecycleState.js +77 -77
- package/src/lifecycle/index.js +1 -1
- package/src/lne3.js +70 -70
- package/src/lookup.js +48 -48
- package/src/mat3.js +51 -51
- package/src/mat4.js +699 -699
- package/src/math/index.js +25 -25
- package/src/math/scalar.js +63 -63
- package/src/media/index.js +1 -1
- package/src/media/mediaTypes.js +50 -50
- package/src/mesh.js +424 -424
- package/src/model/CjsEventEmitter.js +333 -333
- package/src/model/CjsModel.js +1589 -1544
- package/src/model/CjsModelState.js +72 -72
- package/src/model/index.js +4 -4
- package/src/model/sourceRecordUtils.js +54 -54
- package/src/noise.js +310 -310
- package/src/num.js +827 -827
- package/src/object.js +39 -39
- package/src/path.js +53 -53
- package/src/pln.js +125 -125
- package/src/pool.js +9 -9
- package/src/quat.js +144 -144
- package/src/ray3.js +188 -188
- package/src/renderContext/formats.js +145 -145
- package/src/renderContext/index.js +5 -5
- package/src/renderContext/presentation.js +125 -125
- package/src/renderContext/resources.js +27 -27
- package/src/renderContext/upscaling.js +22 -22
- package/src/renderContext/window.js +20 -20
- package/src/runtime/CjsRuntimeState.js +50 -50
- package/src/schema/CjsSchema.js +555 -318
- package/src/schema/index.js +4 -4
- package/src/shader/index.js +1 -1
- package/src/shader/shaderStages.js +37 -37
- package/src/sph3.js +181 -181
- package/src/tangent.js +288 -288
- package/src/text.js +40 -40
- package/src/tri3.js +98 -98
- package/src/types/carbonTypes.js +635 -635
- package/src/types/index.js +2 -2
- package/src/utils.js +58 -58
- package/src/validation.js +46 -46
- package/src/vec2.js +229 -229
- package/src/vec3.js +1188 -1172
- package/src/vec4.js +347 -347
- package/src/vertex.js +108 -108
- package/src/webgpu/index.js +1 -1
- package/src/webgpu/textureFormats.js +121 -121
package/src/schema/index.js
CHANGED
|
@@ -2,12 +2,12 @@ import { CJS_ENUM_NAME, CjsSchema } from "./CjsSchema.js";
|
|
|
2
2
|
|
|
3
3
|
// Namespace decorators re-exported as named bindings so consumers can write
|
|
4
4
|
// `import { type, io } from ".../schema"` and `@type.string` instead of `@CjsSchema.type.string`.
|
|
5
|
-
const { type, io, jessica, impl, carbon, components } = CjsSchema;
|
|
5
|
+
const { type, io, jessica, impl, carbon, components } = CjsSchema;
|
|
6
6
|
|
|
7
7
|
export {
|
|
8
|
-
carbon,
|
|
9
|
-
components,
|
|
10
|
-
CJS_ENUM_NAME,
|
|
8
|
+
carbon,
|
|
9
|
+
components,
|
|
10
|
+
CJS_ENUM_NAME,
|
|
11
11
|
CjsSchema,
|
|
12
12
|
CjsSchema as schema,
|
|
13
13
|
impl,
|
package/src/shader/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./shaderStages.js";
|
|
1
|
+
export * from "./shaderStages.js";
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canonical shader stage tokens.
|
|
3
|
-
*/
|
|
4
|
-
export const ShaderStage = Object.freeze({
|
|
5
|
-
VERTEX: "vertex",
|
|
6
|
-
FRAGMENT: "fragment",
|
|
7
|
-
PIXEL: "pixel",
|
|
8
|
-
COMPUTE: "compute",
|
|
9
|
-
GEOMETRY: "geometry",
|
|
10
|
-
HULL: "hull",
|
|
11
|
-
DOMAIN: "domain"
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Canonical shader model/profile tokens.
|
|
16
|
-
*/
|
|
17
|
-
export const ShaderModel = Object.freeze({
|
|
18
|
-
UNKNOWN: "unknown",
|
|
19
|
-
SM2: "sm2",
|
|
20
|
-
SM3: "sm3",
|
|
21
|
-
SM4: "sm4",
|
|
22
|
-
SM5: "sm5",
|
|
23
|
-
SM6: "sm6",
|
|
24
|
-
GLSL_ES_300: "glsl-es-300",
|
|
25
|
-
WGSL: "wgsl"
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Normalize a shader stage token.
|
|
30
|
-
*
|
|
31
|
-
* @param {string} stage Shader stage token.
|
|
32
|
-
* @returns {string} Canonical lowercase token.
|
|
33
|
-
*/
|
|
34
|
-
export function normalizeShaderStage(stage)
|
|
35
|
-
{
|
|
36
|
-
return stage ? String(stage).trim().toLowerCase() : "";
|
|
37
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Canonical shader stage tokens.
|
|
3
|
+
*/
|
|
4
|
+
export const ShaderStage = Object.freeze({
|
|
5
|
+
VERTEX: "vertex",
|
|
6
|
+
FRAGMENT: "fragment",
|
|
7
|
+
PIXEL: "pixel",
|
|
8
|
+
COMPUTE: "compute",
|
|
9
|
+
GEOMETRY: "geometry",
|
|
10
|
+
HULL: "hull",
|
|
11
|
+
DOMAIN: "domain"
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Canonical shader model/profile tokens.
|
|
16
|
+
*/
|
|
17
|
+
export const ShaderModel = Object.freeze({
|
|
18
|
+
UNKNOWN: "unknown",
|
|
19
|
+
SM2: "sm2",
|
|
20
|
+
SM3: "sm3",
|
|
21
|
+
SM4: "sm4",
|
|
22
|
+
SM5: "sm5",
|
|
23
|
+
SM6: "sm6",
|
|
24
|
+
GLSL_ES_300: "glsl-es-300",
|
|
25
|
+
WGSL: "wgsl"
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Normalize a shader stage token.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} stage Shader stage token.
|
|
32
|
+
* @returns {string} Canonical lowercase token.
|
|
33
|
+
*/
|
|
34
|
+
export function normalizeShaderStage(stage)
|
|
35
|
+
{
|
|
36
|
+
return stage ? String(stage).trim().toLowerCase() : "";
|
|
37
|
+
}
|
package/src/sph3.js
CHANGED
|
@@ -9,35 +9,35 @@ import { box3 } from "./box3.js";
|
|
|
9
9
|
* @typedef {Float32Array} sph3
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
export const sph3 = {};
|
|
13
|
-
|
|
14
|
-
// Scratch
|
|
15
|
-
let sph3_0 = null;
|
|
16
|
-
let box3_0 = null;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Allocates a pooled sph3
|
|
20
|
-
* @returns {Float32Array|sph3}
|
|
21
|
-
*/
|
|
22
|
-
sph3.alloc = vec4.alloc;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Unallocates a pooled sph3
|
|
26
|
-
* @param {sph3|Float32Array} a
|
|
27
|
-
*/
|
|
28
|
-
sph3.unalloc = vec4.unalloc;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns a subarray containing the position component of the sph3
|
|
32
|
-
* - Why does webpack fail to resolve this if referencing pln.normal?
|
|
12
|
+
export const sph3 = {};
|
|
13
|
+
|
|
14
|
+
// Scratch
|
|
15
|
+
let sph3_0 = null;
|
|
16
|
+
let box3_0 = null;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Allocates a pooled sph3
|
|
20
|
+
* @returns {Float32Array|sph3}
|
|
21
|
+
*/
|
|
22
|
+
sph3.alloc = vec4.alloc;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Unallocates a pooled sph3
|
|
26
|
+
* @param {sph3|Float32Array} a
|
|
27
|
+
*/
|
|
28
|
+
sph3.unalloc = vec4.unalloc;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns a subarray containing the position component of the sph3
|
|
32
|
+
* - Why does webpack fail to resolve this if referencing pln.normal?
|
|
33
33
|
*
|
|
34
34
|
* @param {sph3} a
|
|
35
35
|
* @returns {sph3}
|
|
36
36
|
*/
|
|
37
|
-
sph3.$position = function(a)
|
|
38
|
-
{
|
|
39
|
-
return a.subarray(0, 3);
|
|
40
|
-
};
|
|
37
|
+
sph3.$position = function(a)
|
|
38
|
+
{
|
|
39
|
+
return a.subarray(0, 3);
|
|
40
|
+
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Clones a sphere
|
|
@@ -54,10 +54,10 @@ sph3.clone = vec4.clone;
|
|
|
54
54
|
* @param {vec3} p
|
|
55
55
|
* @returns {boolean}
|
|
56
56
|
*/
|
|
57
|
-
sph3.containsPoint = function(a, p)
|
|
58
|
-
{
|
|
59
|
-
if (sph3.isEmpty(a)) return false;
|
|
60
|
-
|
|
57
|
+
sph3.containsPoint = function(a, p)
|
|
58
|
+
{
|
|
59
|
+
if (sph3.isEmpty(a)) return false;
|
|
60
|
+
|
|
61
61
|
let x = p[0] - a[0],
|
|
62
62
|
y = p[1] - a[1],
|
|
63
63
|
z = p[2] - a[2];
|
|
@@ -79,9 +79,9 @@ sph3.copy = vec4.copy;
|
|
|
79
79
|
*
|
|
80
80
|
* @returns {sph3}
|
|
81
81
|
*/
|
|
82
|
-
sph3.create = function()
|
|
83
|
-
{
|
|
84
|
-
return new Float32Array([ 0, 0, 0, -1 ]);
|
|
82
|
+
sph3.create = function()
|
|
83
|
+
{
|
|
84
|
+
return new Float32Array([ 0, 0, 0, -1 ]);
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
/**
|
|
@@ -91,10 +91,10 @@ sph3.create = function()
|
|
|
91
91
|
* @param {sph3} b
|
|
92
92
|
* @returns {number}
|
|
93
93
|
*/
|
|
94
|
-
sph3.distance = function(a, b)
|
|
95
|
-
{
|
|
96
|
-
if (sph3.isEmpty(a) || sph3.isEmpty(b)) return Infinity;
|
|
97
|
-
|
|
94
|
+
sph3.distance = function(a, b)
|
|
95
|
+
{
|
|
96
|
+
if (sph3.isEmpty(a) || sph3.isEmpty(b)) return Infinity;
|
|
97
|
+
|
|
98
98
|
let x = b[0] - a[0],
|
|
99
99
|
y = b[1] - a[1],
|
|
100
100
|
z = b[2] - a[2],
|
|
@@ -110,10 +110,10 @@ sph3.distance = function(a, b)
|
|
|
110
110
|
* @param {vec3} p
|
|
111
111
|
* @returns {number}
|
|
112
112
|
*/
|
|
113
|
-
sph3.distanceToPoint = function(a, p)
|
|
114
|
-
{
|
|
115
|
-
if (sph3.isEmpty(a)) return Infinity;
|
|
116
|
-
|
|
113
|
+
sph3.distanceToPoint = function(a, p)
|
|
114
|
+
{
|
|
115
|
+
if (sph3.isEmpty(a)) return Infinity;
|
|
116
|
+
|
|
117
117
|
let x = p[0] - a[0],
|
|
118
118
|
y = p[1] - a[1],
|
|
119
119
|
z = p[2] - a[2];
|
|
@@ -126,12 +126,12 @@ sph3.distanceToPoint = function(a, p)
|
|
|
126
126
|
* @param {sph3} a
|
|
127
127
|
* @returns {sph3} a
|
|
128
128
|
*/
|
|
129
|
-
sph3.empty = function(a)
|
|
130
|
-
{
|
|
129
|
+
sph3.empty = function(a)
|
|
130
|
+
{
|
|
131
131
|
a[0] = 0;
|
|
132
132
|
a[1] = 0;
|
|
133
133
|
a[2] = 0;
|
|
134
|
-
a[3] = -1;
|
|
134
|
+
a[3] = -1;
|
|
135
135
|
return a;
|
|
136
136
|
};
|
|
137
137
|
|
|
@@ -189,10 +189,10 @@ sph3.extract = pln.extract;
|
|
|
189
189
|
* @param {box3} b
|
|
190
190
|
* @return {sph3} out
|
|
191
191
|
*/
|
|
192
|
-
sph3.fromBox3 = function(out, b)
|
|
193
|
-
{
|
|
194
|
-
if (box3.isEmpty(b)) return sph3.empty(out);
|
|
195
|
-
|
|
192
|
+
sph3.fromBox3 = function(out, b)
|
|
193
|
+
{
|
|
194
|
+
if (box3.isEmpty(b)) return sph3.empty(out);
|
|
195
|
+
|
|
196
196
|
let sX = b[3] - b[0],
|
|
197
197
|
sY = b[4] - b[1],
|
|
198
198
|
sZ = b[5] - b[2];
|
|
@@ -235,9 +235,9 @@ sph3.fromBounds = function(out, min, max)
|
|
|
235
235
|
* @param {number} r
|
|
236
236
|
* @returns {sph3} out
|
|
237
237
|
*/
|
|
238
|
-
sph3.fromPositionRadius = pln.fromNormalConstant;
|
|
239
|
-
|
|
240
|
-
sph3.from = sph3.fromPositionRadius;
|
|
238
|
+
sph3.fromPositionRadius = pln.fromNormalConstant;
|
|
239
|
+
|
|
240
|
+
sph3.from = sph3.fromPositionRadius;
|
|
241
241
|
|
|
242
242
|
/**
|
|
243
243
|
* Sets a sphere from a mat4's translation and a given radius
|
|
@@ -247,12 +247,12 @@ sph3.from = sph3.fromPositionRadius;
|
|
|
247
247
|
* @param {number} radius
|
|
248
248
|
* @returns {sph3} out
|
|
249
249
|
*/
|
|
250
|
-
sph3.fromTranslationRadius = function(out, a, radius)
|
|
251
|
-
{
|
|
252
|
-
const offset = a.length >= 15 ? 12 : 0;
|
|
253
|
-
out[0] = a[offset];
|
|
254
|
-
out[1] = a[offset + 1];
|
|
255
|
-
out[2] = a[offset + 2];
|
|
250
|
+
sph3.fromTranslationRadius = function(out, a, radius)
|
|
251
|
+
{
|
|
252
|
+
const offset = a.length >= 15 ? 12 : 0;
|
|
253
|
+
out[0] = a[offset];
|
|
254
|
+
out[1] = a[offset + 1];
|
|
255
|
+
out[2] = a[offset + 2];
|
|
256
256
|
out[3] = radius;
|
|
257
257
|
return out;
|
|
258
258
|
};
|
|
@@ -286,11 +286,11 @@ let aPosition,
|
|
|
286
286
|
* @param {sph3} b
|
|
287
287
|
* @returns {sph3} out
|
|
288
288
|
*/
|
|
289
|
-
sph3.union = function(out, a, b)
|
|
290
|
-
{
|
|
291
|
-
if (sph3.isEmpty(a)) return sph3.copy(out, b);
|
|
292
|
-
if (sph3.isEmpty(b)) return sph3.copy(out, a);
|
|
293
|
-
|
|
289
|
+
sph3.union = function(out, a, b)
|
|
290
|
+
{
|
|
291
|
+
if (sph3.isEmpty(a)) return sph3.copy(out, b);
|
|
292
|
+
if (sph3.isEmpty(b)) return sph3.copy(out, a);
|
|
293
|
+
|
|
294
294
|
if (!aPosition)
|
|
295
295
|
{
|
|
296
296
|
aPosition = vec3.create();
|
|
@@ -331,11 +331,11 @@ sph3.union = function(out, a, b)
|
|
|
331
331
|
* @param {Number} radius
|
|
332
332
|
* @returns {sph3}
|
|
333
333
|
*/
|
|
334
|
-
sph3.unionPositionRadius = function(out, a, position, radius)
|
|
335
|
-
{
|
|
336
|
-
if (!sph3_0) sph3_0 = sph3.create();
|
|
337
|
-
return sph3.union(out, a, sph3.fromPositionRadius(sph3_0, position, radius));
|
|
338
|
-
};
|
|
334
|
+
sph3.unionPositionRadius = function(out, a, position, radius)
|
|
335
|
+
{
|
|
336
|
+
if (!sph3_0) sph3_0 = sph3.create();
|
|
337
|
+
return sph3.union(out, a, sph3.fromPositionRadius(sph3_0, position, radius));
|
|
338
|
+
};
|
|
339
339
|
|
|
340
340
|
/**
|
|
341
341
|
* Gets a point clamped to the sphere
|
|
@@ -346,14 +346,14 @@ sph3.unionPositionRadius = function(out, a, position, radius)
|
|
|
346
346
|
* @param {vec3} p
|
|
347
347
|
* @returns {vec3} out
|
|
348
348
|
*/
|
|
349
|
-
sph3.getClampedPoint = function(out, a, p)
|
|
350
|
-
{
|
|
349
|
+
sph3.getClampedPoint = function(out, a, p)
|
|
350
|
+
{
|
|
351
351
|
out[0] = p[0];
|
|
352
352
|
out[1] = p[1];
|
|
353
|
-
out[2] = p[2];
|
|
354
|
-
|
|
355
|
-
if (sph3.isEmpty(a)) return out;
|
|
356
|
-
|
|
353
|
+
out[2] = p[2];
|
|
354
|
+
|
|
355
|
+
if (sph3.isEmpty(a)) return out;
|
|
356
|
+
|
|
357
357
|
let x = a[0] - p[0],
|
|
358
358
|
y = a[1] - p[1],
|
|
359
359
|
z = a[2] - p[2];
|
|
@@ -407,10 +407,10 @@ sph3.getPosition = pln.getNormal;
|
|
|
407
407
|
* @param {sph3} b
|
|
408
408
|
* @returns {boolean}
|
|
409
409
|
*/
|
|
410
|
-
sph3.intersectsSph3 = function(a, b)
|
|
411
|
-
{
|
|
412
|
-
if (sph3.isEmpty(a) || sph3.isEmpty(b)) return false;
|
|
413
|
-
|
|
410
|
+
sph3.intersectsSph3 = function(a, b)
|
|
411
|
+
{
|
|
412
|
+
if (sph3.isEmpty(a) || sph3.isEmpty(b)) return false;
|
|
413
|
+
|
|
414
414
|
let x = b[0] - a[0],
|
|
415
415
|
y = b[1] - a[1],
|
|
416
416
|
z = b[2] - a[2];
|
|
@@ -426,9 +426,9 @@ sph3.intersectsSph3 = function(a, b)
|
|
|
426
426
|
* @param {box3} b
|
|
427
427
|
* @returns {boolean}
|
|
428
428
|
*/
|
|
429
|
-
sph3.intersectsBox3 = function(a, b)
|
|
430
|
-
{
|
|
431
|
-
return !sph3.isEmpty(a) && !box3.isEmpty(b) && box3.intersectsSph3(b, a);
|
|
429
|
+
sph3.intersectsBox3 = function(a, b)
|
|
430
|
+
{
|
|
431
|
+
return !sph3.isEmpty(a) && !box3.isEmpty(b) && box3.intersectsSph3(b, a);
|
|
432
432
|
};
|
|
433
433
|
|
|
434
434
|
/**
|
|
@@ -439,10 +439,10 @@ sph3.intersectsBox3 = function(a, b)
|
|
|
439
439
|
* @param {vec3} max
|
|
440
440
|
* @returns {boolean}
|
|
441
441
|
*/
|
|
442
|
-
sph3.intersectsBounds = function(a, min, max)
|
|
443
|
-
{
|
|
444
|
-
if (sph3.isEmpty(a) || box3.bounds.isEmpty(min, max)) return false;
|
|
445
|
-
|
|
442
|
+
sph3.intersectsBounds = function(a, min, max)
|
|
443
|
+
{
|
|
444
|
+
if (sph3.isEmpty(a) || box3.bounds.isEmpty(min, max)) return false;
|
|
445
|
+
|
|
446
446
|
let x = Math.max(min[0], Math.min(max[0], a[0])) - a[0],
|
|
447
447
|
y = Math.max(min[1], Math.min(max[1], a[1])) - a[1],
|
|
448
448
|
z = Math.max(min[2], Math.min(max[2], a[2])) - a[2];
|
|
@@ -458,10 +458,10 @@ sph3.intersectsBounds = function(a, min, max)
|
|
|
458
458
|
* @param {number} r
|
|
459
459
|
* @returns {boolean}
|
|
460
460
|
*/
|
|
461
|
-
sph3.intersectsPositionRadius = function(a, p, r)
|
|
462
|
-
{
|
|
463
|
-
if (sph3.isEmpty(a) || r < 0) return false;
|
|
464
|
-
|
|
461
|
+
sph3.intersectsPositionRadius = function(a, p, r)
|
|
462
|
+
{
|
|
463
|
+
if (sph3.isEmpty(a) || r < 0) return false;
|
|
464
|
+
|
|
465
465
|
let x = p[0] - a[0],
|
|
466
466
|
y = p[1] - a[1],
|
|
467
467
|
z = p[2] - a[2];
|
|
@@ -490,15 +490,15 @@ sph3.intersectsPln = function(a, p)
|
|
|
490
490
|
* @param {number} c - plane constant
|
|
491
491
|
* @returns {boolean}
|
|
492
492
|
*/
|
|
493
|
-
sph3.intersectsNormalConstant = function(a, n, c)
|
|
494
|
-
{
|
|
495
|
-
if (sph3.isEmpty(a)) return false;
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
distance = a[0] * n[0] + a[1] * n[1] + a[2] * n[2] + c,
|
|
499
|
-
normalLength = Math.hypot(n[0], n[1], n[2]);
|
|
500
|
-
return Math.abs(distance) <= a[3] * normalLength;
|
|
501
|
-
};
|
|
493
|
+
sph3.intersectsNormalConstant = function(a, n, c)
|
|
494
|
+
{
|
|
495
|
+
if (sph3.isEmpty(a)) return false;
|
|
496
|
+
|
|
497
|
+
const
|
|
498
|
+
distance = a[0] * n[0] + a[1] * n[1] + a[2] * n[2] + c,
|
|
499
|
+
normalLength = Math.hypot(n[0], n[1], n[2]);
|
|
500
|
+
return Math.abs(distance) <= a[3] * normalLength;
|
|
501
|
+
};
|
|
502
502
|
|
|
503
503
|
/**
|
|
504
504
|
* Checks if a sph3 is empty
|
|
@@ -506,9 +506,9 @@ sph3.intersectsNormalConstant = function(a, n, c)
|
|
|
506
506
|
* @param {sph3} a
|
|
507
507
|
* @returns {boolean}
|
|
508
508
|
*/
|
|
509
|
-
sph3.isEmpty = function(a)
|
|
510
|
-
{
|
|
511
|
-
return a[3] < 0;
|
|
509
|
+
sph3.isEmpty = function(a)
|
|
510
|
+
{
|
|
511
|
+
return a[3] < 0;
|
|
512
512
|
};
|
|
513
513
|
|
|
514
514
|
/**
|
|
@@ -549,10 +549,10 @@ sph3.setArray = vec4.setArray;
|
|
|
549
549
|
* @param {vec3} [position] - An optional center position
|
|
550
550
|
* @returns {sph3} out - the receiving sphere
|
|
551
551
|
*/
|
|
552
|
-
sph3.setPoints = function(out, points, position)
|
|
553
|
-
{
|
|
554
|
-
if (!points.length) return sph3.empty(out);
|
|
555
|
-
|
|
552
|
+
sph3.setPoints = function(out, points, position)
|
|
553
|
+
{
|
|
554
|
+
if (!points.length) return sph3.empty(out);
|
|
555
|
+
|
|
556
556
|
if (!box3_0) box3_0 = box3.create();
|
|
557
557
|
|
|
558
558
|
if (position)
|
|
@@ -591,16 +591,16 @@ sph3.setPoints = function(out, points, position)
|
|
|
591
591
|
* @param {sph3} b
|
|
592
592
|
* @returns {number}
|
|
593
593
|
*/
|
|
594
|
-
sph3.squaredDistance = function(a, b)
|
|
595
|
-
{
|
|
596
|
-
if (sph3.isEmpty(a) || sph3.isEmpty(b)) return Infinity;
|
|
597
|
-
|
|
594
|
+
sph3.squaredDistance = function(a, b)
|
|
595
|
+
{
|
|
596
|
+
if (sph3.isEmpty(a) || sph3.isEmpty(b)) return Infinity;
|
|
597
|
+
|
|
598
598
|
let x = b[0] - a[0],
|
|
599
599
|
y = b[1] - a[1],
|
|
600
|
-
z = b[2] - a[2],
|
|
601
|
-
distance = Math.sqrt(x * x + y * y + z * z) - (b[3] + a[3]);
|
|
602
|
-
|
|
603
|
-
return distance * distance;
|
|
600
|
+
z = b[2] - a[2],
|
|
601
|
+
distance = Math.sqrt(x * x + y * y + z * z) - (b[3] + a[3]);
|
|
602
|
+
|
|
603
|
+
return distance * distance;
|
|
604
604
|
};
|
|
605
605
|
|
|
606
606
|
/**
|
|
@@ -610,17 +610,17 @@ sph3.squaredDistance = function(a, b)
|
|
|
610
610
|
* @param {vec3} p
|
|
611
611
|
* @returns {number}
|
|
612
612
|
*/
|
|
613
|
-
sph3.squaredDistanceToPoint = function(a, p)
|
|
614
|
-
{
|
|
615
|
-
if (sph3.isEmpty(a)) return Infinity;
|
|
616
|
-
|
|
617
|
-
let x = p[0] - a[0],
|
|
618
|
-
y = p[1] - a[1],
|
|
619
|
-
z = p[2] - a[2],
|
|
620
|
-
distance = Math.sqrt(x * x + y * y + z * z) - a[3];
|
|
621
|
-
|
|
622
|
-
return distance * distance;
|
|
623
|
-
};
|
|
613
|
+
sph3.squaredDistanceToPoint = function(a, p)
|
|
614
|
+
{
|
|
615
|
+
if (sph3.isEmpty(a)) return Infinity;
|
|
616
|
+
|
|
617
|
+
let x = p[0] - a[0],
|
|
618
|
+
y = p[1] - a[1],
|
|
619
|
+
z = p[2] - a[2],
|
|
620
|
+
distance = Math.sqrt(x * x + y * y + z * z) - a[3];
|
|
621
|
+
|
|
622
|
+
return distance * distance;
|
|
623
|
+
};
|
|
624
624
|
|
|
625
625
|
/**
|
|
626
626
|
* Sets an array at an optional offset, with the values of a sph3
|
|
@@ -669,10 +669,10 @@ sph3.toPositionRadius = function(a, position)
|
|
|
669
669
|
* @param {mat4} m - the matrix to transform by
|
|
670
670
|
* @returns {sph3}
|
|
671
671
|
*/
|
|
672
|
-
sph3.transformMat4 = function(out, a, m)
|
|
673
|
-
{
|
|
674
|
-
if (sph3.isEmpty(a)) return sph3.empty(out);
|
|
675
|
-
|
|
672
|
+
sph3.transformMat4 = function(out, a, m)
|
|
673
|
+
{
|
|
674
|
+
if (sph3.isEmpty(a)) return sph3.empty(out);
|
|
675
|
+
|
|
676
676
|
let x = a[0],
|
|
677
677
|
y = a[1],
|
|
678
678
|
z = a[2];
|
|
@@ -697,58 +697,58 @@ sph3.transformMat4 = function(out, a, m)
|
|
|
697
697
|
* @param {vec3} v - the vector to translate with
|
|
698
698
|
* @returns {sph3}
|
|
699
699
|
*/
|
|
700
|
-
sph3.translate = function(out, a, v)
|
|
701
|
-
{
|
|
702
|
-
out[0] = a[0] + v[0];
|
|
703
|
-
out[1] = a[1] + v[1];
|
|
704
|
-
out[2] = a[2] + v[2];
|
|
705
|
-
out[3] = a[3];
|
|
706
|
-
return out;
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
export const {
|
|
710
|
-
alloc,
|
|
711
|
-
unalloc,
|
|
712
|
-
$position,
|
|
713
|
-
clone,
|
|
714
|
-
containsPoint,
|
|
715
|
-
copy,
|
|
716
|
-
create,
|
|
717
|
-
distance,
|
|
718
|
-
distanceToPoint,
|
|
719
|
-
empty,
|
|
720
|
-
equals,
|
|
721
|
-
equalsPositionRadius,
|
|
722
|
-
exactEquals,
|
|
723
|
-
exactEqualsPositionRadius,
|
|
724
|
-
extract,
|
|
725
|
-
fromBox3,
|
|
726
|
-
fromBounds,
|
|
727
|
-
fromPositionRadius,
|
|
728
|
-
from,
|
|
729
|
-
fromTranslationRadius,
|
|
730
|
-
fromMat4,
|
|
731
|
-
union,
|
|
732
|
-
unionPositionRadius,
|
|
733
|
-
getClampedPoint,
|
|
734
|
-
getPointFromLongLat,
|
|
735
|
-
getPosition,
|
|
736
|
-
intersectsSph3,
|
|
737
|
-
intersectsBox3,
|
|
738
|
-
intersectsBounds,
|
|
739
|
-
intersectsPositionRadius,
|
|
740
|
-
intersectsPln,
|
|
741
|
-
intersectsNormalConstant,
|
|
742
|
-
isEmpty,
|
|
743
|
-
radius,
|
|
744
|
-
set,
|
|
745
|
-
setArray,
|
|
746
|
-
setPoints,
|
|
747
|
-
squaredDistance,
|
|
748
|
-
squaredDistanceToPoint,
|
|
749
|
-
toArray,
|
|
750
|
-
toBounds,
|
|
751
|
-
toPositionRadius,
|
|
752
|
-
transformMat4,
|
|
753
|
-
translate
|
|
754
|
-
} = sph3;
|
|
700
|
+
sph3.translate = function(out, a, v)
|
|
701
|
+
{
|
|
702
|
+
out[0] = a[0] + v[0];
|
|
703
|
+
out[1] = a[1] + v[1];
|
|
704
|
+
out[2] = a[2] + v[2];
|
|
705
|
+
out[3] = a[3];
|
|
706
|
+
return out;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
export const {
|
|
710
|
+
alloc,
|
|
711
|
+
unalloc,
|
|
712
|
+
$position,
|
|
713
|
+
clone,
|
|
714
|
+
containsPoint,
|
|
715
|
+
copy,
|
|
716
|
+
create,
|
|
717
|
+
distance,
|
|
718
|
+
distanceToPoint,
|
|
719
|
+
empty,
|
|
720
|
+
equals,
|
|
721
|
+
equalsPositionRadius,
|
|
722
|
+
exactEquals,
|
|
723
|
+
exactEqualsPositionRadius,
|
|
724
|
+
extract,
|
|
725
|
+
fromBox3,
|
|
726
|
+
fromBounds,
|
|
727
|
+
fromPositionRadius,
|
|
728
|
+
from,
|
|
729
|
+
fromTranslationRadius,
|
|
730
|
+
fromMat4,
|
|
731
|
+
union,
|
|
732
|
+
unionPositionRadius,
|
|
733
|
+
getClampedPoint,
|
|
734
|
+
getPointFromLongLat,
|
|
735
|
+
getPosition,
|
|
736
|
+
intersectsSph3,
|
|
737
|
+
intersectsBox3,
|
|
738
|
+
intersectsBounds,
|
|
739
|
+
intersectsPositionRadius,
|
|
740
|
+
intersectsPln,
|
|
741
|
+
intersectsNormalConstant,
|
|
742
|
+
isEmpty,
|
|
743
|
+
radius,
|
|
744
|
+
set,
|
|
745
|
+
setArray,
|
|
746
|
+
setPoints,
|
|
747
|
+
squaredDistance,
|
|
748
|
+
squaredDistanceToPoint,
|
|
749
|
+
toArray,
|
|
750
|
+
toBounds,
|
|
751
|
+
toPositionRadius,
|
|
752
|
+
transformMat4,
|
|
753
|
+
translate
|
|
754
|
+
} = sph3;
|