@math.gl/culling 4.0.0-alpha.1 → 4.0.0-alpha.2
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/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -2
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -1
- package/dist/lib/algorithms/bounding-box-from-points.js +3 -3
- package/dist/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +2 -2
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.js +2 -2
- package/dist/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +2 -2
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.js +1 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -2
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +1 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -2
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/bounding-sphere.js +1 -1
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -1
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +3 -3
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +2 -2
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/lib/culling-volume.d.ts +3 -3
- package/dist/lib/culling-volume.d.ts.map +1 -1
- package/dist/lib/culling-volume.js +2 -2
- package/dist/lib/culling-volume.js.map +1 -1
- package/dist/lib/perspective-frustum.d.ts +3 -3
- package/dist/lib/perspective-frustum.d.ts.map +1 -1
- package/dist/lib/perspective-frustum.js +2 -2
- package/dist/lib/perspective-frustum.js.map +1 -1
- package/dist/lib/perspective-off-center-frustum.d.ts +3 -3
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
- package/dist/lib/perspective-off-center-frustum.js +3 -3
- package/dist/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/lib/plane.d.ts +1 -1
- package/dist/lib/plane.d.ts.map +1 -1
- package/dist/lib/plane.js +1 -1
- package/dist/lib/plane.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +9 -9
- package/src/lib/algorithms/bounding-box-from-points.ts +3 -3
- package/src/lib/algorithms/bounding-sphere-from-points.ts +2 -2
- package/src/lib/algorithms/compute-eigen-decomposition.ts +1 -1
- package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +2 -2
- package/src/lib/bounding-volumes/bounding-sphere.ts +2 -2
- package/src/lib/bounding-volumes/bounding-volume.ts +1 -1
- package/src/lib/bounding-volumes/oriented-bounding-box.ts +3 -3
- package/src/lib/culling-volume.ts +3 -3
- package/src/lib/perspective-frustum.ts +3 -3
- package/src/lib/perspective-off-center-frustum.ts +3 -3
- package/src/lib/plane.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["Vector3","Matrix3","Quaternion","BoundingSphere","INTERSECTION","scratchVector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","constructor","center","halfAxes","from","halfSize","xAxis","getColumn","yAxis","zAxis","len","quaternion","normXAxis","normalize","normYAxis","normZAxis","fromMatrix3","fromCenterHalfSizeQuaternion","quaternionObject","directionsMatrix","fromQuaternion","clone","equals","right","Boolean","getBoundingSphere","result","u","v","w","cornerVector","copy","add","radius","magnitude","intersectPlane","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","OUTSIDE","INSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","computePlaneDistances","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transform","transformation","transformAsPoint","getTransform","Error"],"mappings":";AAGA,SAAQA,OAAR,EAAiBC,OAAjB,EAAmCC,UAAnC,QAAkE,eAAlE;OAEOC,c;SAECC,Y;AAER,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,aAAa,GAAG,IAAIN,OAAJ,EAAtB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA,MAAMQ,cAAc,GAAG,IAAIR,OAAJ,EAAvB;AACA,MAAMS,cAAc,GAAG,IAAIT,OAAJ,EAAvB;AACA,MAAMU,aAAa,GAAG,IAAIV,OAAJ,EAAtB;AACA,MAAMW,eAAe,GAAG,IAAIX,OAAJ,EAAxB;AAEA,MAAMY,OAAO,GAAG;AACdC,EAAAA,WAAW,EAAE,CADC;AAEdC,EAAAA,WAAW,EAAE,CAFC;AAGdC,EAAAA,WAAW,EAAE,CAHC;AAIdC,EAAAA,WAAW,EAAE,CAJC;AAKdC,EAAAA,WAAW,EAAE,CALC;AAMdC,EAAAA,WAAW,EAAE,CANC;AAOdC,EAAAA,WAAW,EA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EAAAA,SAAS,CAACC,cAAD,EAA0C;AACjD,SAAK5E,MAAL,CAAY6E,gBAAZ,CAA6BD,cAA7B;AAEA,UAAMxE,KAAK,GAAG,KAAKH,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BtB,cAA3B,CAAd;AACAqB,IAAAA,KAAK,CAACyE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMtE,KAAK,GAAG,KAAKL,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BrB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACuE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMrE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BpB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACsE,gBAAN,CAAuBD,cAAvB;AAEA,SAAK3E,QAAL,GAAgB,IAAIxB,OAAJ,CAAY,CAAC,GAAG2B,KAAJ,EAAW,GAAGE,KAAd,EAAqB,GAAGC,KAAxB,CAAZ,CAAhB;AACA,WAAO,IAAP;AACD;;AAEDuE,EAAAA,YAAY,GAAY;AAGtB,UAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;AACD;;AAvTgE","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: Readonly<NumericArray>, halfAxes?: Readonly<NumericArray>);\n constructor(\n center: Readonly<NumericArray> = [0, 0, 0],\n halfAxes: Readonly<NumericArray> = [0, 0, 0, 0, 0, 0, 0, 0, 0]\n ) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["Vector3","Matrix3","Quaternion","BoundingSphere","INTERSECTION","scratchVector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","constructor","center","halfAxes","from","halfSize","xAxis","getColumn","yAxis","zAxis","len","quaternion","normXAxis","normalize","normYAxis","normZAxis","fromMatrix3","fromCenterHalfSizeQuaternion","quaternionObject","directionsMatrix","fromQuaternion","clone","equals","right","Boolean","getBoundingSphere","result","u","v","w","cornerVector","copy","add","radius","magnitude","intersectPlane","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","OUTSIDE","INSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","computePlaneDistances","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transform","transformation","transformAsPoint","getTransform","Error"],"mappings":";AAGA,SAAQA,OAAR,EAAiBC,OAAjB,EAAmCC,UAAnC,QAAkE,eAAlE;SAEQC,c;SAEAC,Y;AAER,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,aAAa,GAAG,IAAIN,OAAJ,EAAtB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA,MAAMQ,cAAc,GAAG,IAAIR,OAAJ,EAAvB;AACA,MAAMS,cAAc,GAAG,IAAIT,OAAJ,EAAvB;AACA,MAAMU,aAAa,GAAG,IAAIV,OAAJ,EAAtB;AACA,MAAMW,eAAe,GAAG,IAAIX,OAAJ,EAAxB;AAEA,MAAMY,OAAO,GAAG;AACdC,EAAAA,WAAW,EAAE,CADC;AAEdC,EAAAA,WAAW,EAAE,CAFC;AAGdC,EAAAA,WAAW,EAAE,CAHC;AAIdC,EAAAA,WAAW,EAAE,CAJC;AAKdC,EAAAA,WAAW,EAAE,CALC;AAMdC,EAAAA,WAAW,EAAE,CANC;AAOdC,EAAAA,WAAW,EAAE,CAPC;AAQdC,EAAAA,WAAW,EAAE,CARC;AASdC,EAAAA,WAAW,EAAE;AATC,CAAhB;AAiBA,OAAO,MAAMC,m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KAAK,GAAG,KAAKH,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BtB,cAA3B,CAAd;AACAqB,IAAAA,KAAK,CAACyE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMtE,KAAK,GAAG,KAAKL,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BrB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACuE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMrE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BpB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACsE,gBAAN,CAAuBD,cAAvB;AAEA,SAAK3E,QAAL,GAAgB,IAAIxB,OAAJ,CAAY,CAAC,GAAG2B,KAAJ,EAAW,GAAGE,KAAd,EAAqB,GAAGC,KAAxB,CAAZ,CAAhB;AACA,WAAO,IAAP;AACD;;AAEDuE,EAAAA,YAAY,GAAY;AAGtB,UAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;AACD;;AAvTwD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport {BoundingSphere} from './bounding-sphere';\nimport type {Plane} from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: Readonly<NumericArray>, halfAxes?: Readonly<NumericArray>);\n constructor(\n center: Readonly<NumericArray> = [0, 0, 0],\n halfAxes: Readonly<NumericArray> = [0, 0, 0, 0, 0, 0, 0, 0, 0]\n ) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Plane from './plane';
|
|
1
|
+
import { Plane } from './plane';
|
|
2
2
|
import type { BoundingVolume } from './bounding-volumes/bounding-volume';
|
|
3
|
-
import type BoundingSphere from './bounding-volumes/bounding-sphere';
|
|
3
|
+
import type { BoundingSphere } from './bounding-volumes/bounding-sphere';
|
|
4
4
|
/** A culling volume defined by planes. */
|
|
5
|
-
export
|
|
5
|
+
export declare class CullingVolume {
|
|
6
6
|
/**
|
|
7
7
|
* For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value
|
|
8
8
|
* represents the case where the object bounding volume is entirely outside the culling volume.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"culling-volume.d.ts","sourceRoot":"","sources":["../../src/lib/culling-volume.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"culling-volume.d.ts","sourceRoot":"","sources":["../../src/lib/culling-volume.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oCAAoC,CAAC;AASvE,0CAA0C;AAC1C,qBAAa,aAAa;IACxB;;;OAGG;IACH,MAAM,CAAC,YAAY,SAAc;IAEjC;;;OAGG;IACH,MAAM,CAAC,WAAW,SAAc;IAEhC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,SAAc;IAEvC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IAEzB;;;SAGK;gBACO,MAAM,GAAE,KAAK,EAAO;IAIhC;;;OAGG;IACH,kBAAkB,CAAC,cAAc,EAAE,cAAc,GAAG,aAAa;IAsCjE,0EAA0E;IAC1E,iBAAiB,CAAC,cAAc,EAAE,cAAc,GAAG,MAAM;IAsBzD;;;;;;;OAOG;IACH,8BAA8B,CAAC,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM;CAmChG"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { Vector3, assert } from '@math.gl/core';
|
|
3
3
|
import { INTERSECTION } from "../constants.js";
|
|
4
|
-
import Plane from "./plane.js";
|
|
4
|
+
import { Plane } from "./plane.js";
|
|
5
5
|
const faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];
|
|
6
6
|
const scratchPlaneCenter = new Vector3();
|
|
7
7
|
const scratchPlaneNormal = new Vector3();
|
|
8
|
-
export
|
|
8
|
+
export class CullingVolume {
|
|
9
9
|
constructor(planes = []) {
|
|
10
10
|
_defineProperty(this, "planes", void 0);
|
|
11
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/culling-volume.ts"],"names":["Vector3","assert","INTERSECTION","Plane","faces","scratchPlaneCenter","scratchPlaneNormal","CullingVolume","constructor","planes","fromBoundingSphere","boundingSphere","length","center","radius","planeIndex","faceNormal","plane0","plane1","plane0Center","copy","scale","add","fromPointNormal","plane1Center","negatedFaceNormal","negate","computeVisibility","boundingVolume","intersect","INSIDE","plane","result","intersectPlane","OUTSIDE","INTERSECTING","computeVisibilityWithPlaneMask","parentPlaneMask","Number","isFinite","MASK_OUTSIDE","MASK_INSIDE","mask","k","flag"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,QAA8B,eAA9B;SACQC,Y;
|
|
1
|
+
{"version":3,"sources":["../../src/lib/culling-volume.ts"],"names":["Vector3","assert","INTERSECTION","Plane","faces","scratchPlaneCenter","scratchPlaneNormal","CullingVolume","constructor","planes","fromBoundingSphere","boundingSphere","length","center","radius","planeIndex","faceNormal","plane0","plane1","plane0Center","copy","scale","add","fromPointNormal","plane1Center","negatedFaceNormal","negate","computeVisibility","boundingVolume","intersect","INSIDE","plane","result","intersectPlane","OUTSIDE","INTERSECTING","computeVisibilityWithPlaneMask","parentPlaneMask","Number","isFinite","MASK_OUTSIDE","MASK_INSIDE","mask","k","flag"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,QAA8B,eAA9B;SACQC,Y;SACAC,K;AAKR,MAAMC,KAAK,GAAG,CAAC,IAAIJ,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAD,EAAyB,IAAIA,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAzB,EAAiD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AGD,CAAC,GAAG,EAAJ,GAAS,KAAKA,CAAd,GAAkB,CAA/B;;AACA,UAAIA,CAAC,GAAG,EAAJ,IAAU,CAACN,eAAe,GAAGO,IAAnB,MAA6B,CAA3C,EAA8C;AAE5C;AACD;;AAED,YAAMb,KAAK,GAAGtB,MAAM,CAACkC,CAAD,CAApB;AACA,YAAMX,MAAM,GAAGJ,cAAc,CAACK,cAAf,CAA8BF,KAA9B,CAAf;;AACA,UAAIC,MAAM,KAAK9B,YAAY,CAACgC,OAA5B,EAAqC;AACnC,eAAO3B,aAAa,CAACiC,YAArB;AACD,OAFD,MAEO,IAAIR,MAAM,KAAK9B,YAAY,CAACiC,YAA5B,EAA0C;AAC/CO,QAAAA,IAAI,IAAIE,IAAR;AACD;AACF;;AAED,WAAOF,IAAP;AACD;;AAzIwB;;gBAAdnC,a,kBAKW,U;;gBALXA,a,iBAWU,U;;gBAXVA,a,wBAiBiB,U","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Vector3, assert} from '@math.gl/core';\nimport {INTERSECTION} from '../constants';\nimport {Plane} from './plane';\nimport type {BoundingVolume} from './bounding-volumes/bounding-volume';\nimport type {BoundingSphere} from './bounding-volumes/bounding-sphere';\n\n// X, Y, Z Unit vectors\nconst faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];\n\nconst scratchPlaneCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n// const scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);\n\n/** A culling volume defined by planes. */\nexport class CullingVolume {\n /**\n * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value\n * represents the case where the object bounding volume is entirely outside the culling volume.\n */\n static MASK_OUTSIDE = 0xffffffff;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume is entirely inside the culling volume.\n */\n static MASK_INSIDE = 0x00000000;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume (may) intersect all planes of the culling volume.\n */\n static MASK_INDETERMINATE = 0x7fffffff;\n\n /** Array of clipping planes. */\n readonly planes: Plane[];\n\n /**\n * Create a new `CullingVolume` bounded by an array of clipping planed\n * @param planes Array of clipping planes.\n * */\n constructor(planes: Plane[] = []) {\n this.planes = planes;\n }\n\n /**\n * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.\n * The planes are aligned to the x, y, and z axes in world coordinates.\n */\n fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume {\n this.planes.length = 2 * faces.length;\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let planeIndex = 0;\n\n for (const faceNormal of faces) {\n let plane0 = this.planes[planeIndex];\n let plane1 = this.planes[planeIndex + 1];\n\n if (!plane0) {\n plane0 = this.planes[planeIndex] = new Plane();\n }\n if (!plane1) {\n plane1 = this.planes[planeIndex + 1] = new Plane();\n }\n\n const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);\n // const plane0Distance = -faceNormal.dot(plane0Center);\n\n plane0.fromPointNormal(plane0Center, faceNormal);\n\n const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);\n\n const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();\n\n // const plane1Distance = -negatedFaceNormal.dot(plane1Center);\n\n plane1.fromPointNormal(plane1Center, negatedFaceNormal);\n\n planeIndex += 2;\n }\n\n return this;\n }\n\n /** Determines whether a bounding volume intersects the culling volume. */\n computeVisibility(boundingVolume: BoundingVolume): number {\n // const planes = this.planes;\n let intersect: number = INTERSECTION.INSIDE;\n for (const plane of this.planes) {\n const result = boundingVolume.intersectPlane(plane);\n switch (result) {\n case INTERSECTION.OUTSIDE:\n // We are done\n return INTERSECTION.OUTSIDE;\n\n case INTERSECTION.INTERSECTING:\n // If no other intersection is outside, return INTERSECTING\n intersect = INTERSECTION.INTERSECTING;\n break;\n\n default:\n }\n }\n\n return intersect;\n }\n\n /**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling\n * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then\n * the parent (and therefore this) volume is completely inside plane[planeIndex]\n * and that plane check can be skipped.\n */\n computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number {\n assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');\n\n if (\n parentPlaneMask === CullingVolume.MASK_OUTSIDE ||\n parentPlaneMask === CullingVolume.MASK_INSIDE\n ) {\n // parent is completely outside or completely inside, so this child is as well.\n return parentPlaneMask;\n }\n\n // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.\n // (Because if there are fewer than 31 planes, the upper bits wont be changed.)\n let mask = CullingVolume.MASK_INSIDE;\n\n const planes = this.planes;\n for (let k = 0; k < this.planes.length; ++k) {\n // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.\n const flag = k < 31 ? 1 << k : 0;\n if (k < 31 && (parentPlaneMask & flag) === 0) {\n // boundingVolume is known to be INSIDE this plane.\n continue;\n }\n\n const plane = planes[k];\n const result = boundingVolume.intersectPlane(plane);\n if (result === INTERSECTION.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n } else if (result === INTERSECTION.INTERSECTING) {\n mask |= flag;\n }\n }\n\n return mask;\n }\n}\n"],"file":"culling-volume.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Matrix4, NumericArray, Vector2 } from '@math.gl/core';
|
|
2
|
-
import CullingVolume from './culling-volume';
|
|
3
|
-
type PerspectiveFrustumOptions = {
|
|
2
|
+
import { CullingVolume } from './culling-volume';
|
|
3
|
+
declare type PerspectiveFrustumOptions = {
|
|
4
4
|
/** The angle of the field of view (FOV), in radians. */
|
|
5
5
|
fov?: number;
|
|
6
6
|
/** The aspect ratio of the frustum's width to it's height. */
|
|
@@ -32,7 +32,7 @@ type PerspectiveFrustumOptions = {
|
|
|
32
32
|
*
|
|
33
33
|
* @see PerspectiveOffCenterFrustum
|
|
34
34
|
*/
|
|
35
|
-
export
|
|
35
|
+
export declare class PerspectiveFrustum {
|
|
36
36
|
private _offCenterFrustum;
|
|
37
37
|
/**
|
|
38
38
|
* The angle of the field of view (FOV), in radians. This angle will be used
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perspective-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAS,OAAO,EAAE,YAAY,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAErE,OAAO,aAAa,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"perspective-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAS,OAAO,EAAE,YAAY,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAErE,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAI/C,aAAK,yBAAyB,GAAG;IAC/B,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,iBAAiB,CAAqC;IAC9D;;;;OAIG;IACH,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iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,GACf,OAAO;IAWV,OAAO,CAAC,OAAO;CAqDhB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { assert, Vector2 } from '@math.gl/core';
|
|
3
|
-
import PerspectiveOffCenterFrustum from "./perspective-off-center-frustum.js";
|
|
3
|
+
import { PerspectiveOffCenterFrustum } from "./perspective-off-center-frustum.js";
|
|
4
4
|
|
|
5
5
|
const defined = val => val !== null && typeof val !== 'undefined';
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export class PerspectiveFrustum {
|
|
8
8
|
constructor(options = {}) {
|
|
9
9
|
_defineProperty(this, "_offCenterFrustum", new PerspectiveOffCenterFrustum());
|
|
10
10
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/perspective-frustum.ts"],"names":["assert","Vector2","PerspectiveOffCenterFrustum","defined","val","PerspectiveFrustum","constructor","options","fov","aspectRatio","near","far","xOffset","yOffset","clone","equals","other","_update","_offCenterFrustum","projectionMatrix","infiniteProjectionMatrix","fovy","_fovy","sseDenominator","_sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","f","_fov","_aspectRatio","_near","_far","_xOffset","_yOffset","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";AAOA,SAAQA,MAAR,EAAuCC,OAAvC,QAAqD,eAArD;OACOC,2B;;AAGP,MAAMC,OAAO,GAAIC,GAAD,IAAkBA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAjE;;AAmCA,eAAe,MAAMC,kBAAN,CAAyB;AAyCtCC,EAAAA,WAAW,CAACC,OAAkC,GAAG,EAAtC,EAA0C;AAAA,+CAxCzB,IAAIL,2BAAJ,EAwCyB;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA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;AACA0B,MAAAA,CAAC,CAACzB,GAAF,GAAQ,KAAKA,GAAb;AAEAyB,MAAAA,CAAC,CAACa,KAAF,IAAW,KAAKrC,OAAhB;AACAwB,MAAAA,CAAC,CAACc,IAAF,IAAU,KAAKtC,OAAf;AACAwB,MAAAA,CAAC,CAACW,GAAF,IAAS,KAAKlC,OAAd;AACAuB,MAAAA,CAAC,CAACY,MAAF,IAAY,KAAKnC,OAAjB;AACD;AACF;;AAzOqC","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\nimport {assert, Matrix4, NumericArray, Vector2} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\nimport CullingVolume from './culling-volume';\n\nconst defined = (val: unknown) => val !== null && typeof val !== 'undefined';\n\ntype PerspectiveFrustumOptions = {\n /** The angle of the field of view (FOV), in radians. */\n fov?: number;\n /** The aspect ratio of the frustum's width to it's height. */\n aspectRatio?: number;\n /** The distance of the near plane. */\n near?: number;\n /** The distance of the far plane. */\n far?: number;\n /** The offset in the x direction. */\n xOffset?: number;\n /** The offset in the y direction. */\n yOffset?: number;\n};\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport default class PerspectiveFrustum {\n private _offCenterFrustum = new PerspectiveOffCenterFrustum();\n /**\n * The angle of the field of view (FOV), in radians. This angle will be used\n * as the horizontal FOV if the width is greater than the height, otherwise\n * it will be the vertical FOV.\n */\n fov?: number;\n private _fov: number;\n private _fovy: number;\n private _sseDenominator: number;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio?: number;\n private _aspectRatio: number;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n private _xOffset: number;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n private _yOffset: number;\n\n constructor(options: PerspectiveFrustumOptions = {}) {\n const {fov, aspectRatio, near = 1.0, far = 500000000.0, xOffset = 0.0, yOffset = 0.0} = options;\n\n this.fov = fov;\n this.aspectRatio = aspectRatio;\n this.near = near;\n this.far = far;\n this.xOffset = xOffset;\n this.yOffset = yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n */\n clone(): PerspectiveFrustum {\n return new PerspectiveFrustum({\n aspectRatio: this.aspectRatio,\n fov: this.fov,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveFrustum): boolean {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n this._update();\n other._update();\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view this.\n */\n get projectionMatrix(): Matrix4 {\n this._update();\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n */\n get infiniteProjectionMatrix(): Matrix4 {\n this._update();\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n */\n get fovy(): number {\n this._update();\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n this._update();\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this this.ion.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the this.\n * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(\n /** A Vector3 defines the eye position. */\n position: Readonly<NumericArray>,\n /** A Vector3 defines the view direction. */\n direction: Readonly<NumericArray>,\n /** A Vector3 defines the up direction. */\n up: Readonly<NumericArray>\n ): CullingVolume {\n this._update();\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(\n /** The width of the drawing buffer. */\n drawingBufferWidth: number,\n /** The height of the drawing buffer. */\n drawingBufferHeight: number,\n /** The distance to the near plane in meters. */\n distance: number,\n /** The object onto which to store the result. */\n result?: Vector2\n ): Vector2 {\n this._update();\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result || new Vector2()\n );\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update(): void {\n assert(\n Number.isFinite(this.fov) &&\n Number.isFinite(this.aspectRatio) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = this._offCenterFrustum;\n\n if (\n this.fov !== this._fov ||\n this.aspectRatio !== this._aspectRatio ||\n this.near !== this._near ||\n this.far !== this._far ||\n this.xOffset !== this._xOffset ||\n this.yOffset !== this._yOffset\n ) {\n assert(this.fov >= 0 && this.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(this.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(this.near >= 0 && this.near < this.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n this._aspectRatio = this.aspectRatio;\n this._fov = this.fov;\n this._fovy =\n this.aspectRatio <= 1\n ? this.fov\n : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;\n this._near = this.near;\n this._far = this.far;\n this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);\n this._xOffset = this.xOffset;\n this._yOffset = this.yOffset;\n\n f.top = this.near * Math.tan(0.5 * this._fovy);\n f.bottom = -f.top;\n f.right = this.aspectRatio * f.top;\n f.left = -f.right;\n f.near = this.near;\n f.far = this.far;\n\n f.right += this.xOffset;\n f.left += this.xOffset;\n f.top += this.yOffset;\n f.bottom += this.yOffset;\n }\n }\n}\n"],"file":"perspective-frustum.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/perspective-frustum.ts"],"names":["assert","Vector2","PerspectiveOffCenterFrustum","defined","val","PerspectiveFrustum","constructor","options","fov","aspectRatio","near","far","xOffset","yOffset","clone","equals","other","_update","_offCenterFrustum","projectionMatrix","infiniteProjectionMatrix","fovy","_fovy","sseDenominator","_sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","f","_fov","_aspectRatio","_near","_far","_xOffset","_yOffset","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";AAOA,SAAQA,MAAR,EAAuCC,OAAvC,QAAqD,eAArD;SACQC,2B;;AAGR,MAAMC,OAAO,GAAIC,GAAD,IAAkBA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAjE;;AAmCA,OAAO,MAAMC,kBAAN,CAAyB;AAyC9BC,EAAAA,WAAW,CAACC,OAAkC,GAAG,EAAtC,EAA0C;AAAA,+CAxCzB,IAAIL,2BAAJ,EAwCyB;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACnD,UAAM;AAACM,MAAAA,GAAD;AAAMC,MAAAA,WAAN;AAAmBC,MAAAA,IAAI,GAAG,GAA1B;AAA+BC,MAAAA,GAAG,GAAG,WAArC;AAAkDC,MAAAA,OAAO,GAAG,GAA5D;AAAiEC,MAAAA,OAAO,GAAG;AAA3E,QAAkFN,OAAxF;AAEA,SAAKC,GAAL,GAAWA,GAAX;AACA,SAAKC,WAAL,GAAmBA,WAAnB;AACA,SAAKC,IAAL,GAAYA,IAAZ;AACA,SAAKC,GAAL,GAAWA,GAAX;AACA,SAAKC,OAAL,GAAeA,OAAf;AACA,SAAKC,OAAL,GAAeA,OAAf;AACD;;AAKDC,EAAAA,KAAK,GAAuB;AAC1B,WAAO,IAAIT,kBAAJ,CAAuB;AAC5BI,MAAAA,WAAW,EAAE,KAAKA,WADU;AAE5BD,MAAAA,GAAG,EAAE,KAAKA,GAFkB;AAG5BE,MAAAA,IAAI,EAAE,KAAKA,IAHiB;AAI5BC,MAAAA,GAAG,EAAE,KAAKA;AAJkB,KAAvB,CAAP;AAMD;;AAMDI,EAAA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AAuB,MAAMmB,IAAI,CAACG,GAAL,CAAS,MAAM,KAAKxB,KAApB,CAA7B;AACA,WAAKmB,QAAL,GAAgB,KAAK7B,OAArB;AACA,WAAK8B,QAAL,GAAgB,KAAK7B,OAArB;AAEAuB,MAAAA,CAAC,CAACW,GAAF,GAAQ,KAAKrC,IAAL,GAAYiC,IAAI,CAACG,GAAL,CAAS,MAAM,KAAKxB,KAApB,CAApB;AACAc,MAAAA,CAAC,CAACY,MAAF,GAAW,CAACZ,CAAC,CAACW,GAAd;AACAX,MAAAA,CAAC,CAACa,KAAF,GAAU,KAAKxC,WAAL,GAAmB2B,CAAC,CAACW,GAA/B;AACAX,MAAAA,CAAC,CAACc,IAAF,GAAS,CAACd,CAAC,CAACa,KAAZ;AACAb,MAAAA,CAAC,CAAC1B,IAAF,GAAS,KAAKA,IAAd;AACA0B,MAAAA,CAAC,CAACzB,GAAF,GAAQ,KAAKA,GAAb;AAEAyB,MAAAA,CAAC,CAACa,KAAF,IAAW,KAAKrC,OAAhB;AACAwB,MAAAA,CAAC,CAACc,IAAF,IAAU,KAAKtC,OAAf;AACAwB,MAAAA,CAAC,CAACW,GAAF,IAAS,KAAKlC,OAAd;AACAuB,MAAAA,CAAC,CAACY,MAAF,IAAY,KAAKnC,OAAjB;AACD;AACF;;AAzO6B","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\nimport {assert, Matrix4, NumericArray, Vector2} from '@math.gl/core';\nimport {PerspectiveOffCenterFrustum} from './perspective-off-center-frustum';\nimport {CullingVolume} from './culling-volume';\n\nconst defined = (val: unknown) => val !== null && typeof val !== 'undefined';\n\ntype PerspectiveFrustumOptions = {\n /** The angle of the field of view (FOV), in radians. */\n fov?: number;\n /** The aspect ratio of the frustum's width to it's height. */\n aspectRatio?: number;\n /** The distance of the near plane. */\n near?: number;\n /** The distance of the far plane. */\n far?: number;\n /** The offset in the x direction. */\n xOffset?: number;\n /** The offset in the y direction. */\n yOffset?: number;\n};\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport class PerspectiveFrustum {\n private _offCenterFrustum = new PerspectiveOffCenterFrustum();\n /**\n * The angle of the field of view (FOV), in radians. This angle will be used\n * as the horizontal FOV if the width is greater than the height, otherwise\n * it will be the vertical FOV.\n */\n fov?: number;\n private _fov: number;\n private _fovy: number;\n private _sseDenominator: number;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio?: number;\n private _aspectRatio: number;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n private _xOffset: number;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n private _yOffset: number;\n\n constructor(options: PerspectiveFrustumOptions = {}) {\n const {fov, aspectRatio, near = 1.0, far = 500000000.0, xOffset = 0.0, yOffset = 0.0} = options;\n\n this.fov = fov;\n this.aspectRatio = aspectRatio;\n this.near = near;\n this.far = far;\n this.xOffset = xOffset;\n this.yOffset = yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n */\n clone(): PerspectiveFrustum {\n return new PerspectiveFrustum({\n aspectRatio: this.aspectRatio,\n fov: this.fov,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveFrustum): boolean {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n this._update();\n other._update();\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view this.\n */\n get projectionMatrix(): Matrix4 {\n this._update();\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n */\n get infiniteProjectionMatrix(): Matrix4 {\n this._update();\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n */\n get fovy(): number {\n this._update();\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n this._update();\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this this.ion.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the this.\n * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(\n /** A Vector3 defines the eye position. */\n position: Readonly<NumericArray>,\n /** A Vector3 defines the view direction. */\n direction: Readonly<NumericArray>,\n /** A Vector3 defines the up direction. */\n up: Readonly<NumericArray>\n ): CullingVolume {\n this._update();\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(\n /** The width of the drawing buffer. */\n drawingBufferWidth: number,\n /** The height of the drawing buffer. */\n drawingBufferHeight: number,\n /** The distance to the near plane in meters. */\n distance: number,\n /** The object onto which to store the result. */\n result?: Vector2\n ): Vector2 {\n this._update();\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result || new Vector2()\n );\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update(): void {\n assert(\n Number.isFinite(this.fov) &&\n Number.isFinite(this.aspectRatio) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = this._offCenterFrustum;\n\n if (\n this.fov !== this._fov ||\n this.aspectRatio !== this._aspectRatio ||\n this.near !== this._near ||\n this.far !== this._far ||\n this.xOffset !== this._xOffset ||\n this.yOffset !== this._yOffset\n ) {\n assert(this.fov >= 0 && this.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(this.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(this.near >= 0 && this.near < this.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n this._aspectRatio = this.aspectRatio;\n this._fov = this.fov;\n this._fovy =\n this.aspectRatio <= 1\n ? this.fov\n : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;\n this._near = this.near;\n this._far = this.far;\n this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);\n this._xOffset = this.xOffset;\n this._yOffset = this.yOffset;\n\n f.top = this.near * Math.tan(0.5 * this._fovy);\n f.bottom = -f.top;\n f.right = this.aspectRatio * f.top;\n f.left = -f.right;\n f.near = this.near;\n f.far = this.far;\n\n f.right += this.xOffset;\n f.left += this.xOffset;\n f.top += this.yOffset;\n f.bottom += this.yOffset;\n }\n }\n}\n"],"file":"perspective-frustum.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Vector2, Matrix4, NumericArray } from '@math.gl/core';
|
|
2
|
-
import CullingVolume from './culling-volume';
|
|
3
|
-
type PerspectiveOffCenterFrustumOptions = {
|
|
2
|
+
import { CullingVolume } from './culling-volume';
|
|
3
|
+
declare type PerspectiveOffCenterFrustumOptions = {
|
|
4
4
|
left?: number;
|
|
5
5
|
right?: number;
|
|
6
6
|
top?: number;
|
|
@@ -8,7 +8,7 @@ type PerspectiveOffCenterFrustumOptions = {
|
|
|
8
8
|
near?: number;
|
|
9
9
|
far?: number;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export declare class PerspectiveOffCenterFrustum {
|
|
12
12
|
/**
|
|
13
13
|
* Defines the left clipping plane.
|
|
14
14
|
* @type {Number}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perspective-off-center-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-off-center-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAU,OAAO,EAAE,OAAO,EAAU,YAAY,EAAC,MAAM,eAAe,CAAC;AAC9E,OAAO,aAAa,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"perspective-off-center-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-off-center-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAU,OAAO,EAAE,OAAO,EAAU,YAAY,EAAC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QG;IAEH,oBAAoB;IAClB,0CAA0C;IAC1C,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC;IAChC,4CAA4C;IAC5C,SAAS,EAAE,QAAQ,CAAC,YAAY,CAAC;IACjC,0CAA0C;IAC1C,EAAE,EAAE,QAAQ,CAAC,YAAY,CAAC,GACzB,aAAa;IAmEhB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,kBAAkB;IAChB,uCAAuC;IACvC,kBAAkB,EAAE,MAAM;IAC1B,wCAAwC;IACxC,mBAAmB,EAAE,MAAM;IAC3B,gDAAgD;IAChD,QAAQ,EAAE,MAAM;IAChB,iDAAiD;IACjD,MAAM,EAAE,OAAO,GACd,OAAO;IA0BV,OAAO,CAAC,OAAO;CAkDhB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { Vector3, Matrix4, assert } from '@math.gl/core';
|
|
3
|
-
import CullingVolume from "./culling-volume.js";
|
|
4
|
-
import Plane from "./plane.js";
|
|
3
|
+
import { CullingVolume } from "./culling-volume.js";
|
|
4
|
+
import { Plane } from "./plane.js";
|
|
5
5
|
const scratchPlaneUpVector = new Vector3();
|
|
6
6
|
const scratchPlaneRightVector = new Vector3();
|
|
7
7
|
const scratchPlaneNearCenter = new Vector3();
|
|
8
8
|
const scratchPlaneFarCenter = new Vector3();
|
|
9
9
|
const scratchPlaneNormal = new Vector3();
|
|
10
|
-
export
|
|
10
|
+
export class PerspectiveOffCenterFrustum {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
_defineProperty(this, "left", void 0);
|
|
13
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/perspective-off-center-frustum.ts"],"names":["Vector3","Matrix4","assert","CullingVolume","Plane","scratchPlaneUpVector","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","constructor","options","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","clone","equals","other","projectionMatrix","_update","_perspectiveMatrix","infiniteProjectionMatrix","_infinitePerspective","computeCullingVolume","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x","y","frustum","Infinity"],"mappings":";AAOA,SAAQA,OAAR,EAA0BC,OAA1B,EAAmCC,MAAnC,QAA8D,eAA9D;OACOC,a;OACAC,K;AAEP,MAAMC,oBAAoB,GAAG,IAAIL,OAAJ,EAA7B;AACA,MAAMM,uBAAuB,GAAG,IAAIN,OAAJ,EAAhC;AACA,MAAMO,sBAAsB,GAAG,IAAIP,OAAJ,EAA/B;AACA,MAAMQ,qBAAqB,GAAG,IAAIR,OAAJ,EAA9B;AACA,MAAMS,kBAAkB,GAAG,IAAIT,OAAJ,EAA3B;AAWA,eAAe,MAAMU,2BAAN,CAAkC;AA2E/CC,EAAAA,WAAW,CAACC,OAA2C,GAAG,EAA/C,EAAmD;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,4CA/BrC,IAAIT,aAAJ,CAAkB,CACzC,IAAIC,KAAJ,EADyC,EAEzC,IAAIA,KAAJ,EAFyC,EAGzC,IAAIA,KAAJ,EAHyC,EAIzC,IAAIA,KAAJ,EAJyC,EAKzC,IAAIA,KAAJ,EALyC,EAMzC,IAAIA,KAAJ,EANyC,CAAlB,CA+BqC;;AAAA,gDAvBjC,IAAIH,OAAJ,EAuBiC;;AAAA,kDAtB/B,IAAIA,OAAJ,EAsB+B;;AAC5D,UAAM;AAACY,MAAAA,IAAI,GAAG,GAAR;AAAaC,MAAAA,GAAG,GAAG;AAAnB,QAAkCF,OAAxC;AAEA,SAAKG,IAAL,GAAYH,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,KAAK,KAAK,KAAKC,MAHf,IAIAN,IAAI,KAAK,KAAKW,KAJd,IAKAV,GAAG,KAAK,KAAKW,IANf,EAOE;AACAvB,MAAAA,MAAM,CACJ,KAAKW,IAAL,GAAY,CAAZ,IAAiB,KAAKA,IAAL,GAAY,KAAKC,GAD9B,EAEJ,mDAFI,CAAN;AAKA,WAAKE,KAAL,GAAaD,IAAb;AACA,WAAKI,MAAL,GAAcD,KAAd;AACA,WAAKG,IAAL,GAAYD,GAAZ;AACA,WAAKG,OAAL,GAAeD,MAAf;AACA,WAAKE,KAAL,GAAaX,IAAb;AACA,WAAKY,IAAL,GAAYX,GAAZ;AACA,WAAKiB,kBAAL,GAA0B,IAAI9B,OAAJ,GAAc+D,OAAd,CAAsB;AAC9CjD,QAAAA,IAD8C;AAE9CG,QAAAA,KAF8C;AAG9CI,QAAAA,MAH8C;AAI9CF,QAAAA,GAJ8C;AAK9CP,QAAAA,IAL8C;AAM9CC,QAAAA;AAN8C,OAAtB,CAA1B;AAQA,WAAKmB,oBAAL,GAA4B,IAAIhC,OAAJ,GAAc+D,OAAd,CAAsB;AAChDjD,QAAAA,IADgD;AAEhDG,QAAAA,KAFgD;AAGhDI,QAAAA,MAHgD;AAIhDF,QAAAA,GAJgD;AAKhDP,QAAAA,IALgD;AAMhDC,QAAAA,GAAG,EAAEmD;AAN2C,OAAtB,CAA5B;AAQD;AACF;;AA3V8C","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\nimport {Vector3, Vector2, Matrix4, assert, NumericArray} from '@math.gl/core';\nimport CullingVolume from './culling-volume';\nimport Plane from './plane';\n\nconst scratchPlaneUpVector = new Vector3();\nconst scratchPlaneRightVector = new Vector3();\nconst scratchPlaneNearCenter = new Vector3();\nconst scratchPlaneFarCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n\ntype PerspectiveOffCenterFrustumOptions = {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n near?: number;\n far?: number;\n};\n\nexport default class PerspectiveOffCenterFrustum {\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n left?: number;\n private _left?: number;\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n right?: number;\n private _right?: number;\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n top?: number;\n private _top?: number;\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n bottom?: number;\n private _bottom?: number;\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n\n private _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n private _perspectiveMatrix = new Matrix4();\n private _infinitePerspective = new Matrix4();\n\n /**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveOffCenterFrustum\n *\n * @example\n * const frustum = new PerspectiveOffCenterFrustum({\n * left : -1.0,\n * right : 1.0,\n * top : 1.0,\n * bottom : -1.0,\n * near : 1.0,\n * far : 100.0\n * });\n *\n * @see PerspectiveFrustum\n */\n constructor(options: PerspectiveOffCenterFrustumOptions = {}) {\n const {near = 1.0, far = 500000000.0} = options;\n\n this.left = options.left;\n this._left = undefined;\n\n this.right = options.right;\n this._right = undefined;\n\n this.top = options.top;\n this._top = undefined;\n\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n this.near = near;\n this._near = near;\n\n this.far = far;\n this._far = far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone(): PerspectiveOffCenterFrustum {\n return new PerspectiveOffCenterFrustum({\n right: this.right,\n left: this.left,\n top: this.top,\n bottom: this.bottom,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveOffCenterFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveOffCenterFrustum): boolean {\n return (\n other &&\n other instanceof PerspectiveOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix(): Matrix4 {\n this._update();\n return this._perspectiveMatrix;\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix(): Matrix4 {\n this._update();\n return this._infinitePerspective;\n }\n\n /**\n * Creates a culling volume for this frustum.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(\n /** A Vector3 defines the eye position. */\n position: Readonly<NumericArray>,\n /** A Vector3 defines the view direction. */\n direction: Readonly<NumericArray>,\n /** A Vector3 defines the up direction. */\n up: Readonly<NumericArray>\n ): CullingVolume {\n assert(position, 'position is required.');\n assert(direction, 'direction is required.');\n assert(up, 'up is required.');\n\n const planes = this._cullingVolume.planes;\n\n up = scratchPlaneUpVector.copy(up).normalize();\n const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();\n\n const nearCenter = scratchPlaneNearCenter\n .copy(direction)\n .multiplyByScalar(this.near)\n .add(position);\n\n const farCenter = scratchPlaneFarCenter\n .copy(direction)\n .multiplyByScalar(this.far)\n .add(position);\n\n let normal = scratchPlaneNormal;\n\n // Left plane computation\n normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);\n\n planes[0].fromPointNormal(position, normal);\n\n // Right plane computation\n normal\n .copy(right)\n .multiplyByScalar(this.right)\n .add(nearCenter)\n .subtract(position)\n .cross(up)\n .negate();\n\n planes[1].fromPointNormal(position, normal);\n\n // Bottom plane computation\n normal\n .copy(up)\n .multiplyByScalar(this.bottom)\n .add(nearCenter)\n .subtract(position)\n .cross(right)\n .negate();\n\n planes[2].fromPointNormal(position, normal);\n\n // Top plane computation\n normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);\n\n planes[3].fromPointNormal(position, normal);\n\n normal = new Vector3().copy(direction);\n\n // Near plane computation\n planes[4].fromPointNormal(nearCenter, normal);\n\n // Far plane computation\n normal.negate();\n\n planes[5].fromPointNormal(farCenter, normal);\n\n return this._cullingVolume;\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * const position = camera.position;\n * const direction = camera.direction;\n * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * const distance = Vector3.magnitude(toCenterProj);\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(\n /** The width of the drawing buffer. */\n drawingBufferWidth: number,\n /** The height of the drawing buffer. */\n drawingBufferHeight: number,\n /** The distance to the near plane in meters. */\n distance: number,\n /** The object onto which to store the result. */\n result: Vector2\n ): Vector2 {\n this._update();\n\n assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));\n // 'Both drawingBufferWidth and drawingBufferHeight are required.'\n assert(drawingBufferWidth > 0);\n // 'drawingBufferWidth must be greater than zero.'\n assert(drawingBufferHeight > 0);\n // 'drawingBufferHeight must be greater than zero.'\n assert(distance > 0);\n // 'distance is required.');\n assert(result);\n // 'A result object is required.');\n\n const inverseNear = 1.0 / this.near;\n let tanTheta = this.top * inverseNear;\n const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;\n tanTheta = this.right * inverseNear;\n const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update() {\n assert(\n Number.isFinite(this.right) &&\n Number.isFinite(this.left) &&\n Number.isFinite(this.top) &&\n Number.isFinite(this.bottom) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');\n\n const {top, bottom, right, left, near, far} = this;\n\n if (\n top !== this._top ||\n bottom !== this._bottom ||\n left !== this._left ||\n right !== this._right ||\n near !== this._near ||\n far !== this._far\n ) {\n assert(\n this.near > 0 && this.near < this.far,\n 'near must be greater than zero and less than far.'\n );\n\n this._left = left;\n this._right = right;\n this._top = top;\n this._bottom = bottom;\n this._near = near;\n this._far = far;\n this._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n this._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/perspective-off-center-frustum.ts"],"names":["Vector3","Matrix4","assert","CullingVolume","Plane","scratchPlaneUpVector","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","constructor","options","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","clone","equals","other","projectionMatrix","_update","_perspectiveMatrix","infiniteProjectionMatrix","_infinitePerspective","computeCullingVolume","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x","y","frustum","Infinity"],"mappings":";AAOA,SAAQA,OAAR,EAA0BC,OAA1B,EAAmCC,MAAnC,QAA8D,eAA9D;SACQC,a;SACAC,K;AAER,MAAMC,oBAAoB,GAAG,IAAIL,OAAJ,EAA7B;AACA,MAAMM,uBAAuB,GAAG,IAAIN,OAAJ,EAAhC;AACA,MAAMO,sBAAsB,GAAG,IAAIP,OAAJ,EAA/B;AACA,MAAMQ,qBAAqB,GAAG,IAAIR,OAAJ,EAA9B;AACA,MAAMS,kBAAkB,GAAG,IAAIT,OAAJ,EAA3B;AAWA,OAAO,MAAMU,2BAAN,CAAkC;AA2EvCC,EAAAA,WAAW,CAACC,OAA2C,GAAG,EAA/C,EAAmD;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,4CA/BrC,IAAIT,aAAJ,CAAkB,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5B;AAQD;AACF;;AA3VsC","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\nimport {Vector3, Vector2, Matrix4, assert, NumericArray} from '@math.gl/core';\nimport {CullingVolume} from './culling-volume';\nimport {Plane} from './plane';\n\nconst scratchPlaneUpVector = new Vector3();\nconst scratchPlaneRightVector = new Vector3();\nconst scratchPlaneNearCenter = new Vector3();\nconst scratchPlaneFarCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n\ntype PerspectiveOffCenterFrustumOptions = {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n near?: number;\n far?: number;\n};\n\nexport class PerspectiveOffCenterFrustum {\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n left?: number;\n private _left?: number;\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n right?: number;\n private _right?: number;\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n top?: number;\n private _top?: number;\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n bottom?: number;\n private _bottom?: number;\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n\n private _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n private _perspectiveMatrix = new Matrix4();\n private _infinitePerspective = new Matrix4();\n\n /**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveOffCenterFrustum\n *\n * @example\n * const frustum = new PerspectiveOffCenterFrustum({\n * left : -1.0,\n * right : 1.0,\n * top : 1.0,\n * bottom : -1.0,\n * near : 1.0,\n * far : 100.0\n * });\n *\n * @see PerspectiveFrustum\n */\n constructor(options: PerspectiveOffCenterFrustumOptions = {}) {\n const {near = 1.0, far = 500000000.0} = options;\n\n this.left = options.left;\n this._left = undefined;\n\n this.right = options.right;\n this._right = undefined;\n\n this.top = options.top;\n this._top = undefined;\n\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n this.near = near;\n this._near = near;\n\n this.far = far;\n this._far = far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone(): PerspectiveOffCenterFrustum {\n return new PerspectiveOffCenterFrustum({\n right: this.right,\n left: this.left,\n top: this.top,\n bottom: this.bottom,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveOffCenterFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveOffCenterFrustum): boolean {\n return (\n other &&\n other instanceof PerspectiveOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix(): Matrix4 {\n this._update();\n return this._perspectiveMatrix;\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix(): Matrix4 {\n this._update();\n return this._infinitePerspective;\n }\n\n /**\n * Creates a culling volume for this frustum.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(\n /** A Vector3 defines the eye position. */\n position: Readonly<NumericArray>,\n /** A Vector3 defines the view direction. */\n direction: Readonly<NumericArray>,\n /** A Vector3 defines the up direction. */\n up: Readonly<NumericArray>\n ): CullingVolume {\n assert(position, 'position is required.');\n assert(direction, 'direction is required.');\n assert(up, 'up is required.');\n\n const planes = this._cullingVolume.planes;\n\n up = scratchPlaneUpVector.copy(up).normalize();\n const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();\n\n const nearCenter = scratchPlaneNearCenter\n .copy(direction)\n .multiplyByScalar(this.near)\n .add(position);\n\n const farCenter = scratchPlaneFarCenter\n .copy(direction)\n .multiplyByScalar(this.far)\n .add(position);\n\n let normal = scratchPlaneNormal;\n\n // Left plane computation\n normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);\n\n planes[0].fromPointNormal(position, normal);\n\n // Right plane computation\n normal\n .copy(right)\n .multiplyByScalar(this.right)\n .add(nearCenter)\n .subtract(position)\n .cross(up)\n .negate();\n\n planes[1].fromPointNormal(position, normal);\n\n // Bottom plane computation\n normal\n .copy(up)\n .multiplyByScalar(this.bottom)\n .add(nearCenter)\n .subtract(position)\n .cross(right)\n .negate();\n\n planes[2].fromPointNormal(position, normal);\n\n // Top plane computation\n normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);\n\n planes[3].fromPointNormal(position, normal);\n\n normal = new Vector3().copy(direction);\n\n // Near plane computation\n planes[4].fromPointNormal(nearCenter, normal);\n\n // Far plane computation\n normal.negate();\n\n planes[5].fromPointNormal(farCenter, normal);\n\n return this._cullingVolume;\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * const position = camera.position;\n * const direction = camera.direction;\n * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * const distance = Vector3.magnitude(toCenterProj);\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(\n /** The width of the drawing buffer. */\n drawingBufferWidth: number,\n /** The height of the drawing buffer. */\n drawingBufferHeight: number,\n /** The distance to the near plane in meters. */\n distance: number,\n /** The object onto which to store the result. */\n result: Vector2\n ): Vector2 {\n this._update();\n\n assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));\n // 'Both drawingBufferWidth and drawingBufferHeight are required.'\n assert(drawingBufferWidth > 0);\n // 'drawingBufferWidth must be greater than zero.'\n assert(drawingBufferHeight > 0);\n // 'drawingBufferHeight must be greater than zero.'\n assert(distance > 0);\n // 'distance is required.');\n assert(result);\n // 'A result object is required.');\n\n const inverseNear = 1.0 / this.near;\n let tanTheta = this.top * inverseNear;\n const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;\n tanTheta = this.right * inverseNear;\n const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update() {\n assert(\n Number.isFinite(this.right) &&\n Number.isFinite(this.left) &&\n Number.isFinite(this.top) &&\n Number.isFinite(this.bottom) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');\n\n const {top, bottom, right, left, near, far} = this;\n\n if (\n top !== this._top ||\n bottom !== this._bottom ||\n left !== this._left ||\n right !== this._right ||\n near !== this._near ||\n far !== this._far\n ) {\n assert(\n this.near > 0 && this.near < this.far,\n 'near must be greater than zero and less than far.'\n );\n\n this._left = left;\n this._right = right;\n this._top = top;\n this._bottom = bottom;\n this._near = near;\n this._far = far;\n this._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n this._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
|
package/dist/lib/plane.d.ts
CHANGED
package/dist/lib/plane.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plane.d.ts","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAkB,YAAY,EAAC,MAAM,eAAe,CAAC;AAMpE,
|
|
1
|
+
{"version":3,"file":"plane.d.ts","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAkB,YAAY,EAAC,MAAM,eAAe,CAAC;AAMpE,qBAAa,KAAK;IAChB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;gBAEL,MAAM,GAAE,QAAQ,CAAC,YAAY,CAAa,EAAE,QAAQ,GAAE,MAAU;IAM5E,oEAAoE;IACpE,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAO1E,8DAA8D;IAC9D,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI;IAQpF,gDAAgD;IAChD,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAOlE,mCAAmC;IACnC,KAAK,IAAI,KAAK;IAId,0DAA0D;IAC1D,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAI7B;;OAEG;IACH,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM;IAIvD,+DAA+D;IAC/D,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI;IAMhD,uCAAuC;IACvC,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAC9E,qBAAqB,CACnB,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC7B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE;CAUrB"}
|
package/dist/lib/plane.js
CHANGED
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
2
2
|
import { Vector3, equals, assert } from '@math.gl/core';
|
|
3
3
|
const scratchPosition = new Vector3();
|
|
4
4
|
const scratchNormal = new Vector3();
|
|
5
|
-
export
|
|
5
|
+
export class Plane {
|
|
6
6
|
constructor(normal = [0, 0, 1], distance = 0) {
|
|
7
7
|
_defineProperty(this, "normal", void 0);
|
|
8
8
|
|
package/dist/lib/plane.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/plane.ts"],"names":["Vector3","equals","assert","scratchPosition","scratchNormal","Plane","constructor","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","fromPointNormal","point","dot","fromCoefficients","a","b","c","d","set","len","clone","right","getPointDistance","transform","matrix4","copy","transformAsVector","scale","projectPointOntoPlane","result","scratchPoint","pointDistance","scaledNormal","subtract","to"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,EAAyBC,MAAzB,QAAoD,eAApD;AAEA,MAAMC,eAAe,GAAG,IAAIH,OAAJ,EAAxB;AACA,MAAMI,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AAGA,
|
|
1
|
+
{"version":3,"sources":["../../src/lib/plane.ts"],"names":["Vector3","equals","assert","scratchPosition","scratchNormal","Plane","constructor","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","fromPointNormal","point","dot","fromCoefficients","a","b","c","d","set","len","clone","right","getPointDistance","transform","matrix4","copy","transformAsVector","scale","projectPointOntoPlane","result","scratchPoint","pointDistance","scaledNormal","subtract","to"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,EAAyBC,MAAzB,QAAoD,eAApD;AAEA,MAAMC,eAAe,GAAG,IAAIH,OAAJ,EAAxB;AACA,MAAMI,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AAGA,OAAO,MAAMK,KAAN,CAAY;AAIjBC,EAAAA,WAAW,CAACC,MAA8B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAlC,EAA6CC,QAAgB,GAAG,CAAhE,EAAmE;AAAA;;AAAA;;AAC5E,SAAKD,MAAL,GAAc,IAAIP,OAAJ,EAAd;AACA,SAAKQ,QAAL,GAAgB,CAAC,CAAjB;AACA,SAAKC,kBAAL,CAAwBF,MAAxB,EAAgCC,QAAhC;AACD;;AAGDC,EAAAA,kBAAkB,CAACF,MAAD,EAAiCC,QAAjC,EAAyD;AACzEN,IAAAA,MAAM,CAACQ,MAAM,CAACC,QAAP,CAAgBH,QAAhB,CAAD,CAAN;AACA,SAAKD,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAA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AmB,KAAKtB,MAAxB,EAAgCuB,iBAAhC,CAAkDF,OAAlD,EAA2Df,SAA3D,EAAf;AACA,UAAME,KAAK,GAAG,KAAKR,MAAL,CAAYwB,KAAZ,CAAkB,CAAC,KAAKvB,QAAxB,EAAkCmB,SAAlC,CAA4CC,OAA5C,CAAd;AACA,WAAO,KAAKd,eAAL,CAAqBC,KAArB,EAA4BR,MAA5B,CAAP;AACD;;AASDyB,EAAAA,qBAAqB,CAACjB,KAAD,EAAgCkB,MAAM,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAzC,EAAoD;AACvE,UAAMC,YAAY,GAAG/B,eAAe,CAACS,IAAhB,CAAqBG,KAArB,CAArB;AAEA,UAAMoB,aAAa,GAAG,KAAKT,gBAAL,CAAsBQ,YAAtB,CAAtB;AACA,UAAME,YAAY,GAAGhC,aAAa,CAACyB,IAAd,CAAmB,KAAKtB,MAAxB,EAAgCwB,KAAhC,CAAsCI,aAAtC,CAArB;AAEA,WAAOD,YAAY,CAACG,QAAb,CAAsBD,YAAtB,EAAoCE,EAApC,CAAuCL,MAAvC,CAAP;AACD;;AAzEgB","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Vector3, equals, assert, NumericArray} from '@math.gl/core';\n\nconst scratchPosition = new Vector3();\nconst scratchNormal = new Vector3();\n\n// A plane in Hessian Normal Form\nexport class Plane {\n readonly normal: Vector3;\n distance: number;\n\n constructor(normal: Readonly<NumericArray> = [0, 0, 1], distance: number = 0) {\n this.normal = new Vector3();\n this.distance = -0;\n this.fromNormalDistance(normal, distance);\n }\n\n /** Creates a plane from a normal and a distance from the origin. */\n fromNormalDistance(normal: Readonly<NumericArray>, distance: number): this {\n assert(Number.isFinite(distance));\n this.normal.from(normal).normalize();\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from a normal and a point on the plane. */\n fromPointNormal(point: Readonly<NumericArray>, normal: Readonly<NumericArray>): this {\n point = scratchPosition.from(point);\n this.normal.from(normal).normalize();\n const distance = -this.normal.dot(point);\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from the general equation */\n fromCoefficients(a: number, b: number, c: number, d: number): this {\n this.normal.set(a, b, c);\n assert(equals(this.normal.len(), 1));\n this.distance = d;\n return this;\n }\n\n /** Duplicates a Plane instance. */\n clone(): Plane {\n return new Plane(this.normal, this.distance);\n }\n\n /** Compares the provided Planes by normal and distance */\n equals(right: Plane): boolean {\n return equals(this.distance, right.distance) && equals(this.normal, right.normal);\n }\n\n /** Computes the signed shortest distance of a point to a plane.\n * The sign of the distance determines which side of the plane the point is on.\n */\n getPointDistance(point: Readonly<NumericArray>): number {\n return this.normal.dot(point) + this.distance;\n }\n\n /** Transforms the plane by the given transformation matrix. */\n transform(matrix4: Readonly<NumericArray>): this {\n const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();\n const point = this.normal.scale(-this.distance).transform(matrix4);\n return this.fromPointNormal(point, normal);\n }\n\n /** Projects a point onto the plane. */\n projectPointOntoPlane(point: Readonly<NumericArray>, result: Vector3): Vector3;\n projectPointOntoPlane(\n point: Readonly<NumericArray>,\n result?: readonly number[]\n ): readonly number[];\n\n projectPointOntoPlane(point: Readonly<NumericArray>, result = [0, 0, 0]) {\n const scratchPoint = scratchPosition.from(point);\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = this.getPointDistance(scratchPoint);\n const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);\n\n return scratchPoint.subtract(scaledNormal).to(result);\n }\n}\n"],"file":"plane.js"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"version": "4.0.0-alpha.
|
|
9
|
+
"version": "4.0.0-alpha.2",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"webgl",
|
|
12
12
|
"javascript",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@babel/runtime": "^7.12.0",
|
|
39
|
-
"@math.gl/core": "4.0.0-alpha.
|
|
39
|
+
"@math.gl/core": "4.0.0-alpha.2",
|
|
40
40
|
"gl-matrix": "^3.4.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2e693639e3cf898fee8e323c93efdd07be7c2ca7"
|
|
43
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
export {INTERSECTION} from './constants';
|
|
5
5
|
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
6
|
+
export {AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';
|
|
7
|
+
export {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';
|
|
8
|
+
export {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';
|
|
9
|
+
export {CullingVolume} from './lib/culling-volume';
|
|
10
|
+
export {Plane} from './lib/plane';
|
|
11
11
|
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
12
|
+
export {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';
|
|
13
|
+
export {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';
|
|
14
14
|
|
|
15
|
-
export {
|
|
15
|
+
export {makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';
|
|
16
16
|
export {
|
|
17
17
|
makeAxisAlignedBoundingBoxFromPoints,
|
|
18
18
|
makeOrientedBoundingBoxFromPoints
|
|
19
19
|
} from './lib/algorithms/bounding-box-from-points';
|
|
20
|
-
export {
|
|
20
|
+
export {computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
3
|
|
|
4
4
|
import {Vector3, Matrix3} from '@math.gl/core';
|
|
5
|
-
import computeEigenDecomposition from './compute-eigen-decomposition';
|
|
6
|
-
import OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';
|
|
7
|
-
import AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';
|
|
5
|
+
import {computeEigenDecomposition} from './compute-eigen-decomposition';
|
|
6
|
+
import {OrientedBoundingBox} from '../bounding-volumes/oriented-bounding-box';
|
|
7
|
+
import {AxisAlignedBoundingBox} from '../bounding-volumes/axis-aligned-bounding-box';
|
|
8
8
|
|
|
9
9
|
const scratchVector2 = new Vector3();
|
|
10
10
|
|