@woosh/meep-engine 2.65.0 → 2.67.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 +51290 -54244
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +51290 -54244
- 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/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/BVH.d.ts +1 -1
- package/src/core/bvh2/bvh3/BvhClient.d.ts +11 -0
- package/src/core/bvh2/bvh3/BvhClient.js +19 -0
- 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/GraphicsEngine.js +16 -25
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +8 -11
- 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/compileAllMaterials.js +5 -12
- package/src/engine/graphics/ecs/light/LightSystem.js +12 -48
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +9 -31
- package/src/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +3 -43
- package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +22 -24
- package/src/engine/graphics/ecs/mesh-v2/sample/prototype_sg_raycast.js +21 -23
- 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/emitter/ParticleEmitter.js +1 -1
- package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +8 -11
- 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 +4 -3
- package/src/engine/graphics/render/layers/RenderLayer.js +34 -108
- package/src/engine/graphics/render/make_bvh_visibility_builder.js +64 -0
- 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/core/bvh2/binary/tiny/TinyBVH.js +0 -221
- package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +0 -138
|
@@ -12,21 +12,20 @@ import {
|
|
|
12
12
|
Sphere as ThreeSphere,
|
|
13
13
|
Vector3 as ThreeVector3
|
|
14
14
|
} from 'three';
|
|
15
|
-
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
|
|
15
|
+
import { BinaryUint32BVH } from "../../../../core/bvh2/binary/2/BinaryUint32BVH.js";
|
|
16
|
+
import { bvh32_query_user_data_ray } from "../../../../core/bvh2/binary/2/bvh32_query_user_data_ray.js";
|
|
17
|
+
import { BvhClient } from "../../../../core/bvh2/bvh3/BvhClient.js";
|
|
20
18
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
21
19
|
import Signal from "../../../../core/events/signal/Signal.js";
|
|
22
|
-
import { passThrough } from "../../../../core/function/Functions.js";
|
|
23
20
|
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
21
|
+
import { ray3_array_apply_matrix4 } from "../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
22
|
+
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
24
23
|
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
24
|
+
import { computeTriangleRayIntersection } from "../../../../core/geom/3d/triangle/computeTriangleRayIntersection.js";
|
|
25
25
|
import Vector2 from '../../../../core/geom/Vector2.js';
|
|
26
26
|
import Vector3 from '../../../../core/geom/Vector3.js';
|
|
27
27
|
import { NumericInterval } from "../../../../core/math/interval/NumericInterval.js";
|
|
28
28
|
import ObservedInteger from "../../../../core/model/ObservedInteger.js";
|
|
29
|
-
import { BVHGeometryRaycaster } from "../../../graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js";
|
|
30
29
|
|
|
31
30
|
import ThreeFactory from '../../../graphics/three/ThreeFactory.js';
|
|
32
31
|
|
|
@@ -34,6 +33,12 @@ import ThreeFactory from '../../../graphics/three/ThreeFactory.js';
|
|
|
34
33
|
const EMPTY_GEOMETRY = new ThreeBufferGeometry();
|
|
35
34
|
const DEFAULT_MATERIAL = new MeshBasicMaterial();
|
|
36
35
|
|
|
36
|
+
const scratch_array = []
|
|
37
|
+
const scratch_hit = new SurfacePoint3()
|
|
38
|
+
|
|
39
|
+
const ray_tmp = [];
|
|
40
|
+
const m4_tmp = [];
|
|
41
|
+
|
|
37
42
|
/**
|
|
38
43
|
* terrain tile is a part of a 2d array
|
|
39
44
|
*/
|
|
@@ -66,13 +71,13 @@ class TerrainTile {
|
|
|
66
71
|
|
|
67
72
|
/**
|
|
68
73
|
*
|
|
69
|
-
* @type {
|
|
74
|
+
* @type {BvhClient}
|
|
70
75
|
*/
|
|
71
|
-
|
|
76
|
+
external_bvh = new BvhClient();
|
|
72
77
|
|
|
73
78
|
/**
|
|
74
79
|
*
|
|
75
|
-
* @type {
|
|
80
|
+
* @type {BinaryUint32BVH}
|
|
76
81
|
*/
|
|
77
82
|
bvh = null;
|
|
78
83
|
|
|
@@ -121,8 +126,6 @@ class TerrainTile {
|
|
|
121
126
|
*/
|
|
122
127
|
__initial_height_range = new NumericInterval(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY);
|
|
123
128
|
|
|
124
|
-
raycaster = new BVHGeometryRaycaster();
|
|
125
|
-
|
|
126
129
|
constructor() {
|
|
127
130
|
|
|
128
131
|
this.mesh.name = "TerrainTile";
|
|
@@ -132,9 +135,6 @@ class TerrainTile {
|
|
|
132
135
|
* @type {boolean}
|
|
133
136
|
*/
|
|
134
137
|
this.mesh.matrixWorldNeedsUpdate = false;
|
|
135
|
-
|
|
136
|
-
//Binary BVH form doesn't have distinct leaf objects and stores face indices directly, this requires a special face index extractor that treats leaves as indices directly.
|
|
137
|
-
this.raycaster.extractFaceIndexFromLeaf = passThrough;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
@@ -152,32 +152,6 @@ class TerrainTile {
|
|
|
152
152
|
set transform(m4) {
|
|
153
153
|
array_copy(m4, 0, this.mesh.matrixWorld.elements, 0, 16);
|
|
154
154
|
this.computeBoundingBox();
|
|
155
|
-
|
|
156
|
-
// raycaster needs to store transform as well
|
|
157
|
-
array_copy(m4, 0, this.raycaster.transform, 0, 16);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* @param {Vector3} origin
|
|
163
|
-
* @param {Vector3} direction
|
|
164
|
-
* @param {function} callback
|
|
165
|
-
* @param {function} missCallback
|
|
166
|
-
*/
|
|
167
|
-
raycast(origin, direction, callback, missCallback) {
|
|
168
|
-
const hitFound = this.raycaster.raycast(
|
|
169
|
-
hit,
|
|
170
|
-
origin.x, origin.y, origin.z,
|
|
171
|
-
direction.x, direction.y, direction.z
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
if (hitFound) {
|
|
175
|
-
callback(hit.position, hit.normal);
|
|
176
|
-
} else {
|
|
177
|
-
missCallback();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return hitFound;
|
|
181
155
|
}
|
|
182
156
|
|
|
183
157
|
/**
|
|
@@ -191,11 +165,87 @@ class TerrainTile {
|
|
|
191
165
|
* @param {number} directionZ
|
|
192
166
|
* @return {boolean}
|
|
193
167
|
*/
|
|
194
|
-
raycastFirstSync(
|
|
168
|
+
raycastFirstSync(
|
|
169
|
+
result,
|
|
170
|
+
originX, originY, originZ,
|
|
171
|
+
directionX, directionY, directionZ
|
|
172
|
+
) {
|
|
173
|
+
|
|
174
|
+
const m4 = this.transform;
|
|
175
|
+
|
|
176
|
+
mat4.invert(m4_tmp, m4);
|
|
177
|
+
|
|
178
|
+
ray3_array_compose(
|
|
179
|
+
ray_tmp,
|
|
180
|
+
originX, originY, originZ,
|
|
181
|
+
directionX, directionY, directionZ
|
|
182
|
+
);
|
|
195
183
|
|
|
196
|
-
|
|
184
|
+
ray3_array_apply_matrix4(ray_tmp, 0, ray_tmp, 0, m4_tmp);
|
|
185
|
+
|
|
186
|
+
const _originX = ray_tmp[0];
|
|
187
|
+
const _originY = ray_tmp[1];
|
|
188
|
+
const _originZ = ray_tmp[2];
|
|
189
|
+
|
|
190
|
+
const _directionX = ray_tmp[3];
|
|
191
|
+
const _directionY = ray_tmp[4];
|
|
192
|
+
const _directionZ = ray_tmp[5];
|
|
193
|
+
|
|
194
|
+
const hit_count = bvh32_query_user_data_ray(
|
|
195
|
+
this.bvh,
|
|
196
|
+
scratch_array, 0,
|
|
197
|
+
_originX, _originY, _originZ,
|
|
198
|
+
_directionX, _directionY, _directionZ
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
let best_distance = Infinity;
|
|
202
|
+
let hit_found = false;
|
|
203
|
+
|
|
204
|
+
const geometry = this.geometry;
|
|
197
205
|
|
|
198
|
-
|
|
206
|
+
const geometryIndices = geometry.getIndex().array;
|
|
207
|
+
const geometryPositions = geometry.getAttribute('position').array;
|
|
208
|
+
|
|
209
|
+
for (let i = 0; i < hit_count; i++) {
|
|
210
|
+
const triangle_index = scratch_array[i];
|
|
211
|
+
|
|
212
|
+
const index3 = triangle_index * 3;
|
|
213
|
+
|
|
214
|
+
const a = geometryIndices[index3] * 3;
|
|
215
|
+
const b = geometryIndices[index3 + 1] * 3;
|
|
216
|
+
const c = geometryIndices[index3 + 2] * 3;
|
|
217
|
+
|
|
218
|
+
const triangle_hit_found = computeTriangleRayIntersection(
|
|
219
|
+
scratch_hit,
|
|
220
|
+
_originX, _originY, _originZ,
|
|
221
|
+
_directionX, _directionY, _directionZ,
|
|
222
|
+
geometryPositions[a], geometryPositions[a + 1], geometryPositions[a + 2],
|
|
223
|
+
geometryPositions[b], geometryPositions[b + 1], geometryPositions[b + 2],
|
|
224
|
+
geometryPositions[c], geometryPositions[c + 1], geometryPositions[c + 2],
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
if (!triangle_hit_found) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
hit_found = true;
|
|
232
|
+
|
|
233
|
+
const distance_sqr = scratch_hit.position._distanceSqrTo(_originX, _originY, _originZ);
|
|
234
|
+
|
|
235
|
+
if (distance_sqr < best_distance) {
|
|
236
|
+
best_distance = distance_sqr;
|
|
237
|
+
result.copy(scratch_hit);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (hit_found) {
|
|
242
|
+
result.applyMatrix4(m4);
|
|
243
|
+
|
|
244
|
+
// make sure to pull normal to magnitude of 1
|
|
245
|
+
result.normal.normalize();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return hit_found;
|
|
199
249
|
}
|
|
200
250
|
|
|
201
251
|
getVertexNormal(index, result) {
|
|
@@ -468,16 +518,27 @@ class TerrainTile {
|
|
|
468
518
|
|
|
469
519
|
//check for bvh
|
|
470
520
|
const bvh = this.bvh;
|
|
521
|
+
|
|
471
522
|
if (bvh !== null) {
|
|
472
|
-
|
|
523
|
+
const float32 = bvh.float32;
|
|
524
|
+
|
|
525
|
+
const x0 = float32[0];
|
|
526
|
+
const y0 = float32[1];
|
|
527
|
+
const z0 = float32[2];
|
|
528
|
+
|
|
529
|
+
const x1 = float32[3];
|
|
530
|
+
const y1 = float32[4];
|
|
531
|
+
const z1 = float32[5];
|
|
473
532
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const
|
|
533
|
+
geometry.boundingBox = new ThreeBox3(new ThreeVector3(x0, y0, z0), new ThreeVector3(x1, y1, z1));
|
|
534
|
+
|
|
535
|
+
const dX = x1 - x0;
|
|
536
|
+
const dY = y1 - y0;
|
|
537
|
+
const dZ = z1 - z0;
|
|
477
538
|
|
|
478
539
|
const radius = Math.sqrt(dX * dX + dY * dY + dZ * dZ) / 2;
|
|
479
540
|
|
|
480
|
-
const center = new ThreeVector3(
|
|
541
|
+
const center = new ThreeVector3(x0 + dX / 2, y0 + dY / 2, z0 + dZ / 2);
|
|
481
542
|
|
|
482
543
|
geometry.boundingSphere = new ThreeSphere(center, radius);
|
|
483
544
|
}
|
|
@@ -505,12 +566,10 @@ class TerrainTile {
|
|
|
505
566
|
|
|
506
567
|
geometry_bb.applyMatrix4(this.transform);
|
|
507
568
|
|
|
508
|
-
this.
|
|
569
|
+
this.external_bvh.resize(
|
|
509
570
|
geometry_bb.x0, geometry_bb.y0, geometry_bb.z0,
|
|
510
571
|
geometry_bb.x1, geometry_bb.y1, geometry_bb.z1
|
|
511
572
|
);
|
|
512
|
-
// update changes up the tree
|
|
513
|
-
this.boundingBox.bubbleRefit();
|
|
514
573
|
}
|
|
515
574
|
|
|
516
575
|
/**
|
|
@@ -536,6 +595,11 @@ class TerrainTile {
|
|
|
536
595
|
this.onDestroyed.send1(this);
|
|
537
596
|
}
|
|
538
597
|
|
|
598
|
+
/**
|
|
599
|
+
*
|
|
600
|
+
* @param {{geometry, bvh?:{leaf_count:number, data:ArrayBuffer}}} tileData
|
|
601
|
+
* @returns {Mesh}
|
|
602
|
+
*/
|
|
539
603
|
build(tileData) {
|
|
540
604
|
this.isBuilt = true;
|
|
541
605
|
// console.groupCollapsed('Building tile');
|
|
@@ -557,12 +621,12 @@ class TerrainTile {
|
|
|
557
621
|
if (this.enableBVH) {
|
|
558
622
|
// console.time('bvh');
|
|
559
623
|
// this.generateBufferedGeometryBVH();
|
|
560
|
-
const bvh = this.bvh = new
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
624
|
+
const bvh = this.bvh = new BinaryUint32BVH();
|
|
625
|
+
const serialized_bvh = tileData.bvh;
|
|
626
|
+
|
|
627
|
+
bvh.setLeafCount(serialized_bvh.leaf_count);
|
|
628
|
+
bvh.data = serialized_bvh.data;
|
|
629
|
+
|
|
566
630
|
// console.timeEnd('bvh');
|
|
567
631
|
}
|
|
568
632
|
|
|
@@ -582,17 +646,8 @@ class TerrainTile {
|
|
|
582
646
|
// console.timeEnd('total');
|
|
583
647
|
// console.groupEnd();
|
|
584
648
|
|
|
585
|
-
this.raycaster.bvh = this.bvh;
|
|
586
|
-
this.raycaster.geometry = g;
|
|
587
|
-
this.raycaster.position = this.position;
|
|
588
|
-
this.raycaster.scale = this.scale;
|
|
589
|
-
this.raycaster.resolution = this.resolution.getValue();
|
|
590
|
-
this.raycaster.size = this.size;
|
|
591
|
-
|
|
592
649
|
return mesh;
|
|
593
650
|
}
|
|
594
651
|
}
|
|
595
652
|
|
|
596
|
-
const hit = new SurfacePoint3();
|
|
597
|
-
|
|
598
653
|
export default TerrainTile;
|