123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622 |
- /*global define*/
- define([
- '../Core/Color',
- '../Core/ColorGeometryInstanceAttribute',
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/destroyObject',
- '../Core/DeveloperError',
- '../Core/EllipseGeometry',
- '../Core/EllipseOutlineGeometry',
- '../Core/Event',
- '../Core/GeometryInstance',
- '../Core/Iso8601',
- '../Core/ShowGeometryInstanceAttribute',
- '../Scene/MaterialAppearance',
- '../Scene/PerInstanceColorAppearance',
- '../Scene/Primitive',
- './ColorMaterialProperty',
- './ConstantProperty',
- './MaterialProperty',
- './Property'
- ], function(
- Color,
- ColorGeometryInstanceAttribute,
- defaultValue,
- defined,
- defineProperties,
- destroyObject,
- DeveloperError,
- EllipseGeometry,
- EllipseOutlineGeometry,
- Event,
- GeometryInstance,
- Iso8601,
- ShowGeometryInstanceAttribute,
- MaterialAppearance,
- PerInstanceColorAppearance,
- Primitive,
- ColorMaterialProperty,
- ConstantProperty,
- MaterialProperty,
- Property) {
- "use strict";
- var defaultMaterial = ColorMaterialProperty.fromColor(Color.WHITE);
- var defaultShow = new ConstantProperty(true);
- var defaultFill = new ConstantProperty(true);
- var defaultOutline = new ConstantProperty(false);
- var defaultOutlineColor = new ConstantProperty(Color.BLACK);
- var scratchColor = new Color();
- var GeometryOptions = function(entity) {
- this.id = entity;
- this.vertexFormat = undefined;
- this.center = undefined;
- this.semiMajorAxis = undefined;
- this.semiMinorAxis = undefined;
- this.rotation = undefined;
- this.height = undefined;
- this.extrudedHeight = undefined;
- this.granularity = undefined;
- this.stRotation = undefined;
- this.numberOfVerticalLines = undefined;
- };
- /**
- * A {@link GeometryUpdater} for ellipses.
- * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
- * @alias EllipseGeometryUpdater
- * @constructor
- *
- * @param {Entity} entity The entity containing the geometry to be visualized.
- * @param {Scene} scene The scene where visualization is taking place.
- */
- var EllipseGeometryUpdater = function(entity, scene) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined(entity)) {
- throw new DeveloperError('entity is required');
- }
- if (!defined(scene)) {
- throw new DeveloperError('scene is required');
- }
- //>>includeEnd('debug');
- this._entity = entity;
- this._scene = scene;
- this._entitySubscription = entity.definitionChanged.addEventListener(EllipseGeometryUpdater.prototype._onEntityPropertyChanged, this);
- this._fillEnabled = false;
- this._isClosed = false;
- this._dynamic = false;
- this._outlineEnabled = false;
- this._geometryChanged = new Event();
- this._showProperty = undefined;
- this._materialProperty = undefined;
- this._hasConstantOutline = true;
- this._showOutlineProperty = undefined;
- this._outlineColorProperty = undefined;
- this._outlineWidth = 1.0;
- this._options = new GeometryOptions(entity);
- this._onEntityPropertyChanged(entity, 'ellipse', entity.ellipse, undefined);
- };
- defineProperties(EllipseGeometryUpdater, {
- /**
- * Gets the type of Appearance to use for simple color-based geometry.
- * @memberof EllipseGeometryUpdater
- * @type {Appearance}
- */
- perInstanceColorAppearanceType : {
- value : PerInstanceColorAppearance
- },
- /**
- * Gets the type of Appearance to use for material-based geometry.
- * @memberof EllipseGeometryUpdater
- * @type {Appearance}
- */
- materialAppearanceType : {
- value : MaterialAppearance
- }
- });
- defineProperties(EllipseGeometryUpdater.prototype, {
- /**
- * Gets the entity associated with this geometry.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Entity}
- * @readonly
- */
- entity : {
- get : function() {
- return this._entity;
- }
- },
- /**
- * Gets a value indicating if the geometry has a fill component.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Boolean}
- * @readonly
- */
- fillEnabled : {
- get : function() {
- return this._fillEnabled;
- }
- },
- /**
- * Gets a value indicating if fill visibility varies with simulation time.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Boolean}
- * @readonly
- */
- hasConstantFill : {
- get : function() {
- return !this._fillEnabled ||
- (!defined(this._entity.availability) &&
- Property.isConstant(this._showProperty) &&
- Property.isConstant(this._fillProperty));
- }
- },
- /**
- * Gets the material property used to fill the geometry.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {MaterialProperty}
- * @readonly
- */
- fillMaterialProperty : {
- get : function() {
- return this._materialProperty;
- }
- },
- /**
- * Gets a value indicating if the geometry has an outline component.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Boolean}
- * @readonly
- */
- outlineEnabled : {
- get : function() {
- return this._outlineEnabled;
- }
- },
- /**
- * Gets a value indicating if outline visibility varies with simulation time.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Boolean}
- * @readonly
- */
- hasConstantOutline : {
- get : function() {
- return !this._outlineEnabled ||
- (!defined(this._entity.availability) &&
- Property.isConstant(this._showProperty) &&
- Property.isConstant(this._showOutlineProperty));
- }
- },
- /**
- * Gets the {@link Color} property for the geometry outline.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Property}
- * @readonly
- */
- outlineColorProperty : {
- get : function() {
- return this._outlineColorProperty;
- }
- },
- /**
- * Gets the constant with of the geometry outline, in pixels.
- * This value is only valid if isDynamic is false.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Number}
- * @readonly
- */
- outlineWidth : {
- get : function() {
- return this._outlineWidth;
- }
- },
- /**
- * Gets a value indicating if the geometry is time-varying.
- * If true, all visualization is delegated to the {@link DynamicGeometryUpdater}
- * returned by GeometryUpdater#createDynamicUpdater.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Boolean}
- * @readonly
- */
- isDynamic : {
- get : function() {
- return this._dynamic;
- }
- },
- /**
- * Gets a value indicating if the geometry is closed.
- * This property is only valid for static geometry.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Boolean}
- * @readonly
- */
- isClosed : {
- get : function() {
- return this._isClosed;
- }
- },
- /**
- * Gets an event that is raised whenever the public properties
- * of this updater change.
- * @memberof EllipseGeometryUpdater.prototype
- *
- * @type {Boolean}
- * @readonly
- */
- geometryChanged : {
- get : function() {
- return this._geometryChanged;
- }
- }
- });
- /**
- * Checks if the geometry is outlined at the provided time.
- *
- * @param {JulianDate} time The time for which to retrieve visibility.
- * @returns {Boolean} true if geometry is outlined at the provided time, false otherwise.
- */
- EllipseGeometryUpdater.prototype.isOutlineVisible = function(time) {
- var entity = this._entity;
- return this._outlineEnabled && entity.isAvailable(time) && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time);
- };
- /**
- * Checks if the geometry is filled at the provided time.
- *
- * @param {JulianDate} time The time for which to retrieve visibility.
- * @returns {Boolean} true if geometry is filled at the provided time, false otherwise.
- */
- EllipseGeometryUpdater.prototype.isFilled = function(time) {
- var entity = this._entity;
- return this._fillEnabled && entity.isAvailable(time) && this._showProperty.getValue(time) && this._fillProperty.getValue(time);
- };
- /**
- * 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.
- */
- EllipseGeometryUpdater.prototype.createFillGeometryInstance = function(time) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined(time)) {
- throw new DeveloperError('time is required.');
- }
- if (!this._fillEnabled) {
- throw new DeveloperError('This instance does not represent a filled geometry.');
- }
- //>>includeEnd('debug');
- var entity = this._entity;
- var isAvailable = entity.isAvailable(time);
- var attributes;
- var color;
- var show = new ShowGeometryInstanceAttribute(isAvailable && this._showProperty.getValue(time) && this._fillProperty.getValue(time));
- if (this._materialProperty instanceof ColorMaterialProperty) {
- var currentColor = Color.WHITE;
- if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) {
- currentColor = this._materialProperty.color.getValue(time);
- }
- color = ColorGeometryInstanceAttribute.fromColor(currentColor);
- attributes = {
- show : show,
- color : color
- };
- } else {
- attributes = {
- show : show
- };
- }
- return new GeometryInstance({
- id : entity,
- geometry : new EllipseGeometry(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.
- */
- EllipseGeometryUpdater.prototype.createOutlineGeometryInstance = function(time) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined(time)) {
- throw new DeveloperError('time is required.');
- }
- if (!this._outlineEnabled) {
- throw new DeveloperError('This instance does not represent an outlined geometry.');
- }
- //>>includeEnd('debug');
- var entity = this._entity;
- var isAvailable = entity.isAvailable(time);
- var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK);
- return new GeometryInstance({
- id : entity,
- geometry : new EllipseOutlineGeometry(this._options),
- attributes : {
- show : new ShowGeometryInstanceAttribute(isAvailable && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
- color : ColorGeometryInstanceAttribute.fromColor(outlineColor)
- }
- });
- };
- /**
- * Returns true if this object was destroyed; otherwise, false.
- *
- * @returns {Boolean} True if this object was destroyed; otherwise, false.
- */
- EllipseGeometryUpdater.prototype.isDestroyed = function() {
- return false;
- };
- /**
- * Destroys and resources used by the object. Once an object is destroyed, it should not be used.
- *
- * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
- */
- EllipseGeometryUpdater.prototype.destroy = function() {
- this._entitySubscription();
- destroyObject(this);
- };
- EllipseGeometryUpdater.prototype._onEntityPropertyChanged = function(entity, propertyName, newValue, oldValue) {
- if (!(propertyName === 'availability' || propertyName === 'position' || propertyName === 'ellipse')) {
- return;
- }
- var ellipse = this._entity.ellipse;
- if (!defined(ellipse)) {
- if (this._fillEnabled || this._outlineEnabled) {
- this._fillEnabled = false;
- this._outlineEnabled = false;
- this._geometryChanged.raiseEvent(this);
- }
- return;
- }
- var fillProperty = ellipse.fill;
- var fillEnabled = defined(fillProperty) && fillProperty.isConstant ? fillProperty.getValue(Iso8601.MINIMUM_VALUE) : true;
- var outlineProperty = ellipse.outline;
- var outlineEnabled = defined(outlineProperty);
- if (outlineEnabled && outlineProperty.isConstant) {
- outlineEnabled = outlineProperty.getValue(Iso8601.MINIMUM_VALUE);
- }
- if (!fillEnabled && !outlineEnabled) {
- if (this._fillEnabled || this._outlineEnabled) {
- this._fillEnabled = false;
- this._outlineEnabled = false;
- this._geometryChanged.raiseEvent(this);
- }
- return;
- }
- var position = this._entity.position;
- var semiMajorAxis = ellipse.semiMajorAxis;
- var semiMinorAxis = ellipse.semiMinorAxis;
- var show = ellipse.show;
- if ((defined(show) && show.isConstant && !show.getValue(Iso8601.MINIMUM_VALUE)) || //
- (!defined(position) || !defined(semiMajorAxis) || !defined(semiMinorAxis))) {
- if (this._fillEnabled || this._outlineEnabled) {
- this._fillEnabled = false;
- this._outlineEnabled = false;
- this._geometryChanged.raiseEvent(this);
- }
- return;
- }
- var material = defaultValue(ellipse.material, defaultMaterial);
- var isColorMaterial = material instanceof ColorMaterialProperty;
- this._materialProperty = material;
- this._fillProperty = defaultValue(fillProperty, defaultFill);
- this._showProperty = defaultValue(show, defaultShow);
- this._showOutlineProperty = defaultValue(ellipse.outline, defaultOutline);
- this._outlineColorProperty = outlineEnabled ? defaultValue(ellipse.outlineColor, defaultOutlineColor) : undefined;
- var rotation = ellipse.rotation;
- var height = ellipse.height;
- var extrudedHeight = ellipse.extrudedHeight;
- var granularity = ellipse.granularity;
- var stRotation = ellipse.stRotation;
- var outlineWidth = ellipse.outlineWidth;
- var numberOfVerticalLines = ellipse.numberOfVerticalLines;
- this._isClosed = defined(extrudedHeight);
- this._fillEnabled = fillEnabled;
- this._outlineEnabled = outlineEnabled;
- if (!position.isConstant || //
- !semiMajorAxis.isConstant || //
- !semiMinorAxis.isConstant || //
- !Property.isConstant(rotation) || //
- !Property.isConstant(height) || //
- !Property.isConstant(extrudedHeight) || //
- !Property.isConstant(granularity) || //
- !Property.isConstant(stRotation) || //
- !Property.isConstant(outlineWidth) || //
- !Property.isConstant(numberOfVerticalLines)) {
- if (!this._dynamic) {
- this._dynamic = true;
- this._geometryChanged.raiseEvent(this);
- }
- } else {
- var options = this._options;
- options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
- options.center = position.getValue(Iso8601.MINIMUM_VALUE, options.center);
- options.semiMajorAxis = semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMajorAxis);
- options.semiMinorAxis = semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMinorAxis);
- options.rotation = defined(rotation) ? rotation.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- options.height = defined(height) ? height.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- options.extrudedHeight = defined(extrudedHeight) ? extrudedHeight.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- options.stRotation = defined(stRotation) ? stRotation.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- options.numberOfVerticalLines = defined(numberOfVerticalLines) ? numberOfVerticalLines.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- this._outlineWidth = defined(outlineWidth) ? outlineWidth.getValue(Iso8601.MINIMUM_VALUE) : 1.0;
- this._dynamic = false;
- this._geometryChanged.raiseEvent(this);
- }
- };
- /**
- * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true.
- *
- * @param {PrimitiveCollection} primitives The primitive collection to use.
- * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame.
- *
- * @exception {DeveloperError} This instance does not represent dynamic geometry.
- */
- EllipseGeometryUpdater.prototype.createDynamicUpdater = function(primitives) {
- //>>includeStart('debug', pragmas.debug);
- if (!this._dynamic) {
- throw new DeveloperError('This instance does not represent dynamic geometry.');
- }
- if (!defined(primitives)) {
- throw new DeveloperError('primitives is required.');
- }
- //>>includeEnd('debug');
- return new DynamicGeometryUpdater(primitives, this);
- };
- /**
- * @private
- */
- var DynamicGeometryUpdater = function(primitives, geometryUpdater) {
- this._primitives = primitives;
- this._primitive = undefined;
- this._outlinePrimitive = undefined;
- this._geometryUpdater = geometryUpdater;
- this._options = new GeometryOptions(geometryUpdater._entity);
- };
- DynamicGeometryUpdater.prototype.update = function(time) {
- //>>includeStart('debug', pragmas.debug);
- if (!defined(time)) {
- throw new DeveloperError('time is required.');
- }
- //>>includeEnd('debug');
- var primitives = this._primitives;
- primitives.removeAndDestroy(this._primitive);
- primitives.removeAndDestroy(this._outlinePrimitive);
- var geometryUpdater = this._geometryUpdater;
- var entity = geometryUpdater._entity;
- var ellipse = entity.ellipse;
- if (!entity.isAvailable(time) || !Property.getValueOrDefault(ellipse.show, time, true)) {
- return;
- }
- var options = this._options;
- var center = Property.getValueOrUndefined(entity.position, time, options.center);
- var semiMajorAxis = Property.getValueOrUndefined(ellipse.semiMajorAxis, time);
- var semiMinorAxis = Property.getValueOrUndefined(ellipse.semiMinorAxis, time);
- if (!defined(center) || !defined(semiMajorAxis) || !defined(semiMinorAxis)) {
- return;
- }
- options.center = center;
- options.semiMajorAxis = semiMajorAxis;
- options.semiMinorAxis = semiMinorAxis;
- options.rotation = Property.getValueOrUndefined(ellipse.rotation, time);
- options.height = Property.getValueOrUndefined(ellipse.height, time);
- options.extrudedHeight = Property.getValueOrUndefined(ellipse.extrudedHeight, time);
- options.granularity = Property.getValueOrUndefined(ellipse.granularity, time);
- options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, time);
- options.numberOfVerticalLines = Property.getValueOrUndefined(ellipse.numberOfVerticalLines, time);
- if (Property.getValueOrDefault(ellipse.fill, time, true)) {
- var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
- this._material = material;
- var appearance = new MaterialAppearance({
- material : material,
- translucent : material.isTranslucent(),
- closed : defined(options.extrudedHeight)
- });
- options.vertexFormat = appearance.vertexFormat;
- this._primitive = primitives.add(new Primitive({
- geometryInstances : new GeometryInstance({
- id : entity,
- geometry : new EllipseGeometry(options)
- }),
- appearance : appearance,
- asynchronous : false
- }));
- }
- if (Property.getValueOrDefault(ellipse.outline, time, false)) {
- options.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT;
- var outlineColor = Property.getValueOrClonedDefault(ellipse.outlineColor, time, Color.BLACK, scratchColor);
- var outlineWidth = Property.getValueOrDefault(ellipse.outlineWidth, 1.0);
- var translucent = outlineColor.alpha !== 1.0;
- this._outlinePrimitive = primitives.add(new Primitive({
- geometryInstances : new GeometryInstance({
- id : entity,
- geometry : new EllipseOutlineGeometry(options),
- attributes : {
- color : ColorGeometryInstanceAttribute.fromColor(outlineColor)
- }
- }),
- appearance : new PerInstanceColorAppearance({
- flat : true,
- translucent : translucent,
- renderState : {
- lineWidth : geometryUpdater._scene.clampLineWidth(outlineWidth)
- }
- }),
- asynchronous : false
- }));
- }
- };
- DynamicGeometryUpdater.prototype.isDestroyed = function() {
- return false;
- };
- DynamicGeometryUpdater.prototype.destroy = function() {
- var primitives = this._primitives;
- primitives.removeAndDestroy(this._primitive);
- primitives.removeAndDestroy(this._outlinePrimitive);
- destroyObject(this);
- };
- return EllipseGeometryUpdater;
- });
|