@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.
Files changed (104) hide show
  1. package/core/assert.js +3 -1
  2. package/core/bvh2/traversal/__detailed_box_volume_intersection.js +11 -8
  3. package/core/collection/HashMap.js +66 -22
  4. package/core/geom/3d/CircleMath.js +4 -4
  5. package/core/geom/3d/cone/computeConeBoundingBox.js +4 -4
  6. package/core/geom/3d/{compute_bounding_cone_of_2_cones.js → cone/compute_bounding_cone_of_2_cones.js} +3 -3
  7. package/core/geom/3d/{compute_bounding_cone_of_2_cones.spec.js → cone/compute_bounding_cone_of_2_cones.spec.js} +1 -1
  8. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +1 -1
  9. package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +10 -2
  10. package/core/geom/3d/{encode_unit3_hemioct.js → normal/hemioct/encode_unit3_hemioct.js} +0 -0
  11. package/core/geom/3d/{unit_hemioct.spec.js → normal/hemioct/unit_hemioct.spec.js} +1 -1
  12. package/core/geom/3d/normal/lamber_azimuth/transform.js +61 -0
  13. package/core/geom/3d/normal/spherical/sphere_map_transform.js +77 -0
  14. package/core/geom/3d/{lerp_planes_to_array.js → plane/lerp_planes_to_array.js} +1 -3
  15. package/core/geom/3d/plane/plane3_lerp.js +3 -1
  16. package/core/geom/3d/plane/plane3_slerp.js +4 -1
  17. package/core/geom/3d/{plane_computeConvex3PlaneIntersection.js → plane/plane_computeConvex3PlaneIntersection.js} +14 -16
  18. package/core/geom/3d/topology/TopoTriangle.js +1 -1
  19. package/core/geom/3d/topology/TopoVertex.js +1 -1
  20. package/core/geom/3d/topology/bounds/computeTraingleClusterNormalBoundingCone.js +2 -2
  21. package/core/geom/3d/topology/simplify/compute_face_normal_change_dot_product.js +1 -1
  22. package/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +1 -1
  23. package/core/geom/3d/triangle/computeTrianglePlaneSide.js +1 -1
  24. package/core/geom/3d/triangle/computeTriangleRayIntersection.js +1 -1
  25. package/core/geom/3d/voxel/DenseBitVolume3D.js +87 -0
  26. package/core/geom/3d/voxel/buildVolumeFromProjectedGeometry.js +23 -0
  27. package/core/geom/LineSegment.js +3 -1
  28. package/core/geom/Matrix4.js +2 -1
  29. package/core/geom/Plane.js +15 -10
  30. package/core/geom/Quaternion.js +2 -1
  31. package/core/geom/Vector3.d.ts +2 -0
  32. package/core/geom/Vector3.js +33 -158
  33. package/core/geom/Vector3.spec.js +2 -1
  34. package/core/geom/v3_angle_between.js +31 -0
  35. package/core/geom/v3_distance.js +16 -0
  36. package/core/geom/v3_distance_sqr.js +17 -0
  37. package/core/geom/v3_dot.js +13 -0
  38. package/core/geom/v3_length.js +5 -0
  39. package/core/geom/v3_length_sqr.js +10 -0
  40. package/core/geom/v3_lerp.js +21 -0
  41. package/core/geom/v3_slerp.js +48 -0
  42. package/core/primitives/array/computeIntegerArrayHash.js +6 -1
  43. package/engine/asset/loaders/material/computeImageBitmapEquality.js +11 -0
  44. package/engine/asset/loaders/material/computeImageBitmapHash.js +22 -28
  45. package/engine/asset/loaders/material/computeMaterialHash.js +1 -2
  46. package/engine/asset/loaders/material/computeTextureEquality.js +13 -5
  47. package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +3 -1
  48. package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +3 -1
  49. package/engine/ecs/fow/FogOfWar.js +2 -3
  50. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +1 -1
  51. package/engine/ecs/systems/SteeringSystem.js +2 -1
  52. package/engine/ecs/terrain/ecs/Terrain.js +6 -0
  53. package/engine/ecs/terrain/ecs/layers/TerrainLayers.js +5 -0
  54. package/engine/ecs/terrain/ecs/splat/SplatMapping.js +5 -0
  55. package/engine/ecs/util/hideEntityGracefully.js +18 -0
  56. package/engine/graphics/GraphicsEngine.js +1 -0
  57. package/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
  58. package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
  59. package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +0 -53
  60. package/engine/graphics/ecs/path/testPathDisplaySystem.js +98 -98
  61. package/engine/graphics/ecs/trail2d/Trail2D.js +17 -4
  62. package/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts +2 -3
  63. package/engine/graphics/ecs/trail2d/Trail2DSystem.js +34 -118
  64. package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -1
  65. package/engine/graphics/micron/build/clustering/computeFaceCurvatureScore.js +1 -1
  66. package/engine/graphics/micron/build/clustering/compute_face_connection_weight.js +1 -1
  67. package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +1 -1
  68. package/engine/graphics/micron/build/hierarchy/patch_combine.js +1 -1
  69. package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +2 -2
  70. package/engine/graphics/particles/particular/engine/ParticularEngine.js +4 -2
  71. package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +20 -0
  72. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +40 -97
  73. package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +12 -2
  74. package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +37 -0
  75. package/engine/graphics/particles/particular/engine/emitter/distance_to_camera.js +25 -0
  76. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +7 -25
  77. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
  78. package/engine/graphics/render/forward_plus/LightManager.js +10 -2
  79. package/engine/graphics/render/forward_plus/computeFrustumCorners.js +15 -33
  80. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +12 -2
  81. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  82. package/engine/graphics/render/forward_plus/prototypeLightManager.js +96 -95
  83. package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +18 -6
  84. package/engine/graphics/render/layers/RenderLayerUtils.js +8 -5
  85. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +1 -1
  86. package/engine/graphics/texture/atlas/AtlasPatch.js +7 -2
  87. package/engine/graphics/texture/atlas/TextureAtlas.js +18 -14
  88. package/engine/graphics/texture/sampler/Sampler2D.js +8 -7
  89. package/engine/graphics/texture/sampler/scaleSampler2D.js +7 -10
  90. package/engine/graphics/trail/x/RibbonMaterialX.js +3 -3
  91. package/engine/graphics/trail/x/RibbonX.js +17 -2
  92. package/engine/graphics/trail/x/RibbonXPlugin.js +51 -1
  93. package/engine/graphics/util/projectSphere.js +1 -1
  94. package/engine/grid/components/GridObstacle.js +2 -9
  95. package/engine/navigation/ecs/components/Path.js +2 -1
  96. package/engine/network/convertPathToURL.js +2 -2
  97. package/engine/reference/v2/Reference.js +6 -0
  98. package/generation/filtering/numeric/complex/CellFilterAngleToNormal.js +3 -2
  99. package/generation/markers/GridCellActionPlaceMarker.js +13 -1
  100. package/generation/markers/MarkerNode.js +6 -0
  101. package/generation/theme/ThemeEngine.js +4 -1
  102. package/package.json +3 -3
  103. package/view/View.js +4 -2
  104. package/view/minimap/gl/MinimapMarkersGL.js +13 -1
package/core/assert.js CHANGED
@@ -332,7 +332,9 @@ assert.notNull = function (value, name = "value") {
332
332
  * @param {string} name
333
333
  */
334
334
  assert.notNaN = function (value, name = "value") {
335
- assert.ok(!Number.isNaN(value), `${name} must be a valid number, instead was NaN`);
335
+ if (Number.isNaN(value)) {
336
+ throw new Error(`${name} must be a valid number, instead was NaN`);
337
+ }
336
338
  };
337
339
 
338
340
  /**
@@ -4,9 +4,8 @@ import { computePointDistanceToPlane, plane3_computeLineSegmentIntersection } fr
4
4
  import { aabb3_corner_edge_mapping } from "../aabb3/aabb3_corner_edge_mapping.js";
5
5
  import { aabb3_edge_corner_mapping } from "../aabb3/aabb3_edge_corner_mapping.js";
6
6
  import { __process_point_if_within_planes } from "./__process_point_if_within_planes.js";
7
- import { plane_computeConvex3PlaneIntersection } from "../../geom/3d/plane_computeConvex3PlaneIntersection.js";
7
+ import { plane_computeConvex3PlaneIntersection } from "../../geom/3d/plane/plane_computeConvex3PlaneIntersection.js";
8
8
  import { EPSILON } from "../../math/MathUtils.js";
9
- import Vector3 from "../../geom/Vector3.js";
10
9
 
11
10
  /**
12
11
  *
@@ -26,7 +25,11 @@ const scratch_aabb_planes = new Float32Array(24);
26
25
  */
27
26
  const scratch_corner_out_bitfields = new Uint32Array(8);
28
27
 
29
- const scratch_v3 = new Vector3();
28
+ /**
29
+ *
30
+ * @type {number[]}
31
+ */
32
+ const scratch_v3_array = new Float32Array(3);
30
33
 
31
34
  /**
32
35
  *
@@ -183,7 +186,7 @@ export function __detailed_box_volume_intersection(
183
186
  const c = planes[plane_address + 3];
184
187
 
185
188
  const edge_intersects = plane3_computeLineSegmentIntersection(
186
- scratch_v3,
189
+ scratch_v3_array, 0,
187
190
  corner_0_x, corner_0_y, corner_0_z,
188
191
  corner_1_x, corner_1_y, corner_1_z,
189
192
  nx, ny, nz, c
@@ -192,7 +195,7 @@ export function __detailed_box_volume_intersection(
192
195
  if (edge_intersects) {
193
196
  // a possible candidate, let's see if this point is within rest of the planes
194
197
  __process_point_if_within_planes(
195
- scratch_v3.x, scratch_v3.y, scratch_v3.z,
198
+ scratch_v3_array[0], scratch_v3_array[1], scratch_v3_array[2],
196
199
  (plane_mask ^ plane_bit_mask),
197
200
  planes,
198
201
  plane_count,
@@ -230,7 +233,7 @@ export function __detailed_box_volume_intersection(
230
233
  const cp_1 = next_orthogonal_plane_index * 4;
231
234
 
232
235
  const intersection_exists = plane_computeConvex3PlaneIntersection(
233
- scratch_v3,
236
+ scratch_v3_array, 0,
234
237
  aabb_plane_nx, aabb_plane_ny, aabb_plane_nz, aabb_plane_constant,
235
238
  planes[cp_0], planes[cp_0 + 1], planes[cp_0 + 2], planes[cp_0 + 3],
236
239
  planes[cp_1], planes[cp_1 + 1], planes[cp_1 + 2], planes[cp_1 + 3]
@@ -238,14 +241,14 @@ export function __detailed_box_volume_intersection(
238
241
 
239
242
  if (intersection_exists) {
240
243
 
241
- const point_within_box = box.containsPointWithTolerance(scratch_v3.x, scratch_v3.y, scratch_v3.z, EPSILON);
244
+ const point_within_box = box.containsPointWithTolerance(scratch_v3_array[0], scratch_v3_array[1], scratch_v3_array[2], EPSILON);
242
245
 
243
246
  if (point_within_box) {
244
247
  // point is within the AABB bounds
245
248
 
246
249
  // ThreeClippingPlaneComputingBVHVisitor.DEBUG_POINTS_2.send3(scratch_v3.x, scratch_v3.y, scratch_v3.z);
247
250
 
248
- callback.call(thisArg, scratch_v3.x, scratch_v3.y, scratch_v3.z);
251
+ callback.call(thisArg, scratch_v3_array[0], scratch_v3_array[1], scratch_v3_array[2]);
249
252
  }
250
253
  }
251
254
  }
@@ -26,6 +26,18 @@ class MapEntry {
26
26
  }
27
27
  }
28
28
 
29
+ /**
30
+ * @readonly
31
+ * @type {number}
32
+ */
33
+ const DEFAULT_INITIAL_CAPACITY = 16;
34
+
35
+ /**
36
+ * @readonly
37
+ * @type {number}
38
+ */
39
+ const DEFAULT_LOAD_FACTOR = 0.75;
40
+
29
41
  /**
30
42
  * Implements part of {@link Map} interface
31
43
  * @template K,V
@@ -36,10 +48,14 @@ export class HashMap {
36
48
  * @template K, V
37
49
  * @param {function(K):number} [keyHashFunction]
38
50
  * @param {function(K,K):boolean} [keyEqualityFunction]
51
+ * @param {number} [capacity] initial number of buckets in the hash table
52
+ * @param {number} [loadFactor] a measure of how full the hash table is allowed to get before its capacity is automatically increased
39
53
  */
40
54
  constructor({
41
55
  keyHashFunction = invokeObjectHash,
42
- keyEqualityFunction = invokeObjectEquals
56
+ keyEqualityFunction = invokeObjectEquals,
57
+ capacity = DEFAULT_INITIAL_CAPACITY,
58
+ loadFactor = DEFAULT_LOAD_FACTOR
43
59
  } = {}) {
44
60
  assert.typeOf(keyHashFunction, 'function', 'keyHashFunction');
45
61
  assert.typeOf(keyEqualityFunction, 'function', 'keyEqualityFunction');
@@ -69,14 +85,21 @@ export class HashMap {
69
85
  * @type {number}
70
86
  * @private
71
87
  */
72
- this.__bucket_count = 16384;
88
+ this.__bucket_count = capacity;
89
+
90
+ /**
91
+ * How full the table can get before number of buckets is increased
92
+ * @type {number}
93
+ * @private
94
+ */
95
+ this.__load_factor = loadFactor;
73
96
  }
74
97
 
75
98
  /**
76
99
  * Proportion between actual number of records in the map and the bucket count (number of potential hashes)
77
100
  * @returns {number}
78
101
  */
79
- getLoadFactor() {
102
+ getCurrentLoad() {
80
103
  return this.size / this.__bucket_count;
81
104
  }
82
105
 
@@ -133,7 +156,7 @@ export class HashMap {
133
156
  this.__bucket_count = count;
134
157
  if (this.size > 0) {
135
158
  // re-hash
136
- this.updateHashes();
159
+ this.rebuild();
137
160
  }
138
161
  }
139
162
 
@@ -167,31 +190,49 @@ export class HashMap {
167
190
  let bucket = this.records[bucket_index];
168
191
 
169
192
  if (bucket === undefined) {
170
- bucket = [new MapEntry(key, value)];
193
+
194
+ // bucket for this value doesn't exist
195
+
196
+ bucket = [];
197
+
171
198
  this.records[bucket_index] = bucket;
172
199
 
173
- this.size++;
200
+ } else {
174
201
 
175
- return;
176
- }
202
+ // bucket exists
177
203
 
178
- const bucketSize = bucket.length;
204
+ const bucketSize = bucket.length;
179
205
 
180
- //check if key already exists
181
- for (let i = 0; i < bucketSize; i++) {
182
- const entry = bucket[i];
206
+ //check if key already exists
207
+ for (let i = 0; i < bucketSize; i++) {
208
+ const entry = bucket[i];
183
209
 
184
- const entryKey = entry.key;
185
- if (entryKey === key || this.keyEqualityFunction(entryKey, key)) {
210
+ const entryKey = entry.key;
186
211
 
187
- entry.value = value;
188
- return;
212
+ if (entryKey === key || this.keyEqualityFunction(entryKey, key)) {
213
+
214
+ entry.value = value;
215
+ return;
216
+
217
+ }
189
218
 
190
219
  }
220
+
191
221
  }
192
222
 
193
223
  bucket.push(new MapEntry(key, value));
194
- this.size++;
224
+
225
+ const old_size = this.size;
226
+ const new_size = old_size + 1;
227
+ this.size = new_size;
228
+
229
+ // compute actual current load
230
+ const load = new_size / this.__bucket_count;
231
+
232
+ if (load > this.__load_factor) {
233
+ // increase table size
234
+ this.setBucketCount(this.__bucket_count * 2);
235
+ }
195
236
  }
196
237
 
197
238
  /**
@@ -308,20 +349,22 @@ export class HashMap {
308
349
  }
309
350
 
310
351
  /**
311
- *
352
+ * Rebuild table, useful for when table is resized or hashes of stored keys change
312
353
  */
313
- updateHashes() {
354
+ rebuild() {
314
355
 
315
356
  let h, i, l;
316
357
 
317
358
  const records = this.records;
318
359
 
319
360
  for (h in records) {
361
+ const stored_bucket_index = parseInt(h);
362
+
320
363
  if (!records.hasOwnProperty(h)) {
321
364
  continue;
322
365
  }
323
366
 
324
- const bucket = records[h];
367
+ const bucket = records[stored_bucket_index];
325
368
 
326
369
  for (i = 0, l = bucket.length; i < l; i++) {
327
370
  /**
@@ -333,7 +376,6 @@ export class HashMap {
333
376
  const raw_hash = this.keyHashFunction(entry.key);
334
377
  const actual_bucket_index = this.__compute_bucket_index(raw_hash);
335
378
 
336
- const stored_bucket_index = parseInt(h);
337
379
 
338
380
  if (actual_bucket_index !== stored_bucket_index) {
339
381
  //remove entry from the bucket
@@ -345,15 +387,17 @@ export class HashMap {
345
387
 
346
388
  if (bucket.length === 0) {
347
389
  //delete empty bucket
348
- delete records[h];
390
+ delete records[stored_bucket_index];
349
391
  }
350
392
 
351
393
  const newBucket = records[actual_bucket_index];
394
+
352
395
  if (newBucket === undefined) {
353
396
  records[actual_bucket_index] = [entry];
354
397
  } else {
355
398
  newBucket.push(entry);
356
399
  }
400
+
357
401
  }
358
402
  }
359
403
  }
@@ -1,4 +1,4 @@
1
- import { v3_angleBetween } from "../Vector3.js";
1
+ import { v3_angle_between } from "../v3_angle_between.js";
2
2
 
3
3
  /**
4
4
  * NOTE: based on https://stackoverflow.com/questions/2592011/bounding-boxes-for-circle-and-arcs-in-3d
@@ -12,9 +12,9 @@ import { v3_angleBetween } from "../Vector3.js";
12
12
  * @param {number} radius
13
13
  */
14
14
  export function computeCircleBoundingBox(result, centerX, centerY, centerZ, normalX, normalY, normalZ, radius) {
15
- const ax = v3_angleBetween(normalX, normalY, normalZ, 1, 0, 0);
16
- const ay = v3_angleBetween(normalX, normalY, normalZ, 0, 1, 0);
17
- const az = v3_angleBetween(normalX, normalY, normalZ, 0, 0, 1);
15
+ const ax = v3_angle_between(normalX, normalY, normalZ, 1, 0, 0);
16
+ const ay = v3_angle_between(normalX, normalY, normalZ, 0, 1, 0);
17
+ const az = v3_angle_between(normalX, normalY, normalZ, 0, 0, 1);
18
18
 
19
19
  const rX = Math.sin(ax) * radius;
20
20
  const rY = Math.sin(ay) * radius;
@@ -1,6 +1,6 @@
1
1
  import { max2 } from "../../../math/max2.js";
2
2
  import { min2 } from "../../../math/min2.js";
3
- import { v3_angleBetween } from "../../Vector3.js";
3
+ import { v3_angle_between } from "../../v3_angle_between.js";
4
4
 
5
5
  /**
6
6
  * NOTE: used stackoverflow answer as a basis for circle part: https://stackoverflow.com/questions/2592011/bounding-boxes-for-circle-and-arcs-in-3d
@@ -15,9 +15,9 @@ import { v3_angleBetween } from "../../Vector3.js";
15
15
  * @param {number} length
16
16
  */
17
17
  export function computeConeBoundingBox(result, originX, originY, originZ, directionX, directionY, directionZ, angle, length) {
18
- const ax = v3_angleBetween(directionX, directionY, directionZ, 1, 0, 0);
19
- const ay = v3_angleBetween(directionX, directionY, directionZ, 0, 1, 0);
20
- const az = v3_angleBetween(directionX, directionY, directionZ, 0, 0, 1);
18
+ const ax = v3_angle_between(directionX, directionY, directionZ, 1, 0, 0);
19
+ const ay = v3_angle_between(directionX, directionY, directionZ, 0, 1, 0);
20
+ const az = v3_angle_between(directionX, directionY, directionZ, 0, 0, 1);
21
21
 
22
22
  //compute radius of the base of the cone
23
23
  const radius = length * Math.tan(angle);
@@ -1,9 +1,9 @@
1
1
  //
2
2
 
3
3
 
4
- import Vector3 from "../Vector3.js";
5
- import Quaternion, { quat3_createFromAxisAngle } from "../Quaternion.js";
6
- import { max2 } from "../../math/max2.js";
4
+ import Vector3 from "../../Vector3.js";
5
+ import Quaternion, { quat3_createFromAxisAngle } from "../../Quaternion.js";
6
+ import { max2 } from "../../../math/max2.js";
7
7
 
8
8
  const tangent = new Vector3();
9
9
 
@@ -1,5 +1,5 @@
1
1
  import { compute_bounding_cone_of_2_cones } from "./compute_bounding_cone_of_2_cones.js";
2
- import { ConicRay } from "../ConicRay.js";
2
+ import { ConicRay } from "../../ConicRay.js";
3
3
 
4
4
  /**
5
5
  *
@@ -1,4 +1,4 @@
1
- import { v3_length } from "../../Vector3.js";
1
+ import { v3_length } from "../../v3_length.js";
2
2
 
3
3
  /**
4
4
  *
@@ -2,7 +2,7 @@ import { ray_computeNearestPointToPoint } from "../../LineSegment.js";
2
2
  import { computePlanePlaneIntersection, computePointDistanceToPlane } from "../../Plane.js";
3
3
  import Vector3 from "../../Vector3.js";
4
4
  import { plane3_projectPoint } from "../plane/plane3_projectPoint.js";
5
- import { plane_three_computeConvex3PlaneIntersection } from "../plane_computeConvex3PlaneIntersection.js";
5
+ import { plane_three_computeConvex3PlaneIntersection } from "../plane/plane_computeConvex3PlaneIntersection.js";
6
6
 
7
7
  /**
8
8
  *
@@ -14,6 +14,12 @@ const scratch_v3_0 = new Vector3();
14
14
 
15
15
  const scratch_v3_1 = new Vector3();
16
16
 
17
+ /**
18
+ *
19
+ * @type {number[]}
20
+ */
21
+ const scratch_v3_array = [];
22
+
17
23
  /**
18
24
  *
19
25
  * @param {Vector3} result
@@ -94,7 +100,9 @@ export function frustum3_computeNearestPointToPoint(result, planes, target_x, ta
94
100
  const plane_1 = planes[plane_1_index];
95
101
  const plane_2 = planes[plane_2_index];
96
102
 
97
- plane_three_computeConvex3PlaneIntersection(result, plane_0, plane_1, plane_2);
103
+ plane_three_computeConvex3PlaneIntersection(scratch_v3_array, 0, plane_0, plane_1, plane_2);
104
+
105
+ result.readFromArray(scratch_v3_array, 0)
98
106
  }
99
107
 
100
108
  return false;
@@ -1,5 +1,5 @@
1
1
  import { decode_hemioct_to_unit, encode_unit_to_hemioct } from "./encode_unit3_hemioct.js";
2
- import { v3_length } from "../Vector3.d.ts";
2
+ import { v3_length } from "../../../Vector3.d.ts";
3
3
 
4
4
  test('encode-decode', () => {
5
5
  const v0 = [];
@@ -0,0 +1,61 @@
1
+ import { v2_dot } from "../../../Vector2.js";
2
+
3
+ /*
4
+ @source https://aras-p.info/texts/CompactNormalStorage.html
5
+ @source https://en.wikipedia.org/wiki/Lambert_azimuthal_equal-area_projection
6
+
7
+ half2 encode (half3 n, float3 view)
8
+ {
9
+ half f = sqrt(8*n.z+8);
10
+ return n.xy / f + 0.5;
11
+ }
12
+ half3 decode (half4 enc, float3 view)
13
+ {
14
+ half2 fenc = enc*4-2;
15
+ half f = dot(fenc,fenc);
16
+ half g = sqrt(1-f/4);
17
+ half3 n;
18
+ n.xy = fenc*g;
19
+ n.z = 1-f/2;
20
+ return n;
21
+ }
22
+ */
23
+
24
+ /**
25
+ *
26
+ * @param {number[]} output
27
+ * @param {number} output_offset
28
+ * @param {number} x
29
+ * @param {number} y
30
+ * @param {number} z
31
+ */
32
+ export function encode_unit_to_azimuth(output, output_offset, x, y, z) {
33
+ const f = Math.sqrt(8 * z + 8);
34
+
35
+ output[output_offset] = x / f + 0.5;
36
+ output[output_offset + 1] = y / f + 0.5;
37
+ }
38
+
39
+ /**
40
+ *
41
+ * @param {number[]} output
42
+ * @param {number} output_offset
43
+ * @param {number} x range [-1,1]
44
+ * @param {number} y range [-1,1]
45
+ */
46
+ export function decode_azimuth_to_unit(output, output_offset, x, y) {
47
+ const fenc_x = x * 4 - 2;
48
+ const fenc_y = y * 4 - 2;
49
+
50
+ const f = v2_dot(fenc_x, fenc_y, fenc_x, fenc_y);
51
+
52
+ const g = Math.sqrt(1 - f / 4);
53
+
54
+ const n_x = fenc_x * g;
55
+ const n_y = fenc_y * g;
56
+ const n_z = 1 - f / 2;
57
+
58
+ output[output_offset] = n_x;
59
+ output[output_offset + 1] = n_y;
60
+ output[output_offset + 2] = n_z;
61
+ }
@@ -0,0 +1,77 @@
1
+ import { v2_magnitude } from "../../../Vector2.js";
2
+ import { v3_dot } from "../../../v3_dot.js";
3
+
4
+ /*
5
+ @source https://aras-p.info/texts/CompactNormalStorage.html#method04spheremap
6
+ @source Siggraph 99
7
+ @source Cry Engine 3, presented by Martin Mittring in "A bit more Deferred"
8
+
9
+ half2 encode (half3 n, float3 view)
10
+ {
11
+ half2 enc = normalize(n.xy) * (sqrt(-n.z*0.5+0.5));
12
+ enc = enc*0.5+0.5;
13
+ return enc;
14
+ }
15
+ half3 decode (half4 enc, float3 view)
16
+ {
17
+ half4 nn = enc*half4(2,2,0,0) + half4(-1,-1,1,-1);
18
+ half l = dot(nn.xyz,-nn.xyw);
19
+ nn.z = l;
20
+ nn.xy *= sqrt(l);
21
+ return nn.xyz * 2 + half3(0,0,-1);
22
+ }
23
+ */
24
+
25
+
26
+ /**
27
+ * Encode v3 to v2
28
+ * @param {number[]} output
29
+ * @param {number} output_offset
30
+ * @param {number} x
31
+ * @param {number} y
32
+ * @param {number} z
33
+ */
34
+ export function encode_unit_to_spheremap(output, output_offset, x, y, z) {
35
+ const length_xy = v2_magnitude(x, y);
36
+
37
+ const norm_xy_x = x / length_xy;
38
+ const norm_xy_y = y / length_xy;
39
+
40
+ const z_factor = Math.sqrt(-z * 0.5 - 0.5) * 0.5;
41
+
42
+ const enc_x = norm_xy_x * z_factor + 0.5;
43
+ const enc_y = norm_xy_y * z_factor + 0.5;
44
+
45
+ output[output_offset] = enc_x;
46
+ output[output_offset + 1] = enc_y;
47
+ }
48
+
49
+ /**
50
+ * @param {number[]} output
51
+ * @param {number} output_offset
52
+ * @param {number} x range [-1,1]
53
+ * @param {number} y range [-1,1]
54
+ */
55
+ function decode_spheremap_to_unit(output, output_offset, x, y) {
56
+ const nn4_x = x * 2 - 1;
57
+ const nn4_y = y * 2 - 1;
58
+ const nn4_z = 1;
59
+ const nn4_w = -1;
60
+
61
+ const l = v3_dot(nn4_x, nn4_y, nn4_z, -nn4_x, -nn4_y, -nn4_w);
62
+
63
+ const nn_z = l;
64
+
65
+ const l_sqrt = Math.sqrt(l);
66
+
67
+ const nn_x = nn4_x * l_sqrt;
68
+ const nn_y = nn4_y * l_sqrt;
69
+
70
+ const _x = nn_x * 2;
71
+ const _y = nn_y * 2;
72
+ const _z = nn_z * 2 - 1;
73
+
74
+ output[output_offset] = _x;
75
+ output[output_offset + 1] = _y;
76
+ output[output_offset + 2] = _z;
77
+ }
@@ -1,6 +1,4 @@
1
- import Vector3, { v3_dot } from "../Vector3.js";
2
-
3
- const t_v3 = new Vector3();
1
+ import { v3_dot } from "../../v3_dot.js";
4
2
 
5
3
  /**
6
4
  * Calculate a plane that is a linear interpolation between two other planes A and B with interpolation factor between 0 and 1
@@ -1,6 +1,8 @@
1
1
  import { lerp } from "../../../math/lerp.js";
2
- import Vector3, { v3_dot, v3_length } from "../../Vector3.js";
2
+ import Vector3 from "../../Vector3.js";
3
3
  import { plane3_intersect_plane } from "./plane3_intersect_plane.js";
4
+ import { v3_dot } from "../../v3_dot.js";
5
+ import { v3_length } from "../../v3_length.js";
4
6
 
5
7
  const v0 = new Vector3();
6
8
  const v1 = new Vector3();
@@ -1,6 +1,9 @@
1
1
  import { lerp } from "../../../math/lerp.js";
2
2
  import { EPSILON } from "../../../math/MathUtils.js";
3
- import Vector3, { v3_dot, v3_length_sqr, v3_slerp } from "../../Vector3.js";
3
+ import Vector3 from "../../Vector3.js";
4
+ import { v3_dot } from "../../v3_dot.js";
5
+ import { v3_length_sqr } from "../../v3_length_sqr.js";
6
+ import { v3_slerp } from "../../v3_slerp.js";
4
7
 
5
8
  const e = new Vector3();
6
9
 
@@ -1,21 +1,22 @@
1
- import { v3_dot } from "../Vector3.js";
2
-
1
+ import { v3_dot } from "../../v3_dot.js";
3
2
 
4
3
  /**
5
4
  *
6
- * @param {Vector3} result
5
+ * @param {number[]} result
6
+ * @param {number} result_offset
7
7
  * @param {Plane} a
8
8
  * @param {Plane} b
9
9
  * @param {Plane} c
10
10
  * @returns {boolean}
11
11
  */
12
- export function plane_three_computeConvex3PlaneIntersection(result, a, b, c) {
12
+ export function plane_three_computeConvex3PlaneIntersection(result, result_offset, a, b, c) {
13
13
  const a_normal = a.normal;
14
14
  const b_normal = b.normal;
15
15
  const c_normal = c.normal;
16
16
 
17
17
  return plane_computeConvex3PlaneIntersection(
18
18
  result,
19
+ result_offset,
19
20
  a_normal.x, a_normal.y, a_normal.z, a.constant,
20
21
  b_normal.x, b_normal.y, b_normal.z, b.constant,
21
22
  c_normal.x, c_normal.y, c_normal.z, c.constant,
@@ -24,7 +25,8 @@ export function plane_three_computeConvex3PlaneIntersection(result, a, b, c) {
24
25
 
25
26
  /**
26
27
  * NOTE: Based on Intersection of 3 planes, Graphics Gems 1 pg 305
27
- * @param {Vector3} result
28
+ * @param {Float32Array|number[]|vec3} result
29
+ * @param {number} result_offset
28
30
  * @param {number} a_normal_x
29
31
  * @param {number} a_normal_y
30
32
  * @param {number} a_normal_z
@@ -40,7 +42,7 @@ export function plane_three_computeConvex3PlaneIntersection(result, a, b, c) {
40
42
  * @returns {boolean} true if planes intersect, false otherwise
41
43
  */
42
44
  export function plane_computeConvex3PlaneIntersection(
43
- result,
45
+ result, result_offset,
44
46
  a_normal_x, a_normal_y, a_normal_z, a_constant,
45
47
  b_normal_x, b_normal_y, b_normal_z, b_constant,
46
48
  c_normal_x, c_normal_y, c_normal_z, c_constant
@@ -75,18 +77,14 @@ export function plane_computeConvex3PlaneIntersection(
75
77
  const d = 1 / determinant;
76
78
 
77
79
  const neg_a_constant = -a_constant;
78
- const neg_b_constant = -b_constant;
79
- const neg_c_constant = -c_constant;
80
80
 
81
- const x = (bxc_x * neg_a_constant + cxa_x * neg_b_constant + axb_x * neg_c_constant) * d;
82
- const y = (bxc_y * neg_a_constant + cxa_y * neg_b_constant + axb_y * neg_c_constant) * d;
83
- const z = (bxc_z * neg_a_constant + cxa_z * neg_b_constant + axb_z * neg_c_constant) * d;
81
+ const x = (bxc_x * neg_a_constant - cxa_x * b_constant - axb_x * c_constant) * d;
82
+ const y = (bxc_y * neg_a_constant - cxa_y * b_constant - axb_y * c_constant) * d;
83
+ const z = (bxc_z * neg_a_constant - cxa_z * b_constant - axb_z * c_constant) * d;
84
84
 
85
- result.set(
86
- x,
87
- y,
88
- z
89
- );
85
+ result[result_offset] = x;
86
+ result[result_offset + 1] = y;
87
+ result[result_offset + 2] = z;
90
88
 
91
89
  return true;
92
90
  }
@@ -1,9 +1,9 @@
1
- import { v3_length } from "../../Vector3.js";
2
1
  import { array_replace_all } from "../../../collection/array/array_replace_all.js";
3
2
  import { array_push_if_unique } from "../../../collection/array/array_push_if_unique.js";
4
3
  import { assert } from "../../../assert.js";
5
4
  import { array_remove_first } from "../../../collection/array/array_remove_first.js";
6
5
  import { vec3 } from "gl-matrix";
6
+ import { v3_length } from "../../v3_length.js";
7
7
 
8
8
  /**
9
9
  *
@@ -1,7 +1,7 @@
1
- import { v3_distance } from "../../Vector3.js";
2
1
  import { assert } from "../../../assert.js";
3
2
  import { array_push_if_unique } from "../../../collection/array/array_push_if_unique.js";
4
3
  import { array_remove_first } from "../../../collection/array/array_remove_first.js";
4
+ import { v3_distance } from "../../v3_distance.js";
5
5
 
6
6
  export class TopoVertex {
7
7
  constructor() {
@@ -1,9 +1,9 @@
1
1
  import { Miniball } from "../../../packing/miniball/Miniball.js";
2
2
  import { PointSet } from "../../../packing/miniball/PointSet.js";
3
3
  import { ConicRay } from "../../../ConicRay.js";
4
- import { v3_angleBetween } from "../../../Vector3.js";
5
4
  import { array_copy } from "../../../../collection/array/copyArray.js";
6
5
  import { min2 } from "../../../../math/min2.js";
6
+ import { v3_angle_between } from "../../../v3_angle_between.js";
7
7
 
8
8
  /**
9
9
  * Using Shirman and Abi-Ezzi method, compute bounding sphere of points, then build a cone from that
@@ -66,7 +66,7 @@ export function computeTraingleClusterNormalBoundingCone(result, faces) {
66
66
  const normal_y = normal_data[i3];
67
67
  const normal_z = normal_data[i3];
68
68
 
69
- const angle = v3_angleBetween(
69
+ const angle = v3_angle_between(
70
70
  normal_x, normal_y, normal_z,
71
71
  result_direction.x, result_direction.y, result_direction.z
72
72
  );
@@ -1,4 +1,4 @@
1
- import { v3_dot } from "../../../Vector3.js";
1
+ import { v3_dot } from "../../../v3_dot.js";
2
2
 
3
3
  /**
4
4
  * Used to detect face normal flips for mesh optimization.