All files / engine/Source/DataSources EllipsoidGeometryUpdater.js

97.04% Statements 197/203
88.49% Branches 100/113
100% Functions 11/11
97.04% Lines 197/203

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711                                                      1x 1x   1x 1x 1x 1x 1x     77x 77x 77x 77x 77x 77x 77x 77x 77x 77x 77x 77x                         77x                         77x               1x 1x 1x     1x                   9x                             1x           21x     20x 20x     20x             20x   20x       20x             20x   19x       19x   19x 1x   19x 19x   20x 3x                   20x                                                   1x           19x     18x 18x   18x             18x   18x                           18x 3x                   18x                               1x 7x     1x 66x             1x 64x                               1x       37x         37x 37x       37x       37x       37x       37x       37x       37x       37x       37x       37x       37x           1x     1x                     8x             8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x     1x 1x     1x       1x   12x     12x 12x 12x         1x 1x     1x 1x   1x     11x         11x                 11x 2x 2x     2x 2x   2x       9x 9x         9x           9x             9x         9x       9x       9x 9x 9x       9x       9x       9x         9x           9x           9x   9x   9x   9x     9x   9x   9x                   9x                             9x 7x 7x 7x 7x 7x 7x 7x   7x 7x 7x 7x 7x 7x 2x 1x             1x     5x   7x 7x 7x 7x   7x         7x   7x           7x                 7x         7x                               7x 7x 7x 7x 7x 2x   2x 2x   2x 2x 2x   2x 2x 2x 2x   2x 1x       1x     2x   2x 2x   2x     2x 1x       1x     2x 1x       1x     2x                                           2x                         9x       8x 8x 8x   8x 8x 8x        
import Cartesian3 from "../Core/Cartesian3.js";
import Check from "../Core/Check.js";
import Color from "../Core/Color.js";
import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js";
import defined from "../Core/defined.js";
import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
import DistanceDisplayConditionGeometryInstanceAttribute from "../Core/DistanceDisplayConditionGeometryInstanceAttribute.js";
import EllipsoidGeometry from "../Core/EllipsoidGeometry.js";
import EllipsoidOutlineGeometry from "../Core/EllipsoidOutlineGeometry.js";
import GeometryInstance from "../Core/GeometryInstance.js";
import GeometryOffsetAttribute from "../Core/GeometryOffsetAttribute.js";
import Iso8601 from "../Core/Iso8601.js";
import Matrix4 from "../Core/Matrix4.js";
import OffsetGeometryInstanceAttribute from "../Core/OffsetGeometryInstanceAttribute.js";
import ShowGeometryInstanceAttribute from "../Core/ShowGeometryInstanceAttribute.js";
import HeightReference from "../Scene/HeightReference.js";
import MaterialAppearance from "../Scene/MaterialAppearance.js";
import PerInstanceColorAppearance from "../Scene/PerInstanceColorAppearance.js";
import Primitive from "../Scene/Primitive.js";
import SceneMode from "../Scene/SceneMode.js";
import ColorMaterialProperty from "./ColorMaterialProperty.js";
import DynamicGeometryUpdater from "./DynamicGeometryUpdater.js";
import GeometryUpdater from "./GeometryUpdater.js";
import heightReferenceOnEntityPropertyChanged from "./heightReferenceOnEntityPropertyChanged.js";
import MaterialProperty from "./MaterialProperty.js";
import Property from "./Property.js";
 
const defaultMaterial = new ColorMaterialProperty(Color.WHITE);
const defaultOffset = Cartesian3.ZERO;
 
const offsetScratch = new Cartesian3();
const radiiScratch = new Cartesian3();
const innerRadiiScratch = new Cartesian3();
const scratchColor = new Color();
const unitSphere = new Cartesian3(1, 1, 1);
 
function EllipsoidGeometryOptions(entity) {
  this.id = entity;
  this.vertexFormat = undefined;
  this.radii = undefined;
  this.innerRadii = undefined;
  this.minimumClock = undefined;
  this.maximumClock = undefined;
  this.minimumCone = undefined;
  this.maximumCone = undefined;
  this.stackPartitions = undefined;
  this.slicePartitions = undefined;
  this.subdivisions = undefined;
  this.offsetAttribute = undefined;
}
 
/**
 * A {@link GeometryUpdater} for ellipsoids.
 * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
 * @alias EllipsoidGeometryUpdater
 * @constructor
 *
 * @param {Entity} entity The entity containing the geometry to be visualized.
 * @param {Scene} scene The scene where visualization is taking place.
 */
function EllipsoidGeometryUpdater(entity, scene) {
  GeometryUpdater.call(this, {
    entity: entity,
    scene: scene,
    geometryOptions: new EllipsoidGeometryOptions(entity),
    geometryPropertyName: "ellipsoid",
    observedPropertyNames: [
      "availability",
      "position",
      "orientation",
      "ellipsoid",
    ],
  });
 
  this._onEntityPropertyChanged(
    entity,
    "ellipsoid",
    entity.ellipsoid,
    undefined,
  );
}
 
Eif (defined(Object.create)) {
  EllipsoidGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);
  EllipsoidGeometryUpdater.prototype.constructor = EllipsoidGeometryUpdater;
}
 
Object.defineProperties(EllipsoidGeometryUpdater.prototype, {
  /**
   * Gets the terrain offset property
   * @type {TerrainOffsetProperty}
   * @memberof EllipsoidGeometryUpdater.prototype
   * @readonly
   * @private
   */
  terrainOffsetProperty: {
    get: function () {
      return this._terrainOffsetProperty;
    },
  },
});
 
/**
 * Creates the geometry instance which represents the fill of the geometry.
 *
 * @param {JulianDate} time The time to use when retrieving initial attribute values.
 * @param {boolean} [skipModelMatrix=false] Whether to compute a model matrix for the geometry instance
 * @param {Matrix4} [modelMatrixResult] Used to store the result of the model matrix calculation
 * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
 *
 * @exception {DeveloperError} This instance does not represent a filled geometry.
 */
EllipsoidGeometryUpdater.prototype.createFillGeometryInstance = function (
  time,
  skipModelMatrix,
  modelMatrixResult,
) {
  //>>includeStart('debug', pragmas.debug);
  Check.defined("time", time);
  //>>includeEnd('debug');
 
  const entity = this._entity;
  const isAvailable = entity.isAvailable(time);
 
  let color;
  const show = new ShowGeometryInstanceAttribute(
    isAvailable &&
      entity.isShowing &&
      this._showProperty.getValue(time) &&
      this._fillProperty.getValue(time),
  );
  const distanceDisplayCondition =
    this._distanceDisplayConditionProperty.getValue(time);
  const distanceDisplayConditionAttribute =
    DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
      distanceDisplayCondition,
    );
 
  const attributes = {
    show: show,
    distanceDisplayCondition: distanceDisplayConditionAttribute,
    color: undefined,
    offset: undefined,
  };
 
  if (this._materialProperty instanceof ColorMaterialProperty) {
    let currentColor;
    Eif (
      defined(this._materialProperty.color) &&
      (this._materialProperty.color.isConstant || isAvailable)
    ) {
      currentColor = this._materialProperty.color.getValue(time, scratchColor);
    }
    if (!defined(currentColor)) {
      currentColor = Color.WHITE;
    }
    color = ColorGeometryInstanceAttribute.fromColor(currentColor);
    attributes.color = color;
  }
  if (defined(this._options.offsetAttribute)) {
    attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(
      Property.getValueOrDefault(
        this._terrainOffsetProperty,
        time,
        defaultOffset,
        offsetScratch,
      ),
    );
  }
 
  return new GeometryInstance({
    id: entity,
    geometry: new EllipsoidGeometry(this._options),
    modelMatrix: skipModelMatrix
      ? undefined
      : entity.computeModelMatrixForHeightReference(
          time,
          entity.ellipsoid.heightReference,
          this._options.radii.z * 0.5,
          this._scene.ellipsoid,
          modelMatrixResult,
        ),
    attributes: attributes,
  });
};
 
/**
 * Creates the geometry instance which represents the outline of the geometry.
 *
 * @param {JulianDate} time The time to use when retrieving initial attribute values.
 * @param {boolean} [skipModelMatrix=false] Whether to compute a model matrix for the geometry instance
 * @param {Matrix4} [modelMatrixResult] Used to store the result of the model matrix calculation
 * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
 *
 * @exception {DeveloperError} This instance does not represent an outlined geometry.
 */
EllipsoidGeometryUpdater.prototype.createOutlineGeometryInstance = function (
  time,
  skipModelMatrix,
  modelMatrixResult,
) {
  //>>includeStart('debug', pragmas.debug);
  Check.defined("time", time);
  //>>includeEnd('debug');
 
  const entity = this._entity;
  const isAvailable = entity.isAvailable(time);
 
  const outlineColor = Property.getValueOrDefault(
    this._outlineColorProperty,
    time,
    Color.BLACK,
    scratchColor,
  );
  const distanceDisplayCondition =
    this._distanceDisplayConditionProperty.getValue(time);
 
  const attributes = {
    show: new ShowGeometryInstanceAttribute(
      isAvailable &&
        entity.isShowing &&
        this._showProperty.getValue(time) &&
        this._showOutlineProperty.getValue(time),
    ),
    color: ColorGeometryInstanceAttribute.fromColor(outlineColor),
    distanceDisplayCondition:
      DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
        distanceDisplayCondition,
      ),
    offset: undefined,
  };
  if (defined(this._options.offsetAttribute)) {
    attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(
      Property.getValueOrDefault(
        this._terrainOffsetProperty,
        time,
        defaultOffset,
        offsetScratch,
      ),
    );
  }
 
  return new GeometryInstance({
    id: entity,
    geometry: new EllipsoidOutlineGeometry(this._options),
    modelMatrix: skipModelMatrix
      ? undefined
      : entity.computeModelMatrixForHeightReference(
          time,
          entity.ellipsoid.heightReference,
          this._options.radii.z * 0.5,
          this._scene.ellipsoid,
          modelMatrixResult,
        ),
    attributes: attributes,
  });
};
 
EllipsoidGeometryUpdater.prototype._computeCenter = function (time, result) {
  return Property.getValueOrUndefined(this._entity.position, time, result);
};
 
EllipsoidGeometryUpdater.prototype._isHidden = function (entity, ellipsoid) {
  return (
    !defined(entity.position) ||
    !defined(ellipsoid.radii) ||
    GeometryUpdater.prototype._isHidden.call(this, entity, ellipsoid)
  );
};
 
EllipsoidGeometryUpdater.prototype._isDynamic = function (entity, ellipsoid) {
  return (
    !entity.position.isConstant || //
    !Property.isConstant(entity.orientation) || //
    !ellipsoid.radii.isConstant || //
    !Property.isConstant(ellipsoid.innerRadii) || //
    !Property.isConstant(ellipsoid.stackPartitions) || //
    !Property.isConstant(ellipsoid.slicePartitions) || //
    !Property.isConstant(ellipsoid.outlineWidth) || //
    !Property.isConstant(ellipsoid.minimumClock) || //
    !Property.isConstant(ellipsoid.maximumClock) || //
    !Property.isConstant(ellipsoid.minimumCone) || //
    !Property.isConstant(ellipsoid.maximumCone) || //
    !Property.isConstant(ellipsoid.subdivisions)
  );
};
 
EllipsoidGeometryUpdater.prototype._setStaticOptions = function (
  entity,
  ellipsoid,
) {
  const heightReference = Property.getValueOrDefault(
    ellipsoid.heightReference,
    Iso8601.MINIMUM_VALUE,
    HeightReference.NONE,
  );
  const options = this._options;
  options.vertexFormat =
    this._materialProperty instanceof ColorMaterialProperty
      ? PerInstanceColorAppearance.VERTEX_FORMAT
      : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  options.radii = ellipsoid.radii.getValue(
    Iso8601.MINIMUM_VALUE,
    options.radii,
  );
  options.innerRadii = Property.getValueOrUndefined(
    ellipsoid.innerRadii,
    options.radii,
  );
  options.minimumClock = Property.getValueOrUndefined(
    ellipsoid.minimumClock,
    Iso8601.MINIMUM_VALUE,
  );
  options.maximumClock = Property.getValueOrUndefined(
    ellipsoid.maximumClock,
    Iso8601.MINIMUM_VALUE,
  );
  options.minimumCone = Property.getValueOrUndefined(
    ellipsoid.minimumCone,
    Iso8601.MINIMUM_VALUE,
  );
  options.maximumCone = Property.getValueOrUndefined(
    ellipsoid.maximumCone,
    Iso8601.MINIMUM_VALUE,
  );
  options.stackPartitions = Property.getValueOrUndefined(
    ellipsoid.stackPartitions,
    Iso8601.MINIMUM_VALUE,
  );
  options.slicePartitions = Property.getValueOrUndefined(
    ellipsoid.slicePartitions,
    Iso8601.MINIMUM_VALUE,
  );
  options.subdivisions = Property.getValueOrUndefined(
    ellipsoid.subdivisions,
    Iso8601.MINIMUM_VALUE,
  );
  options.offsetAttribute =
    heightReference !== HeightReference.NONE
      ? GeometryOffsetAttribute.ALL
      : undefined;
};
 
EllipsoidGeometryUpdater.prototype._onEntityPropertyChanged =
  heightReferenceOnEntityPropertyChanged;
 
EllipsoidGeometryUpdater.DynamicGeometryUpdater =
  DynamicEllipsoidGeometryUpdater;
 
/**
 * @private
 */
function DynamicEllipsoidGeometryUpdater(
  geometryUpdater,
  primitives,
  groundPrimitives,
) {
  DynamicGeometryUpdater.call(
    this,
    geometryUpdater,
    primitives,
    groundPrimitives,
  );
 
  this._scene = geometryUpdater._scene;
  this._modelMatrix = new Matrix4();
  this._attributes = undefined;
  this._outlineAttributes = undefined;
  this._lastSceneMode = undefined;
  this._lastShow = undefined;
  this._lastOutlineShow = undefined;
  this._lastOutlineWidth = undefined;
  this._lastOutlineColor = undefined;
  this._lastOffset = new Cartesian3();
  this._material = {};
}
 
Eif (defined(Object.create)) {
  DynamicEllipsoidGeometryUpdater.prototype = Object.create(
    DynamicGeometryUpdater.prototype,
  );
  DynamicEllipsoidGeometryUpdater.prototype.constructor =
    DynamicEllipsoidGeometryUpdater;
}
 
DynamicEllipsoidGeometryUpdater.prototype.update = function (time) {
  //>>includeStart('debug', pragmas.debug);
  Check.defined("time", time);
  //>>includeEnd('debug');
 
  const entity = this._entity;
  const ellipsoid = entity.ellipsoid;
  if (
    !entity.isShowing ||
    !entity.isAvailable(time) ||
    !Property.getValueOrDefault(ellipsoid.show, time, true)
  ) {
    Eif (defined(this._primitive)) {
      this._primitive.show = false;
    }
 
    Eif (defined(this._outlinePrimitive)) {
      this._outlinePrimitive.show = false;
    }
    return;
  }
 
  const radii = Property.getValueOrUndefined(
    ellipsoid.radii,
    time,
    radiiScratch,
  );
  let modelMatrix = defined(radii)
    ? entity.computeModelMatrixForHeightReference(
        time,
        ellipsoid.heightReference,
        radii.z * 0.5,
        this._scene.ellipsoid,
        this._modelMatrix,
      )
    : undefined;
  if (!defined(modelMatrix) || !defined(radii)) {
    Eif (defined(this._primitive)) {
      this._primitive.show = false;
    }
 
    Eif (defined(this._outlinePrimitive)) {
      this._outlinePrimitive.show = false;
    }
    return;
  }
 
  //Compute attributes and material.
  const showFill = Property.getValueOrDefault(ellipsoid.fill, time, true);
  const showOutline = Property.getValueOrDefault(
    ellipsoid.outline,
    time,
    false,
  );
  const outlineColor = Property.getValueOrClonedDefault(
    ellipsoid.outlineColor,
    time,
    Color.BLACK,
    scratchColor,
  );
  const material = MaterialProperty.getValue(
    time,
    ellipsoid.material ?? defaultMaterial,
    this._material,
  );
 
  // Check properties that could trigger a primitive rebuild.
  const innerRadii = Property.getValueOrUndefined(
    ellipsoid.innerRadii,
    time,
    innerRadiiScratch,
  );
  const minimumClock = Property.getValueOrUndefined(
    ellipsoid.minimumClock,
    time,
  );
  const maximumClock = Property.getValueOrUndefined(
    ellipsoid.maximumClock,
    time,
  );
  const minimumCone = Property.getValueOrUndefined(ellipsoid.minimumCone, time);
  const maximumCone = Property.getValueOrUndefined(ellipsoid.maximumCone, time);
  const stackPartitions = Property.getValueOrUndefined(
    ellipsoid.stackPartitions,
    time,
  );
  const slicePartitions = Property.getValueOrUndefined(
    ellipsoid.slicePartitions,
    time,
  );
  const subdivisions = Property.getValueOrUndefined(
    ellipsoid.subdivisions,
    time,
  );
  const outlineWidth = Property.getValueOrDefault(
    ellipsoid.outlineWidth,
    time,
    1.0,
  );
  const heightReference = Property.getValueOrDefault(
    ellipsoid.heightReference,
    time,
    HeightReference.NONE,
  );
  const offsetAttribute =
    heightReference !== HeightReference.NONE
      ? GeometryOffsetAttribute.ALL
      : undefined;
 
  //In 3D we use a fast path by modifying Primitive.modelMatrix instead of regenerating the primitive every frame.
  //Also check for height reference because this method doesn't work when the height is relative to terrain.
  const sceneMode = this._scene.mode;
  const in3D =
    sceneMode === SceneMode.SCENE3D && heightReference === HeightReference.NONE;
 
  const options = this._options;
 
  const shadows = this._geometryUpdater.shadowsProperty.getValue(time);
 
  const distanceDisplayConditionProperty =
    this._geometryUpdater.distanceDisplayConditionProperty;
  const distanceDisplayCondition =
    distanceDisplayConditionProperty.getValue(time);
 
  const offset = Property.getValueOrDefault(
    this._geometryUpdater.terrainOffsetProperty,
    time,
    defaultOffset,
    offsetScratch,
  );
 
  //We only rebuild the primitive if something other than the radii has changed
  //For the radii, we use unit sphere and then deform it with a scale matrix.
  const rebuildPrimitives =
    !in3D ||
    this._lastSceneMode !== sceneMode ||
    !defined(this._primitive) || //
    options.stackPartitions !== stackPartitions ||
    options.slicePartitions !== slicePartitions || //
    (defined(innerRadii) &&
      !Cartesian3.equals(options.innerRadii !== innerRadii)) ||
    options.minimumClock !== minimumClock || //
    options.maximumClock !== maximumClock ||
    options.minimumCone !== minimumCone || //
    options.maximumCone !== maximumCone ||
    options.subdivisions !== subdivisions || //
    this._lastOutlineWidth !== outlineWidth ||
    options.offsetAttribute !== offsetAttribute;
 
  if (rebuildPrimitives) {
    const primitives = this._primitives;
    primitives.removeAndDestroy(this._primitive);
    primitives.removeAndDestroy(this._outlinePrimitive);
    this._primitive = undefined;
    this._outlinePrimitive = undefined;
    this._lastSceneMode = sceneMode;
    this._lastOutlineWidth = outlineWidth;
 
    options.stackPartitions = stackPartitions;
    options.slicePartitions = slicePartitions;
    options.subdivisions = subdivisions;
    options.offsetAttribute = offsetAttribute;
    options.radii = Cartesian3.clone(in3D ? unitSphere : radii, options.radii);
    if (defined(innerRadii)) {
      if (in3D) {
        options.innerRadii = Cartesian3.fromElements(
          innerRadii.x / radii.x,
          innerRadii.y / radii.y,
          innerRadii.z / radii.z,
          options.innerRadii,
        );
      } else {
        options.innerRadii = Cartesian3.clone(innerRadii, options.innerRadii);
      }
    } else {
      options.innerRadii = undefined;
    }
    options.minimumClock = minimumClock;
    options.maximumClock = maximumClock;
    options.minimumCone = minimumCone;
    options.maximumCone = maximumCone;
 
    const appearance = new MaterialAppearance({
      material: material,
      translucent: material.isTranslucent(),
      closed: true,
    });
    options.vertexFormat = appearance.vertexFormat;
 
    const fillInstance = this._geometryUpdater.createFillGeometryInstance(
      time,
      in3D,
      this._modelMatrix,
    );
 
    this._primitive = primitives.add(
      new Primitive({
        geometryInstances: fillInstance,
        appearance: appearance,
        asynchronous: false,
        shadows: shadows,
      }),
    );
 
    const outlineInstance = this._geometryUpdater.createOutlineGeometryInstance(
      time,
      in3D,
      this._modelMatrix,
    );
    this._outlinePrimitive = primitives.add(
      new Primitive({
        geometryInstances: outlineInstance,
        appearance: new PerInstanceColorAppearance({
          flat: true,
          translucent: outlineInstance.attributes.color.value[3] !== 255,
          renderState: {
            lineWidth:
              this._geometryUpdater._scene.clampLineWidth(outlineWidth),
          },
        }),
        asynchronous: false,
        shadows: shadows,
      }),
    );
 
    this._lastShow = showFill;
    this._lastOutlineShow = showOutline;
    this._lastOutlineColor = Color.clone(outlineColor, this._lastOutlineColor);
    this._lastDistanceDisplayCondition = distanceDisplayCondition;
    this._lastOffset = Cartesian3.clone(offset, this._lastOffset);
  } else Eif (this._primitive.ready) {
    //Update attributes only.
    const primitive = this._primitive;
    const outlinePrimitive = this._outlinePrimitive;
 
    primitive.show = true;
    outlinePrimitive.show = true;
    primitive.appearance.material = material;
 
    let attributes = this._attributes;
    Eif (!defined(attributes)) {
      attributes = primitive.getGeometryInstanceAttributes(entity);
      this._attributes = attributes;
    }
    if (showFill !== this._lastShow) {
      attributes.show = ShowGeometryInstanceAttribute.toValue(
        showFill,
        attributes.show,
      );
      this._lastShow = showFill;
    }
 
    let outlineAttributes = this._outlineAttributes;
 
    Eif (!defined(outlineAttributes)) {
      outlineAttributes =
        outlinePrimitive.getGeometryInstanceAttributes(entity);
      this._outlineAttributes = outlineAttributes;
    }
 
    if (showOutline !== this._lastOutlineShow) {
      outlineAttributes.show = ShowGeometryInstanceAttribute.toValue(
        showOutline,
        outlineAttributes.show,
      );
      this._lastOutlineShow = showOutline;
    }
 
    if (!Color.equals(outlineColor, this._lastOutlineColor)) {
      outlineAttributes.color = ColorGeometryInstanceAttribute.toValue(
        outlineColor,
        outlineAttributes.color,
      );
      Color.clone(outlineColor, this._lastOutlineColor);
    }
 
    Iif (
      !DistanceDisplayCondition.equals(
        distanceDisplayCondition,
        this._lastDistanceDisplayCondition,
      )
    ) {
      attributes.distanceDisplayCondition =
        DistanceDisplayConditionGeometryInstanceAttribute.toValue(
          distanceDisplayCondition,
          attributes.distanceDisplayCondition,
        );
      outlineAttributes.distanceDisplayCondition =
        DistanceDisplayConditionGeometryInstanceAttribute.toValue(
          distanceDisplayCondition,
          outlineAttributes.distanceDisplayCondition,
        );
      DistanceDisplayCondition.clone(
        distanceDisplayCondition,
        this._lastDistanceDisplayCondition,
      );
    }
 
    Iif (!Cartesian3.equals(offset, this._lastOffset)) {
      attributes.offset = OffsetGeometryInstanceAttribute.toValue(
        offset,
        attributes.offset,
      );
      outlineAttributes.offset = OffsetGeometryInstanceAttribute.toValue(
        offset,
        attributes.offset,
      );
      Cartesian3.clone(offset, this._lastOffset);
    }
  }
 
  if (in3D) {
    //Since we are scaling a unit sphere, we can't let any of the values go to zero.
    //Instead we clamp them to a small value.  To the naked eye, this produces the same results
    //that you get passing EllipsoidGeometry a radii with a zero component.
    radii.x = Math.max(radii.x, 0.001);
    radii.y = Math.max(radii.y, 0.001);
    radii.z = Math.max(radii.z, 0.001);
 
    modelMatrix = Matrix4.multiplyByScale(modelMatrix, radii, modelMatrix);
    this._primitive.modelMatrix = modelMatrix;
    this._outlinePrimitive.modelMatrix = modelMatrix;
  }
};
export default EllipsoidGeometryUpdater;