b50b4d8cdf1c67c576f5c3900d9c67a6b80f90144fc7f8c251cfe8da72330e50.json 16 KB

1
  1. {"ast":null,"code":"import { BuildArray } from \"../Misc/arrayTools.js\";\nimport { Matrix, Vector3 } from \"../Maths/math.vector.js\";\n/**\n * Class used to store bounding sphere information\n */\nexport class BoundingSphere {\n /**\n * Creates a new bounding sphere\n * @param min defines the minimum vector (in local space)\n * @param max defines the maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n constructor(min, max, worldMatrix) {\n /**\n * Gets the center of the bounding sphere in local space\n */\n this.center = Vector3.Zero();\n /**\n * Gets the center of the bounding sphere in world space\n */\n this.centerWorld = Vector3.Zero();\n /**\n * Gets the minimum vector in local space\n */\n this.minimum = Vector3.Zero();\n /**\n * Gets the maximum vector in local space\n */\n this.maximum = Vector3.Zero();\n this.reConstruct(min, max, worldMatrix);\n }\n /**\n * Recreates the entire bounding sphere from scratch as if we call the constructor in place\n * @param min defines the new minimum vector (in local space)\n * @param max defines the new maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n reConstruct(min, max, worldMatrix) {\n this.minimum.copyFrom(min);\n this.maximum.copyFrom(max);\n const distance = Vector3.Distance(min, max);\n max.addToRef(min, this.center).scaleInPlace(0.5);\n this.radius = distance * 0.5;\n this._update(worldMatrix || Matrix.IdentityReadOnly);\n }\n /**\n * Scale the current bounding sphere by applying a scale factor\n * @param factor defines the scale factor to apply\n * @returns the current bounding box\n */\n scale(factor) {\n const newRadius = this.radius * factor;\n const tmpVectors = BoundingSphere._TmpVector3;\n const tempRadiusVector = tmpVectors[0].setAll(newRadius);\n const min = this.center.subtractToRef(tempRadiusVector, tmpVectors[1]);\n const max = this.center.addToRef(tempRadiusVector, tmpVectors[2]);\n this.reConstruct(min, max, this._worldMatrix);\n return this;\n }\n /**\n * Gets the world matrix of the bounding box\n * @returns a matrix\n */\n getWorldMatrix() {\n return this._worldMatrix;\n }\n // Methods\n /**\n * @internal\n */\n _update(worldMatrix) {\n if (!worldMatrix.isIdentity()) {\n Vector3.TransformCoordinatesToRef(this.center, worldMatrix, this.centerWorld);\n const tempVector = BoundingSphere._TmpVector3[0];\n Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, worldMatrix, tempVector);\n this.radiusWorld = Math.max(Math.abs(tempVector.x), Math.abs(tempVector.y), Math.abs(tempVector.z)) * this.radius;\n } else {\n this.centerWorld.copyFrom(this.center);\n this.radiusWorld = this.radius;\n }\n }\n /**\n * Tests if the bounding sphere is intersecting the frustum planes\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if there is an intersection\n */\n isInFrustum(frustumPlanes) {\n const center = this.centerWorld;\n const radius = this.radiusWorld;\n for (let i = 0; i < 6; i++) {\n if (frustumPlanes[i].dotCoordinate(center) <= -radius) {\n return false;\n }\n }\n return true;\n }\n /**\n * Tests if the bounding sphere center is in between the frustum planes.\n * Used for optimistic fast inclusion.\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if the sphere center is in between the frustum planes\n */\n isCenterInFrustum(frustumPlanes) {\n const center = this.centerWorld;\n for (let i = 0; i < 6; i++) {\n if (frustumPlanes[i].dotCoordinate(center) < 0) {\n return false;\n }\n }\n return true;\n }\n /**\n * Tests if a point is inside the bounding sphere\n * @param point defines the point to test\n * @returns true if the point is inside the bounding sphere\n */\n intersectsPoint(point) {\n const squareDistance = Vector3.DistanceSquared(this.centerWorld, point);\n if (this.radiusWorld * this.radiusWorld < squareDistance) {\n return false;\n }\n return true;\n }\n // Statics\n /**\n * Checks if two sphere intersect\n * @param sphere0 sphere 0\n * @param sphere1 sphere 1\n * @returns true if the spheres intersect\n */\n static Intersects(sphere0, sphere1) {\n const squareDistance = Vector3.DistanceSquared(sphere0.centerWorld, sphere1.centerWorld);\n const radiusSum = sphere0.radiusWorld + sphere1.radiusWorld;\n if (radiusSum * radiusSum < squareDistance) {\n return false;\n }\n return true;\n }\n /**\n * Creates a sphere from a center and a radius\n * @param center The center\n * @param radius radius\n * @param matrix Optional worldMatrix\n * @returns The sphere\n */\n static CreateFromCenterAndRadius(center, radius, matrix) {\n this._TmpVector3[0].copyFrom(center);\n this._TmpVector3[1].copyFromFloats(0, 0, radius);\n this._TmpVector3[2].copyFrom(center);\n this._TmpVector3[0].addInPlace(this._TmpVector3[1]);\n this._TmpVector3[2].subtractInPlace(this._TmpVector3[1]);\n const sphere = new BoundingSphere(this._TmpVector3[0], this._TmpVector3[2]);\n if (matrix) {\n sphere._worldMatrix = matrix;\n } else {\n sphere._worldMatrix = Matrix.Identity();\n }\n return sphere;\n }\n}\nBoundingSphere._TmpVector3 = BuildArray(3, Vector3.Zero);","map":{"version":3,"names":["BuildArray","Matrix","Vector3","BoundingSphere","constructor","min","max","worldMatrix","center","Zero","centerWorld","minimum","maximum","reConstruct","copyFrom","distance","Distance","addToRef","scaleInPlace","radius","_update","IdentityReadOnly","scale","factor","newRadius","tmpVectors","_TmpVector3","tempRadiusVector","setAll","subtractToRef","_worldMatrix","getWorldMatrix","isIdentity","TransformCoordinatesToRef","tempVector","TransformNormalFromFloatsToRef","radiusWorld","Math","abs","x","y","z","isInFrustum","frustumPlanes","i","dotCoordinate","isCenterInFrustum","intersectsPoint","point","squareDistance","DistanceSquared","Intersects","sphere0","sphere1","radiusSum","CreateFromCenterAndRadius","matrix","copyFromFloats","addInPlace","subtractInPlace","sphere","Identity"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Culling/boundingSphere.js"],"sourcesContent":["import { BuildArray } from \"../Misc/arrayTools.js\";\nimport { Matrix, Vector3 } from \"../Maths/math.vector.js\";\n/**\n * Class used to store bounding sphere information\n */\nexport class BoundingSphere {\n /**\n * Creates a new bounding sphere\n * @param min defines the minimum vector (in local space)\n * @param max defines the maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n constructor(min, max, worldMatrix) {\n /**\n * Gets the center of the bounding sphere in local space\n */\n this.center = Vector3.Zero();\n /**\n * Gets the center of the bounding sphere in world space\n */\n this.centerWorld = Vector3.Zero();\n /**\n * Gets the minimum vector in local space\n */\n this.minimum = Vector3.Zero();\n /**\n * Gets the maximum vector in local space\n */\n this.maximum = Vector3.Zero();\n this.reConstruct(min, max, worldMatrix);\n }\n /**\n * Recreates the entire bounding sphere from scratch as if we call the constructor in place\n * @param min defines the new minimum vector (in local space)\n * @param max defines the new maximum vector (in local space)\n * @param worldMatrix defines the new world matrix\n */\n reConstruct(min, max, worldMatrix) {\n this.minimum.copyFrom(min);\n this.maximum.copyFrom(max);\n const distance = Vector3.Distance(min, max);\n max.addToRef(min, this.center).scaleInPlace(0.5);\n this.radius = distance * 0.5;\n this._update(worldMatrix || Matrix.IdentityReadOnly);\n }\n /**\n * Scale the current bounding sphere by applying a scale factor\n * @param factor defines the scale factor to apply\n * @returns the current bounding box\n */\n scale(factor) {\n const newRadius = this.radius * factor;\n const tmpVectors = BoundingSphere._TmpVector3;\n const tempRadiusVector = tmpVectors[0].setAll(newRadius);\n const min = this.center.subtractToRef(tempRadiusVector, tmpVectors[1]);\n const max = this.center.addToRef(tempRadiusVector, tmpVectors[2]);\n this.reConstruct(min, max, this._worldMatrix);\n return this;\n }\n /**\n * Gets the world matrix of the bounding box\n * @returns a matrix\n */\n getWorldMatrix() {\n return this._worldMatrix;\n }\n // Methods\n /**\n * @internal\n */\n _update(worldMatrix) {\n if (!worldMatrix.isIdentity()) {\n Vector3.TransformCoordinatesToRef(this.center, worldMatrix, this.centerWorld);\n const tempVector = BoundingSphere._TmpVector3[0];\n Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, worldMatrix, tempVector);\n this.radiusWorld = Math.max(Math.abs(tempVector.x), Math.abs(tempVector.y), Math.abs(tempVector.z)) * this.radius;\n }\n else {\n this.centerWorld.copyFrom(this.center);\n this.radiusWorld = this.radius;\n }\n }\n /**\n * Tests if the bounding sphere is intersecting the frustum planes\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if there is an intersection\n */\n isInFrustum(frustumPlanes) {\n const center = this.centerWorld;\n const radius = this.radiusWorld;\n for (let i = 0; i < 6; i++) {\n if (frustumPlanes[i].dotCoordinate(center) <= -radius) {\n return false;\n }\n }\n return true;\n }\n /**\n * Tests if the bounding sphere center is in between the frustum planes.\n * Used for optimistic fast inclusion.\n * @param frustumPlanes defines the frustum planes to test\n * @returns true if the sphere center is in between the frustum planes\n */\n isCenterInFrustum(frustumPlanes) {\n const center = this.centerWorld;\n for (let i = 0; i < 6; i++) {\n if (frustumPlanes[i].dotCoordinate(center) < 0) {\n return false;\n }\n }\n return true;\n }\n /**\n * Tests if a point is inside the bounding sphere\n * @param point defines the point to test\n * @returns true if the point is inside the bounding sphere\n */\n intersectsPoint(point) {\n const squareDistance = Vector3.DistanceSquared(this.centerWorld, point);\n if (this.radiusWorld * this.radiusWorld < squareDistance) {\n return false;\n }\n return true;\n }\n // Statics\n /**\n * Checks if two sphere intersect\n * @param sphere0 sphere 0\n * @param sphere1 sphere 1\n * @returns true if the spheres intersect\n */\n static Intersects(sphere0, sphere1) {\n const squareDistance = Vector3.DistanceSquared(sphere0.centerWorld, sphere1.centerWorld);\n const radiusSum = sphere0.radiusWorld + sphere1.radiusWorld;\n if (radiusSum * radiusSum < squareDistance) {\n return false;\n }\n return true;\n }\n /**\n * Creates a sphere from a center and a radius\n * @param center The center\n * @param radius radius\n * @param matrix Optional worldMatrix\n * @returns The sphere\n */\n static CreateFromCenterAndRadius(center, radius, matrix) {\n this._TmpVector3[0].copyFrom(center);\n this._TmpVector3[1].copyFromFloats(0, 0, radius);\n this._TmpVector3[2].copyFrom(center);\n this._TmpVector3[0].addInPlace(this._TmpVector3[1]);\n this._TmpVector3[2].subtractInPlace(this._TmpVector3[1]);\n const sphere = new BoundingSphere(this._TmpVector3[0], this._TmpVector3[2]);\n if (matrix) {\n sphere._worldMatrix = matrix;\n }\n else {\n sphere._worldMatrix = Matrix.Identity();\n }\n return sphere;\n }\n}\nBoundingSphere._TmpVector3 = BuildArray(3, Vector3.Zero);\n"],"mappings":"AAAA,SAASA,UAAU,QA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