@woosh/meep-engine 2.64.0 → 2.66.0
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 +33388 -34714
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +33388 -34714
- package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +4 -10
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +7 -7
- package/editor/tools/SelectionTool.js +6 -95
- package/package.json +1 -1
- package/src/core/bvh2/BinaryNode.js +14 -14
- package/src/core/bvh2/LeafNode.js +4 -4
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +118 -113
- package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +98 -0
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.d.ts → BVH.d.ts} +1 -1
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.js → BVH.js} +2 -2
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.spec.js → BVH.spec.js} +20 -20
- package/src/core/bvh2/bvh3/BvhClient.d.ts +11 -0
- package/src/core/bvh2/bvh3/{EBBVHLeafProxy.js → BvhClient.js} +22 -3
- package/src/core/bvh2/bvh3/BvhClient.spec.js +51 -0
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.js +2 -2
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +4 -4
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +3 -3
- package/src/core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js +2 -8
- package/src/core/bvh2/bvh3/query/BVHQuery.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +3 -8
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +3 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.spec.js +3 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +3 -3
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +4 -4
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.spec.js +3 -3
- package/src/core/collection/array/array_copy.js +6 -0
- package/src/core/geom/3d/aabb/aabb3_array_combine.js +17 -8
- package/src/core/geom/3d/aabb/aabb3_array_intersects_ray.js +5 -2
- package/src/core/geom/3d/aabb/aabb3_array_set.js +25 -0
- package/src/core/geom/3d/aabb/aabb3_compute_half_surface_area.js +3 -0
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +8 -1
- package/src/engine/EngineHarness.js +23 -25
- package/src/engine/ecs/renderable/RenderSystem.js +44 -32
- package/src/engine/ecs/renderable/Renderable.d.ts +2 -2
- package/src/engine/ecs/renderable/Renderable.js +12 -11
- package/src/engine/ecs/terrain/ecs/Terrain.js +83 -87
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +106 -57
- package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +5 -2
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +122 -67
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +162 -146
- package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +16 -5
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +3 -6
- package/src/engine/graphics/debug/VisualSymbolLine.js +1 -0
- package/src/engine/graphics/ecs/camera/CameraSystem.js +9 -9
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +3 -23
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +22 -24
- package/src/engine/graphics/ecs/light/LightSystem.js +12 -48
- package/src/engine/graphics/ecs/mesh/Mesh.js +8 -8
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +12 -36
- package/src/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +3 -43
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +6 -6
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +3 -3
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +16 -18
- package/src/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +5 -5
- package/src/engine/graphics/ecs/trail2d/Trail2D.js +105 -106
- package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +60 -61
- package/src/engine/graphics/ecs/trail2d/makeGradientTrail.js +3 -3
- package/src/engine/graphics/ecs/water/WATER_SIZE.js +1 -0
- package/src/engine/graphics/ecs/water/Water.js +84 -42
- package/src/engine/graphics/ecs/water/WaterSystem.js +53 -105
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +13 -7
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +58 -0
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +32 -62
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +9 -11
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +4 -4
- package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +8 -11
- package/src/engine/graphics/render/forward_plus/LightManager.js +30 -32
- package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +3 -3
- package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +21 -19
- package/src/engine/graphics/render/layers/RenderLayer.d.ts +8 -2
- package/src/engine/graphics/render/layers/RenderLayer.js +7 -65
- package/src/engine/graphics/render/make_bvh_visibility_builder.js +64 -0
- package/src/engine/graphics/sh3/LightProbeVolume.js +19 -19
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +4 -6
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +17 -19
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +4 -4
- package/src/engine/graphics/trail/x/RibbonX.js +26 -5
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +18 -16
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +3 -5
- package/src/core/bvh2/binary/tiny/TinyBVH.js +0 -221
- package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +0 -138
|
@@ -1,32 +1,96 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by Alex on 21/05/2016.
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
5
|
-
import Vector2 from '../../../../core/geom/Vector2.js';
|
|
6
|
-
import Signal from '../../../../core/events/signal/Signal.js';
|
|
7
|
-
import TerrainTile from './TerrainTile.js';
|
|
8
|
-
|
|
9
|
-
import { BinaryNode } from '../../../../core/bvh2/BinaryNode.js';
|
|
10
|
-
|
|
11
|
-
import CheckersTexture from '../../../graphics/texture/CheckersTexture.js';
|
|
4
|
+
import { mat4, vec3 } from "gl-matrix";
|
|
12
5
|
|
|
13
6
|
|
|
14
7
|
import { MeshPhongMaterial } from 'three';
|
|
15
8
|
import { assert } from "../../../../core/assert.js";
|
|
9
|
+
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
10
|
+
import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
|
|
11
|
+
import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
|
|
16
12
|
import { Color } from "../../../../core/color/Color.js";
|
|
13
|
+
import Signal from '../../../../core/events/signal/Signal.js';
|
|
17
14
|
import { noop } from "../../../../core/function/Functions.js";
|
|
15
|
+
import { aabb2_overlap_exists } from "../../../../core/geom/2d/aabb/aabb2_overlap_exists.js";
|
|
18
16
|
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
19
|
-
import
|
|
20
|
-
import { FirstRayIntersectionTerrainBVHVisitor } from "./FirstRayIntersectionTerrainBVHVisitor.js";
|
|
21
|
-
import { traverseBinaryNodeUsingVisitor } from "../../../../core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js";
|
|
22
|
-
import ObservedInteger from "../../../../core/model/ObservedInteger.js";
|
|
17
|
+
import Vector2 from '../../../../core/geom/Vector2.js';
|
|
23
18
|
import { NumericInterval } from "../../../../core/math/interval/NumericInterval.js";
|
|
24
19
|
import { randomFloatBetween } from "../../../../core/math/random/randomFloatBetween.js";
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
|
|
20
|
+
import ObservedInteger from "../../../../core/model/ObservedInteger.js";
|
|
21
|
+
import ObservedValue from '../../../../core/model/ObservedValue.js';
|
|
22
|
+
|
|
23
|
+
import CheckersTexture from '../../../graphics/texture/CheckersTexture.js';
|
|
24
|
+
import TerrainTile from './TerrainTile.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @type {number[]}
|
|
29
|
+
*/
|
|
30
|
+
const scratch_array = [];
|
|
31
|
+
const scratch_contact = new SurfacePoint3();
|
|
28
32
|
|
|
29
33
|
class TerrainTileManager {
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @type {TerrainTile[]}
|
|
37
|
+
*/
|
|
38
|
+
tiles = [];
|
|
39
|
+
|
|
40
|
+
on = {
|
|
41
|
+
tileBuilt: new Signal(),
|
|
42
|
+
tileDestroyed: new Signal()
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {Vector2}
|
|
48
|
+
*/
|
|
49
|
+
tileSize = new Vector2(10, 10);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @type {Vector2}
|
|
54
|
+
*/
|
|
55
|
+
totalSize = new Vector2(1, 1);
|
|
56
|
+
/**
|
|
57
|
+
* Number of subdivisions per single grid cell
|
|
58
|
+
* @type {ObservedInteger}
|
|
59
|
+
*/
|
|
60
|
+
resolution = new ObservedInteger(4);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 2D Scale of the terrain
|
|
64
|
+
* @type {Vector2}
|
|
65
|
+
*/
|
|
66
|
+
scale = new Vector2(1, 1);
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @type {Float32Array}
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
__transform = new Float32Array(16);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @readonly
|
|
78
|
+
* @type {BVH}
|
|
79
|
+
*/
|
|
80
|
+
bvh = new BVH();
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @type {NumericInterval}
|
|
85
|
+
*/
|
|
86
|
+
heightRange = new NumericInterval(0, 0);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Debug parameter, makes all tiles have random colored material for easy visual distinction
|
|
90
|
+
* @type {boolean}
|
|
91
|
+
*/
|
|
92
|
+
debugTileMaterialRandom = false;
|
|
93
|
+
|
|
30
94
|
/**
|
|
31
95
|
*
|
|
32
96
|
* @param {Vector2} [tileSize]
|
|
@@ -40,28 +104,6 @@ class TerrainTileManager {
|
|
|
40
104
|
}
|
|
41
105
|
) {
|
|
42
106
|
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
* @type {TerrainTile[]}
|
|
46
|
-
*/
|
|
47
|
-
this.tiles = [];
|
|
48
|
-
|
|
49
|
-
this.on = {
|
|
50
|
-
tileBuilt: new Signal(),
|
|
51
|
-
tileDestroyed: new Signal()
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @type {Vector2}
|
|
57
|
-
*/
|
|
58
|
-
this.tileSize = new Vector2(10, 10);
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @type {Vector2}
|
|
63
|
-
*/
|
|
64
|
-
this.totalSize = new Vector2(1, 1);
|
|
65
107
|
|
|
66
108
|
if (material === undefined) {
|
|
67
109
|
const defaultMaterialTexture = CheckersTexture.create(this.totalSize.clone()._sub(1, 1).multiplyScalar(0.5));
|
|
@@ -70,17 +112,6 @@ class TerrainTileManager {
|
|
|
70
112
|
|
|
71
113
|
this.material = new ObservedValue(material);
|
|
72
114
|
|
|
73
|
-
/**
|
|
74
|
-
* Number of subdivisions per single grid cell
|
|
75
|
-
* @type {ObservedInteger}
|
|
76
|
-
*/
|
|
77
|
-
this.resolution = new ObservedInteger(4);
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 2D Scale of the terrain
|
|
81
|
-
* @type {Vector2}
|
|
82
|
-
*/
|
|
83
|
-
this.scale = new Vector2(1, 1);
|
|
84
115
|
|
|
85
116
|
/**
|
|
86
117
|
*
|
|
@@ -88,31 +119,10 @@ class TerrainTileManager {
|
|
|
88
119
|
*/
|
|
89
120
|
this.buildWorker = buildWorker;
|
|
90
121
|
|
|
91
|
-
this.bvh = new BinaryNode();
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @type {NumericInterval}
|
|
96
|
-
*/
|
|
97
|
-
this.heightRange = new NumericInterval(0, 0);
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Debug parameter, makes all tiles have random colored material for easy visual distinction
|
|
101
|
-
* @type {boolean}
|
|
102
|
-
*/
|
|
103
|
-
this.debugTileMaterialRandom = false;
|
|
104
|
-
|
|
105
122
|
this.material.onChanged.add(() => {
|
|
106
123
|
this.traverse(this.assignTileMaterial, this);
|
|
107
124
|
});
|
|
108
125
|
|
|
109
|
-
/**
|
|
110
|
-
*
|
|
111
|
-
* @type {Float32Array}
|
|
112
|
-
* @private
|
|
113
|
-
*/
|
|
114
|
-
this.__transform = new Float32Array(16);
|
|
115
|
-
|
|
116
126
|
}
|
|
117
127
|
|
|
118
128
|
set transform(m4) {
|
|
@@ -155,17 +165,12 @@ class TerrainTileManager {
|
|
|
155
165
|
|
|
156
166
|
if (!terrainTile.isBuilt && !terrainTile.isBuildInProgress) {
|
|
157
167
|
|
|
158
|
-
const bb = terrainTile.
|
|
168
|
+
const bb = terrainTile.external_bvh;
|
|
159
169
|
|
|
160
|
-
bb.
|
|
161
|
-
|
|
162
|
-
min_height,
|
|
163
|
-
bb.z0,
|
|
170
|
+
bb.bounds[1] = min_height;
|
|
171
|
+
bb.bounds[4] = max_height;
|
|
164
172
|
|
|
165
|
-
|
|
166
|
-
max_height,
|
|
167
|
-
bb.z1
|
|
168
|
-
);
|
|
173
|
+
bb.write_bounds();
|
|
169
174
|
|
|
170
175
|
}
|
|
171
176
|
|
|
@@ -175,8 +180,6 @@ class TerrainTileManager {
|
|
|
175
180
|
initialize() {
|
|
176
181
|
this.destroyTiles();
|
|
177
182
|
|
|
178
|
-
this.bvh.setNegativelyInfiniteBounds();
|
|
179
|
-
|
|
180
183
|
this.initializeTiles();
|
|
181
184
|
}
|
|
182
185
|
|
|
@@ -224,6 +227,7 @@ class TerrainTileManager {
|
|
|
224
227
|
for (let i = 0; i < tile_count; i++) {
|
|
225
228
|
const tile = tiles[i];
|
|
226
229
|
|
|
230
|
+
tile.external_bvh.unlink();
|
|
227
231
|
tile.dispose();
|
|
228
232
|
|
|
229
233
|
}
|
|
@@ -231,8 +235,7 @@ class TerrainTileManager {
|
|
|
231
235
|
tiles.splice(0, tile_count);
|
|
232
236
|
|
|
233
237
|
//clear out BVH
|
|
234
|
-
this.bvh.
|
|
235
|
-
this.bvh.left = null;
|
|
238
|
+
this.bvh.release_all();
|
|
236
239
|
|
|
237
240
|
}
|
|
238
241
|
|
|
@@ -252,19 +255,27 @@ class TerrainTileManager {
|
|
|
252
255
|
* @param {number} u1
|
|
253
256
|
* @param {number} v1
|
|
254
257
|
*/
|
|
255
|
-
rebuildTilesByUV(
|
|
258
|
+
rebuildTilesByUV(
|
|
259
|
+
u0, v0,
|
|
260
|
+
u1, v1
|
|
261
|
+
) {
|
|
262
|
+
|
|
263
|
+
const size = this.totalSize;
|
|
256
264
|
|
|
257
|
-
const tx0 = u0 *
|
|
258
|
-
const tx1 = u1 *
|
|
265
|
+
const tx0 = u0 * size.x;
|
|
266
|
+
const tx1 = u1 * size.x;
|
|
259
267
|
|
|
260
|
-
const ty0 = v0 *
|
|
261
|
-
const ty1 = v1 *
|
|
268
|
+
const ty0 = v0 * size.y;
|
|
269
|
+
const ty1 = v1 * size.y;
|
|
262
270
|
|
|
263
|
-
const
|
|
271
|
+
const dirty_tiles = this.getRawTilesOverlappingRectangle(tx0 - 1, ty0 - 1, tx1 + 1, ty1 + 1);
|
|
264
272
|
|
|
265
|
-
|
|
273
|
+
const dirty_count = dirty_tiles.length;
|
|
274
|
+
|
|
275
|
+
for (let i = 0; i < dirty_count; i++) {
|
|
276
|
+
const tile = dirty_tiles[i];
|
|
266
277
|
tile.isBuilt = false;
|
|
267
|
-
}
|
|
278
|
+
}
|
|
268
279
|
}
|
|
269
280
|
|
|
270
281
|
|
|
@@ -310,11 +321,14 @@ class TerrainTileManager {
|
|
|
310
321
|
|
|
311
322
|
initializeTiles() {
|
|
312
323
|
|
|
313
|
-
const
|
|
314
|
-
gridSize.divide(this.tileSize);
|
|
315
|
-
gridSize.ceil();
|
|
324
|
+
const total_size = this.totalSize;
|
|
316
325
|
|
|
317
|
-
const
|
|
326
|
+
const gridSize = total_size.clone();
|
|
327
|
+
|
|
328
|
+
const time_size = this.tileSize;
|
|
329
|
+
|
|
330
|
+
gridSize.divide(time_size);
|
|
331
|
+
gridSize.ceil();
|
|
318
332
|
|
|
319
333
|
const tiles = this.tiles;
|
|
320
334
|
|
|
@@ -328,19 +342,23 @@ class TerrainTileManager {
|
|
|
328
342
|
|
|
329
343
|
//populate tiles
|
|
330
344
|
for (let y = 0; y < gridSize.y; y++) {
|
|
331
|
-
|
|
345
|
+
|
|
346
|
+
const tY = y < gridSize.y - 1 ? time_size.y : (total_size.y - time_size.y * y);
|
|
347
|
+
|
|
332
348
|
for (let x = 0; x < gridSize.x; x++) {
|
|
333
|
-
|
|
349
|
+
|
|
350
|
+
const tX = x < gridSize.x - 1 ? time_size.x : (total_size.x - time_size.x * x);
|
|
334
351
|
|
|
335
352
|
const tile = new TerrainTile();
|
|
336
|
-
|
|
353
|
+
const index = y * gridSize.x + x;
|
|
354
|
+
tiles[index] = tile;
|
|
337
355
|
|
|
338
356
|
this.assignTileMaterial(tile);
|
|
339
357
|
|
|
340
358
|
tile.gridPosition.set(x, y);
|
|
341
359
|
|
|
342
360
|
tile.size.set(tX, tY);
|
|
343
|
-
tile.position.set(
|
|
361
|
+
tile.position.set(time_size.x * x, time_size.y * y);
|
|
344
362
|
tile.scale.copy(this.scale);
|
|
345
363
|
tile.resolution.copy(this.resolution);
|
|
346
364
|
|
|
@@ -349,12 +367,11 @@ class TerrainTileManager {
|
|
|
349
367
|
|
|
350
368
|
//hook for building
|
|
351
369
|
tile.ensureBuilt = ensureBuilt(x, y);
|
|
370
|
+
|
|
371
|
+
tile.external_bvh.link(this.bvh, index);
|
|
352
372
|
}
|
|
353
373
|
}
|
|
354
374
|
|
|
355
|
-
this.bvh.insertManyBoxes2(function (index) {
|
|
356
|
-
return tiles[index].boundingBox;
|
|
357
|
-
}, tileCount);
|
|
358
375
|
}
|
|
359
376
|
|
|
360
377
|
/**
|
|
@@ -395,9 +412,7 @@ class TerrainTileManager {
|
|
|
395
412
|
assert.ok(tileIndex >= 0, `tileIndex(=${tileIndex}) must be >= 0`);
|
|
396
413
|
assert.ok(tileIndex <= this.tiles.length, `tileIndex(=${tileIndex}) must be <= tileCount(=${this.tiles.length})`);
|
|
397
414
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return tile;
|
|
415
|
+
return this.tiles[tileIndex];
|
|
401
416
|
}
|
|
402
417
|
|
|
403
418
|
/**
|
|
@@ -456,22 +471,6 @@ class TerrainTileManager {
|
|
|
456
471
|
return this.obtain(tile.gridPosition.x, tile.gridPosition.y);
|
|
457
472
|
}
|
|
458
473
|
|
|
459
|
-
/**
|
|
460
|
-
* @deprecated use {@link #obtain instead}
|
|
461
|
-
* @param {number} x
|
|
462
|
-
* @param {number} y
|
|
463
|
-
* @param {function(TerrainTile):*} callback
|
|
464
|
-
*/
|
|
465
|
-
processTile(x, y, callback) {
|
|
466
|
-
const tile = this.getRaw(x, y);
|
|
467
|
-
|
|
468
|
-
if (tile.isBuilt) {
|
|
469
|
-
callback(tile);
|
|
470
|
-
} else {
|
|
471
|
-
tile.onBuilt.addOne(callback);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
474
|
/**
|
|
476
475
|
*
|
|
477
476
|
* @param {number} x coordinate
|
|
@@ -601,26 +600,49 @@ class TerrainTileManager {
|
|
|
601
600
|
directionZ
|
|
602
601
|
) {
|
|
603
602
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
603
|
+
const hit_count = bvh_query_leaves_ray(
|
|
604
|
+
this.bvh,
|
|
605
|
+
this.bvh.root,
|
|
606
|
+
scratch_array, 0,
|
|
607
|
+
originX, originY, originZ,
|
|
608
|
+
directionX, directionY, directionZ
|
|
609
|
+
);
|
|
610
|
+
|
|
611
|
+
let closest_hit_distance = Number.POSITIVE_INFINITY;
|
|
612
|
+
let hit_found = false;
|
|
613
|
+
|
|
614
|
+
for (let i = 0; i < hit_count; i++) {
|
|
615
|
+
const node_id = scratch_array[i];
|
|
616
|
+
|
|
617
|
+
const tile_index = this.bvh.node_get_user_data(node_id);
|
|
618
|
+
|
|
619
|
+
const tile = this.tiles[tile_index];
|
|
608
620
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
621
|
+
if(!tile.isBuilt){
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const tile_hit_found = tile.raycastFirstSync(
|
|
626
|
+
scratch_contact,
|
|
627
|
+
originX, originY, originZ,
|
|
628
|
+
directionX, directionY, directionZ
|
|
629
|
+
);
|
|
612
630
|
|
|
613
|
-
|
|
631
|
+
if (!tile_hit_found) {
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
614
634
|
|
|
615
|
-
|
|
635
|
+
hit_found = true;
|
|
616
636
|
|
|
617
|
-
|
|
618
|
-
result.copy(firstRayIntersectionTerrainBVHVisitor.closest);
|
|
637
|
+
const distance_sqr = scratch_contact.position._distanceSqrTo(originX, originY, originZ);
|
|
619
638
|
|
|
620
|
-
|
|
639
|
+
if (distance_sqr < closest_hit_distance) {
|
|
640
|
+
closest_hit_distance = distance_sqr;
|
|
641
|
+
result.copy(scratch_contact);
|
|
642
|
+
}
|
|
621
643
|
}
|
|
622
644
|
|
|
623
|
-
return
|
|
645
|
+
return hit_found;
|
|
624
646
|
}
|
|
625
647
|
|
|
626
648
|
/**
|
|
@@ -649,10 +671,6 @@ class TerrainTileManager {
|
|
|
649
671
|
assert.typeOf(resolve, 'function', 'resolve');
|
|
650
672
|
assert.typeOf(reject, 'function', 'reject');
|
|
651
673
|
|
|
652
|
-
const processName = 'building tile x = ' + x + ", y = " + y;
|
|
653
|
-
const self = this;
|
|
654
|
-
|
|
655
|
-
|
|
656
674
|
const tileIndex = this.computeTileIndex(x, y);
|
|
657
675
|
const tile = this.tiles[tileIndex];
|
|
658
676
|
|
|
@@ -665,12 +683,12 @@ class TerrainTileManager {
|
|
|
665
683
|
tile.position.toJSON(),
|
|
666
684
|
tile.size.toJSON(),
|
|
667
685
|
tile.scale.toJSON(),
|
|
668
|
-
|
|
686
|
+
this.totalSize.toJSON(),
|
|
669
687
|
tile_resolution
|
|
670
|
-
).then(
|
|
688
|
+
).then((tileData) => {
|
|
671
689
|
|
|
672
690
|
//check that the tile under index is still the same tile
|
|
673
|
-
if (
|
|
691
|
+
if (this.tiles[tileIndex] !== tile) {
|
|
674
692
|
//the original tile was destroyed
|
|
675
693
|
reject('Original tile was destroyed during build process');
|
|
676
694
|
return;
|
|
@@ -681,16 +699,17 @@ class TerrainTileManager {
|
|
|
681
699
|
return;
|
|
682
700
|
}
|
|
683
701
|
|
|
702
|
+
// const processName = 'building tile x = ' + x + ", y = " + y;
|
|
684
703
|
// console.time(processName);
|
|
685
704
|
|
|
686
705
|
tile.build(tileData);
|
|
687
706
|
|
|
688
707
|
assert.equal(tile.resolution.getValue(), tile_resolution, 'tile resolution has changed');
|
|
689
708
|
|
|
690
|
-
|
|
709
|
+
this.stitchTile(x, y, tile);
|
|
691
710
|
|
|
692
711
|
//refit the bvh
|
|
693
|
-
tile.
|
|
712
|
+
tile.external_bvh.write_bounds();
|
|
694
713
|
|
|
695
714
|
tile.isBuilt = true;
|
|
696
715
|
tile.isBuildInProgress = false;
|
|
@@ -700,13 +719,10 @@ class TerrainTileManager {
|
|
|
700
719
|
|
|
701
720
|
// console.timeEnd(processName);
|
|
702
721
|
|
|
703
|
-
|
|
722
|
+
this.on.tileBuilt.send1(tile);
|
|
704
723
|
}, reject);
|
|
705
724
|
}
|
|
706
725
|
}
|
|
707
726
|
|
|
708
|
-
const raycastBVHVisitor = new RaycastBVHVisitor();
|
|
709
|
-
const firstRayIntersectionTerrainBVHVisitor = new FirstRayIntersectionTerrainBVHVisitor();
|
|
710
|
-
|
|
711
727
|
export default TerrainTileManager;
|
|
712
728
|
|
|
@@ -2,16 +2,27 @@
|
|
|
2
2
|
* Created by Alex on 29/05/2016.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { BinaryUint32BVH } from "../../../../core/bvh2/binary/2/BinaryUint32BVH.js";
|
|
6
|
+
import { bvh32_from_indexed_geometry } from "../../../graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js";
|
|
6
7
|
import { Sampler2D } from '../../../graphics/texture/sampler/Sampler2D.js';
|
|
8
|
+
import { sampler2d_channel_compute_max } from "../../../graphics/texture/sampler/sampler2d_channel_compute_max.js";
|
|
9
|
+
import { sampler2d_channel_compute_min } from "../../../graphics/texture/sampler/sampler2d_channel_compute_min.js";
|
|
7
10
|
import BufferedGeometryArraysBuilder from '../BufferedGeometryArraysBuilder.js';
|
|
8
11
|
import { tensionOptimizeUV } from "../util/tensionOptimizeUV.js";
|
|
9
|
-
import { sampler2d_channel_compute_min } from "../../../graphics/texture/sampler/sampler2d_channel_compute_min.js";
|
|
10
|
-
import { sampler2d_channel_compute_max } from "../../../graphics/texture/sampler/sampler2d_channel_compute_max.js";
|
|
11
|
-
|
|
12
12
|
|
|
13
13
|
self.Lib = {
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {Float32Array} vertices
|
|
17
|
+
* @param {Uint32Array} indices
|
|
18
|
+
* @returns {BinaryUint32BVH}
|
|
19
|
+
*/
|
|
20
|
+
build_bvh(vertices, indices) {
|
|
21
|
+
const bvh = new BinaryUint32BVH();
|
|
22
|
+
bvh32_from_indexed_geometry(bvh, vertices, indices);
|
|
23
|
+
|
|
24
|
+
return bvh;
|
|
25
|
+
},
|
|
15
26
|
Sampler2D,
|
|
16
27
|
BufferedGeometryArraysBuilder,
|
|
17
28
|
tensionOptimizeUV,
|
|
@@ -2,9 +2,6 @@ import { Frustum, OrthographicCamera } from "three";
|
|
|
2
2
|
import FacingDirectionSystem from "../../../../../model/game/ecs/system/FacingDirectionSystem.js";
|
|
3
3
|
import { makeEngineOptionsModel } from "../../../../../model/game/options/makeEngineOptionsModel.js";
|
|
4
4
|
import { enableEditor } from "../../../../editor/enableEditor.js";
|
|
5
|
-
import {
|
|
6
|
-
ThreeClippingPlaneComputingBVHVisitor
|
|
7
|
-
} from "../../../core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js";
|
|
8
5
|
import { RingBuffer } from "../../../core/collection/RingBuffer.js";
|
|
9
6
|
import { convex_hull_jarvis_2d } from "../../../core/geom/2d/convex-hull/convex_hull_jarvis_2d.js";
|
|
10
7
|
import Vector2 from "../../../core/geom/Vector2.js";
|
|
@@ -20,9 +17,9 @@ import HeadsUpDisplaySystem from "../../ecs/gui/hud/HeadsUpDisplaySystem.js";
|
|
|
20
17
|
import ViewportPosition from "../../ecs/gui/position/ViewportPosition.js";
|
|
21
18
|
import ViewportPositionSystem from "../../ecs/gui/position/ViewportPositionSystem.js";
|
|
22
19
|
import { InverseKinematicsSystem } from "../../ecs/ik/InverseKinematicsSystem.js";
|
|
20
|
+
import RenderSystem from "../../ecs/renderable/RenderSystem.js";
|
|
23
21
|
import AnimationSystem from "../../ecs/systems/AnimationSystem.js";
|
|
24
22
|
import MotionSystem from "../../ecs/systems/MotionSystem.js";
|
|
25
|
-
import RenderSystem from "../../ecs/systems/RenderSystem.js";
|
|
26
23
|
import ScriptSystem from "../../ecs/systems/ScriptSystem.js";
|
|
27
24
|
import SteeringSystem from "../../ecs/systems/SteeringSystem.js";
|
|
28
25
|
import TagSystem from "../../ecs/systems/TagSystem.js";
|
|
@@ -292,7 +289,7 @@ function makeCameraClippingDebug(engine) {
|
|
|
292
289
|
const buffer = new RingBuffer(100);
|
|
293
290
|
|
|
294
291
|
engine.graphics.on.postRender.add(() => {
|
|
295
|
-
buffer.push(ThreeClippingPlaneComputingBVHVisitor.VISIT_COUNT_LEAF);
|
|
292
|
+
// buffer.push(ThreeClippingPlaneComputingBVHVisitor.VISIT_COUNT_LEAF);
|
|
296
293
|
|
|
297
294
|
ctx.clearRect(0, 0, canvasView.size.x, canvasView.size.y);
|
|
298
295
|
|
|
@@ -327,7 +324,7 @@ function makeCameraClippingDebug(engine) {
|
|
|
327
324
|
|
|
328
325
|
special_hits_2.splice(0, special_hits_2.length);
|
|
329
326
|
|
|
330
|
-
ThreeClippingPlaneComputingBVHVisitor.VISIT_COUNT_LEAF = 0;
|
|
327
|
+
// ThreeClippingPlaneComputingBVHVisitor.VISIT_COUNT_LEAF = 0;
|
|
331
328
|
});
|
|
332
329
|
|
|
333
330
|
setInterval(() => {
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { System } from '../../../ecs/System.js';
|
|
7
|
-
import { Camera } from './Camera.js';
|
|
8
|
-
import { Transform } from '../../../ecs/transform/Transform.js';
|
|
9
6
|
import { Frustum as ThreeFrustum, } from 'three';
|
|
10
7
|
import { assert } from "../../../../core/assert.js";
|
|
11
8
|
import { SignalBinding } from "../../../../core/events/signal/SignalBinding.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
9
|
+
import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
|
|
10
|
+
import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
|
|
11
|
+
import { System } from '../../../ecs/System.js';
|
|
12
|
+
import { Transform } from '../../../ecs/transform/Transform.js';
|
|
15
13
|
import { auto_set_camera_clipping_planes } from "./auto_set_camera_clipping_planes.js";
|
|
14
|
+
import { build_three_camera_object } from "./build_three_camera_object.js";
|
|
15
|
+
import { Camera } from './Camera.js';
|
|
16
16
|
import { frustum_from_camera } from "./frustum_from_camera.js";
|
|
17
17
|
import { invertQuaternionOrientation } from "./InvertQuaternionOrientation.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import { set_camera_aspect_ratio } from "./set_camera_aspect_ratio.js";
|
|
19
|
+
import { update_camera_transform } from "./update_camera_transform.js";
|
|
20
20
|
|
|
21
21
|
export class CameraSystem extends System {
|
|
22
22
|
/**
|
|
@@ -32,7 +32,7 @@ export class CameraSystem extends System {
|
|
|
32
32
|
this.dependencies = [Camera, Transform];
|
|
33
33
|
|
|
34
34
|
this.components_used = [
|
|
35
|
-
ResourceAccessSpecification.from(Camera,ResourceAccessKind.Write)
|
|
35
|
+
ResourceAccessSpecification.from(Camera, ResourceAccessKind.Write)
|
|
36
36
|
];
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
import { CameraClippingPlaneComputer } from "./CameraClippingPlaneComputer.js";
|
|
2
|
-
|
|
3
|
-
const cameraClippingPlaneComputer = new CameraClippingPlaneComputer();
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
*
|
|
7
3
|
* @param {Camera} c
|
|
8
4
|
* @param {RenderLayerManager} layers
|
|
9
5
|
*/
|
|
10
6
|
export function auto_set_camera_clipping_planes(c, layers) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @type {number}
|
|
16
|
-
*/
|
|
17
|
-
const hysteresis = c.autoClipHysteresis;
|
|
18
|
-
|
|
19
|
-
cameraClippingPlaneComputer.hysteresis = hysteresis;
|
|
20
|
-
cameraClippingPlaneComputer.camera = camera;
|
|
21
|
-
cameraClippingPlaneComputer.layers = layers;
|
|
22
|
-
|
|
23
|
-
cameraClippingPlaneComputer.compute();
|
|
24
|
-
|
|
25
|
-
if (camera.near !== cameraClippingPlaneComputer.near || camera.far !== cameraClippingPlaneComputer.far) {
|
|
26
|
-
camera.near = cameraClippingPlaneComputer.near;
|
|
27
|
-
camera.far = cameraClippingPlaneComputer.far;
|
|
7
|
+
// TODO implement
|
|
28
8
|
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
c.object.far = c.clip_far;
|
|
10
|
+
c.object.near = c.clip_near;
|
|
31
11
|
|
|
32
12
|
}
|