@woosh/meep-engine 2.47.3 → 2.47.10

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 (130) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -0
  2. package/build/bundle-worker-terrain.js +1 -0
  3. package/build/meep.cjs +1044 -933
  4. package/build/meep.min.js +1 -1
  5. package/build/meep.module.js +1044 -933
  6. package/package.json +2 -2
  7. package/src/core/binary/BitSet.spec.js +3 -3
  8. package/src/core/bvh2/BinaryNode.js +12 -10
  9. package/src/core/bvh2/aabb3/AABB3.js +30 -31
  10. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +1 -1
  11. package/src/core/bvh2/binary/BinaryBVH.js +1 -1
  12. package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +1 -1
  13. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -1
  14. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +2 -2
  15. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +1 -1
  16. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +1 -1
  17. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +10 -8
  18. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +14 -22
  19. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +13 -15
  20. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +14 -21
  21. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +16 -24
  22. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +23 -26
  23. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +10 -11
  24. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +2 -2
  25. package/src/core/bvh2/transform/tryRotateSingleNode.js +2 -2
  26. package/src/core/bvh2/traversal/aabb3_detailed_volume_intersection_callback_based.js +1 -1
  27. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +1 -1
  28. package/src/core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js +13 -0
  29. package/src/core/color/Color.d.ts +2 -1
  30. package/src/core/color/Color.js +30 -5
  31. package/src/core/color/ColorUtils.js +7 -5
  32. package/src/core/color/parseHex.js +11 -3
  33. package/src/core/color/rgb2hex.js +1 -1
  34. package/src/core/geom/3d/SurfacePoint3.d.ts +7 -0
  35. package/src/core/geom/3d/SurfacePoint3.js +56 -1
  36. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_combine.js +2 -2
  37. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_contains_point.js +1 -1
  38. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_degree.js +2 -2
  39. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_combined_surface_area.js +2 -2
  40. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js +1 -1
  41. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.spec.js +8 -0
  42. package/src/core/geom/3d/aabb/{computeAABB3PlaneSide.js → aabb3_compute_plane_side.js} +1 -1
  43. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_detailed_volume_intersection.js +7 -7
  44. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array.js +4 -4
  45. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array_transformed.js +2 -2
  46. package/src/core/{bvh2/aabb3/aabb3_intersect_aabb3.js → geom/3d/aabb/aabb3_intersects_aabb3.js} +2 -2
  47. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_array.js +2 -2
  48. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_degree.js +4 -4
  49. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_line_segment.js +1 -1
  50. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +87 -0
  51. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray.spec.js +1 -1
  52. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_branchless.js +2 -2
  53. package/src/core/{bvh2/aabb3/aabb3_intersect_ray_slab.js → geom/3d/aabb/aabb3_intersects_ray_slab.js} +35 -17
  54. package/src/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +5 -1
  55. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_nearest_point_on_surface.js +2 -2
  56. package/src/core/geom/3d/aabb/aabb3_raycast.js +103 -0
  57. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_signed_distance_sqr_to_point.js +1 -1
  58. package/src/core/geom/3d/aabb/computeBoundingBoxFromVertexData.js +4 -12
  59. package/src/core/geom/3d/aabb/compute_aabb_from_points.js +8 -1
  60. package/src/core/geom/3d/shape/UnitCubeShape3D.js +1 -1
  61. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +4 -7
  62. package/src/core/model/node-graph/DataType.d.ts +4 -0
  63. package/src/core/model/node-graph/node/NodeDescription.d.ts +11 -1
  64. package/src/core/model/node-graph/node/NodeRegistry.spec.js +47 -1
  65. package/src/core/model/node-graph/node/Port.d.ts +3 -0
  66. package/src/core/model/node-graph/node/Port.js +7 -3
  67. package/src/core/model/node-graph/node/Port.spec.js +44 -0
  68. package/src/core/model/node-graph/node/PortDirection.d.ts +5 -0
  69. package/src/engine/asset/Asset.js +1 -1
  70. package/src/engine/asset/AssetLoadState.js +10 -0
  71. package/src/engine/asset/AssetManager.js +164 -228
  72. package/src/engine/asset/PendingAsset.js +61 -0
  73. package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
  74. package/src/engine/ecs/foliage/InstancedFoliage.js +1 -1
  75. package/src/engine/ecs/storage/BinaryBufferSerializer.js +13 -1
  76. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +11 -4
  77. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter2.js +54 -0
  78. package/src/engine/ecs/systems/RenderSystem.js +1 -33
  79. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +2 -4
  80. package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +6 -1
  81. package/src/engine/graphics/GraphicsEngine.js +5 -1
  82. package/src/engine/graphics/ecs/decal/v2/Decal.js +44 -2
  83. package/src/engine/graphics/ecs/decal/v2/DecalSerializationAdapter.js +31 -0
  84. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +16 -5
  85. package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +88 -56
  86. package/src/engine/graphics/geometry/buffered/compute_buffer_geometry_byte_size.js +5 -1
  87. package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +2 -2
  88. package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +1 -1
  89. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +3 -2
  90. package/src/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +3 -2
  91. package/src/engine/graphics/micron/format/MicronGeometry.js +1 -1
  92. package/src/engine/graphics/micron/format/validate_patch_bounds.js +1 -1
  93. package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +1 -1
  94. package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +16 -16
  95. package/src/engine/graphics/render/forward_plus/LightManager.js +3 -0
  96. package/src/engine/graphics/render/forward_plus/LightManager.spec.js +5 -5
  97. package/src/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_APPLY_DECALS.js +4 -0
  98. package/src/engine/graphics/render/forward_plus/model/Decal.js +10 -2
  99. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +2 -2
  100. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +18 -16
  101. package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +2 -0
  102. package/src/engine/graphics/render/visibility/IncrementalDeltaSet.js +26 -13
  103. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +8 -2
  104. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +3 -3
  105. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +18 -15
  106. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.js +1 -1
  107. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min.js +1 -1
  108. package/src/engine/graphics/three/three_computeObjectBoundingBox.js +56 -0
  109. package/src/engine/input/devices/{InputDeviceButton.d.ts → InputDeviceSwitch.d.ts} +1 -1
  110. package/src/engine/input/devices/{InputDeviceButton.js → InputDeviceSwitch.js} +1 -1
  111. package/src/engine/input/devices/KeyboardDevice.d.ts +2 -2
  112. package/src/engine/input/devices/KeyboardDevice.js +58 -40
  113. package/src/engine/input/devices/PointerDevice.js +224 -179
  114. package/src/core/bvh2/aabb3/aabb3_intersects_ray.js +0 -97
  115. package/src/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane_max.spec.js +0 -8
  116. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_array.js +0 -0
  117. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray.js +0 -0
  118. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray_array.js +0 -0
  119. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_box_surface_area_2.js +0 -0
  120. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_half_surface_area.js +0 -0
  121. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_surface_area.js +0 -0
  122. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.js +0 -0
  123. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.spec.js +0 -0
  124. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.js +0 -0
  125. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.spec.js +0 -0
  126. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_plane_mapping.js +0 -0
  127. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_expand_array.js +0 -0
  128. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_fast.js +0 -0
  129. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_score_boxes_SAH.js +0 -0
  130. /package/src/core/{bvh2/aabb3/aabb_score_boxes_SAH_delta.js → geom/3d/aabb/aabb3_score_boxes_SAH_delta.js} +0 -0
@@ -229,18 +229,31 @@ export class IncrementalDeltaSet {
229
229
  finalizeUpdate() {
230
230
  assert.equal(this.state, IncrementalDeltaSetState.Building, `Expected BUILDING state, instead got '${this.state}'`);
231
231
 
232
- this.size = this.__elements_cursor;
232
+ const array_main_count = this.__elements_cursor;
233
+ const array_previous_count = this.__swap_elements_count;
234
+
235
+ this.size = array_main_count;
233
236
 
234
237
  // sort newly populated elements array
235
- array_shrink_to_size(this.__elements, this.size);
236
- this.__elements.sort(this.__compare);
238
+ const array_main = this.__elements;
239
+ const array_previous = this.__swap_elements;
240
+
241
+ const compare = this.__compare;
242
+
243
+ const onAdded = this.onAdded;
244
+ const onRemoved = this.onRemoved;
245
+
246
+ array_shrink_to_size(array_main, array_main_count);
247
+ array_main.sort(compare);
248
+
237
249
 
238
250
  let i0 = 0, i1 = 0;
239
- while (i0 < this.size && i1 < this.__swap_elements_count) {
240
- const el_0 = this.__elements[i0];
241
- const el_1 = this.__swap_elements[i1];
242
251
 
243
- const diff = this.__compare(el_0, el_1);
252
+ while (i0 < array_main_count && i1 < array_previous_count) {
253
+ const el_0 = array_main[i0];
254
+ const el_1 = array_previous[i1];
255
+
256
+ const diff = compare(el_0, el_1);
244
257
 
245
258
  if (diff === 0) {
246
259
  i0++;
@@ -249,20 +262,20 @@ export class IncrementalDeltaSet {
249
262
  } else if (diff < 0) {
250
263
  i0++;
251
264
  // addition
252
- this.onAdded.send1(el_0);
265
+ onAdded.send1(el_0);
253
266
  } else {
254
267
  i1++;
255
268
  // removal
256
- this.onRemoved.send1(el_1);
269
+ onRemoved.send1(el_1);
257
270
  }
258
271
  }
259
272
 
260
273
  // process remainders
261
- for (; i0 < this.size; i0++) {
262
- this.onAdded.send1(this.__elements[i0]);
274
+ for (; i0 < array_main_count; i0++) {
275
+ onAdded.send1(array_main[i0]);
263
276
  }
264
- for (; i1 < this.__swap_elements_count; i1++) {
265
- this.onRemoved.send1(this.__swap_elements[i1]);
277
+ for (; i1 < array_previous_count; i1++) {
278
+ onRemoved.send1(array_previous[i1]);
266
279
  }
267
280
 
268
281
  this.state = IncrementalDeltaSetState.Ready;
@@ -2,7 +2,9 @@ import {
2
2
  ExplicitBinaryBoundingVolumeHierarchy
3
3
  } from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
4
4
  import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
5
- import { aabb3_signed_distance_sqr_to_point } from "../../../../core/bvh2/aabb3/aabb3_signed_distance_sqr_to_point.js";
5
+ import {
6
+ aabb3_signed_distance_sqr_to_point
7
+ } from "../../../../core/geom/3d/aabb/aabb3_signed_distance_sqr_to_point.js";
6
8
  import {
7
9
  computeTriangleRayIntersectionBarycentric
8
10
  } from "../../../../core/geom/3d/triangle/computeTriangleRayIntersection.js";
@@ -197,7 +199,11 @@ export class GeometryBVHBatched {
197
199
 
198
200
  bvh.node_get_aabb(node_id, temp_aabb3);
199
201
 
200
- const distance = aabb3_signed_distance_sqr_to_point(temp_aabb3[0], temp_aabb3[1], temp_aabb3[2], temp_aabb3[3], temp_aabb3[4], temp_aabb3[5], ray[0], ray[1], ray[2]);
202
+ const distance = aabb3_signed_distance_sqr_to_point(
203
+ temp_aabb3[0], temp_aabb3[1], temp_aabb3[2],
204
+ temp_aabb3[3], temp_aabb3[4], temp_aabb3[5],
205
+ ray[0], ray[1], ray[2]
206
+ );
201
207
 
202
208
  if (distance > best_t * best_t) {
203
209
  // whole AABB is too far
@@ -92,8 +92,8 @@ export class PathTracer {
92
92
  this.geo_cache = new Map();
93
93
 
94
94
  /**
95
- *
96
- * @type {Map<THREE.Texture, Sampler2D>}
95
+ * Maps {@link Texture.id} to relevant sampler
96
+ * @type {Map<number, Sampler2D>}
97
97
  */
98
98
  this.textures = new Map();
99
99
 
@@ -171,7 +171,7 @@ export class PathTracer {
171
171
 
172
172
  /**
173
173
  *
174
- * @param {THREE.Light} light
174
+ * @param {AbstractLight} light
175
175
  */
176
176
  addLight(light) {
177
177
  this.__lights.push(light);
@@ -397,8 +397,8 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
397
397
  camera.matrixWorldInverse.copy(camera.matrixWorld);
398
398
  camera.matrixWorldInverse.invert();
399
399
 
400
- const out = [];
401
- const out2 = [];
400
+ const pixel_color = [];
401
+ const pixel_accummulation = [];
402
402
  const ray = [];
403
403
 
404
404
  const ray_origin = new Vector3();
@@ -414,7 +414,7 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
414
414
  const pixel_scale_x = 1 / (width - 1);
415
415
  const pixel_scale_y = 1 / (height - 1);
416
416
 
417
- const pixel_sample_count = 500;
417
+ const pixel_sample_count = 4;
418
418
 
419
419
  progress.total = width * height;
420
420
 
@@ -446,9 +446,13 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
446
446
  const u = x * pixel_scale_x;
447
447
  const _x = u * 2 - 1;
448
448
 
449
- out2[0] = 0;
450
- out2[1] = 0;
451
- out2[2] = 0;
449
+ pixel_accummulation[0] = 0;
450
+ pixel_accummulation[1] = 0;
451
+ pixel_accummulation[2] = 0;
452
+
453
+ const pixel_address = ((max_y - y) * width + x) * 4;
454
+
455
+ target.data[pixel_address + 3] = 255;
452
456
 
453
457
  for (let i = 0; i < pixel_sample_count; i++) {
454
458
 
@@ -464,22 +468,20 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
464
468
  ray_direction.x, ray_direction.y, ray_direction.z
465
469
  );
466
470
 
467
- pt.path_trace(out, ray, Infinity, 4, random);
471
+ pt.path_trace(pixel_color, ray, Infinity, 4, random);
468
472
 
469
- out2[0] += out[0];
470
- out2[1] += out[1];
471
- out2[2] += out[2];
473
+ pixel_accummulation[0] += pixel_color[0];
474
+ pixel_accummulation[1] += pixel_color[1];
475
+ pixel_accummulation[2] += pixel_color[2];
472
476
 
473
477
 
474
478
  sample_count++;
475
479
  }
476
480
 
477
- const pixel_address = ((max_y - y) * width + x) * 4;
481
+ target.data[pixel_address] = float2uint8(pixel_accummulation[0] / pixel_sample_count);
482
+ target.data[pixel_address + 1] = float2uint8(pixel_accummulation[1] / pixel_sample_count);
483
+ target.data[pixel_address + 2] = float2uint8(pixel_accummulation[2] / pixel_sample_count);
478
484
 
479
- target.data[pixel_address] = float2uint8(out2[0] / pixel_sample_count);
480
- target.data[pixel_address + 1] = float2uint8(out2[1] / pixel_sample_count);
481
- target.data[pixel_address + 2] = float2uint8(out2[2] / pixel_sample_count);
482
- target.data[pixel_address + 3] = 255;
483
485
 
484
486
  progress.current++;
485
487
 
@@ -515,6 +517,7 @@ async function start_renderer(camera) {
515
517
  camera.aspect = vCanvas.size.x / vCanvas.size.y;
516
518
 
517
519
  // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
520
+ const path = 'data/models/pica_pica/pica_pica.gltf';
518
521
  // const path = 'data/models/road_bike/road_bike.gltf'; //large CAD-type model
519
522
 
520
523
  // await prepare_scene_lucy(pt, camera);
@@ -35,7 +35,7 @@ export function sampler2d_channel_compute_max(sampler, channel=0){
35
35
 
36
36
  }
37
37
 
38
- const width = this.width;
38
+ const width = sampler.width;
39
39
 
40
40
  const itemIndex = (bestIndex / itemSize) | 0;
41
41
 
@@ -35,7 +35,7 @@ export function sampler2d_channel_compute_min(sampler, channel=0){
35
35
 
36
36
  }
37
37
 
38
- const width = this.width;
38
+ const width = sampler.width;
39
39
 
40
40
  const itemIndex = (bestIndex / itemSize) | 0;
41
41
 
@@ -0,0 +1,56 @@
1
+ import { Box3 } from "three";
2
+
3
+ /**
4
+ *
5
+ * @param {Object3D} object
6
+ * @param {AABB3} result
7
+ */
8
+ export function three_computeObjectBoundingBox(object, result) {
9
+ const _sX = object.scale.x;
10
+ const _sY = object.scale.y;
11
+ const _sZ = object.scale.z;
12
+
13
+ object.scale.set(1, 1, 1);
14
+
15
+ const box3 = new Box3();
16
+
17
+ box3.expandByObject(object);
18
+
19
+ object.scale.set(_sX, _sY, _sZ);
20
+
21
+ const min = box3.min;
22
+ const max = box3.max;
23
+
24
+ let x0 = min.x;
25
+ let y0 = min.y;
26
+ let z0 = min.z;
27
+ let x1 = max.x;
28
+ let y1 = max.y;
29
+ let z1 = max.z;
30
+
31
+ // validate and fix missing bounds
32
+ if (x1 < x0) {
33
+ // no bounds
34
+ x0 = 0;
35
+ x1 = 0;
36
+ }
37
+
38
+ if (y1 < y0) {
39
+ // no bounds
40
+ y0 = 0;
41
+ y1 = 0;
42
+ }
43
+
44
+ if (z1 < z0) {
45
+ // no bounds
46
+ z0 = 0;
47
+ z1 = 0;
48
+ }
49
+
50
+
51
+ result.setBounds(
52
+ x0, y0, z0,
53
+ x1, y1, z1
54
+ );
55
+
56
+ }
@@ -1,6 +1,6 @@
1
1
  import Signal from "../../../core/events/signal/Signal";
2
2
 
3
- export class InputDeviceButton{
3
+ export class InputDeviceSwitch {
4
4
  readonly up: Signal
5
5
  readonly down: Signal
6
6
  readonly is_down: boolean
@@ -3,7 +3,7 @@ import Signal from "../../../core/events/signal/Signal.js";
3
3
  /**
4
4
  * Representation of an input device key
5
5
  */
6
- export class InputDeviceButton {
6
+ export class InputDeviceSwitch {
7
7
  /**
8
8
  * Button press
9
9
  * @type {Signal}
@@ -1,4 +1,4 @@
1
- import {InputDeviceButton} from "./InputDeviceButton";
1
+ import {InputDeviceSwitch} from "./InputDeviceSwitch";
2
2
  import Signal from "../../../core/events/signal/Signal";
3
3
 
4
4
  export default class KeyboardDevice {
@@ -6,7 +6,7 @@ export default class KeyboardDevice {
6
6
 
7
7
  readonly on: {up:Signal,down:Signal}
8
8
 
9
- readonly keys:{[key:string]:InputDeviceButton}
9
+ readonly keys:{[key:string]:InputDeviceSwitch}
10
10
 
11
11
  start():void
12
12
 
@@ -5,7 +5,7 @@
5
5
  import Signal from "../../../core/events/signal/Signal.js";
6
6
  import { KeyCodes } from './KeyCodes.js';
7
7
  import { KeyboardEvents } from "./events/KeyboardEvents.js";
8
- import { InputDeviceButton } from "./InputDeviceButton.js";
8
+ import { InputDeviceSwitch } from "./InputDeviceSwitch.js";
9
9
 
10
10
  /**
11
11
  *
@@ -42,7 +42,28 @@ function isFocusable(el) {
42
42
  || isInstanceOf(el, HTMLAreaElement)
43
43
  }
44
44
 
45
+ /**
46
+ * @readonly
47
+ * @type {string[]}
48
+ */
49
+ const codeToKeyNameMap = [];
50
+
45
51
  class KeyboardDevice {
52
+
53
+ /**
54
+ * @readonly
55
+ */
56
+ on = {
57
+ down: new Signal(),
58
+ up: new Signal()
59
+ };
60
+
61
+ /**
62
+ * @readonly
63
+ * @type {Object<InputDeviceSwitch>}
64
+ */
65
+ keys = {};
66
+
46
67
  /**
47
68
  *
48
69
  * @param {EventTarget|Element} domElement
@@ -62,19 +83,6 @@ class KeyboardDevice {
62
83
  */
63
84
  this.domElement = domElement;
64
85
 
65
- this.on = {
66
- down: new Signal(),
67
- up: new Signal()
68
- };
69
-
70
-
71
- /**
72
- *
73
- * @type {Object<InputDeviceButton>}
74
- */
75
- const keys = this.keys = {};
76
-
77
- const codeToKeyNameMap = [];
78
86
 
79
87
  //initialize separate events for each key
80
88
  for (let keyName in KeyCodes) {
@@ -83,51 +91,61 @@ class KeyboardDevice {
83
91
 
84
92
  codeToKeyNameMap[keyCode] = keyName;
85
93
 
86
- keys[keyName] = new InputDeviceButton();
94
+ this.keys[keyName] = new InputDeviceSwitch();
87
95
  }
88
96
 
89
- this.__handlerKeyDown = (event) => {
90
- this.on.down.send1(event);
97
+ }
91
98
 
92
- //hook up dispatch handler for individual keys
93
- const keyCode = event.keyCode;
94
- const keyName = codeToKeyNameMap[keyCode];
99
+ /**
100
+ *
101
+ * @param {KeyboardEvent} event
102
+ * @private
103
+ */
104
+ #handlerKeyDown = (event) => {
105
+ this.on.down.send1(event);
95
106
 
96
- if (keyName !== undefined) {
97
- const button = keys[keyName];
107
+ //hook up dispatch handler for individual keys
108
+ const keyCode = event.keyCode;
109
+ const keyName = codeToKeyNameMap[keyCode];
98
110
 
99
- button.is_down = true;
100
- button.down.send1(event);
111
+ if (keyName !== undefined) {
112
+ const button = this.keys[keyName];
113
+
114
+ button.is_down = true;
115
+ button.down.send1(event);
101
116
 
102
- }
103
117
  }
118
+ }
104
119
 
105
- this.__handlerKeyUp = (event) => {
106
- this.on.up.send1(event);
120
+ /**
121
+ *
122
+ * @param {KeyboardEvent} event
123
+ * @private
124
+ */
125
+ #handlerKeyUp = (event) => {
126
+ this.on.up.send1(event);
107
127
 
108
- //hook up dispatch handler for individual keys
109
- const keyCode = event.keyCode;
128
+ //hook up dispatch handler for individual keys
129
+ const keyCode = event.keyCode;
110
130
 
111
- const keyName = codeToKeyNameMap[keyCode];
131
+ const keyName = codeToKeyNameMap[keyCode];
112
132
 
113
- if (keyName !== undefined) {
114
- const button = keys[keyName];
133
+ if (keyName !== undefined) {
134
+ const button = this.keys[keyName];
115
135
 
116
- button.is_down = false;
117
- button.up.send1(event);
118
- }
136
+ button.is_down = false;
137
+ button.up.send1(event);
119
138
  }
120
139
  }
121
140
 
122
-
123
141
  start() {
124
- this.domElement.addEventListener(KeyboardEvents.KeyDown, this.__handlerKeyDown);
125
- this.domElement.addEventListener(KeyboardEvents.KeyUp, this.__handlerKeyUp);
142
+ this.domElement.addEventListener(KeyboardEvents.KeyDown, this.#handlerKeyDown);
143
+ this.domElement.addEventListener(KeyboardEvents.KeyUp, this.#handlerKeyUp);
126
144
  }
127
145
 
128
146
  stop() {
129
- this.domElement.removeEventListener(KeyboardEvents.KeyDown, this.__handlerKeyDown);
130
- this.domElement.removeEventListener(KeyboardEvents.KeyUp, this.__handlerKeyUp);
147
+ this.domElement.removeEventListener(KeyboardEvents.KeyDown, this.#handlerKeyDown);
148
+ this.domElement.removeEventListener(KeyboardEvents.KeyUp, this.#handlerKeyUp);
131
149
  }
132
150
  }
133
151