@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.
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +1052 -1234
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +1052 -1234
- package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
- package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
- package/editor/ecs/component/createObjectEditor.js +2 -2
- package/editor/process/EditorProcess.js +12 -16
- package/editor/process/ProcessEngine.js +9 -10
- package/package.json +1 -1
- package/src/core/binary/dec2hex.js +1 -1
- package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
- package/src/core/math/newton_solver_1d.js +13 -4
- package/src/core/math/solveQuadratic.js +5 -3
- package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
- package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
- package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
- package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
- package/src/core/math/spline/interpolate_bicubic.js +12 -0
- package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
- package/src/core/model/object/ImmutableObjectPool.js +14 -5
- package/src/engine/control/ControlContext.js +25 -27
- package/src/engine/ecs/EntityManager.js +12 -9
- package/src/engine/ecs/EntityObserver.js +26 -22
- package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
- package/src/engine/ecs/components/Motion.js +5 -7
- package/src/engine/ecs/components/SerializationMetadata.js +5 -3
- package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
- package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
- package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
- package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
- package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
- package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
- package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
- package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
- package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
- package/src/engine/ecs/parent/EntityNode.js +39 -37
- package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
- package/src/engine/ecs/storage/BinaryBufferDeSerializer.js +7 -9
- package/src/engine/ecs/storage/BinaryBufferSerializer.js +15 -16
- package/src/engine/ecs/storage/binary/BinaryClassUpgrader.js +10 -59
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +14 -15
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js +3 -3
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +60 -62
- package/src/engine/ecs/storage/binary/executeBinaryClassUpgraderChain.js +46 -0
- package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter.js +2 -2
- package/src/engine/ecs/system/SystemEntityContext.js +25 -23
- package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
- package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayer.js +37 -31
- package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +8 -7
- package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
- package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
- package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
- package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
- package/src/engine/graphics/render/RendererPool.js +36 -40
- package/src/engine/graphics/render/buffer/FrameBuffer.js +25 -24
- package/src/engine/graphics/render/buffer/RenderGraph.js +21 -21
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -5
- package/src/engine/graphics/render/frame_graph/IRenderContext.js +31 -1
- package/src/engine/graphics/render/frame_graph/RenderGraph.js +5 -5
- package/src/engine/graphics/render/frame_graph/RenderTarget.js +9 -0
- package/src/engine/graphics/render/frame_graph/RenderTextureManager.js +57 -0
- package/src/engine/graphics/render/frame_graph/ResourceEntry.js +7 -5
- package/src/engine/graphics/render/frame_graph/TextureDescriptor.js +48 -33
- package/src/engine/graphics/render/frame_graph/TextureInitialState.js +14 -0
- package/src/engine/graphics/render/frame_graph/sample/deferred/CopyPass.js +20 -0
- package/src/engine/graphics/render/frame_graph/sample/deferred/LightingPass.js +4 -0
- package/src/engine/graphics/render/frame_graph/sample/deferred/run.js +34 -6
- package/src/engine/graphics/render/frame_graph/webgl/WebGLRenderContext.js +34 -0
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +3 -6
- package/src/engine/graphics/sh3/gi/prototypeSHGI.js +92 -0
- package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
- package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
- package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
- package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
- package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
- package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
- package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
- package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMemoryMapping.js → VirtualTextureMemoryMapping.js} +2 -26
- package/src/engine/graphics/texture/virtual/{v2/VirtualTexturePage.js → VirtualTexturePage.js} +10 -10
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureTileLoader.js → VirtualTextureTileLoader.js} +7 -7
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsage.js → VirtualTextureUsage.js} +1 -1
- package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageUpdater.js → VirtualTextureUsageUpdater.js} +7 -7
- package/src/engine/graphics/texture/virtual/{v2/debug → debug}/ResidencyDebugView.js +4 -4
- package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsageDebugView.js +2 -2
- package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsagePyramidDebugView.js +4 -4
- package/src/engine/graphics/texture/virtual/{v2/prototype.js → prototype.js} +7 -7
- package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_finger_print.js +1 -1
- package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_tile_address.js +2 -2
- package/src/engine/graphics/texture/virtual/{v2/tile → tile}/tile_address_to_finger_print.js +1 -1
- package/src/engine/navigation/ecs/components/Path.js +10 -9
- package/src/engine/physics/computeInterceptPoint.js +44 -0
- package/src/engine/plugin/EnginePlugin.js +1 -2
- package/src/engine/ecs/components/AlignToVelocity.js +0 -9
- package/src/engine/ecs/components/CharacterController.js +0 -31
- package/src/engine/ecs/components/PhysicalBody.js +0 -51
- package/src/engine/ecs/components/Steering.js +0 -111
- package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
- package/src/engine/ecs/storage/json/Blueprint.js +0 -129
- package/src/engine/ecs/storage/json/EntityFactory.js +0 -207
- package/src/engine/ecs/storage/json/JSONDeSerializer.js +0 -148
- package/src/engine/ecs/storage/json/JSONSerializer.js +0 -132
- package/src/engine/ecs/storage/json/README.md +0 -5
- package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
- package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
- package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
- package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
- package/src/engine/ecs/systems/SteeringSystem.js +0 -171
- package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
- package/src/engine/ecs/systems/TagSystem.js +0 -31
- package/src/engine/graphics/render/webgpu/sample/MeshInstance.js +0 -108
- package/src/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +0 -71
- package/src/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +0 -39
- package/src/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +0 -21
- package/src/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +0 -41
- package/src/engine/graphics/render/webgpu/sample/main.js +0 -605
- package/src/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +0 -9
- package/src/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +0 -30
- package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
- package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
- package/src/engine/graphics/texture/virtual/TileOperation.js +0 -13
- package/src/engine/graphics/texture/virtual/TileTree.js +0 -150
- package/src/engine/graphics/texture/virtual/TileTree.spec.js +0 -58
- package/src/engine/graphics/texture/virtual/TileUsage.js +0 -137
- package/src/engine/graphics/texture/virtual/VirtualTexture.js +0 -238
- package/src/engine/graphics/texture/virtual/VirtualTexture.spec.js +0 -39
- package/src/engine/graphics/texture/virtual/page/TilePage.js +0 -148
- package/src/engine/graphics/texture/virtual/page/TilePageSlot.js +0 -36
- package/src/engine/graphics/texture/virtual/tile/Tile.js +0 -44
- package/src/engine/graphics/texture/virtual/tile/Tile.spec.js +0 -11
- package/src/engine/graphics/texture/virtual/tile/TileAddress.js +0 -63
- package/src/engine/graphics/texture/virtual/tile/TileAddress.spec.js +0 -30
- package/src/engine/graphics/texture/virtual/tile/TileLoader.js +0 -178
- package/src/engine/graphics/texture/virtual/tile/TileRequest.js +0 -40
- package/src/engine/graphics/texture/virtual/tile/TileStatus.js +0 -10
- package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
- /package/src/engine/graphics/texture/virtual/{v2/NOTES.md → NOTES.md} +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMaterial.js → VirtualTextureMaterial.js} +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageShader.js → VirtualTextureUsageShader.js} +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/VirtualTextureTile.js +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/decompose_finger_print.js +0 -0
- /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/finger_print_to_tile_address.js +0 -0
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://github.com/hughsk/bicubic/blob/master/index.js
|
|
3
|
-
* @param {number} xf
|
|
4
|
-
* @param {number} yf
|
|
5
|
-
* @param {number} p00
|
|
6
|
-
* @param {number} p01
|
|
7
|
-
* @param {number} p02
|
|
8
|
-
* @param {number} p03
|
|
9
|
-
* @param {number} p10
|
|
10
|
-
* @param {number} p11
|
|
11
|
-
* @param {number} p12
|
|
12
|
-
* @param {number} p13
|
|
13
|
-
* @param {number} p20
|
|
14
|
-
* @param {number} p21
|
|
15
|
-
* @param {number} p22
|
|
16
|
-
* @param {number} p23
|
|
17
|
-
* @param {number} p30
|
|
18
|
-
* @param {number} p31
|
|
19
|
-
* @param {number} p32
|
|
20
|
-
* @param {number} p33
|
|
21
|
-
* @returns {number}
|
|
22
|
-
*/
|
|
23
|
-
export function bicubic(
|
|
24
|
-
xf, yf
|
|
25
|
-
, p00, p01, p02, p03
|
|
26
|
-
, p10, p11, p12, p13
|
|
27
|
-
, p20, p21, p22, p23
|
|
28
|
-
, p30, p31, p32, p33
|
|
29
|
-
) {
|
|
30
|
-
var yf2 = yf * yf
|
|
31
|
-
var xf2 = xf * xf
|
|
32
|
-
var xf3 = xf * xf2
|
|
33
|
-
|
|
34
|
-
var x00 = p03 - p02 - p00 + p01
|
|
35
|
-
var x01 = p00 - p01 - x00
|
|
36
|
-
var x02 = p02 - p00
|
|
37
|
-
var x0 = x00 * xf3 + x01 * xf2 + x02 * xf + p01
|
|
38
|
-
|
|
39
|
-
var x10 = p13 - p12 - p10 + p11
|
|
40
|
-
var x11 = p10 - p11 - x10
|
|
41
|
-
var x12 = p12 - p10
|
|
42
|
-
var x1 = x10 * xf3 + x11 * xf2 + x12 * xf + p11
|
|
43
|
-
|
|
44
|
-
var x20 = p23 - p22 - p20 + p21
|
|
45
|
-
var x21 = p20 - p21 - x20
|
|
46
|
-
var x22 = p22 - p20
|
|
47
|
-
var x2 = x20 * xf3 + x21 * xf2 + x22 * xf + p21
|
|
48
|
-
|
|
49
|
-
var x30 = p33 - p32 - p30 + p31
|
|
50
|
-
var x31 = p30 - p31 - x30
|
|
51
|
-
var x32 = p32 - p30
|
|
52
|
-
var x3 = x30 * xf3 + x31 * xf2 + x32 * xf + p31
|
|
53
|
-
|
|
54
|
-
var y0 = x3 - x2 - x0 + x1
|
|
55
|
-
var y1 = x0 - x1 - y0
|
|
56
|
-
var y2 = x2 - x0
|
|
57
|
-
|
|
58
|
-
return y0 * yf * yf2 + y1 * yf2 + y2 * yf + x1
|
|
59
|
-
}
|
|
@@ -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
|
-
});
|