@woosh/meep-engine 2.109.24 → 2.109.26

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 (93) hide show
  1. package/build/meep.cjs +248 -117
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +248 -117
  4. package/package.json +1 -1
  5. package/src/core/collection/heap/{FastBinaryHeap.d.ts → BinaryHeap.d.ts} +16 -9
  6. package/src/core/collection/heap/BinaryHeap.d.ts.map +1 -0
  7. package/src/core/collection/heap/{FastBinaryHeap.js → BinaryHeap.js} +31 -21
  8. package/src/core/collection/heap/BinaryHeap.spec.d.ts +2 -0
  9. package/src/core/collection/heap/BinaryHeap.spec.d.ts.map +1 -0
  10. package/src/core/collection/heap/{FastBinaryHeap.spec.js → BinaryHeap.spec.js} +1 -1
  11. package/src/core/collection/heap/Uint32Heap.spec.d.ts +2 -0
  12. package/src/core/collection/heap/Uint32Heap.spec.d.ts.map +1 -0
  13. package/src/core/collection/table/RowFirstTable.d.ts +10 -7
  14. package/src/core/collection/table/RowFirstTable.d.ts.map +1 -1
  15. package/src/core/collection/table/RowFirstTable.js +23 -6
  16. package/src/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.js +2 -2
  17. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.d.ts +1 -0
  18. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.d.ts.map +1 -1
  19. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.js +5 -5
  20. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.d.ts.map +1 -1
  21. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +14 -8
  22. package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +1 -1
  23. package/src/core/graph/Edge.d.ts +1 -0
  24. package/src/core/graph/Edge.d.ts.map +1 -1
  25. package/src/core/graph/Edge.js +5 -0
  26. package/src/core/graph/graph_compute_distance_matrix.js +2 -2
  27. package/src/core/graph/metis/cluster_mesh_metis.d.ts +9 -0
  28. package/src/core/graph/metis/cluster_mesh_metis.d.ts.map +1 -0
  29. package/src/core/graph/metis/cluster_mesh_metis.js +31 -0
  30. package/src/core/graph/metis/mesh_to_metis_graph.d.ts +10 -0
  31. package/src/core/graph/metis/mesh_to_metis_graph.d.ts.map +1 -0
  32. package/src/core/graph/metis/mesh_to_metis_graph.js +64 -0
  33. package/src/core/graph/metis/metis_cluster_bs.d.ts +12 -0
  34. package/src/core/graph/metis/metis_cluster_bs.d.ts.map +1 -0
  35. package/src/core/graph/{cluster_mesh_metis.js → metis/metis_cluster_bs.js} +12 -98
  36. package/src/core/graph/mn_graph_coarsen.d.ts.map +1 -1
  37. package/src/core/graph/mn_graph_coarsen.js +7 -3
  38. package/src/core/graph/mn_graph_coarsen.spec.js +2 -0
  39. package/src/engine/animation/async/TimeSeries.d.ts.map +1 -1
  40. package/src/engine/animation/async/TimeSeries.js +6 -2
  41. package/src/engine/animation/async/table_find_min_index_in_ordered_column.d.ts +9 -0
  42. package/src/engine/animation/async/table_find_min_index_in_ordered_column.d.ts.map +1 -0
  43. package/src/engine/animation/async/{findSampleIndex.js → table_find_min_index_in_ordered_column.js} +5 -4
  44. package/src/engine/asset/AssetManager.js +2 -2
  45. package/src/engine/graphics/sh3/gi/material/common.glsl +46 -55
  46. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.d.ts.map +1 -1
  47. package/src/engine/graphics/sh3/gi/material/makeOctahedralDepthAtlas.js +5 -3
  48. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +1 -1
  49. package/src/engine/graphics/sh3/lpv/LightProbeVolumeBaker.js +1 -1
  50. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
  51. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +3 -2
  52. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
  53. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +19 -7
  54. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/visualise.frag.glsl +17 -15
  55. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  56. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +6 -2
  57. package/src/engine/graphics/sh3/lpv/serialization/LightProbeVolumeSerializationAdapter.js +2 -2
  58. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  59. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +10 -0
  60. package/src/engine/graphics/sh3/prototypeSH3Probe.js +3 -3
  61. package/src/engine/input/devices/InputDeviceSwitch.d.ts.map +1 -1
  62. package/src/engine/input/devices/InputDeviceSwitch.js +18 -0
  63. package/src/engine/input/devices/KeyboardDevice.d.ts.map +1 -1
  64. package/src/engine/input/devices/KeyboardDevice.js +4 -41
  65. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts +11 -0
  66. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts.map +1 -0
  67. package/src/engine/input/devices/LocationalInteractionMetadata.js +18 -0
  68. package/src/engine/input/devices/PointerDevice.d.ts.map +1 -1
  69. package/src/engine/input/devices/PointerDevice.js +90 -37
  70. package/src/engine/input/devices/events/eventToSourceIdentifier.d.ts +7 -0
  71. package/src/engine/input/devices/events/eventToSourceIdentifier.d.ts.map +1 -0
  72. package/src/engine/input/devices/events/eventToSourceIdentifier.js +36 -0
  73. package/src/engine/input/devices/isHTMLElementFocusable.d.ts +6 -0
  74. package/src/engine/input/devices/isHTMLElementFocusable.d.ts.map +1 -0
  75. package/src/engine/input/devices/isHTMLElementFocusable.js +34 -0
  76. package/src/engine/network/PriorityFetch.d.ts.map +1 -1
  77. package/src/engine/network/PriorityFetch.js +2 -2
  78. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +1 -1
  79. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.d.ts.map +1 -1
  80. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js +4 -4
  81. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.d.ts.map +1 -1
  82. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.js +2 -2
  83. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +1 -1
  84. package/src/core/collection/heap/FastBinaryHeap.d.ts.map +0 -1
  85. package/src/core/collection/heap/FastBinaryHeap.spec.d.ts +0 -2
  86. package/src/core/collection/heap/FastBinaryHeap.spec.d.ts.map +0 -1
  87. package/src/core/collection/heap/Uin32Heap.spec.d.ts +0 -2
  88. package/src/core/collection/heap/Uin32Heap.spec.d.ts.map +0 -1
  89. package/src/core/graph/cluster_mesh_metis.d.ts +0 -28
  90. package/src/core/graph/cluster_mesh_metis.d.ts.map +0 -1
  91. package/src/engine/animation/async/findSampleIndex.d.ts +0 -9
  92. package/src/engine/animation/async/findSampleIndex.d.ts.map +0 -1
  93. /package/src/core/collection/heap/{Uin32Heap.spec.js → Uint32Heap.spec.js} +0 -0
@@ -168,6 +168,14 @@ float lpv_bilinear_lerp(float v00, float v01, float v10, float v11, vec2 fractio
168
168
  return mix(x0, x1, fraction.y);
169
169
  }
170
170
 
171
+ vec2 lpv_bilinear_lerp(vec2 v00, vec2 v01, vec2 v10, vec2 v11, vec2 fraction) {
172
+
173
+ vec2 x0 = mix(v00, v01, fraction.x);
174
+ vec2 x1 = mix(v10, v11, fraction.x);
175
+
176
+ return mix(x0, x1, fraction.y);
177
+ }
178
+
171
179
  vec2 lpv_sample_bilinear(sampler2D tex, ivec2 texel_position, vec2 fraction) {
172
180
 
173
181
  float texel_00 = texelFetch(tex, texel_position, 0).r;
@@ -264,22 +272,16 @@ vec2 lpv_probe_getDepthBilinear(uint probe_index, vec3 direction) {
264
272
  tile_p_10 = wrapOctahedralTexelCoordinates(texel_position + ivec2(0, 1), depth_tile_resolution);
265
273
  tile_p_11 = wrapOctahedralTexelCoordinates(texel_position + ivec2(1, 1), depth_tile_resolution);
266
274
 
267
- float texel_00 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_00, 0).r;
268
- float texel_01 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_01, 0).r;
269
- float texel_10 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_10, 0).r;
270
- float texel_11 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_11, 0).r;
271
275
 
272
- return vec2(
273
- lpv_bilinear_lerp(
274
- texel_00, texel_01,
275
- texel_10, texel_11,
276
- gridFrac
277
- ),
278
- lpv_bilinear_lerp(
279
- texel_00 * texel_00, texel_01 * texel_01,
280
- texel_10 * texel_10, texel_11 * texel_11,
281
- gridFrac
282
- )
276
+ vec2 texel_00 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_00, 0).rg;
277
+ vec2 texel_01 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_01, 0).rg;
278
+ vec2 texel_10 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_10, 0).rg;
279
+ vec2 texel_11 = texelFetch(lpv_t_probe_depth, tile_offset + tile_p_11, 0).rg;
280
+
281
+ return lpv_bilinear_lerp(
282
+ texel_00, texel_01,
283
+ texel_10, texel_11,
284
+ gridFrac
283
285
  );
284
286
  }
285
287
 
@@ -1 +1 @@
1
- {"version":3,"file":"probe_volume_to_textures.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/probe_volume_to_textures.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,6EAHW,MAAM,EAAE,eACR,MAAM,QAiChB;AAGD;;;;;;GAMG;AACH,2DALW,oBAAoB,UACpB,MAAM,EAAE,eACR,MAAM,eACN,MAAM,QAiBhB;qCAhEoC,uCAAuC"}
1
+ {"version":3,"file":"probe_volume_to_textures.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/probe_volume_to_textures.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,6EAHW,MAAM,EAAE,eACR,MAAM,QAqChB;AAGD;;;;;;GAMG;AACH,2DALW,oBAAoB,UACpB,MAAM,EAAE,eACR,MAAM,eACN,MAAM,QAiBhB;qCApEoC,uCAAuC"}
@@ -27,14 +27,18 @@ export function octahedral_depth_to_atlas(lpv, atlas_data, atlas_width) {
27
27
 
28
28
  const tile_pixel_index = pixel_y * tile_resolution + pixel_x;
29
29
 
30
- const source_value = probe_depth[source_offset + tile_pixel_index];
30
+ const source_pixel_index = source_offset + tile_pixel_index;
31
31
 
32
32
  const target_pixel_x = tile_x * tile_resolution + pixel_x;
33
33
  const target_pixel_y = tile_y * tile_resolution + pixel_y;
34
34
 
35
35
  const target_pixel_index = target_pixel_y * atlas_width + target_pixel_x;
36
36
 
37
- atlas_data[target_pixel_index] = source_value;
37
+ const target_pixel_address = target_pixel_index * 2;
38
+ const source_pixel_address = source_pixel_index * 2;
39
+
40
+ atlas_data[target_pixel_address] = probe_depth[source_pixel_address];
41
+ atlas_data[target_pixel_address + 1] = probe_depth[source_pixel_address + 1];
38
42
  }
39
43
  }
40
44
  }
@@ -23,7 +23,7 @@ export class LightProbeVolumeSerializationAdapter extends BinaryClassSerializati
23
23
  // depth
24
24
  const depth_resolution = value.depth_map_resolution;
25
25
  buffer.writeUint32(depth_resolution);
26
- buffer.writeFloat32Array(value.depth, 0, depth_resolution * depth_resolution * count);
26
+ buffer.writeFloat32Array(value.depth, 0, depth_resolution * depth_resolution * count * 2);
27
27
 
28
28
  value.mesh.serialize(buffer);
29
29
  }
@@ -46,7 +46,7 @@ export class LightProbeVolumeSerializationAdapter extends BinaryClassSerializati
46
46
  // depth
47
47
  const depth_resolution = buffer.readUint32();
48
48
  value.depth_map_resolution = depth_resolution;
49
- buffer.readFloat32Array(value.depth, 0, depth_resolution * depth_resolution * count);
49
+ buffer.readFloat32Array(value.depth, 0, depth_resolution * depth_resolution * count * 2);
50
50
 
51
51
  value.mesh.deserialize(buffer);
52
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAgCA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAiF7C,iBAOC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QAgCd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAkElB;;CACJ;oBArgB8B,mCAAmC;+BAkBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBALzC,kCAAkC"}
1
+ {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAgCA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAiF7C,iBAOC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QA0Cd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAkElB;;CACJ;oBA/gB8B,mCAAmC;+BAkBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBALzC,kCAAkC"}
@@ -329,6 +329,16 @@ export class PathTracedScene {
329
329
 
330
330
  sample_material(out, mesh, primitive_id, u, v);
331
331
 
332
+ if (v3_dot(
333
+ hit[3], hit[4], hit[5], //geometry nornal
334
+ incoming_ray[3], incoming_ray[4], incoming_ray[5],
335
+ ) > 0) {
336
+ // back-facing triangle
337
+ out[3] = -out[3];
338
+ out[4] = -out[4];
339
+ out[5] = -out[5];
340
+ }
341
+
332
342
  // const pdf = mesh.material.scattering_pdf(
333
343
  // incoming_ray[3],incoming_ray[4],incoming_ray[5],
334
344
  // out[3],out[4],out[5],
@@ -246,7 +246,7 @@ async function getVolume({
246
246
  engine,
247
247
  ecd,
248
248
  bounds: mesh_bounds,
249
- density: 500
249
+ density: 5000
250
250
  });
251
251
 
252
252
  const buffer = new BinaryBuffer();
@@ -382,8 +382,8 @@ async function main(engine) {
382
382
  // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
383
383
  // const path = 'data/models/samples/cyberpunk_bike/scene.gltf';
384
384
  // const path = 'data/models/LowPolyTownshipSet/Town_Hall/model.gltf';
385
- // const path = 'data/models/sibenik/3-window-less/model.gltf';
386
- const path = 'data/models/sponza-pbr/gltf/sponza.glb';
385
+ const path = 'data/models/sibenik/3-window-less/model.gltf';
386
+ // const path = 'data/models/sponza-pbr/gltf/sponza.glb';
387
387
  // const path = 'data/models/samples/susanne.glb';
388
388
  // const path = 'data/models/samples/teapot.gltf';
389
389
  // const path = 'data/models/samples/salle_de_bain/model.glb';
@@ -1 +1 @@
1
- {"version":3,"file":"InputDeviceSwitch.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/InputDeviceSwitch.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IACI;;;OAGG;IACH,MAFU,MAAM,CAEG;IACnB;;;OAGG;IACH,IAFU,MAAM,CAEC;IACjB;;;OAGG;IACH,SAFU,OAAO,CAEF;CAClB;mBArBkB,uCAAuC"}
1
+ {"version":3,"file":"InputDeviceSwitch.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/InputDeviceSwitch.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IACI;;;OAGG;IACH,MAFU,MAAM,CAEG;IACnB;;;OAGG;IACH,IAFU,MAAM,CAEC;IACjB;;;OAGG;IACH,SAFU,OAAO,CAEF;IAEf,cAOC;IAED,gBAOC;CACJ;mBAvCkB,uCAAuC"}
@@ -19,4 +19,22 @@ export class InputDeviceSwitch {
19
19
  * @type {boolean}
20
20
  */
21
21
  is_down = false
22
+
23
+ press() {
24
+ if (this.is_down) {
25
+ return;
26
+ }
27
+
28
+ this.is_down = true;
29
+ this.down.send0();
30
+ }
31
+
32
+ release() {
33
+ if (!this.is_down) {
34
+ return;
35
+ }
36
+
37
+ this.is_down = false;
38
+ this.up.send0();
39
+ }
22
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KeyboardDevice.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/KeyboardDevice.js"],"names":[],"mappings":";AA8CA;IAgBI;;;OAGG;IACH,wBAFW,WAAW,GAAC,OAAO,EA+B7B;IA/CD;;OAEG;IACH;;;MAGE;IAEF;;;OAGG;IACH,mBAAU;IAkBN;;;OAGG;IACH,YAFU,WAAW,CAEO;IA+DhC,cAGC;IAED,aAGC;;CACJ;mBA1JkB,uCAAuC"}
1
+ {"version":3,"file":"KeyboardDevice.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/KeyboardDevice.js"],"names":[],"mappings":";AAYA;IAgBI;;;OAGG;IACH,wBAFW,WAAW,GAAC,OAAO,EA+B7B;IA/CD;;OAEG;IACH;;;MAGE;IAEF;;;OAGG;IACH,mBAAU;IAkBN;;;OAGG;IACH,YAFU,WAAW,CAEO;IA4DhC,cAGC;IAED,aAGC;;CACJ;mBArHkB,uCAAuC"}
@@ -1,43 +1,9 @@
1
1
  import Signal from "../../../core/events/signal/Signal.js";
2
2
  import { KeyboardEvents } from "./events/KeyboardEvents.js";
3
3
  import { InputDeviceSwitch } from "./InputDeviceSwitch.js";
4
+ import { isHTMLElementFocusable } from "./isHTMLElementFocusable.js";
4
5
  import { KeyCodes } from './KeyCodes.js';
5
6
 
6
- /**
7
- *
8
- * @param thing
9
- * @param klass
10
- * @returns {boolean}
11
- */
12
- function isInstanceOf(thing, klass) {
13
- if (klass === undefined) {
14
- return false;
15
- }
16
- if (klass === null) {
17
- return false;
18
- }
19
-
20
- if (typeof klass !== "object") {
21
- return false;
22
- }
23
-
24
-
25
- return thing instanceof klass;
26
- }
27
-
28
- /**
29
- * Based on the article about focusable events: https://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
30
- * @param {Element} el
31
- */
32
- function isFocusable(el) {
33
- return isInstanceOf(el, HTMLInputElement)
34
- || isInstanceOf(el, HTMLSelectElement)
35
- || isInstanceOf(el, HTMLTextAreaElement)
36
- || isInstanceOf(el, HTMLAnchorElement)
37
- || isInstanceOf(el, HTMLButtonElement)
38
- || isInstanceOf(el, HTMLAreaElement)
39
- }
40
-
41
7
  /**
42
8
  * @readonly
43
9
  * @type {string[]}
@@ -70,7 +36,7 @@ class KeyboardDevice {
70
36
  Only element in focus receives keyboard events, so the element supplied here must be focusable in order to be able to receive events
71
37
  */
72
38
  if (
73
- !isFocusable(domElement)
39
+ !isHTMLElementFocusable(domElement)
74
40
  && domElement.getAttribute('tabindex') === null
75
41
  ) {
76
42
  new TypeError('Supplied element is not inherently focusable and does not have tabindex attribute, so it must have a tabindex attribute in order to be able receive keyboard events. Something like tabindex=0 would suffice.');
@@ -116,9 +82,7 @@ class KeyboardDevice {
116
82
  if (keyName !== undefined) {
117
83
  const button = this.keys[keyName];
118
84
 
119
- button.is_down = true;
120
- button.down.send1(event);
121
-
85
+ button.press()
122
86
  }
123
87
  }
124
88
 
@@ -138,8 +102,7 @@ class KeyboardDevice {
138
102
  if (keyName !== undefined) {
139
103
  const button = this.keys[keyName];
140
104
 
141
- button.is_down = false;
142
- button.up.send1(event);
105
+ button.release();
143
106
  }
144
107
  }
145
108
 
@@ -0,0 +1,11 @@
1
+ export class LocationalInteractionMetadata {
2
+ /**
3
+ *
4
+ * @param {Vector2} p
5
+ */
6
+ static from(p: Vector2): LocationalInteractionMetadata;
7
+ timestamp: number;
8
+ position: Vector2;
9
+ }
10
+ import Vector2 from "../../../core/geom/Vector2.js";
11
+ //# sourceMappingURL=LocationalInteractionMetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocationalInteractionMetadata.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/LocationalInteractionMetadata.js"],"names":[],"mappings":"AAEA;IAII;;;OAGG;IACH,eAFW,OAAO,iCAQjB;IAbD,kBAA6B;IAC7B,kBAAwB;CAa3B;oBAjBmB,+BAA+B"}
@@ -0,0 +1,18 @@
1
+ import Vector2 from "../../../core/geom/Vector2.js";
2
+
3
+ export class LocationalInteractionMetadata {
4
+ timestamp = performance.now()
5
+ position = new Vector2()
6
+
7
+ /**
8
+ *
9
+ * @param {Vector2} p
10
+ */
11
+ static from(p) {
12
+ const r = new LocationalInteractionMetadata();
13
+
14
+ r.position.copy(p);
15
+
16
+ return r;
17
+ }
18
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"PointerDevice.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/PointerDevice.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,wDAFY,OAAO,EAAE,CAapB;AAiRD;;;;;GAKG;AACH,mDAJW,OAAO,SACP,UAAU,GAAC,KAAK,WAChB,OAAO,QAejB;AAED;;GAEG;AACH;IA2FI;;;;OAIG;IACH,wBAHW,WAAW,EA0CrB;IArID;;;;OAIG;IACH,mBAFU,OAAO,CAEQ;IAczB;;OAEG;IACH;;;;QAII;;WAEG;aADO,OAAO,OAAO,EAAE,CAAC,UAAU,GAAC,UAAU,CAAC,CAAC;;;;;;;;MAUpD;IAeF;;;OAGG;IACH,kBAAkB;IAElB;;;;OAIG;IACH,kBAFU,iBAAiB,EAAE,CAEL;IAExB;;;OAGG;IACH,yCAEC;IAED;;;OAGG;IACH,0CAEC;IAED;;;OAGG;IACH,2CAEC;IAgLD;;;OAGG;IACH,oBAFY,OAAO,CAIlB;IAED;;;OAGG;IACH,6BAsBC;IAED,0BAEC;IAED;;;;OAIG;IACH,qCAHW,OAAO,SACP,UAAU,GAAC,KAAK,QAI1B;IAED,cAkCC;IAED,aA2BC;;CACJ;oBA5rBmB,+BAA+B;mBADhC,uCAAuC;kCAMxB,wBAAwB"}
1
+ {"version":3,"file":"PointerDevice.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/PointerDevice.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,wDAFY,OAAO,EAAE,CAapB;AA+UD;;;;;GAKG;AACH,mDAJW,OAAO,SACP,UAAU,GAAC,KAAK,WAChB,OAAO,QAejB;AAED;;GAEG;AACH;IA2FI;;;;OAIG;IACH,wBAHW,WAAW,EAoCrB;IA/HD;;;;OAIG;IACH,mBAFU,OAAO,CAEQ;IAczB;;OAEG;IACH;;;;QAII;;WAEG;aADO,OAAO,OAAO,EAAE,CAAC,UAAU,GAAC,UAAU,CAAC,CAAC;;;;;;;;MAUpD;IAeF;;;OAGG;IACH,kBAAkB;IAElB;;;;OAIG;IACH,kBAFU,iBAAiB,EAAE,CAEL;IAExB;;;OAGG;IACH,yCAEC;IAED;;;OAGG;IACH,0CAEC;IAED;;;OAGG;IACH,2CAEC;IAqKD;;;OAGG;IACH,oBAFY,OAAO,CAIlB;IAED;;;OAGG;IACH,6BAsBC;IAED,0BAEC;IAED;;;;OAIG;IACH,qCAHW,OAAO,SACP,UAAU,GAAC,KAAK,QAI1B;IAED,cAkCC;IAED,aA2BC;;CACJ;oBAjvBmB,+BAA+B;mBADhC,uCAAuC;kCAOxB,wBAAwB"}
@@ -3,9 +3,11 @@ import Signal from "../../../core/events/signal/Signal.js";
3
3
  import Vector2 from "../../../core/geom/Vector2.js";
4
4
  import Vector3 from "../../../core/geom/Vector3.js";
5
5
  import { sign } from "../../../core/math/sign.js";
6
+ import { eventToSourceIdentifier } from "./events/eventToSourceIdentifier.js";
6
7
  import { MouseEvents } from "./events/MouseEvents.js";
7
8
  import { TouchEvents } from "./events/TouchEvents.js";
8
9
  import { InputDeviceSwitch } from "./InputDeviceSwitch.js";
10
+ import { LocationalInteractionMetadata } from "./LocationalInteractionMetadata.js";
9
11
 
10
12
  /**
11
13
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
@@ -84,6 +86,7 @@ function getTouchCenter(touchList, result) {
84
86
 
85
87
  }
86
88
 
89
+
87
90
  /**
88
91
  *
89
92
  * @param {Signal} up
@@ -92,13 +95,51 @@ function getTouchCenter(touchList, result) {
92
95
  * @param {number} maxDistance
93
96
  * @param {Signal} signal
94
97
  */
95
- function observeTap(up, down, move, maxDistance, signal) {
98
+ function observeTap(
99
+ up,
100
+ down,
101
+ move,
102
+ maxDistance,
103
+ signal
104
+ ) {
96
105
 
97
- const origin = new Vector2();
106
+ /**
107
+ *
108
+ * @type {Map<number, LocationalInteractionMetadata>}
109
+ */
110
+ const active = new Map();
111
+
112
+ /**
113
+ *
114
+ * @param {number} id
115
+ */
116
+ function reset(id) {
117
+ assert.isNonNegativeInteger(id, 'id');
98
118
 
119
+ if (active.delete(id)) {
120
+ up.remove(handleUp);
121
+ move.remove(handleMove);
122
+ }
123
+ }
124
+
125
+ /**
126
+ *
127
+ * @param {Vector2} position
128
+ * @param {MouseEvent|TouchEvent} event
129
+ */
99
130
  function handleUp(position, event) {
100
- up.remove(handleUp);
101
- move.remove(handleMove);
131
+ const id = eventToSourceIdentifier(event);
132
+
133
+ const meta = active.get(id);
134
+
135
+ if (meta === undefined) {
136
+ // this should not happen
137
+ console.warn(`Unregistered up event handler`);
138
+ return;
139
+ }
140
+
141
+ reset(id);
142
+
102
143
  signal.send2(position, event);
103
144
  }
104
145
 
@@ -108,20 +149,43 @@ function observeTap(up, down, move, maxDistance, signal) {
108
149
  * @param {MouseEvent|TouchEvent} event
109
150
  */
110
151
  function handleMove(position, event) {
111
- if (origin.distanceTo(position) > maxDistance) {
112
- //we moved too far, abort tap
113
- move.remove(handleMove);
152
+ const id = eventToSourceIdentifier(event);
114
153
 
115
- up.remove(handleUp);
154
+ const meta = active.get(id);
155
+
156
+ if (meta === undefined) {
157
+ // this should not happen
158
+ console.warn(`Unregistered move event handler`);
159
+
160
+ reset(id);
161
+
162
+ return;
116
163
  }
164
+
165
+ if (meta.position.distanceTo(position) > maxDistance) {
166
+ //we moved too far, abort tap
167
+ reset(id);
168
+ }
169
+
117
170
  }
118
171
 
119
- function handleDown(position) {
172
+ /**
173
+ *
174
+ * @param {Vector2} position
175
+ * @param {TouchEvent|MouseEvent} event
176
+ */
177
+ function handleDown(position, event) {
178
+ const id = eventToSourceIdentifier(event);
179
+
180
+ // make sure to cancel previous pending resolution
181
+ reset(id);
182
+
183
+ active.set(id, LocationalInteractionMetadata.from(position));
184
+
120
185
  up.addOne(handleUp);
186
+
121
187
  //track move
122
188
  move.add(handleMove);
123
-
124
- origin.copy(position);
125
189
  }
126
190
 
127
191
  down.add(handleDown);
@@ -433,17 +497,11 @@ export class PointerDevice {
433
497
  this.#domElement = domElement;
434
498
 
435
499
 
436
- this.#touchStart.add((param0, param1, param2) => {
437
- this.on.down.send3(param0, param1, param2);
438
- });
500
+ this.#touchStart.add(this.on.down.send3, this.on.down);
439
501
 
440
- this.#touchEnd.add((param0, param1, param2) => {
441
- this.on.up.send3(param0, param1, param2);
442
- });
443
- this.#touchMove.add((param0, param1, param2) => {
444
- this.on.move.send3(param0, param1, param2);
445
- });
502
+ this.#touchEnd.add(this.on.up.send3, this.on.up);
446
503
 
504
+ this.#touchMove.add(this.on.move.send3, this.on.move);
447
505
 
448
506
  //constructed events
449
507
  observeTap(this.on.up, this.on.down, this.on.move, 10, this.on.tap);
@@ -459,6 +517,16 @@ export class PointerDevice {
459
517
  });
460
518
  }
461
519
 
520
+
521
+ /**
522
+ *
523
+ * @param {TouchEvent} event
524
+ */
525
+ #eventHandlerGlobalTouchEnd = (event) => {
526
+ getTouchCenter(event.touches, this.position);
527
+ this.#globalUp.send2(this.position, event);
528
+ }
529
+
462
530
  /**
463
531
  *
464
532
  * @param {MouseEvent} event
@@ -472,19 +540,7 @@ export class PointerDevice {
472
540
 
473
541
  const button = this.buttons[button_index];
474
542
 
475
- if (button !== undefined) {
476
- button.is_down = true;
477
- button.down.send0();
478
- }
479
- }
480
-
481
- /**
482
- *
483
- * @param {TouchEvent} event
484
- */
485
- #eventHandlerGlobalTouchEnd = (event) => {
486
- getTouchCenter(event.touches, this.position);
487
- this.#globalUp.send2(this.position, event);
543
+ button?.press();
488
544
  }
489
545
 
490
546
  /**
@@ -509,10 +565,7 @@ export class PointerDevice {
509
565
 
510
566
  const button = this.buttons[button_index];
511
567
 
512
- if (button !== undefined) {
513
- button.is_down = false;
514
- button.up.send0();
515
- }
568
+ button?.release();
516
569
  }
517
570
 
518
571
  /**
@@ -0,0 +1,7 @@
1
+ /**
2
+ *
3
+ * @param {TouchEvent|MouseEvent} event
4
+ * @returns {number}
5
+ */
6
+ export function eventToSourceIdentifier(event: TouchEvent | MouseEvent): number;
7
+ //# sourceMappingURL=eventToSourceIdentifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventToSourceIdentifier.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/input/devices/events/eventToSourceIdentifier.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,+CAHW,UAAU,GAAC,UAAU,GACnB,MAAM,CAgClB"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ *
3
+ * @param {TouchEvent|MouseEvent} event
4
+ * @returns {number}
5
+ */
6
+ export function eventToSourceIdentifier(event) {
7
+ let device_id = 0;
8
+ let source_id = 0;
9
+
10
+ if (event instanceof MouseEvent) {
11
+
12
+ // mouse
13
+
14
+ device_id = 1;
15
+ source_id = event.button;
16
+
17
+ } else if (event instanceof TouchEvent) {
18
+
19
+ // touch
20
+
21
+ device_id = 2;
22
+ const touches = event.changedTouches;
23
+ const num_changes = touches.length;
24
+
25
+ if (num_changes > 0) {
26
+ const touch = touches.item(0);
27
+
28
+ source_id = touch.identifier;
29
+ }
30
+
31
+ }
32
+
33
+ return ((device_id & 0b11) << 29)
34
+ | (source_id & 0b11111111111111111111111111111)
35
+ ;
36
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Based on the article about focusable events: https://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
3
+ * @param {Element} el
4
+ */
5
+ export function isHTMLElementFocusable(el: Element): boolean;
6
+ //# sourceMappingURL=isHTMLElementFocusable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isHTMLElementFocusable.d.ts","sourceRoot":"","sources":["../../../../../src/engine/input/devices/isHTMLElementFocusable.js"],"names":[],"mappings":"AAsBA;;;GAGG;AACH,2CAFW,OAAO,WASjB"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ *
3
+ * @param thing
4
+ * @param klass
5
+ * @returns {boolean}
6
+ */
7
+ function isInstanceOf(thing, klass) {
8
+ if (klass === undefined) {
9
+ return false;
10
+ }
11
+ if (klass === null) {
12
+ return false;
13
+ }
14
+
15
+ if (typeof klass !== "object") {
16
+ return false;
17
+ }
18
+
19
+
20
+ return thing instanceof klass;
21
+ }
22
+
23
+ /**
24
+ * Based on the article about focusable events: https://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
25
+ * @param {Element} el
26
+ */
27
+ export function isHTMLElementFocusable(el) {
28
+ return isInstanceOf(el, HTMLInputElement)
29
+ || isInstanceOf(el, HTMLSelectElement)
30
+ || isInstanceOf(el, HTMLTextAreaElement)
31
+ || isInstanceOf(el, HTMLAnchorElement)
32
+ || isInstanceOf(el, HTMLButtonElement)
33
+ || isInstanceOf(el, HTMLAreaElement)
34
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"PriorityFetch.d.ts","sourceRoot":"","sources":["../../../../src/engine/network/PriorityFetch.js"],"names":[],"mappings":"AAiFA;;;GAGG;AACH;IACI;;;OA+BC;IA3BG;;;;OAIG;IACH,sBAAgC;IAEhC;;;;OAIG;IACH,gBAAqD;IAErD;;;;OAIG;IACH,sBAA8B;IAE9B;;;;OAIG;IACH,kBAAwB;IAG5B;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,6BAMC;IAED;;;OAGG;IACH,0BAEC;IAED;;;;OAIG;IACH,mBAkBC;IAED,eAMC;IAED,iDAUC;CACJ;qBA7LoB,6BAA6B"}
1
+ {"version":3,"file":"PriorityFetch.d.ts","sourceRoot":"","sources":["../../../../src/engine/network/PriorityFetch.js"],"names":[],"mappings":"AAiFA;;;GAGG;AACH;IACI;;;OA+BC;IA3BG;;;;OAIG;IACH,sBAAgC;IAEhC;;;;OAIG;IACH,gBAAiD;IAEjD;;;;OAIG;IACH,sBAA8B;IAE9B;;;;OAIG;IACH,kBAAwB;IAG5B;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,6BAMC;IAED;;;OAGG;IACH,0BAEC;IAED;;;;OAIG;IACH,mBAkBC;IAED,eAMC;IAED,iDAUC;CACJ;qBA7LoB,6BAA6B"}
@@ -1,5 +1,5 @@
1
1
  import { assert } from "../../core/assert.js";
2
- import FastBinaryHeap from "../../core/collection/heap/FastBinaryHeap.js";
2
+ import BinaryHeap from "../../core/collection/heap/BinaryHeap.js";
3
3
  import { noop } from "../../core/function/noop.js";
4
4
 
5
5
  /**
@@ -100,7 +100,7 @@ export class PriorityFetch {
100
100
  * @type {BinaryHeap<FetchRequest>}
101
101
  * @private
102
102
  */
103
- this.__queue = new FastBinaryHeap(get_priority_score);
103
+ this.__queue = new BinaryHeap(get_priority_score);
104
104
 
105
105
  /**
106
106
  *
@@ -1,7 +1,7 @@
1
1
  import { matcher_tag_unoccupied } from "../../../../../samples/generation/rules/matcher_tag_unoccupied.js";
2
2
  import { assert } from "../../../../core/assert.js";
3
3
  import { BitSet } from "../../../../core/binary/BitSet.js";
4
- import BinaryHeap from "../../../../core/collection/heap/FastBinaryHeap.js";
4
+ import BinaryHeap from "../../../../core/collection/heap/BinaryHeap.js";
5
5
  import { Uint32Heap } from "../../../../core/collection/heap/Uint32Heap.js";
6
6
  import { passThrough } from "../../../../core/function/passThrough.js";
7
7
  import Vector2 from "../../../../core/geom/Vector2.js";
@@ -1 +1 @@
1
- {"version":3,"file":"GridTaskBuildSourceDistanceMap.d.ts","sourceRoot":"","sources":["../../../../../../../src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js"],"names":[],"mappings":"AAUA;;GAEG;AACH;IA6BI;;;;;;;OAOG;IACH;;;;;;uCAgBC;IAjDG;;;OAGG;IACH,2BAAyB;IAEzB;;;OAGG;IACH,yBAAuB;IAEvB;;;OAGG;IACH,cAAiB;IAEjB;;;OAGG;IACH,SAFU,MAAM,CAEI;IA6BxB,iDA8IC;CACJ;kCA9MiC,+BAA+B;sBAH3C,+CAA+C"}
1
+ {"version":3,"file":"GridTaskBuildSourceDistanceMap.d.ts","sourceRoot":"","sources":["../../../../../../../src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js"],"names":[],"mappings":"AAUA;;GAEG;AACH;IA6BI;;;;;;;OAOG;IACH;;;;;;uCAgBC;IAjDG;;;OAGG;IACH,2BAAyB;IAEzB;;;OAGG;IACH,yBAAuB;IAEvB;;;OAGG;IACH,cAAiB;IAEjB;;;OAGG;IACH,SAFU,MAAM,CAEI;IA6BxB,iDA8IC;CACJ;kCA3MiC,+BAA+B;sBAJ3C,+CAA+C"}
@@ -1,12 +1,12 @@
1
- import Task from "../../../../../core/process/task/Task.js";
1
+ import { assert } from "../../../../../core/assert.js";
2
2
  import { BitSet } from "../../../../../core/binary/BitSet.js";
3
+ import BinaryHeap from "../../../../../core/collection/heap/BinaryHeap.js";
4
+ import Task from "../../../../../core/process/task/Task.js";
3
5
  import TaskGroup from "../../../../../core/process/task/TaskGroup.js";
4
6
  import { TaskSignal } from "../../../../../core/process/task/TaskSignal.js";
5
- import BinaryHeap from "../../../../../core/collection/heap/FastBinaryHeap.js";
6
- import { GridTaskGenerator } from "../../../GridTaskGenerator.js";
7
- import { assert } from "../../../../../core/assert.js";
8
7
  import { actionTask } from "../../../../../core/process/task/util/actionTask.js";
9
8
  import { countTask } from "../../../../../core/process/task/util/countTask.js";
9
+ import { GridTaskGenerator } from "../../../GridTaskGenerator.js";
10
10
 
11
11
  /**
12
12
  * Build a map of distances across the grid, using 2 concepts: source cells and passable cells. Source cells are where the distance is 0, and passable cells are those that can be travelled through
@@ -1 +1 @@
1
- {"version":3,"file":"GridTaskDistanceToMarkers.d.ts","sourceRoot":"","sources":["../../../../../../../src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.js"],"names":[],"mappings":"AAIA;IAIQ;;;OAGG;IACH,yBAAuB;IAEvB;;;OAGG;IACH,OAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,SAFU,MAAM,CAEI;IAGxB,oBAKC;IAED,4CAgCC;CACJ;kCAnEiC,+BAA+B"}
1
+ {"version":3,"file":"GridTaskDistanceToMarkers.d.ts","sourceRoot":"","sources":["../../../../../../../src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.js"],"names":[],"mappings":"AAIA;IAIQ;;;OAGG;IACH,yBAAuB;IAEvB;;;OAGG;IACH,OAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,SAFU,MAAM,CAEI;IAGxB,oBAKC;IAED,4CAgCC;CACJ;kCAjEiC,+BAA+B"}
@@ -1,6 +1,6 @@
1
- import { GridTaskGenerator } from "../../../GridTaskGenerator.js";
2
- import BinaryHeap from "../../../../../core/collection/heap/FastBinaryHeap.js";
1
+ import BinaryHeap from "../../../../../core/collection/heap/BinaryHeap.js";
3
2
  import { actionTask } from "../../../../../core/process/task/util/actionTask.js";
3
+ import { GridTaskGenerator } from "../../../GridTaskGenerator.js";
4
4
 
5
5
  export class GridTaskDistanceToMarkers extends GridTaskGenerator {
6
6
  constructor() {