All files / engine/Source/DataSources PolylineVolumeGeometryUpdater.js

100% Statements 67/67
92.85% Branches 39/42
100% Functions 10/10
100% Lines 67/67

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                                    1x     67x 67x 67x 67x 67x 67x                         67x               67x               1x 1x     1x                       1x       15x   14x 1x           13x 13x         13x             13x   13x     13x   12x       12x   12x 1x   12x 12x           1x           13x                             1x     13x   12x 1x           11x 11x 11x             11x   11x                                     1x       37x             1x       35x                 1x       23x 23x   23x   23x 23x     23x       23x       23x     23x         1x                     5x               1x 1x     1x       1x         8x 8x                       1x         8x 8x         8x       8x       8x            
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 DeveloperError from "../Core/DeveloperError.js";
import DistanceDisplayConditionGeometryInstanceAttribute from "../Core/DistanceDisplayConditionGeometryInstanceAttribute.js";
import GeometryInstance from "../Core/GeometryInstance.js";
import Iso8601 from "../Core/Iso8601.js";
import PolylineVolumeGeometry from "../Core/PolylineVolumeGeometry.js";
import PolylineVolumeOutlineGeometry from "../Core/PolylineVolumeOutlineGeometry.js";
import ShowGeometryInstanceAttribute from "../Core/ShowGeometryInstanceAttribute.js";
import MaterialAppearance from "../Scene/MaterialAppearance.js";
import PerInstanceColorAppearance from "../Scene/PerInstanceColorAppearance.js";
import ColorMaterialProperty from "./ColorMaterialProperty.js";
import DynamicGeometryUpdater from "./DynamicGeometryUpdater.js";
import GeometryUpdater from "./GeometryUpdater.js";
import Property from "./Property.js";
 
const scratchColor = new Color();
 
function PolylineVolumeGeometryOptions(entity) {
  this.id = entity;
  this.vertexFormat = undefined;
  this.polylinePositions = undefined;
  this.shapePositions = undefined;
  this.cornerType = undefined;
  this.granularity = undefined;
}
 
/**
 * A {@link GeometryUpdater} for polyline volumes.
 * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
 * @alias PolylineVolumeGeometryUpdater
 * @constructor
 *
 * @param {Entity} entity The entity containing the geometry to be visualized.
 * @param {Scene} scene The scene where visualization is taking place.
 */
function PolylineVolumeGeometryUpdater(entity, scene) {
  GeometryUpdater.call(this, {
    entity: entity,
    scene: scene,
    geometryOptions: new PolylineVolumeGeometryOptions(entity),
    geometryPropertyName: "polylineVolume",
    observedPropertyNames: ["availability", "polylineVolume"],
  });
 
  this._onEntityPropertyChanged(
    entity,
    "polylineVolume",
    entity.polylineVolume,
    undefined,
  );
}
 
Eif (defined(Object.create)) {
  PolylineVolumeGeometryUpdater.prototype = Object.create(
    GeometryUpdater.prototype,
  );
  PolylineVolumeGeometryUpdater.prototype.constructor =
    PolylineVolumeGeometryUpdater;
}
 
/**
 * Creates the geometry instance which represents the fill of the geometry.
 *
 * @param {JulianDate} time The time to use when retrieving initial attribute values.
 * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
 *
 * @exception {DeveloperError} This instance does not represent a filled geometry.
 */
PolylineVolumeGeometryUpdater.prototype.createFillGeometryInstance = function (
  time,
) {
  //>>includeStart('debug', pragmas.debug);
  Check.defined("time", time);
 
  if (!this._fillEnabled) {
    throw new DeveloperError(
      "This instance does not represent a filled geometry.",
    );
  }
  //>>includeEnd('debug');
 
  const entity = this._entity;
  const isAvailable = entity.isAvailable(time);
 
  let attributes;
 
  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,
    );
  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 = {
      show: show,
      distanceDisplayCondition: distanceDisplayConditionAttribute,
      color: color,
    };
  } else {
    attributes = {
      show: show,
      distanceDisplayCondition: distanceDisplayConditionAttribute,
    };
  }
 
  return new GeometryInstance({
    id: entity,
    geometry: new PolylineVolumeGeometry(this._options),
    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.
 * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
 *
 * @exception {DeveloperError} This instance does not represent an outlined geometry.
 */
PolylineVolumeGeometryUpdater.prototype.createOutlineGeometryInstance =
  function (time) {
    //>>includeStart('debug', pragmas.debug);
    Check.defined("time", time);
 
    if (!this._outlineEnabled) {
      throw new DeveloperError(
        "This instance does not represent an outlined geometry.",
      );
    }
    //>>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);
 
    return new GeometryInstance({
      id: entity,
      geometry: new PolylineVolumeOutlineGeometry(this._options),
      attributes: {
        show: new ShowGeometryInstanceAttribute(
          isAvailable &&
            entity.isShowing &&
            this._showProperty.getValue(time) &&
            this._showOutlineProperty.getValue(time),
        ),
        color: ColorGeometryInstanceAttribute.fromColor(outlineColor),
        distanceDisplayCondition:
          DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
            distanceDisplayCondition,
          ),
      },
    });
  };
 
PolylineVolumeGeometryUpdater.prototype._isHidden = function (
  entity,
  polylineVolume,
) {
  return (
    !defined(polylineVolume.positions) ||
    !defined(polylineVolume.shape) ||
    GeometryUpdater.prototype._isHidden.call(this, entity, polylineVolume)
  );
};
 
PolylineVolumeGeometryUpdater.prototype._isDynamic = function (
  entity,
  polylineVolume,
) {
  return (
    !polylineVolume.positions.isConstant || //
    !polylineVolume.shape.isConstant || //
    !Property.isConstant(polylineVolume.granularity) || //
    !Property.isConstant(polylineVolume.outlineWidth) || //
    !Property.isConstant(polylineVolume.cornerType)
  );
};
 
PolylineVolumeGeometryUpdater.prototype._setStaticOptions = function (
  entity,
  polylineVolume,
) {
  const granularity = polylineVolume.granularity;
  const cornerType = polylineVolume.cornerType;
 
  const options = this._options;
  const isColorMaterial =
    this._materialProperty instanceof ColorMaterialProperty;
  options.vertexFormat = isColorMaterial
    ? PerInstanceColorAppearance.VERTEX_FORMAT
    : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  options.polylinePositions = polylineVolume.positions.getValue(
    Iso8601.MINIMUM_VALUE,
    options.polylinePositions,
  );
  options.shapePositions = polylineVolume.shape.getValue(
    Iso8601.MINIMUM_VALUE,
    options.shape,
  );
  options.granularity = defined(granularity)
    ? granularity.getValue(Iso8601.MINIMUM_VALUE)
    : undefined;
  options.cornerType = defined(cornerType)
    ? cornerType.getValue(Iso8601.MINIMUM_VALUE)
    : undefined;
};
 
PolylineVolumeGeometryUpdater.DynamicGeometryUpdater =
  DynamicPolylineVolumeGeometryUpdater;
 
/**
 * @private
 */
function DynamicPolylineVolumeGeometryUpdater(
  geometryUpdater,
  primitives,
  groundPrimitives,
) {
  DynamicGeometryUpdater.call(
    this,
    geometryUpdater,
    primitives,
    groundPrimitives,
  );
}
 
Eif (defined(Object.create)) {
  DynamicPolylineVolumeGeometryUpdater.prototype = Object.create(
    DynamicGeometryUpdater.prototype,
  );
  DynamicPolylineVolumeGeometryUpdater.prototype.constructor =
    DynamicPolylineVolumeGeometryUpdater;
}
 
DynamicPolylineVolumeGeometryUpdater.prototype._isHidden = function (
  entity,
  polylineVolume,
  time,
) {
  const options = this._options;
  return (
    !defined(options.polylinePositions) ||
    !defined(options.shapePositions) ||
    DynamicGeometryUpdater.prototype._isHidden.call(
      this,
      entity,
      polylineVolume,
      time,
    )
  );
};
 
DynamicPolylineVolumeGeometryUpdater.prototype._setOptions = function (
  entity,
  polylineVolume,
  time,
) {
  const options = this._options;
  options.polylinePositions = Property.getValueOrUndefined(
    polylineVolume.positions,
    time,
    options.polylinePositions,
  );
  options.shapePositions = Property.getValueOrUndefined(
    polylineVolume.shape,
    time,
  );
  options.granularity = Property.getValueOrUndefined(
    polylineVolume.granularity,
    time,
  );
  options.cornerType = Property.getValueOrUndefined(
    polylineVolume.cornerType,
    time,
  );
};
export default PolylineVolumeGeometryUpdater;