@woosh/meep-engine 2.75.6 → 2.75.8

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 (81) hide show
  1. package/build/meep.cjs +268 -252
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +268 -252
  4. package/editor/ecs/component/createObjectEditor.js +2 -2
  5. package/package.json +1 -1
  6. package/src/core/geom/3d/frustum/read_three_planes_to_array.d.ts +3 -0
  7. package/src/core/model/object/ImmutableObjectPool.js +14 -5
  8. package/src/engine/ecs/storage/BinaryBufferDeSerializer.js +7 -9
  9. package/src/engine/ecs/storage/BinaryBufferSerializer.js +15 -16
  10. package/src/engine/ecs/storage/binary/BinaryClassUpgrader.js +10 -59
  11. package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +14 -15
  12. package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js +3 -3
  13. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +60 -62
  14. package/src/engine/ecs/storage/binary/executeBinaryClassUpgraderChain.js +46 -0
  15. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter.js +2 -2
  16. package/src/engine/ecs/terrain/ecs/layers/TerrainLayer.js +37 -31
  17. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +8 -7
  18. package/src/engine/graphics/render/RendererPool.js +36 -40
  19. package/src/engine/graphics/render/buffer/FrameBuffer.js +25 -24
  20. package/src/engine/graphics/render/buffer/RenderGraph.js +21 -21
  21. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  22. package/src/engine/graphics/render/frame_graph/IRenderContext.js +31 -1
  23. package/src/engine/graphics/render/frame_graph/RenderGraph.js +5 -5
  24. package/src/engine/graphics/render/frame_graph/RenderTarget.js +9 -0
  25. package/src/engine/graphics/render/frame_graph/RenderTextureManager.js +57 -0
  26. package/src/engine/graphics/render/frame_graph/ResourceEntry.js +7 -5
  27. package/src/engine/graphics/render/frame_graph/TextureDescriptor.js +48 -33
  28. package/src/engine/graphics/render/frame_graph/TextureInitialState.js +14 -0
  29. package/src/engine/graphics/render/frame_graph/sample/deferred/CopyPass.js +20 -0
  30. package/src/engine/graphics/render/frame_graph/sample/deferred/LightingPass.js +4 -0
  31. package/src/engine/graphics/render/frame_graph/sample/deferred/run.js +34 -6
  32. package/src/engine/graphics/render/frame_graph/webgl/WebGLRenderContext.js +34 -0
  33. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +3 -2
  34. package/src/engine/graphics/sh3/gi/prototypeSHGI.js +92 -0
  35. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMemoryMapping.js → VirtualTextureMemoryMapping.js} +2 -26
  36. package/src/engine/graphics/texture/virtual/{v2/VirtualTexturePage.js → VirtualTexturePage.js} +10 -10
  37. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureTileLoader.js → VirtualTextureTileLoader.js} +7 -7
  38. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsage.js → VirtualTextureUsage.js} +1 -1
  39. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageUpdater.js → VirtualTextureUsageUpdater.js} +7 -7
  40. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/ResidencyDebugView.js +4 -4
  41. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsageDebugView.js +2 -2
  42. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsagePyramidDebugView.js +4 -4
  43. package/src/engine/graphics/texture/virtual/{v2/prototype.js → prototype.js} +7 -7
  44. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_finger_print.js +1 -1
  45. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_tile_address.js +2 -2
  46. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/tile_address_to_finger_print.js +1 -1
  47. package/src/core/geom/3d/frustum/read_frustum_planes_to_array.d.ts +0 -3
  48. package/src/engine/ecs/storage/json/Blueprint.js +0 -129
  49. package/src/engine/ecs/storage/json/EntityFactory.js +0 -207
  50. package/src/engine/ecs/storage/json/JSONDeSerializer.js +0 -148
  51. package/src/engine/ecs/storage/json/JSONSerializer.js +0 -132
  52. package/src/engine/ecs/storage/json/README.md +0 -5
  53. package/src/engine/graphics/render/webgpu/sample/MeshInstance.js +0 -108
  54. package/src/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +0 -71
  55. package/src/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +0 -39
  56. package/src/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +0 -21
  57. package/src/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +0 -41
  58. package/src/engine/graphics/render/webgpu/sample/main.js +0 -605
  59. package/src/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +0 -9
  60. package/src/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +0 -30
  61. package/src/engine/graphics/texture/virtual/TileOperation.js +0 -13
  62. package/src/engine/graphics/texture/virtual/TileTree.js +0 -150
  63. package/src/engine/graphics/texture/virtual/TileTree.spec.js +0 -58
  64. package/src/engine/graphics/texture/virtual/TileUsage.js +0 -137
  65. package/src/engine/graphics/texture/virtual/VirtualTexture.js +0 -238
  66. package/src/engine/graphics/texture/virtual/VirtualTexture.spec.js +0 -39
  67. package/src/engine/graphics/texture/virtual/page/TilePage.js +0 -148
  68. package/src/engine/graphics/texture/virtual/page/TilePageSlot.js +0 -36
  69. package/src/engine/graphics/texture/virtual/tile/Tile.js +0 -44
  70. package/src/engine/graphics/texture/virtual/tile/Tile.spec.js +0 -11
  71. package/src/engine/graphics/texture/virtual/tile/TileAddress.js +0 -63
  72. package/src/engine/graphics/texture/virtual/tile/TileAddress.spec.js +0 -30
  73. package/src/engine/graphics/texture/virtual/tile/TileLoader.js +0 -178
  74. package/src/engine/graphics/texture/virtual/tile/TileRequest.js +0 -40
  75. package/src/engine/graphics/texture/virtual/tile/TileStatus.js +0 -10
  76. /package/src/engine/graphics/texture/virtual/{v2/NOTES.md → NOTES.md} +0 -0
  77. /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMaterial.js → VirtualTextureMaterial.js} +0 -0
  78. /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageShader.js → VirtualTextureUsageShader.js} +0 -0
  79. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/VirtualTextureTile.js +0 -0
  80. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/decompose_finger_print.js +0 -0
  81. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/finger_print_to_tile_address.js +0 -0
@@ -1,150 +0,0 @@
1
- /*
2
- This is a state representation of virtual texture tiles
3
- */
4
-
5
-
6
- import { Tile } from "./tile/Tile.js";
7
- import { TileAddress } from "./tile/TileAddress.js";
8
-
9
- class TileTreeNode {
10
- /**
11
- *
12
- * @param {Tile} tile
13
- */
14
- constructor(tile) {
15
- /**
16
- *
17
- * @type {Tile}
18
- */
19
- this.tile = tile;
20
-
21
- /**
22
- *
23
- * @type {TileTreeNode|null}
24
- */
25
- this.parent = null;
26
- }
27
- }
28
-
29
- class TileTreeQuadNode extends TileTreeNode {
30
- /**
31
- *
32
- * @param {Tile} tile
33
- */
34
- constructor(tile) {
35
- super(tile);
36
-
37
- /**
38
- *
39
- * @type {TileTreeNode|null}
40
- */
41
- this.topLeft = null;
42
-
43
- /**
44
- *
45
- * @type {TileTreeNode|null}
46
- */
47
- this.topRight = null;
48
-
49
- /**
50
- *
51
- * @type {TileTreeNode|null}
52
- */
53
- this.bottomLeft = null;
54
-
55
- /**
56
- *
57
- * @type {TileTreeNode|null}
58
- */
59
- this.bottomRight = null;
60
- }
61
- }
62
-
63
- /**
64
- *
65
- * @param {number} mip
66
- * @param {number} x
67
- * @param {number} y
68
- * @returns {Tile}
69
- */
70
- function buildEmptyTile(mip, x, y) {
71
- const tileAddress = new TileAddress();
72
-
73
- tileAddress.mip = mip;
74
- tileAddress.x = x;
75
- tileAddress.y = y;
76
-
77
- const tile = new Tile();
78
-
79
- tile.address = tileAddress;
80
-
81
- return tile;
82
- }
83
-
84
- /**
85
- *
86
- * @param {number} x
87
- * @param {number} y
88
- * @param {number} mip
89
- * @param {number} maxMip
90
- * @param {Vector2} size
91
- * @returns {TileTreeNode}
92
- */
93
- function buildTree(x, y, mip, maxMip,size) {
94
- const tile = buildEmptyTile(mip, x, y);
95
-
96
- if (mip === maxMip) {
97
- return new TileTreeNode(tile);
98
- } else {
99
- const node = new TileTreeQuadNode(tile);
100
- const childX = x * 2;
101
- const childY = y * 2;
102
-
103
- const childMip = mip + 1;
104
-
105
- node.topLeft = buildTree(childX, childY, childMip, maxMip, size);
106
- node.topLeft.parent = node;
107
-
108
- if (childX < size.x) {
109
- node.topRight = buildTree(childX + 1, childY, childMip, maxMip, size);
110
- node.topRight.parent = node;
111
-
112
- if (childY < size.y) {
113
- node.bottomLeft = buildTree(childX, childY + 1, childMip, maxMip, size);
114
- node.bottomLeft.parent = node;
115
-
116
- node.bottomRight = buildTree(childX + 1, childY + 1, childMip, maxMip, size);
117
- node.bottomRight.parent = node;
118
- }
119
- } else if (childY < size.y) {
120
- node.bottomLeft = buildTree(childX, childY + 1, childMip, maxMip, size);
121
- node.bottomLeft.parent = node;
122
- }
123
-
124
- return node;
125
- }
126
- }
127
-
128
- /**
129
- *
130
- * @param {Vector2} size
131
- * @returns {TileTreeQuadNode|TileTreeNode}
132
- */
133
- export function buildTileTree(size) {
134
-
135
- const maxMipLevel = Math.ceil(Math.log2(Math.max(size.x, size.y)));
136
-
137
- if (size.x < 1 || size.y < 1) {
138
- throw new Error(`Can't build a tree, size must be at least 1x1, was ${size.x}x${size.y}`);
139
- }
140
-
141
- return buildTree(0, 0, 0, maxMipLevel, size);
142
- }
143
-
144
-
145
- export {
146
- TileTreeNode,
147
- TileTreeQuadNode
148
- };
149
-
150
-
@@ -1,58 +0,0 @@
1
- import { buildTileTree, TileTreeQuadNode } from "./TileTree.js";
2
- import Vector2 from "../../../../core/geom/Vector2.js";
3
-
4
- test("Building a tree with size 0x0 fails", () => {
5
- expect(() => buildTileTree(new Vector2(0, 0))).toThrow();
6
- });
7
-
8
- test("Building a tree with size 1x1 produces a single leaf node", () => {
9
- const node = buildTileTree(new Vector2(1, 1));
10
-
11
- expect(node instanceof TileTreeQuadNode).toBe(false);
12
-
13
- expect(node.tile).toBeDefined();
14
-
15
- expect(node.tile.address).toBeDefined();
16
-
17
- expect(node.tile.address.x).toBe(0);
18
- expect(node.tile.address.y).toBe(0);
19
-
20
- expect(node.tile.address.mip).toBe(0);
21
- });
22
-
23
- test("Building a tree with size 2x2 produced correct tree", () => {
24
- const node = buildTileTree(new Vector2(2, 2));
25
-
26
- expect(node instanceof TileTreeQuadNode).toBe(true);
27
-
28
- expect(node.topLeft).toBeDefined();
29
- expect(node.topRight).toBeDefined();
30
- expect(node.bottomLeft).toBeDefined();
31
- expect(node.bottomRight).toBeDefined();
32
-
33
- expect(node.topLeft instanceof TileTreeQuadNode).toBe(false);
34
- expect(node.topRight instanceof TileTreeQuadNode).toBe(false);
35
- expect(node.bottomLeft instanceof TileTreeQuadNode).toBe(false);
36
- expect(node.bottomRight instanceof TileTreeQuadNode).toBe(false);
37
-
38
- expect(node.topLeft.parent).toBe(node);
39
- expect(node.topRight.parent).toBe(node);
40
- expect(node.bottomLeft.parent).toBe(node);
41
- expect(node.bottomRight.parent).toBe(node);
42
-
43
- expect(node.topLeft.tile.address.mip).toEqual(1);
44
- expect(node.topLeft.tile.address.x).toEqual(0);
45
- expect(node.topLeft.tile.address.y).toEqual(0);
46
-
47
- expect(node.topRight.tile.address.mip).toEqual(1);
48
- expect(node.topRight.tile.address.x).toEqual(1);
49
- expect(node.topRight.tile.address.y).toEqual(0);
50
-
51
- expect(node.bottomLeft.tile.address.mip).toEqual(1);
52
- expect(node.bottomLeft.tile.address.x).toEqual(0);
53
- expect(node.bottomLeft.tile.address.y).toEqual(1);
54
-
55
- expect(node.bottomRight.tile.address.mip).toEqual(1);
56
- expect(node.bottomRight.tile.address.x).toEqual(1);
57
- expect(node.bottomRight.tile.address.y).toEqual(1);
58
- });
@@ -1,137 +0,0 @@
1
- /**
2
- * Accelerated Datastructure to track tile usage
3
- * @constructor
4
- */
5
- function TileUsage() {
6
- this.data = [];
7
- }
8
-
9
- /**
10
- *
11
- * @returns {TileUsage}
12
- */
13
- TileUsage.prototype.clone = function () {
14
- const result = new TileUsage();
15
- result.data = this.data.slice();
16
- return result;
17
- };
18
-
19
- /**
20
- *
21
- * @param {TileAddress} tileAddress
22
- * @returns {number}
23
- */
24
- TileUsage.prototype.find = function (tileAddress) {
25
- let offset = -1;
26
- do {
27
- offset = this.data.indexOf(tileAddress, offset);
28
- } while (offset !== -1 && offset % 2 !== 0);
29
-
30
- return offset;
31
- };
32
-
33
-
34
- /**
35
- *
36
- * @param {TileAddress} tileAddress
37
- * @returns {number}
38
- */
39
- TileUsage.prototype.obtain = function (tileAddress) {
40
- const i = this.find(tileAddress);
41
- if (i !== -1) {
42
- return i;
43
- } else {
44
- const data = this.data;
45
- const result = data.length;
46
- data.push(tileAddress, 0);
47
- return result;
48
- }
49
- };
50
-
51
- TileUsage.prototype.sort = function () {
52
- const arr = this.data;
53
-
54
- function quickSort(left, right) {
55
- if (left < right) {
56
- const pivot = right;
57
- const partitionIndex = partition(pivot, left, right);
58
-
59
- //sort left and right
60
- quickSort(left, partitionIndex - 1);
61
- quickSort(partitionIndex + 1, right);
62
- }
63
- return arr;
64
- }
65
-
66
- function partition(pivot, left, right) {
67
- const pivotValue = arr[pivot * 2 + 1];
68
- let partitionIndex = left;
69
-
70
- for (let i = left; i < right; i++) {
71
- if (arr[i * 2 + 1] < pivotValue) {
72
- swap(arr, i, partitionIndex);
73
- partitionIndex++;
74
- }
75
- }
76
- swap(arr, right, partitionIndex);
77
- return partitionIndex;
78
- }
79
-
80
- function swap(arr, i, j) {
81
- const i2 = i * 2;
82
- const j2 = j * 2;
83
-
84
- const temp0 = arr[i2];
85
- const temp1 = arr[i2 + 1];
86
-
87
- arr[i2] = arr[j2];
88
- arr[i2 + 1] = arr[j2 + 1];
89
-
90
- arr[j2] = temp0;
91
- arr[j2 + 1] = temp1;
92
- }
93
-
94
- quickSort(0, this.data.length / 2);
95
- };
96
-
97
- /**
98
- *
99
- * @param {function} visitor
100
- */
101
- TileUsage.prototype.traverseReverse = function (visitor) {
102
- const data = this.data;
103
- const length = data.length;
104
- for (let i = length - 1; i >= 0; i -= 2) {
105
- const continueFlag = visitor(data[i], data[i + 1]);
106
- if (continueFlag === false) {
107
- return;
108
- }
109
- }
110
- };
111
-
112
- /**
113
- *
114
- * @param {function} visitor
115
- */
116
- TileUsage.prototype.traverse = function (visitor) {
117
- const data = this.data;
118
- const length = data.length;
119
- for (let i = 0; i < length; i += 2) {
120
- const continueFlag = visitor(data[i], data[i + 1]);
121
- if (continueFlag === false) {
122
- return;
123
- }
124
- }
125
- };
126
-
127
- /**
128
- *
129
- * @param {TileAddress} tileAddress
130
- * @param {number} count
131
- */
132
- TileUsage.prototype.add = function (tileAddress, count) {
133
- const i = this.obtain(tileAddress);
134
- this.data[i + 1] += count;
135
- };
136
-
137
- export { TileUsage };
@@ -1,238 +0,0 @@
1
- import { Tile } from "./tile/Tile.js";
2
- import { TileLoader } from "./tile/TileLoader.js";
3
- import { Cache } from "../../../../core/cache/Cache.js";
4
- import Vector2 from "../../../../core/geom/Vector2.js";
5
- import { TilePage } from "./page/TilePage.js";
6
- import { create32BitCodec } from "../../../../core/binary/32BitEncoder.js";
7
- import { TileStatus } from "./tile/TileStatus.js";
8
- import { assert } from "../../../../core/assert.js";
9
-
10
- /**
11
- *
12
- * @param tileSize
13
- * @param textureSize
14
- * @returns {{encode: (function(..value:number): number), decode: (function(number, number[]): void)}}
15
- */
16
- function buildAddressEncoder(tileSize, textureSize) {
17
- assert.isNumber(tileSize,'tileSize');
18
- assert.notNaN(tileSize,'tileSize');
19
- assert.isNonNegativeInteger(tileSize,'tileSize');
20
-
21
- assert.isNumber(textureSize,'textureSize');
22
- assert.notNaN(textureSize,'textureSize');
23
- assert.isNonNegativeInteger(textureSize,'textureSize');
24
-
25
- const numberOfTiles = Math.ceil(textureSize / tileSize);
26
- const numberOfMips = Math.ceil(Math.log2(numberOfTiles));
27
-
28
- const bitsPerMip = Math.ceil(Math.log2(numberOfMips));
29
- const bitsPerCoordinate = Math.ceil(Math.log2(numberOfTiles));
30
-
31
- return create32BitCodec([bitsPerCoordinate, bitsPerCoordinate, bitsPerMip]);
32
- }
33
-
34
- const BYTES_PER_MEGABYTE = 1024 * 1024;
35
-
36
- const DEFAULT_CACHE_SIZE = 100 * BYTES_PER_MEGABYTE;
37
-
38
- const DEFAULT_PAGE_SIZE = new Vector2(2048, 2048);
39
-
40
- const DEFAULT_PADDING = 4;
41
-
42
- export class VirtualTexture {
43
- /**
44
- *
45
- * @param {AssetManager} assetManager
46
- * @constructor
47
- */
48
- constructor(assetManager) {
49
- this.addressCodec = null;
50
-
51
-
52
- /**
53
- * Active page cache texture
54
- * @type {TilePage}
55
- */
56
- this.page = new TilePage();
57
-
58
- const loader = this.loader = new TileLoader(assetManager);
59
-
60
- /**
61
- *
62
- * @type {Cache.<number, Tile>}
63
- */
64
- this.cache = new Cache({
65
- keyWeigher: function (key) {
66
- return 8;
67
- },
68
- valueWeigher: function (tile) {
69
- return 1;
70
- },
71
- removeListener: function (key, value) {
72
- loader.remove(value.address);
73
- }
74
- });
75
-
76
- /**
77
- * When a tile is loaded, this bias is used to add portion of tile's usage count to coarser mip level tile.
78
- * In effect, it controls likelihood fetching lower resolution mip for a tile. Value should be between 0 and 1, value of 0 means - no bias, value of 1 means - making lower resolution mip at least as likely to get fetched
79
- * @type {number}
80
- * @private
81
- */
82
- this.__settingMipBias = 0.7;
83
-
84
- this.maxMipLevel = 0;
85
- this.tileResolution = new Vector2(0, 0);
86
- this.resolution = new Vector2(0, 0);
87
- this.sizeInTiles = new Vector2(0, 0);
88
- }
89
-
90
- /**
91
- *
92
- * @param {number} address
93
- * @returns {Tile}
94
- */
95
- getTile(address) {
96
- const cachedTile = this.cache.get(address);
97
- if (cachedTile !== null) {
98
- return cachedTile;
99
- }
100
-
101
- const decodedAddress = [];
102
-
103
- this.addressCodec.decode(address, decodedAddress);
104
-
105
- const [x, y, mip] = decodedAddress;
106
-
107
- //tile is not cached
108
- const tile = new Tile();
109
- tile.address.x = x;
110
- tile.address.y = y;
111
- tile.address.mip = mip;
112
-
113
- this.cache.put(address, tile);
114
- this.loader.add(tile);
115
- }
116
-
117
- /**
118
- *
119
- * @param {number} [cacheSize] resolution of the cache for tiles
120
- * @param {Vector2} [pageSize] size of the texture page
121
- * @param {number} [padding]
122
- * @param {Vector2} resolution maximum mip-level resolution fo the texture
123
- * @param {Vector2} tileResolution resolution or a single tile
124
- */
125
- init({
126
- cacheSize = DEFAULT_CACHE_SIZE,
127
- pageSize = DEFAULT_PAGE_SIZE,
128
- padding = DEFAULT_PADDING,
129
- resolution,
130
- tileResolution
131
- }) {
132
- this.resolution.copy(resolution);
133
- this.tileResolution.copy(tileResolution);
134
-
135
- //build address codec
136
- this.addressCodec = buildAddressEncoder(tileResolution, resolution);
137
-
138
- //initialize cache
139
- this.cache.drop();
140
- this.cache.setMaxWeight(cacheSize);
141
-
142
- const tileByteSize = tileResolution.x * tileResolution.y * 4;
143
- const cacheValueWeigher = new Function('tile', `return ${tileByteSize};`);
144
-
145
- this.cache.setValueWeigher(cacheValueWeigher);
146
-
147
- //initialize page
148
- this.page.init(pageSize, tileResolution, padding);
149
-
150
- const sizeInTiles = resolution.clone().divide(tileResolution);
151
-
152
- if (sizeInTiles.x % 1 !== 0 || sizeInTiles.y % 1 !== 0) {
153
- throw new Error(`Texture resolution must be a multiple of tile resolution, instead multiples were ${JSON.stringify(sizeInTiles.toJSON())}`);
154
- }
155
-
156
- this.sizeInTiles.copy(sizeInTiles);
157
- this.maxMipLevel = Math.ceil(Math.log2(Math.max(sizeInTiles.x, sizeInTiles.y)));
158
- }
159
-
160
- /**
161
- *
162
- * @param {TileUsage} input
163
- */
164
- updateUsage(input) {
165
- const usage = input.clone();
166
-
167
- const addressCodec = this.addressCodec;
168
-
169
- const settingMipBias = this.__settingMipBias;
170
-
171
- const maxMipLevel = this.maxMipLevel;
172
-
173
- /**
174
- *
175
- * @param {number} x
176
- * @param {number} y
177
- * @param {number} mip
178
- * @param {number} count
179
- */
180
- function registerUsage(x, y, mip, count) {
181
- if (mip > maxMipLevel) {
182
- //invalid mip, do nothing
183
- return;
184
- }
185
-
186
- const address = addressCodec.encode(x, y, mip);
187
- usage.add(address, count);
188
-
189
- //include earlier levels
190
- const x1 = Math.floor(x / 2);
191
- const y1 = Math.floor(y / 2);
192
- registerUsage(x1, y1, mip + 1, count * settingMipBias);
193
- }
194
-
195
- const decodedAddress = [0, 0, 0];
196
- input.traverse(function (address, count) {
197
-
198
- //decode address
199
- addressCodec.decode(address, decodedAddress);
200
-
201
- const x = decodedAddress[0];
202
- const y = decodedAddress[1];
203
- const mip = decodedAddress[2];
204
-
205
- //include earlier levels
206
- registerUsage(x, y, mip + 1, count * settingMipBias);
207
- });
208
-
209
- //we have a collection of pages with usage count at this point
210
-
211
- usage.sort();
212
-
213
-
214
- let remainingPageSlots = this.page.capacity;
215
- const self = this;
216
- const page = this.page;
217
- usage.traverse(function (address, count) {
218
- const tile = self.getTile(address);
219
- if (remainingPageSlots > 0 && tile.status === TileStatus.Loaded) {
220
- //tile is loaded, put it into page
221
- if (page.put(tile)) {
222
- //tile was added into the page
223
- remainingPageSlots--;
224
- }
225
- }
226
- });
227
-
228
- if (remainingPageSlots !== this.page.capacity) {
229
- //page was modified
230
- this.page.update();
231
- }
232
-
233
- //reorder loading queue, put used tiles at the front with most used being foremost
234
- usage.traverseReverse(function (address, count) {
235
- self.loader.promote(address);
236
- });
237
- }
238
- }
@@ -1,39 +0,0 @@
1
- import { VirtualTexture } from "./VirtualTexture.js";
2
- import Vector2 from "../../../../core/geom/Vector2.js";
3
-
4
- function mockAssetManager() {
5
- const assetManager = {
6
- get: function ({ path, type, success, failure }) {
7
- const delay = Math.random() * 100;
8
- setTimeout(function () {
9
- success({
10
- create: function () {
11
- return null;
12
- }
13
- });
14
- }, delay);
15
- },
16
- isAssetManager: true
17
- };
18
-
19
- return assetManager;
20
- }
21
-
22
- test("constructor doesn't throw", () => {
23
- const assetManager = mockAssetManager();
24
-
25
- new VirtualTexture(assetManager)
26
- });
27
-
28
- test.skip("init computes sizes correctly", () => {
29
- const assetManager = mockAssetManager();
30
-
31
- const sut = new VirtualTexture(assetManager);
32
-
33
- sut.init({ padding: 4, resolution: new Vector2(16, 3), tileResolution: new Vector2(1, 1) });
34
-
35
- expect(sut.maxMipLevel).toBe(4);
36
-
37
- expect(sut.sizeInTiles.x).toBe(16);
38
- expect(sut.sizeInTiles.y).toBe(3);
39
- });