@woosh/meep-engine 2.75.8 → 2.75.9

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 (77) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +784 -982
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +784 -982
  5. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
  6. package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
  7. package/editor/process/EditorProcess.js +12 -16
  8. package/editor/process/ProcessEngine.js +9 -10
  9. package/package.json +1 -1
  10. package/src/core/binary/dec2hex.js +1 -1
  11. package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
  12. package/src/core/math/newton_solver_1d.js +13 -4
  13. package/src/core/math/solveQuadratic.js +5 -3
  14. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  15. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  17. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  18. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  19. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  20. package/src/engine/control/ControlContext.js +25 -27
  21. package/src/engine/ecs/EntityManager.js +12 -9
  22. package/src/engine/ecs/EntityObserver.js +26 -22
  23. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  24. package/src/engine/ecs/components/Motion.js +5 -7
  25. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  26. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  27. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  28. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  29. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  30. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  31. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  32. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  33. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  34. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  35. package/src/engine/ecs/parent/EntityNode.js +39 -37
  36. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  37. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  38. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  39. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  40. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  41. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  42. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  43. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  44. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  45. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  46. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  47. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  48. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  49. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  50. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -4
  51. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -4
  52. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  53. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  54. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  55. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  56. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  57. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  58. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  59. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  60. package/src/engine/navigation/ecs/components/Path.js +10 -9
  61. package/src/engine/physics/computeInterceptPoint.js +44 -0
  62. package/src/engine/plugin/EnginePlugin.js +1 -2
  63. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  64. package/src/engine/ecs/components/CharacterController.js +0 -31
  65. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  66. package/src/engine/ecs/components/Steering.js +0 -111
  67. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  68. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  69. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  70. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  71. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  72. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  73. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  74. package/src/engine/ecs/systems/TagSystem.js +0 -31
  75. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  76. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  77. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
@@ -49635,137 +49635,6 @@ const TerrainShader = {
49635
49635
  fragmentShader: fragment$2()
49636
49636
  };
49637
49637
 
49638
- /**
49639
- *
49640
- * Produces a proportional mix of 2 values, a*(1-portion) + b*portion
49641
- * Same as lerp
49642
- */
49643
- const mix = lerp$1;
49644
-
49645
- /**
49646
- * Color blending modes
49647
- * @enum {number}
49648
- */
49649
- const BlendingType = {
49650
- NoBlending: 5,
49651
- Normal: 0,
49652
- Add: 1,
49653
- Subtract: 2,
49654
- Multiply: 3,
49655
- MultiplyAdd: 4
49656
- };
49657
-
49658
- function typedArrayConstructorByInstance(a) {
49659
- if (a instanceof Int8Array) {
49660
- return Int8Array;
49661
- } else if (a instanceof Int16Array) {
49662
- return Int16Array;
49663
- } else if (a instanceof Int32Array) {
49664
- return Int32Array;
49665
- } else if (a instanceof Uint8Array) {
49666
- return Uint8Array;
49667
- } else if (a instanceof Uint8ClampedArray) {
49668
- return Uint8ClampedArray;
49669
- } else if (a instanceof Uint16Array) {
49670
- return Uint16Array;
49671
- } else if (a instanceof Uint32Array) {
49672
- return Uint32Array;
49673
- } else if (a instanceof Float32Array) {
49674
- return Float32Array;
49675
- } else if (a instanceof Float64Array) {
49676
- return Float64Array;
49677
- } else if (Array.isArray(a)) {
49678
- return Array;
49679
- } else {
49680
- throw new TypeError(`Unsupported array type`);
49681
- }
49682
- }
49683
-
49684
- /**
49685
- * @readonly
49686
- * @enum {string}
49687
- */
49688
- const BinaryDataType = {
49689
- Uint8: "uint8",
49690
- Uint16: "uint16",
49691
- Uint32: "uint32",
49692
- Uint64: "uint64",
49693
-
49694
- Int8: "int8",
49695
- Int16: "int16",
49696
- Int32: "int32",
49697
- Int64: "int64",
49698
-
49699
- Float16: 'float16',
49700
- Float32: "float32",
49701
- Float64: "float64"
49702
- };
49703
-
49704
- /**
49705
- *
49706
- * @param {*} v
49707
- * @returns {BinaryDataType}
49708
- */
49709
- function typedArrayToDataType(v) {
49710
- const ctor = Object.getPrototypeOf(v).constructor;
49711
-
49712
- switch (ctor) {
49713
- case Uint8Array:
49714
- case Uint8ClampedArray:
49715
- return BinaryDataType.Uint8;
49716
- case Uint16Array:
49717
- return BinaryDataType.Uint16;
49718
- case Uint32Array:
49719
- return BinaryDataType.Uint32;
49720
-
49721
- case Int8Array:
49722
- return BinaryDataType.Int8;
49723
- case Int16Array:
49724
- return BinaryDataType.Int16;
49725
- case Int32Array:
49726
- return BinaryDataType.Int32;
49727
-
49728
- case Float32Array:
49729
- return BinaryDataType.Float32;
49730
- case Float64Array:
49731
- return BinaryDataType.Float64;
49732
- default:
49733
- throw new Error('unsupported constructor type');
49734
- }
49735
- }
49736
-
49737
- /**
49738
- * Mapping from {@DataType} to TypedArray constructors
49739
- * @enum {function}
49740
- */
49741
- const DataType2TypedArrayConstructorMapping = {
49742
- [BinaryDataType.Uint8]: Uint8Array,
49743
- [BinaryDataType.Uint16]: Uint16Array,
49744
- [BinaryDataType.Uint32]: Uint32Array,
49745
- [BinaryDataType.Int8]: Int8Array,
49746
- [BinaryDataType.Int16]: Int16Array,
49747
- [BinaryDataType.Int32]: Int32Array,
49748
- // No float16 array type, using uint16 as a backing instead
49749
- [BinaryDataType.Float16]: Uint16Array,
49750
- [BinaryDataType.Float32]: Float32Array,
49751
- [BinaryDataType.Float64]: Float64Array,
49752
- };
49753
-
49754
- /**
49755
- *
49756
- * @param {BinaryDataType} dt
49757
- * @returns {constructor|function}
49758
- */
49759
- function compute_typed_array_constructor_from_data_type(dt) {
49760
- const r = DataType2TypedArrayConstructorMapping[dt];
49761
-
49762
- if (r === undefined) {
49763
- throw new Error(`Unsupported data type '${dt}'`);
49764
- }
49765
-
49766
- return r;
49767
- }
49768
-
49769
49638
  /**
49770
49639
  * Adapted from https://github.com/beatgammit/base64-js
49771
49640
  * @author Jameson Little
@@ -49978,25 +49847,55 @@ class Base64 {
49978
49847
  }
49979
49848
 
49980
49849
  /**
49981
- * Useful for computing hashes of large arrays, can pick a relevant stride and skip large chunks of memory while still capturing good amount of unique information from evenly-spaced areas of the array
49982
- * @param {number[]|Uint32Array|Uint16Array|Uint8Array} array
49983
- * @param {number} offset
49984
- * @param {number} length
49985
- * @param {number} stride
49986
- * @return {number}
49850
+ * @readonly
49851
+ * @enum {string}
49987
49852
  */
49988
- function computeStridedIntegerArrayHash(
49989
- array, offset, length, stride
49990
- ) {
49991
- let result = length;
49853
+ const BinaryDataType = {
49854
+ Uint8: "uint8",
49855
+ Uint16: "uint16",
49856
+ Uint32: "uint32",
49857
+ Uint64: "uint64",
49992
49858
 
49993
- for (let i = offset; i < length; i += stride) {
49994
- const value = array[i];
49859
+ Int8: "int8",
49860
+ Int16: "int16",
49861
+ Int32: "int32",
49862
+ Int64: "int64",
49995
49863
 
49996
- result = ((result * 31) + value) | 0;
49864
+ Float16: 'float16',
49865
+ Float32: "float32",
49866
+ Float64: "float64"
49867
+ };
49868
+
49869
+ /**
49870
+ * Mapping from {@DataType} to TypedArray constructors
49871
+ * @enum {function}
49872
+ */
49873
+ const DataType2TypedArrayConstructorMapping = {
49874
+ [BinaryDataType.Uint8]: Uint8Array,
49875
+ [BinaryDataType.Uint16]: Uint16Array,
49876
+ [BinaryDataType.Uint32]: Uint32Array,
49877
+ [BinaryDataType.Int8]: Int8Array,
49878
+ [BinaryDataType.Int16]: Int16Array,
49879
+ [BinaryDataType.Int32]: Int32Array,
49880
+ // No float16 array type, using uint16 as a backing instead
49881
+ [BinaryDataType.Float16]: Uint16Array,
49882
+ [BinaryDataType.Float32]: Float32Array,
49883
+ [BinaryDataType.Float64]: Float64Array,
49884
+ };
49885
+
49886
+ /**
49887
+ *
49888
+ * @param {BinaryDataType} dt
49889
+ * @returns {constructor|function}
49890
+ */
49891
+ function compute_typed_array_constructor_from_data_type(dt) {
49892
+ const r = DataType2TypedArrayConstructorMapping[dt];
49893
+
49894
+ if (r === undefined) {
49895
+ throw new Error(`Unsupported data type '${dt}'`);
49997
49896
  }
49998
49897
 
49999
- return result;
49898
+ return r;
50000
49899
  }
50001
49900
 
50002
49901
  //
@@ -50066,6 +49965,107 @@ function is_typed_array_equals(a, b) {
50066
49965
  return isArrayEqualStrict(a_proxy, b_proxy);
50067
49966
  }
50068
49967
 
49968
+ /**
49969
+ *
49970
+ * @param {*} v
49971
+ * @returns {BinaryDataType}
49972
+ */
49973
+ function typedArrayToDataType(v) {
49974
+ const ctor = Object.getPrototypeOf(v).constructor;
49975
+
49976
+ switch (ctor) {
49977
+ case Uint8Array:
49978
+ case Uint8ClampedArray:
49979
+ return BinaryDataType.Uint8;
49980
+ case Uint16Array:
49981
+ return BinaryDataType.Uint16;
49982
+ case Uint32Array:
49983
+ return BinaryDataType.Uint32;
49984
+
49985
+ case Int8Array:
49986
+ return BinaryDataType.Int8;
49987
+ case Int16Array:
49988
+ return BinaryDataType.Int16;
49989
+ case Int32Array:
49990
+ return BinaryDataType.Int32;
49991
+
49992
+ case Float32Array:
49993
+ return BinaryDataType.Float32;
49994
+ case Float64Array:
49995
+ return BinaryDataType.Float64;
49996
+ default:
49997
+ throw new Error('unsupported constructor type');
49998
+ }
49999
+ }
50000
+
50001
+ /**
50002
+ *
50003
+ * Produces a proportional mix of 2 values, a*(1-portion) + b*portion
50004
+ * Same as lerp
50005
+ */
50006
+ const mix = lerp$1;
50007
+
50008
+ /**
50009
+ * Based on code from reddit https://www.reddit.com/r/javascript/comments/jxa8x/bicubic_interpolation/
50010
+ * @param {number} t ratio
50011
+ * @param {number} a position -2
50012
+ * @param {number} b position -1
50013
+ * @param {number} c position +1
50014
+ * @param {number} d position +2
50015
+ * @returns {number}
50016
+ */
50017
+ function interpolate_bicubic(t, a, b, c, d) {
50018
+ return 0.5 * (c - a + (2.0 * a - 5.0 * b + 4.0 * c - d + (3.0 * (b - c) + d - a) * t) * t) * t + b;
50019
+ }
50020
+
50021
+ /**
50022
+ * Useful for computing hashes of large arrays, can pick a relevant stride and skip large chunks of memory while still capturing good amount of unique information from evenly-spaced areas of the array
50023
+ * @param {number[]|Uint32Array|Uint16Array|Uint8Array} array
50024
+ * @param {number} offset
50025
+ * @param {number} length
50026
+ * @param {number} stride
50027
+ * @return {number}
50028
+ */
50029
+ function computeStridedIntegerArrayHash(
50030
+ array, offset, length, stride
50031
+ ) {
50032
+ let result = length;
50033
+
50034
+ for (let i = offset; i < length; i += stride) {
50035
+ const value = array[i];
50036
+
50037
+ result = ((result * 31) + value) | 0;
50038
+ }
50039
+
50040
+ return result;
50041
+ }
50042
+
50043
+ function typedArrayConstructorByInstance(a) {
50044
+ if (a instanceof Int8Array) {
50045
+ return Int8Array;
50046
+ } else if (a instanceof Int16Array) {
50047
+ return Int16Array;
50048
+ } else if (a instanceof Int32Array) {
50049
+ return Int32Array;
50050
+ } else if (a instanceof Uint8Array) {
50051
+ return Uint8Array;
50052
+ } else if (a instanceof Uint8ClampedArray) {
50053
+ return Uint8ClampedArray;
50054
+ } else if (a instanceof Uint16Array) {
50055
+ return Uint16Array;
50056
+ } else if (a instanceof Uint32Array) {
50057
+ return Uint32Array;
50058
+ } else if (a instanceof Float32Array) {
50059
+ return Float32Array;
50060
+ } else if (a instanceof Float64Array) {
50061
+ return Float64Array;
50062
+ } else if (Array.isArray(a)) {
50063
+ return Array;
50064
+ } else {
50065
+ throw new TypeError(`Unsupported array type`);
50066
+ }
50067
+ }
50068
+
50069
50069
  /**
50070
50070
  * Created by Alex on 11/11/2014.
50071
50071
  */
@@ -50134,35 +50134,6 @@ class Sampler2D {
50134
50134
  this.version = 0;
50135
50135
  }
50136
50136
 
50137
- /**
50138
- * @deprecated
50139
- * @param {number} [channel=0]
50140
- * @returns {{x: number, index: number, y: number, value: number}}
50141
- */
50142
- computeMax(channel = 0) {
50143
- throw new Error("deprecated, use sampler2d_channel_compute_max");
50144
- }
50145
-
50146
- /**
50147
- * @deprecated
50148
- * @param {number[]} result
50149
- * @param {number} result_offset
50150
- * @param {number} [channel=0]
50151
- * @returns {number} number of matches written to result array
50152
- */
50153
- computeMinIndices(result, result_offset = 0, channel = 0) {
50154
- throw new Error("deprecated, use sampler2d_channel_compute_min_indices")
50155
- }
50156
-
50157
- /**
50158
- * @deprecated
50159
- * @param {number} [channel=0]
50160
- * @returns {{x: number, index: number, y: number, value: number}}
50161
- */
50162
- computeMin(channel = 0) {
50163
- throw new Error("deprecated, use sampler2d_channel_compute_min");
50164
- }
50165
-
50166
50137
  /**
50167
50138
  *
50168
50139
  * @deprecated
@@ -50172,18 +50143,7 @@ class Sampler2D {
50172
50143
  * @returns {number}
50173
50144
  */
50174
50145
  get(x, y, result) {
50175
- console.warn("Deprecated method, use sampleBilinear instead");
50176
-
50177
- const t = [];
50178
-
50179
- this.sampleBilinear(x, y, t, 0);
50180
-
50181
- if (result !== undefined) {
50182
- result.readFromArray(t, 0);
50183
- return result;
50184
- } else {
50185
- return t[0];
50186
- }
50146
+ throw new Error("Deprecated method, use sampleBilinear instead");
50187
50147
  }
50188
50148
 
50189
50149
  /**
@@ -50386,23 +50346,14 @@ class Sampler2D {
50386
50346
  const vl2 = data[row3_address + col2_offset];
50387
50347
  const vl3 = data[row3_address + col3_offset];
50388
50348
 
50389
-
50390
- // return bicubic(xd, yd,
50391
- // vi0, vi1, vi2, vi3,
50392
- // vj0, vj1, vj2, vj3,
50393
- // vk0, vk1, vk2, vk3,
50394
- // vl0, vl1, vl2, vl3,
50395
- // );
50396
-
50397
-
50398
50349
  // perform filtering in X (rows)
50399
- const s0 = bicubic_terp(xd, vi0, vi1, vi2, vi3);
50400
- const s1 = bicubic_terp(xd, vj0, vj1, vj2, vj3);
50401
- const s2 = bicubic_terp(xd, vk0, vk1, vk2, vk3);
50402
- const s3 = bicubic_terp(xd, vl0, vl1, vl2, vl3);
50350
+ const s0 = interpolate_bicubic(xd, vi0, vi1, vi2, vi3);
50351
+ const s1 = interpolate_bicubic(xd, vj0, vj1, vj2, vj3);
50352
+ const s2 = interpolate_bicubic(xd, vk0, vk1, vk2, vk3);
50353
+ const s3 = interpolate_bicubic(xd, vl0, vl1, vl2, vl3);
50403
50354
 
50404
50355
  // filter in Y (columns)
50405
- return bicubic_terp(yd, s0, s1, s2, s3);
50356
+ return interpolate_bicubic(yd, s0, s1, s2, s3);
50406
50357
  }
50407
50358
 
50408
50359
  /**
@@ -50641,162 +50592,6 @@ class Sampler2D {
50641
50592
  result.set(x, y);
50642
50593
  }
50643
50594
 
50644
- /**
50645
- * Copy a patch from another sampler with a margin.
50646
- * This is useful for texture rendering where filtering can cause bleeding along the edges of the patch.
50647
- * @param {Sampler2D} source where to copy from
50648
- * @param {Number} sourceX where to start reading from, X coordinate
50649
- * @param {Number} sourceY where to start reading from, X coordinate
50650
- * @param {Number} destinationX where to start writing to, X coordinate
50651
- * @param {Number} destinationY where to start writing to, X coordinate
50652
- * @param {Number} width size of the patch that is to be copied
50653
- * @param {Number} height size of the patch that is to be copied
50654
- * @param {Number} marginLeft
50655
- * @param {Number} marginRight
50656
- * @param {Number} marginTop
50657
- * @param {Number} marginBottom
50658
- */
50659
- copyWithMargin(source, sourceX, sourceY, destinationX, destinationY, width, height, marginLeft, marginRight, marginTop, marginBottom) {
50660
- const dItemSize = this.itemSize;
50661
- const sItemSize = source.itemSize;
50662
- const _itemSize = Math.min(dItemSize, sItemSize);
50663
-
50664
-
50665
- const dRowSize = dItemSize * this.width;
50666
- const sRowSize = sItemSize * source.width;
50667
-
50668
- const sData = source.data;
50669
- const dData = this.data;
50670
-
50671
- let x, y, i;
50672
-
50673
- let xMax, yMax;
50674
-
50675
- let dA, sA, dOffset, sOffset;
50676
- //Write top-left corner
50677
- sOffset = sourceY * sRowSize + sourceX * dItemSize;
50678
- for (y = Math.max(0, destinationY - marginTop), yMax = destinationY; y < yMax; y++) {
50679
- dA = y * dRowSize;
50680
-
50681
- for (x = Math.max(0, destinationX - marginLeft), xMax = destinationX; x < xMax; x++) {
50682
-
50683
- dOffset = dA + x * dItemSize;
50684
-
50685
- for (i = 0; i < _itemSize; i++) {
50686
- dData[dOffset + i] = sData[sOffset + i];
50687
- }
50688
- }
50689
- }
50690
- //Write top margin
50691
- sA = sourceY * sRowSize;
50692
- for (y = Math.max(0, destinationY - marginTop), yMax = destinationY; y < yMax; y++) {
50693
- dA = y * dRowSize;
50694
-
50695
- for (x = 0; x < width; x++) {
50696
-
50697
- dOffset = dA + (x + destinationX) * dItemSize;
50698
- sOffset = sA + (x + sourceX) * dItemSize;
50699
- for (i = 0; i < _itemSize; i++) {
50700
- dData[dOffset + i] = sData[sOffset + i];
50701
- }
50702
- }
50703
- }
50704
- //Write top-right corner
50705
- sOffset = sourceY * sRowSize + (sourceX + width - 1) * dItemSize;
50706
- for (y = Math.max(0, destinationY - marginTop), yMax = destinationY; y < yMax; y++) {
50707
- dA = y * dRowSize;
50708
-
50709
- for (x = destinationX + width, xMax = Math.min(this.width, x + marginRight); x < xMax; x++) {
50710
-
50711
- dOffset = dA + x * dItemSize;
50712
-
50713
- for (i = 0; i < _itemSize; i++) {
50714
- dData[dOffset + i] = sData[sOffset + i];
50715
- }
50716
- }
50717
- }
50718
- //Write left margin
50719
- for (y = 0; y < height; y++) {
50720
- dA = (y + destinationY) * dRowSize;
50721
- sA = (y + sourceY) * sRowSize;
50722
-
50723
- sOffset = sA + (sourceX) * dItemSize;
50724
-
50725
- for (x = Math.max(0, destinationX - marginLeft), xMax = destinationX; x < xMax; x++) {
50726
-
50727
- dOffset = dA + x * dItemSize;
50728
-
50729
- for (i = 0; i < _itemSize; i++) {
50730
- dData[dOffset + i] = sData[sOffset + i];
50731
- }
50732
- }
50733
- }
50734
- //write actual patch
50735
- this.copy(source, sourceX, sourceY, destinationX, destinationY, width, height);
50736
-
50737
- //Write right margin
50738
- for (y = 0; y < height; y++) {
50739
- dA = (y + destinationY) * dRowSize;
50740
- sA = (y + sourceY) * sRowSize;
50741
-
50742
- sOffset = sA + (sourceX + width - 1) * dItemSize;
50743
-
50744
- for (x = destinationX + width, xMax = Math.min(this.width, x + marginRight); x < xMax; x++) {
50745
-
50746
- dOffset = dA + x * dItemSize;
50747
-
50748
- for (i = 0; i < _itemSize; i++) {
50749
- dData[dOffset + i] = sData[sOffset + i];
50750
- }
50751
- }
50752
- }
50753
-
50754
- //Write Bottom-left margin
50755
- sOffset = (sourceY + height - 1) * sRowSize + sourceX * dItemSize;
50756
- for (y = destinationY + width, yMax = Math.min(this.height, y + marginBottom); y < yMax; y++) {
50757
- dA = y * dRowSize;
50758
-
50759
- for (x = Math.max(0, destinationX - marginLeft), xMax = destinationX; x < xMax; x++) {
50760
-
50761
- dOffset = dA + x * dItemSize;
50762
-
50763
- for (i = 0; i < _itemSize; i++) {
50764
- dData[dOffset + i] = sData[sOffset + i];
50765
- }
50766
- }
50767
- }
50768
- //Write Bottom margin
50769
- sA = (sourceY + height - 1) * sRowSize;
50770
- for (y = destinationY + width, yMax = Math.min(this.height, y + marginBottom); y < yMax; y++) {
50771
- dA = y * dRowSize;
50772
-
50773
- for (x = 0; x < width; x++) {
50774
-
50775
- dOffset = dA + (x + destinationX) * dItemSize;
50776
- sOffset = sA + (x + sourceX) * dItemSize;
50777
- for (i = 0; i < _itemSize; i++) {
50778
- dData[dOffset + i] = sData[sOffset + i];
50779
- }
50780
- }
50781
- }
50782
- //Write Bottom-right margin
50783
- sOffset = (sourceY + height - 1) * sRowSize + (sourceX + width - 1) * dItemSize;
50784
- for (y = destinationY + width, yMax = Math.min(this.height, y + marginBottom); y < yMax; y++) {
50785
- dA = y * dRowSize;
50786
-
50787
- for (x = destinationX + width, xMax = Math.min(this.width, x + marginRight); x < xMax; x++) {
50788
-
50789
- dOffset = dA + x * dItemSize;
50790
-
50791
- for (i = 0; i < _itemSize; i++) {
50792
- dData[dOffset + i] = sData[sOffset + i];
50793
- }
50794
- }
50795
- }
50796
-
50797
- this.version++;
50798
- }
50799
-
50800
50595
  /**
50801
50596
  * Copy a patch from another sampler
50802
50597
  * @param {Sampler2D} source where to copy from
@@ -50853,106 +50648,6 @@ class Sampler2D {
50853
50648
  this.version++;
50854
50649
  }
50855
50650
 
50856
- /**
50857
- * Copy a patch from another sampler with the same itemSize
50858
- * @param {Sampler2D} source where to copy from
50859
- * @param {Number} sourceX where to start reading from, X coordinate
50860
- * @param {Number} sourceY where to start reading from, X coordinate
50861
- * @param {Number} destinationX where to start writing to, X coordinate
50862
- * @param {Number} destinationY where to start writing to, X coordinate
50863
- * @param {Number} width size of the patch that is to be copied
50864
- * @param {Number} height size of the patch that is to be copied
50865
- */
50866
- copy_sameItemSize(source, sourceX, sourceY, destinationX, destinationY, width, height) {
50867
- const itemSize = this.itemSize;
50868
- const sItemSize = source.itemSize;
50869
-
50870
- assert.equal(sItemSize, sItemSize, `source.itemSize(=${sItemSize}) != this.itemSize(=${itemSize})`);
50871
-
50872
- const _w = Math.min(width, source.width - sourceX, this.width - destinationX);
50873
- const _h = Math.min(height, source.height - sourceY, this.height - destinationY);
50874
-
50875
-
50876
- const dRowSize = itemSize * this.width;
50877
- const sRowSize = itemSize * source.width;
50878
-
50879
- const sData = source.data;
50880
- const dData = this.data;
50881
-
50882
- const patchRowSize = _w * itemSize;
50883
-
50884
- let y, i;
50885
-
50886
- for (y = 0; y < _h; y++) {
50887
- const dA = (y + destinationY) * dRowSize;
50888
- const sA = (y + sourceY) * sRowSize;
50889
-
50890
- const dOffset = dA + destinationX * itemSize;
50891
- const sOffset = sA + sourceX * itemSize;
50892
-
50893
- for (i = 0; i < patchRowSize; i++) {
50894
-
50895
- dData[dOffset + i] = sData[sOffset + i];
50896
-
50897
- }
50898
- }
50899
-
50900
- this.version++;
50901
- }
50902
-
50903
- /**
50904
- * Assumes both samplers are uint8 with values 0-255
50905
- * @param {Sampler2D} source
50906
- * @param sourceX
50907
- * @param sourceY
50908
- * @param destinationX
50909
- * @param destinationY
50910
- * @param width
50911
- * @param height
50912
- * @param {BlendingType} [blendMode]
50913
- */
50914
- paint(source, sourceX, sourceY, destinationX, destinationY, width, height, blendMode = BlendingType.Normal) {
50915
- let blendFunction;
50916
- if (blendMode === BlendingType.Normal) {
50917
- blendFunction = blendFunctionNormal;
50918
- } else {
50919
- throw new Error(`Unsupported blendType(=${blendMode})`);
50920
- }
50921
-
50922
- const _w = Math.min(width, source.width - sourceX, this.width - destinationX);
50923
- const _h = Math.min(height, source.height - sourceY, this.height - destinationY);
50924
-
50925
- const _x0 = Math.max(0, -destinationX);
50926
- const _y0 = Math.max(0, -destinationY);
50927
-
50928
- const c0 = [0, 0, 0, 255];
50929
- const c1 = [0, 0, 0, 255];
50930
-
50931
- const c3 = [];
50932
-
50933
- let x, y;
50934
-
50935
- for (y = _y0; y < _h; y++) {
50936
- for (x = _x0; x < _w; x++) {
50937
- const d_x = Math.round(x + destinationX);
50938
- const d_y = Math.round(y + destinationY);
50939
-
50940
- this.read(d_x, d_y, c0);
50941
-
50942
- const s_x = Math.round(x + sourceY);
50943
- const s_y = Math.round(y + sourceY);
50944
-
50945
- source.read(s_x, s_y, c1);
50946
-
50947
- blendFunction(c1, c0, c3);
50948
-
50949
- this.set(d_x, d_y, c3);
50950
-
50951
- }
50952
- }
50953
-
50954
-
50955
- }
50956
50651
 
50957
50652
  /**
50958
50653
  * Fill data values with zeros for a given area
@@ -51213,22 +50908,6 @@ class Sampler2D {
51213
50908
  return dataSize + 280;
51214
50909
  }
51215
50910
 
51216
- /**
51217
- * @deprecated Use {@link Sampler2DSerializationAdapter} adapter instead
51218
- * @param {BinaryBuffer} buffer
51219
- */
51220
- toBinaryBuffer(buffer) {
51221
- throw new Error('Deprecated, use Sampler2DSerializationAdapter instead');
51222
- }
51223
-
51224
- /**
51225
- * @deprecated Use {@link Sampler2DSerializationAdapter} adapter instead
51226
- * @param {BinaryBuffer} buffer
51227
- */
51228
- fromBinaryBuffer(buffer) {
51229
- throw new Error('Deprecated, use Sampler2DSerializationAdapter instead');
51230
- }
51231
-
51232
50911
  /**
51233
50912
  *
51234
50913
  * @param {Sampler2D} other
@@ -51439,38 +51118,7 @@ Sampler2D.prototype.isSampler2D = true;
51439
51118
  * @readonly
51440
51119
  * @type {string}
51441
51120
  */
51442
- Sampler2D.typeName = "Sampler2D";
51443
-
51444
- /**
51445
- * Based on code from reddit https://www.reddit.com/r/javascript/comments/jxa8x/bicubic_interpolation/
51446
- * @param {number} t
51447
- * @param {number} a
51448
- * @param {number} b
51449
- * @param {number} c
51450
- * @param {number} d
51451
- * @returns {number}
51452
- */
51453
- function bicubic_terp(t, a, b, c, d) {
51454
- return 0.5 * (c - a + (2.0 * a - 5.0 * b + 4.0 * c - d + (3.0 * (b - c) + d - a) * t) * t) * t + b;
51455
- }
51456
-
51457
-
51458
- /**
51459
- *
51460
- * @param {number[]} source
51461
- * @param {number[]} destination
51462
- * @param {Array} result
51463
- */
51464
- function blendFunctionNormal(source, destination, result) {
51465
-
51466
- const a1 = source[3] / 255;
51467
- const a0 = destination[3] / 255;
51468
-
51469
- result[0] = source[0] * a1 + destination[0] * (1 - a1);
51470
- result[1] = source[1] * a1 + destination[1] * (1 - a1);
51471
- result[2] = source[2] * a1 + destination[2] * (1 - a1);
51472
- result[3] = (a1 + a0 * (1 - a1)) * 255;
51473
- }
51121
+ Sampler2D.typeName = "Sampler2D";
51474
51122
 
51475
51123
  /**
51476
51124
  *
@@ -51779,6 +51427,354 @@ function SplatMaterial(
51779
51427
 
51780
51428
  const WHITE_PIXEL_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdj+P///38ACfsD/QVDRcoAAAAASUVORK5CYII=";
51781
51429
 
51430
+ /**
51431
+ *
51432
+ * @param {number} v
51433
+ * @returns {number}
51434
+ */
51435
+ function float2uint8(v) {
51436
+ return Math.round(v * 255);
51437
+ }
51438
+
51439
+ /**
51440
+ *
51441
+ * @param {number} v
51442
+ * @returns {number}
51443
+ */
51444
+ function uint82float(v) {
51445
+ return v / 255;
51446
+ }
51447
+
51448
+ /**
51449
+ * Copy data from one array to another
51450
+ * Follows Java System.arraycopy interface
51451
+ * @template T
51452
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Int32Array|Float32Array|Float64Array} source The source array
51453
+ * @param {number} source_position Starting position where to copy from inside the source array
51454
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Int32Array|Float32Array|Float64Array} destination The destination array
51455
+ * @param {number} destination_position Starting position where to copy to inside the destination array
51456
+ * @param {number} length How many elements should be copied
51457
+ */
51458
+ function array_copy(
51459
+ source,
51460
+ source_position,
51461
+ destination,
51462
+ destination_position,
51463
+ length
51464
+ ) {
51465
+ assert.isNonNegativeInteger(source_position, 'source_position');
51466
+ assert.isNonNegativeInteger(destination_position, 'destination_position');
51467
+ assert.isNonNegativeInteger(length, 'length');
51468
+
51469
+ let i, j, k;
51470
+
51471
+ for (k = 0; k < length; k++) {
51472
+ i = source_position + k;
51473
+ j = destination_position + k;
51474
+
51475
+ destination[j] = source[i];
51476
+ }
51477
+ }
51478
+
51479
+ /**
51480
+ * @author Alex Goldring
51481
+ * @copyright Alex Goldring 2018
51482
+ */
51483
+
51484
+
51485
+ class Vector1 extends Number {
51486
+ /**
51487
+ *
51488
+ * @param {number} [x=0]
51489
+ * @constructor
51490
+ * @class
51491
+ * @property {number} x
51492
+ */
51493
+ constructor(x = 0) {
51494
+ super();
51495
+
51496
+ assert.isNumber( x, 'x');
51497
+ assert.notNaN(x, 'x');
51498
+
51499
+ this.x = x;
51500
+
51501
+ this.onChanged = new Signal();
51502
+ }
51503
+
51504
+ /**
51505
+ * Inherited from Number class
51506
+ * @returns {number}
51507
+ */
51508
+ valueOf() {
51509
+ return this.x;
51510
+ }
51511
+
51512
+ /**
51513
+ *
51514
+ * @returns {string}
51515
+ */
51516
+ toString() {
51517
+ return String(this.x);
51518
+ }
51519
+
51520
+ /**
51521
+ *
51522
+ * @returns {number}
51523
+ */
51524
+ getValue() {
51525
+ return this.x;
51526
+ }
51527
+
51528
+ /**
51529
+ *
51530
+ * @param {Vector1} other
51531
+ * @returns {number}
51532
+ */
51533
+ compareTo(other) {
51534
+ return this.x - other.x;
51535
+ }
51536
+
51537
+ /**
51538
+ *
51539
+ * @param {number} x
51540
+ * @returns {Vector1}
51541
+ */
51542
+ set(x) {
51543
+ assert.isNumber( x,'x');
51544
+ assert.notNaN(x, 'x');
51545
+
51546
+ const oldValue = this.x;
51547
+ if (oldValue !== x) {
51548
+ this.x = x;
51549
+
51550
+ if (this.onChanged.hasHandlers()) {
51551
+ this.onChanged.send2(x, oldValue);
51552
+ }
51553
+ }
51554
+
51555
+ return this;
51556
+ }
51557
+
51558
+ /**
51559
+ * Set value without triggering {@link #onChanged} signal
51560
+ * @param {number} x
51561
+ */
51562
+ setSilent(x) {
51563
+ this.x = x;
51564
+ }
51565
+
51566
+ /**
51567
+ *
51568
+ * @return {boolean}
51569
+ */
51570
+ isZero() {
51571
+ return this.x === 0;
51572
+ }
51573
+
51574
+ increment() {
51575
+ this._add(1);
51576
+ }
51577
+
51578
+ decrement() {
51579
+ this._add(-1);
51580
+ }
51581
+
51582
+ /**
51583
+ *
51584
+ * @param {Number} v
51585
+ * @return {Vector1}
51586
+ */
51587
+ _add(v) {
51588
+ return this.set(this.x + v);
51589
+ }
51590
+
51591
+ /**
51592
+ *
51593
+ * @param {Vector1|Vector2|Vector3|Vector4} other
51594
+ */
51595
+ add(other) {
51596
+ return this._add(other.x);
51597
+ }
51598
+
51599
+ /**
51600
+ *
51601
+ * @param {Number} v
51602
+ * @return {Vector1}
51603
+ */
51604
+ _sub(v) {
51605
+ return this._add(-v);
51606
+ }
51607
+
51608
+ /**
51609
+ *
51610
+ * @param {Vector1} other
51611
+ * @returns {Vector1}
51612
+ */
51613
+ sub(other) {
51614
+ return this._sub(other.x);
51615
+ }
51616
+
51617
+ /**
51618
+ *
51619
+ * @param {Vector1} other
51620
+ * @returns {Vector1}
51621
+ */
51622
+ multiply(other) {
51623
+ return this.set(this.x * other.x);
51624
+ }
51625
+
51626
+ /**
51627
+ *
51628
+ * @param {number} v
51629
+ */
51630
+ multiplyScalar(v) {
51631
+ this.set(this.x * v);
51632
+ }
51633
+
51634
+ /**
51635
+ *
51636
+ * @param {number} low
51637
+ * @param {number} high
51638
+ * @returns {Vector1}
51639
+ */
51640
+ clamp(low, high) {
51641
+ return this.set(clamp$1(this.x, low, high));
51642
+ }
51643
+
51644
+ /**
51645
+ *
51646
+ * @param {Vector1|Vector2|Vector3|Vector4} other
51647
+ */
51648
+ copy(other) {
51649
+ this.set(other.x);
51650
+ }
51651
+
51652
+ /**
51653
+ *
51654
+ * @returns {Vector1}
51655
+ */
51656
+ clone() {
51657
+ return new Vector1(this.x);
51658
+ }
51659
+
51660
+ /**
51661
+ *
51662
+ * @param {Vector1} other
51663
+ * @returns {boolean}
51664
+ */
51665
+ equals(other) {
51666
+ return this.x === other.x;
51667
+ }
51668
+
51669
+ /**
51670
+ * @returns {number}
51671
+ */
51672
+ hash() {
51673
+ return computeHashFloat(this.x);
51674
+ }
51675
+
51676
+ /**
51677
+ *
51678
+ * @param {function(newValue:number, oldValue:number)} handler
51679
+ */
51680
+ process(handler) {
51681
+ handler(this.x, this.x);
51682
+ this.onChanged.add(handler);
51683
+ }
51684
+
51685
+ toJSON() {
51686
+ return this.x;
51687
+ }
51688
+
51689
+ fromJSON(val) {
51690
+ this.set(val);
51691
+ }
51692
+
51693
+ /**
51694
+ *
51695
+ * @param {number[]} array
51696
+ * @param {number} offset
51697
+ */
51698
+ readFromArray(array, offset=0) {
51699
+ this.set(array[offset]);
51700
+ }
51701
+
51702
+ /**
51703
+ *
51704
+ * @param {number[]} array
51705
+ * @param {number} offset
51706
+ */
51707
+ writeToArray(array, offset=0) {
51708
+ array[offset] = this.x;
51709
+ }
51710
+
51711
+ asArray(){
51712
+ return [this.x];
51713
+ }
51714
+
51715
+ /**
51716
+ *
51717
+ * @param {BinaryBuffer} buffer
51718
+ */
51719
+ toBinaryBuffer(buffer) {
51720
+ buffer.writeFloat64(this.x);
51721
+ }
51722
+
51723
+ /**
51724
+ *
51725
+ * @param {BinaryBuffer} buffer
51726
+ */
51727
+ fromBinaryBuffer(buffer) {
51728
+ const x = buffer.readFloat64();
51729
+
51730
+ this.set(x);
51731
+ }
51732
+
51733
+ /**
51734
+ *
51735
+ * @param {Vector1} a
51736
+ * @param {Vector1} b
51737
+ * @return {number}
51738
+ */
51739
+ static compare(a, b) {
51740
+ return a.x - b.x;
51741
+ }
51742
+
51743
+ get 0() {
51744
+ return this.x;
51745
+ }
51746
+
51747
+ set 0(v) {
51748
+ this.x = v;
51749
+ }
51750
+
51751
+ * [Symbol.iterator]() {
51752
+
51753
+ yield this.x;
51754
+
51755
+ }
51756
+ }
51757
+
51758
+ /**
51759
+ * @readonly
51760
+ * @type {boolean}
51761
+ */
51762
+ Vector1.prototype.isVector1 = true;
51763
+
51764
+ Vector1.typeName = "Vector1";
51765
+
51766
+ /**
51767
+ * @readonly
51768
+ * @type {Vector1}
51769
+ */
51770
+ Vector1.zero = Object.freeze(new Vector1(0));
51771
+
51772
+ /**
51773
+ * @readonly
51774
+ * @type {Vector1}
51775
+ */
51776
+ Vector1.one = Object.freeze(new Vector1(1));
51777
+
51782
51778
  /**
51783
51779
  *
51784
51780
  * @param {Uint8Array|number[]|ArrayLike<number>|IArguments} data
@@ -52276,342 +52272,6 @@ class Vector4 {
52276
52272
  }
52277
52273
  }
52278
52274
 
52279
- /**
52280
- * Created by Alex on 11/11/2014.
52281
- */
52282
-
52283
-
52284
- function canvas2Sampler2D(canvas) {
52285
- const width = canvas.width;
52286
- const height = canvas.height;
52287
-
52288
- const context = canvas.getContext("2d");
52289
-
52290
- const result = new Sampler2D(null, 4, width, height);
52291
-
52292
- canvasDataToSampler(result, context);
52293
-
52294
- return result;
52295
-
52296
- }
52297
-
52298
- /**
52299
- *
52300
- * @param {Sampler2D} target
52301
- * @param {CanvasRenderingContext2D} ctx
52302
- */
52303
- function canvasDataToSampler(target, ctx) {
52304
- const width = target.width;
52305
- const height = target.height;
52306
-
52307
- const imageData = ctx.getImageData(0, 0, width, height);
52308
-
52309
- const data = imageData.data;
52310
-
52311
- assert.equal(data.length, target.height * target.width * target.itemSize);
52312
-
52313
- target.data = data;
52314
- }
52315
-
52316
- /**
52317
- * @author Alex Goldring
52318
- * @copyright Alex Goldring 2018
52319
- */
52320
-
52321
-
52322
- class Vector1 extends Number {
52323
- /**
52324
- *
52325
- * @param {number} [x=0]
52326
- * @constructor
52327
- * @class
52328
- * @property {number} x
52329
- */
52330
- constructor(x = 0) {
52331
- super();
52332
-
52333
- assert.isNumber( x, 'x');
52334
- assert.notNaN(x, 'x');
52335
-
52336
- this.x = x;
52337
-
52338
- this.onChanged = new Signal();
52339
- }
52340
-
52341
- /**
52342
- * Inherited from Number class
52343
- * @returns {number}
52344
- */
52345
- valueOf() {
52346
- return this.x;
52347
- }
52348
-
52349
- /**
52350
- *
52351
- * @returns {string}
52352
- */
52353
- toString() {
52354
- return String(this.x);
52355
- }
52356
-
52357
- /**
52358
- *
52359
- * @returns {number}
52360
- */
52361
- getValue() {
52362
- return this.x;
52363
- }
52364
-
52365
- /**
52366
- *
52367
- * @param {Vector1} other
52368
- * @returns {number}
52369
- */
52370
- compareTo(other) {
52371
- return this.x - other.x;
52372
- }
52373
-
52374
- /**
52375
- *
52376
- * @param {number} x
52377
- * @returns {Vector1}
52378
- */
52379
- set(x) {
52380
- assert.isNumber( x,'x');
52381
- assert.notNaN(x, 'x');
52382
-
52383
- const oldValue = this.x;
52384
- if (oldValue !== x) {
52385
- this.x = x;
52386
-
52387
- if (this.onChanged.hasHandlers()) {
52388
- this.onChanged.send2(x, oldValue);
52389
- }
52390
- }
52391
-
52392
- return this;
52393
- }
52394
-
52395
- /**
52396
- * Set value without triggering {@link #onChanged} signal
52397
- * @param {number} x
52398
- */
52399
- setSilent(x) {
52400
- this.x = x;
52401
- }
52402
-
52403
- /**
52404
- *
52405
- * @return {boolean}
52406
- */
52407
- isZero() {
52408
- return this.x === 0;
52409
- }
52410
-
52411
- increment() {
52412
- this._add(1);
52413
- }
52414
-
52415
- decrement() {
52416
- this._add(-1);
52417
- }
52418
-
52419
- /**
52420
- *
52421
- * @param {Number} v
52422
- * @return {Vector1}
52423
- */
52424
- _add(v) {
52425
- return this.set(this.x + v);
52426
- }
52427
-
52428
- /**
52429
- *
52430
- * @param {Vector1|Vector2|Vector3|Vector4} other
52431
- */
52432
- add(other) {
52433
- return this._add(other.x);
52434
- }
52435
-
52436
- /**
52437
- *
52438
- * @param {Number} v
52439
- * @return {Vector1}
52440
- */
52441
- _sub(v) {
52442
- return this._add(-v);
52443
- }
52444
-
52445
- /**
52446
- *
52447
- * @param {Vector1} other
52448
- * @returns {Vector1}
52449
- */
52450
- sub(other) {
52451
- return this._sub(other.x);
52452
- }
52453
-
52454
- /**
52455
- *
52456
- * @param {Vector1} other
52457
- * @returns {Vector1}
52458
- */
52459
- multiply(other) {
52460
- return this.set(this.x * other.x);
52461
- }
52462
-
52463
- /**
52464
- *
52465
- * @param {number} v
52466
- */
52467
- multiplyScalar(v) {
52468
- this.set(this.x * v);
52469
- }
52470
-
52471
- /**
52472
- *
52473
- * @param {number} low
52474
- * @param {number} high
52475
- * @returns {Vector1}
52476
- */
52477
- clamp(low, high) {
52478
- return this.set(clamp$1(this.x, low, high));
52479
- }
52480
-
52481
- /**
52482
- *
52483
- * @param {Vector1|Vector2|Vector3|Vector4} other
52484
- */
52485
- copy(other) {
52486
- this.set(other.x);
52487
- }
52488
-
52489
- /**
52490
- *
52491
- * @returns {Vector1}
52492
- */
52493
- clone() {
52494
- return new Vector1(this.x);
52495
- }
52496
-
52497
- /**
52498
- *
52499
- * @param {Vector1} other
52500
- * @returns {boolean}
52501
- */
52502
- equals(other) {
52503
- return this.x === other.x;
52504
- }
52505
-
52506
- /**
52507
- * @returns {number}
52508
- */
52509
- hash() {
52510
- return computeHashFloat(this.x);
52511
- }
52512
-
52513
- /**
52514
- *
52515
- * @param {function(newValue:number, oldValue:number)} handler
52516
- */
52517
- process(handler) {
52518
- handler(this.x, this.x);
52519
- this.onChanged.add(handler);
52520
- }
52521
-
52522
- toJSON() {
52523
- return this.x;
52524
- }
52525
-
52526
- fromJSON(val) {
52527
- this.set(val);
52528
- }
52529
-
52530
- /**
52531
- *
52532
- * @param {number[]} array
52533
- * @param {number} offset
52534
- */
52535
- readFromArray(array, offset=0) {
52536
- this.set(array[offset]);
52537
- }
52538
-
52539
- /**
52540
- *
52541
- * @param {number[]} array
52542
- * @param {number} offset
52543
- */
52544
- writeToArray(array, offset=0) {
52545
- array[offset] = this.x;
52546
- }
52547
-
52548
- asArray(){
52549
- return [this.x];
52550
- }
52551
-
52552
- /**
52553
- *
52554
- * @param {BinaryBuffer} buffer
52555
- */
52556
- toBinaryBuffer(buffer) {
52557
- buffer.writeFloat64(this.x);
52558
- }
52559
-
52560
- /**
52561
- *
52562
- * @param {BinaryBuffer} buffer
52563
- */
52564
- fromBinaryBuffer(buffer) {
52565
- const x = buffer.readFloat64();
52566
-
52567
- this.set(x);
52568
- }
52569
-
52570
- /**
52571
- *
52572
- * @param {Vector1} a
52573
- * @param {Vector1} b
52574
- * @return {number}
52575
- */
52576
- static compare(a, b) {
52577
- return a.x - b.x;
52578
- }
52579
-
52580
- get 0() {
52581
- return this.x;
52582
- }
52583
-
52584
- set 0(v) {
52585
- this.x = v;
52586
- }
52587
-
52588
- * [Symbol.iterator]() {
52589
-
52590
- yield this.x;
52591
-
52592
- }
52593
- }
52594
-
52595
- /**
52596
- * @readonly
52597
- * @type {boolean}
52598
- */
52599
- Vector1.prototype.isVector1 = true;
52600
-
52601
- Vector1.typeName = "Vector1";
52602
-
52603
- /**
52604
- * @readonly
52605
- * @type {Vector1}
52606
- */
52607
- Vector1.zero = Object.freeze(new Vector1(0));
52608
-
52609
- /**
52610
- * @readonly
52611
- * @type {Vector1}
52612
- */
52613
- Vector1.one = Object.freeze(new Vector1(1));
52614
-
52615
52275
  /**
52616
52276
  *
52617
52277
  * @param {string|null|undefined} string
@@ -52773,6 +52433,43 @@ class ObservedString extends String {
52773
52433
  */
52774
52434
  ObservedString.prototype.isObservedString = true;
52775
52435
 
52436
+ /**
52437
+ * Created by Alex on 11/11/2014.
52438
+ */
52439
+
52440
+
52441
+ function canvas2Sampler2D(canvas) {
52442
+ const width = canvas.width;
52443
+ const height = canvas.height;
52444
+
52445
+ const context = canvas.getContext("2d");
52446
+
52447
+ const result = new Sampler2D(null, 4, width, height);
52448
+
52449
+ canvasDataToSampler(result, context);
52450
+
52451
+ return result;
52452
+
52453
+ }
52454
+
52455
+ /**
52456
+ *
52457
+ * @param {Sampler2D} target
52458
+ * @param {CanvasRenderingContext2D} ctx
52459
+ */
52460
+ function canvasDataToSampler(target, ctx) {
52461
+ const width = target.width;
52462
+ const height = target.height;
52463
+
52464
+ const imageData = ctx.getImageData(0, 0, width, height);
52465
+
52466
+ const data = imageData.data;
52467
+
52468
+ assert.equal(data.length, target.height * target.width * target.itemSize);
52469
+
52470
+ target.data = data;
52471
+ }
52472
+
52776
52473
  /**
52777
52474
  *
52778
52475
  * @param {Sampler2D} input
@@ -53007,52 +52704,96 @@ function sampler2d_scale(input, output) {
53007
52704
  }
53008
52705
 
53009
52706
  /**
53010
- *
53011
- * @param {number} v
53012
- * @returns {number}
52707
+ * Color blending modes
52708
+ * @enum {number}
53013
52709
  */
53014
- function uint82float(v) {
53015
- return v / 255;
53016
- }
52710
+ const BlendingType = {
52711
+ NoBlending: 5,
52712
+ Normal: 0,
52713
+ Add: 1,
52714
+ Subtract: 2,
52715
+ Multiply: 3,
52716
+ MultiplyAdd: 4
52717
+ };
53017
52718
 
53018
52719
  /**
53019
52720
  *
53020
- * @param {number} v
53021
- * @returns {number}
52721
+ * @param {number[]} source
52722
+ * @param {number[]} destination
52723
+ * @param {Array} result
53022
52724
  */
53023
- function float2uint8(v) {
53024
- return Math.round(v * 255);
53025
- }
53026
-
52725
+ function blendFunctionNormal(source, destination, result) {
52726
+
52727
+ const a1 = source[3] / 255;
52728
+ const a0 = destination[3] / 255;
52729
+
52730
+ result[0] = source[0] * a1 + destination[0] * (1 - a1);
52731
+ result[1] = source[1] * a1 + destination[1] * (1 - a1);
52732
+ result[2] = source[2] * a1 + destination[2] * (1 - a1);
52733
+ result[3] = (a1 + a0 * (1 - a1)) * 255;
52734
+ }
52735
+
53027
52736
  /**
53028
- * Copy data from one array to another
53029
- * Follows Java System.arraycopy interface
53030
- * @template T
53031
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Int32Array|Float32Array|Float64Array} source The source array
53032
- * @param {number} source_position Starting position where to copy from inside the source array
53033
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Uint32Array|Int32Array|Float32Array|Float64Array} destination The destination array
53034
- * @param {number} destination_position Starting position where to copy to inside the destination array
53035
- * @param {number} length How many elements should be copied
52737
+ * Assumes both samplers are RGBA uint8 with values 0-255
52738
+ * @param {Sampler2D} destination
52739
+ * @param {Sampler2D} source
52740
+ * @param {number} sourceX
52741
+ * @param {number} sourceY
52742
+ * @param {number} destinationX
52743
+ * @param {number} destinationY
52744
+ * @param {number} width
52745
+ * @param {number} height
52746
+ * @param {BlendingType} [blendMode]
53036
52747
  */
53037
- function array_copy(
53038
- source,
53039
- source_position,
52748
+ function sampler2d_paint(
53040
52749
  destination,
53041
- destination_position,
53042
- length
52750
+ source,
52751
+ sourceX, sourceY,
52752
+ destinationX, destinationY,
52753
+ width, height,
52754
+ blendMode = BlendingType.Normal
53043
52755
  ) {
53044
- assert.isNonNegativeInteger(source_position, 'source_position');
53045
- assert.isNonNegativeInteger(destination_position, 'destination_position');
53046
- assert.isNonNegativeInteger(length, 'length');
53047
52756
 
53048
- let i, j, k;
52757
+ let blendFunction;
52758
+ if (blendMode === BlendingType.Normal) {
52759
+ blendFunction = blendFunctionNormal;
52760
+ } else {
52761
+ throw new Error(`Unsupported blendType(=${blendMode})`);
52762
+ }
53049
52763
 
53050
- for (k = 0; k < length; k++) {
53051
- i = source_position + k;
53052
- j = destination_position + k;
52764
+ const _w = Math.min(width, source.width - sourceX, destination.width - destinationX);
52765
+ const _h = Math.min(height, source.height - sourceY, destination.height - destinationY);
53053
52766
 
53054
- destination[j] = source[i];
52767
+ const _x0 = Math.max(0, -destinationX);
52768
+ const _y0 = Math.max(0, -destinationY);
52769
+
52770
+ const c0 = [0, 0, 0, 255];
52771
+ const c1 = [0, 0, 0, 255];
52772
+
52773
+ const c3 = [];
52774
+
52775
+ let x, y;
52776
+
52777
+ for (y = _y0; y < _h; y++) {
52778
+ for (x = _x0; x < _w; x++) {
52779
+ const d_x = Math.round(x + destinationX);
52780
+ const d_y = Math.round(y + destinationY);
52781
+
52782
+ destination.read(d_x, d_y, c0);
52783
+
52784
+ const s_x = Math.round(x + sourceY);
52785
+ const s_y = Math.round(y + sourceY);
52786
+
52787
+ source.read(s_x, s_y, c1);
52788
+
52789
+ blendFunction(c1, c0, c3);
52790
+
52791
+ destination.set(d_x, d_y, c3);
52792
+
52793
+ }
53055
52794
  }
52795
+
52796
+
53056
52797
  }
53057
52798
 
53058
52799
  /**
@@ -53110,7 +52851,7 @@ class TerrainOverlay {
53110
52851
  */
53111
52852
  this.size = new Vector2(size.x, size.y);
53112
52853
 
53113
- /**
52854
+ /**
53114
52855
  *
53115
52856
  * @type {ObservedString}
53116
52857
  */
@@ -53161,7 +52902,7 @@ class TerrainOverlay {
53161
52902
  *
53162
52903
  * @returns {string}
53163
52904
  */
53164
- get baseTileImage(){
52905
+ get baseTileImage() {
53165
52906
  return this.stack.length === 0 ? this.tileImage.getValue() : this.stack[0].tileImage
53166
52907
  }
53167
52908
 
@@ -53169,7 +52910,7 @@ class TerrainOverlay {
53169
52910
  *
53170
52911
  * @param {string} v
53171
52912
  */
53172
- set baseTileImage(v){
52913
+ set baseTileImage(v) {
53173
52914
  if (this.stack.length === 0) {
53174
52915
  this.tileImage.set(v);
53175
52916
  } else {
@@ -53357,7 +53098,7 @@ class TerrainOverlay {
53357
53098
  const scaled_source = Sampler2D.uint8(4, dWidth, dHeight);
53358
53099
  sampler2d_scale(source, scaled_source);
53359
53100
 
53360
- this.sampler.paint(scaled_source, 0, 0, dx, dy, dWidth, dHeight);
53101
+ sampler2d_paint(this, scaled_source, 0, 0, dx, dy, dWidth, dHeight);
53361
53102
 
53362
53103
  this.texture.needsUpdate = true;
53363
53104
  }
@@ -53394,31 +53135,30 @@ function loadCloudTexture(url) {
53394
53135
 
53395
53136
 
53396
53137
  class Clouds {
53397
- constructor() {
53398
- /**
53399
- *
53400
- * @type {boolean}
53401
- * @private
53402
- */
53403
- this.__enabled = false;
53404
- /**
53405
- *
53406
- * @type {Array}
53407
- * @private
53408
- */
53409
- this.materials = [];
53410
- this.time = 0;
53138
+ /**
53139
+ *
53140
+ * @type {boolean}
53141
+ * @private
53142
+ */
53143
+ __enabled = false;
53144
+ /**
53145
+ *
53146
+ * @type {Array}
53147
+ * @private
53148
+ */
53149
+ materials = [];
53150
+ time = 0;
53411
53151
 
53412
53152
 
53413
- this.__speed0 = new Vector2();
53414
- this.__speed1 = new Vector2();
53415
- this.__speed2 = new Vector2();
53153
+ __speed0 = new Vector2();
53154
+ __speed1 = new Vector2();
53155
+ __speed2 = new Vector2();
53416
53156
 
53417
- //how fast clouds reform
53418
- this.variability = 0.37;
53157
+ //how fast clouds reform
53158
+ variability = 0.37;
53419
53159
 
53160
+ constructor() {
53420
53161
  this.setSpeed(0.5, -0.5);
53421
-
53422
53162
  }
53423
53163
 
53424
53164
  /**
@@ -55268,7 +55008,7 @@ function rgb2uint24(r, g, b) {
55268
55008
  /**
55269
55009
  * Convert a decimal value to hex
55270
55010
  * @param {number} c generally expects b byte value, 0-255
55271
- * @returns {string}
55011
+ * @returns {string} zero-padded value, for example instead of "0", will return "00" and instead of "F" will return "0F"
55272
55012
  */
55273
55013
  function dec2hex(c) {
55274
55014
  const hex = Math.round(c).toString(16);
@@ -72147,6 +71887,25 @@ BitSet.fixedSize = function (x) {
72147
71887
  */
72148
71888
 
72149
71889
  class EntityObserver {
71890
+ /**
71891
+ *
71892
+ * @type {BitSet}
71893
+ */
71894
+ componentMask = new BitSet();
71895
+
71896
+ /**
71897
+ * Mapping from component index to position in array of observed component types,
71898
+ * this is used to build arguments for callbacks
71899
+ * @type {number[]}
71900
+ */
71901
+ componentIndexMapping = [];
71902
+
71903
+ /**
71904
+ *
71905
+ * @type {EntityComponentDataset|null}
71906
+ */
71907
+ dataset = null;
71908
+
72150
71909
  /**
72151
71910
  *
72152
71911
  * @param {Array} componentTypes
@@ -72155,7 +71914,12 @@ class EntityObserver {
72155
71914
  * @param {*} [thisArg=undefined] will assume {@link this} value inside callbacks
72156
71915
  * @constructor
72157
71916
  */
72158
- constructor(componentTypes, completedCallback, brokenCallback, thisArg) {
71917
+ constructor(
71918
+ componentTypes,
71919
+ completedCallback,
71920
+ brokenCallback,
71921
+ thisArg
71922
+ ) {
72159
71923
  assert.isArray(componentTypes, 'componentTypes must be an array, instead was something else');
72160
71924
  assert.isFunction(completedCallback, 'completedCallback');
72161
71925
  assert.isFunction(brokenCallback, 'brokenCallback');
@@ -72194,26 +71958,6 @@ class EntityObserver {
72194
71958
  * @type {*}
72195
71959
  */
72196
71960
  this.thisArg = thisArg;
72197
-
72198
-
72199
- /**
72200
- *
72201
- * @type {BitSet}
72202
- */
72203
- this.componentMask = new BitSet();
72204
-
72205
- /**
72206
- * Mapping from component index to position in array of observed component types,
72207
- * this is used to build arguments for callbacks
72208
- * @type {number[]}
72209
- */
72210
- this.componentIndexMapping = [];
72211
-
72212
- /**
72213
- *
72214
- * @type {EntityComponentDataset|null}
72215
- */
72216
- this.dataset = null;
72217
71961
  }
72218
71962
 
72219
71963
  /**
@@ -73298,6 +73042,9 @@ class EntityManager {
73298
73042
  on = {
73299
73043
  systemStarted: new Signal(),
73300
73044
  systemStopped: new Signal(),
73045
+ /**
73046
+ * @type {Signal<System>}
73047
+ */
73301
73048
  systemAdded: new Signal(),
73302
73049
  systemRemoved: new Signal(),
73303
73050
  };
@@ -74724,17 +74471,43 @@ ParentEntity.serializable = false;
74724
74471
  const DEFAULT_FLAGS$1 = EntityNodeFlags.LiveManagement;
74725
74472
 
74726
74473
  class EntityNode {
74474
+ /**
74475
+ *
74476
+ * @type {EntityNode|null}
74477
+ * @private
74478
+ */
74479
+ __parent = null;
74480
+
74481
+ /**
74482
+ *
74483
+ * @type {EntityNode[]}
74484
+ * @private
74485
+ */
74486
+ __children = [];
74487
+
74488
+ /**
74489
+ * Local transform
74490
+ * @type {Transform}
74491
+ * @private
74492
+ */
74493
+ __transform = new Transform();
74494
+
74495
+ on = {
74496
+ built: new Signal(),
74497
+ destroyed: new Signal()
74498
+ };
74499
+
74500
+ /**
74501
+ *
74502
+ * @type {number}
74503
+ */
74504
+ flags = DEFAULT_FLAGS$1;
74505
+
74727
74506
  /**
74728
74507
  *
74729
74508
  * @param {Entity} [entity] optional entity to be wrapped
74730
74509
  */
74731
74510
  constructor(entity = new Entity()) {
74732
- /**
74733
- *
74734
- * @type {EntityNode|null}
74735
- * @private
74736
- */
74737
- this.__parent = null;
74738
74511
 
74739
74512
  /**
74740
74513
  *
@@ -74743,30 +74516,6 @@ class EntityNode {
74743
74516
  */
74744
74517
  this.__entity = entity;
74745
74518
 
74746
- /**
74747
- *
74748
- * @type {EntityNode[]}
74749
- * @private
74750
- */
74751
- this.__children = [];
74752
-
74753
- /**
74754
- * Local transform
74755
- * @type {Transform}
74756
- * @private
74757
- */
74758
- this.__transform = new Transform();
74759
-
74760
- this.on = {
74761
- built: new Signal(),
74762
- destroyed: new Signal()
74763
- };
74764
-
74765
- /**
74766
- *
74767
- * @type {number}
74768
- */
74769
- this.flags = DEFAULT_FLAGS$1;
74770
74519
  }
74771
74520
 
74772
74521
  /**
@@ -79437,7 +79186,6 @@ class EnginePlugin extends BaseProcess {
79437
79186
  */
79438
79187
  engine = null;
79439
79188
 
79440
-
79441
79189
  attach() {
79442
79190
  /**
79443
79191
  * Must be unique for each plugin
@@ -82585,10 +82333,12 @@ const SerializationFlags = {
82585
82333
  };
82586
82334
 
82587
82335
  class SerializationMetadata {
82588
- constructor() {
82589
- this.flags = 0;
82590
- }
82591
82336
 
82337
+ /**
82338
+ *
82339
+ * @type {number}
82340
+ */
82341
+ flags = 0;
82592
82342
 
82593
82343
  /**
82594
82344
  *
@@ -109373,6 +109123,64 @@ class IdPool {
109373
109123
  }
109374
109124
  }
109375
109125
 
109126
+ /**
109127
+ * @template T
109128
+ * @param {T} object
109129
+ * @return {T}
109130
+ */
109131
+ function invokeObjectClone(object) {
109132
+ return object.clone();
109133
+ }
109134
+
109135
+ /**
109136
+ * Copy a patch from another sampler with the same itemSize
109137
+ * @param {Sampler2D} destination
109138
+ * @param {Sampler2D} source where to copy from
109139
+ * @param {Number} sourceX where to start reading from, X coordinate
109140
+ * @param {Number} sourceY where to start reading from, X coordinate
109141
+ * @param {Number} destinationX where to start writing to, X coordinate
109142
+ * @param {Number} destinationY where to start writing to, X coordinate
109143
+ * @param {Number} width size of the patch that is to be copied
109144
+ * @param {Number} height size of the patch that is to be copied
109145
+ */
109146
+ function sampler2d_sub_copy_same_item_size(destination, source, sourceX, sourceY, destinationX, destinationY, width, height) {
109147
+ const itemSize = destination.itemSize;
109148
+ const sItemSize = source.itemSize;
109149
+
109150
+ assert.equal(sItemSize, sItemSize, `source.itemSize(=${sItemSize}) != destination.itemSize(=${itemSize})`);
109151
+
109152
+ const _w = Math.min(width, source.width - sourceX, destination.width - destinationX);
109153
+ const _h = Math.min(height, source.height - sourceY, destination.height - destinationY);
109154
+
109155
+
109156
+ const dRowSize = itemSize * destination.width;
109157
+ const sRowSize = itemSize * source.width;
109158
+
109159
+ const sData = source.data;
109160
+ const dData = destination.data;
109161
+
109162
+ const patchRowSize = _w * itemSize;
109163
+
109164
+ let y, i;
109165
+
109166
+ for (y = 0; y < _h; y++) {
109167
+ const dA = (y + destinationY) * dRowSize;
109168
+ const sA = (y + sourceY) * sRowSize;
109169
+
109170
+ const dOffset = dA + destinationX * itemSize;
109171
+ const sOffset = sA + sourceX * itemSize;
109172
+
109173
+ for (i = 0; i < patchRowSize; i++) {
109174
+
109175
+ dData[dOffset + i] = sData[sOffset + i];
109176
+
109177
+ }
109178
+ }
109179
+
109180
+ // update destination version
109181
+ destination.version++;
109182
+ }
109183
+
109376
109184
  class AtlasPatch {
109377
109185
  constructor() {
109378
109186
  /**
@@ -109541,15 +109349,6 @@ const AtlasPatchFlag = {
109541
109349
  Attached: 4
109542
109350
  };
109543
109351
 
109544
- /**
109545
- * @template T
109546
- * @param {T} object
109547
- * @return {T}
109548
- */
109549
- function invokeObjectClone(object) {
109550
- return object.clone();
109551
- }
109552
-
109553
109352
  class TextureAtlas extends AbstractTextureAtlas {
109554
109353
  /**
109555
109354
  *
@@ -109748,7 +109547,8 @@ class TextureAtlas extends AbstractTextureAtlas {
109748
109547
  const patch_position = patch.position;
109749
109548
  const patch_size = patch.size;
109750
109549
 
109751
- target.copy_sameItemSize(
109550
+ sampler2d_sub_copy_same_item_size(
109551
+ target,
109752
109552
  source,
109753
109553
  0, 0,
109754
109554
  patch_position.x, patch_position.y, patch_size.x, patch_size.y
@@ -113544,29 +113344,31 @@ var FrustumProjector = {
113544
113344
  };
113545
113345
 
113546
113346
  class SystemEntityContext {
113547
- constructor() {
113548
113347
 
113549
- this.entity = -1;
113348
+ /**
113349
+ *
113350
+ * @type {number}
113351
+ */
113352
+ entity = -1;
113550
113353
 
113551
- /**
113552
- * Pointer back to the system
113553
- * @type {System}
113554
- */
113555
- this.system = null;
113354
+ /**
113355
+ * Pointer back to the system
113356
+ * @type {System}
113357
+ */
113358
+ system = null;
113556
113359
 
113557
- /**
113558
- *
113559
- * @type {*[]}
113560
- */
113561
- this.components = [];
113360
+ /**
113361
+ *
113362
+ * @type {*[]}
113363
+ */
113364
+ components = [];
113562
113365
 
113563
- /**
113564
- *
113565
- * @type {boolean}
113566
- * @protected
113567
- */
113568
- this.__is_linked = false;
113569
- }
113366
+ /**
113367
+ *
113368
+ * @type {boolean}
113369
+ * @protected
113370
+ */
113371
+ __is_linked = false;
113570
113372
 
113571
113373
  /**
113572
113374
  *