@woosh/meep-engine 2.71.0 → 2.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +36 -187
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +36 -187
  5. package/package.json +3 -2
  6. package/src/core/collection/array/array_get_index_in_range.js +1 -1
  7. package/src/core/collection/array/array_swap.js +2 -2
  8. package/src/core/geom/3d/v3_compute_triangle_normal.js +7 -1
  9. package/src/core/geom/vec3/v3_normalize_array.js +27 -0
  10. package/src/engine/ecs/terrain/BufferedGeometryArraysBuilder.js +2 -2
  11. package/src/engine/graphics/ecs/camera/FrustumProjector.js +31 -182
  12. package/src/engine/graphics/geometry/buffered/ComputeNormals.js +11 -26
  13. package/src/engine/graphics/texture/virtual/v2/NOTES.md +27 -0
  14. package/src/engine/graphics/texture/virtual/v2/ShaderUsage.js +51 -26
  15. package/src/engine/graphics/texture/virtual/v2/SparseTexture.js +182 -0
  16. package/src/engine/graphics/texture/virtual/v2/TextureTile.js +31 -0
  17. package/src/engine/graphics/texture/virtual/v2/TileLoader.js +215 -0
  18. package/src/engine/graphics/texture/virtual/v2/UsageDebugView.js +64 -0
  19. package/src/engine/graphics/texture/virtual/v2/UsageMetadata.js +153 -0
  20. package/src/engine/graphics/texture/virtual/v2/UsagePyramidDebugView.js +252 -0
  21. package/src/engine/graphics/texture/virtual/v2/VirtualTextureManager.js +257 -0
  22. package/src/engine/graphics/texture/virtual/v2/compose_finger_print.js +13 -0
  23. package/src/engine/graphics/texture/virtual/v2/finger_print_to_tile_index.js +37 -0
  24. package/src/engine/graphics/texture/virtual/v2/prototype.js +122 -31
  25. package/src/engine/graphics/texture/virtual/v2/tile_index_to_finger_print.js +31 -0
  26. package/src/core/geom/2d/quad-tree/PointQuadTree.js +0 -478
  27. package/src/core/math/random/makeRangedRandom.js +0 -19
  28. package/src/engine/ecs/terrain/TerrainGeometryBuilder.js +0 -152
  29. package/src/engine/ecs/terrain/ecs/PromiseSamplerHeight.js +0 -66
  30. package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +0 -125
  31. package/src/engine/graphics/clouds/MaterialTransformer.js +0 -0
  32. package/src/engine/graphics/clouds/TerrainCloudsPlugin.js +0 -0
  33. package/src/engine/graphics/clouds/cs_build_fragment_shader.js +0 -0
  34. package/src/engine/graphics/clouds/cs_build_vertex_shader.js +0 -0
  35. package/src/engine/graphics/ecs/camera/TiltCameraController.js +0 -69
  36. package/src/engine/graphics/ecs/camera/is_valid_distance_value.js +0 -11
  37. package/src/engine/graphics/texture/sampler/SampleTraverser.js +0 -165
@@ -56718,9 +56718,9 @@ function ceilPowerOfTwo(v) {
56718
56718
 
56719
56719
  /**
56720
56720
  * @template T
56721
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} a
56721
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} a
56722
56722
  * @param {number} a_offset
56723
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} b
56723
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} b
56724
56724
  * @param {number} b_offset
56725
56725
  * @param {number} length How many elements should be moved
56726
56726
  */
@@ -111512,7 +111512,7 @@ function aabb3_matrix4_project_by_corners(
111512
111512
  result[5] = z1;
111513
111513
  }
111514
111514
 
111515
- const corners = [];
111515
+ const corners$1 = [];
111516
111516
 
111517
111517
  class Decal extends AbstractLight {
111518
111518
  constructor() {
@@ -111598,9 +111598,9 @@ class Decal extends AbstractLight {
111598
111598
  }
111599
111599
 
111600
111600
  getAABB(result) {
111601
- aabb3_build_corners(corners, 0, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5);
111601
+ aabb3_build_corners(corners$1, 0, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5);
111602
111602
 
111603
- aabb3_matrix4_project_by_corners(result, corners, this.transform);
111603
+ aabb3_matrix4_project_by_corners(result, corners$1, this.transform);
111604
111604
  }
111605
111605
 
111606
111606
  toArray(destination, address) {
@@ -113432,190 +113432,41 @@ class ForwardPlusRenderingPlugin extends EnginePlugin {
113432
113432
  */
113433
113433
 
113434
113434
 
113435
- const projectInWorldSpace = (function () {
113436
- const corners = [
113437
- new Vector3(-1, -1, 0),
113438
- new Vector3(-1, -1, 0),
113435
+ const corners = [
113436
+ new Vector3(-1, -1, 0),
113437
+ new Vector3(-1, -1, 0),
113439
113438
 
113440
- new Vector3(-1, 1, 0),
113441
- new Vector3(-1, 1, 0),
113439
+ new Vector3(-1, 1, 0),
113440
+ new Vector3(-1, 1, 0),
113442
113441
 
113443
- new Vector3(1, -1, 0),
113444
- new Vector3(1, -1, 0),
113442
+ new Vector3(1, -1, 0),
113443
+ new Vector3(1, -1, 0),
113445
113444
 
113446
- new Vector3(1, 1, 0),
113447
- new Vector3(1, 1, 0)
113448
- ];
113449
-
113450
-
113451
- /**
113452
- *
113453
- * @param {Number} nearZ
113454
- * @param {Number} farZ
113455
- * @param {THREE.Camera} camera
113456
- * @param {THREE.Matrix4} matrixWorldInverse
113457
- * @param {function} callback
113458
- */
113459
- function projectInWorldSpace(nearZ, farZ, camera, callback) {
113460
- corners[0].set(-1, -1, nearZ);
113461
- corners[1].set(-1, -1, farZ);
113462
-
113463
- corners[2].set(-1, 1, nearZ);
113464
- corners[3].set(-1, 1, farZ);
113465
-
113466
- corners[4].set(1, -1, nearZ);
113467
- corners[5].set(1, -1, farZ);
113468
-
113469
- corners[6].set(1, 1, nearZ);
113470
- corners[7].set(1, 1, farZ);
113471
-
113472
- //compute corners of view frustum in light space
113473
- let x0 = Number.POSITIVE_INFINITY;
113474
- let y0 = Number.POSITIVE_INFINITY;
113475
- let z0 = Number.POSITIVE_INFINITY;
113476
-
113477
- let x1 = Number.NEGATIVE_INFINITY;
113478
- let y1 = Number.NEGATIVE_INFINITY;
113479
- let z1 = Number.NEGATIVE_INFINITY;
113480
-
113481
-
113482
- for (let i = 0; i < 8; i++) {
113483
- const corner = corners[i];
113484
- corner.unproject(camera);
113485
-
113486
- if (corner.x < x0) {
113487
- x0 = corner.x;
113488
- }
113489
- if (corner.x > x1) {
113490
- x1 = corner.x;
113491
- }
113492
-
113493
- if (corner.y < y0) {
113494
- y0 = corner.y;
113495
- }
113496
- if (corner.y > y1) {
113497
- y1 = corner.y;
113498
- }
113499
-
113500
- if (corner.z < z0) {
113501
- z0 = corner.z;
113502
- }
113503
- if (corner.z > z1) {
113504
- z1 = corner.z;
113505
- }
113506
- }
113507
-
113508
- callback(x0, y0, z0, x1, y1, z1);
113509
- }
113510
-
113511
- return projectInWorldSpace;
113512
- })();
113513
-
113514
- const project = (function () {
113515
- const corners = [
113516
- new Vector3(-1, -1, 0),
113517
- new Vector3(-1, -1, 0),
113518
-
113519
- new Vector3(-1, 1, 0),
113520
- new Vector3(-1, 1, 0),
113521
-
113522
- new Vector3(1, -1, 0),
113523
- new Vector3(1, -1, 0),
113524
-
113525
- new Vector3(1, 1, 0),
113526
- new Vector3(1, 1, 0)
113527
- ];
113528
-
113529
-
113530
- /**
113531
- *
113532
- * @param {Number} nearZ
113533
- * @param {Number} farZ
113534
- * @param {THREE.Camera} camera
113535
- * @param {THREE.Matrix4} matrixWorldInverse
113536
- * @param {AABB3} result
113537
- */
113538
- function project(nearZ, farZ, camera, matrixWorldInverse, result) {
113539
- corners[0].set(-1, -1, nearZ);
113540
- corners[1].set(-1, -1, farZ);
113541
-
113542
- corners[2].set(-1, 1, nearZ);
113543
- corners[3].set(-1, 1, farZ);
113544
-
113545
- corners[4].set(1, -1, nearZ);
113546
- corners[5].set(1, -1, farZ);
113547
-
113548
- corners[6].set(1, 1, nearZ);
113549
- corners[7].set(1, 1, farZ);
113550
-
113551
- //compute corners of view frustum in light space
113552
- let x0 = Number.POSITIVE_INFINITY;
113553
- let y0 = Number.POSITIVE_INFINITY;
113554
- let z0 = Number.POSITIVE_INFINITY;
113555
-
113556
- let x1 = Number.NEGATIVE_INFINITY;
113557
- let y1 = Number.NEGATIVE_INFINITY;
113558
- let z1 = Number.NEGATIVE_INFINITY;
113559
-
113560
-
113561
- for (let i = 0; i < 8; i++) {
113562
- const corner = corners[i];
113563
- corner.unproject(camera);
113564
- corner.applyMatrix4(matrixWorldInverse);
113565
-
113566
- if (corner.x < x0) {
113567
- x0 = corner.x;
113568
- }
113569
- if (corner.x > x1) {
113570
- x1 = corner.x;
113571
- }
113572
-
113573
- if (corner.y < y0) {
113574
- y0 = corner.y;
113575
- }
113576
- if (corner.y > y1) {
113577
- y1 = corner.y;
113578
- }
113579
-
113580
- if (corner.z < z0) {
113581
- z0 = corner.z;
113582
- }
113583
- if (corner.z > z1) {
113584
- z1 = corner.z;
113585
- }
113586
- }
113587
-
113588
- result.setBounds(x0, y0, z0, x1, y1, z1);
113589
- }
113445
+ new Vector3(1, 1, 0),
113446
+ new Vector3(1, 1, 0)
113447
+ ];
113590
113448
 
113591
- return project;
113592
- })();
113593
113449
 
113594
113450
  /**
113595
113451
  *
113596
- * @param _x0
113597
- * @param _y0
113598
- * @param _z0
113599
- * @param _x1
113600
- * @param _y1
113601
- * @param _z1
113602
- * @param {Camera} camera
113603
- * @param callback
113452
+ * @param {Number} nearZ
113453
+ * @param {Number} farZ
113454
+ * @param {THREE.Camera} camera
113455
+ * @param {THREE.Matrix4} matrixWorldInverse
113456
+ * @param {AABB3} result
113604
113457
  */
113605
- function unproject(_x0, _y0, _z0, _x1, _y1, _z1, camera, callback) {
113606
- const corners = [
113607
- new Vector3(_x0, _y0, _z0),
113608
- new Vector3(_x0, _y0, _z1),
113458
+ function project(nearZ, farZ, camera, matrixWorldInverse, result) {
113459
+ corners[0].set(-1, -1, nearZ);
113460
+ corners[1].set(-1, -1, farZ);
113609
113461
 
113610
- new Vector3(_x0, _y1, _z0),
113611
- new Vector3(_x0, _y1, _z1),
113462
+ corners[2].set(-1, 1, nearZ);
113463
+ corners[3].set(-1, 1, farZ);
113612
113464
 
113613
- new Vector3(_x1, _y0, _z0),
113614
- new Vector3(_x1, _y0, _z1),
113465
+ corners[4].set(1, -1, nearZ);
113466
+ corners[5].set(1, -1, farZ);
113615
113467
 
113616
- new Vector3(_x1, _y1, _z0),
113617
- new Vector3(_x1, _y1, _z1)
113618
- ];
113468
+ corners[6].set(1, 1, nearZ);
113469
+ corners[7].set(1, 1, farZ);
113619
113470
 
113620
113471
  //compute corners of view frustum in light space
113621
113472
  let x0 = Number.POSITIVE_INFINITY;
@@ -113627,8 +113478,10 @@ function unproject(_x0, _y0, _z0, _x1, _y1, _z1, camera, callback) {
113627
113478
  let z1 = Number.NEGATIVE_INFINITY;
113628
113479
 
113629
113480
 
113630
- corners.forEach(function (corner) {
113631
- corner.project(camera);
113481
+ for (let i = 0; i < 8; i++) {
113482
+ const corner = corners[i];
113483
+ corner.unproject(camera);
113484
+ corner.applyMatrix4(matrixWorldInverse);
113632
113485
 
113633
113486
  if (corner.x < x0) {
113634
113487
  x0 = corner.x;
@@ -113650,21 +113503,17 @@ function unproject(_x0, _y0, _z0, _x1, _y1, _z1, camera, callback) {
113650
113503
  if (corner.z > z1) {
113651
113504
  z1 = corner.z;
113652
113505
  }
113653
- });
113506
+ }
113654
113507
 
113655
- callback(x0, y0, z0, x1, y1, z1);
113508
+ result.setBounds(x0, y0, z0, x1, y1, z1);
113656
113509
  }
113657
113510
 
113511
+
113658
113512
  var FrustumProjector = {
113659
113513
  /**
113660
113514
  * @deprecated use non-threejs specific code
113661
113515
  */
113662
113516
  project,
113663
- unproject,
113664
- /**
113665
- * @deprecated use non-threejs specific code
113666
- */
113667
- projectInWorldSpace
113668
113517
  };
113669
113518
 
113670
113519
  class SystemEntityContext {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.71.0",
8
+ "version": "2.73.0",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -39,7 +39,8 @@
39
39
  "gl-matrix": "3.4.3",
40
40
  "opentype.js": "1.3.3",
41
41
  "robust-predicates": "3.0.1",
42
- "simplex-noise": "2.4.0"
42
+ "simplex-noise": "2.4.0",
43
+ "pako": "2.0.3"
43
44
  },
44
45
  "peerDependencies": {
45
46
  "three": ">=0.135.0 & <0.137.0"
@@ -2,7 +2,7 @@ import { assert } from "../../assert.js";
2
2
 
3
3
  /**
4
4
  * @template T
5
- * @param {T[]} array
5
+ * @param {T[]|Uint32Array} array
6
6
  * @param {T} needle
7
7
  * @param {number} min_index
8
8
  * @param {number} max_index
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @template T
3
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} a
3
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} a
4
4
  * @param {number} a_offset
5
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array} b
5
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Float32Array} b
6
6
  * @param {number} b_offset
7
7
  * @param {number} length How many elements should be moved
8
8
  */
@@ -14,7 +14,13 @@ import { v3_length_sqr } from "../vec3/v3_length_sqr.js";
14
14
  * @param {number} vCy
15
15
  * @param {number} vCz
16
16
  */
17
- export function v3_compute_triangle_normal(result, result_offset, vAx, vAy, vAz, vBx, vBy, vBz, vCx, vCy, vCz) {
17
+ export function v3_compute_triangle_normal(
18
+ result, result_offset,
19
+ vAx, vAy, vAz,
20
+ vBx, vBy, vBz,
21
+ vCx, vCy, vCz
22
+ ) {
23
+
18
24
  //compute CB and AB vectors
19
25
  const vCBx = vCx - vBx;
20
26
  const vCBy = vCy - vBy;
@@ -0,0 +1,27 @@
1
+ /**
2
+ *
3
+ * @param {number[]} input
4
+ * @param {number} input_offset
5
+ * @param {number[]} output
6
+ * @param {number} output_offset
7
+ */
8
+ export function v3_normalize_array(
9
+ input, input_offset,
10
+ output, output_offset
11
+ ) {
12
+
13
+
14
+ // extract vector components
15
+ const x = input[input_offset];
16
+ const y = input[input_offset + 1];
17
+ const z = input[input_offset + 2];
18
+
19
+ // compute vector inverse magnitude
20
+ const n = 1.0 / Math.hypot(x, y, z);
21
+
22
+ // write back
23
+ output[output_offset] = x * n;
24
+ output[output_offset + 1] = y * n;
25
+ output[output_offset + 2] = z * n;
26
+
27
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
 
6
- import ComputeNormals from '../../graphics/geometry/buffered/ComputeNormals.js';
6
+ import { computeVertexNormals } from '../../graphics/geometry/buffered/ComputeNormals.js';
7
7
 
8
8
  /**
9
9
  *
@@ -108,7 +108,7 @@ function buildBufferGeometry(samplerHeight, position, size, scale, totalSize, re
108
108
  }
109
109
  }
110
110
 
111
- ComputeNormals.computeNormals(vertices, normals, indices);
111
+ computeVertexNormals(vertices, normals, indices);
112
112
 
113
113
  //CleanupGeometry(geometry);
114
114
  return {
@@ -6,190 +6,41 @@
6
6
  import { Vector3 as ThreeVector3 } from 'three';
7
7
 
8
8
 
9
- const projectInWorldSpace = (function () {
10
- const corners = [
11
- new ThreeVector3(-1, -1, 0),
12
- new ThreeVector3(-1, -1, 0),
9
+ const corners = [
10
+ new ThreeVector3(-1, -1, 0),
11
+ new ThreeVector3(-1, -1, 0),
13
12
 
14
- new ThreeVector3(-1, 1, 0),
15
- new ThreeVector3(-1, 1, 0),
13
+ new ThreeVector3(-1, 1, 0),
14
+ new ThreeVector3(-1, 1, 0),
16
15
 
17
- new ThreeVector3(1, -1, 0),
18
- new ThreeVector3(1, -1, 0),
16
+ new ThreeVector3(1, -1, 0),
17
+ new ThreeVector3(1, -1, 0),
19
18
 
20
- new ThreeVector3(1, 1, 0),
21
- new ThreeVector3(1, 1, 0)
22
- ];
19
+ new ThreeVector3(1, 1, 0),
20
+ new ThreeVector3(1, 1, 0)
21
+ ];
23
22
 
24
23
 
25
- /**
26
- *
27
- * @param {Number} nearZ
28
- * @param {Number} farZ
29
- * @param {THREE.Camera} camera
30
- * @param {THREE.Matrix4} matrixWorldInverse
31
- * @param {function} callback
32
- */
33
- function projectInWorldSpace(nearZ, farZ, camera, callback) {
34
- corners[0].set(-1, -1, nearZ);
35
- corners[1].set(-1, -1, farZ);
36
-
37
- corners[2].set(-1, 1, nearZ);
38
- corners[3].set(-1, 1, farZ);
39
-
40
- corners[4].set(1, -1, nearZ);
41
- corners[5].set(1, -1, farZ);
42
-
43
- corners[6].set(1, 1, nearZ);
44
- corners[7].set(1, 1, farZ);
45
-
46
- //compute corners of view frustum in light space
47
- let x0 = Number.POSITIVE_INFINITY;
48
- let y0 = Number.POSITIVE_INFINITY;
49
- let z0 = Number.POSITIVE_INFINITY;
50
-
51
- let x1 = Number.NEGATIVE_INFINITY;
52
- let y1 = Number.NEGATIVE_INFINITY;
53
- let z1 = Number.NEGATIVE_INFINITY;
54
-
55
-
56
- for (let i = 0; i < 8; i++) {
57
- const corner = corners[i];
58
- corner.unproject(camera);
59
-
60
- if (corner.x < x0) {
61
- x0 = corner.x;
62
- }
63
- if (corner.x > x1) {
64
- x1 = corner.x;
65
- }
66
-
67
- if (corner.y < y0) {
68
- y0 = corner.y;
69
- }
70
- if (corner.y > y1) {
71
- y1 = corner.y;
72
- }
73
-
74
- if (corner.z < z0) {
75
- z0 = corner.z;
76
- }
77
- if (corner.z > z1) {
78
- z1 = corner.z;
79
- }
80
- }
81
-
82
- callback(x0, y0, z0, x1, y1, z1);
83
- }
84
-
85
- return projectInWorldSpace;
86
- })();
87
-
88
- const project = (function () {
89
- const corners = [
90
- new ThreeVector3(-1, -1, 0),
91
- new ThreeVector3(-1, -1, 0),
92
-
93
- new ThreeVector3(-1, 1, 0),
94
- new ThreeVector3(-1, 1, 0),
95
-
96
- new ThreeVector3(1, -1, 0),
97
- new ThreeVector3(1, -1, 0),
98
-
99
- new ThreeVector3(1, 1, 0),
100
- new ThreeVector3(1, 1, 0)
101
- ];
102
-
103
-
104
- /**
105
- *
106
- * @param {Number} nearZ
107
- * @param {Number} farZ
108
- * @param {THREE.Camera} camera
109
- * @param {THREE.Matrix4} matrixWorldInverse
110
- * @param {AABB3} result
111
- */
112
- function project(nearZ, farZ, camera, matrixWorldInverse, result) {
113
- corners[0].set(-1, -1, nearZ);
114
- corners[1].set(-1, -1, farZ);
115
-
116
- corners[2].set(-1, 1, nearZ);
117
- corners[3].set(-1, 1, farZ);
118
-
119
- corners[4].set(1, -1, nearZ);
120
- corners[5].set(1, -1, farZ);
121
-
122
- corners[6].set(1, 1, nearZ);
123
- corners[7].set(1, 1, farZ);
124
-
125
- //compute corners of view frustum in light space
126
- let x0 = Number.POSITIVE_INFINITY;
127
- let y0 = Number.POSITIVE_INFINITY;
128
- let z0 = Number.POSITIVE_INFINITY;
129
-
130
- let x1 = Number.NEGATIVE_INFINITY;
131
- let y1 = Number.NEGATIVE_INFINITY;
132
- let z1 = Number.NEGATIVE_INFINITY;
133
-
134
-
135
- for (let i = 0; i < 8; i++) {
136
- const corner = corners[i];
137
- corner.unproject(camera);
138
- corner.applyMatrix4(matrixWorldInverse);
139
-
140
- if (corner.x < x0) {
141
- x0 = corner.x;
142
- }
143
- if (corner.x > x1) {
144
- x1 = corner.x;
145
- }
146
-
147
- if (corner.y < y0) {
148
- y0 = corner.y;
149
- }
150
- if (corner.y > y1) {
151
- y1 = corner.y;
152
- }
153
-
154
- if (corner.z < z0) {
155
- z0 = corner.z;
156
- }
157
- if (corner.z > z1) {
158
- z1 = corner.z;
159
- }
160
- }
161
-
162
- result.setBounds(x0, y0, z0, x1, y1, z1);
163
- }
164
-
165
- return project;
166
- })();
167
-
168
24
  /**
169
25
  *
170
- * @param _x0
171
- * @param _y0
172
- * @param _z0
173
- * @param _x1
174
- * @param _y1
175
- * @param _z1
176
- * @param {Camera} camera
177
- * @param callback
26
+ * @param {Number} nearZ
27
+ * @param {Number} farZ
28
+ * @param {THREE.Camera} camera
29
+ * @param {THREE.Matrix4} matrixWorldInverse
30
+ * @param {AABB3} result
178
31
  */
179
- function unproject(_x0, _y0, _z0, _x1, _y1, _z1, camera, callback) {
180
- const corners = [
181
- new ThreeVector3(_x0, _y0, _z0),
182
- new ThreeVector3(_x0, _y0, _z1),
32
+ function project(nearZ, farZ, camera, matrixWorldInverse, result) {
33
+ corners[0].set(-1, -1, nearZ);
34
+ corners[1].set(-1, -1, farZ);
183
35
 
184
- new ThreeVector3(_x0, _y1, _z0),
185
- new ThreeVector3(_x0, _y1, _z1),
36
+ corners[2].set(-1, 1, nearZ);
37
+ corners[3].set(-1, 1, farZ);
186
38
 
187
- new ThreeVector3(_x1, _y0, _z0),
188
- new ThreeVector3(_x1, _y0, _z1),
39
+ corners[4].set(1, -1, nearZ);
40
+ corners[5].set(1, -1, farZ);
189
41
 
190
- new ThreeVector3(_x1, _y1, _z0),
191
- new ThreeVector3(_x1, _y1, _z1)
192
- ];
42
+ corners[6].set(1, 1, nearZ);
43
+ corners[7].set(1, 1, farZ);
193
44
 
194
45
  //compute corners of view frustum in light space
195
46
  let x0 = Number.POSITIVE_INFINITY;
@@ -201,8 +52,10 @@ function unproject(_x0, _y0, _z0, _x1, _y1, _z1, camera, callback) {
201
52
  let z1 = Number.NEGATIVE_INFINITY;
202
53
 
203
54
 
204
- corners.forEach(function (corner) {
205
- corner.project(camera);
55
+ for (let i = 0; i < 8; i++) {
56
+ const corner = corners[i];
57
+ corner.unproject(camera);
58
+ corner.applyMatrix4(matrixWorldInverse);
206
59
 
207
60
  if (corner.x < x0) {
208
61
  x0 = corner.x;
@@ -224,19 +77,15 @@ function unproject(_x0, _y0, _z0, _x1, _y1, _z1, camera, callback) {
224
77
  if (corner.z > z1) {
225
78
  z1 = corner.z;
226
79
  }
227
- });
80
+ }
228
81
 
229
- callback(x0, y0, z0, x1, y1, z1);
82
+ result.setBounds(x0, y0, z0, x1, y1, z1);
230
83
  }
231
84
 
85
+
232
86
  export default {
233
87
  /**
234
88
  * @deprecated use non-threejs specific code
235
89
  */
236
90
  project,
237
- unproject,
238
- /**
239
- * @deprecated use non-threejs specific code
240
- */
241
- projectInWorldSpace
242
91
  };
@@ -3,28 +3,17 @@
3
3
  */
4
4
 
5
5
 
6
+ import { v3_normalize_array } from "../../../../core/geom/vec3/v3_normalize_array.js";
7
+
6
8
  /**
7
9
  *
8
- * @param {Array.<Number>} normals
10
+ * @param {Array.<number>} normals
9
11
  */
10
12
  function normalizeVectors(normals) {
11
- let x, y, z, n;
12
-
13
- let i = 0;
14
- const il = normals.length;
15
- for (; i < il; i += 3) {
13
+ const count = normals.length;
14
+ for (let i = 0; i < count; i += 3) {
16
15
 
17
- // extract vector components
18
- x = normals[i];
19
- y = normals[i + 1];
20
- z = normals[i + 2];
21
-
22
- // compute vector inverse magnitude
23
- n = 1.0 / Math.sqrt(x * x + y * y + z * z);
24
-
25
- normals[i] *= n;
26
- normals[i + 1] *= n;
27
- normals[i + 2] *= n;
16
+ v3_normalize_array(normals, i, normals, i);
28
17
 
29
18
  }
30
19
  }
@@ -32,11 +21,11 @@ function normalizeVectors(normals) {
32
21
  /**
33
22
  * based on code from THREE.js
34
23
  * normals need to be set to 0
35
- * @param {Array.<Number>} vertices
36
- * @param {Array.<Number>} normals
37
- * @param {Array.<Number>} indices
24
+ * @param {Array.<number>|Float32Array} vertices
25
+ * @param {Array.<number>|Float32Array} normals
26
+ * @param {Array.<number>|Uint32Array} indices
38
27
  */
39
- function computeVertexNormals(vertices, normals, indices) {
28
+ export function computeVertexNormals(vertices, normals, indices) {
40
29
  let vA, vB, vC;
41
30
 
42
31
  let vAx, vAy, vAz, vBx, vBy, vBz, vCx, vCy, vCz;
@@ -94,8 +83,4 @@ function computeVertexNormals(vertices, normals, indices) {
94
83
  }
95
84
 
96
85
  normalizeVectors(normals);
97
- }
98
-
99
- export default {
100
- computeNormals: computeVertexNormals
101
- };
86
+ }