@woosh/meep-engine 2.75.7 → 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 (150) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +1052 -1234
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +1052 -1234
  5. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
  6. package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
  7. package/editor/ecs/component/createObjectEditor.js +2 -2
  8. package/editor/process/EditorProcess.js +12 -16
  9. package/editor/process/ProcessEngine.js +9 -10
  10. package/package.json +1 -1
  11. package/src/core/binary/dec2hex.js +1 -1
  12. package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
  13. package/src/core/math/newton_solver_1d.js +13 -4
  14. package/src/core/math/solveQuadratic.js +5 -3
  15. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  17. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  18. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  19. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  20. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  21. package/src/core/model/object/ImmutableObjectPool.js +14 -5
  22. package/src/engine/control/ControlContext.js +25 -27
  23. package/src/engine/ecs/EntityManager.js +12 -9
  24. package/src/engine/ecs/EntityObserver.js +26 -22
  25. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  26. package/src/engine/ecs/components/Motion.js +5 -7
  27. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  28. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  29. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  30. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  31. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  32. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  33. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  34. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  35. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  36. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  37. package/src/engine/ecs/parent/EntityNode.js +39 -37
  38. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  39. package/src/engine/ecs/storage/BinaryBufferDeSerializer.js +7 -9
  40. package/src/engine/ecs/storage/BinaryBufferSerializer.js +15 -16
  41. package/src/engine/ecs/storage/binary/BinaryClassUpgrader.js +10 -59
  42. package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +14 -15
  43. package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js +3 -3
  44. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +60 -62
  45. package/src/engine/ecs/storage/binary/executeBinaryClassUpgraderChain.js +46 -0
  46. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter.js +2 -2
  47. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  48. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  49. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  50. package/src/engine/ecs/terrain/ecs/layers/TerrainLayer.js +37 -31
  51. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +8 -7
  52. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  53. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  54. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  55. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  56. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  57. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  58. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  59. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  60. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  61. package/src/engine/graphics/render/RendererPool.js +36 -40
  62. package/src/engine/graphics/render/buffer/FrameBuffer.js +25 -24
  63. package/src/engine/graphics/render/buffer/RenderGraph.js +21 -21
  64. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  65. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -5
  66. package/src/engine/graphics/render/frame_graph/IRenderContext.js +31 -1
  67. package/src/engine/graphics/render/frame_graph/RenderGraph.js +5 -5
  68. package/src/engine/graphics/render/frame_graph/RenderTarget.js +9 -0
  69. package/src/engine/graphics/render/frame_graph/RenderTextureManager.js +57 -0
  70. package/src/engine/graphics/render/frame_graph/ResourceEntry.js +7 -5
  71. package/src/engine/graphics/render/frame_graph/TextureDescriptor.js +48 -33
  72. package/src/engine/graphics/render/frame_graph/TextureInitialState.js +14 -0
  73. package/src/engine/graphics/render/frame_graph/sample/deferred/CopyPass.js +20 -0
  74. package/src/engine/graphics/render/frame_graph/sample/deferred/LightingPass.js +4 -0
  75. package/src/engine/graphics/render/frame_graph/sample/deferred/run.js +34 -6
  76. package/src/engine/graphics/render/frame_graph/webgl/WebGLRenderContext.js +34 -0
  77. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +3 -6
  78. package/src/engine/graphics/sh3/gi/prototypeSHGI.js +92 -0
  79. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  80. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  81. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  82. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  83. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  84. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  85. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  86. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  87. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMemoryMapping.js → VirtualTextureMemoryMapping.js} +2 -26
  88. package/src/engine/graphics/texture/virtual/{v2/VirtualTexturePage.js → VirtualTexturePage.js} +10 -10
  89. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureTileLoader.js → VirtualTextureTileLoader.js} +7 -7
  90. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsage.js → VirtualTextureUsage.js} +1 -1
  91. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageUpdater.js → VirtualTextureUsageUpdater.js} +7 -7
  92. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/ResidencyDebugView.js +4 -4
  93. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsageDebugView.js +2 -2
  94. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsagePyramidDebugView.js +4 -4
  95. package/src/engine/graphics/texture/virtual/{v2/prototype.js → prototype.js} +7 -7
  96. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_finger_print.js +1 -1
  97. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_tile_address.js +2 -2
  98. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/tile_address_to_finger_print.js +1 -1
  99. package/src/engine/navigation/ecs/components/Path.js +10 -9
  100. package/src/engine/physics/computeInterceptPoint.js +44 -0
  101. package/src/engine/plugin/EnginePlugin.js +1 -2
  102. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  103. package/src/engine/ecs/components/CharacterController.js +0 -31
  104. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  105. package/src/engine/ecs/components/Steering.js +0 -111
  106. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  107. package/src/engine/ecs/storage/json/Blueprint.js +0 -129
  108. package/src/engine/ecs/storage/json/EntityFactory.js +0 -207
  109. package/src/engine/ecs/storage/json/JSONDeSerializer.js +0 -148
  110. package/src/engine/ecs/storage/json/JSONSerializer.js +0 -132
  111. package/src/engine/ecs/storage/json/README.md +0 -5
  112. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  113. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  114. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  115. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  116. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  117. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  118. package/src/engine/ecs/systems/TagSystem.js +0 -31
  119. package/src/engine/graphics/render/webgpu/sample/MeshInstance.js +0 -108
  120. package/src/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +0 -71
  121. package/src/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +0 -39
  122. package/src/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +0 -21
  123. package/src/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +0 -41
  124. package/src/engine/graphics/render/webgpu/sample/main.js +0 -605
  125. package/src/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +0 -9
  126. package/src/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +0 -30
  127. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  128. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  129. package/src/engine/graphics/texture/virtual/TileOperation.js +0 -13
  130. package/src/engine/graphics/texture/virtual/TileTree.js +0 -150
  131. package/src/engine/graphics/texture/virtual/TileTree.spec.js +0 -58
  132. package/src/engine/graphics/texture/virtual/TileUsage.js +0 -137
  133. package/src/engine/graphics/texture/virtual/VirtualTexture.js +0 -238
  134. package/src/engine/graphics/texture/virtual/VirtualTexture.spec.js +0 -39
  135. package/src/engine/graphics/texture/virtual/page/TilePage.js +0 -148
  136. package/src/engine/graphics/texture/virtual/page/TilePageSlot.js +0 -36
  137. package/src/engine/graphics/texture/virtual/tile/Tile.js +0 -44
  138. package/src/engine/graphics/texture/virtual/tile/Tile.spec.js +0 -11
  139. package/src/engine/graphics/texture/virtual/tile/TileAddress.js +0 -63
  140. package/src/engine/graphics/texture/virtual/tile/TileAddress.spec.js +0 -30
  141. package/src/engine/graphics/texture/virtual/tile/TileLoader.js +0 -178
  142. package/src/engine/graphics/texture/virtual/tile/TileRequest.js +0 -40
  143. package/src/engine/graphics/texture/virtual/tile/TileStatus.js +0 -10
  144. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
  145. /package/src/engine/graphics/texture/virtual/{v2/NOTES.md → NOTES.md} +0 -0
  146. /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMaterial.js → VirtualTextureMaterial.js} +0 -0
  147. /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageShader.js → VirtualTextureUsageShader.js} +0 -0
  148. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/VirtualTextureTile.js +0 -0
  149. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/decompose_finger_print.js +0 -0
  150. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/finger_print_to_tile_address.js +0 -0
@@ -1,148 +0,0 @@
1
- import Vector2 from "../../../../../core/geom/Vector2.js";
2
- import { Cache } from "../../../../../core/cache/Cache.js";
3
- import { TilePageSlot } from "./TilePageSlot.js";
4
-
5
- function TilePage() {
6
- this.size = new Vector2(0, 0);
7
- this.capacity = 0;
8
- this.emptySlots = [];
9
-
10
- this.padding = 0;
11
-
12
- this.queueWrite = [];
13
-
14
- const self = this;
15
-
16
- /**
17
- *
18
- * @type {Cache.<Tile, TilePageSlot>}
19
- */
20
- this.active = new Cache({
21
- keyWeigher: function () {
22
- return 0;
23
- },
24
- valueWeigher: function () {
25
- return 1;
26
- },
27
- removeListener: function (tile, slot) {
28
- slot.empty();
29
- self.emptySlots.push(slot);
30
-
31
- //remove from write queue
32
- const i = self.queueWrite.indexOf(slot);
33
- if (i !== -1) {
34
- self.queueWrite.splice(i, 1);
35
- }
36
- }
37
- });
38
-
39
- }
40
-
41
- TilePage.prototype.init = function (pageResolution, tileResolution, padding = 4) {
42
- this.padding = padding;
43
-
44
- //compute size of the page in tiles
45
- this.size.set(Math.floor(pageResolution.x / (tileResolution.x + padding * 2)), Math.floor(pageResolution.y / (tileResolution.y + padding * 2)));
46
-
47
- //figure out how many tiles we can hold
48
- this.capacity = this.size.x * this.size.y;
49
-
50
- //empty out write queue
51
- this.queueWrite = [];
52
-
53
- //create slots
54
- this.emptySlots = [];
55
-
56
- for (let x = 0; x < this.size.x; x++) {
57
- for (let y = 0; y < this.size.y; y++) {
58
- const slot = new TilePageSlot();
59
- slot.position.set(x, y);
60
- this.emptySlots.push(slot);
61
- }
62
- }
63
-
64
-
65
- this.active.drop();
66
- this.active.setMaxWeight(this.capacity);
67
- };
68
-
69
-
70
- /**
71
- * Get a slot with best matching tile, if requested tile is not found, its closest mip ancestor will be returned, if no mip ancestor exists - null will be returned
72
- * @param {number} x
73
- * @param {number} y
74
- * @param {number} mip
75
- * @returns {TilePageSlot}
76
- */
77
- TilePage.prototype.getBestTile = function (x, y, mip) {
78
- /**
79
- *
80
- * @type {TilePageSlot|null}
81
- */
82
- let best = null;
83
-
84
- for (let [tile, slot] of this.active) {
85
- //check if it's a tile we are interested in
86
- const address = tile.address;
87
- if (address._includes(x, y, mip)) {
88
- if (best === null || address.mip < best.tile.address.mip) {
89
-
90
- best = slot;
91
-
92
- if (tile.address.mip === mip) {
93
- //found exact match
94
- break;
95
- }
96
- }
97
- }
98
- }
99
-
100
- return best;
101
- };
102
-
103
- /**
104
- *
105
- * @param {Tile} tile
106
- */
107
- TilePage.prototype.put = function (tile) {
108
- if (this.active.contains(tile)) {
109
- return false;
110
- } else {
111
- if (this.emptySlots.length === 0) {
112
- this.active.evictOne();
113
- }
114
-
115
- //pick free slot
116
- const slot = this.emptySlots.pop();
117
- if (slot === undefined) {
118
- //something went wrong
119
- throw new Error(`Failed to obtain a free page slot`);
120
- }
121
-
122
- slot.tile = tile;
123
-
124
- this.active.put(tile, slot);
125
-
126
- //add to write queue
127
- this.queueWrite.push(slot);
128
- }
129
- };
130
-
131
- TilePage.prototype.update = function () {
132
- const queueWrite = this.queueWrite;
133
-
134
- const length = queueWrite.length;
135
- for (let i = 0; i < length; i++) {
136
- const slot = queueWrite[i];
137
- //TODO write slot
138
-
139
- this.sampler.copyWithPadding(slot.tile.sampler, x, y, width, height, padding);
140
- }
141
-
142
- //drop the queue
143
- this.queueWrite.length = 0;
144
- };
145
-
146
- export {
147
- TilePage
148
- };
@@ -1,36 +0,0 @@
1
- import Vector2 from "../../../../../core/geom/Vector2.js";
2
-
3
- export class TilePageSlot {
4
- /**
5
- *
6
- * @param {number} index
7
- * @constructor
8
- */
9
- constructor(index) {
10
- /**
11
- * @type {number}
12
- */
13
- this.index = index;
14
- /**
15
- * Sequential 2D position of the tile slot on the page
16
- * @type {Vector2}
17
- */
18
- this.position = new Vector2();
19
-
20
- /**
21
- *
22
- * @type {Tile|null}
23
- */
24
- this.tile = null;
25
-
26
- this.isWritten = false;
27
- this.isDirty = false;
28
- }
29
-
30
- empty() {
31
- this.tile = null;
32
- this.isDirty = this.isWritten;
33
- this.isWritten = false;
34
- }
35
- }
36
-
@@ -1,44 +0,0 @@
1
- /**
2
- *
3
- * @constructor
4
- * @class
5
- */
6
- import { TileAddress } from "./TileAddress.js";
7
- import { TileStatus } from "./TileStatus.js";
8
-
9
-
10
- export class Tile {
11
- constructor() {
12
- /**
13
- *
14
- * @type {TileAddress}
15
- */
16
- this.address = new TileAddress();
17
- /**
18
- *
19
- * @type {Sampler2D|null}
20
- */
21
- this.sampler = null;
22
- /**
23
- *
24
- * @type {TileStatus}
25
- */
26
- this.status = TileStatus.Initial;
27
- this.referenceCount = 0;
28
- }
29
-
30
- /**
31
- *
32
- * @returns {number}
33
- */
34
- byteSize() {
35
- const sampler = this.sampler;
36
-
37
- if (sampler === null) {
38
- return 0;
39
- }
40
-
41
- return sampler.computeByteSize();
42
- }
43
- }
44
-
@@ -1,11 +0,0 @@
1
- import { Tile } from "./Tile.js";
2
- import { TileStatus } from "./TileStatus.js";
3
-
4
- test("Tile constructor doesn't throw", () => {
5
- new Tile();
6
- });
7
-
8
- test("new tile has Initial status", () => {
9
- const tile = new Tile();
10
- expect(tile.status).toBe(TileStatus.Initial);
11
- });
@@ -1,63 +0,0 @@
1
- /**
2
- * Represents address of a tile in the overall texture pyramid
3
- */
4
- export class TileAddress {
5
- /**
6
- *
7
- * @constructor
8
- */
9
- constructor() {
10
- /**
11
- * Mip level of the tile
12
- * @type {number}
13
- */
14
- this.mip = 0;
15
- /**
16
- * X address of the tile, this is a sequential integer
17
- * @type {number}
18
- */
19
- this.x = 0;
20
- /**
21
- * Y address of the tile, this is a sequential integer
22
- * @type {number}
23
- */
24
- this.y = 0;
25
- }
26
-
27
- /**
28
- *
29
- * @param {TileAddress} other
30
- * @returns {boolean}
31
- */
32
- equals(other) {
33
- return this.x === other.x && this.y === other.y && this.mip === other.mip;
34
- }
35
-
36
- /**
37
- * Returns true if this address is a equal or higher mip level of what requested address
38
- * @returns {boolean}
39
- */
40
- _includes(x, y, mip) {
41
- if (this.mip < mip) {
42
- //lower level mip
43
- return false;
44
- }
45
- const mipDelta = this.mip - mip;
46
-
47
- const expectedX = x << mipDelta;
48
-
49
- if (this.x !== expectedX) {
50
- return false;
51
- }
52
-
53
- const expectedY = y << mipDelta;
54
-
55
- if (this.y !== expectedY) {
56
- return false;
57
- }
58
-
59
- //match
60
- return true;
61
- }
62
- }
63
-
@@ -1,30 +0,0 @@
1
- import { TileAddress } from "./TileAddress.js";
2
-
3
- test("TileAddress equals works correctly", () => {
4
- const a = new TileAddress();
5
- const b = new TileAddress();
6
-
7
- expect(a.equals(b)).toBeTruthy();
8
-
9
- a.x = 1;
10
- a.y = 3;
11
- a.mip = 7;
12
-
13
- expect(a.equals(b)).toBeFalsy();
14
- expect(b.equals(a)).toBeFalsy();
15
-
16
- b.x = 1;
17
-
18
- expect(a.equals(b)).toBeFalsy();
19
- expect(b.equals(a)).toBeFalsy();
20
-
21
- b.y = 3;
22
-
23
- expect(a.equals(b)).toBeFalsy();
24
- expect(b.equals(a)).toBeFalsy();
25
-
26
- b.mip = 7;
27
-
28
- expect(a.equals(b)).toBeTruthy();
29
- expect(b.equals(a)).toBeTruthy();
30
- });
@@ -1,178 +0,0 @@
1
- /**
2
- *
3
- * @constructor
4
- */
5
- import { Tile } from "./Tile.js";
6
- import { TileStatus } from "./TileStatus.js";
7
- import { TileRequest } from "./TileRequest.js";
8
- import { assert } from "../../../../../core/assert.js";
9
-
10
-
11
- export class TileLoader {
12
- /**
13
- *
14
- * @param {AssetManager} assetManager
15
- */
16
- constructor(assetManager) {
17
- assert.defined(assetManager, 'assetManager');
18
- assert.notNull(assetManager, 'assetManager');
19
- assert.equal(assetManager.isAssetManager, true, 'assetManager.isAssetManager !== true');
20
-
21
- /**
22
- * @type {AssetManager}
23
- */
24
- this.assetManager = assetManager;
25
- /**
26
- * number of tiles to be loaded concurrently
27
- * @type {number}
28
- */
29
- this.concurrency = 3;
30
-
31
- /**
32
- * Set of tiles that are currently being loaded
33
- * @type {Set<TileRequest>}
34
- */
35
- this.pending = new Set();
36
-
37
- /**
38
- * Requested tiles that are not yet being loaded
39
- * @type {TileRequest[]}
40
- */
41
- this.queue = [];
42
- }
43
-
44
- /**
45
- *
46
- * @param {TileAddress} address
47
- */
48
- promote(address) {
49
- const i = this.indexOfQueueRequestByTile(address);
50
- if (i === -1) {
51
- //couldn't find, nothing to do
52
- return;
53
- }
54
- //cut and put in the front
55
- const requests = this.queue.splice(i, 1);
56
- this.queue.unshift(requests[0]);
57
- }
58
-
59
- /**
60
- *
61
- * @param {TileAddress} address
62
- * @returns {number}
63
- */
64
- indexOfQueueRequestByTile(address) {
65
- const queue = this.queue;
66
- const l = queue.length;
67
- for (let i = 0; i < l; i++) {
68
- const request = queue[i];
69
- const tile = request.tile;
70
- if (tile.address.equals(address)) {
71
- return i;
72
- }
73
- }
74
-
75
- return -1;
76
- }
77
-
78
- /**
79
- *
80
- * @param {TileAddress} address
81
- * @returns {boolean}
82
- */
83
- remove(address) {
84
- const i = this.indexOfQueueRequestByTile(address);
85
- if (i !== -1) {
86
- this.queue.splice(i, 1);
87
- return true;
88
- } else {
89
- //TODO check pending queue, cancel load
90
- }
91
- }
92
-
93
- /**
94
- *
95
- * @param {Tile} tile
96
- * @param {function(tile:Tile)} successCallback
97
- * @param {function(tile:Tile)} failureCallback
98
- */
99
- add(tile, successCallback, failureCallback) {
100
- for (let request of this.pending) {
101
- if (request.tile.address.equals(tile.address)) {
102
- //tile is already being loaded
103
- request.attach(successCallback, failureCallback);
104
- return;
105
- }
106
- }
107
-
108
- tile.status = TileStatus.Queued;
109
-
110
- const request = new TileRequest(tile, successCallback, failureCallback);
111
-
112
- this.queue.push(request);
113
- this.prod();
114
- }
115
-
116
- /**
117
- * Initialize loading of a tile
118
- * @param {TileRequest} request
119
- */
120
- load(request) {
121
- this.pending.add(request);
122
-
123
- const tile = request.tile;
124
- const url = tileToURL(tile);
125
- tile.status = TileStatus.Loading;
126
-
127
- const self = this;
128
-
129
- function loadFinished() {
130
- self.pending.delete(request);
131
- self.prod();
132
- }
133
-
134
- function success(asset) {
135
- tile.status = TileStatus.Loaded;
136
- tile.sampler = asset.create();
137
-
138
- request.successCallbacks.forEach(function (cb) {
139
- cb(tile);
140
- });
141
-
142
- loadFinished();
143
- }
144
-
145
- function failure() {
146
- //oh well?
147
- request.failureCallbacks.forEach(function (cb) {
148
- cb(tile);
149
- });
150
-
151
- loadFinished();
152
- }
153
-
154
- //do load
155
- this.assetManager.get({ path: 'image', type: url, callback: success, failure: failure });
156
- }
157
-
158
- /**
159
- * Attempt to start loading another tile as long as it's within the concurrency limit, otherwise does nothing
160
- * @private
161
- */
162
- prod() {
163
- while (this.pending < this.concurrency) {
164
- const request = this.queue.shift();
165
- this.load(request);
166
- }
167
- }
168
- }
169
-
170
- /**
171
- * Constructs a tile URL
172
- * @param {Tile} tile
173
- * @returns {string}
174
- */
175
- function tileToURL(tile) {
176
- const address = tile.address;
177
- return `${address.mip}$${address.x}_${address.y}`;
178
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * Representation of a load request for a virtual texture tile
3
- */
4
- export class TileRequest {
5
- /**
6
- *
7
- * @param {Tile} tile
8
- * @param successCallback
9
- * @param failureCallback
10
- */
11
- constructor(tile, successCallback, failureCallback) {
12
- /**
13
- *
14
- * @type {Tile}
15
- */
16
- this.tile = tile;
17
-
18
- /**
19
- *
20
- * @type {Function[]}
21
- */
22
- this.successCallbacks = [successCallback];
23
-
24
- /**
25
- *
26
- * @type {Function[]}
27
- */
28
- this.failureCallbacks = [failureCallback];
29
- }
30
-
31
- /**
32
- *
33
- * @param {function} success
34
- * @param {function} failure
35
- */
36
- attach(success, failure) {
37
- this.successCallbacks.push(success);
38
- this.failureCallbacks.push(failure);
39
- }
40
- }
@@ -1,10 +0,0 @@
1
- /**
2
- *
3
- * @enum {number}
4
- */
5
- export const TileStatus = {
6
- Initial: 0,
7
- Queued: 1,
8
- Loading: 2,
9
- Loaded: 3
10
- };