Skip to content

Commit

Permalink
Added viewer.zoomTo(timeDynamicPointCloud)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jul 3, 2018
1 parent e1fddc0 commit b767800
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 19 deletions.
6 changes: 1 addition & 5 deletions Apps/Sandcastle/gallery/Time Dynamic Point Cloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@
clock.stopTime = stop;
clock.clockRange = Cesium.ClockRange.LOOP_STOP;

viewer.camera.setView({
destination: new Cesium.Cartesian3(1215034.013185971, -4736376.364704681, 4081587.528471664),
orientation: new Cesium.HeadingPitchRoll(6.2077134961933265, -0.6084278203800215, 6.282880789189662),
endTransform : Cesium.Matrix4.IDENTITY
});
viewer.zoomTo(pointCloud, new Cesium.HeadingPitchRange(0.0, -0.5, 50.0));
//Sandcastle_End
Sandcastle.finishedLoading();
}
Expand Down
19 changes: 15 additions & 4 deletions Source/Scene/PointCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ define([

this.time = 0.0; // For styling
this.shadows = ShadowMode.ENABLED;
this.boundingSphere = undefined;
this._boundingSphere = undefined;

this.clippingPlanes = undefined;
this.isClipped = false;
Expand Down Expand Up @@ -229,6 +229,17 @@ define([
set : function(value) {
this._highlightColor = Color.clone(value, this._highlightColor);
}
},

boundingSphere : {
get : function() {
if (defined(this._drawCommand)) {
return this._drawCommand.boundingVolume;
}
},
set : function(value) {
this._boundingSphere = BoundingSphere.clone(value);
}
}
});

Expand Down Expand Up @@ -634,9 +645,9 @@ define([

if (pointCloud._cull) {
if (isQuantized || isQuantizedDraco) {
pointCloud.boundingSphere = BoundingSphere.fromCornerPoints(Cartesian3.ZERO, pointCloud._quantizedVolumeScale);
pointCloud._boundingSphere = BoundingSphere.fromCornerPoints(Cartesian3.ZERO, pointCloud._quantizedVolumeScale);
} else {
pointCloud.boundingSphere = computeApproximateBoundingSphereFromPositions(positions);
pointCloud._boundingSphere = computeApproximateBoundingSphereFromPositions(positions);
}
}

Expand Down Expand Up @@ -1298,7 +1309,7 @@ define([
}

var boundingSphere = this._drawCommand.boundingVolume;
BoundingSphere.clone(this.boundingSphere, boundingSphere);
BoundingSphere.clone(this._boundingSphere, boundingSphere);

if (this._cull) {
var center = boundingSphere.center;
Expand Down
16 changes: 16 additions & 0 deletions Source/Scene/TimeDynamicPointCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ define([
get : function() {
return this._totalMemoryUsageInBytes;
}
},

/**
* The bounding sphere of the frame being rendered. Returns <code>undefined</code> if no frame is being rendered.
*
* @memberof TimeDynamicPointCloud.prototype
*
* @type {BoundingSphere}
* @readonly
*/
boundingSphere : {
get : function() {
if (defined(this._lastRenderedFrame)) {
return this._lastRenderedFrame.pointCloud.boundingSphere;
}
}
}
});

Expand Down
57 changes: 51 additions & 6 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define([
'../../Scene/Cesium3DTileset',
'../../Scene/ImageryLayer',
'../../Scene/SceneMode',
'../../Scene/TimeDynamicPointCloud',
'../../ThirdParty/knockout',
'../../ThirdParty/when',
'../Animation/Animation',
Expand Down Expand Up @@ -71,6 +72,7 @@ define([
Cesium3DTileset,
ImageryLayer,
SceneMode,
TimeDynamicPointCloud,
knockout,
when,
Animation,
Expand Down Expand Up @@ -1740,7 +1742,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
* target will be the range. The heading will be determined from the offset. If the heading cannot be
* determined from the offset, the heading will be north.</p>
*
* @param {Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|Promise.<Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset>} target The entity, array of entities, entity collection, data source, Cesium#DTileset, or imagery layer to view. You can also pass a promise that resolves to one of the previously mentioned types.
* @param {Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud|Promise.<Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud>} target The entity, array of entities, entity collection, data source, Cesium3DTileset, point cloud, or imagery layer to view. You can also pass a promise that resolves to one of the previously mentioned types.
* @param {HeadingPitchRange} [offset] The offset from the center of the entity in the local east-north-up reference frame.
* @returns {Promise.<Boolean>} A Promise that resolves to true if the zoom was successful or false if the target is not currently visualized in the scene or the zoom was cancelled.
*/
Expand All @@ -1766,7 +1768,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
* target will be the range. The heading will be determined from the offset. If the heading cannot be
* determined from the offset, the heading will be north.</p>
*
* @param {Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|Promise.<Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset>} target The entity, array of entities, entity collection, data source, Cesium3DTileset, or imagery layer to view. You can also pass a promise that resolves to one of the previously mentioned types.
* @param {Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud|Promise.<Entity|Entity[]|EntityCollection|DataSource|ImageryLayer|Cesium3DTileset|TimeDynamicPointCloud>} target The entity, array of entities, entity collection, data source, Cesium3DTileset, point cloud, or imagery layer to view. You can also pass a promise that resolves to one of the previously mentioned types.
* @param {Object} [options] Object with the following properties:
* @param {Number} [options.duration=3.0] The duration of the flight in seconds.
* @param {Number} [options.maximumHeight] The maximum height at the peak of the flight.
Expand Down Expand Up @@ -1818,6 +1820,12 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
return;
}

//If the zoom target is a TimeDynamicPointCloud
if (zoomTarget instanceof TimeDynamicPointCloud) {
that._zoomTarget = zoomTarget;
return;
}

//If the zoom target is a data source, and it's in the middle of loading, wait for it to finish loading.
if (zoomTarget.isLoading && defined(zoomTarget.loadingEvent)) {
var removeEvent = zoomTarget.loadingEvent.addEventListener(function() {
Expand Down Expand Up @@ -1891,12 +1899,13 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
var zoomPromise = viewer._zoomPromise;
var zoomOptions = defaultValue(viewer._zoomOptions, {});
var options;
var boundingSphere;

// If zoomTarget was Cesium3DTileset
if (target instanceof Cesium3DTileset) {
return target.readyPromise.then(function() {
var boundingSphere = target.boundingSphere;
// if offset was originally undefined then give it base value instead of empty object
// If offset was originally undefined then give it base value instead of empty object
if (!defined(zoomOptions.offset)) {
zoomOptions.offset = new HeadingPitchRange(0.0, -0.5, boundingSphere.radius);
}
Expand All @@ -1919,15 +1928,51 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
camera.viewBoundingSphere(boundingSphere, zoomOptions.offset);
camera.lookAtTransform(Matrix4.IDENTITY);

// finish the promise
// Finish the promise
zoomPromise.resolve(true);
}

clearZoom(viewer);
});
}

//If zoomTarget was an ImageryLayer
// If zoomTarget was TimeDynamicPointCloud
if (target instanceof TimeDynamicPointCloud) {
boundingSphere = target.boundingSphere;
if (defined(boundingSphere)) {
// If offset was originally undefined then give it base value instead of empty object
if (!defined(zoomOptions.offset)) {
zoomOptions.offset = new HeadingPitchRange(0.0, -0.5, boundingSphere.radius);
}

options = {
offset : zoomOptions.offset,
duration : zoomOptions.duration,
maximumHeight : zoomOptions.maximumHeight,
complete : function() {
zoomPromise.resolve(true);
},
cancel : function() {
zoomPromise.resolve(false);
}
};

if (viewer._zoomIsFlight) {
camera.flyToBoundingSphere(boundingSphere, options);
} else {
camera.viewBoundingSphere(boundingSphere, zoomOptions.offset);
camera.lookAtTransform(Matrix4.IDENTITY);

// Finish the promise
zoomPromise.resolve(true);
}

clearZoom(viewer);
}
return;
}

// If zoomTarget was an ImageryLayer
if (target instanceof Rectangle) {
options = {
destination : target,
Expand Down Expand Up @@ -1972,7 +2017,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
//Stop tracking the current entity.
viewer.trackedEntity = undefined;

var boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres);
boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres);

if (!viewer._zoomIsFlight) {
camera.viewBoundingSphere(boundingSphere, viewer._zoomOptions.offset);
Expand Down
18 changes: 18 additions & 0 deletions Specs/Scene/TimeDynamicPointCloudSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defineSuite([
'Scene/TimeDynamicPointCloud',
'Core/BoundingSphere',
'Core/Cartesian3',
'Core/Clock',
'Core/ClockStep',
Expand All @@ -26,6 +27,7 @@ defineSuite([
'ThirdParty/when'
], function(
TimeDynamicPointCloud,
BoundingSphere,
Cartesian3,
Clock,
ClockStep,
Expand Down Expand Up @@ -240,6 +242,22 @@ defineSuite([
});
});

it('gets bounding sphere of the rendered frame', function() {
var pointCloud = createTimeDynamicPointCloud({
useTransforms : true
});
expect(pointCloud.boundingSphere).toBeUndefined(); // Undefined until a frame is rendered
return loadAllFrames(pointCloud).then(function() {
var boundingSphereFrame0 = pointCloud.boundingSphere;
expect(boundingSphereFrame0).toBeDefined();
goToFrame(1);
scene.renderForSpecs();
var boundingSphereFrame1 = pointCloud.boundingSphere;
expect(boundingSphereFrame1).toBeDefined();
expect(BoundingSphere.equals(boundingSphereFrame0, boundingSphereFrame1)).toBe(false);
});
});

it('sets show', function() {
var pointCloud = createTimeDynamicPointCloud();

Expand Down
Loading

0 comments on commit b767800

Please sign in to comment.