@carbonenginejs/runtime-utils 0.1.2 → 0.1.4
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 +154 -0
- package/docs/const-kb.md +85 -87
- package/docs/core-types/DECORATOR-TODOS.md +25 -25
- package/docs/core-types/README.md +241 -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 +117 -117
- 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 +1744 -1463
- 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 +141 -23
- 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 -1188
- 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/ray3.js
CHANGED
|
@@ -10,31 +10,31 @@ import { mat3 } from "./mat3.js";
|
|
|
10
10
|
* @typedef {Float32Array} ray3
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export const ray3 = {};
|
|
14
|
-
|
|
15
|
-
function getAtParameter(out, a, t)
|
|
16
|
-
{
|
|
17
|
-
out[0] = a[0] + a[3] * t;
|
|
18
|
-
out[1] = a[1] + a[4] * t;
|
|
19
|
-
out[2] = a[2] + a[5] * t;
|
|
20
|
-
return out;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Allocates a pooled ray3
|
|
25
|
-
* @returns {Float32Array|ray3}
|
|
26
|
-
*/
|
|
27
|
-
ray3.alloc = box3.alloc;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Unallocates a pooled ray3
|
|
31
|
-
* @param {ray3|Float32Array} a
|
|
32
|
-
*/
|
|
33
|
-
ray3.unalloc = box3.unalloc;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Gets a subarray of a ray3's origin vector
|
|
37
|
-
* @property {box3} a
|
|
13
|
+
export const ray3 = {};
|
|
14
|
+
|
|
15
|
+
function getAtParameter(out, a, t)
|
|
16
|
+
{
|
|
17
|
+
out[0] = a[0] + a[3] * t;
|
|
18
|
+
out[1] = a[1] + a[4] * t;
|
|
19
|
+
out[2] = a[2] + a[5] * t;
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Allocates a pooled ray3
|
|
25
|
+
* @returns {Float32Array|ray3}
|
|
26
|
+
*/
|
|
27
|
+
ray3.alloc = box3.alloc;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Unallocates a pooled ray3
|
|
31
|
+
* @param {ray3|Float32Array} a
|
|
32
|
+
*/
|
|
33
|
+
ray3.unalloc = box3.unalloc;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Gets a subarray of a ray3's origin vector
|
|
37
|
+
* @property {box3} a
|
|
38
38
|
* @returns {TypedArray}
|
|
39
39
|
*/
|
|
40
40
|
ray3.$origin = box3.$min;
|
|
@@ -86,10 +86,10 @@ ray3.copyDirection = box3.copyMax;
|
|
|
86
86
|
*
|
|
87
87
|
* @returns {ray3}
|
|
88
88
|
*/
|
|
89
|
-
ray3.create = function ()
|
|
90
|
-
{
|
|
91
|
-
return new Float32Array(6);
|
|
92
|
-
};
|
|
89
|
+
ray3.create = function ()
|
|
90
|
+
{
|
|
91
|
+
return new Float32Array(6);
|
|
92
|
+
};
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* Gets the distance from a ray3 to a point
|
|
@@ -112,18 +112,18 @@ ray3.distance = function (a, p)
|
|
|
112
112
|
* @param {number} c - plane constant
|
|
113
113
|
* @returns {null|number} - distance
|
|
114
114
|
*/
|
|
115
|
-
ray3.distanceNormalConstant = function (a, n, c)
|
|
116
|
-
{
|
|
115
|
+
ray3.distanceNormalConstant = function (a, n, c)
|
|
116
|
+
{
|
|
117
117
|
let den = n[0] * a[3] + n[1] * a[4] + n[2] * a[5];
|
|
118
118
|
let dist = (a[0] * n[0] + a[1] * n[1] + a[2] * n[2]) + c;
|
|
119
119
|
if (den === 0)
|
|
120
120
|
{
|
|
121
121
|
if (dist === 0) return 0;
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let t = -dist / den;
|
|
126
|
-
return t >= 0 ? t * Math.hypot(a[3], a[4], a[5]) : null;
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let t = -dist / den;
|
|
126
|
+
return t >= 0 ? t * Math.hypot(a[3], a[4], a[5]) : null;
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
/**
|
|
@@ -134,9 +134,9 @@ ray3.distanceNormalConstant = function (a, n, c)
|
|
|
134
134
|
* @param {pln} p - plane to measure distance to
|
|
135
135
|
* @returns {null|Number} - distance
|
|
136
136
|
*/
|
|
137
|
-
ray3.distancePln = function (a, p)
|
|
138
|
-
{
|
|
139
|
-
return ray3.distanceNormalConstant(a, p, p[3]);
|
|
137
|
+
ray3.distancePln = function (a, p)
|
|
138
|
+
{
|
|
139
|
+
return ray3.distanceNormalConstant(a, p, p[3]);
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -178,23 +178,23 @@ ray3.exactEquals = box3.exactEquals;
|
|
|
178
178
|
ray3.exactEqualsOriginDestination = box3.exactEqualsBounds;
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
|
-
* Sets a ray3 from origin and direction
|
|
181
|
+
* Sets a ray3 from origin and direction
|
|
182
182
|
*
|
|
183
183
|
* @param {ray3} out
|
|
184
184
|
* @param {vec3} o
|
|
185
185
|
* @param {vec3} d
|
|
186
186
|
* @returns {ray3} out
|
|
187
187
|
*/
|
|
188
|
-
ray3.from = function (out, origin, direction)
|
|
189
|
-
{
|
|
190
|
-
out[0] = origin[0];
|
|
191
|
-
out[1] = origin[1];
|
|
192
|
-
out[2] = origin[2];
|
|
193
|
-
out[3] = direction[0];
|
|
194
|
-
out[4] = direction[1];
|
|
195
|
-
out[5] = direction[2];
|
|
196
|
-
return direction[0] || direction[1] || direction[2] ? ray3.normalize(out, out) : out;
|
|
197
|
-
};
|
|
188
|
+
ray3.from = function (out, origin, direction)
|
|
189
|
+
{
|
|
190
|
+
out[0] = origin[0];
|
|
191
|
+
out[1] = origin[1];
|
|
192
|
+
out[2] = origin[2];
|
|
193
|
+
out[3] = direction[0];
|
|
194
|
+
out[4] = direction[1];
|
|
195
|
+
out[5] = direction[2];
|
|
196
|
+
return direction[0] || direction[1] || direction[2] ? ray3.normalize(out, out) : out;
|
|
197
|
+
};
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
200
|
* Sets a ray3 from an array at an optional offset
|
|
@@ -204,11 +204,11 @@ ray3.from = function (out, origin, direction)
|
|
|
204
204
|
* @param {number} [index=0]
|
|
205
205
|
* @returns {ray3}
|
|
206
206
|
*/
|
|
207
|
-
ray3.fromArray = function (out, array, offset = 0)
|
|
208
|
-
{
|
|
209
|
-
box3.fromArray(out, array, offset);
|
|
210
|
-
return out[3] || out[4] || out[5] ? ray3.normalize(out, out) : out;
|
|
211
|
-
};
|
|
207
|
+
ray3.fromArray = function (out, array, offset = 0)
|
|
208
|
+
{
|
|
209
|
+
box3.fromArray(out, array, offset);
|
|
210
|
+
return out[3] || out[4] || out[5] ? ray3.normalize(out, out) : out;
|
|
211
|
+
};
|
|
212
212
|
|
|
213
213
|
/**
|
|
214
214
|
* Sets a ray 3 from start and end vectors
|
|
@@ -319,11 +319,11 @@ ray3.unproject = function (out, coords, invProjView, viewport)
|
|
|
319
319
|
* @param {number} t - distance along the ray3
|
|
320
320
|
* @returns {vec3} out - receiving vec3
|
|
321
321
|
*/
|
|
322
|
-
ray3.get = function (out, a, t)
|
|
323
|
-
{
|
|
324
|
-
const length = Math.hypot(a[3], a[4], a[5]);
|
|
325
|
-
return length === 0 ? vec3.set(out, a[0], a[1], a[2]) :
|
|
326
|
-
getAtParameter(out, a, t / length);
|
|
322
|
+
ray3.get = function (out, a, t)
|
|
323
|
+
{
|
|
324
|
+
const length = Math.hypot(a[3], a[4], a[5]);
|
|
325
|
+
return length === 0 ? vec3.set(out, a[0], a[1], a[2]) :
|
|
326
|
+
getAtParameter(out, a, t / length);
|
|
327
327
|
};
|
|
328
328
|
|
|
329
329
|
/**
|
|
@@ -344,15 +344,15 @@ ray3.getDirection = box3.getMax;
|
|
|
344
344
|
* @param {vec3} p - point to compare
|
|
345
345
|
* @returns {vec3} out - receiving vec3
|
|
346
346
|
*/
|
|
347
|
-
ray3.getClosestPointToPoint = function (out, a, p)
|
|
348
|
-
{
|
|
347
|
+
ray3.getClosestPointToPoint = function (out, a, p)
|
|
348
|
+
{
|
|
349
349
|
let x = p[0] - a[0],
|
|
350
350
|
y = p[1] - a[1],
|
|
351
351
|
z = p[2] - a[2];
|
|
352
352
|
|
|
353
|
-
const directionLengthSquared = a[3] * a[3] + a[4] * a[4] + a[5] * a[5];
|
|
354
|
-
let dirDist = directionLengthSquared === 0 ? 0 :
|
|
355
|
-
(x * a[3] + y * a[4] + z * a[5]) / directionLengthSquared;
|
|
353
|
+
const directionLengthSquared = a[3] * a[3] + a[4] * a[4] + a[5] * a[5];
|
|
354
|
+
let dirDist = directionLengthSquared === 0 ? 0 :
|
|
355
|
+
(x * a[3] + y * a[4] + z * a[5]) / directionLengthSquared;
|
|
356
356
|
|
|
357
357
|
if (dirDist < 0)
|
|
358
358
|
{
|
|
@@ -362,7 +362,7 @@ ray3.getClosestPointToPoint = function (out, a, p)
|
|
|
362
362
|
}
|
|
363
363
|
else
|
|
364
364
|
{
|
|
365
|
-
getAtParameter(out, a, dirDist);
|
|
365
|
+
getAtParameter(out, a, dirDist);
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
return out;
|
|
@@ -431,7 +431,7 @@ ray3.getIntersectBounds = function (out, a, min, max)
|
|
|
431
431
|
if (tzMax < tMax || tMax !== tMax) tMax = tzMax;
|
|
432
432
|
if (tMax < 0) return null;
|
|
433
433
|
|
|
434
|
-
return getAtParameter(out, a, tMin >= 0 ? tMin : tMax);
|
|
434
|
+
return getAtParameter(out, a, tMin >= 0 ? tMin : tMax);
|
|
435
435
|
};
|
|
436
436
|
|
|
437
437
|
/**
|
|
@@ -559,7 +559,7 @@ ray3.getIntersectVertices = (function ()
|
|
|
559
559
|
let QdN = -sign * vec3.dot(diff, n);
|
|
560
560
|
if (QdN < 0) return null;
|
|
561
561
|
|
|
562
|
-
return getAtParameter(out, a, QdN / DdN);
|
|
562
|
+
return getAtParameter(out, a, QdN / DdN);
|
|
563
563
|
};
|
|
564
564
|
})();
|
|
565
565
|
|
|
@@ -627,33 +627,33 @@ ray3.getIntersectPositionRadius = (function ()
|
|
|
627
627
|
* @param {sph3} s - sphere
|
|
628
628
|
* @returns {(null|vec3)} [out] - null or receiving vec3
|
|
629
629
|
*/
|
|
630
|
-
ray3.getIntersectSph3 = function (out, a, s)
|
|
631
|
-
{
|
|
632
|
-
if (s[3] < 0) return null;
|
|
633
|
-
|
|
634
|
-
const
|
|
635
|
-
x = a[0] - s[0],
|
|
636
|
-
y = a[1] - s[1],
|
|
637
|
-
z = a[2] - s[2],
|
|
638
|
-
directionLengthSquared = a[3] * a[3] + a[4] * a[4] + a[5] * a[5];
|
|
639
|
-
|
|
640
|
-
if (directionLengthSquared === 0) return null;
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
directionDotOffset = a[3] * x + a[4] * y + a[5] * z,
|
|
644
|
-
constant = x * x + y * y + z * z - s[3] * s[3],
|
|
645
|
-
discriminant = directionDotOffset * directionDotOffset - directionLengthSquared * constant;
|
|
646
|
-
|
|
647
|
-
if (discriminant < 0) return null;
|
|
648
|
-
|
|
649
|
-
const
|
|
650
|
-
root = Math.sqrt(discriminant),
|
|
651
|
-
t0 = (-directionDotOffset - root) / directionLengthSquared,
|
|
652
|
-
t1 = (-directionDotOffset + root) / directionLengthSquared;
|
|
630
|
+
ray3.getIntersectSph3 = function (out, a, s)
|
|
631
|
+
{
|
|
632
|
+
if (s[3] < 0) return null;
|
|
633
|
+
|
|
634
|
+
const
|
|
635
|
+
x = a[0] - s[0],
|
|
636
|
+
y = a[1] - s[1],
|
|
637
|
+
z = a[2] - s[2],
|
|
638
|
+
directionLengthSquared = a[3] * a[3] + a[4] * a[4] + a[5] * a[5];
|
|
639
|
+
|
|
640
|
+
if (directionLengthSquared === 0) return null;
|
|
641
|
+
|
|
642
|
+
const
|
|
643
|
+
directionDotOffset = a[3] * x + a[4] * y + a[5] * z,
|
|
644
|
+
constant = x * x + y * y + z * z - s[3] * s[3],
|
|
645
|
+
discriminant = directionDotOffset * directionDotOffset - directionLengthSquared * constant;
|
|
646
|
+
|
|
647
|
+
if (discriminant < 0) return null;
|
|
648
|
+
|
|
649
|
+
const
|
|
650
|
+
root = Math.sqrt(discriminant),
|
|
651
|
+
t0 = (-directionDotOffset - root) / directionLengthSquared,
|
|
652
|
+
t1 = (-directionDotOffset + root) / directionLengthSquared;
|
|
653
653
|
|
|
654
654
|
if (t0 < 0 && t1 < 0) return null;
|
|
655
|
-
if (t0 < 0) return getAtParameter(out, a, t1);
|
|
656
|
-
return getAtParameter(out, a, t0);
|
|
655
|
+
if (t0 < 0) return getAtParameter(out, a, t1);
|
|
656
|
+
return getAtParameter(out, a, t0);
|
|
657
657
|
};
|
|
658
658
|
|
|
659
659
|
|
|
@@ -679,7 +679,7 @@ ray3.intersectsBox3 = (function ()
|
|
|
679
679
|
return function (a, b)
|
|
680
680
|
{
|
|
681
681
|
if (!vec3_0) vec3_0 = vec3.create();
|
|
682
|
-
return ray3.getIntersectBox3(vec3_0, a, b) !== null;
|
|
682
|
+
return ray3.getIntersectBox3(vec3_0, a, b) !== null;
|
|
683
683
|
};
|
|
684
684
|
})();
|
|
685
685
|
|
|
@@ -801,12 +801,12 @@ ray3.normalize = function (out, a)
|
|
|
801
801
|
out[4] = y * len;
|
|
802
802
|
out[5] = z * len;
|
|
803
803
|
}
|
|
804
|
-
else
|
|
805
|
-
{
|
|
806
|
-
out[3] = 0;
|
|
807
|
-
out[4] = 0;
|
|
808
|
-
out[5] = 0;
|
|
809
|
-
throw new Error("Normalization error");
|
|
804
|
+
else
|
|
805
|
+
{
|
|
806
|
+
out[3] = 0;
|
|
807
|
+
out[4] = 0;
|
|
808
|
+
out[5] = 0;
|
|
809
|
+
throw new Error("Normalization error");
|
|
810
810
|
}
|
|
811
811
|
|
|
812
812
|
return out;
|
|
@@ -820,13 +820,13 @@ ray3.normalize = function (out, a)
|
|
|
820
820
|
* @param {number} t - distance along the ray3
|
|
821
821
|
* @returns {ray3} - receiving ray3
|
|
822
822
|
*/
|
|
823
|
-
ray3.recast = function (out, a, t)
|
|
824
|
-
{
|
|
825
|
-
const length = Math.hypot(a[3], a[4], a[5]);
|
|
826
|
-
const scale = length === 0 ? 0 : t / length;
|
|
827
|
-
out[0] = a[0] + (a[3] * scale);
|
|
828
|
-
out[1] = a[1] + (a[4] * scale);
|
|
829
|
-
out[2] = a[2] + (a[5] * scale);
|
|
823
|
+
ray3.recast = function (out, a, t)
|
|
824
|
+
{
|
|
825
|
+
const length = Math.hypot(a[3], a[4], a[5]);
|
|
826
|
+
const scale = length === 0 ? 0 : t / length;
|
|
827
|
+
out[0] = a[0] + (a[3] * scale);
|
|
828
|
+
out[1] = a[1] + (a[4] * scale);
|
|
829
|
+
out[2] = a[2] + (a[5] * scale);
|
|
830
830
|
out[3] = a[3];
|
|
831
831
|
out[4] = a[4];
|
|
832
832
|
out[5] = a[5];
|
|
@@ -841,11 +841,11 @@ ray3.recast = function (out, a, t)
|
|
|
841
841
|
* @param {vec3} endProp
|
|
842
842
|
* @returns {ray3} out
|
|
843
843
|
*/
|
|
844
|
-
ray3.set = function (out, originX, originY, originZ, directionX, directionY, directionZ)
|
|
845
|
-
{
|
|
846
|
-
box3.set(out, originX, originY, originZ, directionX, directionY, directionZ);
|
|
847
|
-
return directionX || directionY || directionZ ? ray3.normalize(out, out) : out;
|
|
848
|
-
};
|
|
844
|
+
ray3.set = function (out, originX, originY, originZ, directionX, directionY, directionZ)
|
|
845
|
+
{
|
|
846
|
+
box3.set(out, originX, originY, originZ, directionX, directionY, directionZ);
|
|
847
|
+
return directionX || directionY || directionZ ? ray3.normalize(out, out) : out;
|
|
848
|
+
};
|
|
849
849
|
|
|
850
850
|
/**
|
|
851
851
|
* Ray3 generic sorting
|
|
@@ -884,16 +884,16 @@ ray3.squaredDistance = (function ()
|
|
|
884
884
|
vec3_0[1] = p[1] - a[1];
|
|
885
885
|
vec3_0[2] = p[2] - a[2];
|
|
886
886
|
|
|
887
|
-
const directionLengthSquared = a[3] * a[3] + a[4] * a[4] + a[5] * a[5];
|
|
888
|
-
let dirDist = directionLengthSquared === 0 ? 0 :
|
|
889
|
-
(vec3_0[0] * a[3] + vec3_0[1] * a[4] + vec3_0[2] * a[5]) / directionLengthSquared;
|
|
887
|
+
const directionLengthSquared = a[3] * a[3] + a[4] * a[4] + a[5] * a[5];
|
|
888
|
+
let dirDist = directionLengthSquared === 0 ? 0 :
|
|
889
|
+
(vec3_0[0] * a[3] + vec3_0[1] * a[4] + vec3_0[2] * a[5]) / directionLengthSquared;
|
|
890
890
|
if (dirDist < 0)
|
|
891
891
|
{
|
|
892
892
|
ray3.getOrigin(vec3_1, a);
|
|
893
893
|
return vec3.squaredDistance(vec3_1, p); // could just pass in the ray3
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
-
getAtParameter(vec3_0, a, dirDist);
|
|
896
|
+
getAtParameter(vec3_0, a, dirDist);
|
|
897
897
|
return vec3.squaredDistance(vec3_0, p);
|
|
898
898
|
};
|
|
899
899
|
})();
|
|
@@ -966,16 +966,16 @@ ray3.transformMat4 = function (out, a, m)
|
|
|
966
966
|
* @param {vec3} v
|
|
967
967
|
* @returns {ray3} out
|
|
968
968
|
*/
|
|
969
|
-
ray3.translate = function (out, a, v)
|
|
970
|
-
{
|
|
971
|
-
out[0] = a[0] + v[0];
|
|
972
|
-
out[1] = a[1] + v[1];
|
|
973
|
-
out[2] = a[2] + v[2];
|
|
974
|
-
out[3] = a[3];
|
|
975
|
-
out[4] = a[4];
|
|
976
|
-
out[5] = a[5];
|
|
977
|
-
return out;
|
|
978
|
-
};
|
|
969
|
+
ray3.translate = function (out, a, v)
|
|
970
|
+
{
|
|
971
|
+
out[0] = a[0] + v[0];
|
|
972
|
+
out[1] = a[1] + v[1];
|
|
973
|
+
out[2] = a[2] + v[2];
|
|
974
|
+
out[3] = a[3];
|
|
975
|
+
out[4] = a[4];
|
|
976
|
+
out[5] = a[5];
|
|
977
|
+
return out;
|
|
978
|
+
};
|
|
979
979
|
|
|
980
980
|
let viewPort;
|
|
981
981
|
|
|
@@ -989,8 +989,8 @@ let viewPort;
|
|
|
989
989
|
* @param {vec2} [css]
|
|
990
990
|
* @returns {ray3}
|
|
991
991
|
*/
|
|
992
|
-
ray3.fromEvent = function (ray, viewProjectionInverse, event, mouse, pixel, css)
|
|
993
|
-
{
|
|
992
|
+
ray3.fromEvent = function (ray, viewProjectionInverse, event, mouse, pixel, css)
|
|
993
|
+
{
|
|
994
994
|
if (!viewPort) viewPort = pln.create();
|
|
995
995
|
|
|
996
996
|
const
|
|
@@ -999,9 +999,9 @@ ray3.fromEvent = function (ray, viewProjectionInverse, event, mouse, pixel, css)
|
|
|
999
999
|
mX = event.clientX,
|
|
1000
1000
|
mY = event.clientY,
|
|
1001
1001
|
cX = mX - rect.left,
|
|
1002
|
-
cY = mY - rect.top,
|
|
1003
|
-
pX = cX * el.width / el.clientWidth,
|
|
1004
|
-
pY = el.height - cY * el.height / el.clientHeight - 1;
|
|
1002
|
+
cY = mY - rect.top,
|
|
1003
|
+
pX = cX * el.width / el.clientWidth,
|
|
1004
|
+
pY = el.height - cY * el.height / el.clientHeight - 1;
|
|
1005
1005
|
|
|
1006
1006
|
// Should this be a param?
|
|
1007
1007
|
viewPort[0] = 0;
|
|
@@ -1026,60 +1026,60 @@ ray3.fromEvent = function (ray, viewProjectionInverse, event, mouse, pixel, css)
|
|
|
1026
1026
|
css[0] = cX;
|
|
1027
1027
|
css[1] = cY;
|
|
1028
1028
|
}
|
|
1029
|
-
|
|
1030
|
-
return ray3.unproject(ray, [ pX, pY ], viewProjectionInverse, viewPort);
|
|
1031
|
-
};
|
|
1032
|
-
|
|
1033
|
-
export const {
|
|
1034
|
-
alloc,
|
|
1035
|
-
unalloc,
|
|
1036
|
-
$origin,
|
|
1037
|
-
$direction,
|
|
1038
|
-
clone,
|
|
1039
|
-
copy,
|
|
1040
|
-
copyOrigin,
|
|
1041
|
-
copyDirection,
|
|
1042
|
-
create,
|
|
1043
|
-
distance,
|
|
1044
|
-
distanceNormalConstant,
|
|
1045
|
-
distancePln,
|
|
1046
|
-
equals,
|
|
1047
|
-
equalsOriginDestination,
|
|
1048
|
-
exactEquals,
|
|
1049
|
-
exactEqualsOriginDestination,
|
|
1050
|
-
from,
|
|
1051
|
-
fromArray,
|
|
1052
|
-
fromStartEnd,
|
|
1053
|
-
fromMat4,
|
|
1054
|
-
fromPerspective,
|
|
1055
|
-
unproject,
|
|
1056
|
-
get,
|
|
1057
|
-
getDirection,
|
|
1058
|
-
getClosestPointToPoint,
|
|
1059
|
-
getIntersectBounds,
|
|
1060
|
-
getIntersectBox3,
|
|
1061
|
-
getIntersectTri3,
|
|
1062
|
-
getIntersectVertices,
|
|
1063
|
-
getIntersectNormalConstant,
|
|
1064
|
-
getIntersectPln,
|
|
1065
|
-
getIntersectPositionRadius,
|
|
1066
|
-
getIntersectSph3,
|
|
1067
|
-
getOrigin,
|
|
1068
|
-
intersectsBox3,
|
|
1069
|
-
intersectsBounds,
|
|
1070
|
-
intersectsNormalConstant,
|
|
1071
|
-
intersectsPln,
|
|
1072
|
-
intersectsPositionRadius,
|
|
1073
|
-
intersectsSph3,
|
|
1074
|
-
lookAt,
|
|
1075
|
-
normalize,
|
|
1076
|
-
recast,
|
|
1077
|
-
set,
|
|
1078
|
-
SORT,
|
|
1079
|
-
squaredDistance,
|
|
1080
|
-
toArray,
|
|
1081
|
-
toOriginDirection,
|
|
1082
|
-
transformMat4,
|
|
1083
|
-
translate,
|
|
1084
|
-
fromEvent
|
|
1085
|
-
} = ray3;
|
|
1029
|
+
|
|
1030
|
+
return ray3.unproject(ray, [ pX, pY ], viewProjectionInverse, viewPort);
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
export const {
|
|
1034
|
+
alloc,
|
|
1035
|
+
unalloc,
|
|
1036
|
+
$origin,
|
|
1037
|
+
$direction,
|
|
1038
|
+
clone,
|
|
1039
|
+
copy,
|
|
1040
|
+
copyOrigin,
|
|
1041
|
+
copyDirection,
|
|
1042
|
+
create,
|
|
1043
|
+
distance,
|
|
1044
|
+
distanceNormalConstant,
|
|
1045
|
+
distancePln,
|
|
1046
|
+
equals,
|
|
1047
|
+
equalsOriginDestination,
|
|
1048
|
+
exactEquals,
|
|
1049
|
+
exactEqualsOriginDestination,
|
|
1050
|
+
from,
|
|
1051
|
+
fromArray,
|
|
1052
|
+
fromStartEnd,
|
|
1053
|
+
fromMat4,
|
|
1054
|
+
fromPerspective,
|
|
1055
|
+
unproject,
|
|
1056
|
+
get,
|
|
1057
|
+
getDirection,
|
|
1058
|
+
getClosestPointToPoint,
|
|
1059
|
+
getIntersectBounds,
|
|
1060
|
+
getIntersectBox3,
|
|
1061
|
+
getIntersectTri3,
|
|
1062
|
+
getIntersectVertices,
|
|
1063
|
+
getIntersectNormalConstant,
|
|
1064
|
+
getIntersectPln,
|
|
1065
|
+
getIntersectPositionRadius,
|
|
1066
|
+
getIntersectSph3,
|
|
1067
|
+
getOrigin,
|
|
1068
|
+
intersectsBox3,
|
|
1069
|
+
intersectsBounds,
|
|
1070
|
+
intersectsNormalConstant,
|
|
1071
|
+
intersectsPln,
|
|
1072
|
+
intersectsPositionRadius,
|
|
1073
|
+
intersectsSph3,
|
|
1074
|
+
lookAt,
|
|
1075
|
+
normalize,
|
|
1076
|
+
recast,
|
|
1077
|
+
set,
|
|
1078
|
+
SORT,
|
|
1079
|
+
squaredDistance,
|
|
1080
|
+
toArray,
|
|
1081
|
+
toOriginDirection,
|
|
1082
|
+
transformMat4,
|
|
1083
|
+
translate,
|
|
1084
|
+
fromEvent
|
|
1085
|
+
} = ray3;
|