@woosh/meep-engine 2.68.0 → 2.70.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-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +1090 -1581
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +1090 -1581
- package/package.json +1 -1
- package/src/core/__module.js +1 -0
- package/src/core/binary/BinaryBuffer.js +37 -31
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +76 -52
- package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +5 -7
- package/src/core/bvh2/binary/2/bvh32_query_user_data_overlaps_clipping_volume.js +94 -0
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +17 -18
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +4 -2
- package/src/core/geom/3d/aabb/AABB3.js +14 -14
- package/src/core/geom/3d/aabb/aabb3_array_intersects_clipping_volume_array.js +30 -0
- package/src/core/geom/3d/aabb/aabb3_intersects_clipping_volume_array.js +51 -0
- package/src/core/geom/3d/cone/compute_bounding_cone_of_2_cones.js +3 -2
- package/src/core/geom/3d/frustum/{read_frustum_planes_to_array.js → read_three_planes_to_array.js} +5 -3
- package/src/core/geom/3d/morton/v3_morton_encode_bounded.js +34 -0
- package/src/core/geom/3d/morton/v3_morton_encode_transformed.js +2 -1
- package/src/core/geom/3d/quaternion/quat3_createFromAxisAngle.js +11 -0
- package/src/core/geom/3d/quaternion/quat_decode_from_uint32.js +53 -0
- package/src/core/geom/3d/quaternion/quat_encode_to_uint32.js +106 -0
- package/src/core/geom/3d/triangle/triangle_intersects_clipping_volume.js +51 -0
- package/src/core/geom/Quaternion.js +8 -142
- package/src/core/geom/Vector2.js +6 -7
- package/src/core/geom/Vector3.js +15 -82
- package/src/core/geom/vec3/v3_binary_equality_decode.js +44 -0
- package/src/core/geom/vec3/v3_binary_equality_encode.js +47 -0
- package/src/core/primitives/numbers/computeHashFloat.js +2 -2
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
- package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +9 -46
- package/src/engine/ecs/transform/Transform.js +8 -9
- package/src/engine/ecs/transform/TransformSerializationAdapter.js +18 -7
- package/src/engine/graphics/ecs/mesh/Mesh.js +11 -11
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.d.ts +2 -2
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +79 -36
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_overlap_clipping_volume.js +88 -0
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js +108 -0
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +4 -30
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_unindexed_geometry.js +30 -0
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +41 -0
- package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
- package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +2 -2
- package/src/engine/graphics/render/view/CameraView.js +8 -8
- package/src/core/bvh2/binary/BinaryBVH.js +0 -281
- package/src/core/bvh2/binary/IndexedBinaryBVH.js +0 -407
- package/src/core/bvh2/binary/IndexedBinaryBVH.spec.js +0 -27
- package/src/core/bvh2/binary/IndexedBinaryBVHVisitor.js +0 -11
- package/src/core/bvh2/binary/NodeType.js +0 -8
- package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +0 -59
- package/src/core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js +0 -20
- package/src/core/geom/3d/aabb/aabb3_intersects_frustum_array.js +0 -35
- package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +0 -195
- package/src/engine/graphics/geometry/buffered/query/GeometryVisitor.js +0 -87
- package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +0 -206
- package/src/engine/graphics/geometry/bvh/buffered/BinaryBVHFromBufferGeometry.js +0 -123
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { Cache } from "../../../../../core/cache/Cache.js";
|
|
2
|
-
import { buildUnsorted, buildUnsortedUnindexed } from "../../bvh/buffered/BinaryBVHFromBufferGeometry.js";
|
|
3
|
-
import { ClippingPlaneContainmentComputingVisitor } from "./ClippingPlaneContainmentComputingVisitor.js";
|
|
4
|
-
import { RaycastNearestHitComputingVisitor } from "./RaycastNearestHitComputingVisitor.js";
|
|
5
1
|
import { assert } from "../../../../../core/assert.js";
|
|
2
|
+
import { BinaryUint32BVH } from "../../../../../core/bvh2/binary/2/BinaryUint32BVH.js";
|
|
3
|
+
import { Cache } from "../../../../../core/cache/Cache.js";
|
|
4
|
+
import { read_three_planes_to_array } from "../../../../../core/geom/3d/frustum/read_three_planes_to_array.js";
|
|
5
|
+
import { bvh32_from_indexed_geometry } from "../../bvh/buffered/bvh32_from_indexed_geometry.js";
|
|
6
|
+
import { bvh32_from_unindexed_geometry } from "../../bvh/buffered/bvh32_from_unindexed_geometry.js";
|
|
6
7
|
import { deinterleaveBufferAttribute } from "../deinterleaveBufferAttribute.js";
|
|
8
|
+
import { bvh32_geometry_overlap_clipping_volume } from "./bvh32_geometry_overlap_clipping_volume.js";
|
|
9
|
+
import { bvh32_geometry_raycast } from "./bvh32_geometry_raycast.js";
|
|
10
|
+
|
|
11
|
+
const scratch_planes = []
|
|
7
12
|
|
|
8
13
|
export class GeometrySpatialQueryAccelerator {
|
|
9
14
|
constructor(cache_size = 100 * 1024 * 1024) {
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
*
|
|
13
|
-
* @type {Cache<THREE.BufferGeometry,
|
|
18
|
+
* @type {Cache<THREE.BufferGeometry, BinaryUint32BVH>}
|
|
14
19
|
*/
|
|
15
20
|
this.cache = new Cache({
|
|
16
21
|
maxWeight: cache_size,
|
|
@@ -22,15 +27,13 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
22
27
|
},
|
|
23
28
|
/**
|
|
24
29
|
*
|
|
25
|
-
* @param {
|
|
30
|
+
* @param {BinaryUint32BVH} tree
|
|
26
31
|
*/
|
|
27
32
|
valueWeigher(tree) {
|
|
28
33
|
return tree.estimateByteSize();
|
|
29
34
|
}
|
|
30
35
|
});
|
|
31
36
|
|
|
32
|
-
this.__visitor_clip = new ClippingPlaneContainmentComputingVisitor();
|
|
33
|
-
this.__visitor_raycast = new RaycastNearestHitComputingVisitor();
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
/**
|
|
@@ -53,23 +56,46 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
53
56
|
*
|
|
54
57
|
* @param {THREE.BufferGeometry} geometry
|
|
55
58
|
* @param {Plane[]} planes
|
|
56
|
-
* @returns {
|
|
59
|
+
* @returns {boolean} true means some overlap exists, false otherwise
|
|
57
60
|
*/
|
|
58
61
|
queryContainmentViaClippingPlanes(geometry, planes) {
|
|
59
62
|
assert.notNull(geometry, 'geometry');
|
|
60
63
|
assert.defined(geometry, 'geometry');
|
|
61
64
|
|
|
65
|
+
|
|
62
66
|
const bvh = this.__acquireBVH(geometry);
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
read_three_planes_to_array(planes, scratch_planes);
|
|
69
|
+
|
|
70
|
+
const geometryIndices = geometry.getIndex()?.array;
|
|
71
|
+
const position_attribute = geometry.getAttribute('position');
|
|
72
|
+
|
|
73
|
+
let position_data;
|
|
74
|
+
let stride = 3;
|
|
75
|
+
let position_data_offset = 0;
|
|
76
|
+
|
|
77
|
+
if (position_attribute.isInterleavedBufferAttribute) {
|
|
65
78
|
|
|
66
|
-
|
|
67
|
-
this.__visitor_clip.setPlanes(planes);
|
|
68
|
-
this.__visitor_clip.setRoot(bvh);
|
|
79
|
+
position_data = position_attribute.data.array;
|
|
69
80
|
|
|
70
|
-
|
|
81
|
+
stride = position_attribute.data.stride;
|
|
82
|
+
position_data_offset = position_attribute.offset;
|
|
83
|
+
|
|
84
|
+
} else {
|
|
71
85
|
|
|
72
|
-
|
|
86
|
+
position_data = position_attribute.array;
|
|
87
|
+
|
|
88
|
+
stride = 3;
|
|
89
|
+
position_data_offset = 0;
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return bvh32_geometry_overlap_clipping_volume(
|
|
94
|
+
bvh,
|
|
95
|
+
position_data, position_data_offset, stride,
|
|
96
|
+
geometryIndices,
|
|
97
|
+
scratch_planes, 0, planes.length
|
|
98
|
+
);
|
|
73
99
|
}
|
|
74
100
|
|
|
75
101
|
/**
|
|
@@ -119,11 +145,33 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
119
145
|
return false;
|
|
120
146
|
}
|
|
121
147
|
|
|
122
|
-
|
|
148
|
+
const geometryIndices = geometry.getIndex()?.array;
|
|
149
|
+
const position_attribute = geometry.getAttribute('position');
|
|
150
|
+
|
|
151
|
+
let position_data;
|
|
152
|
+
let stride = 3;
|
|
153
|
+
let position_data_offset = 0;
|
|
154
|
+
|
|
155
|
+
if (position_attribute.isInterleavedBufferAttribute) {
|
|
156
|
+
|
|
157
|
+
position_data = position_attribute.data.array;
|
|
123
158
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
159
|
+
stride = position_attribute.data.stride;
|
|
160
|
+
position_data_offset = position_attribute.offset;
|
|
161
|
+
|
|
162
|
+
} else {
|
|
163
|
+
|
|
164
|
+
position_data = position_attribute.array;
|
|
165
|
+
|
|
166
|
+
stride = 3;
|
|
167
|
+
position_data_offset = 0;
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return bvh32_geometry_raycast(
|
|
172
|
+
destination, bvh,
|
|
173
|
+
position_data, position_data_offset, stride,
|
|
174
|
+
geometryIndices,
|
|
127
175
|
ray_origin_x,
|
|
128
176
|
ray_origin_y,
|
|
129
177
|
ray_origin_z,
|
|
@@ -132,16 +180,6 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
132
180
|
ray_direction_z
|
|
133
181
|
);
|
|
134
182
|
|
|
135
|
-
bvh.traversePreOrderStack(this.__visitor_raycast, 0);
|
|
136
|
-
|
|
137
|
-
if (this.__visitor_raycast.isHitFound()) {
|
|
138
|
-
|
|
139
|
-
destination.copy(this.__visitor_raycast.getNearestHit());
|
|
140
|
-
|
|
141
|
-
return true;
|
|
142
|
-
} else {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
183
|
}
|
|
146
184
|
|
|
147
185
|
/**
|
|
@@ -169,7 +207,7 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
169
207
|
/**
|
|
170
208
|
* @private
|
|
171
209
|
* @param {THREE.BufferGeometry} geometry
|
|
172
|
-
* @returns {
|
|
210
|
+
* @returns {BinaryUint32BVH}
|
|
173
211
|
*/
|
|
174
212
|
__acquireBVH(geometry) {
|
|
175
213
|
assert.notNull(geometry, 'geometry');
|
|
@@ -191,7 +229,7 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
191
229
|
/**
|
|
192
230
|
* @private
|
|
193
231
|
* @param {THREE.BufferGeometry} geometry
|
|
194
|
-
* @returns {
|
|
232
|
+
* @returns {BinaryUint32BVH}
|
|
195
233
|
*/
|
|
196
234
|
__buildBVH(geometry) {
|
|
197
235
|
const position_attribute = geometry.getAttribute('position');
|
|
@@ -200,14 +238,19 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
200
238
|
const de_interleaved_position_attribute = deinterleaveBufferAttribute(position_attribute);
|
|
201
239
|
const vertices = de_interleaved_position_attribute.array;
|
|
202
240
|
|
|
241
|
+
const bvh = new BinaryUint32BVH();
|
|
242
|
+
|
|
203
243
|
if (index_attribute === undefined || index_attribute === null) {
|
|
204
|
-
|
|
205
|
-
}
|
|
244
|
+
bvh32_from_unindexed_geometry(bvh, vertices);
|
|
245
|
+
} else {
|
|
246
|
+
|
|
247
|
+
const de_interleaved_index_attribute = deinterleaveBufferAttribute(index_attribute);
|
|
248
|
+
const indices = de_interleaved_index_attribute.array;
|
|
206
249
|
|
|
207
|
-
|
|
208
|
-
|
|
250
|
+
bvh32_from_indexed_geometry(bvh, vertices, indices);
|
|
251
|
+
}
|
|
209
252
|
|
|
210
|
-
return
|
|
253
|
+
return bvh;
|
|
211
254
|
}
|
|
212
255
|
|
|
213
256
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { assert } from "../../../../../core/assert.js";
|
|
2
|
+
import {
|
|
3
|
+
bvh32_query_user_data_overlaps_clipping_volume
|
|
4
|
+
} from "../../../../../core/bvh2/binary/2/bvh32_query_user_data_overlaps_clipping_volume.js";
|
|
5
|
+
import {
|
|
6
|
+
triangle_intersects_clipping_volume
|
|
7
|
+
} from "../../../../../core/geom/3d/triangle/triangle_intersects_clipping_volume.js";
|
|
8
|
+
|
|
9
|
+
const scratch_array = []
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {BinaryUint32BVH} bvh
|
|
14
|
+
* @param {number[]|ArrayLike<number>} vertices
|
|
15
|
+
* @param {number} vertex_offset Unless you're using an interleaved buffer of some kind, this will be 0
|
|
16
|
+
* @param {number} vertex_stride Unless you're using an interleaved buffer, this should be 3
|
|
17
|
+
* @param {number[]|ArrayLike<number>|undefined} indices if this is set to undefined - implicit indexing will be used
|
|
18
|
+
* @param {number[]|Float32Array} planes
|
|
19
|
+
* @param {number} planes_offset
|
|
20
|
+
* @param {number} plane_count
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export function bvh32_geometry_overlap_clipping_volume(
|
|
24
|
+
bvh,
|
|
25
|
+
vertices, vertex_offset, vertex_stride,
|
|
26
|
+
indices,
|
|
27
|
+
planes, planes_offset, plane_count
|
|
28
|
+
) {
|
|
29
|
+
|
|
30
|
+
const hit_count = bvh32_query_user_data_overlaps_clipping_volume(
|
|
31
|
+
scratch_array, 0,
|
|
32
|
+
bvh,
|
|
33
|
+
planes, planes_offset, plane_count
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
let a, b, c;
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < hit_count; i++) {
|
|
39
|
+
const triangle_index = scratch_array[i];
|
|
40
|
+
|
|
41
|
+
const index3 = triangle_index * 3;
|
|
42
|
+
|
|
43
|
+
if (indices !== undefined) {
|
|
44
|
+
assert.lessThan(index3 + 2, indices.length, 'triangle index overflow, possibly geometry changed but tree was not rebuilt?');
|
|
45
|
+
|
|
46
|
+
a = indices[index3];
|
|
47
|
+
b = indices[index3 + 1];
|
|
48
|
+
c = indices[index3 + 2];
|
|
49
|
+
} else {
|
|
50
|
+
// implicit indices
|
|
51
|
+
a = index3;
|
|
52
|
+
b = index3 + 1;
|
|
53
|
+
c = index3 + 2;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const a_address = a * vertex_stride + vertex_offset;
|
|
57
|
+
const b_address = b * vertex_stride + vertex_offset;
|
|
58
|
+
const c_address = c * vertex_stride + vertex_offset;
|
|
59
|
+
|
|
60
|
+
assert.lessThan(a_address + 2, vertices.length, 'a-vertex overflow');
|
|
61
|
+
assert.lessThan(b_address + 2, vertices.length, 'b-vertex overflow');
|
|
62
|
+
assert.lessThan(c_address + 2, vertices.length, 'c-vertex overflow');
|
|
63
|
+
|
|
64
|
+
const ax = vertices[a_address];
|
|
65
|
+
const ay = vertices[a_address + 1];
|
|
66
|
+
const az = vertices[a_address + 2];
|
|
67
|
+
|
|
68
|
+
const bx = vertices[b_address];
|
|
69
|
+
const by = vertices[b_address + 1];
|
|
70
|
+
const bz = vertices[b_address + 2];
|
|
71
|
+
|
|
72
|
+
const cx = vertices[c_address];
|
|
73
|
+
const cy = vertices[c_address + 1];
|
|
74
|
+
const cz = vertices[c_address + 2];
|
|
75
|
+
|
|
76
|
+
if (triangle_intersects_clipping_volume(
|
|
77
|
+
planes, planes_offset, plane_count,
|
|
78
|
+
ax, ay, az,
|
|
79
|
+
bx, by, bz,
|
|
80
|
+
cx, cy, cz
|
|
81
|
+
)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { assert } from "../../../../../core/assert.js";
|
|
2
|
+
import { bvh32_query_user_data_ray } from "../../../../../core/bvh2/binary/2/bvh32_query_user_data_ray.js";
|
|
3
|
+
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
4
|
+
import { computeTriangleRayIntersection } from "../../../../../core/geom/3d/triangle/computeTriangleRayIntersection.js";
|
|
5
|
+
|
|
6
|
+
const scratch_array = []
|
|
7
|
+
const scratch_hit = new SurfacePoint3()
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {SurfacePoint3} result
|
|
12
|
+
* @param {BinaryUint32BVH} bvh
|
|
13
|
+
* @param {number[]|ArrayLike<number>} vertices
|
|
14
|
+
* @param {number} vertex_offset Unless you're using an interleaved buffer of some kind, this will be 0
|
|
15
|
+
* @param {number} vertex_stride Unless you're using an interleaved buffer, this should be 3
|
|
16
|
+
* @param {number[]|ArrayLike<number>|undefined} indices if this is set to undefined - implicit indexing will be used
|
|
17
|
+
* @param {number} originX
|
|
18
|
+
* @param {number} originY
|
|
19
|
+
* @param {number} originZ
|
|
20
|
+
* @param {number} directionX
|
|
21
|
+
* @param {number} directionY
|
|
22
|
+
* @param {number} directionZ
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
export function bvh32_geometry_raycast(
|
|
26
|
+
result,
|
|
27
|
+
bvh,
|
|
28
|
+
vertices, vertex_offset, vertex_stride,
|
|
29
|
+
indices,
|
|
30
|
+
originX, originY, originZ,
|
|
31
|
+
directionX, directionY, directionZ
|
|
32
|
+
) {
|
|
33
|
+
let hit_found = false;
|
|
34
|
+
|
|
35
|
+
const hit_count = bvh32_query_user_data_ray(
|
|
36
|
+
scratch_array, 0,
|
|
37
|
+
bvh,
|
|
38
|
+
originX, originY, originZ,
|
|
39
|
+
directionX, directionY, directionZ
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
let best_distance = Infinity;
|
|
43
|
+
|
|
44
|
+
let a, b, c;
|
|
45
|
+
|
|
46
|
+
for (let i = 0; i < hit_count; i++) {
|
|
47
|
+
const triangle_index = scratch_array[i];
|
|
48
|
+
|
|
49
|
+
const index3 = triangle_index * 3;
|
|
50
|
+
|
|
51
|
+
if (indices !== undefined) {
|
|
52
|
+
assert.lessThan(index3 + 2, indices.length, 'triangle index overflow, possibly geometry changed but tree was not rebuilt?');
|
|
53
|
+
|
|
54
|
+
a = indices[index3];
|
|
55
|
+
b = indices[index3 + 1];
|
|
56
|
+
c = indices[index3 + 2];
|
|
57
|
+
} else {
|
|
58
|
+
// implicit indices
|
|
59
|
+
a = index3;
|
|
60
|
+
b = index3 + 1;
|
|
61
|
+
c = index3 + 2;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const a_address = a * vertex_stride + vertex_offset;
|
|
65
|
+
const b_address = b * vertex_stride + vertex_offset;
|
|
66
|
+
const c_address = c * vertex_stride + vertex_offset;
|
|
67
|
+
|
|
68
|
+
assert.lessThan(a_address + 2, vertices.length, 'a-vertex overflow');
|
|
69
|
+
assert.lessThan(b_address + 2, vertices.length, 'b-vertex overflow');
|
|
70
|
+
assert.lessThan(c_address + 2, vertices.length, 'c-vertex overflow');
|
|
71
|
+
|
|
72
|
+
const ax = vertices[a_address];
|
|
73
|
+
const ay = vertices[a_address + 1];
|
|
74
|
+
const az = vertices[a_address + 2];
|
|
75
|
+
|
|
76
|
+
const bx = vertices[b_address];
|
|
77
|
+
const by = vertices[b_address + 1];
|
|
78
|
+
const bz = vertices[b_address + 2];
|
|
79
|
+
|
|
80
|
+
const cx = vertices[c_address];
|
|
81
|
+
const cy = vertices[c_address + 1];
|
|
82
|
+
const cz = vertices[c_address + 2];
|
|
83
|
+
|
|
84
|
+
const triangle_hit_found = computeTriangleRayIntersection(
|
|
85
|
+
scratch_hit,
|
|
86
|
+
originX, originY, originZ,
|
|
87
|
+
directionX, directionY, directionZ,
|
|
88
|
+
ax, ay, az,
|
|
89
|
+
bx, by, bz,
|
|
90
|
+
cx, cy, cz
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
if (!triangle_hit_found) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
hit_found = true;
|
|
98
|
+
|
|
99
|
+
const distance_sqr = scratch_hit.position._distanceSqrTo(originX, originY, originZ);
|
|
100
|
+
|
|
101
|
+
if (distance_sqr < best_distance) {
|
|
102
|
+
best_distance = distance_sqr;
|
|
103
|
+
result.copy(scratch_hit);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return hit_found;
|
|
108
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { min3 } from "../../../../../core/math/min3.js";
|
|
1
|
+
import { bvh32_set_leaf_from_triangle } from "./bvh32_set_leaf_from_triangle.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
*
|
|
@@ -23,36 +22,11 @@ export function bvh32_from_indexed_geometry(bvh, vertices, indices) {
|
|
|
23
22
|
const iB = indices[index3 + 1];
|
|
24
23
|
const iC = indices[index3 + 2];
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
const b = iB * 3;
|
|
28
|
-
const c = iC * 3;
|
|
29
|
-
|
|
30
|
-
// read actual positions of each vertex
|
|
31
|
-
const aX = vertices[a];
|
|
32
|
-
const aY = vertices[a + 1];
|
|
33
|
-
const aZ = vertices[a + 2];
|
|
34
|
-
|
|
35
|
-
const bX = vertices[b];
|
|
36
|
-
const bY = vertices[b + 1];
|
|
37
|
-
const bZ = vertices[b + 2];
|
|
38
|
-
|
|
39
|
-
const cX = vertices[c];
|
|
40
|
-
const cY = vertices[c + 1];
|
|
41
|
-
const cZ = vertices[c + 2];
|
|
42
|
-
|
|
43
|
-
// compute bounds of the triangle
|
|
44
|
-
const x0 = min3(aX, bX, cX);
|
|
45
|
-
const y0 = min3(aY, bY, cY);
|
|
46
|
-
const z0 = min3(aZ, bZ, cZ);
|
|
47
|
-
|
|
48
|
-
const x1 = max3(aX, bX, cX);
|
|
49
|
-
const y1 = max3(aY, bY, cY);
|
|
50
|
-
const z1 = max3(aZ, bZ, cZ);
|
|
51
|
-
|
|
52
|
-
bvh.setLeafData(i, i, x0, y0, z0, x1, y1, z1)
|
|
25
|
+
bvh32_set_leaf_from_triangle(bvh, i, vertices, iA, iB, iC);
|
|
53
26
|
}
|
|
54
27
|
|
|
55
28
|
// finalize build
|
|
56
29
|
// bvh.sort_morton(MATRIX_4_IDENTITY);
|
|
57
30
|
bvh.build();
|
|
58
|
-
}
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { bvh32_set_leaf_from_triangle } from "./bvh32_set_leaf_from_triangle.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {BinaryUint32BVH} bvh
|
|
6
|
+
* @param {Float32Array} vertices
|
|
7
|
+
*/
|
|
8
|
+
export function bvh32_from_unindexed_geometry(bvh, vertices) {
|
|
9
|
+
|
|
10
|
+
const triangle_count = indices.length / 3;
|
|
11
|
+
|
|
12
|
+
bvh.setLeafCount(triangle_count);
|
|
13
|
+
bvh.initialize_structure();
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < triangle_count; i++) {
|
|
16
|
+
|
|
17
|
+
const index3 = i * 3;
|
|
18
|
+
|
|
19
|
+
// generate triangle vertex indices
|
|
20
|
+
const iA = index3;
|
|
21
|
+
const iB = index3 + 1;
|
|
22
|
+
const iC = index3 + 2;
|
|
23
|
+
|
|
24
|
+
bvh32_set_leaf_from_triangle(bvh, i, vertices, iA, iB, iC);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// finalize build
|
|
28
|
+
// bvh.sort_morton(MATRIX_4_IDENTITY);
|
|
29
|
+
bvh.build();
|
|
30
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { max3 } from "../../../../../core/math/max3.js";
|
|
2
|
+
import { min3 } from "../../../../../core/math/min3.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {BinaryUint32BVH} bvh
|
|
7
|
+
* @param {number} triangle_index
|
|
8
|
+
* @param {number[]|Float32Array} vertices
|
|
9
|
+
* @param {number} a_index
|
|
10
|
+
* @param {number} b_index
|
|
11
|
+
* @param {number} c_index
|
|
12
|
+
*/
|
|
13
|
+
export function bvh32_set_leaf_from_triangle(bvh, triangle_index, vertices, a_index, b_index, c_index) {
|
|
14
|
+
const a = a_index * 3;
|
|
15
|
+
const b = b_index * 3;
|
|
16
|
+
const c = c_index * 3;
|
|
17
|
+
|
|
18
|
+
// read actual positions of each vertex
|
|
19
|
+
const aX = vertices[a];
|
|
20
|
+
const aY = vertices[a + 1];
|
|
21
|
+
const aZ = vertices[a + 2];
|
|
22
|
+
|
|
23
|
+
const bX = vertices[b];
|
|
24
|
+
const bY = vertices[b + 1];
|
|
25
|
+
const bZ = vertices[b + 2];
|
|
26
|
+
|
|
27
|
+
const cX = vertices[c];
|
|
28
|
+
const cY = vertices[c + 1];
|
|
29
|
+
const cZ = vertices[c + 2];
|
|
30
|
+
|
|
31
|
+
// compute bounds of the triangle
|
|
32
|
+
const x0 = min3(aX, bX, cX);
|
|
33
|
+
const y0 = min3(aY, bY, cY);
|
|
34
|
+
const z0 = min3(aZ, bZ, cZ);
|
|
35
|
+
|
|
36
|
+
const x1 = max3(aX, bX, cX);
|
|
37
|
+
const y1 = max3(aY, bY, cY);
|
|
38
|
+
const z1 = max3(aZ, bZ, cZ);
|
|
39
|
+
|
|
40
|
+
bvh.setLeafData(triangle_index, triangle_index, x0, y0, z0, x1, y1, z1)
|
|
41
|
+
}
|
|
@@ -26,7 +26,7 @@ import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
|
26
26
|
import { arrayQuickSort } from "../../../../core/collection/array/arrayQuickSort.js";
|
|
27
27
|
import { arraySwapElements } from "../../../../core/collection/array/arraySwapElements.js";
|
|
28
28
|
import { read_cluster_frustum_corners } from "../../../../core/geom/3d/frustum/read_cluster_frustum_corners.js";
|
|
29
|
-
import {
|
|
29
|
+
import { read_three_planes_to_array } from "../../../../core/geom/3d/frustum/read_three_planes_to_array.js";
|
|
30
30
|
import { slice_frustum_linear_to_points } from "../../../../core/geom/3d/frustum/slice_frustum_linear_to_points.js";
|
|
31
31
|
import { v3_morton_encode_transformed } from "../../../../core/geom/3d/morton/v3_morton_encode_transformed.js";
|
|
32
32
|
import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
|
|
@@ -727,7 +727,7 @@ export class LightManager {
|
|
|
727
727
|
|
|
728
728
|
const nodes = [];
|
|
729
729
|
|
|
730
|
-
|
|
730
|
+
read_three_planes_to_array(this.__view_frustum.planes, scratch_frustum_planes)
|
|
731
731
|
|
|
732
732
|
/*
|
|
733
733
|
Search is done in 2 phases:
|
|
@@ -69,7 +69,7 @@ export function query_bvh_frustum_from_texture(
|
|
|
69
69
|
) {
|
|
70
70
|
let result = 0;
|
|
71
71
|
|
|
72
|
-
const binary_node_count = bvh.
|
|
72
|
+
const binary_node_count = bvh.binary_node_count;
|
|
73
73
|
|
|
74
74
|
if (binary_node_count <= 0) {
|
|
75
75
|
// this should not happen
|
|
@@ -88,7 +88,7 @@ export function query_bvh_frustum_from_texture(
|
|
|
88
88
|
*/
|
|
89
89
|
stack[stack_top] = 0;
|
|
90
90
|
|
|
91
|
-
const last_valid_index = binary_node_count + bvh.
|
|
91
|
+
const last_valid_index = binary_node_count + bvh.leaf_node_count;
|
|
92
92
|
|
|
93
93
|
const float32 = bvh.float32;
|
|
94
94
|
const uint32 = bvh.uint32;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { IncrementalDeltaSet } from "../visibility/IncrementalDeltaSet.js";
|
|
2
|
-
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
3
|
-
import { CameraViewFlags } from "./CameraViewFlags.js";
|
|
4
1
|
import { Frustum } from "three";
|
|
5
|
-
import { read_frustum_planes_to_array } from "../../../../core/geom/3d/frustum/read_frustum_planes_to_array.js";
|
|
6
|
-
import Signal from "../../../../core/events/signal/Signal.js";
|
|
7
|
-
import { compare_three_objects } from "../../three/compare_three_objects.js";
|
|
8
|
-
import { frustum_from_camera } from "../../ecs/camera/frustum_from_camera.js";
|
|
9
2
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
10
3
|
import { array_remove_first } from "../../../../core/collection/array/array_remove_first.js";
|
|
4
|
+
import Signal from "../../../../core/events/signal/Signal.js";
|
|
5
|
+
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
6
|
+
import { read_three_planes_to_array } from "../../../../core/geom/3d/frustum/read_three_planes_to_array.js";
|
|
7
|
+
import { frustum_from_camera } from "../../ecs/camera/frustum_from_camera.js";
|
|
8
|
+
import { compare_three_objects } from "../../three/compare_three_objects.js";
|
|
9
|
+
import { IncrementalDeltaSet } from "../visibility/IncrementalDeltaSet.js";
|
|
10
|
+
import { CameraViewFlags } from "./CameraViewFlags.js";
|
|
11
11
|
|
|
12
12
|
const DEFAULT_FLAGS = CameraViewFlags.Active
|
|
13
13
|
| CameraViewFlags.AdaptivePlaneNear
|
|
@@ -97,7 +97,7 @@ export class CameraView {
|
|
|
97
97
|
frustum_from_camera(camera, scratch_frustum, false);
|
|
98
98
|
|
|
99
99
|
// update view definition
|
|
100
|
-
|
|
100
|
+
read_three_planes_to_array(scratch_frustum.planes, this.frustum);
|
|
101
101
|
|
|
102
102
|
// read projection matrix
|
|
103
103
|
// TODO
|