@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,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Texture } from "three";
|
|
2
|
+
import { GridTransformKind } from "../../../../../../src/engine/ecs/terrain/ecs/GridTransformKind.js";
|
|
3
3
|
import { TerrainFlags } from "../../../../../../src/engine/ecs/terrain/ecs/TerrainFlags.js";
|
|
4
|
-
import {
|
|
4
|
+
import { BitFlagsEditor } from "../../common/BitFlagsEditor.js";
|
|
5
5
|
import { EnumEditor } from "../../common/EnumEditor.js";
|
|
6
|
-
import {
|
|
7
|
-
import { Texture } from "three";
|
|
6
|
+
import { ObjectEditor } from "../../primitive/ObjectEditor.js";
|
|
8
7
|
|
|
9
8
|
export class TerrainEditor extends ObjectEditor {
|
|
10
9
|
build(parent, field, registry) {
|
|
@@ -69,11 +68,6 @@ export class TerrainEditor extends ObjectEditor {
|
|
|
69
68
|
material: {
|
|
70
69
|
transient: true
|
|
71
70
|
},
|
|
72
|
-
heightMapURL: {
|
|
73
|
-
editor: new ImagePathEditor(),
|
|
74
|
-
deprecated: true,
|
|
75
|
-
type: String
|
|
76
|
-
},
|
|
77
71
|
heightRange: {
|
|
78
72
|
deprecated: true
|
|
79
73
|
},
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import { BufferGeometry, Float32BufferAttribute, Line, LineBasicMaterial } from "three";
|
|
2
|
+
import { SurfacePoint3 } from "../../../src/core/geom/3d/SurfacePoint3.js";
|
|
3
|
+
import Vector3 from "../../../src/core/geom/Vector3.js";
|
|
1
4
|
import { max2 } from "../../../src/core/math/max2.js";
|
|
2
5
|
import { min2 } from "../../../src/core/math/min2.js";
|
|
6
|
+
import { ProcessState } from "../../../src/core/process/ProcessState.js";
|
|
3
7
|
import Task from "../../../src/core/process/task/Task.js";
|
|
4
8
|
import { TaskSignal } from "../../../src/core/process/task/TaskSignal.js";
|
|
5
9
|
import Entity from "../../../src/engine/ecs/Entity.js";
|
|
6
|
-
import {
|
|
10
|
+
import { EventType } from "../../../src/engine/ecs/EntityManager.js";
|
|
7
11
|
import Renderable from "../../../src/engine/ecs/renderable/Renderable.js";
|
|
8
|
-
import {
|
|
9
|
-
import Vector3 from "../../../src/core/geom/Vector3.js";
|
|
12
|
+
import { obtainTerrain } from "../../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
10
13
|
import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
|
|
14
|
+
import GridPosition from "../../../src/engine/grid/position/GridPosition.js";
|
|
11
15
|
import EditorEntity from "../../ecs/EditorEntity.js";
|
|
12
|
-
import { EventType } from "../../../src/engine/ecs/EntityManager.js";
|
|
13
16
|
import { make3DSymbolicDisplay } from "./make3DSymbolicDisplay.js";
|
|
14
|
-
import GridPosition from "../../../src/engine/grid/position/GridPosition.js";
|
|
15
|
-
import { ProcessState } from "../../../src/core/process/ProcessState.js";
|
|
16
|
-
import { obtainTerrain } from "../../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
@@ -3,23 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import Vector2 from '../../src/core/geom/Vector2.js';
|
|
6
|
+
import { Frustum as ThreeFrustum } from 'three';
|
|
8
7
|
import AABB2 from '../../src/core/geom/2d/aabb/AABB2.js';
|
|
8
|
+
import Vector2 from '../../src/core/geom/Vector2.js';
|
|
9
|
+
import { makeScreenScissorFrustum } from "../../src/engine/graphics/camera/makeScreenScissorFrustum.js";
|
|
9
10
|
import { Camera } from '../../src/engine/graphics/ecs/camera/Camera.js';
|
|
11
|
+
import { ShadedGeometrySystem } from "../../src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
|
|
12
|
+
import { make_ray_from_viewport_position } from "../../src/engine/graphics/make_ray_from_viewport_position.js";
|
|
10
13
|
import View from '../../src/view/View.js';
|
|
11
14
|
|
|
12
15
|
import SelectionAddAction from '../actions/concrete/SelectionAddAction.js';
|
|
13
16
|
import SelectionClearAction from '../actions/concrete/SelectionClearAction.js';
|
|
14
|
-
|
|
15
|
-
import { Frustum as ThreeFrustum, Raycaster } from 'three';
|
|
16
|
-
import Vector3 from "../../src/core/geom/Vector3.js";
|
|
17
17
|
import EditorEntity from "../ecs/EditorEntity.js";
|
|
18
|
-
import
|
|
19
|
-
import { SurfacePoint3 } from "../../src/core/geom/3d/SurfacePoint3.js";
|
|
20
|
-
import { makeScreenScissorFrustum } from "../../src/engine/graphics/camera/makeScreenScissorFrustum.js";
|
|
21
|
-
import { ShadedGeometrySystem } from "../../src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
|
|
22
|
-
import { make_ray_from_viewport_position } from "../../src/engine/graphics/make_ray_from_viewport_position.js";
|
|
18
|
+
import Tool from './engine/Tool.js';
|
|
23
19
|
|
|
24
20
|
class SelectionView extends View {
|
|
25
21
|
constructor() {
|
|
@@ -283,72 +279,6 @@ export function pickingEntitySelection(point, engine, camera) {
|
|
|
283
279
|
}
|
|
284
280
|
}
|
|
285
281
|
|
|
286
|
-
//query render layers
|
|
287
|
-
engine.graphics.layers.traverse(function (layer) {
|
|
288
|
-
/**
|
|
289
|
-
*
|
|
290
|
-
* @type {BinaryNode}
|
|
291
|
-
*/
|
|
292
|
-
const bvh = layer.bvh;
|
|
293
|
-
|
|
294
|
-
bvh.traverseRayLeafIntersections(ray_origin.x, ray_origin.y, ray_origin.z, ray_direction.x, ray_direction.y, ray_direction.z, function (leaf) {
|
|
295
|
-
const entity = findEntityOfNode(leaf);
|
|
296
|
-
|
|
297
|
-
if (typeof entity !== "number") {
|
|
298
|
-
//no entity
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const object = leaf.object;
|
|
303
|
-
if (
|
|
304
|
-
leaf.hasOwnProperty("object")
|
|
305
|
-
&& typeof object === "object"
|
|
306
|
-
&& object !== null
|
|
307
|
-
&& object.isObject3D
|
|
308
|
-
&& typeof object.raycast === "function"
|
|
309
|
-
) {
|
|
310
|
-
//found a "raycast" function on the value object held by the leaf, assuming this is THREE.js raycast function
|
|
311
|
-
const raycaster = new Raycaster(ray_origin, ray_direction, 0, Infinity);
|
|
312
|
-
|
|
313
|
-
// WORKAROUND FOR https://github.com/mrdoob/three.js/issues/17078
|
|
314
|
-
raycaster.camera = camera;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
object.traverse(node => {
|
|
318
|
-
const intersection = [];
|
|
319
|
-
node.raycast(raycaster, intersection);
|
|
320
|
-
|
|
321
|
-
intersection.forEach(function (contact) {
|
|
322
|
-
tryAddEntity(entity, contact.point);
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
} else {
|
|
327
|
-
/**
|
|
328
|
-
*
|
|
329
|
-
* @type {Terrain}
|
|
330
|
-
*/
|
|
331
|
-
const terrain = dataset.getComponent(entity, Terrain);
|
|
332
|
-
|
|
333
|
-
if (terrain !== undefined) {
|
|
334
|
-
const sp = new SurfacePoint3();
|
|
335
|
-
|
|
336
|
-
terrain.raycastFirstSync(sp, ray_origin.x, ray_origin.y, ray_origin.z, ray_direction.x, ray_direction.y, ray_direction.z);
|
|
337
|
-
|
|
338
|
-
tryAddEntity(entity, sp.position);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const center = new Vector3(0, 0, 0);
|
|
343
|
-
|
|
344
|
-
leaf.getCenter(center);
|
|
345
|
-
|
|
346
|
-
tryAddEntity(entity, center);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
});
|
|
351
|
-
|
|
352
282
|
return bestCandidate !== null ? [bestCandidate] : [];
|
|
353
283
|
}
|
|
354
284
|
|
|
@@ -381,25 +311,6 @@ function marqueeSelection(box, editor, camera) {
|
|
|
381
311
|
makeScreenScissorFrustum(frustum, normalizedBox, camera);
|
|
382
312
|
|
|
383
313
|
const selection = [];
|
|
384
|
-
//query render layers
|
|
385
|
-
engine.graphics.layers.traverse(function (layer) {
|
|
386
|
-
layer.bvh.threeTraverseFrustumsIntersections([frustum], function (leaf, fullyInside) {
|
|
387
|
-
|
|
388
|
-
if (leaf.hasOwnProperty("entity") && selection.indexOf(leaf.entity) === -1) {
|
|
389
|
-
let entity = findEntityOfNode(leaf);
|
|
390
|
-
|
|
391
|
-
entity = dereferenceEntity(entity, dataset);
|
|
392
|
-
|
|
393
|
-
if (entity === -1) {
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (selection.indexOf(entity) === -1) {
|
|
398
|
-
selection.push(entity);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
314
|
|
|
404
315
|
return selection;
|
|
405
316
|
}
|
package/package.json
CHANGED
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import {assert} from "../assert.js";
|
|
7
|
-
import {arrayQuickSort} from "../collection/array/arrayQuickSort.js";
|
|
8
|
-
import {aabb3_box_surface_area_2} from "../geom/3d/aabb/aabb3_box_surface_area_2.js";
|
|
9
|
-
import {aabb3_combined_surface_area} from "../geom/3d/aabb/aabb3_combined_surface_area.js";
|
|
10
|
-
import {aabb3_intersects_aabb3} from "../geom/3d/aabb/aabb3_intersects_aabb3.js";
|
|
11
|
-
import {max2} from "../math/max2.js";
|
|
12
|
-
import {min2} from "../math/min2.js";
|
|
13
|
-
import {computeSampleStandardDeviation} from "../math/statistics/computeSampleStandardDeviation.js";
|
|
14
|
-
import {isLeaf, LeafNode} from "./LeafNode.js";
|
|
15
|
-
import {Node} from "./Node.js";
|
|
16
|
-
import {surfaceAreaHeuristic} from "./sah/surfaceAreaHeuristic.js";
|
|
17
|
-
import {BVHVisitor} from "./traversal/BVHVisitor.js";
|
|
18
|
-
import {traverseBinaryNodeUsingVisitor} from "./traversal/traverseBinaryNodeUsingVisitor.js";
|
|
6
|
+
import { assert } from "../assert.js";
|
|
7
|
+
import { arrayQuickSort } from "../collection/array/arrayQuickSort.js";
|
|
8
|
+
import { aabb3_box_surface_area_2 } from "../geom/3d/aabb/aabb3_box_surface_area_2.js";
|
|
9
|
+
import { aabb3_combined_surface_area } from "../geom/3d/aabb/aabb3_combined_surface_area.js";
|
|
10
|
+
import { aabb3_intersects_aabb3 } from "../geom/3d/aabb/aabb3_intersects_aabb3.js";
|
|
11
|
+
import { max2 } from "../math/max2.js";
|
|
12
|
+
import { min2 } from "../math/min2.js";
|
|
13
|
+
import { computeSampleStandardDeviation } from "../math/statistics/computeSampleStandardDeviation.js";
|
|
14
|
+
import { isLeaf, LeafNode } from "./LeafNode.js";
|
|
15
|
+
import { Node } from "./Node.js";
|
|
16
|
+
import { surfaceAreaHeuristic } from "./sah/surfaceAreaHeuristic.js";
|
|
17
|
+
import { BVHVisitor } from "./traversal/BVHVisitor.js";
|
|
18
|
+
import { traverseBinaryNodeUsingVisitor } from "./traversal/traverseBinaryNodeUsingVisitor.js";
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -37,7 +37,7 @@ let stackPointer = 0;
|
|
|
37
37
|
const stack = [];
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* @deprecated use {@link
|
|
40
|
+
* @deprecated use {@link BVH} instead
|
|
41
41
|
*/
|
|
42
42
|
export class BinaryNode extends Node {
|
|
43
43
|
constructor() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by Alex on 17/11/2014.
|
|
3
3
|
*/
|
|
4
|
-
import {deserializeAABB3} from "../geom/3d/aabb/deserializeAABB3.js";
|
|
5
|
-
import {serializeAABB3} from "../geom/3d/aabb/serializeAABB3.js";
|
|
6
|
-
import {Node} from "./Node.js";
|
|
4
|
+
import { deserializeAABB3 } from "../geom/3d/aabb/deserializeAABB3.js";
|
|
5
|
+
import { serializeAABB3 } from "../geom/3d/aabb/serializeAABB3.js";
|
|
6
|
+
import { Node } from "./Node.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -16,7 +16,7 @@ function isLeaf(node) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @deprecated use {@link
|
|
19
|
+
* @deprecated use {@link BVH} and {@link BvhClient} respectively
|
|
20
20
|
*/
|
|
21
21
|
export class LeafNode extends Node {
|
|
22
22
|
/**
|
|
@@ -1,114 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { min2 } from "../../../math/min2.js";
|
|
3
|
-
import { max2 } from "../../../math/max2.js";
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
4
2
|
import { ceilPowerOfTwo } from "../../../binary/operations/ceilPowerOfTwo.js";
|
|
3
|
+
import { array_copy } from "../../../collection/array/array_copy.js";
|
|
5
4
|
import { array_swap } from "../../../collection/array/array_swap.js";
|
|
5
|
+
import { aabb3_array_combine } from "../../../geom/3d/aabb/aabb3_array_combine.js";
|
|
6
|
+
import { aabb3_array_set } from "../../../geom/3d/aabb/aabb3_array_set.js";
|
|
7
|
+
import { aabb3_compute_half_surface_area } from "../../../geom/3d/aabb/aabb3_compute_half_surface_area.js";
|
|
6
8
|
import { mortonEncode_magicbits } from "../../../geom/3d/morton/mortonEncode_magicbits.js";
|
|
7
|
-
import {
|
|
9
|
+
import { max2 } from "../../../math/max2.js";
|
|
8
10
|
import { max3 } from "../../../math/max3.js";
|
|
9
|
-
import {
|
|
11
|
+
import { min2 } from "../../../math/min2.js";
|
|
12
|
+
import { min3 } from "../../../math/min3.js";
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* @readonly
|
|
13
16
|
* @type {number}
|
|
14
17
|
*/
|
|
15
|
-
export const BVH_BOX_BYTE_SIZE =
|
|
18
|
+
export const BVH_BOX_BYTE_SIZE = 6;
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
|
-
* In
|
|
21
|
+
* In words (4 byte)
|
|
19
22
|
* @readonly
|
|
20
23
|
* @type {number}
|
|
21
24
|
*/
|
|
22
|
-
export const BVH_BINARY_NODE_SIZE =
|
|
25
|
+
export const BVH_BINARY_NODE_SIZE = 6;
|
|
23
26
|
/**
|
|
24
27
|
* @readonly
|
|
25
28
|
* @type {number}
|
|
26
29
|
*/
|
|
27
|
-
export const BVH_LEAF_NODE_SIZE =
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {DataView} data
|
|
32
|
-
* @param {number} destination
|
|
33
|
-
* @param {number} source_a
|
|
34
|
-
* @param {number} source_b
|
|
35
|
-
*/
|
|
36
|
-
function refit_binary(data, destination, source_a, source_b) {
|
|
37
|
-
const ax0 = data.getFloat32(source_a);
|
|
38
|
-
const ay0 = data.getFloat32(source_a + 4);
|
|
39
|
-
const az0 = data.getFloat32(source_a + 8);
|
|
40
|
-
const ax1 = data.getFloat32(source_a + 12);
|
|
41
|
-
const ay1 = data.getFloat32(source_a + 16);
|
|
42
|
-
const az1 = data.getFloat32(source_a + 20);
|
|
43
|
-
|
|
44
|
-
const bx0 = data.getFloat32(source_b);
|
|
45
|
-
const by0 = data.getFloat32(source_b + 4);
|
|
46
|
-
const bz0 = data.getFloat32(source_b + 8);
|
|
47
|
-
const bx1 = data.getFloat32(source_b + 12);
|
|
48
|
-
const by1 = data.getFloat32(source_b + 16);
|
|
49
|
-
const bz1 = data.getFloat32(source_b + 20);
|
|
50
|
-
|
|
51
|
-
const x0 = min2(ax0, bx0);
|
|
52
|
-
const y0 = min2(ay0, by0);
|
|
53
|
-
const z0 = min2(az0, bz0);
|
|
54
|
-
|
|
55
|
-
const x1 = max2(ax1, bx1);
|
|
56
|
-
const y1 = max2(ay1, by1);
|
|
57
|
-
const z1 = max2(az1, bz1);
|
|
58
|
-
|
|
59
|
-
data.setFloat32(destination, x0);
|
|
60
|
-
data.setFloat32(destination + 4, y0);
|
|
61
|
-
data.setFloat32(destination + 8, z0);
|
|
62
|
-
data.setFloat32(destination + 12, x1);
|
|
63
|
-
data.setFloat32(destination + 16, y1);
|
|
64
|
-
data.setFloat32(destination + 20, z1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {Uint8Array} data
|
|
70
|
-
* @param {number} destination
|
|
71
|
-
* @param {number} source
|
|
72
|
-
*/
|
|
73
|
-
function copy_box(data, destination, source) {
|
|
74
|
-
array_copy(data, source, data, destination, 24);
|
|
75
|
-
}
|
|
30
|
+
export const BVH_LEAF_NODE_SIZE = 7;
|
|
76
31
|
|
|
77
32
|
/**
|
|
78
33
|
*
|
|
79
|
-
* @param {
|
|
34
|
+
* @param {Float32Array} data
|
|
80
35
|
* @param {number} destination
|
|
81
36
|
* @param {number} source
|
|
82
37
|
*/
|
|
83
38
|
function copy_box_zero_size(data, destination, source) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const z = data.getFloat32(source + 8);
|
|
39
|
+
assert.isNonNegativeInteger(destination, 'destination');
|
|
40
|
+
assert.isNonNegativeInteger(source, 'source');
|
|
87
41
|
|
|
88
|
-
|
|
89
|
-
data
|
|
90
|
-
data
|
|
42
|
+
const x = data[source];
|
|
43
|
+
const y = data[source + 1];
|
|
44
|
+
const z = data[source + 2];
|
|
91
45
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
46
|
+
assert.notNaN(x, 'x');
|
|
47
|
+
assert.notNaN(y, 'y');
|
|
48
|
+
assert.notNaN(z, 'z');
|
|
49
|
+
|
|
50
|
+
aabb3_array_set(data, destination, x, y, z, x, y, z);
|
|
95
51
|
}
|
|
96
52
|
|
|
97
53
|
/**
|
|
98
54
|
* Assumes data will be normalized to 0...1 value range
|
|
99
|
-
* @param {
|
|
55
|
+
* @param {Float32Array} data
|
|
100
56
|
* @param {number} address
|
|
101
57
|
* @param {number[]} matrix
|
|
102
58
|
* @returns {number}
|
|
103
59
|
*/
|
|
104
60
|
function build_morton(data, address, matrix) {
|
|
105
61
|
|
|
106
|
-
const x0 = data
|
|
107
|
-
const y0 = data
|
|
108
|
-
const z0 = data
|
|
109
|
-
const x1 = data
|
|
110
|
-
const y1 = data
|
|
111
|
-
const z1 = data
|
|
62
|
+
const x0 = data[address];
|
|
63
|
+
const y0 = data[address + 1];
|
|
64
|
+
const z0 = data[address + 2];
|
|
65
|
+
const x1 = data[address + 3];
|
|
66
|
+
const y1 = data[address + 4];
|
|
67
|
+
const z1 = data[address + 5];
|
|
112
68
|
|
|
113
69
|
const cx = (x0 + x1) / 2;
|
|
114
70
|
const cy = (y0 + y1) / 2;
|
|
@@ -123,16 +79,28 @@ const scratch_box_0 = new Float32Array(18);
|
|
|
123
79
|
const stack = [];
|
|
124
80
|
|
|
125
81
|
export class BinaryUint32BVH {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @private
|
|
85
|
+
* @type {ArrayBuffer}
|
|
86
|
+
*/
|
|
87
|
+
__data_buffer;
|
|
129
88
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
89
|
+
/**
|
|
90
|
+
* @readonly
|
|
91
|
+
* @type {Float32Array}
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
__data_float32;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @readonly
|
|
98
|
+
* @private
|
|
99
|
+
* @type {Uint32Array}
|
|
100
|
+
*/
|
|
101
|
+
__data_uint32;
|
|
102
|
+
|
|
103
|
+
constructor() {
|
|
136
104
|
|
|
137
105
|
/**
|
|
138
106
|
*
|
|
@@ -147,6 +115,8 @@ export class BinaryUint32BVH {
|
|
|
147
115
|
* @private
|
|
148
116
|
*/
|
|
149
117
|
this.__node_count_leaf = 0;
|
|
118
|
+
|
|
119
|
+
this.data = new ArrayBuffer(320);
|
|
150
120
|
}
|
|
151
121
|
|
|
152
122
|
getTotalBoxCount() {
|
|
@@ -169,23 +139,37 @@ export class BinaryUint32BVH {
|
|
|
169
139
|
return this.__node_count_binary * BVH_BINARY_NODE_SIZE;
|
|
170
140
|
}
|
|
171
141
|
|
|
142
|
+
get float32() {
|
|
143
|
+
return this.__data_float32;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
get uint32() {
|
|
147
|
+
return this.__data_uint32;
|
|
148
|
+
}
|
|
149
|
+
|
|
172
150
|
/**
|
|
173
151
|
*
|
|
174
|
-
* @
|
|
152
|
+
* @param {ArrayBuffer} v
|
|
175
153
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
154
|
+
set data(v) {
|
|
155
|
+
this.__data_buffer = v;
|
|
156
|
+
|
|
157
|
+
this.__data_float32 = new Float32Array(this.__data_buffer);
|
|
158
|
+
this.__data_uint32 = new Uint32Array(this.__data_buffer);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get data() {
|
|
162
|
+
return this.__data_buffer;
|
|
178
163
|
}
|
|
179
164
|
|
|
180
165
|
initialize_structure() {
|
|
181
166
|
// compute memory requirements
|
|
182
|
-
const
|
|
167
|
+
const word_count = this.__node_count_binary * BVH_BINARY_NODE_SIZE + this.__node_count_leaf * BVH_LEAF_NODE_SIZE;
|
|
168
|
+
const storage_size = word_count * 4;
|
|
183
169
|
|
|
184
170
|
// possibly resize the storage
|
|
185
171
|
if (this.__data_buffer.byteLength < storage_size) {
|
|
186
|
-
this.
|
|
187
|
-
this.__data_uint8 = new Uint8Array(this.__data_buffer);
|
|
188
|
-
this.__data_view = new DataView(this.__data_buffer);
|
|
172
|
+
this.data = new ArrayBuffer(storage_size);
|
|
189
173
|
}
|
|
190
174
|
}
|
|
191
175
|
|
|
@@ -218,19 +202,28 @@ export class BinaryUint32BVH {
|
|
|
218
202
|
* @param {number} y1
|
|
219
203
|
* @param {number} z1
|
|
220
204
|
*/
|
|
221
|
-
setLeafData(
|
|
222
|
-
|
|
205
|
+
setLeafData(
|
|
206
|
+
index, payload,
|
|
207
|
+
x0, y0, z0,
|
|
208
|
+
x1, y1, z1
|
|
209
|
+
) {
|
|
210
|
+
assert.notNaN(x0, 'x0');
|
|
211
|
+
assert.notNaN(y0, 'y0');
|
|
212
|
+
assert.notNaN(z0, 'z0');
|
|
213
|
+
assert.notNaN(x1, 'x1');
|
|
214
|
+
assert.notNaN(y1, 'y1');
|
|
215
|
+
assert.notNaN(z1, 'z1');
|
|
223
216
|
|
|
224
|
-
const
|
|
217
|
+
const address = index * BVH_LEAF_NODE_SIZE + this.__node_count_binary * BVH_BINARY_NODE_SIZE;
|
|
225
218
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
aabb3_array_set(
|
|
220
|
+
this.__data_float32,
|
|
221
|
+
address,
|
|
222
|
+
x0, y0, z0,
|
|
223
|
+
x1, y1, z1
|
|
224
|
+
);
|
|
232
225
|
|
|
233
|
-
|
|
226
|
+
this.__data_uint32[address + 6] = payload;
|
|
234
227
|
}
|
|
235
228
|
|
|
236
229
|
/**
|
|
@@ -240,10 +233,7 @@ export class BinaryUint32BVH {
|
|
|
240
233
|
* @param {number} destination_offset offset within the destination array where to start writing results
|
|
241
234
|
*/
|
|
242
235
|
readBounds(address, destination, destination_offset) {
|
|
243
|
-
|
|
244
|
-
for (let i = 0; i < 6; i++) {
|
|
245
|
-
destination[destination_offset + i] = v.getFloat32(address + i * 4);
|
|
246
|
-
}
|
|
236
|
+
array_copy(this.__data_float32, address, destination, destination_offset, 6);
|
|
247
237
|
}
|
|
248
238
|
|
|
249
239
|
/**
|
|
@@ -256,7 +246,7 @@ export class BinaryUint32BVH {
|
|
|
256
246
|
|
|
257
247
|
const address = block_address + leaf_index * BVH_LEAF_NODE_SIZE + BVH_BOX_BYTE_SIZE;
|
|
258
248
|
|
|
259
|
-
return this.
|
|
249
|
+
return this.__data_uint32[address];
|
|
260
250
|
}
|
|
261
251
|
|
|
262
252
|
compute_total_surface_area() {
|
|
@@ -369,7 +359,7 @@ export class BinaryUint32BVH {
|
|
|
369
359
|
stack[0] = 0; // first node
|
|
370
360
|
stack[1] = this.__node_count_leaf - 1; // last node
|
|
371
361
|
|
|
372
|
-
const data = this.
|
|
362
|
+
const data = this.__data_float32;
|
|
373
363
|
|
|
374
364
|
while (stackPointer > 0) {
|
|
375
365
|
stackPointer -= 2;
|
|
@@ -382,7 +372,9 @@ export class BinaryUint32BVH {
|
|
|
382
372
|
|
|
383
373
|
const pivotIndex = (left + right) >> 1;
|
|
384
374
|
|
|
385
|
-
const
|
|
375
|
+
const pivot_address = pivotIndex * BVH_LEAF_NODE_SIZE + leaf_block_address;
|
|
376
|
+
|
|
377
|
+
const pivot = build_morton(data, pivot_address, projection);
|
|
386
378
|
|
|
387
379
|
/* partition */
|
|
388
380
|
while (i <= j) {
|
|
@@ -426,9 +418,12 @@ export class BinaryUint32BVH {
|
|
|
426
418
|
*/
|
|
427
419
|
__swap_leaves(i, j) {
|
|
428
420
|
const leaf_block_address = this.getLeafBlockAddress();
|
|
421
|
+
const a = i * BVH_LEAF_NODE_SIZE + leaf_block_address;
|
|
422
|
+
const b = j * BVH_LEAF_NODE_SIZE + leaf_block_address;
|
|
423
|
+
|
|
429
424
|
array_swap(
|
|
430
|
-
this.
|
|
431
|
-
this.
|
|
425
|
+
this.__data_float32, a,
|
|
426
|
+
this.__data_float32, b,
|
|
432
427
|
BVH_LEAF_NODE_SIZE
|
|
433
428
|
);
|
|
434
429
|
}
|
|
@@ -453,6 +448,8 @@ export class BinaryUint32BVH {
|
|
|
453
448
|
|
|
454
449
|
const node_count_leaf = this.__node_count_leaf;
|
|
455
450
|
|
|
451
|
+
const float32 = this.__data_float32;
|
|
452
|
+
|
|
456
453
|
// build bottom-most level, just above the leaves
|
|
457
454
|
for (i = 0; i < level_node_count; i++) {
|
|
458
455
|
const leafIndex0 = i * 2;
|
|
@@ -463,13 +460,17 @@ export class BinaryUint32BVH {
|
|
|
463
460
|
|
|
464
461
|
if (leafIndex1 < node_count_leaf) {
|
|
465
462
|
// both children nodes are valid
|
|
466
|
-
|
|
463
|
+
aabb3_array_combine(
|
|
464
|
+
float32, offset,
|
|
465
|
+
float32, leafOffset0,
|
|
466
|
+
float32, leafOffset1
|
|
467
|
+
);
|
|
467
468
|
} else if (leafIndex0 < node_count_leaf) {
|
|
468
469
|
// only left child node is valid
|
|
469
|
-
|
|
470
|
+
array_copy(float32, leafOffset0, float32, offset, 6);
|
|
470
471
|
} else {
|
|
471
472
|
//initialize to 0-size box same position as previous node
|
|
472
|
-
copy_box_zero_size(this.
|
|
473
|
+
copy_box_zero_size(this.__data_float32, offset, (offset - BVH_BINARY_NODE_SIZE));
|
|
473
474
|
}
|
|
474
475
|
|
|
475
476
|
offset += BVH_BINARY_NODE_SIZE;
|
|
@@ -492,7 +493,11 @@ export class BinaryUint32BVH {
|
|
|
492
493
|
const address_child_0 = childIndex0 * BVH_BINARY_NODE_SIZE;
|
|
493
494
|
const address_child_1 = childIndex1 * BVH_BINARY_NODE_SIZE;
|
|
494
495
|
|
|
495
|
-
|
|
496
|
+
aabb3_array_combine(
|
|
497
|
+
float32, address_parent,
|
|
498
|
+
float32, address_child_0,
|
|
499
|
+
float32, address_child_1
|
|
500
|
+
);
|
|
496
501
|
|
|
497
502
|
parentIndex++;
|
|
498
503
|
}
|