@woosh/meep-engine 2.33.2 → 2.33.6
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/core/bvh2/aabb3/AABB3.js +18 -0
- package/core/bvh2/aabb3/aabb3_intersects_frustum.js +38 -0
- package/core/collection/RingBuffer.js +40 -10
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/array/typed/typed_array_copy.js +2 -2
- package/core/collection/table/RowFirstTableSpec.js +8 -0
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +16 -14
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
- package/core/geom/3d/plane/plane3_lerp.js +2 -2
- package/core/geom/3d/topology/TopoTriangle.js +2 -2
- package/core/geom/AABB2.d.ts +2 -0
- package/core/geom/Matrix4.js +4 -4
- package/core/geom/Vector3.js +5 -5
- package/core/model/reactive/model/terminal/ReactiveReference.js +7 -1
- package/core/process/undo/ActionProcessor.d.ts +2 -0
- package/core/process/undo/ActionProcessor.js +59 -1
- package/core/process/undo/ActionProcessor.spec.js +59 -0
- package/core/process/undo/Mark.js +2 -1
- package/engine/asset/loaders/GLTFAssetLoader.js +3 -3
- package/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +11 -1
- package/engine/asset/loaders/material/TextureAttachment.js +12 -1
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
- package/engine/asset/loaders/material/computeTextureEquality.js +1 -1
- package/engine/asset/loaders/material/computeTextureHash.js +16 -14
- package/engine/asset/loaders/material/traverseMaterialTextures.js +2 -2
- package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -2
- package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +4 -4
- package/engine/graphics/GraphicsEngine.d.ts +2 -2
- package/engine/graphics/GraphicsEngine.js +20 -62
- package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
- package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
- package/engine/graphics/filter/ImageFilter.js +20 -51
- package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -2
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
- package/engine/graphics/material/SplatMaterial.js +4 -97
- package/engine/graphics/material/optimization/MaterialOptimizationContext.js +598 -0
- package/engine/graphics/micron/build/PatchRepresentation.js +4 -43
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +4 -75
- package/engine/graphics/micron/build/compute_buffer_geometry_byte_size.js +16 -0
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
- package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -5
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/prototypeVirtualGeometry.js +19 -12
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +34 -27
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
- package/engine/graphics/micron/render/instanced/PatchDataTextures.js +1 -0
- package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +1 -29
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +43 -159
- package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
- package/engine/graphics/micron/render/refinement/array_normalize_plane.js +25 -0
- package/engine/graphics/micron/render/refinement/array_setFromProjectionMatrix.js +60 -0
- package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +43 -0
- package/engine/graphics/micron/render/refinement/is_patch_visible.js +37 -0
- package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
- package/engine/graphics/micron/util/unit_hemioct.spec.js +2 -2
- package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
- package/engine/graphics/render/buffer/buffers/NormalFrameBuffer.js +12 -2
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
- package/engine/graphics/render/forward_plus/LightManager.js +5 -7
- package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
- package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
- package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
- package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
- package/engine/graphics/render/utils/ThreeBypassRenderer.js +1 -3
- package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
- package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
- package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
- package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
- package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
- package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
- package/engine/graphics/texture/atlas/TextureAtlas.js +1 -1
- package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
- package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
- package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +8 -4
- package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
- package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
- package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
- package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
- package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
- package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
- package/package.json +1 -1
- package/view/elements/progress/segmented/SegmentedResourceBarView.js +50 -15
- package/view/minimap/gl/MinimapMarkersGL.js +2 -2
- package/engine/graphics/micron/render/RefinementSpec.js +0 -110
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../../EngineHarness.js";
|
|
2
|
+
import { EngineConfiguration } from "../../../../EngineConfiguration.js";
|
|
3
|
+
import GUIElementSystem from "../../../../ecs/gui/GUIElementSystem.js";
|
|
4
|
+
import HeadsUpDisplaySystem from "../../../../ecs/gui/hud/HeadsUpDisplaySystem.js";
|
|
5
|
+
import ScriptSystem from "../../../../ecs/systems/ScriptSystem.js";
|
|
6
|
+
import FacingDirectionSystem from "../../../../../../model/game/ecs/system/FacingDirectionSystem.js";
|
|
7
|
+
import PathFollowingSystem from "../../../../navigation/ecs/path_following/PathFollowingSystem.js";
|
|
8
|
+
import SteeringSystem from "../../../../ecs/systems/SteeringSystem.js";
|
|
9
|
+
import MotionSystem from "../../../../ecs/systems/MotionSystem.js";
|
|
10
|
+
import TagSystem from "../../../../ecs/systems/TagSystem.js";
|
|
11
|
+
import { AttachmentSocketsSystem } from "../../../../ecs/sockets/AttachmentSocketsSystem.js";
|
|
12
|
+
import { AttachmentSystem } from "../../../../ecs/attachment/AttachmentSystem.js";
|
|
13
|
+
import { SoundEmitterSystem } from "../../../../sound/ecs/emitter/SoundEmitterSystem.js";
|
|
14
|
+
import SoundControllerSystem from "../../../../sound/ecs/SoundControllerSystem.js";
|
|
15
|
+
import SoundListenerSystem from "../../../../sound/ecs/SoundListenerSystem.js";
|
|
16
|
+
import TimerSystem from "../../../../ecs/systems/TimerSystem.js";
|
|
17
|
+
import AnimationSystem from "../../../../ecs/systems/AnimationSystem.js";
|
|
18
|
+
import TopDownCameraControllerSystem from "../../../ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
19
|
+
import { TopDownCameraLanderSystem } from "../../../ecs/camera/topdown/TopDownCameraLanderSystem.js";
|
|
20
|
+
import { CameraSystem } from "../../../ecs/camera/CameraSystem.js";
|
|
21
|
+
import { MeshSystem } from "../../../ecs/mesh/MeshSystem.js";
|
|
22
|
+
import ClingToTerrainSystem from "../../../../ecs/terrain/ecs/ClingToTerrainSystem.js";
|
|
23
|
+
import TerrainSystem from "../../../../ecs/terrain/ecs/TerrainSystem.js";
|
|
24
|
+
import WaterSystem from "../../../ecs/water/WaterSystem.js";
|
|
25
|
+
import Trail2DSystem from "../../../ecs/trail2d/Trail2DSystem.js";
|
|
26
|
+
import { Foliage2System } from "../../../../ecs/foliage/ecs/Foliage2System.js";
|
|
27
|
+
import ViewportPositionSystem from "../../../../ecs/gui/position/ViewportPositionSystem.js";
|
|
28
|
+
import { GridPosition2TransformSystem } from "../../../../grid/systems/GridPosition2TransformSystem.js";
|
|
29
|
+
import { Transform2GridPositionSystem } from "../../../../grid/transform2grid/Transform2GridPositionSystem.js";
|
|
30
|
+
import SynchronizePositionSystem from "../../../../ecs/systems/SynchronizePositionSystem.js";
|
|
31
|
+
import GridObstacleSystem from "../../../../grid/systems/GridObstacleSystem.js";
|
|
32
|
+
import GridPositionSystem from "../../../../grid/systems/GridPositionSystem.js";
|
|
33
|
+
import InputControllerSystem from "../../../../input/ecs/systems/InputControllerSystem.js";
|
|
34
|
+
import { InputSystem } from "../../../../input/ecs/systems/InputSystem.js";
|
|
35
|
+
import MeshHighlightSystem from "../../../ecs/highlight/system/MeshHighlightSystem.js";
|
|
36
|
+
import LightSystem from "../../../ecs/light/LightSystem.js";
|
|
37
|
+
import AnimationControllerSystem from "../../../ecs/animation/AnimationControllerSystem.js";
|
|
38
|
+
import { AnimationGraphSystem } from "../../../ecs/animation/animator/AnimationGraphSystem.js";
|
|
39
|
+
import { FogOfWarSystem } from "../../../../ecs/fow/FogOfWarSystem.js";
|
|
40
|
+
import { FogOfWarRevealerSystem } from "../../../../ecs/fow/FogOfWarRevealerSystem.js";
|
|
41
|
+
import { BehaviorSystem } from "../../../../intelligence/behavior/ecs/BehaviorSystem.js";
|
|
42
|
+
import { SerializationMetadataSystem } from "../../../../ecs/systems/SerializationMetadataSystem.js";
|
|
43
|
+
import { InverseKinematicsSystem } from "../../../../ecs/animation/InverseKinematicsSystem.js";
|
|
44
|
+
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
45
|
+
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
46
|
+
import RenderSystem from "../../../../ecs/systems/RenderSystem.js";
|
|
47
|
+
import { makeEngineOptionsModel } from "../../../../../../model/game/options/makeEngineOptionsModel.js";
|
|
48
|
+
import { enableEditor } from "../../../../../editor/enableEditor.js";
|
|
49
|
+
import EntityBuilder from "../../../../ecs/EntityBuilder.js";
|
|
50
|
+
import { Transform } from "../../../../ecs/transform/Transform.js";
|
|
51
|
+
import Mesh from "../../../ecs/mesh/Mesh.js";
|
|
52
|
+
import { PathDisplaySystem } from "../../../ecs/path/PathDisplaySystem.js";
|
|
53
|
+
import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
|
|
54
|
+
import { StandardFrameBuffers } from "../../../StandardFrameBuffers.js";
|
|
55
|
+
import { HierarchicalZBuffer } from "./buffer/HierarchicalZBuffer.js";
|
|
56
|
+
import ViewportPosition from "../../../../ecs/gui/position/ViewportPosition.js";
|
|
57
|
+
import GUIElement from "../../../../ecs/gui/GUIElement.js";
|
|
58
|
+
import { MetricCollection } from "../../../../development/performance/MetricCollection.js";
|
|
59
|
+
import { MetricStatistics } from "../../../../development/performance/MetricStatistics.js";
|
|
60
|
+
import { prettyPrint } from "../../../../../core/NumberFormat.js";
|
|
61
|
+
import { buildCanvasViewFromTexture } from "./buildCanvasViewFromTexture.js";
|
|
62
|
+
import { BatchOcclusionQuery } from "./query/BatchOcclusionQuery.js";
|
|
63
|
+
import HeadsUpDisplay from "../../../../ecs/gui/hud/HeadsUpDisplay.js";
|
|
64
|
+
import LabelView from "../../../../../view/common/LabelView.js";
|
|
65
|
+
import { randomFloatBetween } from "../../../../../core/math/MathUtils.js";
|
|
66
|
+
import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
|
|
67
|
+
import { Sampler2D } from "../../../texture/sampler/Sampler2D.js";
|
|
68
|
+
import { RefinementSpec } from "../../../micron/render/refinement/RefinementSpec.js";
|
|
69
|
+
import { Matrix4 } from "three";
|
|
70
|
+
import { inverseLerp } from "../../../../../core/math/inverseLerp.js";
|
|
71
|
+
import { clamp } from "../../../../../core/math/clamp.js";
|
|
72
|
+
import { max2 } from "../../../../../core/math/max2.js";
|
|
73
|
+
import { min2 } from "../../../../../core/math/min2.js";
|
|
74
|
+
import { buildCubeURLs } from "../../../texture/cubemap/buildCubeURLs.js";
|
|
75
|
+
|
|
76
|
+
const engineHarness = new EngineHarness();
|
|
77
|
+
|
|
78
|
+
function makeConfig(engine) {
|
|
79
|
+
|
|
80
|
+
const config = new EngineConfiguration();
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @type {SoundEngine}
|
|
85
|
+
*/
|
|
86
|
+
const sound = engine.sound;
|
|
87
|
+
const graphics = engine.graphics;
|
|
88
|
+
const assetManager = engine.assetManager;
|
|
89
|
+
const devices = engine.devices;
|
|
90
|
+
|
|
91
|
+
const guiSystem = new GUIElementSystem(engine.gui.view, engine);
|
|
92
|
+
const headsUpDisplaySystem = new HeadsUpDisplaySystem(graphics);
|
|
93
|
+
|
|
94
|
+
config.systems.push(
|
|
95
|
+
new ScriptSystem(),
|
|
96
|
+
new FacingDirectionSystem(),
|
|
97
|
+
new PathFollowingSystem(),
|
|
98
|
+
new SteeringSystem(),
|
|
99
|
+
new MotionSystem(),
|
|
100
|
+
new TagSystem(),
|
|
101
|
+
new AttachmentSocketsSystem(),
|
|
102
|
+
new AttachmentSystem(),
|
|
103
|
+
new SoundEmitterSystem(assetManager, sound.destination, sound.context),
|
|
104
|
+
new SoundControllerSystem(),
|
|
105
|
+
new SoundListenerSystem(sound.context),
|
|
106
|
+
new TimerSystem(),
|
|
107
|
+
guiSystem,
|
|
108
|
+
new AnimationSystem(graphics.viewport.size),
|
|
109
|
+
new TopDownCameraControllerSystem(graphics),
|
|
110
|
+
new TopDownCameraLanderSystem(),
|
|
111
|
+
new CameraSystem(graphics.scene, graphics),
|
|
112
|
+
new MeshSystem(engine),
|
|
113
|
+
new ClingToTerrainSystem(),
|
|
114
|
+
new TerrainSystem(graphics, assetManager),
|
|
115
|
+
new WaterSystem(graphics),
|
|
116
|
+
new Trail2DSystem(graphics, assetManager),
|
|
117
|
+
new Foliage2System(assetManager, graphics),
|
|
118
|
+
new ViewportPositionSystem(graphics.viewport.size),
|
|
119
|
+
new GridPosition2TransformSystem(),
|
|
120
|
+
new Transform2GridPositionSystem(),
|
|
121
|
+
new SynchronizePositionSystem(),
|
|
122
|
+
new GridObstacleSystem(),
|
|
123
|
+
new GridPositionSystem(),
|
|
124
|
+
new InputControllerSystem(devices),
|
|
125
|
+
new InputSystem(devices),
|
|
126
|
+
new MeshHighlightSystem(engine),
|
|
127
|
+
new LightSystem(engine, {
|
|
128
|
+
shadowResolution: 1024
|
|
129
|
+
}),
|
|
130
|
+
new AnimationControllerSystem(),
|
|
131
|
+
new AnimationGraphSystem(graphics.viewport.size),
|
|
132
|
+
headsUpDisplaySystem,
|
|
133
|
+
new FogOfWarSystem(graphics),
|
|
134
|
+
new FogOfWarRevealerSystem(0),
|
|
135
|
+
new BehaviorSystem(engine),
|
|
136
|
+
new SerializationMetadataSystem(),
|
|
137
|
+
new InverseKinematicsSystem(),
|
|
138
|
+
new PathDisplaySystem(engine),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
// Plugins
|
|
143
|
+
config.addPlugin(MicronRenderPlugin);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// Knowledge
|
|
147
|
+
|
|
148
|
+
return config;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
*
|
|
154
|
+
* @param {EngineHarness} harness
|
|
155
|
+
* @return {Promise<void>}
|
|
156
|
+
*/
|
|
157
|
+
async function init(harness) {
|
|
158
|
+
const engine = harness.engine;
|
|
159
|
+
|
|
160
|
+
engine.entityManager.addSystem(new RenderSystem(engine.graphics));
|
|
161
|
+
|
|
162
|
+
makeEngineOptionsModel(engine.options, engine);
|
|
163
|
+
|
|
164
|
+
await makeConfig(engine).apply(engine);
|
|
165
|
+
|
|
166
|
+
enableEditor(engine);
|
|
167
|
+
|
|
168
|
+
await engine.graphics.loadEnvironmentMap(buildCubeURLs('data/textures/cubemaps/hip_miramar/32/', '.png'));
|
|
169
|
+
|
|
170
|
+
await harness.initialize();
|
|
171
|
+
|
|
172
|
+
main(engine);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const metrics = new MetricCollection();
|
|
176
|
+
|
|
177
|
+
metrics.create({
|
|
178
|
+
name: 'hiz_build', buffer_size: 1000
|
|
179
|
+
});
|
|
180
|
+
metrics.create({
|
|
181
|
+
name: 'hiz_query', buffer_size: 1000
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
function print_perf_stats() {
|
|
185
|
+
|
|
186
|
+
const values = [];
|
|
187
|
+
|
|
188
|
+
const stats = new MetricStatistics();
|
|
189
|
+
metrics.list().forEach(m => {
|
|
190
|
+
const metric = metrics.get(m);
|
|
191
|
+
|
|
192
|
+
metric.computeStats(stats);
|
|
193
|
+
|
|
194
|
+
values.push(`${m}: ${prettyPrint(stats.mean)}`);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
console.log(values.join(", "));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
*
|
|
202
|
+
* @param {HierarchicalZBuffer} hiz
|
|
203
|
+
* @param {GraphicsEngine} graphics
|
|
204
|
+
* @param {EntityComponentDataset} ecd
|
|
205
|
+
*/
|
|
206
|
+
function prepare_query_test(hiz, graphics, ecd) {
|
|
207
|
+
|
|
208
|
+
const query = new BatchOcclusionQuery();
|
|
209
|
+
query.setSize(64);
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
const random = seededRandom(42);
|
|
213
|
+
|
|
214
|
+
const row_count = 8;
|
|
215
|
+
|
|
216
|
+
const entities = [];
|
|
217
|
+
const labels = [];
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
function prepare_query() {
|
|
221
|
+
|
|
222
|
+
const spec = new RefinementSpec();
|
|
223
|
+
spec.build(new Matrix4(), graphics.camera.matrixWorldInverse, graphics.camera.projectionMatrix);
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < query.getSize(); i++) {
|
|
226
|
+
const entity = entities[i];
|
|
227
|
+
|
|
228
|
+
if (entity === undefined) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @type {Mesh}
|
|
234
|
+
*/
|
|
235
|
+
const mesh = entity.getComponent(Mesh);
|
|
236
|
+
const aabb = new Float32Array(6);
|
|
237
|
+
|
|
238
|
+
mesh.bvh.writeToArray(aabb, 0);
|
|
239
|
+
|
|
240
|
+
query.setElement(i, aabb, spec.projection_matrix);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const ENTITY_COUNT = min2(query.getSize(), 100);
|
|
246
|
+
for (let i = 0; i < ENTITY_COUNT; i++) {
|
|
247
|
+
|
|
248
|
+
const ix = i % row_count;
|
|
249
|
+
const iy = Math.floor(i / row_count);
|
|
250
|
+
|
|
251
|
+
const v = new LabelView('a', { classList: ['__debug-plaque'] });
|
|
252
|
+
v.css({
|
|
253
|
+
position: 'absolute',
|
|
254
|
+
whiteSpace: 'pre',
|
|
255
|
+
left: 0,
|
|
256
|
+
top: 0
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
labels[i] = v;
|
|
260
|
+
|
|
261
|
+
const entityBuilder = new EntityBuilder();
|
|
262
|
+
|
|
263
|
+
entities[i] = entityBuilder;
|
|
264
|
+
|
|
265
|
+
const scale = randomFloatBetween(random, 0.1, 1);
|
|
266
|
+
|
|
267
|
+
entityBuilder
|
|
268
|
+
.add(Mesh.fromJSON({
|
|
269
|
+
url: 'data/models/snaps/cube_blue.gltf'
|
|
270
|
+
}))
|
|
271
|
+
.add(Transform.fromJSON({
|
|
272
|
+
position: new Vector3(102 + ix * 5, randomFloatBetween(random, -4, 3), 60 + iy * 5),
|
|
273
|
+
scale: scale
|
|
274
|
+
}))
|
|
275
|
+
.add(new HeadsUpDisplay())
|
|
276
|
+
.add(new ViewportPosition())
|
|
277
|
+
.add(GUIElement.fromView(v))
|
|
278
|
+
.build(ecd);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const rt = query.getResultTexture();
|
|
282
|
+
const result_sampler = Sampler2D.uint8(4, rt.image.width, rt.image.height);
|
|
283
|
+
|
|
284
|
+
function process_query_results() {
|
|
285
|
+
|
|
286
|
+
query.readResultTexture(renderer, result_sampler.data);
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
for (let i = 0; i < ENTITY_COUNT; i++) {
|
|
290
|
+
const value = result_sampler.readChannel(i, 0, 0);
|
|
291
|
+
|
|
292
|
+
labels[i].updateText(value);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const renderer = graphics.getRenderer();
|
|
297
|
+
|
|
298
|
+
function compute_rt_scale(v) {
|
|
299
|
+
return Math.ceil(max2(1, clamp(inverseLerp(256, 32, v), 0, 1) * 8));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const preview_query = buildCanvasViewFromTexture({
|
|
303
|
+
width: rt.image.width * compute_rt_scale(rt.image.width),
|
|
304
|
+
height: rt.image.height * compute_rt_scale(rt.image.height),
|
|
305
|
+
renderer: renderer,
|
|
306
|
+
texture: null,
|
|
307
|
+
flipY: false
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
graphics.on.postRender.add(() => {
|
|
311
|
+
prepare_query();
|
|
312
|
+
|
|
313
|
+
const t0 = performance.now();
|
|
314
|
+
query.execute(renderer, hiz);
|
|
315
|
+
const t1 = performance.now();
|
|
316
|
+
|
|
317
|
+
metrics.get('hiz_query').record(t1 - t0);
|
|
318
|
+
|
|
319
|
+
preview_query.texture = query.getResultTexture();
|
|
320
|
+
preview_query.render();
|
|
321
|
+
|
|
322
|
+
process_query_results();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
new EntityBuilder()
|
|
327
|
+
.add(ViewportPosition.fromJSON({
|
|
328
|
+
offset: new Vector2(10, 276)
|
|
329
|
+
}))
|
|
330
|
+
.add(GUIElement.fromView(preview_query.view))
|
|
331
|
+
.build(ecd);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
setInterval(print_perf_stats, 2000);
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
*
|
|
338
|
+
* @param {Engine} engine
|
|
339
|
+
*/
|
|
340
|
+
function main(engine) {
|
|
341
|
+
EngineHarness.buildBasics({
|
|
342
|
+
engine,
|
|
343
|
+
enableWater: false,
|
|
344
|
+
// enableTerrain: false,
|
|
345
|
+
enableTerrain: true,
|
|
346
|
+
terrainSize: new Vector2(100, 100),
|
|
347
|
+
focus: new Vector3(102, 0, 61),
|
|
348
|
+
// pitch: -0.5,
|
|
349
|
+
// yaw: 2.2,
|
|
350
|
+
// distance: 3
|
|
351
|
+
pitch: 0.9,
|
|
352
|
+
yaw: 3.1,
|
|
353
|
+
distance: 20
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
const graphics = engine.graphics;
|
|
358
|
+
|
|
359
|
+
graphics.renderer.setClearColor('rgba(99,99,99,1)');
|
|
360
|
+
|
|
361
|
+
const ecd = engine.entityManager.dataset;
|
|
362
|
+
//
|
|
363
|
+
// for (let i = 0; i < 10; i++) {
|
|
364
|
+
// for (let j = 0; j < 10; j++) {
|
|
365
|
+
//
|
|
366
|
+
// new EntityBuilder()
|
|
367
|
+
// .add(Transform.fromJSON({
|
|
368
|
+
// position: {
|
|
369
|
+
// x: 60 + i * 10,
|
|
370
|
+
// y: 0,
|
|
371
|
+
// z: 30 + j * 10
|
|
372
|
+
// },
|
|
373
|
+
// scale: {
|
|
374
|
+
// x: 1,
|
|
375
|
+
// y: 1,
|
|
376
|
+
// z: 1
|
|
377
|
+
// }
|
|
378
|
+
// }))
|
|
379
|
+
// .add(Mesh.fromJSON({
|
|
380
|
+
// url: 'data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf',
|
|
381
|
+
// castShadow: true,
|
|
382
|
+
// receiveShadow: true
|
|
383
|
+
// }))
|
|
384
|
+
// .build(ecd);
|
|
385
|
+
// }
|
|
386
|
+
// }
|
|
387
|
+
|
|
388
|
+
const hiz = new HierarchicalZBuffer();
|
|
389
|
+
const depthTexture = graphics.frameBuffers.getById(StandardFrameBuffers.ColorAndDepth).getRenderTarget().depthTexture;
|
|
390
|
+
hiz.input = depthTexture;
|
|
391
|
+
hiz.renderer = graphics.renderer;
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
const renderer = graphics.getRenderer();
|
|
395
|
+
|
|
396
|
+
const preview = buildCanvasViewFromTexture({
|
|
397
|
+
width: 512,
|
|
398
|
+
height: 256,
|
|
399
|
+
renderer: renderer,
|
|
400
|
+
texture: null
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
graphics.on.postRender.add(() => {
|
|
405
|
+
hiz.set_resolution(depthTexture.image.width, depthTexture.image.height);
|
|
406
|
+
hiz.build_mip_chain();
|
|
407
|
+
|
|
408
|
+
const t0 = performance.now();
|
|
409
|
+
hiz.build_mips();
|
|
410
|
+
const t1 = performance.now();
|
|
411
|
+
|
|
412
|
+
metrics.get('hiz_build').record(t1 - t0);
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
preview.texture = hiz.mips[0].texture;
|
|
416
|
+
|
|
417
|
+
preview.render();
|
|
418
|
+
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
console.log(hiz);
|
|
422
|
+
|
|
423
|
+
prepare_query_test(hiz, graphics, ecd);
|
|
424
|
+
|
|
425
|
+
new EntityBuilder()
|
|
426
|
+
.add(ViewportPosition.fromJSON({
|
|
427
|
+
offset: new Vector2(10, 10)
|
|
428
|
+
}))
|
|
429
|
+
.add(GUIElement.fromView(preview.view))
|
|
430
|
+
.build(ecd);
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
init(engineHarness);
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClampToEdgeWrapping,
|
|
3
|
+
DataTexture,
|
|
4
|
+
FloatType,
|
|
5
|
+
NearestFilter,
|
|
6
|
+
RedFormat,
|
|
7
|
+
RGBAFormat,
|
|
8
|
+
UnsignedByteType,
|
|
9
|
+
WebGLRenderTarget
|
|
10
|
+
} from "three";
|
|
11
|
+
import { array_copy } from "../../../../../../core/collection/array/copyArray.js";
|
|
12
|
+
import { makeQueryShader } from "./QueryShader.js";
|
|
13
|
+
import { renderScreenSpace } from "../../../utils/renderScreenSpace.js";
|
|
14
|
+
import { assert } from "../../../../../../core/assert.js";
|
|
15
|
+
import { max2 } from "../../../../../../core/math/max2.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Query element contains following data:
|
|
19
|
+
* [AABB( x0,y0,z0, x1,y1,z1 ) :: Float32], [MATRIX4( ... x16 ) :: Float32]
|
|
20
|
+
* @type {number}
|
|
21
|
+
* @readonly
|
|
22
|
+
*/
|
|
23
|
+
const QUERY_ELEMENT_SIZE = 22;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export class BatchOcclusionQuery {
|
|
27
|
+
constructor() {
|
|
28
|
+
const input_texture = new DataTexture(new Float32Array(1), 1, 1);
|
|
29
|
+
|
|
30
|
+
input_texture.format = RedFormat;
|
|
31
|
+
input_texture.type = FloatType;
|
|
32
|
+
input_texture.internalFormat = 'R32F';
|
|
33
|
+
input_texture.generateMipmaps = false;
|
|
34
|
+
input_texture.wrapT = ClampToEdgeWrapping;
|
|
35
|
+
input_texture.wrapS = ClampToEdgeWrapping;
|
|
36
|
+
input_texture.minFilter = NearestFilter;
|
|
37
|
+
input_texture.magFilter = NearestFilter;
|
|
38
|
+
|
|
39
|
+
this.__input_data_texture = input_texture;
|
|
40
|
+
|
|
41
|
+
this.__output_data_texture = new WebGLRenderTarget(1, 1, {
|
|
42
|
+
minFilter: NearestFilter,
|
|
43
|
+
magFilter: NearestFilter,
|
|
44
|
+
format: RGBAFormat,
|
|
45
|
+
type: UnsignedByteType,
|
|
46
|
+
// internalFormat: 'R8',
|
|
47
|
+
depthBuffer: false,
|
|
48
|
+
stencilBuffer: false,
|
|
49
|
+
wrapS: ClampToEdgeWrapping,
|
|
50
|
+
wrapT: ClampToEdgeWrapping,
|
|
51
|
+
generateMipmaps: false
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
this.__size = -1;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @type {ShaderMaterial}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
this.__material = makeQueryShader();
|
|
62
|
+
this.__material.defines.ITEM_SIZE = QUERY_ELEMENT_SIZE;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @return {THREE.Texture}
|
|
68
|
+
*/
|
|
69
|
+
getResultTexture() {
|
|
70
|
+
return this.__output_data_texture.texture;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @return {number}
|
|
76
|
+
*/
|
|
77
|
+
getSize() {
|
|
78
|
+
return this.__size;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @param {number} count
|
|
84
|
+
*/
|
|
85
|
+
setSize(count) {
|
|
86
|
+
if (this.__size === count) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.__size = count;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* How many query elements are packed per texture row
|
|
94
|
+
* @type {number}
|
|
95
|
+
* @readonly
|
|
96
|
+
*/
|
|
97
|
+
const TEXTURE_COLUMN_COUNT = max2(
|
|
98
|
+
Math.ceil(Math.sqrt(count)),
|
|
99
|
+
4
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const input_texture = this.__input_data_texture;
|
|
103
|
+
|
|
104
|
+
input_texture.dispose();
|
|
105
|
+
|
|
106
|
+
const row_count = Math.ceil(count / TEXTURE_COLUMN_COUNT);
|
|
107
|
+
|
|
108
|
+
const input_image = input_texture.image;
|
|
109
|
+
|
|
110
|
+
input_image.width = TEXTURE_COLUMN_COUNT * QUERY_ELEMENT_SIZE;
|
|
111
|
+
input_image.height = row_count;
|
|
112
|
+
input_image.data = new Float32Array(input_image.width * input_image.height);
|
|
113
|
+
|
|
114
|
+
this.__output_data_texture.setSize(TEXTURE_COLUMN_COUNT, row_count);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* @param {number} index
|
|
120
|
+
* @param {number[]|Float32Array} aabb bounding box of the queries region
|
|
121
|
+
* @param {number[]} transform 4x4 transform matrix
|
|
122
|
+
*/
|
|
123
|
+
setElement(index, aabb, transform) {
|
|
124
|
+
assert.lessThan(index, this.__size, 'index overflow');
|
|
125
|
+
assert.isNonNegativeInteger(index, 'index');
|
|
126
|
+
|
|
127
|
+
// write query element
|
|
128
|
+
const address = index * QUERY_ELEMENT_SIZE;
|
|
129
|
+
|
|
130
|
+
const input_texture = this.__input_data_texture;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
*
|
|
134
|
+
* @type {Uint8ClampedArray}
|
|
135
|
+
*/
|
|
136
|
+
const data = input_texture.image.data;
|
|
137
|
+
|
|
138
|
+
array_copy(aabb, 0, data, address, 6);
|
|
139
|
+
array_copy(transform, 0, data, address + 6, 16);
|
|
140
|
+
|
|
141
|
+
input_texture.needsUpdate = true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
*
|
|
146
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
147
|
+
* @param {Uint8Array} destination
|
|
148
|
+
*/
|
|
149
|
+
readResultTexture(renderer, destination) {
|
|
150
|
+
const rt = this.__output_data_texture;
|
|
151
|
+
|
|
152
|
+
renderer.readRenderTargetPixels(rt, 0, 0, rt.width, rt.height, destination);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
*
|
|
157
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
158
|
+
* @param {HierarchicalZBuffer} hiz_buffer
|
|
159
|
+
*/
|
|
160
|
+
execute(renderer, hiz_buffer) {
|
|
161
|
+
const uniforms = this.__material.uniforms;
|
|
162
|
+
|
|
163
|
+
uniforms.utDepth.value = hiz_buffer.getTexture();
|
|
164
|
+
uniforms.utInput.value = this.__input_data_texture;
|
|
165
|
+
uniforms.uDepthMipLimits.value.set(hiz_buffer.mip_limits.x, hiz_buffer.mip_limits.y);
|
|
166
|
+
|
|
167
|
+
const __rt = renderer.getRenderTarget();
|
|
168
|
+
renderer.setRenderTarget(this.__output_data_texture);
|
|
169
|
+
|
|
170
|
+
renderScreenSpace(renderer, this.__material);
|
|
171
|
+
|
|
172
|
+
renderer.setRenderTarget(__rt);
|
|
173
|
+
}
|
|
174
|
+
}
|