Skip to content

Commit b767800

Browse files
committed
Added viewer.zoomTo(timeDynamicPointCloud)
1 parent e1fddc0 commit b767800

File tree

6 files changed

+265
-19
lines changed

6 files changed

+265
-19
lines changed

Apps/Sandcastle/gallery/Time Dynamic Point Cloud.html

+1-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@
8181
clock.stopTime = stop;
8282
clock.clockRange = Cesium.ClockRange.LOOP_STOP;
8383

84-
viewer.camera.setView({
85-
destination: new Cesium.Cartesian3(1215034.013185971, -4736376.364704681, 4081587.528471664),
86-
orientation: new Cesium.HeadingPitchRoll(6.2077134961933265, -0.6084278203800215, 6.282880789189662),
87-
endTransform : Cesium.Matrix4.IDENTITY
88-
});
84+
viewer.zoomTo(pointCloud, new Cesium.HeadingPitchRange(0.0, -0.5, 50.0));
8985
//Sandcastle_End
9086
Sandcastle.finishedLoading();
9187
}

Source/Scene/PointCloud.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ define([
180180

181181
this.time = 0.0; // For styling
182182
this.shadows = ShadowMode.ENABLED;
183-
this.boundingSphere = undefined;
183+
this._boundingSphere = undefined;
184184

185185
this.clippingPlanes = undefined;
186186
this.isClipped = false;
@@ -229,6 +229,17 @@ define([
229229
set : function(value) {
230230
this._highlightColor = Color.clone(value, this._highlightColor);
231231
}
232+
},
233+
234+
boundingSphere : {
235+
get : function() {
236+
if (defined(this._drawCommand)) {
237+
return this._drawCommand.boundingVolume;
238+
}
239+
},
240+
set : function(value) {
241+
this._boundingSphere = BoundingSphere.clone(value);
242+
}
232243
}
233244
});
234245

@@ -634,9 +645,9 @@ define([
634645

635646
if (pointCloud._cull) {
636647
if (isQuantized || isQuantizedDraco) {
637-
pointCloud.boundingSphere = BoundingSphere.fromCornerPoints(Cartesian3.ZERO, pointCloud._quantizedVolumeScale);
648+
pointCloud._boundingSphere = BoundingSphere.fromCornerPoints(Cartesian3.ZERO, pointCloud._quantizedVolumeScale);
638649
} else {
639-
pointCloud.boundingSphere = computeApproximateBoundingSphereFromPositions(positions);
650+
pointCloud._boundingSphere = computeApproximateBoundingSphereFromPositions(positions);
640651
}
641652
}
642653

@@ -1298,7 +1309,7 @@ define([
12981309
}
12991310

13001311
var boundingSphere = this._drawCommand.boundingVolume;
1301-
BoundingSphere.clone(this.boundingSphere, boundingSphere);
1312+
BoundingSphere.clone(this._boundingSphere, boundingSphere);
13021313

13031314
if (this._cull) {
13041315
var center = boundingSphere.center;

Source/Scene/TimeDynamicPointCloud.js

+16
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@ define([
222222
get : function() {
223223
return this._totalMemoryUsageInBytes;
224224
}
225+
},
226+
227+
/**
228+
* The bounding sphere of the frame being rendered. Returns <code>undefined</code> if no frame is being rendered.
229+
*
230+
* @memberof TimeDynamicPointCloud.prototype
231+
*
232+
* @type {BoundingSphere}
233+
* @readonly
234+
*/
235+
boundingSphere : {
236+
get : function() {
237+
if (defined(this._lastRenderedFrame)) {
238+
return this._lastRenderedFrame.pointCloud.boundingSphere;
239+
}
240+
}
225241
}
226242
});
227243

Source/Widgets/Viewer/Viewer.js

+51-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ define([
2424
'../../Scene/Cesium3DTileset',
2525
'../../Scene/ImageryLayer',
2626
'../../Scene/SceneMode',
27+
'../../Scene/TimeDynamicPointCloud',
2728
'../../ThirdParty/knockout',
2829
'../../ThirdParty/when',
2930
'../Animation/Animation',
@@ -71,6 +72,7 @@ define([
7172
Cesium3DTileset,
7273
ImageryLayer,
7374
SceneMode,
75+
TimeDynamicPointCloud,
7476
knockout,
7577
when,
7678
Animation,
@@ -1740,7 +1742,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
17401742
* target will be the range. The heading will be determined from the offset. If the heading cannot be
17411743
* determined from the offset, the heading will be north.</p>
17421744
*
1743-
* @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.
1745+
* @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.
17441746
* @param {HeadingPitchRange} [offset] The offset from the center of the entity in the local east-north-up reference frame.
17451747
* @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.
17461748
*/
@@ -1766,7 +1768,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
17661768
* target will be the range. The heading will be determined from the offset. If the heading cannot be
17671769
* determined from the offset, the heading will be north.</p>
17681770
*
1769-
* @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.
1771+
* @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.
17701772
* @param {Object} [options] Object with the following properties:
17711773
* @param {Number} [options.duration=3.0] The duration of the flight in seconds.
17721774
* @param {Number} [options.maximumHeight] The maximum height at the peak of the flight.
@@ -1818,6 +1820,12 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
18181820
return;
18191821
}
18201822

1823+
//If the zoom target is a TimeDynamicPointCloud
1824+
if (zoomTarget instanceof TimeDynamicPointCloud) {
1825+
that._zoomTarget = zoomTarget;
1826+
return;
1827+
}
1828+
18211829
//If the zoom target is a data source, and it's in the middle of loading, wait for it to finish loading.
18221830
if (zoomTarget.isLoading && defined(zoomTarget.loadingEvent)) {
18231831
var removeEvent = zoomTarget.loadingEvent.addEventListener(function() {
@@ -1891,12 +1899,13 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
18911899
var zoomPromise = viewer._zoomPromise;
18921900
var zoomOptions = defaultValue(viewer._zoomOptions, {});
18931901
var options;
1902+
var boundingSphere;
18941903

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

1922-
// finish the promise
1931+
// Finish the promise
19231932
zoomPromise.resolve(true);
19241933
}
19251934

19261935
clearZoom(viewer);
19271936
});
19281937
}
19291938

1930-
//If zoomTarget was an ImageryLayer
1939+
// If zoomTarget was TimeDynamicPointCloud
1940+
if (target instanceof TimeDynamicPointCloud) {
1941+
boundingSphere = target.boundingSphere;
1942+
if (defined(boundingSphere)) {
1943+
// If offset was originally undefined then give it base value instead of empty object
1944+
if (!defined(zoomOptions.offset)) {
1945+
zoomOptions.offset = new HeadingPitchRange(0.0, -0.5, boundingSphere.radius);
1946+
}
1947+
1948+
options = {
1949+
offset : zoomOptions.offset,
1950+
duration : zoomOptions.duration,
1951+
maximumHeight : zoomOptions.maximumHeight,
1952+
complete : function() {
1953+
zoomPromise.resolve(true);
1954+
},
1955+
cancel : function() {
1956+
zoomPromise.resolve(false);
1957+
}
1958+
};
1959+
1960+
if (viewer._zoomIsFlight) {
1961+
camera.flyToBoundingSphere(boundingSphere, options);
1962+
} else {
1963+
camera.viewBoundingSphere(boundingSphere, zoomOptions.offset);
1964+
camera.lookAtTransform(Matrix4.IDENTITY);
1965+
1966+
// Finish the promise
1967+
zoomPromise.resolve(true);
1968+
}
1969+
1970+
clearZoom(viewer);
1971+
}
1972+
return;
1973+
}
1974+
1975+
// If zoomTarget was an ImageryLayer
19311976
if (target instanceof Rectangle) {
19321977
options = {
19331978
destination : target,
@@ -1972,7 +2017,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
19722017
//Stop tracking the current entity.
19732018
viewer.trackedEntity = undefined;
19742019

1975-
var boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres);
2020+
boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres);
19762021

19772022
if (!viewer._zoomIsFlight) {
19782023
camera.viewBoundingSphere(boundingSphere, viewer._zoomOptions.offset);

Specs/Scene/TimeDynamicPointCloudSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defineSuite([
22
'Scene/TimeDynamicPointCloud',
3+
'Core/BoundingSphere',
34
'Core/Cartesian3',
45
'Core/Clock',
56
'Core/ClockStep',
@@ -26,6 +27,7 @@ defineSuite([
2627
'ThirdParty/when'
2728
], function(
2829
TimeDynamicPointCloud,
30+
BoundingSphere,
2931
Cartesian3,
3032
Clock,
3133
ClockStep,
@@ -240,6 +242,22 @@ defineSuite([
240242
});
241243
});
242244

245+
it('gets bounding sphere of the rendered frame', function() {
246+
var pointCloud = createTimeDynamicPointCloud({
247+
useTransforms : true
248+
});
249+
expect(pointCloud.boundingSphere).toBeUndefined(); // Undefined until a frame is rendered
250+
return loadAllFrames(pointCloud).then(function() {
251+
var boundingSphereFrame0 = pointCloud.boundingSphere;
252+
expect(boundingSphereFrame0).toBeDefined();
253+
goToFrame(1);
254+
scene.renderForSpecs();
255+
var boundingSphereFrame1 = pointCloud.boundingSphere;
256+
expect(boundingSphereFrame1).toBeDefined();
257+
expect(BoundingSphere.equals(boundingSphereFrame0, boundingSphereFrame1)).toBe(false);
258+
});
259+
});
260+
243261
it('sets show', function() {
244262
var pointCloud = createTimeDynamicPointCloud();
245263

0 commit comments

Comments
 (0)