@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,59 +0,0 @@
|
|
|
1
|
-
import { noop } from "../../function/Functions.js";
|
|
2
|
-
import { IndexedBinaryBVHVisitor } from "./IndexedBinaryBVHVisitor.js";
|
|
3
|
-
import { NodeType } from "./NodeType.js";
|
|
4
|
-
import { aabb3_intersects_ray } from "../../geom/3d/aabb/aabb3_intersects_ray.js";
|
|
5
|
-
|
|
6
|
-
export class RayLeafIntersectionVisitor extends IndexedBinaryBVHVisitor {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
this.callback = noop;
|
|
10
|
-
this.callbackThisArg = null;
|
|
11
|
-
|
|
12
|
-
this.originX = 0;
|
|
13
|
-
this.originY = 0;
|
|
14
|
-
this.originZ = 0;
|
|
15
|
-
|
|
16
|
-
this.directionX = 0;
|
|
17
|
-
this.directionY = 0;
|
|
18
|
-
this.directionZ = 0;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @type {IndexedBinaryBVH}
|
|
23
|
-
*/
|
|
24
|
-
this.root = null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
visit(address, type) {
|
|
28
|
-
const root = this.root;
|
|
29
|
-
|
|
30
|
-
const data = root.data;
|
|
31
|
-
const binaryNodeCount = root.binaryNodeCount;
|
|
32
|
-
|
|
33
|
-
const x0 = data[address];
|
|
34
|
-
const y0 = data[address + 1];
|
|
35
|
-
const z0 = data[address + 2];
|
|
36
|
-
const x1 = data[address + 3];
|
|
37
|
-
const y1 = data[address + 4];
|
|
38
|
-
const z1 = data[address + 5];
|
|
39
|
-
|
|
40
|
-
const intersectionFound = aabb3_intersects_ray(x0, y0, z0, x1, y1, z1,
|
|
41
|
-
this.originX, this.originY, this.originZ,
|
|
42
|
-
this.directionX, this.directionY, this.directionZ
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (!intersectionFound) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (type === NodeType.LEAF) {
|
|
50
|
-
const value = address / 6 - binaryNodeCount;
|
|
51
|
-
|
|
52
|
-
this.callback.call(this.callbackThisArg, value, address, type);
|
|
53
|
-
|
|
54
|
-
return false;
|
|
55
|
-
} else {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { aabb3_intersects_frustum_array } from "./aabb3_intersects_frustum_array.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {Float32Array|number[]} aabb
|
|
6
|
-
* @param {Float32Array|number[]} frustum
|
|
7
|
-
* @return {boolean}
|
|
8
|
-
*/
|
|
9
|
-
export function aabb3_array_intersects_frustum_array(aabb, frustum) {
|
|
10
|
-
|
|
11
|
-
const x0 = aabb[0];
|
|
12
|
-
const y0 = aabb[1];
|
|
13
|
-
const z0 = aabb[2];
|
|
14
|
-
const x1 = aabb[3];
|
|
15
|
-
const y1 = aabb[4];
|
|
16
|
-
const z1 = aabb[5];
|
|
17
|
-
|
|
18
|
-
return aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum);
|
|
19
|
-
}
|
|
20
|
-
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { aabb3_compute_distance_above_plane_max } from "./aabb3_compute_distance_above_plane_max.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {number} x0
|
|
6
|
-
* @param {number} y0
|
|
7
|
-
* @param {number} z0
|
|
8
|
-
* @param {number} x1
|
|
9
|
-
* @param {number} y1
|
|
10
|
-
* @param {number} z1
|
|
11
|
-
* @param {ArrayLike<number>|number[]|Float32Array|Float64Array} frustum
|
|
12
|
-
* @return {boolean}
|
|
13
|
-
*/
|
|
14
|
-
export function aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum) {
|
|
15
|
-
for (let i = 0; i < 24; i += 4) {
|
|
16
|
-
|
|
17
|
-
const plane_x = frustum[i];
|
|
18
|
-
const plane_y = frustum[i + 1];
|
|
19
|
-
const plane_z = frustum[i + 2];
|
|
20
|
-
const plane_w = frustum[i + 3];
|
|
21
|
-
|
|
22
|
-
const plane_distance = aabb3_compute_distance_above_plane_max(
|
|
23
|
-
plane_x, plane_y, plane_z, plane_w,
|
|
24
|
-
x0, y0, z0,
|
|
25
|
-
x1, y1, z1
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
if (plane_distance < 0) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
}
|
package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { aabb3_compute_plane_side } from "../../../../../core/geom/3d/aabb/aabb3_compute_plane_side.js";
|
|
2
|
-
import { NodeType } from "../../../../../core/bvh2/binary/NodeType.js";
|
|
3
|
-
import { computeTrianglePlaneSide } from "../../../../../core/geom/3d/triangle/computeTrianglePlaneSide.js";
|
|
4
|
-
import { GeometrySpatialAcceleratorVisitor } from "./GeometryVisitor.js";
|
|
5
|
-
|
|
6
|
-
export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcceleratorVisitor {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @private
|
|
12
|
-
* @type {Plane[]}
|
|
13
|
-
*/
|
|
14
|
-
this.planes = [];
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @private
|
|
19
|
-
* @type {number}
|
|
20
|
-
*/
|
|
21
|
-
this.plane_count = 0;
|
|
22
|
-
|
|
23
|
-
this.__hit_count_in = 0;
|
|
24
|
-
this.__hit_count_out = 0;
|
|
25
|
-
this.__hit_count_intersect = 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
reset() {
|
|
29
|
-
this.__hit_count_in = 0;
|
|
30
|
-
this.__hit_count_intersect = 0;
|
|
31
|
-
this.__hit_count_out = 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @returns {number}
|
|
37
|
-
*/
|
|
38
|
-
getContainment() {
|
|
39
|
-
if (this.__hit_count_out === 0) {
|
|
40
|
-
if (this.__hit_count_intersect > 0) {
|
|
41
|
-
return 0;
|
|
42
|
-
} else {
|
|
43
|
-
// fully in
|
|
44
|
-
return 1;
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
if (this.__hit_count_intersect > 0 || this.__hit_count_in > 0) {
|
|
48
|
-
return 0;
|
|
49
|
-
} else {
|
|
50
|
-
// fully out
|
|
51
|
-
return -1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {Plane[]} planes
|
|
58
|
-
*/
|
|
59
|
-
setPlanes(planes) {
|
|
60
|
-
this.planes = planes;
|
|
61
|
-
this.plane_count = planes.length;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
visit(address, type) {
|
|
66
|
-
const root = this.__root;
|
|
67
|
-
|
|
68
|
-
const data = root.data;
|
|
69
|
-
const binaryNodeCount = root.binaryNodeCount;
|
|
70
|
-
|
|
71
|
-
const planes = this.planes;
|
|
72
|
-
const plane_count = this.plane_count;
|
|
73
|
-
|
|
74
|
-
let intersect_flag = false;
|
|
75
|
-
if (type === NodeType.LEAF) {
|
|
76
|
-
// check triangle intersection
|
|
77
|
-
|
|
78
|
-
const index = address / 6 - binaryNodeCount;
|
|
79
|
-
|
|
80
|
-
const index3 = index * 3;
|
|
81
|
-
|
|
82
|
-
const indices = this.__buffer_indices;
|
|
83
|
-
|
|
84
|
-
const a = indices[index3];
|
|
85
|
-
const b = indices[index3 + 1];
|
|
86
|
-
const c = indices[index3 + 2];
|
|
87
|
-
|
|
88
|
-
const vertices = this.__buffer_vertices;
|
|
89
|
-
|
|
90
|
-
const stride = this.__buffer_vertex_stride;
|
|
91
|
-
const offset = this.__buffer_position_offset;
|
|
92
|
-
|
|
93
|
-
const a_address = a * stride + offset;
|
|
94
|
-
const b_address = b * stride + offset;
|
|
95
|
-
const c_address = c * stride + offset;
|
|
96
|
-
|
|
97
|
-
const ax = vertices[a_address];
|
|
98
|
-
const ay = vertices[a_address + 1];
|
|
99
|
-
const az = vertices[a_address + 2];
|
|
100
|
-
|
|
101
|
-
const bx = vertices[b_address];
|
|
102
|
-
const by = vertices[b_address + 1];
|
|
103
|
-
const bz = vertices[b_address + 2];
|
|
104
|
-
|
|
105
|
-
const cx = vertices[c_address];
|
|
106
|
-
const cy = vertices[c_address + 1];
|
|
107
|
-
const cz = vertices[c_address + 2];
|
|
108
|
-
|
|
109
|
-
for (let i = 0; i < plane_count; i++) {
|
|
110
|
-
const plane = planes[i];
|
|
111
|
-
|
|
112
|
-
const plane_normal_x = plane.normal.x;
|
|
113
|
-
const plane_normal_y = plane.normal.y;
|
|
114
|
-
const plane_normal_z = plane.normal.z;
|
|
115
|
-
const plane_constant = plane.constant;
|
|
116
|
-
|
|
117
|
-
const side = computeTrianglePlaneSide(
|
|
118
|
-
plane_normal_x,
|
|
119
|
-
plane_normal_y,
|
|
120
|
-
plane_normal_z,
|
|
121
|
-
plane_constant,
|
|
122
|
-
ax, ay, az,
|
|
123
|
-
bx, by, bz,
|
|
124
|
-
cx, cy, cz
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
if (side === -3) {
|
|
128
|
-
// fully outside
|
|
129
|
-
this.__hit_count_out++;
|
|
130
|
-
return false;
|
|
131
|
-
} else if (side < 3) {
|
|
132
|
-
intersect_flag = true;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (intersect_flag) {
|
|
137
|
-
this.__hit_count_intersect++;
|
|
138
|
-
} else {
|
|
139
|
-
this.__hit_count_in++;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return false;
|
|
143
|
-
} else {
|
|
144
|
-
// this is an intermediate node (binary node)
|
|
145
|
-
|
|
146
|
-
// check AABB intersection
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const x0 = data[address];
|
|
150
|
-
const y0 = data[address + 1];
|
|
151
|
-
const z0 = data[address + 2];
|
|
152
|
-
const x1 = data[address + 3];
|
|
153
|
-
const y1 = data[address + 4];
|
|
154
|
-
const z1 = data[address + 5];
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
for (let i = 0; i < plane_count; i++) {
|
|
158
|
-
const plane = planes[i];
|
|
159
|
-
|
|
160
|
-
const plane_normal_x = plane.normal.x;
|
|
161
|
-
const plane_normal_y = plane.normal.y;
|
|
162
|
-
const plane_normal_z = plane.normal.z;
|
|
163
|
-
const plane_constant = plane.constant;
|
|
164
|
-
|
|
165
|
-
const side = aabb3_compute_plane_side(
|
|
166
|
-
plane_normal_x,
|
|
167
|
-
plane_normal_y,
|
|
168
|
-
plane_normal_z,
|
|
169
|
-
plane_constant,
|
|
170
|
-
|
|
171
|
-
x0, y0, z0,
|
|
172
|
-
x1, y1, z1
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
if (side === -2) {
|
|
176
|
-
this.__hit_count_out++;
|
|
177
|
-
|
|
178
|
-
return false;
|
|
179
|
-
} else if (side === 0) {
|
|
180
|
-
intersect_flag = true;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (intersect_flag) {
|
|
185
|
-
return true;
|
|
186
|
-
} else {
|
|
187
|
-
// no need to traverse further down, the whole node is in
|
|
188
|
-
this.__hit_count_in++;
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { IndexedBinaryBVHVisitor } from "../../../../../core/bvh2/binary/IndexedBinaryBVHVisitor.js";
|
|
2
|
-
|
|
3
|
-
export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor {
|
|
4
|
-
constructor() {
|
|
5
|
-
super();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @protected
|
|
10
|
-
* @type {THREE.BufferGeometry}
|
|
11
|
-
*/
|
|
12
|
-
this.__geometry = null;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @type {number[]}
|
|
17
|
-
* @protected
|
|
18
|
-
*/
|
|
19
|
-
this.__buffer_indices = null;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @type {number[]}
|
|
24
|
-
* @protected
|
|
25
|
-
*/
|
|
26
|
-
this.__buffer_vertices = null;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @type {number}
|
|
31
|
-
* @protected
|
|
32
|
-
*/
|
|
33
|
-
this.__buffer_vertex_stride = 3;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @type {number}
|
|
38
|
-
* @protected
|
|
39
|
-
*/
|
|
40
|
-
this.__buffer_position_offset = 0;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @protected
|
|
44
|
-
* @type {IndexedBinaryBVH}
|
|
45
|
-
*/
|
|
46
|
-
this.__root = null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param {IndexedBinaryBVH} root
|
|
51
|
-
*/
|
|
52
|
-
setRoot(root) {
|
|
53
|
-
this.__root = root;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param {THREE.BufferGeometry} geometry
|
|
59
|
-
*/
|
|
60
|
-
setGeometry(geometry) {
|
|
61
|
-
this.geometry = geometry;
|
|
62
|
-
|
|
63
|
-
const index_attribute = geometry.getIndex();
|
|
64
|
-
|
|
65
|
-
if (index_attribute) {
|
|
66
|
-
this.__buffer_indices = index_attribute.array;
|
|
67
|
-
} else {
|
|
68
|
-
// no index attribute
|
|
69
|
-
this.__buffer_indices = null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const position_attribute = geometry.getAttribute('position');
|
|
73
|
-
|
|
74
|
-
if (position_attribute.isInterleavedBufferAttribute) {
|
|
75
|
-
const data = position_attribute.data;
|
|
76
|
-
|
|
77
|
-
this.__buffer_vertices = data.array;
|
|
78
|
-
this.__buffer_vertex_stride = data.stride;
|
|
79
|
-
this.__buffer_position_offset = position_attribute.offset;
|
|
80
|
-
} else {
|
|
81
|
-
this.__buffer_vertices = position_attribute.array;
|
|
82
|
-
this.__buffer_vertex_stride = 3;
|
|
83
|
-
this.__buffer_position_offset = 0;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
2
|
-
import { NodeType } from "../../../../../core/bvh2/binary/NodeType.js";
|
|
3
|
-
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
4
|
-
import { computeTriangleRayIntersection } from "../../../../../core/geom/3d/triangle/computeTriangleRayIntersection.js";
|
|
5
|
-
import { GeometrySpatialAcceleratorVisitor } from "./GeometryVisitor.js";
|
|
6
|
-
import { aabb3_intersects_ray } from "../../../../../core/geom/3d/aabb/aabb3_intersects_ray.js";
|
|
7
|
-
import { assert } from "../../../../../core/assert.js";
|
|
8
|
-
|
|
9
|
-
export class RaycastNearestHitComputingVisitor extends GeometrySpatialAcceleratorVisitor {
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @type {number}
|
|
17
|
-
* @private
|
|
18
|
-
*/
|
|
19
|
-
this.__nearest_distance = Number.POSITIVE_INFINITY;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @readonly
|
|
23
|
-
* @type {SurfacePoint3}
|
|
24
|
-
* @private
|
|
25
|
-
*/
|
|
26
|
-
this.__nearest_hit = new SurfacePoint3();
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @readonly
|
|
30
|
-
* @type {SurfacePoint3}
|
|
31
|
-
* @private
|
|
32
|
-
*/
|
|
33
|
-
this.__temp_hit = new SurfacePoint3();
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @type {boolean}
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
this.__hit_found = false;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @readonly
|
|
44
|
-
* @type {Vector3}
|
|
45
|
-
* @private
|
|
46
|
-
*/
|
|
47
|
-
this.__ray_origin = new Vector3();
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @readonly
|
|
51
|
-
* @type {Vector3}
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
54
|
-
this.__ray_direction = new Vector3();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
* @param {number} origin_x
|
|
60
|
-
* @param {number} origin_y
|
|
61
|
-
* @param {number} origin_z
|
|
62
|
-
* @param {number} direction_x
|
|
63
|
-
* @param {number} direction_y
|
|
64
|
-
* @param {number} direction_z
|
|
65
|
-
*/
|
|
66
|
-
setRay(origin_x, origin_y, origin_z, direction_x, direction_y, direction_z) {
|
|
67
|
-
this.__ray_origin.set(
|
|
68
|
-
origin_x,
|
|
69
|
-
origin_y,
|
|
70
|
-
origin_z
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
this.__ray_direction.set(
|
|
74
|
-
direction_x,
|
|
75
|
-
direction_y,
|
|
76
|
-
direction_z
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
reset() {
|
|
81
|
-
this.__nearest_distance = Number.POSITIVE_INFINITY;
|
|
82
|
-
this.__hit_found = false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getNearestHit() {
|
|
86
|
-
return this.__nearest_hit;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
isHitFound() {
|
|
90
|
-
return this.__hit_found;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
visit(address, type) {
|
|
95
|
-
const root = this.__root;
|
|
96
|
-
|
|
97
|
-
const data = root.data;
|
|
98
|
-
const binaryNodeCount = root.binaryNodeCount;
|
|
99
|
-
|
|
100
|
-
const rayOrigin = this.__ray_origin;
|
|
101
|
-
const rayDirection = this.__ray_direction;
|
|
102
|
-
|
|
103
|
-
if (type === NodeType.LEAF) {
|
|
104
|
-
// do triangle test
|
|
105
|
-
|
|
106
|
-
const index = address / 6 - binaryNodeCount;
|
|
107
|
-
|
|
108
|
-
const index3 = index * 3;
|
|
109
|
-
|
|
110
|
-
const indices = this.__buffer_indices;
|
|
111
|
-
|
|
112
|
-
let a, b, c;
|
|
113
|
-
|
|
114
|
-
if (indices !== null) {
|
|
115
|
-
assert.lessThan(index3 + 2, indices.length, 'triangle index overflow, possibly geometry changed but tree was not rebuilt?');
|
|
116
|
-
|
|
117
|
-
a = indices[index3];
|
|
118
|
-
b = indices[index3 + 1];
|
|
119
|
-
c = indices[index3 + 2];
|
|
120
|
-
} else {
|
|
121
|
-
// implicit indices
|
|
122
|
-
a = index3;
|
|
123
|
-
b = index3 + 1;
|
|
124
|
-
c = index3 + 2;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const vertices = this.__buffer_vertices;
|
|
128
|
-
|
|
129
|
-
const stride = this.__buffer_vertex_stride;
|
|
130
|
-
const offset = this.__buffer_position_offset;
|
|
131
|
-
|
|
132
|
-
const a_address = a * stride + offset;
|
|
133
|
-
const b_address = b * stride + offset;
|
|
134
|
-
const c_address = c * stride + offset;
|
|
135
|
-
|
|
136
|
-
assert.lessThan(a_address + 2, vertices.length, 'a-vertex overflow');
|
|
137
|
-
assert.lessThan(b_address + 2, vertices.length, 'b-vertex overflow');
|
|
138
|
-
assert.lessThan(c_address + 2, vertices.length, 'c-vertex overflow');
|
|
139
|
-
|
|
140
|
-
const ax = vertices[a_address];
|
|
141
|
-
const ay = vertices[a_address + 1];
|
|
142
|
-
const az = vertices[a_address + 2];
|
|
143
|
-
|
|
144
|
-
const bx = vertices[b_address];
|
|
145
|
-
const by = vertices[b_address + 1];
|
|
146
|
-
const bz = vertices[b_address + 2];
|
|
147
|
-
|
|
148
|
-
const cx = vertices[c_address];
|
|
149
|
-
const cy = vertices[c_address + 1];
|
|
150
|
-
const cz = vertices[c_address + 2];
|
|
151
|
-
|
|
152
|
-
const temp_hit = this.__temp_hit;
|
|
153
|
-
|
|
154
|
-
if (computeTriangleRayIntersection(
|
|
155
|
-
temp_hit,
|
|
156
|
-
rayOrigin.x,
|
|
157
|
-
rayOrigin.y,
|
|
158
|
-
rayOrigin.z,
|
|
159
|
-
rayDirection.x,
|
|
160
|
-
rayDirection.y,
|
|
161
|
-
rayDirection.z,
|
|
162
|
-
ax, ay, az,
|
|
163
|
-
bx, by, bz,
|
|
164
|
-
cx, cy, cz
|
|
165
|
-
)) {
|
|
166
|
-
const d = temp_hit.position.distanceSqrTo(rayOrigin);
|
|
167
|
-
|
|
168
|
-
if (d < this.__nearest_distance) {
|
|
169
|
-
this.__nearest_hit.copy(temp_hit);
|
|
170
|
-
this.__nearest_hit.index = index;
|
|
171
|
-
|
|
172
|
-
this.__nearest_distance = d;
|
|
173
|
-
|
|
174
|
-
this.__hit_found = true;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return false;
|
|
180
|
-
|
|
181
|
-
} else {
|
|
182
|
-
// do AABB test
|
|
183
|
-
|
|
184
|
-
const x0 = data[address];
|
|
185
|
-
const y0 = data[address + 1];
|
|
186
|
-
const z0 = data[address + 2];
|
|
187
|
-
const x1 = data[address + 3];
|
|
188
|
-
const y1 = data[address + 4];
|
|
189
|
-
const z1 = data[address + 5];
|
|
190
|
-
|
|
191
|
-
return aabb3_intersects_ray(
|
|
192
|
-
x0, y0, z0,
|
|
193
|
-
x1, y1, z1,
|
|
194
|
-
|
|
195
|
-
rayOrigin.x,
|
|
196
|
-
rayOrigin.y,
|
|
197
|
-
rayOrigin.z,
|
|
198
|
-
|
|
199
|
-
rayDirection.x,
|
|
200
|
-
rayDirection.y,
|
|
201
|
-
rayDirection.z
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|