@woosh/meep-engine 2.37.17 → 2.37.20

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 (206) hide show
  1. package/core/assert.js +1 -1
  2. package/core/binary/float2uint8.js +8 -0
  3. package/core/binary/uint82float.js +8 -0
  4. package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +6 -4
  5. package/core/collection/array/typed/isTypedArray.js +20 -0
  6. package/core/collection/array/typedArrayToDataType.js +1 -0
  7. package/core/collection/list/List.d.ts +1 -1
  8. package/core/collection/table/RowFirstTable.js +34 -0
  9. package/core/collection/table/RowFirstTable.spec.js +59 -1
  10. package/core/color/Color.js +83 -1
  11. package/core/color/YCbCr_to_rgb_uint24.js +3 -4
  12. package/core/color/hsv2rgb.js +4 -3
  13. package/core/color/linear_to_sRGB.js +4 -5
  14. package/core/color/rgb2hex.js +1 -1
  15. package/core/color/rgb2uint24.js +6 -4
  16. package/core/color/rgb_to_YCbCr_uint24.js +11 -13
  17. package/core/events/signal/Signal.d.ts +11 -9
  18. package/core/events/signal/Signal.js +8 -8
  19. package/core/events/signal/Signal.spec.js +16 -0
  20. package/core/geom/2d/quad-tree/qt_collect_by_circle.js +67 -0
  21. package/core/geom/Quaternion.d.ts +21 -1
  22. package/core/geom/Quaternion.js +279 -200
  23. package/core/geom/Quaternion.spec.js +71 -2
  24. package/core/geom/Vector2.js +3 -3
  25. package/core/geom/Vector3.d.ts +2 -0
  26. package/core/geom/Vector3.js +31 -7
  27. package/core/geom/Vector3.schema.json +16 -0
  28. package/core/geom/Vector4.js +16 -0
  29. package/core/json/JsonUtils.js +2 -20
  30. package/core/math/bell_membership_function.js +19 -0
  31. package/core/math/exp2.js +8 -0
  32. package/core/math/interval/NumericInterval.js +17 -0
  33. package/core/math/physics/brdf/brdf_burley.js +25 -0
  34. package/core/math/physics/bsdf/bsdf_schlick.js +22 -0
  35. package/core/math/physics/irradiance/interpolate_irradiance_linear.js +18 -0
  36. package/{engine/sound/ecs/emitter/attenuate/attenuateSoundLogarithmic.js → core/math/physics/irradiance/interpolate_irradiance_lograrithmic.js} +2 -2
  37. package/{engine/sound/ecs/emitter/attenuate/attenuateSoundSmith.js → core/math/physics/irradiance/interpolate_irradiance_smith.js} +1 -1
  38. package/core/model/ObservedEnum.js +8 -0
  39. package/editor/Editor.js +97 -1
  40. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
  41. package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
  42. package/editor/actions/concrete/PatchTerrainHeightAction.js +13 -105
  43. package/editor/ecs/component/FieldDescriptor.js +34 -0
  44. package/editor/ecs/component/FieldValueAdapter.js +20 -0
  45. package/editor/ecs/component/TypeEditor.js +33 -0
  46. package/editor/ecs/component/TypeSchema.d.ts +38 -0
  47. package/editor/ecs/component/createFieldEditor.js +90 -0
  48. package/editor/ecs/component/createObjectEditor.js +266 -60
  49. package/editor/ecs/component/editors/ColorEditor.js +39 -0
  50. package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
  51. package/editor/ecs/component/editors/ImagePathEditor.js +50 -0
  52. package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
  53. package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
  54. package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
  55. package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
  56. package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
  57. package/editor/ecs/component/editors/Sampler2DEditor.js +107 -0
  58. package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
  59. package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
  60. package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
  61. package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
  62. package/editor/ecs/component/editors/common/noEditor.js +9 -0
  63. package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
  64. package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
  65. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +44 -0
  66. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
  67. package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
  68. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +54 -0
  69. package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
  70. package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
  71. package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
  72. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
  73. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +89 -0
  74. package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
  75. package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
  76. package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
  77. package/editor/ecs/component/editors/geom/QuaternionEditor.js +56 -0
  78. package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
  79. package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
  80. package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
  81. package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
  82. package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
  83. package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
  84. package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
  85. package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
  86. package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
  87. package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
  88. package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
  89. package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
  90. package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
  91. package/editor/ecs/component/editors/three/TextureEditor.js +32 -0
  92. package/editor/ecs/component/findNearestRegisteredType.js +59 -0
  93. package/editor/ecs/component/prototypeObjectEditor.js +379 -0
  94. package/editor/tools/SelectionTool.js +1 -1
  95. package/editor/tools/paint/TerrainHeightPaintTool.js +88 -68
  96. package/editor/tools/paint/TerrainPaintTool.js +2 -1
  97. package/editor/tools/paint/TerrainTexturePaintTool.js +8 -73
  98. package/editor/view/EditorView.js +1 -1
  99. package/editor/view/ecs/ComponentControlView.js +2 -30
  100. package/editor/view/ecs/EntityEditor.js +61 -139
  101. package/editor/view/ecs/components/GridObstacleController.js +4 -4
  102. package/editor/view/ecs/components/TerrainController.js +1 -1
  103. package/editor/view/ecs/components/common/NumberController.js +19 -7
  104. package/engine/animation/keyed2/AnimationTrack.js +1 -1
  105. package/engine/asset/AssetManager.d.ts +1 -1
  106. package/engine/asset/AssetManager.js +390 -388
  107. package/engine/asset/loaders/gltf/extensions/MSFT_texture_dds.js +14 -2
  108. package/engine/ecs/components/TagEditor.js +15 -0
  109. package/engine/ecs/fow/FogOfWarEditor.js +13 -0
  110. package/engine/ecs/terrain/ecs/OffsetScaleTransform2D.d.ts +6 -0
  111. package/engine/ecs/terrain/ecs/Terrain.js +44 -43
  112. package/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
  113. package/engine/ecs/terrain/ecs/layers/TerrainLayer.js +1 -1
  114. package/engine/ecs/terrain/ecs/splat/SplatMapping.js +26 -28
  115. package/engine/ecs/terrain/overlay/TerrainOverlay.js +71 -66
  116. package/engine/ecs/terrain/tiles/TerrainTileManager.js +23 -0
  117. package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +1 -1
  118. package/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +13 -7
  119. package/engine/ecs/transform/Transform.d.ts +2 -0
  120. package/engine/ecs/transform/Transform.editor.schema.json +16 -0
  121. package/engine/ecs/transform/Transform.js +3 -0
  122. package/engine/graphics/ecs/highlight/HighlightEditor.js +17 -0
  123. package/engine/graphics/ecs/light/Light.js +0 -47
  124. package/engine/graphics/ecs/light/LightSerializationAdapter.js +50 -0
  125. package/engine/graphics/ecs/mesh/MeshEditor.js +28 -0
  126. package/engine/graphics/ecs/mesh-v2/DrawMode.js +2 -1
  127. package/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +3 -3
  128. package/engine/graphics/ecs/mesh-v2/build_three_object.js +3 -1
  129. package/engine/graphics/ecs/sprite/Sprite.js +11 -0
  130. package/engine/graphics/ecs/sprite/SpriteSystemPE.js +133 -0
  131. package/engine/graphics/ecs/sprite/prototypeSpriteSystem.js +1566 -0
  132. package/engine/graphics/micron/prototypeVirtualGeometry.js +2 -2
  133. package/engine/graphics/micron/render/instanced/shader/shader_rewrite_standard.js +15 -15
  134. package/engine/graphics/particles/particular/engine/ParticularEngine.js +5 -0
  135. package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +17 -9
  136. package/engine/graphics/particles/particular/engine/renderers/ParticleRenderer.js +12 -10
  137. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +7 -2
  138. package/engine/graphics/particles/particular/engine/renderers/billboard/SoftBillboardParticlePool.js +27 -0
  139. package/engine/graphics/particles/particular/engine/renderers/billboard/SoftBillboardParticleRenderer.js +80 -0
  140. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +16 -4
  141. package/engine/graphics/shaders/TerrainShader.js +8 -8
  142. package/engine/graphics/texture/atlas/TextureAtlasDebugger.js +2 -1
  143. package/engine/graphics/texture/sampler/Sampler2D.js +206 -201
  144. package/engine/graphics/texture/sampler/Sampler2D.spec.js +34 -35
  145. package/engine/graphics/texture/sampler/bicubic.js +59 -0
  146. package/engine/graphics/texture/sampler/downsampleSample2D.spec.js +2 -2
  147. package/engine/graphics/texture/sampler/genericResampleSampler2D.js +0 -2
  148. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +146 -0
  149. package/engine/graphics/texture/sampler/{downsampleSampler2D.js → sampler2D_scale_down_linear.js} +8 -4
  150. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +140 -0
  151. package/engine/graphics/texture/sampler/scaleSampler2D.js +3 -3
  152. package/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.js +1 -1
  153. package/engine/graphics/util/ScaleObject3ToBox.js +14 -1
  154. package/engine/graphics/util/makeMeshPreviewScene.js +2 -1
  155. package/engine/grid/components/GridObstacle.js +0 -44
  156. package/engine/grid/components/GridObstacleSerializationAdapter.js +46 -0
  157. package/engine/input/ecs/util/TerrainCameraTargetSampler.js +2 -2
  158. package/engine/navigation/ecs/components/Path.d.ts +2 -0
  159. package/engine/navigation/ecs/components/Path.js +6 -1
  160. package/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +117 -0
  161. package/engine/platform/GetURLHash.js +27 -0
  162. package/engine/platform/WebEnginePlatform.js +1 -22
  163. package/engine/sound/ecs/emitter/SoundEmitter.js +10 -6
  164. package/generation/GridGenerator.js +7 -6
  165. package/generation/example/SampleGenerator0.js +39 -35
  166. package/generation/example/filters/SampleGroundMoistureFilter.js +58 -17
  167. package/generation/example/generators/interactive/mir_generator_place_buff_objects.js +7 -6
  168. package/generation/example/generators/mir_generator_place_bases.js +7 -3
  169. package/generation/example/generators/mir_generator_place_road_decorators.js +3 -3
  170. package/generation/example/generators/mir_generator_place_starting_point.js +3 -2
  171. package/generation/example/themes/SampleTheme0.js +11 -7
  172. package/generation/filtering/numeric/CellFilterLiteralFloat.js +5 -0
  173. package/generation/filtering/numeric/complex/CellFilterDilate.js +36 -0
  174. package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +15 -5
  175. package/generation/filtering/numeric/complex/CellFilterSimplexNoise.js +53 -1
  176. package/generation/filtering/numeric/math/CellFilterMax2.js +3 -0
  177. package/generation/filtering/numeric/math/CellFilterMembershipGeneralizedBell.js +55 -0
  178. package/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.js +42 -0
  179. package/generation/filtering/numeric/sampling/CellFilterSampleLayerCubic.js +36 -0
  180. package/generation/filtering/numeric/sampling/CellFilterSampleLayerLinear.js +41 -0
  181. package/generation/grid/GridData.d.ts +5 -1
  182. package/generation/grid/GridData.js +35 -36
  183. package/generation/grid/MarkerMatchCounter.js +5 -3
  184. package/generation/markers/GridActionRuleSet.js +15 -32
  185. package/generation/markers/GridCellActionPlaceMarker.js +12 -8
  186. package/generation/markers/debug/visualizeMarkers.js +56 -36
  187. package/generation/markers/emitter/MarkerNodeEmitterFromAction.js +8 -8
  188. package/generation/markers/prototypeGridCellActionPlaceMarker.js +209 -0
  189. package/generation/markers/transform/MarkerNodeTransformerOffsetPosition.js +1 -5
  190. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.spec.js +2 -2
  191. package/generation/placement/GridCellPlacementRule.js +31 -25
  192. package/generation/theme/ThemeEngine.js +1 -1
  193. package/package.json +1 -1
  194. package/samples/terrain/from_image.js +7 -3
  195. package/samples/terrain/main.js +1 -1
  196. package/view/View.js +23 -1
  197. package/view/common/LabelView.js +1 -1
  198. package/view/compose3x3transform.js +32 -8
  199. package/view/controller/dat/DatGuiUtils.js +1 -1
  200. package/view/elements/DropDownSelectionView.js +11 -3
  201. package/view/elements/image/ImageView.js +3 -1
  202. package/core/model/ObservedReal.js +0 -55
  203. package/editor/ecs/component/ObjectEditor.js +0 -0
  204. package/engine/graphics/particles/particular/engine/renderers/SoftBillboardParticleRenderer.js +0 -7
  205. package/engine/sound/ecs/emitter/attenuate/attenuateSoundLinear.js +0 -11
  206. package/generation/filtering/numeric/CellFilterReadGridLayer.js +0 -73
package/core/assert.js CHANGED
@@ -1,5 +1,5 @@
1
- import { isTypedArray } from "./json/JsonUtils.js";
2
1
  import { isArrayEqualStrict } from "./collection/array/isArrayEqualStrict.js";
2
+ import { isTypedArray } from "./collection/array/typed/isTypedArray.js";
3
3
 
4
4
  function equal(a, b, m) {
5
5
  assert(a === b, m) // eslint-disable-line eqeqeq
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @param {number} v
4
+ * @returns {number}
5
+ */
6
+ export function float2uint8(v) {
7
+ return Math.round(v * 255);
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @param {number} v
4
+ * @returns {number}
5
+ */
6
+ export function uint82float(v) {
7
+ return v / 255;
8
+ }
@@ -619,20 +619,22 @@ export class ExplicitBinaryBoundingVolumeHierarchy {
619
619
  while (index !== NULL_NODE) {
620
620
  index = this.balance(index);
621
621
 
622
- const child1 = uint32[index * ELEMENT_WORD_COUNT + COLUMN_CHILD_1];
623
- const child2 = uint32[index * ELEMENT_WORD_COUNT + COLUMN_CHILD_2];
622
+ const node_address = index * ELEMENT_WORD_COUNT;
623
+
624
+ const child1 = uint32[node_address + COLUMN_CHILD_1];
625
+ const child2 = uint32[node_address + COLUMN_CHILD_2];
624
626
 
625
627
  assert.notEqual(child1, NULL_NODE, 'child1 is null');
626
628
  assert.notEqual(child2, NULL_NODE, 'child2 is null');
627
629
 
628
- uint32[index * ELEMENT_WORD_COUNT + COLUMN_HEIGHT] = 1 + max2(
630
+ uint32[node_address + COLUMN_HEIGHT] = 1 + max2(
629
631
  uint32[child1 * ELEMENT_WORD_COUNT + COLUMN_HEIGHT],
630
632
  uint32[child2 * ELEMENT_WORD_COUNT + COLUMN_HEIGHT],
631
633
  );
632
634
 
633
635
  this.node_set_combined_aabb(index, child1, child2);
634
636
 
635
- index = uint32[index * ELEMENT_WORD_COUNT + COLUMN_PARENT];
637
+ index = uint32[node_address + COLUMN_PARENT];
636
638
  }
637
639
  }
638
640
 
@@ -0,0 +1,20 @@
1
+ /**
2
+ *
3
+ * @param o
4
+ * @returns {boolean}
5
+ */
6
+ function isTypedArray(o) {
7
+ return (
8
+ o instanceof Int8Array ||
9
+ o instanceof Uint8Array ||
10
+ o instanceof Uint8ClampedArray ||
11
+ o instanceof Int16Array ||
12
+ o instanceof Uint16Array ||
13
+ o instanceof Int32Array ||
14
+ o instanceof Uint32Array ||
15
+ o instanceof Float32Array ||
16
+ o instanceof Float64Array
17
+ );
18
+ }
19
+
20
+ export { isTypedArray };
@@ -10,6 +10,7 @@ export function typedArrayToDataType(v) {
10
10
 
11
11
  switch (ctor) {
12
12
  case Uint8Array:
13
+ case Uint8ClampedArray:
13
14
  return DataType.Uint8;
14
15
  case Uint16Array:
15
16
  return DataType.Uint16;
@@ -5,7 +5,7 @@ export default class List<T> {
5
5
 
6
6
  on: {
7
7
  added: Signal<T>,
8
- removed: Signal<T>
8
+ removed: Signal<T, number>
9
9
  }
10
10
 
11
11
  constructor(elements?: T[])
@@ -6,6 +6,7 @@
6
6
  import { assert } from "../../assert.js";
7
7
  import Signal from "../../events/signal/Signal.js";
8
8
  import { max2 } from "../../math/max2.js";
9
+ import { array_copy } from "../array/copyArray.js";
9
10
 
10
11
  /**
11
12
  *
@@ -414,6 +415,39 @@ RowFirstTable.prototype.setRow = function (index, record) {
414
415
  this.writeRowMethod(this.dataView, this.bytesPerRecord * index, record);
415
416
  }
416
417
 
418
+ /**
419
+ * Reverse order of rows, row-0 will end up at and previously last row will become the first row etc.
420
+ */
421
+ RowFirstTable.prototype.reverse_rows = function () {
422
+ const bpr = this.bytesPerRecord;
423
+ const copy_buffer = new Uint8Array(bpr);
424
+
425
+ const buffer = this.data;
426
+ const wrapper = new Uint8Array(buffer);
427
+
428
+ const length = this.length;
429
+
430
+ if (length <= 1) {
431
+ // need at least 2 rows for reversal to make any change
432
+ return;
433
+ }
434
+
435
+ const last_row_index = length - 1;
436
+
437
+
438
+ const traversal_limit = last_row_index >>> 1;
439
+ for (let i = 0; i <= traversal_limit; i++) {
440
+ const address = i * bpr;
441
+ array_copy(wrapper, address, copy_buffer, 0, bpr);
442
+
443
+ const swap_index = last_row_index - i;
444
+ const swap_address = swap_index * bpr;
445
+
446
+ wrapper.copyWithin(address, swap_address, swap_address + bpr)
447
+ wrapper.set(copy_buffer, swap_address);
448
+ }
449
+ };
450
+
417
451
  /**
418
452
  * clear out all the data and free memory
419
453
  */
@@ -223,7 +223,65 @@ test('copy', () => {
223
223
  a.addRow([-11.3, 13]);
224
224
 
225
225
  const b = new RowFirstTable(spec);
226
- b.copy(a);
226
+ b.copy(a);
227
227
 
228
228
 
229
229
  });
230
+
231
+
232
+ test('reverse_rows 3 rows (odd number)', () => {
233
+
234
+ const spec = new RowFirstTableSpec([DataType.Uint8]);
235
+
236
+ const a = new RowFirstTable(spec);
237
+ a.addRow([1]);
238
+ a.addRow([2]);
239
+ a.addRow([3]);
240
+
241
+ a.reverse_rows();
242
+
243
+ expect(a.readCellValue(0, 0)).toBeCloseTo(3);
244
+ expect(a.readCellValue(1, 0)).toBeCloseTo(2);
245
+ expect(a.readCellValue(2, 0)).toBeCloseTo(1);
246
+ });
247
+
248
+ test('reverse_rows 2 rows', () => {
249
+
250
+ const spec = new RowFirstTableSpec([DataType.Float64, DataType.Uint8]);
251
+
252
+ const a = new RowFirstTable(spec);
253
+ a.addRow([3.1, 7]);
254
+ a.addRow([-11.3, 13]);
255
+
256
+ a.reverse_rows();
257
+
258
+ expect(a.readCellValue(1, 0)).toBeCloseTo(3.1);
259
+ expect(a.readCellValue(1, 1)).toBeCloseTo(7);
260
+
261
+ expect(a.readCellValue(0, 0)).toBeCloseTo(-11.3);
262
+ expect(a.readCellValue(0, 1)).toBeCloseTo(13);
263
+ });
264
+
265
+ test('reverse_rows 1 row', () => {
266
+
267
+ const spec = new RowFirstTableSpec([DataType.Float64, DataType.Uint8]);
268
+
269
+ const a = new RowFirstTable(spec);
270
+
271
+ a.addRow([3.1, 7]);
272
+ a.reverse_rows();
273
+
274
+ expect(a.readCellValue(0, 0)).toBeCloseTo(3.1);
275
+ expect(a.readCellValue(0, 1)).toBeCloseTo(7);
276
+ });
277
+
278
+ test('reverse_rows empty', () => {
279
+
280
+ const spec = new RowFirstTableSpec([DataType.Float64, DataType.Uint8]);
281
+
282
+ const a = new RowFirstTable(spec);
283
+
284
+ a.reverse_rows();
285
+
286
+ expect(a.length).toBe(0);
287
+ });
@@ -9,6 +9,9 @@ import { computeHashFloat } from "../math/hash/computeHashFloat.js";
9
9
  import { rgb2hsv } from "./rgb2hsv.js";
10
10
  import { rgb2uint24 } from "./rgb2uint24.js";
11
11
  import { clamp01 } from "../math/clamp01.js";
12
+ import { rgb2hex } from "./rgb2hex.js";
13
+ import { linear_to_sRGB } from "./linear_to_sRGB.js";
14
+ import { sRGB_to_linear } from "./sRGB_to_linear.js";
12
15
 
13
16
  /**
14
17
  * @class
@@ -346,6 +349,19 @@ export class Color {
346
349
  this.setRGB(r / 255, g / 255, b / 255);
347
350
  }
348
351
 
352
+ /**
353
+ * Returns color in CSS hex color format
354
+ * @example #FF0000
355
+ * @returns {string}
356
+ */
357
+ toHex() {
358
+ return '#' + rgb2hex(
359
+ Math.round(this.r),
360
+ Math.round(this.g),
361
+ Math.round(this.b)
362
+ );
363
+ }
364
+
349
365
  /**
350
366
  *
351
367
  * @param {Color} other
@@ -473,5 +489,71 @@ export class Color {
473
489
  r.parse(str);
474
490
 
475
491
  return r;
476
- };
492
+ }
493
+
494
+ /**
495
+ *
496
+ * @param {Color} input
497
+ * @param {Color} output
498
+ */
499
+ static from_linear_to_sRGB(input, output) {
500
+ linear_to_sRGB(output, 0, input, 0);
501
+ }
502
+
503
+ /**
504
+ *
505
+ * @param {Color} input
506
+ * @param {Color} output
507
+ */
508
+ static from_sRGB_to_linear(input, output) {
509
+ sRGB_to_linear(output, 0, input, 0);
510
+ }
477
511
  }
512
+
513
+ /**
514
+ * @readonly
515
+ * @type {Readonly<Color>}
516
+ */
517
+ Color.red = Object.freeze(new Color(1, 0, 0));
518
+
519
+ /**
520
+ * @readonly
521
+ * @type {Readonly<Color>}
522
+ */
523
+ Color.green = Object.freeze(new Color(0, 1, 0));
524
+
525
+ /**
526
+ * @readonly
527
+ * @type {Readonly<Color>}
528
+ */
529
+ Color.blue = Object.freeze(new Color(0, 0, 1));
530
+
531
+ /**
532
+ * @readonly
533
+ * @type {Readonly<Color>}
534
+ */
535
+ Color.yellow = Object.freeze(new Color(1, 1, 0));
536
+
537
+ /**
538
+ * @readonly
539
+ * @type {Readonly<Color>}
540
+ */
541
+ Color.cyan = Object.freeze(new Color(0, 1, 1));
542
+
543
+ /**
544
+ * @readonly
545
+ * @type {Readonly<Color>}
546
+ */
547
+ Color.magenta = Object.freeze(new Color(1, 0, 1));
548
+
549
+ /**
550
+ * @readonly
551
+ * @type {Readonly<Color>}
552
+ */
553
+ Color.white = Object.freeze(new Color(1, 1, 1));
554
+
555
+ /**
556
+ * @readonly
557
+ * @type {Readonly<Color>}
558
+ */
559
+ Color.black = Object.freeze(new Color(0, 0, 0));
@@ -1,3 +1,5 @@
1
+ import { rgb2uint24 } from "./rgb2uint24.js";
2
+
1
3
  /**
2
4
  * @see https://en.wikipedia.org/wiki/YUV
3
5
  * @param {number} Y
@@ -13,8 +15,5 @@ export function YCbCr_to_rgb_uint24(Y, Cb, Cr) {
13
15
  const g = Y - ((_Cb >> 2) + (_Cb >> 4) + (_Cb >> 5)) - ((_Cr >> 1) + (_Cr >> 3) + (_Cr >> 4) + (_Cr >> 5));
14
16
  const b = Y + _Cb + (_Cb >> 1) + (_Cb >> 2) + (_Cb >> 6);
15
17
 
16
- return (b & 0xFF)
17
- | (g & 0xFF) << 8
18
- | (r & 0xFF) << 16
19
- ;
18
+ return rgb2uint24(r, g, b);
20
19
  }
@@ -1,4 +1,5 @@
1
1
  import { clamp01 } from "../math/clamp01.js";
2
+ import { float2uint8 } from "../binary/float2uint8.js";
2
3
 
3
4
  /**
4
5
  *
@@ -46,9 +47,9 @@ export function hsv2rgb(h, s, v) {
46
47
  break;
47
48
  }
48
49
  return {
49
- r: Math.round(r * 255),
50
- g: Math.round(g * 255),
51
- b: Math.round(b * 255)
50
+ r: float2uint8(r),
51
+ g: float2uint8(g),
52
+ b: float2uint8(b)
52
53
  };
53
54
  }
54
55
 
@@ -1,13 +1,12 @@
1
-
2
- function convert(c){
3
- return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
1
+ function convert(c) {
2
+ return (c < 0.0031308) ? c * 12.92 : 1.055 * (Math.pow(c, 0.41666)) - 0.055;
4
3
  }
5
4
 
6
5
  /**
7
6
  *
8
- * @param {number[]} output
7
+ * @param {number[]|ArrayLike<number>} output
9
8
  * @param {number} output_offset
10
- * @param {number[]} input
9
+ * @param {number[]|ArrayLike<number>} input
11
10
  * @param {number} input_offset
12
11
  */
13
12
  export function linear_to_sRGB(output, output_offset, input, input_offset) {
@@ -1,5 +1,5 @@
1
1
  function dec2hex(c) {
2
- const hex = c.toString(16);
2
+ const hex = Math.round(c).toString(16);
3
3
  return hex.length === 1 ? "0" + hex : hex;
4
4
  }
5
5
 
@@ -1,3 +1,5 @@
1
+ import { float2uint8 } from "../binary/float2uint8.js";
2
+
1
3
  /**
2
4
  *
3
5
  * @param {number} r
@@ -5,10 +7,10 @@
5
7
  * @param {number} b
6
8
  * @returns {number}
7
9
  */
8
- export function rgb2uint24(r,g,b){
9
- const _r = Math.round(r * 255);
10
- const _g = Math.round(g * 255);
11
- const _b = Math.round(b * 255);
10
+ export function rgb2uint24(r, g, b) {
11
+ const _r = float2uint8(r);
12
+ const _g = float2uint8(g);
13
+ const _b = float2uint8(b);
12
14
 
13
15
  return (_b & 0xFF)
14
16
  | (_g & 0xFF) << 8
@@ -1,18 +1,16 @@
1
- /**
2
- *
3
- * @see https://en.wikipedia.org/wiki/YUV
4
- * @param {number} r
5
- * @param {number} g
6
- * @param {number} b
7
- * @returns {number}
8
- */
1
+ import { rgb2uint24 } from "./rgb2uint24.js";
2
+
9
3
  export function rgb_to_YCbCr_uint24(r, g, b) {
10
4
  const Y = 0.299 * r + 0.587 * g + 0.114 * b;
11
5
  const Cb = -0.169 * r - 0.331 * g + 0.499 * b + 128;
12
6
  const Cr = 0.499 * g - 0.418 * g - 0.0813 * b + 128;
13
-
14
- return (Cr & 0xFF)
15
- | (Cb & 0xFF) << 8
16
- | (Y & 0xFF) << 16
17
- ;
7
+ /**
8
+ *
9
+ * @see https://en.wikipedia.org/wiki/YUV
10
+ * @param {number} r
11
+ * @param {number} g
12
+ * @param {number} b
13
+ * @returns {number}
14
+ */
15
+ return rgb2uint24(Y,Cb,Cr);
18
16
  }
@@ -5,9 +5,9 @@ export default class Signal<A = any, B = any, C = any, D = any, E = any, F = any
5
5
  add(listener: (a: A, b: B, c: C) => any, thisArg?: any): void
6
6
  add(listener: (a: A, b: B, c: C, d: D) => any, thisArg?: any): void
7
7
  add(listener: (a: A, b: B, c: C, d: D, e: E) => any, thisArg?: any): void
8
- add(listener: (a: A, b: B, c: C, d: D, e: E,f: F) => any, thisArg?: any): void
9
- add(listener: (a: A, b: B, c: C, d: D, e: E,f: F, g: G) => any, thisArg?: any): void
10
- add(listener: (a: A, b: B, c: C, d: D, e: E,f: F, g: G, h: H) => any, thisArg?: any): void
8
+ add(listener: (a: A, b: B, c: C, d: D, e: E, f: F) => any, thisArg?: any): void
9
+ add(listener: (a: A, b: B, c: C, d: D, e: E, f: F, g: G) => any, thisArg?: any): void
10
+ add(listener: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) => any, thisArg?: any): void
11
11
 
12
12
  addOne(listener: () => any, thisArg?: any): void
13
13
  addOne(listener: (a: A) => any, thisArg?: any): void
@@ -15,9 +15,9 @@ export default class Signal<A = any, B = any, C = any, D = any, E = any, F = any
15
15
  addOne(listener: (a: A, b: B, c: C) => any, thisArg?: any): void
16
16
  addOne(listener: (a: A, b: B, c: C, d: D) => any, thisArg?: any): void
17
17
  addOne(listener: (a: A, b: B, c: C, d: D, e: E) => any, thisArg?: any): void
18
- addOne(listener: (a: A, b: B, c: C, d: D, e: E,f: F) => any, thisArg?: any): void
19
- addOne(listener: (a: A, b: B, c: C, d: D, e: E,f: F, g: G) => any, thisArg?: any): void
20
- addOne(listener: (a: A, b: B, c: C, d: D, e: E,f: F, g: G, h: H) => any, thisArg?: any): void
18
+ addOne(listener: (a: A, b: B, c: C, d: D, e: E, f: F) => any, thisArg?: any): void
19
+ addOne(listener: (a: A, b: B, c: C, d: D, e: E, f: F, g: G) => any, thisArg?: any): void
20
+ addOne(listener: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) => any, thisArg?: any): void
21
21
 
22
22
  remove(listener: () => any, thisArg?: any): void
23
23
  remove(listener: (a: A) => any, thisArg?: any): void
@@ -25,9 +25,9 @@ export default class Signal<A = any, B = any, C = any, D = any, E = any, F = any
25
25
  remove(listener: (a: A, b: B, c: C) => any, thisArg?: any): void
26
26
  remove(listener: (a: A, b: B, c: C, d: D) => any, thisArg?: any): void
27
27
  remove(listener: (a: A, b: B, c: C, d: D, e: E) => any, thisArg?: any): void
28
- remove(listener: (a: A, b: B, c: C, d: D, e: E,f: F) => any, thisArg?: any): void
29
- remove(listener: (a: A, b: B, c: C, d: D, e: E,f: F, g: G) => any, thisArg?: any): void
30
- remove(listener: (a: A, b: B, c: C, d: D, e: E,f: F, g: G, h: H) => any, thisArg?: any): void
28
+ remove(listener: (a: A, b: B, c: C, d: D, e: E, f: F) => any, thisArg?: any): void
29
+ remove(listener: (a: A, b: B, c: C, d: D, e: E, f: F, g: G) => any, thisArg?: any): void
30
+ remove(listener: (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) => any, thisArg?: any): void
31
31
 
32
32
  send0(): void
33
33
 
@@ -47,4 +47,6 @@ export default class Signal<A = any, B = any, C = any, D = any, E = any, F = any
47
47
  * @deprecated use strongly typed dispatch methods instead (send0, send1 etc)
48
48
  */
49
49
  dispatch(...params: any[]): void
50
+
51
+ removeAll(): void
50
52
  }
@@ -240,7 +240,7 @@ export class Signal {
240
240
  // Copy handlers into a temp storage to preserve state during dispatch
241
241
  for (i = 0; i < length; i++) {
242
242
  //copy to proxy
243
- dispatch_stack[stack_pointer + i] = handlers[i];
243
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
244
244
  }
245
245
 
246
246
  // Dispatch phase
@@ -292,7 +292,7 @@ export class Signal {
292
292
  // Copy handlers into a temp storage to preserve state during dispatch
293
293
  for (i = 0; i < length; i++) {
294
294
  //copy to proxy
295
- dispatch_stack[stack_pointer + i] = handlers[i];
295
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
296
296
  }
297
297
 
298
298
  // Dispatch phase
@@ -343,7 +343,7 @@ export class Signal {
343
343
  // Copy handlers into a temp storage to preserve state during dispatch
344
344
  for (i = 0; i < length; i++) {
345
345
  //copy to proxy
346
- dispatch_stack[stack_pointer + i] = handlers[i];
346
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
347
347
  }
348
348
 
349
349
  // Dispatch phase
@@ -395,7 +395,7 @@ export class Signal {
395
395
  // Copy handlers into a temp storage to preserve state during dispatch
396
396
  for (i = 0; i < length; i++) {
397
397
  //copy to proxy
398
- dispatch_stack[stack_pointer + i] = handlers[i];
398
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
399
399
  }
400
400
 
401
401
  // Dispatch phase
@@ -448,7 +448,7 @@ export class Signal {
448
448
  // Copy handlers into a temp storage to preserve state during dispatch
449
449
  for (i = 0; i < length; i++) {
450
450
  //copy to proxy
451
- dispatch_stack[stack_pointer + i] = handlers[i];
451
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
452
452
  }
453
453
 
454
454
  // Dispatch phase
@@ -503,7 +503,7 @@ export class Signal {
503
503
  // Copy handlers into a temp storage to preserve state during dispatch
504
504
  for (i = 0; i < length; i++) {
505
505
  //copy to proxy
506
- dispatch_stack[stack_pointer + i] = handlers[i];
506
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
507
507
  }
508
508
 
509
509
  // Dispatch phase
@@ -560,7 +560,7 @@ export class Signal {
560
560
  // Copy handlers into a temp storage to preserve state during dispatch
561
561
  for (i = 0; i < length; i++) {
562
562
  //copy to proxy
563
- dispatch_stack[stack_pointer + i] = handlers[i];
563
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
564
564
  }
565
565
 
566
566
  // Dispatch phase
@@ -731,7 +731,7 @@ export function dispatchViaProxy(handlers, args) {
731
731
  let i, h;
732
732
  for (i = 0; i < length; i++) {
733
733
  //copy to proxy
734
- dispatch_stack[stack_pointer + i] = handlers[i];
734
+ dispatch_stack[stack_pointer + i] = handlers[length - (i + 1)];
735
735
  }
736
736
 
737
737
  for (i = stack_frame_end - 1; i >= stack_pointer; i--) {
@@ -147,3 +147,19 @@ test("handler context is properly setup during dispatch", () => {
147
147
 
148
148
  expect(handler).toHaveBeenCalled();
149
149
  });
150
+
151
+ test("handlers should be executed in the order in which they are added", () => {
152
+ const signal = new Signal();
153
+
154
+ const marks = [];
155
+
156
+ const write_1 = jest.fn(() => marks.push(1));
157
+ const write_2 = jest.fn(() => marks.push(2));
158
+
159
+ signal.add(write_1);
160
+ signal.add(write_2);
161
+
162
+ signal.send0();
163
+
164
+ expect(marks).toEqual([1, 2]);
165
+ });
@@ -0,0 +1,67 @@
1
+ import { aabb2_sqrDistanceToPoint } from "../AABB2Math.js";
2
+
3
+ /**
4
+ *
5
+ * @type {QuadTreeNode[]}
6
+ */
7
+ const node_stack = [];
8
+
9
+ /**
10
+ * @template T
11
+ * @param {QuadTreeDatum<T>[]} result
12
+ * @param {number} result_offset
13
+ * @param {QuadTreeNode<T>} tree
14
+ * @param {number} x
15
+ * @param {number} y
16
+ * @param {number} radius
17
+ * @returns {number}
18
+ */
19
+ export function qt_collect_by_circle(
20
+ result, result_offset,
21
+ tree,
22
+ x, y, radius
23
+ ) {
24
+ let result_cursor = result_offset;
25
+
26
+ let stack_pointer = 0;
27
+
28
+ const r2 = radius * radius;
29
+
30
+ node_stack[stack_pointer] = tree;
31
+ stack_pointer++;
32
+
33
+ while (stack_pointer > 0) {
34
+
35
+ --stack_pointer;
36
+ const node = node_stack[stack_pointer];
37
+
38
+ const d2 = aabb2_sqrDistanceToPoint(node.x0, node.y0, node.x1, node.y1, x, y);
39
+
40
+ if (d2 > r2) {
41
+ // not a match
42
+ continue;
43
+ }
44
+
45
+ const data = node.data;
46
+ const data_count = data.length;
47
+
48
+ for (let i = 0; i < data_count; i++) {
49
+ const datum = data[i];
50
+
51
+ const d2_to_datum = aabb2_sqrDistanceToPoint(datum.x0, datum.y0, datum.x1, datum.y1, x, y);
52
+
53
+ if (d2_to_datum <= r2) {
54
+ result[result_cursor++] = datum;
55
+ }
56
+ }
57
+
58
+ if (node.isSplit()) {
59
+ node_stack[stack_pointer++] = node.topLeft;
60
+ node_stack[stack_pointer++] = node.bottomLeft;
61
+ node_stack[stack_pointer++] = node.topRight;
62
+ node_stack[stack_pointer++] = node.bottomRight;
63
+ }
64
+ }
65
+
66
+ return result_cursor - result_offset;
67
+ }
@@ -1,5 +1,6 @@
1
1
  import Signal from "../events/signal/Signal";
2
2
  import {Matrix4, Quaternion as ThreeQuaternion} from "three";
3
+ import Vector3 from "./Vector3";
3
4
 
4
5
  export default class Quaternion {
5
6
  public x: number
@@ -7,7 +8,7 @@ export default class Quaternion {
7
8
  public z: number
8
9
  public w: number
9
10
 
10
- public get onChanged(): Signal;
11
+ readonly onChanged: Signal<number, number, number, number, number, number, number, number>;
11
12
 
12
13
  set(x: number, y: number, z: number, w: number): void
13
14
 
@@ -15,6 +16,10 @@ export default class Quaternion {
15
16
  copy(other: ThreeQuaternion): void
16
17
  copy(other: { x: number, y: number, z: number, w: number }): void
17
18
 
19
+ equals(other: { x: number, y: number, z: number, w: number }): boolean
20
+
21
+ normalize(): void
22
+
18
23
  __setThreeEuler(threeEuler: any): void
19
24
 
20
25
  __setFromEuler(x: number, y: number, z: number, order?: string): void
@@ -24,4 +29,19 @@ export default class Quaternion {
24
29
  setFromRotationMatrix(m: Matrix4): void
25
30
 
26
31
  decodeFromUint32(uint: number): void
32
+
33
+
34
+ toEulerAnglesXYZ(v3: { set(x: number, y: number, z: number): any }): void
35
+
36
+ fromEulerAnglesXYZ(x: number, y: number, z: number): void
37
+
38
+ fromAxisAngle(axis: Vector3 | { x: number, y: number, z: number }, angle: number): void
39
+
40
+ computeTwistAngle(axis: Vector3): number
41
+
42
+ multiplyQuaternions(a: Quaternion, b: Quaternion): void
43
+
44
+ toJSON(): any
45
+
46
+ fromJSON(j: any): void
27
47
  }