Skip to content

Commit

Permalink
Merge pull request #1653 from AnalyticalGraphicsInc/visualizer-refactor
Browse files Browse the repository at this point in the history
Visualizer cleanup
  • Loading branch information
shunter committed Apr 29, 2014
2 parents 633227b + 2169e97 commit 762fed3
Show file tree
Hide file tree
Showing 22 changed files with 417 additions and 1,330 deletions.
20 changes: 15 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Beta Releases
* Renamed and moved `Scene.primitives.centralBody` moved to `Scene.globe`.
* Removed `CesiumWidget.centralBody` and `Viewer.centralBody`. Use `Scene.globe`.
* Renamed `CentralBody` to `Globe`.
* Refactored visualizers, removing `setDynamicObjectCollection`, `getDynamicObjectCollection`, `getScene`, and `removeAllPrimitives` which are all superfluous after the introduction of `DataSourceDisplay`. The affected classes are:
* `DynamicBillboardVisualizer`
* `DynamicConeVisualizerUsingCustomSensor`
* `DynamicLabelVisualizer`
* `DynamicModelVisualizer`
* `DynamicPathVisualizer`
* `DynamicPointVisualizer`
* `DynamicPyramidVisualizer`
* `DynamicVectorVisualizer`
* `GeometryVisualizer`
* Renamed Extent to Rectangle
* `Extent` -> `Rectangle`
* `ExtentGeometry` -> `RectangleGeomtry`
Expand All @@ -27,11 +37,11 @@ Beta Releases
* `TilingScheme.tileXYToNativeExtent` -> `TilingScheme.tileXYToNativeRectangle`
* `TilingScheme.tileXYToExtent` -> `TilingScheme.tileXYToRectangle`
* Converted 'DataSource' get methods into properties.
* 'getName` -> `name`
* 'getClock` -> `clock`
* 'getChangedEvent` -> `changedEvent`
* 'getDynamicObjectCollection` -> `dynamicObjects`
* 'getErrorEvent` -> `errorEvent`
* 'getName` -> `name`
* 'getClock` -> `clock`
* 'getChangedEvent` -> `changedEvent`
* 'getDynamicObjectCollection` -> `dynamicObjects`
* 'getErrorEvent` -> `errorEvent`
* `BaseLayerPicker` has been extended to support terrain selection.
* The `BaseLayerPicker` constructor function now takes the container element and an options object instead of a CentralBody and ImageryLayerCollection.
* The `BaseLayerPickerViewModel` constructor function now takes an options object instead of a CentralBody and ImageryLayerCollection.
Expand Down
132 changes: 29 additions & 103 deletions Source/DynamicScene/DynamicBillboardVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ define([
TextureAtlasBuilder) {
"use strict";

//Callback to create a callback so that we close over all of the proper values.
function textureReady(dynamicObject, billboardCollection, textureValue) {
return function(imageIndex) {
//By the time the texture was loaded, the billboard might already be
Expand All @@ -41,83 +40,41 @@ define([
}

/**
* A DynamicObject visualizer which maps the DynamicBillboard instance
* in DynamicObject.billboard to a Billboard primitive.
* A {@link Visualizer} which maps {@link DynamicObject#billboard} to a {@link Billboard}.
* @alias DynamicBillboardVisualizer
* @constructor
*
* @param {Scene} scene The scene the primitives will be rendered in.
* @param {DynamicObjectCollection} [dynamicObjectCollection] The dynamicObjectCollection to visualize.
*
* @see DynamicBillboard
* @see DynamicObject
* @see DynamicObjectCollection
* @see CompositeDynamicObjectCollection
* @see DynamicConeVisualizer
* @see DynamicConeVisualizerUsingCustomSensor
* @see DynamicLabelVisualizer
* @see DynamicPointVisualizer
* @see DynamicPyramidVisualizer
* @param {DynamicObjectCollection} dynamicObjectCollection The dynamicObjectCollection to visualize.
*/
var DynamicBillboardVisualizer = function(scene, dynamicObjectCollection) {
//>>includeStart('debug', pragmas.debug);
if (!defined(scene)) {
throw new DeveloperError('scene is required.');
}
if (!defined(dynamicObjectCollection)) {
throw new DeveloperError('dynamicObjectCollection is required.');
}
//>>includeEnd('debug');

this._scene = scene;
this._unusedIndexes = [];
this._dynamicObjectCollection = undefined;

var billboardCollection = this._billboardCollection = new BillboardCollection();
var atlas = this._textureAtlas = scene.createTextureAtlas();
this._textureAtlasBuilder = new TextureAtlasBuilder(atlas);
var billboardCollection = new BillboardCollection();
var atlas = scene.createTextureAtlas();
billboardCollection.textureAtlas = atlas;
scene.primitives.add(billboardCollection);
this.setDynamicObjectCollection(dynamicObjectCollection);
};

/**
* Returns the scene being used by this visualizer.
*
* @returns {Scene} The scene being used by this visualizer.
*/
DynamicBillboardVisualizer.prototype.getScene = function() {
return this._scene;
};

/**
* Gets the DynamicObjectCollection being visualized.
*
* @returns {DynamicObjectCollection} The DynamicObjectCollection being visualized.
*/
DynamicBillboardVisualizer.prototype.getDynamicObjectCollection = function() {
return this._dynamicObjectCollection;
};
dynamicObjectCollection.collectionChanged.addEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this);

/**
* Sets the DynamicObjectCollection to visualize.
*
* @param dynamicObjectCollection The DynamicObjectCollection to visualizer.
*/
DynamicBillboardVisualizer.prototype.setDynamicObjectCollection = function(dynamicObjectCollection) {
var oldCollection = this._dynamicObjectCollection;
if (oldCollection !== dynamicObjectCollection) {
if (defined(oldCollection)) {
oldCollection.collectionChanged.removeEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this);
this.removeAllPrimitives();
}
this._dynamicObjectCollection = dynamicObjectCollection;
if (defined(dynamicObjectCollection)) {
dynamicObjectCollection.collectionChanged.addEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this);
}
}
this._scene = scene;
this._unusedIndexes = [];
this._textureAtlas = atlas;
this._billboardCollection = billboardCollection;
this._textureAtlasBuilder = new TextureAtlasBuilder(atlas);
this._dynamicObjectCollection = dynamicObjectCollection;
};

/**
* Updates all of the primitives created by this visualizer to match their
* Updates the primitives created by this visualizer to match their
* DynamicObject counterpart at the given time.
* @memberof DynamicBillboardVisualizer
*
* @param {JulianDate} time The time to update to.
* @returns {Boolean} This function always returns true.
Expand All @@ -129,66 +86,36 @@ define([
}
//>>includeEnd('debug');

if (defined(this._dynamicObjectCollection)) {
var dynamicObjects = this._dynamicObjectCollection.getObjects();
for ( var i = 0, len = dynamicObjects.length; i < len; i++) {
updateObject(this, time, dynamicObjects[i]);
}
var dynamicObjects = this._dynamicObjectCollection.getObjects();
for (var i = 0, len = dynamicObjects.length; i < len; i++) {
updateObject(this, time, dynamicObjects[i]);
}
return true;
};

/**
* Removes all primitives from the scene.
*/
DynamicBillboardVisualizer.prototype.removeAllPrimitives = function() {
if (defined(this._dynamicObjectCollection)) {
this._unusedIndexes = [];
this._billboardCollection.removeAll();
var dynamicObjects = this._dynamicObjectCollection.getObjects();
for ( var i = dynamicObjects.length - 1; i > -1; i--) {
dynamicObjects[i]._billboardVisualizerIndex = undefined;
}
}
};

/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
* If this object was destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
*
* @memberof DynamicBillboardVisualizer
*
* @returns {Boolean} True if this object was destroyed; otherwise, false.
*
* @see DynamicBillboardVisualizer#destroy
*/
DynamicBillboardVisualizer.prototype.isDestroyed = function() {
return false;
};

/**
* Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
* release of WebGL resources, instead of relying on the garbage collector to destroy this object.
* <br /><br />
* Once an object is destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
* assign the return value (<code>undefined</code>) to the object as done in the example.
*
* Removes and destroys all primitives created by this instance.
* @memberof DynamicBillboardVisualizer
*
* @returns {undefined}
*
* @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
*
* @see DynamicBillboardVisualizer#isDestroyed
*
* @example
* visualizer = visualizer && visualizer.destroy();
*/
DynamicBillboardVisualizer.prototype.destroy = function() {
this.setDynamicObjectCollection(undefined);
var dynamicObjectCollection = this._dynamicObjectCollection;
dynamicObjectCollection.collectionChanged.removeEventListener(DynamicBillboardVisualizer.prototype._onObjectsRemoved, this);

var dynamicObjects = dynamicObjectCollection.getObjects();
var length = dynamicObjects.length;
for (var i = 0; i < length; i++) {
dynamicObjects[i]._billboardVisualizerIndex = undefined;
}
this._scene.primitives.remove(this._billboardCollection);
return destroyObject(this);
};
Expand Down Expand Up @@ -247,7 +174,6 @@ define([
billboard._visualizerUrl = undefined;
billboard._visualizerTextureAvailable = false;

// CZML_TODO Determine official defaults
billboard.color = Color.WHITE;
billboard.eyeOffset = Cartesian3.ZERO;
billboard.pixelOffset = Cartesian2.ZERO;
Expand Down Expand Up @@ -369,7 +295,7 @@ define([
DynamicBillboardVisualizer.prototype._onObjectsRemoved = function(dynamicObjectCollection, added, dynamicObjects) {
var thisBillboardCollection = this._billboardCollection;
var thisUnusedIndexes = this._unusedIndexes;
for ( var i = dynamicObjects.length - 1; i > -1; i--) {
for (var i = dynamicObjects.length - 1; i > -1; i--) {
var dynamicObject = dynamicObjects[i];
var billboardVisualizerIndex = dynamicObject._billboardVisualizerIndex;
if (defined(billboardVisualizerIndex)) {
Expand Down
Loading

0 comments on commit 762fed3

Please sign in to comment.