@woosh/meep-engine 2.33.19 → 2.33.23
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/core/assert.js +3 -1
- package/core/bvh2/traversal/__detailed_box_volume_intersection.js +11 -8
- package/core/collection/HashMap.js +66 -22
- package/core/geom/3d/CircleMath.js +4 -4
- package/core/geom/3d/cone/computeConeBoundingBox.js +4 -4
- package/core/geom/3d/{compute_bounding_cone_of_2_cones.js → cone/compute_bounding_cone_of_2_cones.js} +3 -3
- package/core/geom/3d/{compute_bounding_cone_of_2_cones.spec.js → cone/compute_bounding_cone_of_2_cones.spec.js} +1 -1
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +1 -1
- package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +10 -2
- package/core/geom/3d/{encode_unit3_hemioct.js → normal/hemioct/encode_unit3_hemioct.js} +0 -0
- package/core/geom/3d/{unit_hemioct.spec.js → normal/hemioct/unit_hemioct.spec.js} +1 -1
- package/core/geom/3d/normal/lamber_azimuth/transform.js +61 -0
- package/core/geom/3d/normal/spherical/sphere_map_transform.js +77 -0
- package/core/geom/3d/{lerp_planes_to_array.js → plane/lerp_planes_to_array.js} +1 -3
- package/core/geom/3d/plane/plane3_lerp.js +3 -1
- package/core/geom/3d/plane/plane3_slerp.js +4 -1
- package/core/geom/3d/{plane_computeConvex3PlaneIntersection.js → plane/plane_computeConvex3PlaneIntersection.js} +14 -16
- package/core/geom/3d/topology/TopoTriangle.js +1 -1
- package/core/geom/3d/topology/TopoVertex.js +1 -1
- package/core/geom/3d/topology/bounds/computeTraingleClusterNormalBoundingCone.js +2 -2
- package/core/geom/3d/topology/simplify/compute_face_normal_change_dot_product.js +1 -1
- package/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +1 -1
- package/core/geom/3d/triangle/computeTrianglePlaneSide.js +1 -1
- package/core/geom/3d/triangle/computeTriangleRayIntersection.js +1 -1
- package/core/geom/3d/voxel/DenseBitVolume3D.js +87 -0
- package/core/geom/3d/voxel/buildVolumeFromProjectedGeometry.js +23 -0
- package/core/geom/LineSegment.js +3 -1
- package/core/geom/Matrix4.js +2 -1
- package/core/geom/Plane.js +15 -10
- package/core/geom/Quaternion.js +2 -1
- package/core/geom/Vector3.d.ts +2 -0
- package/core/geom/Vector3.js +33 -158
- package/core/geom/Vector3.spec.js +2 -1
- package/core/geom/v3_angle_between.js +31 -0
- package/core/geom/v3_distance.js +16 -0
- package/core/geom/v3_distance_sqr.js +17 -0
- package/core/geom/v3_dot.js +13 -0
- package/core/geom/v3_length.js +5 -0
- package/core/geom/v3_length_sqr.js +10 -0
- package/core/geom/v3_lerp.js +21 -0
- package/core/geom/v3_slerp.js +48 -0
- package/core/primitives/array/computeIntegerArrayHash.js +6 -1
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +11 -0
- package/engine/asset/loaders/material/computeImageBitmapHash.js +22 -28
- package/engine/asset/loaders/material/computeMaterialHash.js +1 -2
- package/engine/asset/loaders/material/computeTextureEquality.js +13 -5
- package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +3 -1
- package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +3 -1
- package/engine/ecs/fow/FogOfWar.js +2 -3
- package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +1 -1
- package/engine/ecs/systems/SteeringSystem.js +2 -1
- package/engine/ecs/terrain/ecs/Terrain.js +6 -0
- package/engine/ecs/terrain/ecs/layers/TerrainLayers.js +5 -0
- package/engine/ecs/terrain/ecs/splat/SplatMapping.js +5 -0
- package/engine/ecs/util/hideEntityGracefully.js +18 -0
- package/engine/graphics/GraphicsEngine.js +1 -0
- package/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
- package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
- package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +0 -53
- package/engine/graphics/ecs/path/testPathDisplaySystem.js +98 -98
- package/engine/graphics/ecs/trail2d/Trail2D.js +17 -4
- package/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts +2 -3
- package/engine/graphics/ecs/trail2d/Trail2DSystem.js +34 -118
- package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -1
- package/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +1 -1
- package/engine/graphics/micron/build/clustering/compute_face_connection_weight.js +1 -1
- package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +1 -1
- package/engine/graphics/micron/build/hierarchy/patch_combine.js +1 -1
- package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +2 -2
- package/engine/graphics/particles/particular/engine/ParticularEngine.js +4 -2
- package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +20 -0
- package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +40 -97
- package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +12 -2
- package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +37 -0
- package/engine/graphics/particles/particular/engine/emitter/distance_to_camera.js +25 -0
- package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +7 -25
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
- package/engine/graphics/render/forward_plus/LightManager.js +10 -2
- package/engine/graphics/render/forward_plus/computeFrustumCorners.js +15 -33
- package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +12 -2
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +96 -95
- package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +18 -6
- package/engine/graphics/render/layers/RenderLayerUtils.js +8 -5
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +1 -1
- package/engine/graphics/texture/atlas/AtlasPatch.js +7 -2
- package/engine/graphics/texture/atlas/TextureAtlas.js +18 -14
- package/engine/graphics/texture/sampler/Sampler2D.js +8 -7
- package/engine/graphics/texture/sampler/scaleSampler2D.js +7 -10
- package/engine/graphics/trail/x/RibbonMaterialX.js +3 -3
- package/engine/graphics/trail/x/RibbonX.js +17 -2
- package/engine/graphics/trail/x/RibbonXPlugin.js +51 -1
- package/engine/graphics/util/projectSphere.js +1 -1
- package/engine/grid/components/GridObstacle.js +2 -9
- package/engine/navigation/ecs/components/Path.js +2 -1
- package/engine/network/convertPathToURL.js +2 -2
- package/engine/reference/v2/Reference.js +6 -0
- package/generation/filtering/numeric/complex/CellFilterAngleToNormal.js +3 -2
- package/generation/markers/GridCellActionPlaceMarker.js +13 -1
- package/generation/markers/MarkerNode.js +6 -0
- package/generation/theme/ThemeEngine.js +4 -1
- package/package.json +3 -3
- package/view/View.js +4 -2
- package/view/minimap/gl/MinimapMarkersGL.js +13 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Vector3 from "../../Vector3.js";
|
|
2
|
+
import { BitSet } from "../../../binary/BitSet.js";
|
|
3
|
+
|
|
4
|
+
export class DenseBitVolume3D {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.size = new Vector3(1, 1, 1);
|
|
7
|
+
|
|
8
|
+
this.__data = new BitSet();
|
|
9
|
+
this.__data.preventShrink();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
clear() {
|
|
13
|
+
this.__data.reset();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
resize(x, y, z) {
|
|
17
|
+
// TODO consider how we can resize while keeping the data
|
|
18
|
+
this.clear();
|
|
19
|
+
|
|
20
|
+
this.size.set(x, y, z);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {number} x
|
|
26
|
+
* @param {number} y
|
|
27
|
+
* @param {number} z
|
|
28
|
+
* @return {number}
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
__compute_address(x, y, z) {
|
|
32
|
+
|
|
33
|
+
const size = this.size;
|
|
34
|
+
|
|
35
|
+
const dx = size.x;
|
|
36
|
+
const dy = size.y;
|
|
37
|
+
|
|
38
|
+
return y * dx + z * dx * dy + x;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param {number} x
|
|
44
|
+
* @param {number} y
|
|
45
|
+
* @param {number} z
|
|
46
|
+
* @return {boolean}
|
|
47
|
+
*/
|
|
48
|
+
get(x, y, z) {
|
|
49
|
+
const address = this.__compute_address(x, y, z);
|
|
50
|
+
|
|
51
|
+
return this.__data.get(address)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {boolean} value
|
|
57
|
+
* @param {number} x
|
|
58
|
+
* @param {number} y
|
|
59
|
+
* @param {number} z
|
|
60
|
+
*/
|
|
61
|
+
set(value, x, y, z) {
|
|
62
|
+
const address = this.__compute_address(x, y, z);
|
|
63
|
+
|
|
64
|
+
this.__data.set(address, value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {number} u x-coordinate, normalized to [0,1] range
|
|
70
|
+
* @param {number} v y-coordinate, normalized to [0,1] range
|
|
71
|
+
* @param {number} w z-coordinate, normalized to [0,1] range
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
*/
|
|
74
|
+
sampleNearest(u, v, w) {
|
|
75
|
+
const s = this.size;
|
|
76
|
+
|
|
77
|
+
const dx = s.x;
|
|
78
|
+
const dy = s.y;
|
|
79
|
+
const dz = s.z;
|
|
80
|
+
|
|
81
|
+
const x = Math.round(dx * u) % dx
|
|
82
|
+
const y = Math.round(dy * v) % dy
|
|
83
|
+
const z = Math.round(dz * w) % dz
|
|
84
|
+
|
|
85
|
+
return this.get(x, y, z);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a world-space oriented volume
|
|
3
|
+
* @param {DenseBitVolume3D} volume
|
|
4
|
+
* @param {AABB3} bounds
|
|
5
|
+
* @param {{raycast:function(source_x:number, source_y:number, source_z:number, direction_x:number, direction_y:number, direction_z:number):number}} sampler
|
|
6
|
+
* @param {number[]} frustum 3d frustum, defined as series of 6 planes in order: normal_x, normal_y, normal_z, plane_offset
|
|
7
|
+
*/
|
|
8
|
+
export function buildVolumeFromProjectedGeometry({ volume, sampler, frustum }) {
|
|
9
|
+
// get frustum corners
|
|
10
|
+
|
|
11
|
+
// get first hits from "front" plane to seed the volume
|
|
12
|
+
for (let x = 0; x < 64; x++) {
|
|
13
|
+
for (let y = 0; y < 64; y++) {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// fit volume to the frustum
|
|
19
|
+
|
|
20
|
+
// create a connectivity graph to identify disconnected regions
|
|
21
|
+
|
|
22
|
+
// clear out disconnected regions starting from smallest until only one is left
|
|
23
|
+
}
|
package/core/geom/LineSegment.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Created by Alex on 18/03/14.
|
|
3
3
|
*/
|
|
4
4
|
import { clamp } from "../math/clamp.js";
|
|
5
|
-
import Vector3
|
|
5
|
+
import Vector3 from "./Vector3.js";
|
|
6
|
+
import { v3_dot } from "./v3_dot.js";
|
|
7
|
+
import { v3_distance_sqr } from "./v3_distance_sqr.js";
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
const SMALL_NUM = 1e-9;
|
package/core/geom/Matrix4.js
CHANGED
package/core/geom/Plane.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { v3_dot } from "./
|
|
6
|
+
import { v3_dot } from "./v3_dot.js";
|
|
7
7
|
|
|
8
8
|
function Plane() {
|
|
9
9
|
|
|
@@ -192,7 +192,8 @@ export function computePlaneLineIntersection(out, originX, originY, originZ, dir
|
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
194
|
*
|
|
195
|
-
* @param {
|
|
195
|
+
* @param {Float32Array|number[]|vec3} result
|
|
196
|
+
* @param {number} result_offset
|
|
196
197
|
* @param {number} x0
|
|
197
198
|
* @param {number} y0
|
|
198
199
|
* @param {number} z0
|
|
@@ -205,30 +206,34 @@ export function computePlaneLineIntersection(out, originX, originY, originZ, dir
|
|
|
205
206
|
* @param {number} dist
|
|
206
207
|
* @returns {boolean}
|
|
207
208
|
*/
|
|
208
|
-
export function plane3_computeLineSegmentIntersection(
|
|
209
|
+
export function plane3_computeLineSegmentIntersection(
|
|
210
|
+
result, result_offset,
|
|
211
|
+
x0, y0, z0,
|
|
212
|
+
x1, y1, z1,
|
|
213
|
+
normalX, normalY, normalZ, dist
|
|
214
|
+
) {
|
|
215
|
+
|
|
209
216
|
const directionX = x1 - x0;
|
|
210
217
|
const directionY = y1 - y0;
|
|
211
218
|
const directionZ = z1 - z0;
|
|
212
219
|
|
|
213
220
|
const denom = v3_dot(directionX, directionY, directionZ, normalX, normalY, normalZ);
|
|
214
221
|
|
|
215
|
-
const p = v3_dot(normalX, normalY, normalZ, x0, y0, z0) + dist;
|
|
216
|
-
|
|
217
222
|
if (denom === 0) {
|
|
218
223
|
return false;
|
|
219
224
|
}
|
|
220
225
|
|
|
226
|
+
const p = v3_dot(normalX, normalY, normalZ, x0, y0, z0) + dist;
|
|
227
|
+
|
|
221
228
|
const t = -p / denom;
|
|
222
229
|
|
|
223
230
|
if (t < 0 || t > 1) {
|
|
224
231
|
return false;
|
|
225
232
|
}
|
|
226
233
|
|
|
227
|
-
result
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
directionZ * t + z0
|
|
231
|
-
);
|
|
234
|
+
result[result_offset] = directionX * t + x0;
|
|
235
|
+
result[result_offset + 1] = directionY * t + y0;
|
|
236
|
+
result[result_offset + 2] = directionZ * t + z0;
|
|
232
237
|
|
|
233
238
|
return true;
|
|
234
239
|
|
package/core/geom/Quaternion.js
CHANGED
|
@@ -10,7 +10,8 @@ import { clamp } from "../math/clamp.js";
|
|
|
10
10
|
import { copysign } from "../math/copysign.js";
|
|
11
11
|
import { lerp } from "../math/lerp.js";
|
|
12
12
|
import { EPSILON, epsilonEquals, PI2, PI_HALF } from "../math/MathUtils.js";
|
|
13
|
-
import Vector3
|
|
13
|
+
import Vector3 from "./Vector3.js";
|
|
14
|
+
import { v3_dot } from "./v3_dot.js";
|
|
14
15
|
|
|
15
16
|
const matrix = new ThreeMatrix4();
|
|
16
17
|
|
package/core/geom/Vector3.d.ts
CHANGED
package/core/geom/Vector3.js
CHANGED
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
import { assert } from "../assert.js";
|
|
7
7
|
import Signal from "../events/signal/Signal.js";
|
|
8
|
-
import { clamp } from "../math/clamp.js";
|
|
9
8
|
import { lerp } from "../math/lerp.js";
|
|
10
9
|
import { computeHashFloat, EPSILON, epsilonEquals } from "../math/MathUtils.js";
|
|
11
10
|
import { sign } from "../math/sign.js";
|
|
11
|
+
import { v3_dot } from "./v3_dot.js";
|
|
12
|
+
import { v3_length_sqr } from "./v3_length_sqr.js";
|
|
13
|
+
import { v3_length } from "./v3_length.js";
|
|
14
|
+
import { v3_angle_between } from "./v3_angle_between.js";
|
|
15
|
+
import { v3_lerp } from "./v3_lerp.js";
|
|
16
|
+
import { v3_slerp } from "./v3_slerp.js";
|
|
12
17
|
|
|
13
18
|
class Vector3 {
|
|
14
19
|
/**
|
|
@@ -442,7 +447,7 @@ class Vector3 {
|
|
|
442
447
|
* @returns {number}
|
|
443
448
|
*/
|
|
444
449
|
angleTo(other) {
|
|
445
|
-
return
|
|
450
|
+
return v3_angle_between(this.x, this.y, this.z, other.x, other.y, other.z);
|
|
446
451
|
}
|
|
447
452
|
|
|
448
453
|
/**
|
|
@@ -534,6 +539,32 @@ class Vector3 {
|
|
|
534
539
|
return this.set(_x, _y, _z);
|
|
535
540
|
}
|
|
536
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Assume current vector holds a direction, transform using a matrix to produce a new directional unit vector
|
|
544
|
+
* @param {THREE.Matrix4} m
|
|
545
|
+
*/
|
|
546
|
+
transformDirection_three(m) {
|
|
547
|
+
|
|
548
|
+
// input: THREE.Matrix4 affine matrix
|
|
549
|
+
// vector interpreted as a direction
|
|
550
|
+
|
|
551
|
+
const x = this.x, y = this.y, z = this.z;
|
|
552
|
+
const e = m.elements;
|
|
553
|
+
|
|
554
|
+
const _x = e[0] * x + e[4] * y + e[8] * z;
|
|
555
|
+
const _y = e[1] * x + e[5] * y + e[9] * z;
|
|
556
|
+
const _z = e[2] * x + e[6] * y + e[10] * z;
|
|
557
|
+
|
|
558
|
+
// normalize the result
|
|
559
|
+
const _l = 1 / v3_length(_x, _y, _z);
|
|
560
|
+
|
|
561
|
+
this.set(
|
|
562
|
+
_x * _l,
|
|
563
|
+
_y * _l,
|
|
564
|
+
_z * _l
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
|
|
537
568
|
/**
|
|
538
569
|
*
|
|
539
570
|
* @param {THREE.Matrix3} m
|
|
@@ -947,20 +978,6 @@ Vector3.back = Object.freeze(new Vector3(0, 0, -1));
|
|
|
947
978
|
Vector3.typeName = "Vector3";
|
|
948
979
|
|
|
949
980
|
|
|
950
|
-
/**
|
|
951
|
-
*
|
|
952
|
-
* @param {number} x0
|
|
953
|
-
* @param {number} y0
|
|
954
|
-
* @param {number} z0
|
|
955
|
-
* @param {number} x1
|
|
956
|
-
* @param {number} y1
|
|
957
|
-
* @param {number} z1
|
|
958
|
-
* @returns {number}
|
|
959
|
-
*/
|
|
960
|
-
export function v3_dot(x0, y0, z0, x1, y1, z1) {
|
|
961
|
-
return (x0 * x1 + y0 * y1 + z0 * z1);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
981
|
/**
|
|
965
982
|
*
|
|
966
983
|
* @param {number} x0
|
|
@@ -973,87 +990,11 @@ export function v3_dot(x0, y0, z0, x1, y1, z1) {
|
|
|
973
990
|
*/
|
|
974
991
|
Vector3._dot = v3_dot;
|
|
975
992
|
|
|
976
|
-
/**
|
|
977
|
-
*
|
|
978
|
-
* @param {number} x0
|
|
979
|
-
* @param {number} y0
|
|
980
|
-
* @param {number} z0
|
|
981
|
-
* @param {number} x1
|
|
982
|
-
* @param {number} y1
|
|
983
|
-
* @param {number} z1
|
|
984
|
-
* @returns {number}
|
|
985
|
-
*/
|
|
986
|
-
export function v3_distance(x0, y0, z0, x1, y1, z1) {
|
|
987
|
-
|
|
988
|
-
return Math.sqrt(v3_distance_sqr(x0, y0, z0, x1, y1, z1));
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
*
|
|
993
|
-
* @param {number} x0
|
|
994
|
-
* @param {number} y0
|
|
995
|
-
* @param {number} z0
|
|
996
|
-
* @param {number} x1
|
|
997
|
-
* @param {number} y1
|
|
998
|
-
* @param {number} z1
|
|
999
|
-
* @returns {number}
|
|
1000
|
-
*/
|
|
1001
|
-
export function v3_distance_sqr(x0, y0, z0, x1, y1, z1) {
|
|
1002
|
-
const x = x0 - x1;
|
|
1003
|
-
const y = y0 - y1;
|
|
1004
|
-
const z = z0 - z1;
|
|
1005
|
-
|
|
1006
|
-
return x * x + y * y + z * z;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
993
|
|
|
1010
994
|
function v3Length(v) {
|
|
1011
995
|
return v3_length(v.x, v.y, v.z);
|
|
1012
996
|
}
|
|
1013
997
|
|
|
1014
|
-
export function v3_length(x, y, z) {
|
|
1015
|
-
return Math.sqrt(v3_length_sqr(x, y, z));
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
*
|
|
1020
|
-
* @param {number} x
|
|
1021
|
-
* @param {number} y
|
|
1022
|
-
* @param {number} z
|
|
1023
|
-
* @return {number}
|
|
1024
|
-
*/
|
|
1025
|
-
export function v3_length_sqr(x, y, z) {
|
|
1026
|
-
return x * x + y * y + z * z;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
*
|
|
1032
|
-
* @param {number} x0
|
|
1033
|
-
* @param {number} y0
|
|
1034
|
-
* @param {number} z0
|
|
1035
|
-
* @param {number} x1
|
|
1036
|
-
* @param {number} y1
|
|
1037
|
-
* @param {number} z1
|
|
1038
|
-
* @returns {number}
|
|
1039
|
-
*/
|
|
1040
|
-
export function v3_angleBetween(x0, y0, z0, x1, y1, z1) {
|
|
1041
|
-
const d = v3_dot(x0, y0, z0, x1, y1, z1);
|
|
1042
|
-
|
|
1043
|
-
const magnitude_0 = v3_length(x0, y0, z0);
|
|
1044
|
-
const magnitude_1 = v3_length(x1, y1, z1);
|
|
1045
|
-
|
|
1046
|
-
const l = magnitude_0 * magnitude_1;
|
|
1047
|
-
|
|
1048
|
-
if (l === 0) {
|
|
1049
|
-
// collective magnitude is 0, provide arbitrary angle
|
|
1050
|
-
return 0;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
const theta = clamp(d / l, -1, 1);
|
|
1054
|
-
|
|
1055
|
-
return Math.acos(theta);
|
|
1056
|
-
}
|
|
1057
998
|
|
|
1058
999
|
/**
|
|
1059
1000
|
*
|
|
@@ -1067,70 +1008,4 @@ function v3Lerp(result, a, b, fraction) {
|
|
|
1067
1008
|
v3_lerp(result, a.x, a.y, a.z, b.x, b.y, b.z, fraction);
|
|
1068
1009
|
}
|
|
1069
1010
|
|
|
1070
|
-
/**
|
|
1071
|
-
*
|
|
1072
|
-
* @param {Vector3} result
|
|
1073
|
-
* @param {number} a_x
|
|
1074
|
-
* @param {number} a_y
|
|
1075
|
-
* @param {number} a_z
|
|
1076
|
-
* @param {number} b_x
|
|
1077
|
-
* @param {number} b_y
|
|
1078
|
-
* @param {number} b_z
|
|
1079
|
-
* @param {number} fraction
|
|
1080
|
-
*/
|
|
1081
|
-
function v3_lerp(result, a_x, a_y, a_z, b_x, b_y, b_z, fraction) {
|
|
1082
|
-
|
|
1083
|
-
const x = lerp(a_x, b_x, fraction);
|
|
1084
|
-
const y = lerp(a_y, b_y, fraction);
|
|
1085
|
-
const z = lerp(a_z, b_z, fraction);
|
|
1086
|
-
|
|
1087
|
-
result.set(x, y, z);
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
/**
|
|
1091
|
-
* Spherical linear interpolation
|
|
1092
|
-
* @see https://en.wikipedia.org/wiki/Slerp
|
|
1093
|
-
* @param {Vector3} result
|
|
1094
|
-
* @param {number} a_x
|
|
1095
|
-
* @param {number} a_y
|
|
1096
|
-
* @param {number} a_z
|
|
1097
|
-
* @param {number} b_x
|
|
1098
|
-
* @param {number} b_y
|
|
1099
|
-
* @param {number} b_z
|
|
1100
|
-
* @param {number} fraction
|
|
1101
|
-
*/
|
|
1102
|
-
export function v3_slerp(
|
|
1103
|
-
result,
|
|
1104
|
-
a_x, a_y, a_z,
|
|
1105
|
-
b_x, b_y, b_z,
|
|
1106
|
-
fraction
|
|
1107
|
-
) {
|
|
1108
|
-
const dot = v3_dot(
|
|
1109
|
-
a_x, a_y, a_z,
|
|
1110
|
-
b_x, b_y, b_z
|
|
1111
|
-
);
|
|
1112
|
-
|
|
1113
|
-
if (dot >= 1 || dot <= -1) {
|
|
1114
|
-
// avoid division by 0, both vectors are pointing in the same direction, use lerp instead
|
|
1115
|
-
v3_lerp(result, a_x, a_y, a_z, b_x, b_y, b_z, fraction);
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
// compute angle between two vectors
|
|
1120
|
-
const theta = Math.acos(dot);
|
|
1121
|
-
|
|
1122
|
-
const sin_theta = Math.sin(theta);
|
|
1123
|
-
|
|
1124
|
-
const inv_sin_theta = 1 / sin_theta;
|
|
1125
|
-
|
|
1126
|
-
const scale_0 = Math.sin((1 - fraction) * theta) * inv_sin_theta;
|
|
1127
|
-
const scale_1 = Math.sin((fraction) * theta) * inv_sin_theta;
|
|
1128
|
-
|
|
1129
|
-
const x = a_x * scale_0 + b_x * scale_1;
|
|
1130
|
-
const y = a_y * scale_0 + b_y * scale_1;
|
|
1131
|
-
const z = a_z * scale_0 + b_z * scale_1;
|
|
1132
|
-
|
|
1133
|
-
result.set(x, y, z);
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
1011
|
export default Vector3;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { v3_dot } from "./v3_dot.js";
|
|
2
|
+
import { v3_length } from "./v3_length.js";
|
|
3
|
+
import { clamp } from "../math/clamp.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {number} x0
|
|
8
|
+
* @param {number} y0
|
|
9
|
+
* @param {number} z0
|
|
10
|
+
* @param {number} x1
|
|
11
|
+
* @param {number} y1
|
|
12
|
+
* @param {number} z1
|
|
13
|
+
* @returns {number}
|
|
14
|
+
*/
|
|
15
|
+
export function v3_angle_between(x0, y0, z0, x1, y1, z1) {
|
|
16
|
+
const d = v3_dot(x0, y0, z0, x1, y1, z1);
|
|
17
|
+
|
|
18
|
+
const magnitude_0 = v3_length(x0, y0, z0);
|
|
19
|
+
const magnitude_1 = v3_length(x1, y1, z1);
|
|
20
|
+
|
|
21
|
+
const l = magnitude_0 * magnitude_1;
|
|
22
|
+
|
|
23
|
+
if (l === 0) {
|
|
24
|
+
// collective magnitude is 0, provide arbitrary angle
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const theta = clamp(d / l, -1, 1);
|
|
29
|
+
|
|
30
|
+
return Math.acos(theta);
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { v3_distance_sqr } from "./v3_distance_sqr.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number} x0
|
|
6
|
+
* @param {number} y0
|
|
7
|
+
* @param {number} z0
|
|
8
|
+
* @param {number} x1
|
|
9
|
+
* @param {number} y1
|
|
10
|
+
* @param {number} z1
|
|
11
|
+
* @returns {number}
|
|
12
|
+
*/
|
|
13
|
+
export function v3_distance(x0, y0, z0, x1, y1, z1) {
|
|
14
|
+
|
|
15
|
+
return Math.sqrt(v3_distance_sqr(x0, y0, z0, x1, y1, z1));
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} x0
|
|
4
|
+
* @param {number} y0
|
|
5
|
+
* @param {number} z0
|
|
6
|
+
* @param {number} x1
|
|
7
|
+
* @param {number} y1
|
|
8
|
+
* @param {number} z1
|
|
9
|
+
* @returns {number}
|
|
10
|
+
*/
|
|
11
|
+
export function v3_distance_sqr(x0, y0, z0, x1, y1, z1) {
|
|
12
|
+
const x = x0 - x1;
|
|
13
|
+
const y = y0 - y1;
|
|
14
|
+
const z = z0 - z1;
|
|
15
|
+
|
|
16
|
+
return x * x + y * y + z * z;
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} x0
|
|
4
|
+
* @param {number} y0
|
|
5
|
+
* @param {number} z0
|
|
6
|
+
* @param {number} x1
|
|
7
|
+
* @param {number} y1
|
|
8
|
+
* @param {number} z1
|
|
9
|
+
* @returns {number}
|
|
10
|
+
*/
|
|
11
|
+
export function v3_dot(x0, y0, z0, x1, y1, z1) {
|
|
12
|
+
return (x0 * x1 + y0 * y1 + z0 * z1);
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { lerp } from "../math/lerp.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Vector3} result
|
|
6
|
+
* @param {number} a_x
|
|
7
|
+
* @param {number} a_y
|
|
8
|
+
* @param {number} a_z
|
|
9
|
+
* @param {number} b_x
|
|
10
|
+
* @param {number} b_y
|
|
11
|
+
* @param {number} b_z
|
|
12
|
+
* @param {number} fraction
|
|
13
|
+
*/
|
|
14
|
+
export function v3_lerp(result, a_x, a_y, a_z, b_x, b_y, b_z, fraction) {
|
|
15
|
+
|
|
16
|
+
const x = lerp(a_x, b_x, fraction);
|
|
17
|
+
const y = lerp(a_y, b_y, fraction);
|
|
18
|
+
const z = lerp(a_z, b_z, fraction);
|
|
19
|
+
|
|
20
|
+
result.set(x, y, z);
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { v3_dot } from "./v3_dot.js";
|
|
2
|
+
import { v3_lerp } from "./v3_lerp.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Spherical linear interpolation
|
|
6
|
+
* @see https://en.wikipedia.org/wiki/Slerp
|
|
7
|
+
* @param {Vector3} result
|
|
8
|
+
* @param {number} a_x
|
|
9
|
+
* @param {number} a_y
|
|
10
|
+
* @param {number} a_z
|
|
11
|
+
* @param {number} b_x
|
|
12
|
+
* @param {number} b_y
|
|
13
|
+
* @param {number} b_z
|
|
14
|
+
* @param {number} fraction
|
|
15
|
+
*/
|
|
16
|
+
export function v3_slerp(
|
|
17
|
+
result,
|
|
18
|
+
a_x, a_y, a_z,
|
|
19
|
+
b_x, b_y, b_z,
|
|
20
|
+
fraction
|
|
21
|
+
) {
|
|
22
|
+
const dot = v3_dot(
|
|
23
|
+
a_x, a_y, a_z,
|
|
24
|
+
b_x, b_y, b_z
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (dot >= 1 || dot <= -1) {
|
|
28
|
+
// avoid division by 0, both vectors are pointing in the same direction, use lerp instead
|
|
29
|
+
v3_lerp(result, a_x, a_y, a_z, b_x, b_y, b_z, fraction);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// compute angle between two vectors
|
|
34
|
+
const theta = Math.acos(dot);
|
|
35
|
+
|
|
36
|
+
const sin_theta = Math.sin(theta);
|
|
37
|
+
|
|
38
|
+
const inv_sin_theta = 1 / sin_theta;
|
|
39
|
+
|
|
40
|
+
const scale_0 = Math.sin((1 - fraction) * theta) * inv_sin_theta;
|
|
41
|
+
const scale_1 = Math.sin((fraction) * theta) * inv_sin_theta;
|
|
42
|
+
|
|
43
|
+
const x = a_x * scale_0 + b_x * scale_1;
|
|
44
|
+
const y = a_y * scale_0 + b_y * scale_1;
|
|
45
|
+
const z = a_z * scale_0 + b_z * scale_1;
|
|
46
|
+
|
|
47
|
+
result.set(x, y, z);
|
|
48
|
+
}
|
|
@@ -7,10 +7,15 @@
|
|
|
7
7
|
export function computeIntegerArrayHash(data, offset, length) {
|
|
8
8
|
const end = offset + length;
|
|
9
9
|
|
|
10
|
-
let hash =
|
|
10
|
+
let hash = length;
|
|
11
11
|
|
|
12
12
|
for (let i = offset; i < end; i++) {
|
|
13
13
|
const singleValue = data[i];
|
|
14
|
+
/**
|
|
15
|
+
* Simple hashing scheme, multiplying existing hash by a prime and adding next value
|
|
16
|
+
* (h<<5) - h === h*31
|
|
17
|
+
* @type {number}
|
|
18
|
+
*/
|
|
14
19
|
hash = ((hash << 5) - hash) + singleValue;
|
|
15
20
|
hash |= 0; // Convert to 32bit integer
|
|
16
21
|
}
|
|
@@ -79,6 +79,17 @@ function obtainCanvasCtx(width, height) {
|
|
|
79
79
|
return gl;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param {ImageBitmap} bitmap
|
|
85
|
+
* @return {Sampler2D}
|
|
86
|
+
*/
|
|
87
|
+
export function sampler_from_bitmap(bitmap) {
|
|
88
|
+
const ctx = obtainCanvasCtx(bitmap.width, bitmap.height);
|
|
89
|
+
|
|
90
|
+
return obtainSampler(bitmap, ctx);
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
/**
|
|
83
94
|
*
|
|
84
95
|
* @param {ImageBitmap} a
|