@woosh/meep-engine 2.34.41 → 2.34.45
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/core/bvh2/BinaryNode.js +10 -8
- package/core/bvh2/LeafNode.js +2 -1
- package/core/bvh2/aabb3/AABB3.js +879 -1059
- package/core/bvh2/aabb3/AABB3.spec.js +5 -7
- package/core/bvh2/aabb3/aabb3_array_intersects_ray.js +2 -2
- package/core/bvh2/aabb3/aabb3_box_surface_area_2.js +10 -0
- package/core/bvh2/aabb3/aabb3_compute_half_surface_area.js +16 -0
- package/core/bvh2/aabb3/aabb3_compute_surface_area.js +18 -0
- package/core/bvh2/aabb3/aabb3_expand_array.js +15 -0
- package/core/bvh2/aabb3/aabb3_intersect_aabb3.js +28 -0
- package/core/bvh2/aabb3/aabb3_intersect_ray_slab.js +73 -0
- package/core/bvh2/aabb3/{aabb3_intersects_frustum.js → aabb3_intersects_frustum_array.js} +16 -1
- package/core/bvh2/aabb3/aabb3_intersects_line_segment.js +79 -0
- package/core/bvh2/aabb3/aabb3_intersects_ray.js +92 -0
- package/core/bvh2/aabb3/{AABB3Math.spec.js → aabb3_intersects_ray.spec.js} +3 -3
- package/core/bvh2/aabb3/aabb3_intersects_ray_fast.js +176 -0
- package/core/bvh2/aabb3/aabb3_score_boxes_SAH.js +43 -0
- package/core/bvh2/aabb3/aabb_score_boxes_SAH_delta.js +37 -0
- package/core/bvh2/aabb3/deserializeAABB3.js +17 -0
- package/core/bvh2/aabb3/deserializeAABB3Encoded_v0.js +73 -0
- package/core/bvh2/aabb3/deserializeAABB3Quantized16Uint.js +36 -0
- package/core/bvh2/aabb3/serializeAABB3.js +13 -0
- package/core/bvh2/aabb3/serializeAABB3Quantized16Uint.js +33 -0
- package/core/bvh2/binary/2/BinaryUint32BVH.js +3 -3
- package/core/bvh2/binary/BinaryBVH.js +2 -2
- package/core/bvh2/binary/RayLeafIntersectionVisitor.js +2 -2
- package/core/bvh2/serialization/deserializeBinaryNode.js +1 -1
- package/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +2 -1
- package/core/bvh2/serialization/serializeBinaryNode.js +1 -1
- package/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +2 -1
- package/core/bvh2/transform/BottomUpOptimizingRebuilder.js +6 -5
- package/core/bvh2/transform/tryRotateSingleNode.js +2 -1
- package/core/geom/3d/frustum/{array_setFromProjectionMatrix.js → frustum_from_projection_matrix_array.js} +1 -1
- package/core/geom/3d/topology/TopoMesh.js +0 -8
- package/core/geom/3d/topology/TopoVertex.js +7 -6
- package/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +93 -5
- package/core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js +7 -4
- package/core/geom/3d/topology/simplify/quadratic/compute_edge_collapse_cost_quadratic.js +7 -1
- package/core/geom/3d/topology/simplify/simplifyTopoMesh.js +1 -14
- package/core/math/fabsf.js +8 -0
- package/engine/development/performance/MetricCollection.js +6 -0
- package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +1 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -2
- package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +23 -8
- package/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +2 -2
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +4 -0
- package/engine/graphics/micron/build/hierarchy/merge_patches.js +1 -1
- package/engine/graphics/micron/convert_three_object_to_micron.js +2 -0
- package/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +3 -2
- package/engine/graphics/micron/prototypeVirtualGeometry.js +12 -7
- package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +16 -43
- package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +5 -1
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +4 -10
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +16 -20
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +2 -2
- package/package.json +1 -1
- package/core/bvh2/aabb3/AABB3Math.js +0 -579
package/core/bvh2/aabb3/AABB3.js
CHANGED
|
@@ -6,941 +6,937 @@
|
|
|
6
6
|
import { aabb3_computeDistanceAbovePlane } from "../../geom/3d/aabb/aabb3_computeDistanceAbovePlane.js";
|
|
7
7
|
import { computeAABB3PlaneSide } from "../../geom/3d/aabb/computeAABB3PlaneSide.js";
|
|
8
8
|
import computeMortonCode from "../../geom/3d/morton/Morton.js";
|
|
9
|
-
import { boxSurfaceArea, intersectRay, intersectSegment } from "./AABB3Math.js";
|
|
10
9
|
import { aabb3_build_corners } from "../../geom/3d/aabb/aabb3_build_corners.js";
|
|
11
10
|
import { assert } from "../../assert.js";
|
|
12
11
|
import { aabb3_intersects_frustum_degree } from "./aabb3_intersects_frustum_degree.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
* @param {number} x
|
|
40
|
-
* @param {number} y
|
|
41
|
-
* @param {number} z
|
|
42
|
-
* @returns {boolean}
|
|
43
|
-
*/
|
|
44
|
-
AABB3.prototype.containsPoint = function (x, y, z) {
|
|
45
|
-
return x >= this.x0
|
|
46
|
-
&& x <= this.x1
|
|
47
|
-
&& y >= this.y0
|
|
48
|
-
&& y <= this.y1
|
|
49
|
-
&& z >= this.z0
|
|
50
|
-
&& z <= this.z1;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
* @param {number} x
|
|
56
|
-
* @param {number} y
|
|
57
|
-
* @param {number} z
|
|
58
|
-
* @param {number} tolerance
|
|
59
|
-
* @returns {boolean}
|
|
60
|
-
*/
|
|
61
|
-
AABB3.prototype.containsPointWithTolerance = function (x, y, z, tolerance) {
|
|
62
|
-
if (
|
|
63
|
-
(x + tolerance) < this.x0 || (x - tolerance) > this.x1
|
|
64
|
-
|| (y + tolerance) < this.y0 || (y - tolerance) > this.y1
|
|
65
|
-
|| (z + tolerance) < this.z0 || (z - tolerance) > this.z1
|
|
12
|
+
import { aabb3_intersects_frustum } from "./aabb3_intersects_frustum_array.js";
|
|
13
|
+
import { aabb3_intersects_line_segment } from "./aabb3_intersects_line_segment.js";
|
|
14
|
+
import { aabb3_intersects_ray } from "./aabb3_intersects_ray.js";
|
|
15
|
+
import { aabb3_compute_surface_area } from "./aabb3_compute_surface_area.js";
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export class AABB3 {
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {number} x0
|
|
22
|
+
* @param {number} y0
|
|
23
|
+
* @param {number} z0
|
|
24
|
+
* @param {number} x1
|
|
25
|
+
* @param {number} y1
|
|
26
|
+
* @param {number} z1
|
|
27
|
+
* @constructor
|
|
28
|
+
*/
|
|
29
|
+
constructor(
|
|
30
|
+
x0 = 0,
|
|
31
|
+
y0 = 0,
|
|
32
|
+
z0 = 0,
|
|
33
|
+
x1 = 0,
|
|
34
|
+
y1 = 0,
|
|
35
|
+
z1 = 0
|
|
66
36
|
) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
37
|
+
this.setBounds(x0, y0, z0, x1, y1, z1);
|
|
38
|
+
this._surfaceArea = -1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param {number} x
|
|
44
|
+
* @param {number} y
|
|
45
|
+
* @param {number} z
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
containsPoint(x, y, z) {
|
|
49
|
+
return x >= this.x0
|
|
50
|
+
&& x <= this.x1
|
|
51
|
+
&& y >= this.y0
|
|
52
|
+
&& y <= this.y1
|
|
53
|
+
&& z >= this.z0
|
|
54
|
+
&& z <= this.z1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param {number} x
|
|
60
|
+
* @param {number} y
|
|
61
|
+
* @param {number} z
|
|
62
|
+
* @param {number} tolerance
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
containsPointWithTolerance(x, y, z, tolerance) {
|
|
66
|
+
if (
|
|
67
|
+
(x + tolerance) < this.x0 || (x - tolerance) > this.x1
|
|
68
|
+
|| (y + tolerance) < this.y0 || (y - tolerance) > this.y1
|
|
69
|
+
|| (z + tolerance) < this.z0 || (z - tolerance) > this.z1
|
|
70
|
+
) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
87
73
|
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
* @returns {number}
|
|
91
|
-
*/
|
|
92
|
-
AABB3.prototype.getSurfaceArea = function () {
|
|
93
|
-
if (typeof this._surfaceArea !== "number" || this._surfaceArea <= 0) {
|
|
94
|
-
this._surfaceArea = this.computeSurfaceArea();
|
|
74
|
+
return true;
|
|
95
75
|
}
|
|
96
|
-
return this._surfaceArea;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
* @returns {number}
|
|
102
|
-
*/
|
|
103
|
-
AABB3.prototype.computeVolume = function () {
|
|
104
|
-
return this.getExtentsX() * this.getExtentsY() * this.getExtentsZ();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
* @param {AABB3} other
|
|
110
|
-
*/
|
|
111
|
-
AABB3.prototype.copy = function (other) {
|
|
112
|
-
this.setBounds(other.x0, other.y0, other.z0, other.x1, other.y1, other.z1);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
* @param {Number} x0
|
|
118
|
-
* @param {Number} y0
|
|
119
|
-
* @param {Number} z0
|
|
120
|
-
* @param {Number} x1
|
|
121
|
-
* @param {Number} y1
|
|
122
|
-
* @param {Number} z1
|
|
123
|
-
*/
|
|
124
|
-
AABB3.prototype.setBounds = function (x0, y0, z0, x1, y1, z1) {
|
|
125
|
-
this.x0 = x0;
|
|
126
|
-
this.y0 = y0;
|
|
127
|
-
this.z0 = z0;
|
|
128
|
-
this.x1 = x1;
|
|
129
|
-
this.y1 = y1;
|
|
130
|
-
this.z1 = z1;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
*
|
|
135
|
-
* @param {AABB3} other
|
|
136
|
-
* @returns {boolean}
|
|
137
|
-
*/
|
|
138
|
-
AABB3.prototype.equals = function (other) {
|
|
139
|
-
return this._equals(other.x0, other.y0, other.z0, other.x1, other.y1, other.z1);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
*
|
|
144
|
-
* @param {Number} x0
|
|
145
|
-
* @param {Number} y0
|
|
146
|
-
* @param {Number} z0
|
|
147
|
-
* @param {Number} x1
|
|
148
|
-
* @param {Number} y1
|
|
149
|
-
* @param {Number} z1
|
|
150
|
-
* @returns {boolean}
|
|
151
|
-
*/
|
|
152
|
-
AABB3.prototype._equals = function (x0, y0, z0, x1, y1, z1) {
|
|
153
|
-
return this.x0 === x0 && this.y0 === y0 && this.z0 === z0 && this.x1 === x1 && this.y1 === y1 && this.z1 === z1;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Same as setBounds, but does not require component pairs to be ordered (e.g. x0 <= x1). Method will enforce the correct order and invoke setBounds internally
|
|
158
|
-
* @param {Number} x0
|
|
159
|
-
* @param {Number} y0
|
|
160
|
-
* @param {Number} z0
|
|
161
|
-
* @param {Number} x1
|
|
162
|
-
* @param {Number} y1
|
|
163
|
-
* @param {Number} z1
|
|
164
|
-
*/
|
|
165
|
-
AABB3.prototype.setBoundsUnordered = function (x0, y0, z0, x1, y1, z1) {
|
|
166
|
-
let _x0, _y0, _z0, _x1, _y1, _z1;
|
|
167
|
-
if (x0 < x1) {
|
|
168
|
-
_x0 = x0;
|
|
169
|
-
_x1 = x1;
|
|
170
|
-
} else {
|
|
171
|
-
_x0 = x1;
|
|
172
|
-
_x1 = x0;
|
|
173
|
-
}
|
|
174
|
-
if (y0 < y1) {
|
|
175
|
-
_y0 = y0;
|
|
176
|
-
_y1 = y1;
|
|
177
|
-
} else {
|
|
178
|
-
_y0 = y1;
|
|
179
|
-
_y1 = y0;
|
|
180
|
-
}
|
|
181
|
-
if (z0 < z1) {
|
|
182
|
-
_z0 = z0;
|
|
183
|
-
_z1 = z1;
|
|
184
|
-
} else {
|
|
185
|
-
_z0 = z1;
|
|
186
|
-
_z1 = z0;
|
|
187
|
-
}
|
|
188
|
-
this.setBounds(_x0, _y0, _z0, _x1, _y1, _z1);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
AABB3.prototype.setNegativelyInfiniteBounds = function () {
|
|
192
|
-
this.setBounds(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
AABB3.prototype.setInfiniteBounds = function () {
|
|
196
|
-
this.setBounds(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
*
|
|
201
|
-
* @param {number} x
|
|
202
|
-
* @param {number} y
|
|
203
|
-
* @param {number} z
|
|
204
|
-
* @returns {number} Squared distance to point, value is negative if the point is inside the box
|
|
205
|
-
*/
|
|
206
|
-
AABB3.prototype.distanceToPoint2 = function (x, y, z) {
|
|
207
|
-
const _x0 = this.x0;
|
|
208
|
-
const _y0 = this.y0;
|
|
209
|
-
const _z0 = this.z0;
|
|
210
|
-
const _x1 = this.x1;
|
|
211
|
-
const _y1 = this.y1;
|
|
212
|
-
const _z1 = this.z1;
|
|
213
|
-
|
|
214
|
-
//do projection
|
|
215
|
-
const xp0 = _x0 - x;
|
|
216
|
-
const xp1 = x - _x1;
|
|
217
|
-
const yp0 = _y0 - y;
|
|
218
|
-
const yp1 = y - _y1;
|
|
219
|
-
const zp0 = _z0 - z;
|
|
220
|
-
const zp1 = z - _z1;
|
|
221
|
-
|
|
222
|
-
//calculate separation in each axis
|
|
223
|
-
const dx = Math.max(xp0, xp1);
|
|
224
|
-
const dy = Math.max(yp0, yp1);
|
|
225
|
-
const dz = Math.max(zp0, zp1);
|
|
226
|
-
|
|
227
|
-
//straight-line distance
|
|
228
|
-
const distance2 = dx * dx + dy * dy + dz * dz;
|
|
229
|
-
|
|
230
|
-
if (dx < 0 && dy < 0 && dz < 0) {
|
|
231
|
-
//penetration
|
|
232
|
-
return -distance2;
|
|
233
|
-
} else {
|
|
234
|
-
return distance2;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
*
|
|
240
|
-
* @param {AABB3} box
|
|
241
|
-
* @returns {number}
|
|
242
|
-
*/
|
|
243
|
-
AABB3.prototype.distanceToBox = function (box) {
|
|
244
|
-
return this._distanceToBox(box.x0, box.y0, box.z0, box.x1, box.y1, box.z1);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Computes separation distance between two boxes.
|
|
249
|
-
* If poxes penetrate or one is inside another - the result will be negative.
|
|
250
|
-
* @param {number} x0
|
|
251
|
-
* @param {number} y0
|
|
252
|
-
* @param {number} z0
|
|
253
|
-
* @param {number} x1
|
|
254
|
-
* @param {number} y1
|
|
255
|
-
* @param {number} z1
|
|
256
|
-
* @returns {number}
|
|
257
|
-
*/
|
|
258
|
-
AABB3.prototype._distanceToBox = function (x0, y0, z0, x1, y1, z1) {
|
|
259
|
-
const _x0 = this.x0;
|
|
260
|
-
const _y0 = this.y0;
|
|
261
|
-
const _z0 = this.z0;
|
|
262
|
-
const _x1 = this.x1;
|
|
263
|
-
const _y1 = this.y1;
|
|
264
|
-
const _z1 = this.z1;
|
|
265
|
-
|
|
266
|
-
//do projection
|
|
267
|
-
const xp0 = _x0 - x1;
|
|
268
|
-
const xp1 = x0 - _x1;
|
|
269
|
-
const yp0 = _y0 - y1;
|
|
270
|
-
const yp1 = y0 - _y1;
|
|
271
|
-
const zp0 = _z0 - z1;
|
|
272
|
-
const zp1 = z0 - _z1;
|
|
273
|
-
|
|
274
|
-
//calculate separation in each axis
|
|
275
|
-
const dx = Math.max(xp0, xp1);
|
|
276
|
-
const dy = Math.max(yp0, yp1);
|
|
277
|
-
const dz = Math.max(zp0, zp1);
|
|
278
|
-
|
|
279
|
-
//straight-line distance
|
|
280
|
-
let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
281
|
-
|
|
282
|
-
if (dx < 0 && dy < 0 && dz < 0) {
|
|
283
|
-
//penetration
|
|
284
|
-
return -distance;
|
|
285
|
-
} else {
|
|
286
|
-
return distance;
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
*
|
|
292
|
-
* @param {AABB3} other
|
|
293
|
-
* @returns {number}
|
|
294
|
-
*/
|
|
295
|
-
AABB3.prototype.costForInclusion = function (other) {
|
|
296
|
-
return this._costForInclusion(other.x0, other.y0, other.z0, other.x1, other.y1, other.z1);
|
|
297
|
-
};
|
|
298
76
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
* @param {number} z0
|
|
305
|
-
* @param {number} x1
|
|
306
|
-
* @param {number} y1
|
|
307
|
-
* @param {number} z1
|
|
308
|
-
* @returns {number}
|
|
309
|
-
*/
|
|
310
|
-
AABB3.prototype._costForInclusion = function (x0, y0, z0, x1, y1, z1) {
|
|
311
|
-
let x = 0;
|
|
312
|
-
let y = 0;
|
|
313
|
-
let z = 0;
|
|
314
|
-
//
|
|
315
|
-
const _x0 = this.x0;
|
|
316
|
-
const _y0 = this.y0;
|
|
317
|
-
const _z0 = this.z0;
|
|
318
|
-
const _x1 = this.x1;
|
|
319
|
-
const _y1 = this.y1;
|
|
320
|
-
const _z1 = this.z1;
|
|
321
|
-
//
|
|
322
|
-
if (_x0 > x0) {
|
|
323
|
-
x += _x0 - x0;
|
|
324
|
-
}
|
|
325
|
-
if (_x1 < x1) {
|
|
326
|
-
x += x1 - _x1;
|
|
327
|
-
}
|
|
328
|
-
if (_y0 > y0) {
|
|
329
|
-
y += _y0 - y0;
|
|
330
|
-
}
|
|
331
|
-
if (_y1 < y1) {
|
|
332
|
-
y += y1 - _y1;
|
|
333
|
-
}
|
|
334
|
-
if (_z0 > z0) {
|
|
335
|
-
z += _z0 - z0;
|
|
77
|
+
computeMortonCode() {
|
|
78
|
+
const cx = (this.x0 + this.x1) >> 1;
|
|
79
|
+
const cy = (this.y0 + this.y1) >> 1;
|
|
80
|
+
const cz = (this.z0 + this.z1) >> 1;
|
|
81
|
+
return computeMortonCode(cx, cy, cz);
|
|
336
82
|
}
|
|
337
|
-
if (_z1 < z1) {
|
|
338
|
-
z += z1 - _z1;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const dx = _x1 - _x0;
|
|
342
|
-
const dy = _y1 - _y0;
|
|
343
|
-
const dz = _z1 - _z0;
|
|
344
|
-
|
|
345
|
-
return (x * (dy + dz) + y * (dx + dz) + z * (dx + dy));
|
|
346
|
-
};
|
|
347
83
|
|
|
348
|
-
/**
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
*/
|
|
355
|
-
AABB3.prototype._expandToFitPoint = function (x, y, z) {
|
|
356
|
-
let expanded = false;
|
|
357
|
-
if (x < this.x0) {
|
|
358
|
-
this.x0 = x;
|
|
359
|
-
expanded = true;
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @returns {number}
|
|
87
|
+
*/
|
|
88
|
+
computeSurfaceArea() {
|
|
89
|
+
return aabb3_compute_surface_area(this.x0, this.y0, this.z0, this.x1, this.y1, this.z1);
|
|
360
90
|
}
|
|
361
|
-
if (y < this.y0) {
|
|
362
|
-
this.y0 = y;
|
|
363
|
-
expanded = true;
|
|
364
|
-
}
|
|
365
|
-
if (z < this.z0) {
|
|
366
|
-
this.z0 = z;
|
|
367
|
-
expanded = true;
|
|
368
|
-
}
|
|
369
|
-
if (x > this.x1) {
|
|
370
|
-
this.x1 = x;
|
|
371
|
-
expanded = true;
|
|
372
|
-
}
|
|
373
|
-
if (y > this.y1) {
|
|
374
|
-
this.y1 = y;
|
|
375
|
-
expanded = true;
|
|
376
|
-
}
|
|
377
|
-
if (z > this.z1) {
|
|
378
|
-
this.z1 = z;
|
|
379
|
-
expanded = true;
|
|
380
|
-
}
|
|
381
|
-
return expanded;
|
|
382
|
-
};
|
|
383
91
|
|
|
384
|
-
/**
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
*
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
* @returns {number}
|
|
95
|
+
*/
|
|
96
|
+
getSurfaceArea() {
|
|
97
|
+
if (typeof this._surfaceArea !== "number" || this._surfaceArea <= 0) {
|
|
98
|
+
this._surfaceArea = this.computeSurfaceArea();
|
|
99
|
+
}
|
|
100
|
+
return this._surfaceArea;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @returns {number}
|
|
106
|
+
*/
|
|
107
|
+
computeVolume() {
|
|
108
|
+
return this.getExtentsX() * this.getExtentsY() * this.getExtentsZ();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
* @param {AABB3} other
|
|
114
|
+
*/
|
|
115
|
+
copy(other) {
|
|
116
|
+
this.setBounds(other.x0, other.y0, other.z0, other.x1, other.y1, other.z1);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @param {Number} x0
|
|
122
|
+
* @param {Number} y0
|
|
123
|
+
* @param {Number} z0
|
|
124
|
+
* @param {Number} x1
|
|
125
|
+
* @param {Number} y1
|
|
126
|
+
* @param {Number} z1
|
|
127
|
+
*/
|
|
128
|
+
setBounds(x0, y0, z0, x1, y1, z1) {
|
|
405
129
|
this.x0 = x0;
|
|
406
|
-
expanded = true;
|
|
407
|
-
}
|
|
408
|
-
if (y0 < this.y0) {
|
|
409
130
|
this.y0 = y0;
|
|
410
|
-
expanded = true;
|
|
411
|
-
}
|
|
412
|
-
if (z0 < this.z0) {
|
|
413
131
|
this.z0 = z0;
|
|
414
|
-
expanded = true;
|
|
415
|
-
}
|
|
416
|
-
if (x1 > this.x1) {
|
|
417
132
|
this.x1 = x1;
|
|
418
|
-
expanded = true;
|
|
419
|
-
}
|
|
420
|
-
if (y1 > this.y1) {
|
|
421
133
|
this.y1 = y1;
|
|
422
|
-
expanded = true;
|
|
423
|
-
}
|
|
424
|
-
if (z1 > this.z1) {
|
|
425
134
|
this.z1 = z1;
|
|
426
|
-
expanded = true;
|
|
427
135
|
}
|
|
428
|
-
return expanded;
|
|
429
|
-
};
|
|
430
136
|
|
|
431
|
-
/**
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @param {AABB3} other
|
|
140
|
+
* @returns {boolean}
|
|
141
|
+
*/
|
|
142
|
+
equals(other) {
|
|
143
|
+
return this._equals(other.x0, other.y0, other.z0, other.x1, other.y1, other.z1);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
* @param {Number} x0
|
|
149
|
+
* @param {Number} y0
|
|
150
|
+
* @param {Number} z0
|
|
151
|
+
* @param {Number} x1
|
|
152
|
+
* @param {Number} y1
|
|
153
|
+
* @param {Number} z1
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
156
|
+
_equals(x0, y0, z0, x1, y1, z1) {
|
|
157
|
+
return this.x0 === x0 && this.y0 === y0 && this.z0 === z0 && this.x1 === x1 && this.y1 === y1 && this.z1 === z1;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Same as setBounds, but does not require component pairs to be ordered (e.g. x0 <= x1). Method will enforce the correct order and invoke setBounds internally
|
|
162
|
+
* @param {Number} x0
|
|
163
|
+
* @param {Number} y0
|
|
164
|
+
* @param {Number} z0
|
|
165
|
+
* @param {Number} x1
|
|
166
|
+
* @param {Number} y1
|
|
167
|
+
* @param {Number} z1
|
|
168
|
+
*/
|
|
169
|
+
setBoundsUnordered(x0, y0, z0, x1, y1, z1) {
|
|
170
|
+
let _x0, _y0, _z0, _x1, _y1, _z1;
|
|
171
|
+
if (x0 < x1) {
|
|
172
|
+
_x0 = x0;
|
|
173
|
+
_x1 = x1;
|
|
174
|
+
} else {
|
|
175
|
+
_x0 = x1;
|
|
176
|
+
_x1 = x0;
|
|
177
|
+
}
|
|
178
|
+
if (y0 < y1) {
|
|
179
|
+
_y0 = y0;
|
|
180
|
+
_y1 = y1;
|
|
181
|
+
} else {
|
|
182
|
+
_y0 = y1;
|
|
183
|
+
_y1 = y0;
|
|
184
|
+
}
|
|
185
|
+
if (z0 < z1) {
|
|
186
|
+
_z0 = z0;
|
|
187
|
+
_z1 = z1;
|
|
188
|
+
} else {
|
|
189
|
+
_z0 = z1;
|
|
190
|
+
_z1 = z0;
|
|
191
|
+
}
|
|
192
|
+
this.setBounds(_x0, _y0, _z0, _x1, _y1, _z1);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
setNegativelyInfiniteBounds() {
|
|
196
|
+
this.setBounds(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
setInfiniteBounds() {
|
|
200
|
+
this.setBounds(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
*
|
|
205
|
+
* @param {number} x
|
|
206
|
+
* @param {number} y
|
|
207
|
+
* @param {number} z
|
|
208
|
+
* @returns {number} Squared distance to point, value is negative if the point is inside the box
|
|
209
|
+
*/
|
|
210
|
+
distanceToPoint2(x, y, z) {
|
|
211
|
+
const _x0 = this.x0;
|
|
212
|
+
const _y0 = this.y0;
|
|
213
|
+
const _z0 = this.z0;
|
|
214
|
+
const _x1 = this.x1;
|
|
215
|
+
const _y1 = this.y1;
|
|
216
|
+
const _z1 = this.z1;
|
|
217
|
+
|
|
218
|
+
//do projection
|
|
219
|
+
const xp0 = _x0 - x;
|
|
220
|
+
const xp1 = x - _x1;
|
|
221
|
+
const yp0 = _y0 - y;
|
|
222
|
+
const yp1 = y - _y1;
|
|
223
|
+
const zp0 = _z0 - z;
|
|
224
|
+
const zp1 = z - _z1;
|
|
225
|
+
|
|
226
|
+
//calculate separation in each axis
|
|
227
|
+
const dx = Math.max(xp0, xp1);
|
|
228
|
+
const dy = Math.max(yp0, yp1);
|
|
229
|
+
const dz = Math.max(zp0, zp1);
|
|
230
|
+
|
|
231
|
+
//straight-line distance
|
|
232
|
+
const distance2 = dx * dx + dy * dy + dz * dz;
|
|
233
|
+
|
|
234
|
+
if (dx < 0 && dy < 0 && dz < 0) {
|
|
235
|
+
//penetration
|
|
236
|
+
return -distance2;
|
|
237
|
+
} else {
|
|
238
|
+
return distance2;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
517
241
|
|
|
518
|
-
|
|
519
|
-
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
* @param {AABB3} box
|
|
245
|
+
* @returns {number}
|
|
246
|
+
*/
|
|
247
|
+
distanceToBox(box) {
|
|
248
|
+
return this._distanceToBox(box.x0, box.y0, box.z0, box.x1, box.y1, box.z1);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Computes separation distance between two boxes.
|
|
253
|
+
* If poxes penetrate or one is inside another - the result will be negative.
|
|
254
|
+
* @param {number} x0
|
|
255
|
+
* @param {number} y0
|
|
256
|
+
* @param {number} z0
|
|
257
|
+
* @param {number} x1
|
|
258
|
+
* @param {number} y1
|
|
259
|
+
* @param {number} z1
|
|
260
|
+
* @returns {number}
|
|
261
|
+
*/
|
|
262
|
+
_distanceToBox(x0, y0, z0, x1, y1, z1) {
|
|
263
|
+
const _x0 = this.x0;
|
|
264
|
+
const _y0 = this.y0;
|
|
265
|
+
const _z0 = this.z0;
|
|
266
|
+
const _x1 = this.x1;
|
|
267
|
+
const _y1 = this.y1;
|
|
268
|
+
const _z1 = this.z1;
|
|
269
|
+
|
|
270
|
+
//do projection
|
|
271
|
+
const xp0 = _x0 - x1;
|
|
272
|
+
const xp1 = x0 - _x1;
|
|
273
|
+
const yp0 = _y0 - y1;
|
|
274
|
+
const yp1 = y0 - _y1;
|
|
275
|
+
const zp0 = _z0 - z1;
|
|
276
|
+
const zp1 = z0 - _z1;
|
|
277
|
+
|
|
278
|
+
//calculate separation in each axis
|
|
279
|
+
const dx = Math.max(xp0, xp1);
|
|
280
|
+
const dy = Math.max(yp0, yp1);
|
|
281
|
+
const dz = Math.max(zp0, zp1);
|
|
282
|
+
|
|
283
|
+
//straight-line distance
|
|
284
|
+
let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
285
|
+
|
|
286
|
+
if (dx < 0 && dy < 0 && dz < 0) {
|
|
287
|
+
//penetration
|
|
288
|
+
return -distance;
|
|
289
|
+
} else {
|
|
290
|
+
return distance;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
520
293
|
|
|
521
|
-
/**
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
294
|
+
/**
|
|
295
|
+
*
|
|
296
|
+
* @param {AABB3} other
|
|
297
|
+
* @returns {number}
|
|
298
|
+
*/
|
|
299
|
+
costForInclusion(other) {
|
|
300
|
+
return this._costForInclusion(other.x0, other.y0, other.z0, other.x1, other.y1, other.z1);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Surface area delta when including a given AABB
|
|
305
|
+
* 0 means that including a given AABB would not cause any change to total surface area
|
|
306
|
+
* @param {number} x0
|
|
307
|
+
* @param {number} y0
|
|
308
|
+
* @param {number} z0
|
|
309
|
+
* @param {number} x1
|
|
310
|
+
* @param {number} y1
|
|
311
|
+
* @param {number} z1
|
|
312
|
+
* @returns {number}
|
|
313
|
+
*/
|
|
314
|
+
_costForInclusion(x0, y0, z0, x1, y1, z1) {
|
|
315
|
+
let x = 0;
|
|
316
|
+
let y = 0;
|
|
317
|
+
let z = 0;
|
|
318
|
+
//
|
|
319
|
+
const _x0 = this.x0;
|
|
320
|
+
const _y0 = this.y0;
|
|
321
|
+
const _z0 = this.z0;
|
|
322
|
+
const _x1 = this.x1;
|
|
323
|
+
const _y1 = this.y1;
|
|
324
|
+
const _z1 = this.z1;
|
|
325
|
+
//
|
|
326
|
+
if (_x0 > x0) {
|
|
327
|
+
x += _x0 - x0;
|
|
328
|
+
}
|
|
329
|
+
if (_x1 < x1) {
|
|
330
|
+
x += x1 - _x1;
|
|
331
|
+
}
|
|
332
|
+
if (_y0 > y0) {
|
|
333
|
+
y += _y0 - y0;
|
|
334
|
+
}
|
|
335
|
+
if (_y1 < y1) {
|
|
336
|
+
y += y1 - _y1;
|
|
337
|
+
}
|
|
338
|
+
if (_z0 > z0) {
|
|
339
|
+
z += _z0 - z0;
|
|
340
|
+
}
|
|
341
|
+
if (_z1 < z1) {
|
|
342
|
+
z += z1 - _z1;
|
|
343
|
+
}
|
|
533
344
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
*
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
//var min = boxCenter - minToMax / 2;
|
|
555
|
-
//var max = boxCenter + minToMax / 2;
|
|
556
|
-
//var beginToMin = min - segmentBegin;
|
|
557
|
-
//var beginToMax = max - segmentBegin;
|
|
558
|
-
//var tNear = double.MinValue;
|
|
559
|
-
let tNear = Number.NEGATIVE_INFINITY;
|
|
560
|
-
//var tFar = double.MaxValue;
|
|
561
|
-
let tFar = Number.POSITIVE_INFINITY;
|
|
562
|
-
let t1, t2, tMin, tMax;
|
|
563
|
-
//var intersections = new List<Point3D>();
|
|
564
|
-
//var intersections = [];
|
|
565
|
-
let beginToMin = this.x0 - startX;
|
|
566
|
-
let beginToMax = this.x1 - startX;
|
|
567
|
-
if (deltaX === 0) {//parallel
|
|
568
|
-
if (beginToMin > 0 || beginToMax < 0) {
|
|
569
|
-
return false; //segment is not between planes
|
|
345
|
+
const dx = _x1 - _x0;
|
|
346
|
+
const dy = _y1 - _y0;
|
|
347
|
+
const dz = _z1 - _z0;
|
|
348
|
+
|
|
349
|
+
return (x * (dy + dz) + y * (dx + dz) + z * (dx + dy));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
*
|
|
354
|
+
* @param {number} x
|
|
355
|
+
* @param {number} y
|
|
356
|
+
* @param {number} z
|
|
357
|
+
* @returns {boolean}
|
|
358
|
+
*/
|
|
359
|
+
_expandToFitPoint(x, y, z) {
|
|
360
|
+
let expanded = false;
|
|
361
|
+
if (x < this.x0) {
|
|
362
|
+
this.x0 = x;
|
|
363
|
+
expanded = true;
|
|
570
364
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
tMin = Math.min(t1, t2);
|
|
575
|
-
tMax = Math.max(t1, t2);
|
|
576
|
-
if (tMin > tNear) {
|
|
577
|
-
tNear = tMin;
|
|
365
|
+
if (y < this.y0) {
|
|
366
|
+
this.y0 = y;
|
|
367
|
+
expanded = true;
|
|
578
368
|
}
|
|
579
|
-
if (
|
|
580
|
-
|
|
369
|
+
if (z < this.z0) {
|
|
370
|
+
this.z0 = z;
|
|
371
|
+
expanded = true;
|
|
581
372
|
}
|
|
582
|
-
if (
|
|
583
|
-
|
|
373
|
+
if (x > this.x1) {
|
|
374
|
+
this.x1 = x;
|
|
375
|
+
expanded = true;
|
|
584
376
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
if (deltaY === 0) {//parallel
|
|
589
|
-
if (beginToMin > 0 || beginToMax < 0) {
|
|
590
|
-
return false; //segment is not between planes
|
|
377
|
+
if (y > this.y1) {
|
|
378
|
+
this.y1 = y;
|
|
379
|
+
expanded = true;
|
|
591
380
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
tMin = Math.min(t1, t2);
|
|
596
|
-
tMax = Math.max(t1, t2);
|
|
597
|
-
if (tMin > tNear) {
|
|
598
|
-
tNear = tMin;
|
|
381
|
+
if (z > this.z1) {
|
|
382
|
+
this.z1 = z;
|
|
383
|
+
expanded = true;
|
|
599
384
|
}
|
|
600
|
-
|
|
601
|
-
|
|
385
|
+
return expanded;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
*
|
|
390
|
+
* @param {AABB3} box
|
|
391
|
+
* @returns {boolean}
|
|
392
|
+
*/
|
|
393
|
+
expandToFit(box) {
|
|
394
|
+
return this._expandToFit(box.x0, box.y0, box.z0, box.x1, box.y1, box.z1);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
*
|
|
399
|
+
* @param {number} x0
|
|
400
|
+
* @param {number} y0
|
|
401
|
+
* @param {number} z0
|
|
402
|
+
* @param {number} x1
|
|
403
|
+
* @param {number} y1
|
|
404
|
+
* @param {number} z1
|
|
405
|
+
* @returns {boolean}
|
|
406
|
+
*/
|
|
407
|
+
_expandToFit(x0, y0, z0, x1, y1, z1) {
|
|
408
|
+
let expanded = false;
|
|
409
|
+
if (x0 < this.x0) {
|
|
410
|
+
this.x0 = x0;
|
|
411
|
+
expanded = true;
|
|
602
412
|
}
|
|
603
|
-
if (
|
|
604
|
-
|
|
413
|
+
if (y0 < this.y0) {
|
|
414
|
+
this.y0 = y0;
|
|
415
|
+
expanded = true;
|
|
605
416
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
if (deltaZ === 0) {//parallel
|
|
610
|
-
if (beginToMin > 0 || beginToMax < 0) {
|
|
611
|
-
return false; //segment is not between planes
|
|
417
|
+
if (z0 < this.z0) {
|
|
418
|
+
this.z0 = z0;
|
|
419
|
+
expanded = true;
|
|
612
420
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
tMin = Math.min(t1, t2);
|
|
617
|
-
tMax = Math.max(t1, t2);
|
|
618
|
-
if (tMin > tNear) {
|
|
619
|
-
tNear = tMin;
|
|
421
|
+
if (x1 > this.x1) {
|
|
422
|
+
this.x1 = x1;
|
|
423
|
+
expanded = true;
|
|
620
424
|
}
|
|
621
|
-
if (
|
|
622
|
-
|
|
425
|
+
if (y1 > this.y1) {
|
|
426
|
+
this.y1 = y1;
|
|
427
|
+
expanded = true;
|
|
623
428
|
}
|
|
624
|
-
if (
|
|
625
|
-
|
|
429
|
+
if (z1 > this.z1) {
|
|
430
|
+
this.z1 = z1;
|
|
431
|
+
expanded = true;
|
|
432
|
+
}
|
|
433
|
+
return expanded;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
*
|
|
438
|
+
* @param {number} x0
|
|
439
|
+
* @param {number} y0
|
|
440
|
+
* @param {number} z0
|
|
441
|
+
* @param {number} x1
|
|
442
|
+
* @param {number} y1
|
|
443
|
+
* @param {number} z1
|
|
444
|
+
* @returns {boolean}
|
|
445
|
+
*/
|
|
446
|
+
_containsBox(x0, y0, z0, x1, y1, z1) {
|
|
447
|
+
return x0 >= this.x0 && y0 >= this.y0 && z0 >= this.z0 && x1 <= this.x1 && y1 <= this.y1 && z1 <= this.z1;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
*
|
|
452
|
+
* @param {AABB3} box
|
|
453
|
+
* @returns {boolean}
|
|
454
|
+
*/
|
|
455
|
+
containsBox(box) {
|
|
456
|
+
return this._containsBox(box.x0, box.y0, box.z0, box.x1, box.y1, box.z1);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
*
|
|
461
|
+
* @returns {number}
|
|
462
|
+
*/
|
|
463
|
+
getExtentsX() {
|
|
464
|
+
return (this.x1 - this.x0);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
*
|
|
469
|
+
* @returns {number}
|
|
470
|
+
*/
|
|
471
|
+
getExtentsY() {
|
|
472
|
+
return (this.y1 - this.y0);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
*
|
|
477
|
+
* @returns {number}
|
|
478
|
+
*/
|
|
479
|
+
getExtentsZ() {
|
|
480
|
+
return (this.z1 - this.z0);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* half-width in X axis
|
|
485
|
+
* @returns {number}
|
|
486
|
+
*/
|
|
487
|
+
getHalfExtentsX() {
|
|
488
|
+
return this.getExtentsX() / 2;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* half-width in Y axis
|
|
493
|
+
* @returns {number}
|
|
494
|
+
*/
|
|
495
|
+
getHalfExtentsY() {
|
|
496
|
+
return this.getExtentsY() / 2;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* half-width in Z axis
|
|
501
|
+
* @returns {number}
|
|
502
|
+
*/
|
|
503
|
+
getHalfExtentsZ() {
|
|
504
|
+
return this.getExtentsZ() / 2;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Get center position of the box
|
|
509
|
+
* @param {Vector3} target where to write result
|
|
510
|
+
*/
|
|
511
|
+
getCenter(target) {
|
|
512
|
+
const x = (this.x0 + this.x1) / 2;
|
|
513
|
+
const y = (this.y0 + this.y1) / 2;
|
|
514
|
+
const z = (this.z0 + this.z1) / 2;
|
|
515
|
+
target.set(x, y, z);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
*
|
|
520
|
+
* @param {Vector3} target
|
|
521
|
+
*/
|
|
522
|
+
getExtents(target) {
|
|
523
|
+
const x = (this.x1 - this.x0);
|
|
524
|
+
const y = (this.y1 - this.y0);
|
|
525
|
+
const z = (this.z1 - this.z0);
|
|
526
|
+
|
|
527
|
+
target.set(x, y, z);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Accepts ray description, first set of coordinates is origin (oX,oY,oZ) and second is direction (dX,dY,dZ). Algorithm from GraphicsGems by Andrew Woo
|
|
532
|
+
* @param oX
|
|
533
|
+
* @param oY
|
|
534
|
+
* @param oZ
|
|
535
|
+
* @param dX
|
|
536
|
+
* @param dY
|
|
537
|
+
* @param dZ
|
|
538
|
+
*/
|
|
539
|
+
intersectRay(oX, oY, oZ, dX, dY, dZ) {
|
|
540
|
+
return aabb3_intersects_ray(this.x0, this.y0, this.z0, this.x1, this.y1, this.z1, oX, oY, oZ, dX, dY, dZ);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
intersectSegment(startX, startY, startZ, endX, endY, endZ) {
|
|
544
|
+
return aabb3_intersects_line_segment(this.x0, this.y0, this.z0, this.x1, this.y1, this.z1, startX, startY, startZ, endX, endY, endZ);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* @source http://stackoverflow.com/questions/3106666/intersection-of-line-segment-with-axis-aligned-box-in-c-sharp
|
|
549
|
+
* @param startX
|
|
550
|
+
* @param startY
|
|
551
|
+
* @param startZ
|
|
552
|
+
* @param endX
|
|
553
|
+
* @param endY
|
|
554
|
+
* @param endZ
|
|
555
|
+
* @returns {boolean}
|
|
556
|
+
*/
|
|
557
|
+
intersectSegment2(startX, startY, startZ, endX, endY, endZ) {
|
|
558
|
+
//var beginToEnd = segmentEnd - segmentBegin;
|
|
559
|
+
const deltaX = endX - startX,
|
|
560
|
+
deltaY = endY - startY,
|
|
561
|
+
deltaZ = endZ - startZ;
|
|
562
|
+
//var minToMax = new Vector3D(boxSize.X, boxSize.Y, boxSize.Z);
|
|
563
|
+
|
|
564
|
+
//var min = boxCenter - minToMax / 2;
|
|
565
|
+
//var max = boxCenter + minToMax / 2;
|
|
566
|
+
//var beginToMin = min - segmentBegin;
|
|
567
|
+
//var beginToMax = max - segmentBegin;
|
|
568
|
+
//var tNear = double.MinValue;
|
|
569
|
+
let tNear = Number.NEGATIVE_INFINITY;
|
|
570
|
+
//var tFar = double.MaxValue;
|
|
571
|
+
let tFar = Number.POSITIVE_INFINITY;
|
|
572
|
+
let t1, t2, tMin, tMax;
|
|
573
|
+
//var intersections = new List<Point3D>();
|
|
574
|
+
//var intersections = [];
|
|
575
|
+
let beginToMin = this.x0 - startX;
|
|
576
|
+
let beginToMax = this.x1 - startX;
|
|
577
|
+
if (deltaX === 0) {//parallel
|
|
578
|
+
if (beginToMin > 0 || beginToMax < 0) {
|
|
579
|
+
return false; //segment is not between planes
|
|
580
|
+
}
|
|
581
|
+
} else {
|
|
582
|
+
t1 = beginToMin / deltaX;
|
|
583
|
+
t2 = beginToMax / deltaX;
|
|
584
|
+
tMin = Math.min(t1, t2);
|
|
585
|
+
tMax = Math.max(t1, t2);
|
|
586
|
+
if (tMin > tNear) {
|
|
587
|
+
tNear = tMin;
|
|
588
|
+
}
|
|
589
|
+
if (tMax < tFar) {
|
|
590
|
+
tFar = tMax;
|
|
591
|
+
}
|
|
592
|
+
if (tNear > tFar || tFar < 0) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
beginToMin = this.y0 - startY;
|
|
597
|
+
beginToMax = this.y1 - startY;
|
|
598
|
+
if (deltaY === 0) {//parallel
|
|
599
|
+
if (beginToMin > 0 || beginToMax < 0) {
|
|
600
|
+
return false; //segment is not between planes
|
|
601
|
+
}
|
|
602
|
+
} else {
|
|
603
|
+
t1 = beginToMin / deltaY;
|
|
604
|
+
t2 = beginToMax / deltaY;
|
|
605
|
+
tMin = Math.min(t1, t2);
|
|
606
|
+
tMax = Math.max(t1, t2);
|
|
607
|
+
if (tMin > tNear) {
|
|
608
|
+
tNear = tMin;
|
|
609
|
+
}
|
|
610
|
+
if (tMax < tFar) {
|
|
611
|
+
tFar = tMax;
|
|
612
|
+
}
|
|
613
|
+
if (tNear > tFar || tFar < 0) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
beginToMin = this.z0 - startZ;
|
|
618
|
+
beginToMax = this.z1 - startZ;
|
|
619
|
+
if (deltaZ === 0) {//parallel
|
|
620
|
+
if (beginToMin > 0 || beginToMax < 0) {
|
|
621
|
+
return false; //segment is not between planes
|
|
622
|
+
}
|
|
623
|
+
} else {
|
|
624
|
+
t1 = beginToMin / deltaZ;
|
|
625
|
+
t2 = beginToMax / deltaZ;
|
|
626
|
+
tMin = Math.min(t1, t2);
|
|
627
|
+
tMax = Math.max(t1, t2);
|
|
628
|
+
if (tMin > tNear) {
|
|
629
|
+
tNear = tMin;
|
|
630
|
+
}
|
|
631
|
+
if (tMax < tFar) {
|
|
632
|
+
tFar = tMax;
|
|
633
|
+
}
|
|
634
|
+
if (tNear > tFar || tFar < 0) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
//
|
|
639
|
+
if (tNear >= 0 && tNear <= 1) {
|
|
640
|
+
//intersections.push({
|
|
641
|
+
// x: startX + deltaX * tNear,
|
|
642
|
+
// y: startY + deltaY * tNear,
|
|
643
|
+
// z: startZ + deltaZ * tNear
|
|
644
|
+
//});
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
if (tFar >= 0 && tFar <= 1) {
|
|
648
|
+
//intersections.push({
|
|
649
|
+
// x: startX + deltaX * tFar,
|
|
650
|
+
// y: startY + deltaY * tFar,
|
|
651
|
+
// z: startZ + deltaZ * tFar
|
|
652
|
+
//});
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
return false;
|
|
656
|
+
//foreach (Axis axis in Enum.GetValues(typeof(Axis)))
|
|
657
|
+
//{
|
|
658
|
+
// if (beginToEnd.GetCoordinate(axis) == 0) // parallel
|
|
659
|
+
// {
|
|
660
|
+
// if (beginToMin.GetCoordinate(axis) > 0 || beginToMax.GetCoordinate(axis) < 0)
|
|
661
|
+
// return intersections; // segment is not between planes
|
|
662
|
+
// }
|
|
663
|
+
// else
|
|
664
|
+
// {
|
|
665
|
+
// var t1 = beginToMin.GetCoordinate(axis) / beginToEnd.GetCoordinate(axis);
|
|
666
|
+
// var t2 = beginToMax.GetCoordinate(axis) / beginToEnd.GetCoordinate(axis);
|
|
667
|
+
// var tMin = Math.Min(t1, t2);
|
|
668
|
+
// var tMax = Math.Max(t1, t2);
|
|
669
|
+
// if (tMin > tNear) tNear = tMin;
|
|
670
|
+
// if (tMax < tFar) tFar = tMax;
|
|
671
|
+
// if (tNear > tFar || tFar < 0) return intersections;
|
|
672
|
+
//
|
|
673
|
+
// }
|
|
674
|
+
//}
|
|
675
|
+
//if (tNear >= 0 && tNear <= 1) intersections.Add(segmentBegin + beginToEnd * tNear);
|
|
676
|
+
//if (tFar >= 0 && tFar <= 1) intersections.Add(segmentBegin + beginToEnd * tFar);
|
|
677
|
+
//return intersections;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
*
|
|
682
|
+
* @param {THREE.Box} box
|
|
683
|
+
* @returns {boolean}
|
|
684
|
+
*/
|
|
685
|
+
threeContainsBox(box) {
|
|
686
|
+
const min = box.min;
|
|
687
|
+
const max = box.max;
|
|
688
|
+
return this._containsBox(min.x, min.y, min.z, max.x, max.y, max.z);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
*
|
|
693
|
+
* @param {function(x:number, y:number, z:number)} callback
|
|
694
|
+
* @param {*} [thisArg]
|
|
695
|
+
*/
|
|
696
|
+
traverseCorners(callback, thisArg) {
|
|
697
|
+
const _x0 = this.x0;
|
|
698
|
+
const _y0 = this.y0;
|
|
699
|
+
const _z0 = this.z0;
|
|
700
|
+
const _x1 = this.x1;
|
|
701
|
+
const _y1 = this.y1;
|
|
702
|
+
const _z1 = this.z1;
|
|
703
|
+
|
|
704
|
+
callback.call(thisArg, _x0, _y0, _z0);
|
|
705
|
+
callback.call(thisArg, _x0, _y0, _z1);
|
|
706
|
+
|
|
707
|
+
callback.call(thisArg, _x0, _y1, _z0);
|
|
708
|
+
callback.call(thisArg, _x0, _y1, _z1);
|
|
709
|
+
|
|
710
|
+
callback.call(thisArg, _x1, _y0, _z0);
|
|
711
|
+
callback.call(thisArg, _x1, _y0, _z1);
|
|
712
|
+
|
|
713
|
+
callback.call(thisArg, _x1, _y1, _z0);
|
|
714
|
+
callback.call(thisArg, _x1, _y1, _z1);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
*
|
|
719
|
+
* @param {number[]|Float64Array|Float32Array} result
|
|
720
|
+
*/
|
|
721
|
+
getCorners(result) {
|
|
722
|
+
aabb3_build_corners(
|
|
723
|
+
result,
|
|
724
|
+
0,
|
|
725
|
+
this.x0,
|
|
726
|
+
this.y0,
|
|
727
|
+
this.z0,
|
|
728
|
+
this.x1,
|
|
729
|
+
this.y1,
|
|
730
|
+
this.z1
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
*
|
|
736
|
+
* @param {number[]|Float32Array|Float64Array} result
|
|
737
|
+
* @param {number} offset
|
|
738
|
+
*/
|
|
739
|
+
writeToArray(result, offset) {
|
|
740
|
+
assert.isNonNegativeInteger(offset, 'offset');
|
|
741
|
+
|
|
742
|
+
result[offset] = this.x0;
|
|
743
|
+
result[offset + 1] = this.y0;
|
|
744
|
+
result[offset + 2] = this.z0;
|
|
745
|
+
|
|
746
|
+
result[offset + 3] = this.x1;
|
|
747
|
+
result[offset + 4] = this.y1;
|
|
748
|
+
result[offset + 5] = this.z1;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
*
|
|
753
|
+
* @param {number[]|Float32Array|Float64Array} source
|
|
754
|
+
* @param {number} offset
|
|
755
|
+
*/
|
|
756
|
+
readFromArray(source, offset) {
|
|
757
|
+
assert.isNonNegativeInteger(offset, 'offset');
|
|
758
|
+
|
|
759
|
+
this.x0 = source[offset];
|
|
760
|
+
this.y0 = source[offset + 1];
|
|
761
|
+
this.z0 = source[offset + 2];
|
|
762
|
+
|
|
763
|
+
this.x1 = source[offset + 3];
|
|
764
|
+
this.y1 = source[offset + 4];
|
|
765
|
+
this.z1 = source[offset + 5];
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* @param {THREE.Plane} plane
|
|
770
|
+
* @returns {int} 2,0,or -2; 2: above, -2 : below, 0 : intersects plane
|
|
771
|
+
*/
|
|
772
|
+
computePlaneSide(plane) {
|
|
773
|
+
const normal = plane.normal;
|
|
774
|
+
|
|
775
|
+
return computeAABB3PlaneSide(
|
|
776
|
+
normal.x, normal.y, normal.z, plane.constant,
|
|
777
|
+
this.x0, this.y0, this.z0,
|
|
778
|
+
this.x1, this.y1, this.z1
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
*
|
|
784
|
+
* @param {number} normal_x
|
|
785
|
+
* @param {number} normal_y
|
|
786
|
+
* @param {number} normal_z
|
|
787
|
+
* @param {number} offset
|
|
788
|
+
* @returns {number}
|
|
789
|
+
*/
|
|
790
|
+
computeDistanceAbovePlane(normal_x, normal_y, normal_z, offset) {
|
|
791
|
+
return aabb3_computeDistanceAbovePlane(
|
|
792
|
+
normal_x, normal_y, normal_z, offset,
|
|
793
|
+
this.x0, this.y0, this.z0,
|
|
794
|
+
this.x1, this.y1, this.z1
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
*
|
|
800
|
+
* @param {number} normal_x
|
|
801
|
+
* @param {number} normal_y
|
|
802
|
+
* @param {number} normal_z
|
|
803
|
+
* @param {number} offset
|
|
804
|
+
* @returns {boolean}
|
|
805
|
+
*/
|
|
806
|
+
_isBelowPlane(normal_x, normal_y, normal_z, offset) {
|
|
807
|
+
return this.computeDistanceAbovePlane(normal_x, normal_y, normal_z, offset) < 0;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
*
|
|
812
|
+
* @param {Plane} plane
|
|
813
|
+
* @return {boolean}
|
|
814
|
+
*/
|
|
815
|
+
isBelowPlane(plane) {
|
|
816
|
+
const normal = plane.normal;
|
|
817
|
+
|
|
818
|
+
return this._isBelowPlane(normal.x, normal.y, normal.z, plane.constant);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
*
|
|
823
|
+
* @param {Plane[]} clippingPlanes
|
|
824
|
+
* @returns {boolean}
|
|
825
|
+
*/
|
|
826
|
+
intersectSpace(clippingPlanes) {
|
|
827
|
+
let i = 0;
|
|
828
|
+
const l = clippingPlanes.length;
|
|
829
|
+
for (; i < l; i++) {
|
|
830
|
+
|
|
831
|
+
const plane = clippingPlanes[i];
|
|
832
|
+
if (this.isBelowPlane(plane)) {
|
|
833
|
+
return false;
|
|
834
|
+
}
|
|
626
835
|
}
|
|
627
|
-
}
|
|
628
|
-
//
|
|
629
|
-
if (tNear >= 0 && tNear <= 1) {
|
|
630
|
-
//intersections.push({
|
|
631
|
-
// x: startX + deltaX * tNear,
|
|
632
|
-
// y: startY + deltaY * tNear,
|
|
633
|
-
// z: startZ + deltaZ * tNear
|
|
634
|
-
//});
|
|
635
|
-
return true;
|
|
636
|
-
}
|
|
637
|
-
if (tFar >= 0 && tFar <= 1) {
|
|
638
|
-
//intersections.push({
|
|
639
|
-
// x: startX + deltaX * tFar,
|
|
640
|
-
// y: startY + deltaY * tFar,
|
|
641
|
-
// z: startZ + deltaZ * tFar
|
|
642
|
-
//});
|
|
643
836
|
return true;
|
|
644
837
|
}
|
|
645
|
-
return false;
|
|
646
|
-
//foreach (Axis axis in Enum.GetValues(typeof(Axis)))
|
|
647
|
-
//{
|
|
648
|
-
// if (beginToEnd.GetCoordinate(axis) == 0) // parallel
|
|
649
|
-
// {
|
|
650
|
-
// if (beginToMin.GetCoordinate(axis) > 0 || beginToMax.GetCoordinate(axis) < 0)
|
|
651
|
-
// return intersections; // segment is not between planes
|
|
652
|
-
// }
|
|
653
|
-
// else
|
|
654
|
-
// {
|
|
655
|
-
// var t1 = beginToMin.GetCoordinate(axis) / beginToEnd.GetCoordinate(axis);
|
|
656
|
-
// var t2 = beginToMax.GetCoordinate(axis) / beginToEnd.GetCoordinate(axis);
|
|
657
|
-
// var tMin = Math.Min(t1, t2);
|
|
658
|
-
// var tMax = Math.Max(t1, t2);
|
|
659
|
-
// if (tMin > tNear) tNear = tMin;
|
|
660
|
-
// if (tMax < tFar) tFar = tMax;
|
|
661
|
-
// if (tNear > tFar || tFar < 0) return intersections;
|
|
662
|
-
//
|
|
663
|
-
// }
|
|
664
|
-
//}
|
|
665
|
-
//if (tNear >= 0 && tNear <= 1) intersections.Add(segmentBegin + beginToEnd * tNear);
|
|
666
|
-
//if (tFar >= 0 && tFar <= 1) intersections.Add(segmentBegin + beginToEnd * tFar);
|
|
667
|
-
//return intersections;
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
*
|
|
672
|
-
* @param {THREE.Box} box
|
|
673
|
-
* @returns {boolean}
|
|
674
|
-
*/
|
|
675
|
-
AABB3.prototype.threeContainsBox = function (box) {
|
|
676
|
-
const min = box.min;
|
|
677
|
-
const max = box.max;
|
|
678
|
-
return this._containsBox(min.x, min.y, min.z, max.x, max.y, max.z);
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
*
|
|
683
|
-
* @param {function(x:number, y:number, z:number)} callback
|
|
684
|
-
* @param {*} [thisArg]
|
|
685
|
-
*/
|
|
686
|
-
AABB3.prototype.traverseCorners = function (callback, thisArg) {
|
|
687
|
-
const _x0 = this.x0;
|
|
688
|
-
const _y0 = this.y0;
|
|
689
|
-
const _z0 = this.z0;
|
|
690
|
-
const _x1 = this.x1;
|
|
691
|
-
const _y1 = this.y1;
|
|
692
|
-
const _z1 = this.z1;
|
|
693
|
-
|
|
694
|
-
callback.call(thisArg, _x0, _y0, _z0);
|
|
695
|
-
callback.call(thisArg, _x0, _y0, _z1);
|
|
696
|
-
|
|
697
|
-
callback.call(thisArg, _x0, _y1, _z0);
|
|
698
|
-
callback.call(thisArg, _x0, _y1, _z1);
|
|
699
|
-
|
|
700
|
-
callback.call(thisArg, _x1, _y0, _z0);
|
|
701
|
-
callback.call(thisArg, _x1, _y0, _z1);
|
|
702
|
-
|
|
703
|
-
callback.call(thisArg, _x1, _y1, _z0);
|
|
704
|
-
callback.call(thisArg, _x1, _y1, _z1);
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
*
|
|
709
|
-
* @param {number[]|Float64Array|Float32Array} result
|
|
710
|
-
*/
|
|
711
|
-
AABB3.prototype.getCorners = function (result) {
|
|
712
|
-
aabb3_build_corners(
|
|
713
|
-
result,
|
|
714
|
-
0,
|
|
715
|
-
this.x0,
|
|
716
|
-
this.y0,
|
|
717
|
-
this.z0,
|
|
718
|
-
this.x1,
|
|
719
|
-
this.y1,
|
|
720
|
-
this.z1
|
|
721
|
-
);
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
*
|
|
726
|
-
* @param {number[]|Float32Array|Float64Array} result
|
|
727
|
-
* @param {number} offset
|
|
728
|
-
*/
|
|
729
|
-
AABB3.prototype.writeToArray = function (result, offset) {
|
|
730
|
-
assert.isNonNegativeInteger(offset, 'offset');
|
|
731
|
-
|
|
732
|
-
result[offset] = this.x0;
|
|
733
|
-
result[offset + 1] = this.y0;
|
|
734
|
-
result[offset + 2] = this.z0;
|
|
735
|
-
|
|
736
|
-
result[offset + 3] = this.x1;
|
|
737
|
-
result[offset + 4] = this.y1;
|
|
738
|
-
result[offset + 5] = this.z1;
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
*
|
|
743
|
-
* @param {number[]|Float32Array|Float64Array} source
|
|
744
|
-
* @param {number} offset
|
|
745
|
-
*/
|
|
746
|
-
AABB3.prototype.readFromArray = function (source, offset) {
|
|
747
|
-
assert.isNonNegativeInteger(offset, 'offset');
|
|
748
838
|
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
};
|
|
757
|
-
|
|
758
|
-
/**
|
|
759
|
-
* @param {THREE.Plane} plane
|
|
760
|
-
* @returns {int} 2,0,or -2; 2: above, -2 : below, 0 : intersects plane
|
|
761
|
-
*/
|
|
762
|
-
AABB3.prototype.computePlaneSide = function computePlaneSide(plane) {
|
|
763
|
-
const normal = plane.normal;
|
|
764
|
-
|
|
765
|
-
return computeAABB3PlaneSide(
|
|
766
|
-
normal.x, normal.y, normal.z, plane.constant,
|
|
767
|
-
this.x0, this.y0, this.z0,
|
|
768
|
-
this.x1, this.y1, this.z1
|
|
769
|
-
);
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
/**
|
|
773
|
-
*
|
|
774
|
-
* @param {number} normal_x
|
|
775
|
-
* @param {number} normal_y
|
|
776
|
-
* @param {number} normal_z
|
|
777
|
-
* @param {number} offset
|
|
778
|
-
* @returns {number}
|
|
779
|
-
*/
|
|
780
|
-
AABB3.prototype.computeDistanceAbovePlane = function (normal_x, normal_y, normal_z, offset) {
|
|
781
|
-
return aabb3_computeDistanceAbovePlane(
|
|
782
|
-
normal_x, normal_y, normal_z, offset,
|
|
783
|
-
this.x0, this.y0, this.z0,
|
|
784
|
-
this.x1, this.y1, this.z1
|
|
785
|
-
);
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
*
|
|
790
|
-
* @param {number} normal_x
|
|
791
|
-
* @param {number} normal_y
|
|
792
|
-
* @param {number} normal_z
|
|
793
|
-
* @param {number} offset
|
|
794
|
-
* @returns {boolean}
|
|
795
|
-
*/
|
|
796
|
-
AABB3.prototype._isBelowPlane = function (normal_x, normal_y, normal_z, offset) {
|
|
797
|
-
return this.computeDistanceAbovePlane(normal_x, normal_y, normal_z, offset) < 0;
|
|
798
|
-
};
|
|
839
|
+
/**
|
|
840
|
+
*
|
|
841
|
+
* @param {Frustum} frustum
|
|
842
|
+
* @returns {number}
|
|
843
|
+
*/
|
|
844
|
+
intersectFrustumDegree(frustum) {
|
|
845
|
+
const planes = frustum.planes;
|
|
799
846
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
* @return {boolean}
|
|
804
|
-
*/
|
|
805
|
-
AABB3.prototype.isBelowPlane = function (plane) {
|
|
806
|
-
const normal = plane.normal;
|
|
847
|
+
let i = 0;
|
|
848
|
+
let result = 2;
|
|
849
|
+
for (; i < 6; i++) {
|
|
807
850
|
|
|
808
|
-
|
|
809
|
-
};
|
|
851
|
+
const plane = planes[i];
|
|
810
852
|
|
|
811
|
-
|
|
812
|
-
*
|
|
813
|
-
* @param {Plane[]} clippingPlanes
|
|
814
|
-
* @returns {boolean}
|
|
815
|
-
*/
|
|
816
|
-
AABB3.prototype.intersectSpace = function (clippingPlanes) {
|
|
817
|
-
let i = 0;
|
|
818
|
-
const l = clippingPlanes.length;
|
|
819
|
-
for (; i < l; i++) {
|
|
853
|
+
const planeSide = this.computePlaneSide(plane);
|
|
820
854
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
855
|
+
if (planeSide < 0) {
|
|
856
|
+
return 0;
|
|
857
|
+
} else if (planeSide === 0) {
|
|
858
|
+
result = 1;
|
|
859
|
+
}
|
|
824
860
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
861
|
+
return result;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
*
|
|
866
|
+
* @param {number[]} frustum
|
|
867
|
+
* @returns {number}
|
|
868
|
+
*/
|
|
869
|
+
intersectFrustumDegree_array(frustum) {
|
|
870
|
+
return aabb3_intersects_frustum_degree(
|
|
871
|
+
this.x0, this.y0, this.z0, this.x1, this.y1, this.z1, frustum
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
*
|
|
877
|
+
* @param {{planes:Array}}frustum
|
|
878
|
+
* @returns {boolean}
|
|
879
|
+
*/
|
|
880
|
+
intersectFrustum(frustum) {
|
|
881
|
+
const planes = frustum.planes;
|
|
882
|
+
for (let i = 0; i < 6; i++) {
|
|
883
|
+
|
|
884
|
+
const plane = planes[i];
|
|
885
|
+
if (this.isBelowPlane(plane)) {
|
|
886
|
+
return false;
|
|
887
|
+
}
|
|
849
888
|
}
|
|
889
|
+
return true;
|
|
850
890
|
}
|
|
851
|
-
return result;
|
|
852
|
-
};
|
|
853
|
-
/**
|
|
854
|
-
*
|
|
855
|
-
* @param {number[]} frustum
|
|
856
|
-
* @returns {number}
|
|
857
|
-
*/
|
|
858
|
-
AABB3.prototype.intersectFrustumDegree_array = function (frustum) {
|
|
859
|
-
return aabb3_intersects_frustum_degree(
|
|
860
|
-
this.x0, this.y0, this.z0, this.x1, this.y1, this.z1, frustum
|
|
861
|
-
);
|
|
862
|
-
};
|
|
863
|
-
|
|
864
|
-
/**
|
|
865
|
-
*
|
|
866
|
-
* @param {{planes:Array}}frustum
|
|
867
|
-
* @returns {boolean}
|
|
868
|
-
*/
|
|
869
|
-
AABB3.prototype.intersectFrustum = function intersectFrustum(frustum) {
|
|
870
|
-
const planes = frustum.planes;
|
|
871
|
-
for (let i = 0; i < 6; i++) {
|
|
872
891
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
892
|
+
/**
|
|
893
|
+
*
|
|
894
|
+
* @param {ArrayLike<number>|number[]|Float32Array}frustum
|
|
895
|
+
* @returns {boolean}
|
|
896
|
+
*/
|
|
897
|
+
intersectFrustum_array(frustum) {
|
|
898
|
+
const x0 = this.x0;
|
|
899
|
+
const y0 = this.y0;
|
|
900
|
+
const z0 = this.z0;
|
|
880
901
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
* @returns {boolean}
|
|
885
|
-
*/
|
|
886
|
-
AABB3.prototype.intersectFrustum_array = function intersectFrustum(frustum) {
|
|
887
|
-
const x0 = this.x0;
|
|
888
|
-
const y0 = this.y0;
|
|
889
|
-
const z0 = this.z0;
|
|
890
|
-
const x1 = this.x1;
|
|
891
|
-
const y1 = this.y1;
|
|
892
|
-
const z1 = this.z1;
|
|
893
|
-
|
|
894
|
-
for (let i = 0; i < 24; i += 4) {
|
|
895
|
-
|
|
896
|
-
const p_nx = frustum[i];
|
|
897
|
-
const p_ny = frustum[i + 1];
|
|
898
|
-
const p_nz = frustum[i + 2];
|
|
899
|
-
const p_c = frustum[i + 3];
|
|
900
|
-
|
|
901
|
-
if (aabb3_computeDistanceAbovePlane(
|
|
902
|
-
p_nx, p_ny, p_nz, p_c,
|
|
903
|
-
x0, y0, z0,
|
|
904
|
-
x1, y1, z1
|
|
905
|
-
) < 0) {
|
|
906
|
-
// below plane, i.e. outside of the frustum
|
|
907
|
-
return false;
|
|
908
|
-
}
|
|
902
|
+
const x1 = this.x1;
|
|
903
|
+
const y1 = this.y1;
|
|
904
|
+
const z1 = this.z1;
|
|
909
905
|
|
|
906
|
+
return aabb3_intersects_frustum(x0, y0, z0, x1, y1, z1, frustum);
|
|
910
907
|
}
|
|
911
|
-
return true;
|
|
912
|
-
};
|
|
913
908
|
|
|
909
|
+
/**
|
|
910
|
+
*
|
|
911
|
+
* @param {number} v
|
|
912
|
+
*/
|
|
913
|
+
grow(v) {
|
|
914
|
+
this.x0 -= v;
|
|
915
|
+
this.y0 -= v;
|
|
916
|
+
this.z0 -= v;
|
|
914
917
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
AABB3.prototype.grow = function (v) {
|
|
920
|
-
this.x0 -= v;
|
|
921
|
-
this.y0 -= v;
|
|
922
|
-
this.z0 -= v;
|
|
918
|
+
this.x1 += v;
|
|
919
|
+
this.y1 += v;
|
|
920
|
+
this.z1 += v;
|
|
921
|
+
}
|
|
923
922
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
923
|
+
/**
|
|
924
|
+
*
|
|
925
|
+
* @returns {AABB3}
|
|
926
|
+
*/
|
|
927
|
+
clone() {
|
|
928
|
+
const clone = new AABB3();
|
|
928
929
|
|
|
929
|
-
|
|
930
|
-
*
|
|
931
|
-
* @returns {AABB3}
|
|
932
|
-
*/
|
|
933
|
-
AABB3.prototype.clone = function () {
|
|
934
|
-
const clone = new AABB3();
|
|
930
|
+
clone.copy(this);
|
|
935
931
|
|
|
936
|
-
|
|
932
|
+
return clone;
|
|
933
|
+
}
|
|
937
934
|
|
|
938
|
-
|
|
939
|
-
|
|
935
|
+
fromJSON({ x0, y0, z0, x1, y1, z1 }) {
|
|
936
|
+
this.setBounds(x0, y0, z0, x1, y1, z1);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
940
939
|
|
|
941
|
-
AABB3.prototype.fromJSON = function ({ x0, y0, z0, x1, y1, z1 }) {
|
|
942
|
-
this.setBounds(x0, y0, z0, x1, y1, z1);
|
|
943
|
-
};
|
|
944
940
|
|
|
945
941
|
/**
|
|
946
942
|
*
|
|
@@ -1018,184 +1014,8 @@ export function serializeAABB3Encoded_v0(buffer, box, x0, y0, z0, x1, y1, z1) {
|
|
|
1018
1014
|
}
|
|
1019
1015
|
}
|
|
1020
1016
|
|
|
1021
|
-
|
|
1022
1017
|
/**
|
|
1023
|
-
*
|
|
1024
|
-
* @
|
|
1025
|
-
* @param {AABB3} box
|
|
1026
|
-
* @param {number} x0
|
|
1027
|
-
* @param {number} y0
|
|
1028
|
-
* @param {number} z0
|
|
1029
|
-
* @param {number} x1
|
|
1030
|
-
* @param {number} y1
|
|
1031
|
-
* @param {number} z1
|
|
1018
|
+
* @readonly
|
|
1019
|
+
* @type {boolean}
|
|
1032
1020
|
*/
|
|
1033
|
-
|
|
1034
|
-
const header = buffer.readUint8();
|
|
1035
|
-
|
|
1036
|
-
//compute value ranges
|
|
1037
|
-
const xD = x1 - x0;
|
|
1038
|
-
const yD = y1 - y0;
|
|
1039
|
-
const zD = z1 - z0;
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
let qx0;
|
|
1043
|
-
let qx1;
|
|
1044
|
-
|
|
1045
|
-
let qy0;
|
|
1046
|
-
let qy1;
|
|
1047
|
-
|
|
1048
|
-
let qz0;
|
|
1049
|
-
let qz1;
|
|
1050
|
-
|
|
1051
|
-
if ((header & 1) === 0) {
|
|
1052
|
-
const _x0 = buffer.readUint16();
|
|
1053
|
-
qx0 = (_x0 / 65535) * xD + x0;
|
|
1054
|
-
} else {
|
|
1055
|
-
qx0 = x0;
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
if ((header & 2) === 0) {
|
|
1059
|
-
const _x1 = buffer.readUint16();
|
|
1060
|
-
qx1 = (_x1 / 65535) * xD + x0;
|
|
1061
|
-
} else {
|
|
1062
|
-
qx1 = x1;
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
if ((header & 4) === 0) {
|
|
1066
|
-
const _y0 = buffer.readUint16();
|
|
1067
|
-
qy0 = (_y0 / 65535) * yD + y0;
|
|
1068
|
-
} else {
|
|
1069
|
-
qy0 = y0;
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
if ((header & 8) === 0) {
|
|
1073
|
-
const _y1 = buffer.readUint16();
|
|
1074
|
-
qy1 = (_y1 / 65535) * yD + y0;
|
|
1075
|
-
} else {
|
|
1076
|
-
qy1 = y1;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
if ((header & 16) === 0) {
|
|
1080
|
-
const _z0 = buffer.readUint16();
|
|
1081
|
-
qz0 = (_z0 / 65535) * zD + z0;
|
|
1082
|
-
} else {
|
|
1083
|
-
qz0 = z0;
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
if ((header & 32) === 0) {
|
|
1087
|
-
const _z1 = buffer.readUint16();
|
|
1088
|
-
qz1 = (_z1 / 65535) * zD + z0;
|
|
1089
|
-
} else {
|
|
1090
|
-
qz1 = z1;
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
box.setBounds(qx0, qy0, qz0, qx1, qy1, qz1);
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
/**
|
|
1097
|
-
*
|
|
1098
|
-
* @param {BinaryBuffer} buffer
|
|
1099
|
-
* @param {AABB3} box
|
|
1100
|
-
* @param {number} x0
|
|
1101
|
-
* @param {number} y0
|
|
1102
|
-
* @param {number} z0
|
|
1103
|
-
* @param {number} x1
|
|
1104
|
-
* @param {number} y1
|
|
1105
|
-
* @param {number} z1
|
|
1106
|
-
*/
|
|
1107
|
-
export function serializeAABB3Quantized16Uint(buffer, box, x0, y0, z0, x1, y1, z1) {
|
|
1108
|
-
//compute value ranges
|
|
1109
|
-
const xD = x1 - x0;
|
|
1110
|
-
const yD = y1 - y0;
|
|
1111
|
-
const zD = z1 - z0;
|
|
1112
|
-
|
|
1113
|
-
//quantize all values
|
|
1114
|
-
const _x0 = (((box.x0 - x0) / xD) * 65535) | 0;
|
|
1115
|
-
const _y0 = (((box.y0 - y0) / yD) * 65535) | 0;
|
|
1116
|
-
const _z0 = (((box.z0 - z0) / zD) * 65535) | 0;
|
|
1117
|
-
|
|
1118
|
-
const _x1 = (((box.x1 - x0) / xD) * 65535) | 0;
|
|
1119
|
-
const _y1 = (((box.y1 - y0) / yD) * 65535) | 0;
|
|
1120
|
-
const _z1 = (((box.z1 - z0) / zD) * 65535) | 0;
|
|
1121
|
-
|
|
1122
|
-
buffer.writeUint16(_x0);
|
|
1123
|
-
buffer.writeUint16(_y0);
|
|
1124
|
-
buffer.writeUint16(_z0);
|
|
1125
|
-
buffer.writeUint16(_x1);
|
|
1126
|
-
buffer.writeUint16(_y1);
|
|
1127
|
-
buffer.writeUint16(_z1);
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
/**
|
|
1131
|
-
*
|
|
1132
|
-
* @param {BinaryBuffer} buffer
|
|
1133
|
-
* @param {AABB3} box
|
|
1134
|
-
* @param {number} x0
|
|
1135
|
-
* @param {number} y0
|
|
1136
|
-
* @param {number} z0
|
|
1137
|
-
* @param {number} x1
|
|
1138
|
-
* @param {number} y1
|
|
1139
|
-
* @param {number} z1
|
|
1140
|
-
*/
|
|
1141
|
-
export function deserializeAABB3Quantized16Uint(buffer, box, x0, y0, z0, x1, y1, z1) {
|
|
1142
|
-
//compute value ranges
|
|
1143
|
-
const xD = x1 - x0;
|
|
1144
|
-
const yD = y1 - y0;
|
|
1145
|
-
const zD = z1 - z0;
|
|
1146
|
-
|
|
1147
|
-
//read values
|
|
1148
|
-
const _x0 = buffer.readUint16();
|
|
1149
|
-
const _y0 = buffer.readUint16();
|
|
1150
|
-
const _z0 = buffer.readUint16();
|
|
1151
|
-
const _x1 = buffer.readUint16();
|
|
1152
|
-
const _y1 = buffer.readUint16();
|
|
1153
|
-
const _z1 = buffer.readUint16();
|
|
1154
|
-
|
|
1155
|
-
//quantize all values
|
|
1156
|
-
const qx0 = (_x0 / 65535) * xD + x0;
|
|
1157
|
-
const qy0 = (_y0 / 65535) * yD + y0;
|
|
1158
|
-
const qz0 = (_z0 / 65535) * zD + z0;
|
|
1159
|
-
|
|
1160
|
-
const qx1 = (_x1 / 65535) * xD + x0;
|
|
1161
|
-
const qy1 = (_y1 / 65535) * yD + y0;
|
|
1162
|
-
const qz1 = (_z1 / 65535) * zD + z0;
|
|
1163
|
-
|
|
1164
|
-
box.setBounds(qx0, qy0, qz0, qx1, qy1, qz1);
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
/**
|
|
1168
|
-
*
|
|
1169
|
-
* @param {BinaryBuffer} buffer
|
|
1170
|
-
* @param {AABB3} box
|
|
1171
|
-
*/
|
|
1172
|
-
function serializeAABB3(buffer, box) {
|
|
1173
|
-
buffer.writeFloat64(box.x0);
|
|
1174
|
-
buffer.writeFloat64(box.y0);
|
|
1175
|
-
buffer.writeFloat64(box.z0);
|
|
1176
|
-
buffer.writeFloat64(box.x1);
|
|
1177
|
-
buffer.writeFloat64(box.y1);
|
|
1178
|
-
buffer.writeFloat64(box.z1);
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
/**
|
|
1182
|
-
*
|
|
1183
|
-
* @param {BinaryBuffer} buffer
|
|
1184
|
-
* @param {AABB3} box
|
|
1185
|
-
*/
|
|
1186
|
-
function deserializeAABB3(buffer, box) {
|
|
1187
|
-
const x0 = buffer.readFloat64();
|
|
1188
|
-
const y0 = buffer.readFloat64();
|
|
1189
|
-
const z0 = buffer.readFloat64();
|
|
1190
|
-
const x1 = buffer.readFloat64();
|
|
1191
|
-
const y1 = buffer.readFloat64();
|
|
1192
|
-
const z1 = buffer.readFloat64();
|
|
1193
|
-
|
|
1194
|
-
box.setBounds(x0, y0, z0, x1, y1, z1);
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
export {
|
|
1198
|
-
AABB3,
|
|
1199
|
-
serializeAABB3,
|
|
1200
|
-
deserializeAABB3
|
|
1201
|
-
};
|
|
1021
|
+
AABB3.prototype.isAABB3 = true;
|