123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import BoundingSphere from "../Core/BoundingSphere.js";
- import Cartesian3 from "../Core/Cartesian3.js";
- import Check from "../Core/Check.js";
- import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js";
- import GeometryInstance from "../Core/GeometryInstance.js";
- import CesiumMath from "../Core/Math.js";
- import Matrix4 from "../Core/Matrix4.js";
- import SphereOutlineGeometry from "../Core/SphereOutlineGeometry.js";
- import PerInstanceColorAppearance from "./PerInstanceColorAppearance.js";
- import Primitive from "./Primitive.js";
- function TileBoundingSphere(center, radius) {
- if (radius === 0) {
- radius = CesiumMath.EPSILON7;
- }
- this._boundingSphere = new BoundingSphere(center, radius);
- }
- Object.defineProperties(TileBoundingSphere.prototype, {
-
- center: {
- get: function () {
- return this._boundingSphere.center;
- },
- },
-
- radius: {
- get: function () {
- return this._boundingSphere.radius;
- },
- },
-
- boundingVolume: {
- get: function () {
- return this._boundingSphere;
- },
- },
-
- boundingSphere: {
- get: function () {
- return this._boundingSphere;
- },
- },
- });
- TileBoundingSphere.prototype.distanceToCamera = function (frameState) {
-
- Check.defined("frameState", frameState);
-
- var boundingSphere = this._boundingSphere;
- return Math.max(
- 0.0,
- Cartesian3.distance(boundingSphere.center, frameState.camera.positionWC) -
- boundingSphere.radius
- );
- };
- TileBoundingSphere.prototype.intersectPlane = function (plane) {
-
- Check.defined("plane", plane);
-
- return BoundingSphere.intersectPlane(this._boundingSphere, plane);
- };
- TileBoundingSphere.prototype.update = function (center, radius) {
- Cartesian3.clone(center, this._boundingSphere.center);
- this._boundingSphere.radius = radius;
- };
- TileBoundingSphere.prototype.createDebugVolume = function (color) {
-
- Check.defined("color", color);
-
- var geometry = new SphereOutlineGeometry({
- radius: this.radius,
- });
- var modelMatrix = Matrix4.fromTranslation(
- this.center,
- new Matrix4.clone(Matrix4.IDENTITY)
- );
- var instance = new GeometryInstance({
- geometry: geometry,
- id: "outline",
- modelMatrix: modelMatrix,
- attributes: {
- color: ColorGeometryInstanceAttribute.fromColor(color),
- },
- });
- return new Primitive({
- geometryInstances: instance,
- appearance: new PerInstanceColorAppearance({
- translucent: false,
- flat: true,
- }),
- asynchronous: false,
- });
- };
- export default TileBoundingSphere;
|