@math.gl/culling 4.0.0 → 4.0.1
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/dist/constants.d.ts +0 -1
- package/dist/constants.js +5 -4
- package/dist/index.cjs +27 -45
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +11 -12
- package/dist/index.js +2 -1
- package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -3
- package/dist/lib/algorithms/bounding-box-from-points.js +113 -113
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +1 -2
- package/dist/lib/algorithms/bounding-sphere-from-points.js +117 -103
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -2
- package/dist/lib/algorithms/compute-eigen-decomposition.js +113 -85
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -3
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +100 -80
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -3
- package/dist/lib/bounding-volumes/bounding-sphere.js +106 -97
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -2
- package/dist/lib/bounding-volumes/bounding-volume.js +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +3 -4
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +238 -196
- package/dist/lib/culling-volume.d.ts +3 -4
- package/dist/lib/culling-volume.js +109 -90
- package/dist/lib/perspective-frustum.d.ts +2 -3
- package/dist/lib/perspective-frustum.js +184 -136
- package/dist/lib/perspective-off-center-frustum.d.ts +2 -3
- package/dist/lib/perspective-off-center-frustum.js +259 -158
- package/dist/lib/plane.d.ts +0 -1
- package/dist/lib/plane.js +58 -59
- package/package.json +5 -6
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +0 -1
- package/dist/lib/algorithms/bounding-box-from-points.js.map +0 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +0 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +0 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +0 -1
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/bounding-volume.js.map +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
- package/dist/lib/culling-volume.d.ts.map +0 -1
- package/dist/lib/culling-volume.js.map +0 -1
- package/dist/lib/perspective-frustum.d.ts.map +0 -1
- package/dist/lib/perspective-frustum.js.map +0 -1
- package/dist/lib/perspective-off-center-frustum.d.ts.map +0 -1
- package/dist/lib/perspective-off-center-frustum.js.map +0 -1
- package/dist/lib/plane.d.ts.map +0 -1
- package/dist/lib/plane.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vector3, Matrix3, Matrix4, Quaternion, NumericArray } from '@math.gl/core';
|
|
2
|
-
import type { BoundingVolume } from
|
|
3
|
-
import { BoundingSphere } from
|
|
4
|
-
import type { Plane } from
|
|
2
|
+
import type { BoundingVolume } from "./bounding-volume.js";
|
|
3
|
+
import { BoundingSphere } from "./bounding-sphere.js";
|
|
4
|
+
import type { Plane } from "../plane.js";
|
|
5
5
|
/**
|
|
6
6
|
* An OrientedBoundingBox of some object is a closed and convex cuboid.
|
|
7
7
|
* It can provide a tighter bounding volume than `BoundingSphere` or
|
|
@@ -63,4 +63,3 @@ export declare class OrientedBoundingBox implements BoundingVolume {
|
|
|
63
63
|
transform(transformation: readonly number[]): this;
|
|
64
64
|
getTransform(): Matrix4;
|
|
65
65
|
}
|
|
66
|
-
//# sourceMappingURL=oriented-bounding-box.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
2
3
|
import { Vector3, Matrix3, Quaternion } from '@math.gl/core';
|
|
3
4
|
import { BoundingSphere } from "./bounding-sphere.js";
|
|
4
5
|
import { INTERSECTION } from "../../constants.js";
|
|
@@ -10,205 +11,246 @@ const scratchVectorW = new Vector3();
|
|
|
10
11
|
const scratchCorner = new Vector3();
|
|
11
12
|
const scratchToCenter = new Vector3();
|
|
12
13
|
const MATRIX3 = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
COLUMN0ROW0: 0,
|
|
15
|
+
COLUMN0ROW1: 1,
|
|
16
|
+
COLUMN0ROW2: 2,
|
|
17
|
+
COLUMN1ROW0: 3,
|
|
18
|
+
COLUMN1ROW1: 4,
|
|
19
|
+
COLUMN1ROW2: 5,
|
|
20
|
+
COLUMN2ROW0: 6,
|
|
21
|
+
COLUMN2ROW1: 7,
|
|
22
|
+
COLUMN2ROW2: 8
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* An OrientedBoundingBox of some object is a closed and convex cuboid.
|
|
26
|
+
* It can provide a tighter bounding volume than `BoundingSphere` or
|
|
27
|
+
* `AxisAlignedBoundingBox` in many cases.
|
|
28
|
+
*/
|
|
23
29
|
export class OrientedBoundingBox {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "halfAxes", void 0);
|
|
28
|
-
|
|
29
|
-
this.center = new Vector3().from(center);
|
|
30
|
-
this.halfAxes = new Matrix3(halfAxes);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get halfSize() {
|
|
34
|
-
const xAxis = this.halfAxes.getColumn(0);
|
|
35
|
-
const yAxis = this.halfAxes.getColumn(1);
|
|
36
|
-
const zAxis = this.halfAxes.getColumn(2);
|
|
37
|
-
return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get quaternion() {
|
|
41
|
-
const xAxis = this.halfAxes.getColumn(0);
|
|
42
|
-
const yAxis = this.halfAxes.getColumn(1);
|
|
43
|
-
const zAxis = this.halfAxes.getColumn(2);
|
|
44
|
-
const normXAxis = new Vector3(xAxis).normalize();
|
|
45
|
-
const normYAxis = new Vector3(yAxis).normalize();
|
|
46
|
-
const normZAxis = new Vector3(zAxis).normalize();
|
|
47
|
-
return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
fromCenterHalfSizeQuaternion(center, halfSize, quaternion) {
|
|
51
|
-
const quaternionObject = new Quaternion(quaternion);
|
|
52
|
-
const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);
|
|
53
|
-
directionsMatrix[0] = directionsMatrix[0] * halfSize[0];
|
|
54
|
-
directionsMatrix[1] = directionsMatrix[1] * halfSize[0];
|
|
55
|
-
directionsMatrix[2] = directionsMatrix[2] * halfSize[0];
|
|
56
|
-
directionsMatrix[3] = directionsMatrix[3] * halfSize[1];
|
|
57
|
-
directionsMatrix[4] = directionsMatrix[4] * halfSize[1];
|
|
58
|
-
directionsMatrix[5] = directionsMatrix[5] * halfSize[1];
|
|
59
|
-
directionsMatrix[6] = directionsMatrix[6] * halfSize[2];
|
|
60
|
-
directionsMatrix[7] = directionsMatrix[7] * halfSize[2];
|
|
61
|
-
directionsMatrix[8] = directionsMatrix[8] * halfSize[2];
|
|
62
|
-
this.center = new Vector3().from(center);
|
|
63
|
-
this.halfAxes = directionsMatrix;
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
clone() {
|
|
68
|
-
return new OrientedBoundingBox(this.center, this.halfAxes);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
equals(right) {
|
|
72
|
-
return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getBoundingSphere(result = new BoundingSphere()) {
|
|
76
|
-
const halfAxes = this.halfAxes;
|
|
77
|
-
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
78
|
-
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
79
|
-
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
80
|
-
const cornerVector = scratchVector3.copy(u).add(v).add(w);
|
|
81
|
-
result.center.copy(this.center);
|
|
82
|
-
result.radius = cornerVector.magnitude();
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
intersectPlane(plane) {
|
|
87
|
-
const center = this.center;
|
|
88
|
-
const normal = plane.normal;
|
|
89
|
-
const halfAxes = this.halfAxes;
|
|
90
|
-
const normalX = normal.x;
|
|
91
|
-
const normalY = normal.y;
|
|
92
|
-
const normalZ = normal.z;
|
|
93
|
-
const radEffective = Math.abs(normalX * halfAxes[MATRIX3.COLUMN0ROW0] + normalY * halfAxes[MATRIX3.COLUMN0ROW1] + normalZ * halfAxes[MATRIX3.COLUMN0ROW2]) + Math.abs(normalX * halfAxes[MATRIX3.COLUMN1ROW0] + normalY * halfAxes[MATRIX3.COLUMN1ROW1] + normalZ * halfAxes[MATRIX3.COLUMN1ROW2]) + Math.abs(normalX * halfAxes[MATRIX3.COLUMN2ROW0] + normalY * halfAxes[MATRIX3.COLUMN2ROW1] + normalZ * halfAxes[MATRIX3.COLUMN2ROW2]);
|
|
94
|
-
const distanceToPlane = normal.dot(center) + plane.distance;
|
|
95
|
-
|
|
96
|
-
if (distanceToPlane <= -radEffective) {
|
|
97
|
-
return INTERSECTION.OUTSIDE;
|
|
98
|
-
} else if (distanceToPlane >= radEffective) {
|
|
99
|
-
return INTERSECTION.INSIDE;
|
|
30
|
+
constructor(center = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {
|
|
31
|
+
this.center = new Vector3().from(center);
|
|
32
|
+
this.halfAxes = new Matrix3(halfAxes);
|
|
100
33
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
distanceSquaredTo(point) {
|
|
110
|
-
const offset = scratchOffset.from(point).subtract(this.center);
|
|
111
|
-
const halfAxes = this.halfAxes;
|
|
112
|
-
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
113
|
-
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
114
|
-
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
115
|
-
const uHalf = u.magnitude();
|
|
116
|
-
const vHalf = v.magnitude();
|
|
117
|
-
const wHalf = w.magnitude();
|
|
118
|
-
u.normalize();
|
|
119
|
-
v.normalize();
|
|
120
|
-
w.normalize();
|
|
121
|
-
let distanceSquared = 0.0;
|
|
122
|
-
let d;
|
|
123
|
-
d = Math.abs(offset.dot(u)) - uHalf;
|
|
124
|
-
|
|
125
|
-
if (d > 0) {
|
|
126
|
-
distanceSquared += d * d;
|
|
34
|
+
/** Returns an array with three halfSizes for the bounding box */
|
|
35
|
+
get halfSize() {
|
|
36
|
+
const xAxis = this.halfAxes.getColumn(0);
|
|
37
|
+
const yAxis = this.halfAxes.getColumn(1);
|
|
38
|
+
const zAxis = this.halfAxes.getColumn(2);
|
|
39
|
+
return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];
|
|
127
40
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
41
|
+
/** Returns a quaternion describing the orientation of the bounding box */
|
|
42
|
+
get quaternion() {
|
|
43
|
+
const xAxis = this.halfAxes.getColumn(0);
|
|
44
|
+
const yAxis = this.halfAxes.getColumn(1);
|
|
45
|
+
const zAxis = this.halfAxes.getColumn(2);
|
|
46
|
+
const normXAxis = new Vector3(xAxis).normalize();
|
|
47
|
+
const normYAxis = new Vector3(yAxis).normalize();
|
|
48
|
+
const normZAxis = new Vector3(zAxis).normalize();
|
|
49
|
+
return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));
|
|
133
50
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Create OrientedBoundingBox from quaternion based OBB,
|
|
53
|
+
*/
|
|
54
|
+
fromCenterHalfSizeQuaternion(center, halfSize, quaternion) {
|
|
55
|
+
const quaternionObject = new Quaternion(quaternion);
|
|
56
|
+
const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);
|
|
57
|
+
directionsMatrix[0] = directionsMatrix[0] * halfSize[0];
|
|
58
|
+
directionsMatrix[1] = directionsMatrix[1] * halfSize[0];
|
|
59
|
+
directionsMatrix[2] = directionsMatrix[2] * halfSize[0];
|
|
60
|
+
directionsMatrix[3] = directionsMatrix[3] * halfSize[1];
|
|
61
|
+
directionsMatrix[4] = directionsMatrix[4] * halfSize[1];
|
|
62
|
+
directionsMatrix[5] = directionsMatrix[5] * halfSize[1];
|
|
63
|
+
directionsMatrix[6] = directionsMatrix[6] * halfSize[2];
|
|
64
|
+
directionsMatrix[7] = directionsMatrix[7] * halfSize[2];
|
|
65
|
+
directionsMatrix[8] = directionsMatrix[8] * halfSize[2];
|
|
66
|
+
this.center = new Vector3().from(center);
|
|
67
|
+
this.halfAxes = directionsMatrix;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/** Duplicates a OrientedBoundingBox instance. */
|
|
71
|
+
clone() {
|
|
72
|
+
return new OrientedBoundingBox(this.center, this.halfAxes);
|
|
73
|
+
}
|
|
74
|
+
/** Compares the provided OrientedBoundingBox component wise and returns */
|
|
75
|
+
equals(right) {
|
|
76
|
+
return (this === right ||
|
|
77
|
+
(Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes)));
|
|
78
|
+
}
|
|
79
|
+
/** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */
|
|
80
|
+
getBoundingSphere(result = new BoundingSphere()) {
|
|
81
|
+
const halfAxes = this.halfAxes;
|
|
82
|
+
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
83
|
+
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
84
|
+
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
85
|
+
// Calculate "corner" vector
|
|
86
|
+
const cornerVector = scratchVector3.copy(u).add(v).add(w);
|
|
87
|
+
result.center.copy(this.center);
|
|
88
|
+
result.radius = cornerVector.magnitude();
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
/** Determines which side of a plane the oriented bounding box is located. */
|
|
92
|
+
intersectPlane(plane) {
|
|
93
|
+
const center = this.center;
|
|
94
|
+
const normal = plane.normal;
|
|
95
|
+
const halfAxes = this.halfAxes;
|
|
96
|
+
const normalX = normal.x;
|
|
97
|
+
const normalY = normal.y;
|
|
98
|
+
const normalZ = normal.z;
|
|
99
|
+
// Plane is used as if it is its normal; the first three components are assumed to be normalized
|
|
100
|
+
const radEffective = Math.abs(normalX * halfAxes[MATRIX3.COLUMN0ROW0] +
|
|
101
|
+
normalY * halfAxes[MATRIX3.COLUMN0ROW1] +
|
|
102
|
+
normalZ * halfAxes[MATRIX3.COLUMN0ROW2]) +
|
|
103
|
+
Math.abs(normalX * halfAxes[MATRIX3.COLUMN1ROW0] +
|
|
104
|
+
normalY * halfAxes[MATRIX3.COLUMN1ROW1] +
|
|
105
|
+
normalZ * halfAxes[MATRIX3.COLUMN1ROW2]) +
|
|
106
|
+
Math.abs(normalX * halfAxes[MATRIX3.COLUMN2ROW0] +
|
|
107
|
+
normalY * halfAxes[MATRIX3.COLUMN2ROW1] +
|
|
108
|
+
normalZ * halfAxes[MATRIX3.COLUMN2ROW2]);
|
|
109
|
+
const distanceToPlane = normal.dot(center) + plane.distance;
|
|
110
|
+
if (distanceToPlane <= -radEffective) {
|
|
111
|
+
// The entire box is on the negative side of the plane normal
|
|
112
|
+
return INTERSECTION.OUTSIDE;
|
|
113
|
+
}
|
|
114
|
+
else if (distanceToPlane >= radEffective) {
|
|
115
|
+
// The entire box is on the positive side of the plane normal
|
|
116
|
+
return INTERSECTION.INSIDE;
|
|
117
|
+
}
|
|
118
|
+
return INTERSECTION.INTERSECTING;
|
|
119
|
+
}
|
|
120
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
121
|
+
distanceTo(point) {
|
|
122
|
+
return Math.sqrt(this.distanceSquaredTo(point));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Computes the estimated distance squared from the closest point
|
|
126
|
+
* on a bounding box to a point.
|
|
127
|
+
* See Geometric Tools for Computer Graphics 10.4.2
|
|
128
|
+
*/
|
|
129
|
+
distanceSquaredTo(point) {
|
|
130
|
+
// Computes the estimated distance squared from the
|
|
131
|
+
// closest point on a bounding box to a point.
|
|
132
|
+
// See Geometric Tools for Computer Graphics 10.4.2
|
|
133
|
+
const offset = scratchOffset.from(point).subtract(this.center);
|
|
134
|
+
const halfAxes = this.halfAxes;
|
|
135
|
+
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
136
|
+
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
137
|
+
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
138
|
+
const uHalf = u.magnitude();
|
|
139
|
+
const vHalf = v.magnitude();
|
|
140
|
+
const wHalf = w.magnitude();
|
|
141
|
+
u.normalize();
|
|
142
|
+
v.normalize();
|
|
143
|
+
w.normalize();
|
|
144
|
+
let distanceSquared = 0.0;
|
|
145
|
+
let d;
|
|
146
|
+
d = Math.abs(offset.dot(u)) - uHalf;
|
|
147
|
+
if (d > 0) {
|
|
148
|
+
distanceSquared += d * d;
|
|
149
|
+
}
|
|
150
|
+
d = Math.abs(offset.dot(v)) - vHalf;
|
|
151
|
+
if (d > 0) {
|
|
152
|
+
distanceSquared += d * d;
|
|
153
|
+
}
|
|
154
|
+
d = Math.abs(offset.dot(w)) - wHalf;
|
|
155
|
+
if (d > 0) {
|
|
156
|
+
distanceSquared += d * d;
|
|
157
|
+
}
|
|
158
|
+
return distanceSquared;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The distances calculated by the vector from the center of the bounding box
|
|
162
|
+
* to position projected onto direction.
|
|
163
|
+
*
|
|
164
|
+
* - If you imagine the infinite number of planes with normal direction,
|
|
165
|
+
* this computes the smallest distance to the closest and farthest planes
|
|
166
|
+
* from `position` that intersect the bounding box.
|
|
167
|
+
*
|
|
168
|
+
* @param position The position to calculate the distance from.
|
|
169
|
+
* @param direction The direction from position.
|
|
170
|
+
* @param result An Interval (array of length 2) to store the nearest and farthest distances.
|
|
171
|
+
* @returns Interval (array of length 2) with nearest and farthest distances
|
|
172
|
+
* on the bounding box from position in direction.
|
|
173
|
+
*/
|
|
174
|
+
// eslint-disable-next-line max-statements
|
|
175
|
+
computePlaneDistances(position, direction, result = [-0, -0]) {
|
|
176
|
+
let minDist = Number.POSITIVE_INFINITY;
|
|
177
|
+
let maxDist = Number.NEGATIVE_INFINITY;
|
|
178
|
+
const center = this.center;
|
|
179
|
+
const halfAxes = this.halfAxes;
|
|
180
|
+
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
181
|
+
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
182
|
+
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
183
|
+
// project first corner
|
|
184
|
+
const corner = scratchCorner.copy(u).add(v).add(w).add(center);
|
|
185
|
+
const toCenter = scratchToCenter.copy(corner).subtract(position);
|
|
186
|
+
let mag = direction.dot(toCenter);
|
|
187
|
+
minDist = Math.min(mag, minDist);
|
|
188
|
+
maxDist = Math.max(mag, maxDist);
|
|
189
|
+
// project second corner
|
|
190
|
+
corner.copy(center).add(u).add(v).subtract(w);
|
|
191
|
+
toCenter.copy(corner).subtract(position);
|
|
192
|
+
mag = direction.dot(toCenter);
|
|
193
|
+
minDist = Math.min(mag, minDist);
|
|
194
|
+
maxDist = Math.max(mag, maxDist);
|
|
195
|
+
// project third corner
|
|
196
|
+
corner.copy(center).add(u).subtract(v).add(w);
|
|
197
|
+
toCenter.copy(corner).subtract(position);
|
|
198
|
+
mag = direction.dot(toCenter);
|
|
199
|
+
minDist = Math.min(mag, minDist);
|
|
200
|
+
maxDist = Math.max(mag, maxDist);
|
|
201
|
+
// project fourth corner
|
|
202
|
+
corner.copy(center).add(u).subtract(v).subtract(w);
|
|
203
|
+
toCenter.copy(corner).subtract(position);
|
|
204
|
+
mag = direction.dot(toCenter);
|
|
205
|
+
minDist = Math.min(mag, minDist);
|
|
206
|
+
maxDist = Math.max(mag, maxDist);
|
|
207
|
+
// project fifth corner
|
|
208
|
+
center.copy(corner).subtract(u).add(v).add(w);
|
|
209
|
+
toCenter.copy(corner).subtract(position);
|
|
210
|
+
mag = direction.dot(toCenter);
|
|
211
|
+
minDist = Math.min(mag, minDist);
|
|
212
|
+
maxDist = Math.max(mag, maxDist);
|
|
213
|
+
// project sixth corner
|
|
214
|
+
center.copy(corner).subtract(u).add(v).subtract(w);
|
|
215
|
+
toCenter.copy(corner).subtract(position);
|
|
216
|
+
mag = direction.dot(toCenter);
|
|
217
|
+
minDist = Math.min(mag, minDist);
|
|
218
|
+
maxDist = Math.max(mag, maxDist);
|
|
219
|
+
// project seventh corner
|
|
220
|
+
center.copy(corner).subtract(u).subtract(v).add(w);
|
|
221
|
+
toCenter.copy(corner).subtract(position);
|
|
222
|
+
mag = direction.dot(toCenter);
|
|
223
|
+
minDist = Math.min(mag, minDist);
|
|
224
|
+
maxDist = Math.max(mag, maxDist);
|
|
225
|
+
// project eighth corner
|
|
226
|
+
center.copy(corner).subtract(u).subtract(v).subtract(w);
|
|
227
|
+
toCenter.copy(corner).subtract(position);
|
|
228
|
+
mag = direction.dot(toCenter);
|
|
229
|
+
minDist = Math.min(mag, minDist);
|
|
230
|
+
maxDist = Math.max(mag, maxDist);
|
|
231
|
+
result[0] = minDist;
|
|
232
|
+
result[1] = maxDist;
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
237
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
238
|
+
* @returns itself, i.e. the modified BoundingVolume.
|
|
239
|
+
*/
|
|
240
|
+
transform(transformation) {
|
|
241
|
+
this.center.transformAsPoint(transformation);
|
|
242
|
+
const xAxis = this.halfAxes.getColumn(0, scratchVectorU);
|
|
243
|
+
xAxis.transformAsPoint(transformation);
|
|
244
|
+
const yAxis = this.halfAxes.getColumn(1, scratchVectorV);
|
|
245
|
+
yAxis.transformAsPoint(transformation);
|
|
246
|
+
const zAxis = this.halfAxes.getColumn(2, scratchVectorW);
|
|
247
|
+
zAxis.transformAsPoint(transformation);
|
|
248
|
+
this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
getTransform() {
|
|
252
|
+
// const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);
|
|
253
|
+
// return modelMatrix;
|
|
254
|
+
throw new Error('not implemented');
|
|
139
255
|
}
|
|
140
|
-
|
|
141
|
-
return distanceSquared;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
computePlaneDistances(position, direction, result = [-0, -0]) {
|
|
145
|
-
let minDist = Number.POSITIVE_INFINITY;
|
|
146
|
-
let maxDist = Number.NEGATIVE_INFINITY;
|
|
147
|
-
const center = this.center;
|
|
148
|
-
const halfAxes = this.halfAxes;
|
|
149
|
-
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
150
|
-
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
151
|
-
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
152
|
-
const corner = scratchCorner.copy(u).add(v).add(w).add(center);
|
|
153
|
-
const toCenter = scratchToCenter.copy(corner).subtract(position);
|
|
154
|
-
let mag = direction.dot(toCenter);
|
|
155
|
-
minDist = Math.min(mag, minDist);
|
|
156
|
-
maxDist = Math.max(mag, maxDist);
|
|
157
|
-
corner.copy(center).add(u).add(v).subtract(w);
|
|
158
|
-
toCenter.copy(corner).subtract(position);
|
|
159
|
-
mag = direction.dot(toCenter);
|
|
160
|
-
minDist = Math.min(mag, minDist);
|
|
161
|
-
maxDist = Math.max(mag, maxDist);
|
|
162
|
-
corner.copy(center).add(u).subtract(v).add(w);
|
|
163
|
-
toCenter.copy(corner).subtract(position);
|
|
164
|
-
mag = direction.dot(toCenter);
|
|
165
|
-
minDist = Math.min(mag, minDist);
|
|
166
|
-
maxDist = Math.max(mag, maxDist);
|
|
167
|
-
corner.copy(center).add(u).subtract(v).subtract(w);
|
|
168
|
-
toCenter.copy(corner).subtract(position);
|
|
169
|
-
mag = direction.dot(toCenter);
|
|
170
|
-
minDist = Math.min(mag, minDist);
|
|
171
|
-
maxDist = Math.max(mag, maxDist);
|
|
172
|
-
center.copy(corner).subtract(u).add(v).add(w);
|
|
173
|
-
toCenter.copy(corner).subtract(position);
|
|
174
|
-
mag = direction.dot(toCenter);
|
|
175
|
-
minDist = Math.min(mag, minDist);
|
|
176
|
-
maxDist = Math.max(mag, maxDist);
|
|
177
|
-
center.copy(corner).subtract(u).add(v).subtract(w);
|
|
178
|
-
toCenter.copy(corner).subtract(position);
|
|
179
|
-
mag = direction.dot(toCenter);
|
|
180
|
-
minDist = Math.min(mag, minDist);
|
|
181
|
-
maxDist = Math.max(mag, maxDist);
|
|
182
|
-
center.copy(corner).subtract(u).subtract(v).add(w);
|
|
183
|
-
toCenter.copy(corner).subtract(position);
|
|
184
|
-
mag = direction.dot(toCenter);
|
|
185
|
-
minDist = Math.min(mag, minDist);
|
|
186
|
-
maxDist = Math.max(mag, maxDist);
|
|
187
|
-
center.copy(corner).subtract(u).subtract(v).subtract(w);
|
|
188
|
-
toCenter.copy(corner).subtract(position);
|
|
189
|
-
mag = direction.dot(toCenter);
|
|
190
|
-
minDist = Math.min(mag, minDist);
|
|
191
|
-
maxDist = Math.max(mag, maxDist);
|
|
192
|
-
result[0] = minDist;
|
|
193
|
-
result[1] = maxDist;
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
transform(transformation) {
|
|
198
|
-
this.center.transformAsPoint(transformation);
|
|
199
|
-
const xAxis = this.halfAxes.getColumn(0, scratchVectorU);
|
|
200
|
-
xAxis.transformAsPoint(transformation);
|
|
201
|
-
const yAxis = this.halfAxes.getColumn(1, scratchVectorV);
|
|
202
|
-
yAxis.transformAsPoint(transformation);
|
|
203
|
-
const zAxis = this.halfAxes.getColumn(2, scratchVectorW);
|
|
204
|
-
zAxis.transformAsPoint(transformation);
|
|
205
|
-
this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);
|
|
206
|
-
return this;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
getTransform() {
|
|
210
|
-
throw new Error('not implemented');
|
|
211
|
-
}
|
|
212
|
-
|
|
213
256
|
}
|
|
214
|
-
//# sourceMappingURL=oriented-bounding-box.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Plane } from
|
|
2
|
-
import type { BoundingVolume } from
|
|
3
|
-
import type { BoundingSphere } from
|
|
1
|
+
import { Plane } from "./plane.js";
|
|
2
|
+
import type { BoundingVolume } from "./bounding-volumes/bounding-volume.js";
|
|
3
|
+
import type { BoundingSphere } from "./bounding-volumes/bounding-sphere.js";
|
|
4
4
|
/** A culling volume defined by planes. */
|
|
5
5
|
export declare class CullingVolume {
|
|
6
6
|
/**
|
|
@@ -42,4 +42,3 @@ export declare class CullingVolume {
|
|
|
42
42
|
*/
|
|
43
43
|
computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number;
|
|
44
44
|
}
|
|
45
|
-
//# sourceMappingURL=culling-volume.d.ts.map
|