@math.gl/culling
Advanced tools
Comparing version 3.6.0-alpha.1 to 3.6.0-alpha.2
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.INTERSECTION = void 0; | ||
let INTERSECTION; | ||
var INTERSECTION; | ||
exports.INTERSECTION = INTERSECTION; | ||
@@ -10,0 +10,0 @@ |
@@ -10,3 +10,3 @@ "use strict"; | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _constants.INTERSECTION; | ||
@@ -17,3 +17,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _axisAlignedBoundingBox.default; | ||
@@ -24,3 +24,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _boundingSphere.default; | ||
@@ -31,3 +31,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _orientedBoundingBox.default; | ||
@@ -38,3 +38,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _cullingVolume.default; | ||
@@ -45,3 +45,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _plane.default; | ||
@@ -52,3 +52,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _perspectiveOffCenterFrustum.default; | ||
@@ -59,3 +59,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _perspectiveFrustum.default; | ||
@@ -66,3 +66,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _boundingSphereFromPoints.default; | ||
@@ -73,3 +73,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _boundingBoxFromPoints.makeAxisAlignedBoundingBoxFromPoints; | ||
@@ -80,3 +80,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _boundingBoxFromPoints.makeOrientedBoundingBoxFromPoints; | ||
@@ -87,3 +87,3 @@ } | ||
enumerable: true, | ||
get: function () { | ||
get: function get() { | ||
return _computeEigenDecomposition.default; | ||
@@ -90,0 +90,0 @@ } |
@@ -19,9 +19,15 @@ "use strict"; | ||
const scratchVector2 = new _core.Vector3(); | ||
const scratchVector3 = new _core.Vector3(); | ||
const scratchVector4 = new _core.Vector3(); | ||
const scratchVector5 = new _core.Vector3(); | ||
const scratchVector6 = new _core.Vector3(); | ||
const scratchCovarianceResult = new _core.Matrix3(); | ||
const scratchEigenResult = { | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var scratchVector2 = new _core.Vector3(); | ||
var scratchVector3 = new _core.Vector3(); | ||
var scratchVector4 = new _core.Vector3(); | ||
var scratchVector5 = new _core.Vector3(); | ||
var scratchVector6 = new _core.Vector3(); | ||
var scratchCovarianceResult = new _core.Matrix3(); | ||
var scratchEigenResult = { | ||
diagonal: new _core.Matrix3(), | ||
@@ -31,3 +37,5 @@ unitary: new _core.Matrix3() | ||
function makeOrientedBoundingBoxFromPoints(positions, result = new _orientedBoundingBox.default()) { | ||
function makeOrientedBoundingBoxFromPoints(positions) { | ||
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _orientedBoundingBox.default(); | ||
if (!positions || positions.length === 0) { | ||
@@ -39,26 +47,46 @@ result.halfAxes = new _core.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]); | ||
const length = positions.length; | ||
const meanPoint = new _core.Vector3(0, 0, 0); | ||
var length = positions.length; | ||
var meanPoint = new _core.Vector3(0, 0, 0); | ||
for (const position of positions) { | ||
meanPoint.add(position); | ||
var _iterator = _createForOfIteratorHelper(positions), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var position = _step.value; | ||
meanPoint.add(position); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
const invLength = 1.0 / length; | ||
var invLength = 1.0 / length; | ||
meanPoint.multiplyByScalar(invLength); | ||
let exx = 0.0; | ||
let exy = 0.0; | ||
let exz = 0.0; | ||
let eyy = 0.0; | ||
let eyz = 0.0; | ||
let ezz = 0.0; | ||
var exx = 0.0; | ||
var exy = 0.0; | ||
var exz = 0.0; | ||
var eyy = 0.0; | ||
var eyz = 0.0; | ||
var ezz = 0.0; | ||
for (const position of positions) { | ||
const p = scratchVector2.copy(position).subtract(meanPoint); | ||
exx += p.x * p.x; | ||
exy += p.x * p.y; | ||
exz += p.x * p.z; | ||
eyy += p.y * p.y; | ||
eyz += p.y * p.z; | ||
ezz += p.z * p.z; | ||
var _iterator2 = _createForOfIteratorHelper(positions), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var _position = _step2.value; | ||
var p = scratchVector2.copy(_position).subtract(meanPoint); | ||
exx += p.x * p.x; | ||
exy += p.x * p.y; | ||
exz += p.x * p.z; | ||
eyy += p.y * p.y; | ||
eyz += p.y * p.z; | ||
ezz += p.z * p.z; | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
@@ -72,3 +100,3 @@ | ||
ezz *= invLength; | ||
const covarianceMatrix = scratchCovarianceResult; | ||
var covarianceMatrix = scratchCovarianceResult; | ||
covarianceMatrix[0] = exx; | ||
@@ -83,24 +111,35 @@ covarianceMatrix[1] = exy; | ||
covarianceMatrix[8] = ezz; | ||
const { | ||
unitary | ||
} = (0, _computeEigenDecomposition.default)(covarianceMatrix, scratchEigenResult); | ||
const rotation = result.halfAxes.copy(unitary); | ||
let v1 = rotation.getColumn(0, scratchVector4); | ||
let v2 = rotation.getColumn(1, scratchVector5); | ||
let v3 = rotation.getColumn(2, scratchVector6); | ||
let u1 = -Number.MAX_VALUE; | ||
let u2 = -Number.MAX_VALUE; | ||
let u3 = -Number.MAX_VALUE; | ||
let l1 = Number.MAX_VALUE; | ||
let l2 = Number.MAX_VALUE; | ||
let l3 = Number.MAX_VALUE; | ||
for (const position of positions) { | ||
scratchVector2.copy(position); | ||
u1 = Math.max(scratchVector2.dot(v1), u1); | ||
u2 = Math.max(scratchVector2.dot(v2), u2); | ||
u3 = Math.max(scratchVector2.dot(v3), u3); | ||
l1 = Math.min(scratchVector2.dot(v1), l1); | ||
l2 = Math.min(scratchVector2.dot(v2), l2); | ||
l3 = Math.min(scratchVector2.dot(v3), l3); | ||
var _computeEigenDecompos = (0, _computeEigenDecomposition.default)(covarianceMatrix, scratchEigenResult), | ||
unitary = _computeEigenDecompos.unitary; | ||
var rotation = result.halfAxes.copy(unitary); | ||
var v1 = rotation.getColumn(0, scratchVector4); | ||
var v2 = rotation.getColumn(1, scratchVector5); | ||
var v3 = rotation.getColumn(2, scratchVector6); | ||
var u1 = -Number.MAX_VALUE; | ||
var u2 = -Number.MAX_VALUE; | ||
var u3 = -Number.MAX_VALUE; | ||
var l1 = Number.MAX_VALUE; | ||
var l2 = Number.MAX_VALUE; | ||
var l3 = Number.MAX_VALUE; | ||
var _iterator3 = _createForOfIteratorHelper(positions), | ||
_step3; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _position2 = _step3.value; | ||
scratchVector2.copy(_position2); | ||
u1 = Math.max(scratchVector2.dot(v1), u1); | ||
u2 = Math.max(scratchVector2.dot(v2), u2); | ||
u3 = Math.max(scratchVector2.dot(v3), u3); | ||
l1 = Math.min(scratchVector2.dot(v1), l1); | ||
l2 = Math.min(scratchVector2.dot(v2), l2); | ||
l3 = Math.min(scratchVector2.dot(v3), l3); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
} | ||
@@ -112,4 +151,4 @@ | ||
result.center.copy(v1).add(v2).add(v3); | ||
const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5); | ||
const scaleMatrix = new _core.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]); | ||
var scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5); | ||
var scaleMatrix = new _core.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]); | ||
result.halfAxes.multiplyRight(scaleMatrix); | ||
@@ -119,3 +158,5 @@ return result; | ||
function makeAxisAlignedBoundingBoxFromPoints(positions, result = new _axisAlignedBoundingBox.default()) { | ||
function makeAxisAlignedBoundingBoxFromPoints(positions) { | ||
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _axisAlignedBoundingBox.default(); | ||
if (!positions || positions.length === 0) { | ||
@@ -129,19 +170,29 @@ result.minimum.set(0, 0, 0); | ||
let minimumX = positions[0][0]; | ||
let minimumY = positions[0][1]; | ||
let minimumZ = positions[0][2]; | ||
let maximumX = positions[0][0]; | ||
let maximumY = positions[0][1]; | ||
let maximumZ = positions[0][2]; | ||
var minimumX = positions[0][0]; | ||
var minimumY = positions[0][1]; | ||
var minimumZ = positions[0][2]; | ||
var maximumX = positions[0][0]; | ||
var maximumY = positions[0][1]; | ||
var maximumZ = positions[0][2]; | ||
for (const p of positions) { | ||
const x = p[0]; | ||
const y = p[1]; | ||
const z = p[2]; | ||
minimumX = Math.min(x, minimumX); | ||
maximumX = Math.max(x, maximumX); | ||
minimumY = Math.min(y, minimumY); | ||
maximumY = Math.max(y, maximumY); | ||
minimumZ = Math.min(z, minimumZ); | ||
maximumZ = Math.max(z, maximumZ); | ||
var _iterator4 = _createForOfIteratorHelper(positions), | ||
_step4; | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var p = _step4.value; | ||
var x = p[0]; | ||
var y = p[1]; | ||
var z = p[2]; | ||
minimumX = Math.min(x, minimumX); | ||
maximumX = Math.max(x, maximumX); | ||
minimumY = Math.min(y, minimumY); | ||
maximumY = Math.max(y, maximumY); | ||
minimumZ = Math.min(z, minimumZ); | ||
maximumZ = Math.max(z, maximumZ); | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
@@ -148,0 +199,0 @@ |
@@ -14,17 +14,25 @@ "use strict"; | ||
const fromPointsXMin = new _core.Vector3(); | ||
const fromPointsYMin = new _core.Vector3(); | ||
const fromPointsZMin = new _core.Vector3(); | ||
const fromPointsXMax = new _core.Vector3(); | ||
const fromPointsYMax = new _core.Vector3(); | ||
const fromPointsZMax = new _core.Vector3(); | ||
const fromPointsCurrentPos = new _core.Vector3(); | ||
const fromPointsScratch = new _core.Vector3(); | ||
const fromPointsRitterCenter = new _core.Vector3(); | ||
const fromPointsMinBoxPt = new _core.Vector3(); | ||
const fromPointsMaxBoxPt = new _core.Vector3(); | ||
const fromPointsNaiveCenterScratch = new _core.Vector3(); | ||
const volumeConstant = 4.0 / 3.0 * Math.PI; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function makeBoundingSphereFromPoints(positions, result = new _boundingSphere.default()) { | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var fromPointsXMin = new _core.Vector3(); | ||
var fromPointsYMin = new _core.Vector3(); | ||
var fromPointsZMin = new _core.Vector3(); | ||
var fromPointsXMax = new _core.Vector3(); | ||
var fromPointsYMax = new _core.Vector3(); | ||
var fromPointsZMax = new _core.Vector3(); | ||
var fromPointsCurrentPos = new _core.Vector3(); | ||
var fromPointsScratch = new _core.Vector3(); | ||
var fromPointsRitterCenter = new _core.Vector3(); | ||
var fromPointsMinBoxPt = new _core.Vector3(); | ||
var fromPointsMaxBoxPt = new _core.Vector3(); | ||
var fromPointsNaiveCenterScratch = new _core.Vector3(); | ||
var volumeConstant = 4.0 / 3.0 * Math.PI; | ||
function makeBoundingSphereFromPoints(positions) { | ||
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _boundingSphere.default(); | ||
if (!positions || positions.length === 0) { | ||
@@ -34,47 +42,57 @@ return result.fromCenterRadius([0, 0, 0], 0); | ||
const currentPos = fromPointsCurrentPos.copy(positions[0]); | ||
const xMin = fromPointsXMin.copy(currentPos); | ||
const yMin = fromPointsYMin.copy(currentPos); | ||
const zMin = fromPointsZMin.copy(currentPos); | ||
const xMax = fromPointsXMax.copy(currentPos); | ||
const yMax = fromPointsYMax.copy(currentPos); | ||
const zMax = fromPointsZMax.copy(currentPos); | ||
var currentPos = fromPointsCurrentPos.copy(positions[0]); | ||
var xMin = fromPointsXMin.copy(currentPos); | ||
var yMin = fromPointsYMin.copy(currentPos); | ||
var zMin = fromPointsZMin.copy(currentPos); | ||
var xMax = fromPointsXMax.copy(currentPos); | ||
var yMax = fromPointsYMax.copy(currentPos); | ||
var zMax = fromPointsZMax.copy(currentPos); | ||
for (const position of positions) { | ||
currentPos.copy(position); | ||
const x = currentPos.x; | ||
const y = currentPos.y; | ||
const z = currentPos.z; | ||
var _iterator = _createForOfIteratorHelper(positions), | ||
_step; | ||
if (x < xMin.x) { | ||
xMin.copy(currentPos); | ||
} | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var position = _step.value; | ||
currentPos.copy(position); | ||
var x = currentPos.x; | ||
var y = currentPos.y; | ||
var z = currentPos.z; | ||
if (x > xMax.x) { | ||
xMax.copy(currentPos); | ||
} | ||
if (x < xMin.x) { | ||
xMin.copy(currentPos); | ||
} | ||
if (y < yMin.y) { | ||
yMin.copy(currentPos); | ||
} | ||
if (x > xMax.x) { | ||
xMax.copy(currentPos); | ||
} | ||
if (y > yMax.y) { | ||
yMax.copy(currentPos); | ||
} | ||
if (y < yMin.y) { | ||
yMin.copy(currentPos); | ||
} | ||
if (z < zMin.z) { | ||
zMin.copy(currentPos); | ||
} | ||
if (y > yMax.y) { | ||
yMax.copy(currentPos); | ||
} | ||
if (z > zMax.z) { | ||
zMax.copy(currentPos); | ||
if (z < zMin.z) { | ||
zMin.copy(currentPos); | ||
} | ||
if (z > zMax.z) { | ||
zMax.copy(currentPos); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared(); | ||
const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared(); | ||
const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared(); | ||
let diameter1 = xMin; | ||
let diameter2 = xMax; | ||
let maxSpan = xSpan; | ||
var xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared(); | ||
var ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared(); | ||
var zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared(); | ||
var diameter1 = xMin; | ||
var diameter2 = xMax; | ||
var maxSpan = xSpan; | ||
@@ -93,38 +111,48 @@ if (ySpan > maxSpan) { | ||
const ritterCenter = fromPointsRitterCenter; | ||
var ritterCenter = fromPointsRitterCenter; | ||
ritterCenter.x = (diameter1.x + diameter2.x) * 0.5; | ||
ritterCenter.y = (diameter1.y + diameter2.y) * 0.5; | ||
ritterCenter.z = (diameter1.z + diameter2.z) * 0.5; | ||
let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared(); | ||
let ritterRadius = Math.sqrt(radiusSquared); | ||
const minBoxPt = fromPointsMinBoxPt; | ||
var radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared(); | ||
var ritterRadius = Math.sqrt(radiusSquared); | ||
var minBoxPt = fromPointsMinBoxPt; | ||
minBoxPt.x = xMin.x; | ||
minBoxPt.y = yMin.y; | ||
minBoxPt.z = zMin.z; | ||
const maxBoxPt = fromPointsMaxBoxPt; | ||
var maxBoxPt = fromPointsMaxBoxPt; | ||
maxBoxPt.x = xMax.x; | ||
maxBoxPt.y = yMax.y; | ||
maxBoxPt.z = zMax.z; | ||
const naiveCenter = fromPointsNaiveCenterScratch.copy(minBoxPt).add(maxBoxPt).multiplyByScalar(0.5); | ||
let naiveRadius = 0; | ||
var naiveCenter = fromPointsNaiveCenterScratch.copy(minBoxPt).add(maxBoxPt).multiplyByScalar(0.5); | ||
var naiveRadius = 0; | ||
for (const position of positions) { | ||
currentPos.copy(position); | ||
const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude(); | ||
var _iterator2 = _createForOfIteratorHelper(positions), | ||
_step2; | ||
if (r > naiveRadius) { | ||
naiveRadius = r; | ||
} | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var _position = _step2.value; | ||
currentPos.copy(_position); | ||
var r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude(); | ||
const oldCenterToPointSquared = fromPointsScratch.copy(currentPos).subtract(ritterCenter).magnitudeSquared(); | ||
if (r > naiveRadius) { | ||
naiveRadius = r; | ||
} | ||
if (oldCenterToPointSquared > radiusSquared) { | ||
const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared); | ||
ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5; | ||
radiusSquared = ritterRadius * ritterRadius; | ||
const oldToNew = oldCenterToPoint - ritterRadius; | ||
ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint; | ||
ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint; | ||
ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint; | ||
var oldCenterToPointSquared = fromPointsScratch.copy(currentPos).subtract(ritterCenter).magnitudeSquared(); | ||
if (oldCenterToPointSquared > radiusSquared) { | ||
var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared); | ||
ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5; | ||
radiusSquared = ritterRadius * ritterRadius; | ||
var oldToNew = oldCenterToPoint - ritterRadius; | ||
ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint; | ||
ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint; | ||
ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
@@ -131,0 +159,0 @@ |
@@ -10,18 +10,19 @@ "use strict"; | ||
const scratchMatrix = new _core.Matrix3(); | ||
const scratchUnitary = new _core.Matrix3(); | ||
const scratchDiagonal = new _core.Matrix3(); | ||
const jMatrix = new _core.Matrix3(); | ||
const jMatrixTranspose = new _core.Matrix3(); | ||
var scratchMatrix = new _core.Matrix3(); | ||
var scratchUnitary = new _core.Matrix3(); | ||
var scratchDiagonal = new _core.Matrix3(); | ||
var jMatrix = new _core.Matrix3(); | ||
var jMatrixTranspose = new _core.Matrix3(); | ||
function computeEigenDecomposition(matrix, result = {}) { | ||
const EIGEN_TOLERANCE = _core._MathUtils.EPSILON20; | ||
const EIGEN_MAX_SWEEPS = 10; | ||
let count = 0; | ||
let sweep = 0; | ||
const unitaryMatrix = scratchUnitary; | ||
const diagonalMatrix = scratchDiagonal; | ||
function computeEigenDecomposition(matrix) { | ||
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var EIGEN_TOLERANCE = _core._MathUtils.EPSILON20; | ||
var EIGEN_MAX_SWEEPS = 10; | ||
var count = 0; | ||
var sweep = 0; | ||
var unitaryMatrix = scratchUnitary; | ||
var diagonalMatrix = scratchDiagonal; | ||
unitaryMatrix.identity(); | ||
diagonalMatrix.copy(matrix); | ||
const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix); | ||
var epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix); | ||
@@ -47,6 +48,6 @@ while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) { | ||
function computeFrobeniusNorm(matrix) { | ||
let norm = 0.0; | ||
var norm = 0.0; | ||
for (let i = 0; i < 9; ++i) { | ||
const temp = matrix[i]; | ||
for (var i = 0; i < 9; ++i) { | ||
var temp = matrix[i]; | ||
norm += temp * temp; | ||
@@ -58,10 +59,10 @@ } | ||
const rowVal = [1, 0, 0]; | ||
const colVal = [2, 2, 1]; | ||
var rowVal = [1, 0, 0]; | ||
var colVal = [2, 2, 1]; | ||
function offDiagonalFrobeniusNorm(matrix) { | ||
let norm = 0.0; | ||
var norm = 0.0; | ||
for (let i = 0; i < 3; ++i) { | ||
const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]; | ||
for (var i = 0; i < 3; ++i) { | ||
var temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]; | ||
norm += 2.0 * temp * temp; | ||
@@ -74,8 +75,8 @@ } | ||
function shurDecomposition(matrix, result) { | ||
const tolerance = _core._MathUtils.EPSILON15; | ||
let maxDiagonal = 0.0; | ||
let rotAxis = 1; | ||
var tolerance = _core._MathUtils.EPSILON15; | ||
var maxDiagonal = 0.0; | ||
var rotAxis = 1; | ||
for (let i = 0; i < 3; ++i) { | ||
const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]); | ||
for (var i = 0; i < 3; ++i) { | ||
var temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]); | ||
@@ -88,13 +89,13 @@ if (temp > maxDiagonal) { | ||
const p = rowVal[rotAxis]; | ||
const q = colVal[rotAxis]; | ||
let c = 1.0; | ||
let s = 0.0; | ||
var p = rowVal[rotAxis]; | ||
var q = colVal[rotAxis]; | ||
var c = 1.0; | ||
var s = 0.0; | ||
if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) { | ||
const qq = matrix[scratchMatrix.getElementIndex(q, q)]; | ||
const pp = matrix[scratchMatrix.getElementIndex(p, p)]; | ||
const qp = matrix[scratchMatrix.getElementIndex(q, p)]; | ||
const tau = (qq - pp) / 2.0 / qp; | ||
let t; | ||
var qq = matrix[scratchMatrix.getElementIndex(q, q)]; | ||
var pp = matrix[scratchMatrix.getElementIndex(p, p)]; | ||
var qp = matrix[scratchMatrix.getElementIndex(q, p)]; | ||
var tau = (qq - pp) / 2.0 / qp; | ||
var t; | ||
@@ -101,0 +102,0 @@ if (tau < 0.0) { |
@@ -10,2 +10,6 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -17,7 +21,11 @@ | ||
const scratchVector = new _core.Vector3(); | ||
const scratchNormal = new _core.Vector3(); | ||
var scratchVector = new _core.Vector3(); | ||
var scratchNormal = new _core.Vector3(); | ||
class AxisAlignedBoundingBox { | ||
constructor(minimum = [0, 0, 0], maximum = [0, 0, 0], center) { | ||
var AxisAlignedBoundingBox = function () { | ||
function AxisAlignedBoundingBox() { | ||
var minimum = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0]; | ||
var maximum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0]; | ||
var center = arguments.length > 2 ? arguments[2] : undefined; | ||
(0, _classCallCheck2.default)(this, AxisAlignedBoundingBox); | ||
(0, _defineProperty2.default)(this, "center", void 0); | ||
@@ -34,72 +42,76 @@ (0, _defineProperty2.default)(this, "halfDiagonal", void 0); | ||
clone() { | ||
return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center); | ||
} | ||
(0, _createClass2.default)(AxisAlignedBoundingBox, [{ | ||
key: "clone", | ||
value: function clone() { | ||
return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center); | ||
} | ||
}, { | ||
key: "equals", | ||
value: function equals(right) { | ||
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum); | ||
} | ||
}, { | ||
key: "transform", | ||
value: function transform(_transform) { | ||
this.center.transformAsPoint(_transform); | ||
this.halfDiagonal.transform(_transform); | ||
this.minimum.transform(_transform); | ||
this.maximum.transform(_transform); | ||
return this; | ||
} | ||
}, { | ||
key: "intersectPlane", | ||
value: function intersectPlane(plane) { | ||
var halfDiagonal = this.halfDiagonal; | ||
var normal = scratchNormal.from(plane.normal); | ||
var e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z); | ||
var s = this.center.dot(normal) + plane.distance; | ||
equals(right) { | ||
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum); | ||
} | ||
if (s - e > 0) { | ||
return _constants.INTERSECTION.INSIDE; | ||
} | ||
transform(transform) { | ||
this.center.transformAsPoint(transform); | ||
this.halfDiagonal.transform(transform); | ||
this.minimum.transform(transform); | ||
this.maximum.transform(transform); | ||
return this; | ||
} | ||
if (s + e < 0) { | ||
return _constants.INTERSECTION.OUTSIDE; | ||
} | ||
intersectPlane(plane) { | ||
const { | ||
halfDiagonal | ||
} = this; | ||
const normal = scratchNormal.from(plane.normal); | ||
const e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z); | ||
const s = this.center.dot(normal) + plane.distance; | ||
if (s - e > 0) { | ||
return _constants.INTERSECTION.INSIDE; | ||
return _constants.INTERSECTION.INTERSECTING; | ||
} | ||
if (s + e < 0) { | ||
return _constants.INTERSECTION.OUTSIDE; | ||
}, { | ||
key: "distanceTo", | ||
value: function distanceTo(point) { | ||
return Math.sqrt(this.distanceSquaredTo(point)); | ||
} | ||
}, { | ||
key: "distanceSquaredTo", | ||
value: function distanceSquaredTo(point) { | ||
var offset = scratchVector.from(point).subtract(this.center); | ||
var halfDiagonal = this.halfDiagonal; | ||
var distanceSquared = 0.0; | ||
var d; | ||
d = Math.abs(offset.x) - halfDiagonal.x; | ||
return _constants.INTERSECTION.INTERSECTING; | ||
} | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
distanceTo(point) { | ||
return Math.sqrt(this.distanceSquaredTo(point)); | ||
} | ||
d = Math.abs(offset.y) - halfDiagonal.y; | ||
distanceSquaredTo(point) { | ||
const offset = scratchVector.from(point).subtract(this.center); | ||
const { | ||
halfDiagonal | ||
} = this; | ||
let distanceSquared = 0.0; | ||
let d; | ||
d = Math.abs(offset.x) - halfDiagonal.x; | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
d = Math.abs(offset.z) - halfDiagonal.z; | ||
d = Math.abs(offset.y) - halfDiagonal.y; | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
return distanceSquared; | ||
} | ||
}]); | ||
return AxisAlignedBoundingBox; | ||
}(); | ||
d = Math.abs(offset.z) - halfDiagonal.z; | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
return distanceSquared; | ||
} | ||
} | ||
exports.default = AxisAlignedBoundingBox; | ||
//# sourceMappingURL=axis-aligned-bounding-box.js.map |
@@ -5,2 +5,4 @@ "use strict"; | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,2 +13,6 @@ value: true | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -20,11 +26,14 @@ | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const scratchVector = new _core.Vector3(); | ||
const scratchVector2 = new _core.Vector3(); | ||
var scratchVector = new _core.Vector3(); | ||
var scratchVector2 = new _core.Vector3(); | ||
class BoundingSphere { | ||
constructor(center = [0, 0, 0], radius = 0.0) { | ||
var BoundingSphere = function () { | ||
function BoundingSphere() { | ||
var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0]; | ||
var radius = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0; | ||
(0, _classCallCheck2.default)(this, BoundingSphere); | ||
(0, _defineProperty2.default)(this, "center", void 0); | ||
@@ -37,95 +46,107 @@ (0, _defineProperty2.default)(this, "radius", void 0); | ||
fromCenterRadius(center, radius) { | ||
this.center.from(center); | ||
this.radius = radius; | ||
return this; | ||
} | ||
(0, _createClass2.default)(BoundingSphere, [{ | ||
key: "fromCenterRadius", | ||
value: function fromCenterRadius(center, radius) { | ||
this.center.from(center); | ||
this.radius = radius; | ||
return this; | ||
} | ||
}, { | ||
key: "fromCornerPoints", | ||
value: function fromCornerPoints(corner, oppositeCorner) { | ||
oppositeCorner = scratchVector.from(oppositeCorner); | ||
this.center = new _core.Vector3().from(corner).add(oppositeCorner).scale(0.5); | ||
this.radius = this.center.distance(oppositeCorner); | ||
return this; | ||
} | ||
}, { | ||
key: "equals", | ||
value: function equals(right) { | ||
return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius; | ||
} | ||
}, { | ||
key: "clone", | ||
value: function clone() { | ||
return new BoundingSphere(this.center, this.radius); | ||
} | ||
}, { | ||
key: "union", | ||
value: function union(boundingSphere) { | ||
var leftCenter = this.center; | ||
var leftRadius = this.radius; | ||
var rightCenter = boundingSphere.center; | ||
var rightRadius = boundingSphere.radius; | ||
var toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter); | ||
var centerSeparation = toRightCenter.magnitude(); | ||
fromCornerPoints(corner, oppositeCorner) { | ||
oppositeCorner = scratchVector.from(oppositeCorner); | ||
this.center = new _core.Vector3().from(corner).add(oppositeCorner).scale(0.5); | ||
this.radius = this.center.distance(oppositeCorner); | ||
return this; | ||
} | ||
if (leftRadius >= centerSeparation + rightRadius) { | ||
return this.clone(); | ||
} | ||
equals(right) { | ||
return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius; | ||
} | ||
if (rightRadius >= centerSeparation + leftRadius) { | ||
return boundingSphere.clone(); | ||
} | ||
clone() { | ||
return new BoundingSphere(this.center, this.radius); | ||
} | ||
var halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5; | ||
scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter); | ||
this.center.copy(scratchVector2); | ||
this.radius = halfDistanceBetweenTangentPoints; | ||
return this; | ||
} | ||
}, { | ||
key: "expand", | ||
value: function expand(point) { | ||
var scratchPoint = scratchVector.from(point); | ||
var radius = scratchPoint.subtract(this.center).magnitude(); | ||
union(boundingSphere) { | ||
const leftCenter = this.center; | ||
const leftRadius = this.radius; | ||
const rightCenter = boundingSphere.center; | ||
const rightRadius = boundingSphere.radius; | ||
const toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter); | ||
const centerSeparation = toRightCenter.magnitude(); | ||
if (radius > this.radius) { | ||
this.radius = radius; | ||
} | ||
if (leftRadius >= centerSeparation + rightRadius) { | ||
return this.clone(); | ||
return this; | ||
} | ||
if (rightRadius >= centerSeparation + leftRadius) { | ||
return boundingSphere.clone(); | ||
}, { | ||
key: "transform", | ||
value: function transform(_transform) { | ||
this.center.transform(_transform); | ||
var scale = mat4.getScaling(scratchVector, _transform); | ||
this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius; | ||
return this; | ||
} | ||
const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5; | ||
scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter); | ||
this.center.copy(scratchVector2); | ||
this.radius = halfDistanceBetweenTangentPoints; | ||
return this; | ||
} | ||
expand(point) { | ||
const scratchPoint = scratchVector.from(point); | ||
const radius = scratchPoint.subtract(this.center).magnitude(); | ||
if (radius > this.radius) { | ||
this.radius = radius; | ||
}, { | ||
key: "distanceSquaredTo", | ||
value: function distanceSquaredTo(point) { | ||
var d = this.distanceTo(point); | ||
return d * d; | ||
} | ||
}, { | ||
key: "distanceTo", | ||
value: function distanceTo(point) { | ||
var scratchPoint = scratchVector.from(point); | ||
var delta = scratchPoint.subtract(this.center); | ||
return Math.max(0, delta.len() - this.radius); | ||
} | ||
}, { | ||
key: "intersectPlane", | ||
value: function intersectPlane(plane) { | ||
var center = this.center; | ||
var radius = this.radius; | ||
var normal = plane.normal; | ||
var distanceToPlane = normal.dot(center) + plane.distance; | ||
return this; | ||
} | ||
if (distanceToPlane < -radius) { | ||
return _constants.INTERSECTION.OUTSIDE; | ||
} | ||
transform(transform) { | ||
this.center.transform(transform); | ||
const scale = mat4.getScaling(scratchVector, transform); | ||
this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius; | ||
return this; | ||
} | ||
if (distanceToPlane < radius) { | ||
return _constants.INTERSECTION.INTERSECTING; | ||
} | ||
distanceSquaredTo(point) { | ||
const d = this.distanceTo(point); | ||
return d * d; | ||
} | ||
distanceTo(point) { | ||
const scratchPoint = scratchVector.from(point); | ||
const delta = scratchPoint.subtract(this.center); | ||
return Math.max(0, delta.len() - this.radius); | ||
} | ||
intersectPlane(plane) { | ||
const center = this.center; | ||
const radius = this.radius; | ||
const normal = plane.normal; | ||
const distanceToPlane = normal.dot(center) + plane.distance; | ||
if (distanceToPlane < -radius) { | ||
return _constants.INTERSECTION.OUTSIDE; | ||
return _constants.INTERSECTION.INSIDE; | ||
} | ||
}]); | ||
return BoundingSphere; | ||
}(); | ||
if (distanceToPlane < radius) { | ||
return _constants.INTERSECTION.INTERSECTING; | ||
} | ||
return _constants.INTERSECTION.INSIDE; | ||
} | ||
} | ||
exports.default = BoundingSphere; | ||
//# sourceMappingURL=bounding-sphere.js.map |
@@ -10,2 +10,8 @@ "use strict"; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -19,10 +25,10 @@ | ||
const scratchVector3 = new _core.Vector3(); | ||
const scratchOffset = new _core.Vector3(); | ||
const scratchVectorU = new _core.Vector3(); | ||
const scratchVectorV = new _core.Vector3(); | ||
const scratchVectorW = new _core.Vector3(); | ||
const scratchCorner = new _core.Vector3(); | ||
const scratchToCenter = new _core.Vector3(); | ||
const MATRIX3 = { | ||
var scratchVector3 = new _core.Vector3(); | ||
var scratchOffset = new _core.Vector3(); | ||
var scratchVectorU = new _core.Vector3(); | ||
var scratchVectorV = new _core.Vector3(); | ||
var scratchVectorW = new _core.Vector3(); | ||
var scratchCorner = new _core.Vector3(); | ||
var scratchToCenter = new _core.Vector3(); | ||
var MATRIX3 = { | ||
COLUMN0ROW0: 0, | ||
@@ -39,4 +45,7 @@ COLUMN0ROW1: 1, | ||
class OrientedBoundingBox { | ||
constructor(center = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) { | ||
var OrientedBoundingBox = function () { | ||
function OrientedBoundingBox() { | ||
var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0]; | ||
var halfAxes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
(0, _classCallCheck2.default)(this, OrientedBoundingBox); | ||
(0, _defineProperty2.default)(this, "center", void 0); | ||
@@ -48,185 +57,201 @@ (0, _defineProperty2.default)(this, "halfAxes", void 0); | ||
get halfSize() { | ||
const xAxis = this.halfAxes.getColumn(0); | ||
const yAxis = this.halfAxes.getColumn(1); | ||
const zAxis = this.halfAxes.getColumn(2); | ||
return [new _core.Vector3(xAxis).len(), new _core.Vector3(yAxis).len(), new _core.Vector3(zAxis).len()]; | ||
} | ||
(0, _createClass2.default)(OrientedBoundingBox, [{ | ||
key: "halfSize", | ||
get: function get() { | ||
var xAxis = this.halfAxes.getColumn(0); | ||
var yAxis = this.halfAxes.getColumn(1); | ||
var zAxis = this.halfAxes.getColumn(2); | ||
return [new _core.Vector3(xAxis).len(), new _core.Vector3(yAxis).len(), new _core.Vector3(zAxis).len()]; | ||
} | ||
}, { | ||
key: "quaternion", | ||
get: function get() { | ||
var xAxis = this.halfAxes.getColumn(0); | ||
var yAxis = this.halfAxes.getColumn(1); | ||
var zAxis = this.halfAxes.getColumn(2); | ||
var normXAxis = new _core.Vector3(xAxis).normalize(); | ||
var normYAxis = new _core.Vector3(yAxis).normalize(); | ||
var normZAxis = new _core.Vector3(zAxis).normalize(); | ||
return new _core.Quaternion().fromMatrix3(new _core.Matrix3([].concat((0, _toConsumableArray2.default)(normXAxis), (0, _toConsumableArray2.default)(normYAxis), (0, _toConsumableArray2.default)(normZAxis)))); | ||
} | ||
}, { | ||
key: "fromCenterHalfSizeQuaternion", | ||
value: function fromCenterHalfSizeQuaternion(center, halfSize, quaternion) { | ||
var quaternionObject = new _core.Quaternion(quaternion); | ||
var directionsMatrix = new _core.Matrix3().fromQuaternion(quaternionObject); | ||
directionsMatrix[0] = directionsMatrix[0] * halfSize[0]; | ||
directionsMatrix[1] = directionsMatrix[1] * halfSize[0]; | ||
directionsMatrix[2] = directionsMatrix[2] * halfSize[0]; | ||
directionsMatrix[3] = directionsMatrix[3] * halfSize[1]; | ||
directionsMatrix[4] = directionsMatrix[4] * halfSize[1]; | ||
directionsMatrix[5] = directionsMatrix[5] * halfSize[1]; | ||
directionsMatrix[6] = directionsMatrix[6] * halfSize[2]; | ||
directionsMatrix[7] = directionsMatrix[7] * halfSize[2]; | ||
directionsMatrix[8] = directionsMatrix[8] * halfSize[2]; | ||
this.center = new _core.Vector3().from(center); | ||
this.halfAxes = directionsMatrix; | ||
return this; | ||
} | ||
}, { | ||
key: "clone", | ||
value: function clone() { | ||
return new OrientedBoundingBox(this.center, this.halfAxes); | ||
} | ||
}, { | ||
key: "equals", | ||
value: function equals(right) { | ||
return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes); | ||
} | ||
}, { | ||
key: "getBoundingSphere", | ||
value: function getBoundingSphere() { | ||
var result = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new _boundingSphere.default(); | ||
var halfAxes = this.halfAxes; | ||
var u = halfAxes.getColumn(0, scratchVectorU); | ||
var v = halfAxes.getColumn(1, scratchVectorV); | ||
var w = halfAxes.getColumn(2, scratchVectorW); | ||
var cornerVector = scratchVector3.copy(u).add(v).add(w); | ||
result.center.copy(this.center); | ||
result.radius = cornerVector.magnitude(); | ||
return result; | ||
} | ||
}, { | ||
key: "intersectPlane", | ||
value: function intersectPlane(plane) { | ||
var center = this.center; | ||
var normal = plane.normal; | ||
var halfAxes = this.halfAxes; | ||
var normalX = normal.x; | ||
var normalY = normal.y; | ||
var normalZ = normal.z; | ||
var 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]); | ||
var distanceToPlane = normal.dot(center) + plane.distance; | ||
get quaternion() { | ||
const xAxis = this.halfAxes.getColumn(0); | ||
const yAxis = this.halfAxes.getColumn(1); | ||
const zAxis = this.halfAxes.getColumn(2); | ||
const normXAxis = new _core.Vector3(xAxis).normalize(); | ||
const normYAxis = new _core.Vector3(yAxis).normalize(); | ||
const normZAxis = new _core.Vector3(zAxis).normalize(); | ||
return new _core.Quaternion().fromMatrix3(new _core.Matrix3([...normXAxis, ...normYAxis, ...normZAxis])); | ||
} | ||
if (distanceToPlane <= -radEffective) { | ||
return _constants.INTERSECTION.OUTSIDE; | ||
} else if (distanceToPlane >= radEffective) { | ||
return _constants.INTERSECTION.INSIDE; | ||
} | ||
fromCenterHalfSizeQuaternion(center, halfSize, quaternion) { | ||
const quaternionObject = new _core.Quaternion(quaternion); | ||
const directionsMatrix = new _core.Matrix3().fromQuaternion(quaternionObject); | ||
directionsMatrix[0] = directionsMatrix[0] * halfSize[0]; | ||
directionsMatrix[1] = directionsMatrix[1] * halfSize[0]; | ||
directionsMatrix[2] = directionsMatrix[2] * halfSize[0]; | ||
directionsMatrix[3] = directionsMatrix[3] * halfSize[1]; | ||
directionsMatrix[4] = directionsMatrix[4] * halfSize[1]; | ||
directionsMatrix[5] = directionsMatrix[5] * halfSize[1]; | ||
directionsMatrix[6] = directionsMatrix[6] * halfSize[2]; | ||
directionsMatrix[7] = directionsMatrix[7] * halfSize[2]; | ||
directionsMatrix[8] = directionsMatrix[8] * halfSize[2]; | ||
this.center = new _core.Vector3().from(center); | ||
this.halfAxes = directionsMatrix; | ||
return this; | ||
} | ||
clone() { | ||
return new OrientedBoundingBox(this.center, this.halfAxes); | ||
} | ||
equals(right) { | ||
return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes); | ||
} | ||
getBoundingSphere(result = new _boundingSphere.default()) { | ||
const halfAxes = this.halfAxes; | ||
const u = halfAxes.getColumn(0, scratchVectorU); | ||
const v = halfAxes.getColumn(1, scratchVectorV); | ||
const w = halfAxes.getColumn(2, scratchVectorW); | ||
const cornerVector = scratchVector3.copy(u).add(v).add(w); | ||
result.center.copy(this.center); | ||
result.radius = cornerVector.magnitude(); | ||
return result; | ||
} | ||
intersectPlane(plane) { | ||
const center = this.center; | ||
const normal = plane.normal; | ||
const halfAxes = this.halfAxes; | ||
const normalX = normal.x; | ||
const normalY = normal.y; | ||
const normalZ = normal.z; | ||
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]); | ||
const distanceToPlane = normal.dot(center) + plane.distance; | ||
if (distanceToPlane <= -radEffective) { | ||
return _constants.INTERSECTION.OUTSIDE; | ||
} else if (distanceToPlane >= radEffective) { | ||
return _constants.INTERSECTION.INSIDE; | ||
return _constants.INTERSECTION.INTERSECTING; | ||
} | ||
}, { | ||
key: "distanceTo", | ||
value: function distanceTo(point) { | ||
return Math.sqrt(this.distanceSquaredTo(point)); | ||
} | ||
}, { | ||
key: "distanceSquaredTo", | ||
value: function distanceSquaredTo(point) { | ||
var offset = scratchOffset.from(point).subtract(this.center); | ||
var halfAxes = this.halfAxes; | ||
var u = halfAxes.getColumn(0, scratchVectorU); | ||
var v = halfAxes.getColumn(1, scratchVectorV); | ||
var w = halfAxes.getColumn(2, scratchVectorW); | ||
var uHalf = u.magnitude(); | ||
var vHalf = v.magnitude(); | ||
var wHalf = w.magnitude(); | ||
u.normalize(); | ||
v.normalize(); | ||
w.normalize(); | ||
var distanceSquared = 0.0; | ||
var d; | ||
d = Math.abs(offset.dot(u)) - uHalf; | ||
return _constants.INTERSECTION.INTERSECTING; | ||
} | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
distanceTo(point) { | ||
return Math.sqrt(this.distanceSquaredTo(point)); | ||
} | ||
d = Math.abs(offset.dot(v)) - vHalf; | ||
distanceSquaredTo(point) { | ||
const offset = scratchOffset.from(point).subtract(this.center); | ||
const halfAxes = this.halfAxes; | ||
const u = halfAxes.getColumn(0, scratchVectorU); | ||
const v = halfAxes.getColumn(1, scratchVectorV); | ||
const w = halfAxes.getColumn(2, scratchVectorW); | ||
const uHalf = u.magnitude(); | ||
const vHalf = v.magnitude(); | ||
const wHalf = w.magnitude(); | ||
u.normalize(); | ||
v.normalize(); | ||
w.normalize(); | ||
let distanceSquared = 0.0; | ||
let d; | ||
d = Math.abs(offset.dot(u)) - uHalf; | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
d = Math.abs(offset.dot(w)) - wHalf; | ||
d = Math.abs(offset.dot(v)) - vHalf; | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
} | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
return distanceSquared; | ||
} | ||
d = Math.abs(offset.dot(w)) - wHalf; | ||
if (d > 0) { | ||
distanceSquared += d * d; | ||
}, { | ||
key: "computePlaneDistances", | ||
value: function computePlaneDistances(position, direction) { | ||
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [-0, -0]; | ||
var minDist = Number.POSITIVE_INFINITY; | ||
var maxDist = Number.NEGATIVE_INFINITY; | ||
var center = this.center; | ||
var halfAxes = this.halfAxes; | ||
var u = halfAxes.getColumn(0, scratchVectorU); | ||
var v = halfAxes.getColumn(1, scratchVectorV); | ||
var w = halfAxes.getColumn(2, scratchVectorW); | ||
var corner = scratchCorner.copy(u).add(v).add(w).add(center); | ||
var toCenter = scratchToCenter.copy(corner).subtract(position); | ||
var mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
corner.copy(center).add(u).add(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
corner.copy(center).add(u).subtract(v).add(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
corner.copy(center).add(u).subtract(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).add(v).add(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).add(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).subtract(v).add(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).subtract(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
result[0] = minDist; | ||
result[1] = maxDist; | ||
return result; | ||
} | ||
}, { | ||
key: "transform", | ||
value: function transform(transformation) { | ||
this.center.transformAsPoint(transformation); | ||
var xAxis = this.halfAxes.getColumn(0, scratchVectorU); | ||
xAxis.transformAsPoint(transformation); | ||
var yAxis = this.halfAxes.getColumn(1, scratchVectorV); | ||
yAxis.transformAsPoint(transformation); | ||
var zAxis = this.halfAxes.getColumn(2, scratchVectorW); | ||
zAxis.transformAsPoint(transformation); | ||
this.halfAxes = new _core.Matrix3([].concat((0, _toConsumableArray2.default)(xAxis), (0, _toConsumableArray2.default)(yAxis), (0, _toConsumableArray2.default)(zAxis))); | ||
return this; | ||
} | ||
}, { | ||
key: "getTransform", | ||
value: function getTransform() { | ||
throw new Error('not implemented'); | ||
} | ||
}]); | ||
return OrientedBoundingBox; | ||
}(); | ||
return distanceSquared; | ||
} | ||
computePlaneDistances(position, direction, result = [-0, -0]) { | ||
let minDist = Number.POSITIVE_INFINITY; | ||
let maxDist = Number.NEGATIVE_INFINITY; | ||
const center = this.center; | ||
const halfAxes = this.halfAxes; | ||
const u = halfAxes.getColumn(0, scratchVectorU); | ||
const v = halfAxes.getColumn(1, scratchVectorV); | ||
const w = halfAxes.getColumn(2, scratchVectorW); | ||
const corner = scratchCorner.copy(u).add(v).add(w).add(center); | ||
const toCenter = scratchToCenter.copy(corner).subtract(position); | ||
let mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
corner.copy(center).add(u).add(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
corner.copy(center).add(u).subtract(v).add(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
corner.copy(center).add(u).subtract(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).add(v).add(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).add(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).subtract(v).add(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
center.copy(corner).subtract(u).subtract(v).subtract(w); | ||
toCenter.copy(corner).subtract(position); | ||
mag = direction.dot(toCenter); | ||
minDist = Math.min(mag, minDist); | ||
maxDist = Math.max(mag, maxDist); | ||
result[0] = minDist; | ||
result[1] = maxDist; | ||
return result; | ||
} | ||
transform(transformation) { | ||
this.center.transformAsPoint(transformation); | ||
const xAxis = this.halfAxes.getColumn(0, scratchVectorU); | ||
xAxis.transformAsPoint(transformation); | ||
const yAxis = this.halfAxes.getColumn(1, scratchVectorV); | ||
yAxis.transformAsPoint(transformation); | ||
const zAxis = this.halfAxes.getColumn(2, scratchVectorW); | ||
zAxis.transformAsPoint(transformation); | ||
this.halfAxes = new _core.Matrix3([...xAxis, ...yAxis, ...zAxis]); | ||
return this; | ||
} | ||
getTransform() { | ||
throw new Error('not implemented'); | ||
} | ||
} | ||
exports.default = OrientedBoundingBox; | ||
//# sourceMappingURL=oriented-bounding-box.js.map |
@@ -10,2 +10,6 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -19,9 +23,17 @@ | ||
const faces = [new _core.Vector3([1, 0, 0]), new _core.Vector3([0, 1, 0]), new _core.Vector3([0, 0, 1])]; | ||
const scratchPlaneCenter = new _core.Vector3(); | ||
const scratchPlaneNormal = new _core.Vector3(); | ||
const scratchPlane = new _plane.default(new _core.Vector3(1.0, 0.0, 0.0), 0.0); | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
class CullingVolume { | ||
constructor(planes = []) { | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var faces = [new _core.Vector3([1, 0, 0]), new _core.Vector3([0, 1, 0]), new _core.Vector3([0, 0, 1])]; | ||
var scratchPlaneCenter = new _core.Vector3(); | ||
var scratchPlaneNormal = new _core.Vector3(); | ||
var scratchPlane = new _plane.default(new _core.Vector3(1.0, 0.0, 0.0), 0.0); | ||
var CullingVolume = function () { | ||
function CullingVolume() { | ||
var planes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
(0, _classCallCheck2.default)(this, CullingVolume); | ||
(0, _defineProperty2.default)(this, "planes", void 0); | ||
@@ -31,86 +43,111 @@ this.planes = planes; | ||
fromBoundingSphere(boundingSphere) { | ||
this.planes.length = 2 * faces.length; | ||
const center = boundingSphere.center; | ||
const radius = boundingSphere.radius; | ||
let planeIndex = 0; | ||
(0, _createClass2.default)(CullingVolume, [{ | ||
key: "fromBoundingSphere", | ||
value: function fromBoundingSphere(boundingSphere) { | ||
this.planes.length = 2 * faces.length; | ||
var center = boundingSphere.center; | ||
var radius = boundingSphere.radius; | ||
var planeIndex = 0; | ||
for (const faceNormal of faces) { | ||
let plane0 = this.planes[planeIndex]; | ||
let plane1 = this.planes[planeIndex + 1]; | ||
var _iterator = _createForOfIteratorHelper(faces), | ||
_step; | ||
if (!plane0) { | ||
plane0 = this.planes[planeIndex] = new _plane.default(); | ||
} | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var faceNormal = _step.value; | ||
var plane0 = this.planes[planeIndex]; | ||
var plane1 = this.planes[planeIndex + 1]; | ||
if (!plane1) { | ||
plane1 = this.planes[planeIndex + 1] = new _plane.default(); | ||
if (!plane0) { | ||
plane0 = this.planes[planeIndex] = new _plane.default(); | ||
} | ||
if (!plane1) { | ||
plane1 = this.planes[planeIndex + 1] = new _plane.default(); | ||
} | ||
var plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center); | ||
var plane0Distance = -faceNormal.dot(plane0Center); | ||
plane0.fromPointNormal(plane0Center, faceNormal); | ||
var plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center); | ||
var negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate(); | ||
var plane1Distance = -negatedFaceNormal.dot(plane1Center); | ||
plane1.fromPointNormal(plane1Center, negatedFaceNormal); | ||
planeIndex += 2; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center); | ||
const plane0Distance = -faceNormal.dot(plane0Center); | ||
plane0.fromPointNormal(plane0Center, faceNormal); | ||
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center); | ||
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate(); | ||
const plane1Distance = -negatedFaceNormal.dot(plane1Center); | ||
plane1.fromPointNormal(plane1Center, negatedFaceNormal); | ||
planeIndex += 2; | ||
return this; | ||
} | ||
}, { | ||
key: "computeVisibility", | ||
value: function computeVisibility(boundingVolume) { | ||
var intersect = _constants.INTERSECTION.INSIDE; | ||
return this; | ||
} | ||
var _iterator2 = _createForOfIteratorHelper(this.planes), | ||
_step2; | ||
computeVisibility(boundingVolume) { | ||
let intersect = _constants.INTERSECTION.INSIDE; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var plane = _step2.value; | ||
var result = boundingVolume.intersectPlane(plane); | ||
for (const plane of this.planes) { | ||
const result = boundingVolume.intersectPlane(plane); | ||
switch (result) { | ||
case _constants.INTERSECTION.OUTSIDE: | ||
return _constants.INTERSECTION.OUTSIDE; | ||
switch (result) { | ||
case _constants.INTERSECTION.OUTSIDE: | ||
return _constants.INTERSECTION.OUTSIDE; | ||
case _constants.INTERSECTION.INTERSECTING: | ||
intersect = _constants.INTERSECTION.INTERSECTING; | ||
break; | ||
case _constants.INTERSECTION.INTERSECTING: | ||
intersect = _constants.INTERSECTION.INTERSECTING; | ||
break; | ||
default: | ||
} | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
default: | ||
} | ||
return intersect; | ||
} | ||
}, { | ||
key: "computeVisibilityWithPlaneMask", | ||
value: function computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) { | ||
(0, _core.assert)(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.'); | ||
return intersect; | ||
} | ||
if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) { | ||
return parentPlaneMask; | ||
} | ||
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) { | ||
(0, _core.assert)(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.'); | ||
var mask = CullingVolume.MASK_INSIDE; | ||
var planes = this.planes; | ||
if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) { | ||
return parentPlaneMask; | ||
} | ||
for (var k = 0; k < this.planes.length; ++k) { | ||
var flag = k < 31 ? 1 << k : 0; | ||
let mask = CullingVolume.MASK_INSIDE; | ||
const planes = this.planes; | ||
if (k < 31 && (parentPlaneMask & flag) === 0) { | ||
continue; | ||
} | ||
for (let k = 0; k < this.planes.length; ++k) { | ||
const flag = k < 31 ? 1 << k : 0; | ||
var plane = planes[k]; | ||
var result = boundingVolume.intersectPlane(plane); | ||
if (k < 31 && (parentPlaneMask & flag) === 0) { | ||
continue; | ||
if (result === _constants.INTERSECTION.OUTSIDE) { | ||
return CullingVolume.MASK_OUTSIDE; | ||
} else if (result === _constants.INTERSECTION.INTERSECTING) { | ||
mask |= flag; | ||
} | ||
} | ||
const plane = planes[k]; | ||
const result = boundingVolume.intersectPlane(plane); | ||
if (result === _constants.INTERSECTION.OUTSIDE) { | ||
return CullingVolume.MASK_OUTSIDE; | ||
} else if (result === _constants.INTERSECTION.INTERSECTING) { | ||
mask |= flag; | ||
} | ||
return mask; | ||
} | ||
}]); | ||
return CullingVolume; | ||
}(); | ||
return mask; | ||
} | ||
} | ||
exports.default = CullingVolume; | ||
@@ -117,0 +154,0 @@ (0, _defineProperty2.default)(CullingVolume, "MASK_OUTSIDE", 0xffffffff); |
@@ -10,2 +10,6 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -17,6 +21,14 @@ | ||
const defined = val => val !== null && typeof val !== 'undefined'; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
class PerspectiveFrustum { | ||
constructor(options = {}) { | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var defined = function defined(val) { | ||
return val !== null && typeof val !== 'undefined'; | ||
}; | ||
var PerspectiveFrustum = function () { | ||
function PerspectiveFrustum() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
(0, _classCallCheck2.default)(this, PerspectiveFrustum); | ||
(0, _defineProperty2.default)(this, "_offCenterFrustum", new _perspectiveOffCenterFrustum.default()); | ||
@@ -37,9 +49,8 @@ (0, _defineProperty2.default)(this, "fov", void 0); | ||
(0, _defineProperty2.default)(this, "_yOffset", void 0); | ||
options = { | ||
options = _objectSpread({ | ||
near: 1.0, | ||
far: 500000000.0, | ||
xOffset: 0.0, | ||
yOffset: 0.0, | ||
...options | ||
}; | ||
yOffset: 0.0 | ||
}, options); | ||
this.fov = options.fov; | ||
@@ -57,53 +68,63 @@ this.aspectRatio = options.aspectRatio; | ||
clone() { | ||
return new PerspectiveFrustum({ | ||
aspectRatio: this.aspectRatio, | ||
fov: this.fov, | ||
near: this.near, | ||
far: this.far | ||
}); | ||
} | ||
(0, _createClass2.default)(PerspectiveFrustum, [{ | ||
key: "clone", | ||
value: function clone() { | ||
return new PerspectiveFrustum({ | ||
aspectRatio: this.aspectRatio, | ||
fov: this.fov, | ||
near: this.near, | ||
far: this.far | ||
}); | ||
} | ||
}, { | ||
key: "equals", | ||
value: function equals(other) { | ||
if (!defined(other) || !(other instanceof PerspectiveFrustum)) { | ||
return false; | ||
} | ||
equals(other) { | ||
if (!defined(other) || !(other instanceof PerspectiveFrustum)) { | ||
return false; | ||
update(this); | ||
update(other); | ||
return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum); | ||
} | ||
}, { | ||
key: "projectionMatrix", | ||
get: function get() { | ||
update(this); | ||
return this._offCenterFrustum.projectionMatrix; | ||
} | ||
}, { | ||
key: "infiniteProjectionMatrix", | ||
get: function get() { | ||
update(this); | ||
return this._offCenterFrustum.infiniteProjectionMatrix; | ||
} | ||
}, { | ||
key: "fovy", | ||
get: function get() { | ||
update(this); | ||
return this._fovy; | ||
} | ||
}, { | ||
key: "sseDenominator", | ||
get: function get() { | ||
update(this); | ||
return this._sseDenominator; | ||
} | ||
}, { | ||
key: "computeCullingVolume", | ||
value: function computeCullingVolume(position, direction, up) { | ||
update(this); | ||
return this._offCenterFrustum.computeCullingVolume(position, direction, up); | ||
} | ||
}, { | ||
key: "getPixelDimensions", | ||
value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) { | ||
update(this); | ||
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result); | ||
} | ||
}]); | ||
return PerspectiveFrustum; | ||
}(); | ||
update(this); | ||
update(other); | ||
return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum); | ||
} | ||
get projectionMatrix() { | ||
update(this); | ||
return this._offCenterFrustum.projectionMatrix; | ||
} | ||
get infiniteProjectionMatrix() { | ||
update(this); | ||
return this._offCenterFrustum.infiniteProjectionMatrix; | ||
} | ||
get fovy() { | ||
update(this); | ||
return this._fovy; | ||
} | ||
get sseDenominator() { | ||
update(this); | ||
return this._sseDenominator; | ||
} | ||
computeCullingVolume(position, direction, up) { | ||
update(this); | ||
return this._offCenterFrustum.computeCullingVolume(position, direction, up); | ||
} | ||
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) { | ||
update(this); | ||
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result); | ||
} | ||
} | ||
exports.default = PerspectiveFrustum; | ||
@@ -113,3 +134,3 @@ | ||
(0, _core.assert)(Number.isFinite(frustum.fov) && Number.isFinite(frustum.aspectRatio) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far)); | ||
const f = frustum._offCenterFrustum; | ||
var f = frustum._offCenterFrustum; | ||
@@ -116,0 +137,0 @@ if (frustum.fov !== frustum._fov || frustum.aspectRatio !== frustum._aspectRatio || frustum.near !== frustum._near || frustum.far !== frustum._far || frustum.xOffset !== frustum._xOffset || frustum.yOffset !== frustum._yOffset) { |
@@ -10,2 +10,6 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -19,10 +23,16 @@ | ||
const scratchPlaneUpVector = new _core.Vector3(); | ||
const scratchPlaneRightVector = new _core.Vector3(); | ||
const scratchPlaneNearCenter = new _core.Vector3(); | ||
const scratchPlaneFarCenter = new _core.Vector3(); | ||
const scratchPlaneNormal = new _core.Vector3(); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
class PerspectiveOffCenterFrustum { | ||
constructor(options = {}) { | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var scratchPlaneUpVector = new _core.Vector3(); | ||
var scratchPlaneRightVector = new _core.Vector3(); | ||
var scratchPlaneNearCenter = new _core.Vector3(); | ||
var scratchPlaneFarCenter = new _core.Vector3(); | ||
var scratchPlaneNormal = new _core.Vector3(); | ||
var PerspectiveOffCenterFrustum = function () { | ||
function PerspectiveOffCenterFrustum() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
(0, _classCallCheck2.default)(this, PerspectiveOffCenterFrustum); | ||
(0, _defineProperty2.default)(this, "left", void 0); | ||
@@ -43,7 +53,6 @@ (0, _defineProperty2.default)(this, "_left", void 0); | ||
(0, _defineProperty2.default)(this, "_infinitePerspective", new _core.Matrix4()); | ||
options = { | ||
options = _objectSpread({ | ||
near: 1.0, | ||
far: 500000000.0, | ||
...options | ||
}; | ||
far: 500000000.0 | ||
}, options); | ||
this.left = options.left; | ||
@@ -63,71 +72,79 @@ this._left = undefined; | ||
clone() { | ||
return new PerspectiveOffCenterFrustum({ | ||
right: this.right, | ||
left: this.left, | ||
top: this.top, | ||
bottom: this.bottom, | ||
near: this.near, | ||
far: this.far | ||
}); | ||
} | ||
(0, _createClass2.default)(PerspectiveOffCenterFrustum, [{ | ||
key: "clone", | ||
value: function clone() { | ||
return new PerspectiveOffCenterFrustum({ | ||
right: this.right, | ||
left: this.left, | ||
top: this.top, | ||
bottom: this.bottom, | ||
near: this.near, | ||
far: this.far | ||
}); | ||
} | ||
}, { | ||
key: "equals", | ||
value: function equals(other) { | ||
return other && other instanceof PerspectiveOffCenterFrustum && this.right === other.right && this.left === other.left && this.top === other.top && this.bottom === other.bottom && this.near === other.near && this.far === other.far; | ||
} | ||
}, { | ||
key: "projectionMatrix", | ||
get: function get() { | ||
update(this); | ||
return this._perspectiveMatrix; | ||
} | ||
}, { | ||
key: "infiniteProjectionMatrix", | ||
get: function get() { | ||
update(this); | ||
return this._infinitePerspective; | ||
} | ||
}, { | ||
key: "computeCullingVolume", | ||
value: function computeCullingVolume(position, direction, up) { | ||
(0, _core.assert)(position, 'position is required.'); | ||
(0, _core.assert)(direction, 'direction is required.'); | ||
(0, _core.assert)(up, 'up is required.'); | ||
var planes = this._cullingVolume.planes; | ||
up = scratchPlaneUpVector.copy(up).normalize(); | ||
var right = scratchPlaneRightVector.copy(direction).cross(up).normalize(); | ||
var nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position); | ||
var farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position); | ||
var normal = scratchPlaneNormal; | ||
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up); | ||
planes[0].fromPointNormal(position, normal); | ||
normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate(); | ||
planes[1].fromPointNormal(position, normal); | ||
normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate(); | ||
planes[2].fromPointNormal(position, normal); | ||
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right); | ||
planes[3].fromPointNormal(position, normal); | ||
normal = new _core.Vector3().copy(direction); | ||
planes[4].fromPointNormal(nearCenter, normal); | ||
normal.negate(); | ||
planes[5].fromPointNormal(farCenter, normal); | ||
return this._cullingVolume; | ||
} | ||
}, { | ||
key: "getPixelDimensions", | ||
value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) { | ||
update(this); | ||
(0, _core.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight)); | ||
(0, _core.assert)(drawingBufferWidth > 0); | ||
(0, _core.assert)(drawingBufferHeight > 0); | ||
(0, _core.assert)(distance > 0); | ||
(0, _core.assert)(result); | ||
var inverseNear = 1.0 / this.near; | ||
var tanTheta = this.top * inverseNear; | ||
var pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight; | ||
tanTheta = this.right * inverseNear; | ||
var pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth; | ||
result.x = pixelWidth; | ||
result.y = pixelHeight; | ||
return result; | ||
} | ||
}]); | ||
return PerspectiveOffCenterFrustum; | ||
}(); | ||
equals(other) { | ||
return other && other instanceof PerspectiveOffCenterFrustum && this.right === other.right && this.left === other.left && this.top === other.top && this.bottom === other.bottom && this.near === other.near && this.far === other.far; | ||
} | ||
get projectionMatrix() { | ||
update(this); | ||
return this._perspectiveMatrix; | ||
} | ||
get infiniteProjectionMatrix() { | ||
update(this); | ||
return this._infinitePerspective; | ||
} | ||
computeCullingVolume(position, direction, up) { | ||
(0, _core.assert)(position, 'position is required.'); | ||
(0, _core.assert)(direction, 'direction is required.'); | ||
(0, _core.assert)(up, 'up is required.'); | ||
const planes = this._cullingVolume.planes; | ||
up = scratchPlaneUpVector.copy(up).normalize(); | ||
const right = scratchPlaneRightVector.copy(direction).cross(up).normalize(); | ||
const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position); | ||
const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position); | ||
let normal = scratchPlaneNormal; | ||
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up); | ||
planes[0].fromPointNormal(position, normal); | ||
normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate(); | ||
planes[1].fromPointNormal(position, normal); | ||
normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate(); | ||
planes[2].fromPointNormal(position, normal); | ||
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right); | ||
planes[3].fromPointNormal(position, normal); | ||
normal = new _core.Vector3().copy(direction); | ||
planes[4].fromPointNormal(nearCenter, normal); | ||
normal.negate(); | ||
planes[5].fromPointNormal(farCenter, normal); | ||
return this._cullingVolume; | ||
} | ||
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) { | ||
update(this); | ||
(0, _core.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight)); | ||
(0, _core.assert)(drawingBufferWidth > 0); | ||
(0, _core.assert)(drawingBufferHeight > 0); | ||
(0, _core.assert)(distance > 0); | ||
(0, _core.assert)(result); | ||
const inverseNear = 1.0 / this.near; | ||
let tanTheta = this.top * inverseNear; | ||
const pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight; | ||
tanTheta = this.right * inverseNear; | ||
const pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth; | ||
result.x = pixelWidth; | ||
result.y = pixelHeight; | ||
return result; | ||
} | ||
} | ||
exports.default = PerspectiveOffCenterFrustum; | ||
@@ -137,10 +154,8 @@ | ||
(0, _core.assert)(Number.isFinite(frustum.right) && Number.isFinite(frustum.left) && Number.isFinite(frustum.top) && Number.isFinite(frustum.bottom) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far)); | ||
const { | ||
top, | ||
bottom, | ||
right, | ||
left, | ||
near, | ||
far | ||
} = frustum; | ||
var top = frustum.top, | ||
bottom = frustum.bottom, | ||
right = frustum.right, | ||
left = frustum.left, | ||
near = frustum.near, | ||
far = frustum.far; | ||
@@ -156,15 +171,15 @@ if (top !== frustum._top || bottom !== frustum._bottom || left !== frustum._left || right !== frustum._right || near !== frustum._near || far !== frustum._far) { | ||
frustum._perspectiveMatrix = new _core.Matrix4().frustum({ | ||
left, | ||
right, | ||
bottom, | ||
top, | ||
near, | ||
far | ||
left: left, | ||
right: right, | ||
bottom: bottom, | ||
top: top, | ||
near: near, | ||
far: far | ||
}); | ||
frustum._infinitePerspective = new _core.Matrix4().frustum({ | ||
left, | ||
right, | ||
bottom, | ||
top, | ||
near, | ||
left: left, | ||
right: right, | ||
bottom: bottom, | ||
top: top, | ||
near: near, | ||
far: Infinity | ||
@@ -171,0 +186,0 @@ }); |
@@ -10,2 +10,6 @@ "use strict"; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -15,7 +19,10 @@ | ||
const scratchPosition = new _core.Vector3(); | ||
const scratchNormal = new _core.Vector3(); | ||
var scratchPosition = new _core.Vector3(); | ||
var scratchNormal = new _core.Vector3(); | ||
class Plane { | ||
constructor(normal = [0, 0, 1], distance = 0) { | ||
var Plane = function () { | ||
function Plane() { | ||
var normal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 1]; | ||
var distance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
(0, _classCallCheck2.default)(this, Plane); | ||
(0, _defineProperty2.default)(this, "normal", void 0); | ||
@@ -28,52 +35,63 @@ (0, _defineProperty2.default)(this, "distance", void 0); | ||
fromNormalDistance(normal, distance) { | ||
(0, _core.assert)(Number.isFinite(distance)); | ||
this.normal.from(normal).normalize(); | ||
this.distance = distance; | ||
return this; | ||
} | ||
(0, _createClass2.default)(Plane, [{ | ||
key: "fromNormalDistance", | ||
value: function fromNormalDistance(normal, distance) { | ||
(0, _core.assert)(Number.isFinite(distance)); | ||
this.normal.from(normal).normalize(); | ||
this.distance = distance; | ||
return this; | ||
} | ||
}, { | ||
key: "fromPointNormal", | ||
value: function fromPointNormal(point, normal) { | ||
point = scratchPosition.from(point); | ||
this.normal.from(normal).normalize(); | ||
var distance = -this.normal.dot(point); | ||
this.distance = distance; | ||
return this; | ||
} | ||
}, { | ||
key: "fromCoefficients", | ||
value: function fromCoefficients(a, b, c, d) { | ||
this.normal.set(a, b, c); | ||
(0, _core.assert)((0, _core.equals)(this.normal.len(), 1)); | ||
this.distance = d; | ||
return this; | ||
} | ||
}, { | ||
key: "clone", | ||
value: function clone() { | ||
return new Plane(this.normal, this.distance); | ||
} | ||
}, { | ||
key: "equals", | ||
value: function equals(right) { | ||
return (0, _core.equals)(this.distance, right.distance) && (0, _core.equals)(this.normal, right.normal); | ||
} | ||
}, { | ||
key: "getPointDistance", | ||
value: function getPointDistance(point) { | ||
return this.normal.dot(point) + this.distance; | ||
} | ||
}, { | ||
key: "transform", | ||
value: function transform(matrix4) { | ||
var normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize(); | ||
var point = this.normal.scale(-this.distance).transform(matrix4); | ||
return this.fromPointNormal(point, normal); | ||
} | ||
}, { | ||
key: "projectPointOntoPlane", | ||
value: function projectPointOntoPlane(point) { | ||
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0]; | ||
point = scratchPosition.from(point); | ||
var pointDistance = this.getPointDistance(point); | ||
var scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance); | ||
return point.subtract(scaledNormal).to(result); | ||
} | ||
}]); | ||
return Plane; | ||
}(); | ||
fromPointNormal(point, normal) { | ||
point = scratchPosition.from(point); | ||
this.normal.from(normal).normalize(); | ||
const distance = -this.normal.dot(point); | ||
this.distance = distance; | ||
return this; | ||
} | ||
fromCoefficients(a, b, c, d) { | ||
this.normal.set(a, b, c); | ||
(0, _core.assert)((0, _core.equals)(this.normal.len(), 1)); | ||
this.distance = d; | ||
return this; | ||
} | ||
clone() { | ||
return new Plane(this.normal, this.distance); | ||
} | ||
equals(right) { | ||
return (0, _core.equals)(this.distance, right.distance) && (0, _core.equals)(this.normal, right.normal); | ||
} | ||
getPointDistance(point) { | ||
return this.normal.dot(point) + this.distance; | ||
} | ||
transform(matrix4) { | ||
const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize(); | ||
const point = this.normal.scale(-this.distance).transform(matrix4); | ||
return this.fromPointNormal(point, normal); | ||
} | ||
projectPointOntoPlane(point, result = [0, 0, 0]) { | ||
point = scratchPosition.from(point); | ||
const pointDistance = this.getPointDistance(point); | ||
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance); | ||
return point.subtract(scaledNormal).to(result); | ||
} | ||
} | ||
exports.default = Plane; | ||
//# sourceMappingURL=plane.js.map |
@@ -133,3 +133,2 @@ // This file is derived from the Cesium math library under Apache 2 license | ||
ritterCenter.to(result.center); | ||
// @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property. | ||
result.radius = ritterRadius; | ||
@@ -139,3 +138,2 @@ } | ||
naiveCenter.to(result.center); | ||
// @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property. | ||
result.radius = naiveRadius; | ||
@@ -142,0 +140,0 @@ } |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "3.6.0-alpha.1", | ||
"version": "3.6.0-alpha.2", | ||
"keywords": [ | ||
@@ -39,6 +39,6 @@ "webgl", | ||
"@babel/runtime": "^7.12.0", | ||
"@math.gl/core": "3.6.0-alpha.1", | ||
"gl-matrix": "~3.3.0" | ||
"@math.gl/core": "3.6.0-alpha.2", | ||
"gl-matrix": "^3.4.0" | ||
}, | ||
"gitHead": "45386981340895bf201c2ebb76257c9bbffd8ff6" | ||
"gitHead": "ea7dc265c98b68af56218302d1d42b7d65f74ccb" | ||
} |
@@ -162,7 +162,5 @@ // This file is derived from the Cesium math library under Apache 2 license | ||
ritterCenter.to(result.center); | ||
// @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property. | ||
result.radius = ritterRadius; | ||
} else { | ||
naiveCenter.to(result.center); | ||
// @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property. | ||
result.radius = naiveRadius; | ||
@@ -169,0 +167,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
536224
6503
0
+ Added@math.gl/core@3.6.0-alpha.2(transitive)
+ Added@math.gl/types@3.6.0-alpha.2(transitive)
+ Addedgl-matrix@3.4.3(transitive)
- Removed@math.gl/core@3.6.0-alpha.1(transitive)
- Removed@math.gl/types@3.6.0-alpha.1(transitive)
- Removedgl-matrix@3.3.0(transitive)
Updated@math.gl/core@3.6.0-alpha.2
Updatedgl-matrix@^3.4.0