Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sampleHeight fixes and cleanup #7174

Merged
merged 4 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
### 1.51 - 2018-11-01

##### Additions :tada:
* Added `Ray.clone`. [#7115](https://github.com/AnalyticalGraphicsInc/cesium/pull/7115)
* Shrink minified and gzipped Cesium.js by 27 KB (~3.7%) by delay loading seldom-used third-party dependencies. [#7140](https://github.com/AnalyticalGraphicsInc/cesium/pull/7140)
* Added WMS-T (time) support in WebMapServiceImageryProvider [#2581](https://github.com/AnalyticalGraphicsInc/cesium/issues/2581)
* Added `Transforms.fixedFrameToHeadingPitchRoll`, a helper function for extracting a `HeadingPitchRoll` from a fixed frame transform [#7164](https://github.com/AnalyticalGraphicsInc/cesium/pull/7164)
Expand All @@ -13,6 +14,7 @@ Change Log

##### Fixes :wrench:
* Fixed an issue where `pickPosition` would return incorrect results when called after `sampleHeight` or `clampToHeight`. [#7113](https://github.com/AnalyticalGraphicsInc/cesium/pull/7113)
* Fixed an issue where `sampleHeight` and `clampToHeight` would crash if picking a primitive that doesn't write depth. [#7120](https://github.com/AnalyticalGraphicsInc/cesium/issues/7120)
* Fixed crash when updating polyline attributes twice in one frame [#7155](https://github.com/AnalyticalGraphicsInc/cesium/pull/7155)
* Fixed a crash when using `BingMapsGeocoderService` [#7143](https://github.com/AnalyticalGraphicsInc/cesium/issues/7143)

Expand Down
35 changes: 25 additions & 10 deletions Source/Core/Ray.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
define([
'./Cartesian3',
'./Check',
'./defaultValue',
'./defined',
'./DeveloperError'
'./defined'
], function(
Cartesian3,
Check,
defaultValue,
defined,
DeveloperError) {
defined) {
'use strict';

/**
Expand Down Expand Up @@ -38,6 +38,25 @@ define([
this.direction = direction;
}

/**
* Duplicates a Ray instance.
*
* @param {Ray} ray The ray to duplicate.
* @param {Ray} [result] The object onto which to store the result.
* @returns {Ray} The modified result parameter or a new Ray instance if one was not provided. (Returns undefined if ray is undefined)
*/
Ray.clone = function(ray, result) {
if (!defined(ray)) {
return undefined;
}
if (!defined(result)) {
return new Ray(ray.origin, ray.direction);
}
result.origin = ray.origin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below should clone ray.origin and ray.direction.

result.direction = ray.direction;
return result;
};

/**
* Computes the point along the ray given by r(t) = o + t*d,
* where o is the origin of the ray and d is the direction.
Expand All @@ -54,12 +73,8 @@ define([
*/
Ray.getPoint = function(ray, t, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(ray)){
throw new DeveloperError('ray is requred');
}
if (typeof t !== 'number') {
throw new DeveloperError('t is a required number');
}
Check.typeOf.object('ray', ray);
Check.typeOf.number('t', t);
//>>includeEnd('debug');

if (!defined(result)) {
Expand Down
69 changes: 69 additions & 0 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define([
'../Core/Matrix3',
'../Core/Matrix4',
'../Core/OrientedBoundingBox',
'../Core/OrthographicFrustum',
'../Core/Rectangle',
'../Core/Request',
'../Core/RequestScheduler',
Expand Down Expand Up @@ -54,6 +55,7 @@ define([
Matrix3,
Matrix4,
OrientedBoundingBox,
OrthographicFrustum,
Rectangle,
Request,
RequestScheduler,
Expand Down Expand Up @@ -607,6 +609,63 @@ define([

var scratchJulianDate = new JulianDate();

/**
* Get the tile's screen space error.
*
* @private
*/
Cesium3DTile.prototype.getScreenSpaceError = function(frameState, useParentGeometricError) {
lilleyse marked this conversation as resolved.
Show resolved Hide resolved
var tileset = this._tileset;
var parentGeometricError = defined(this.parent) ? this.parent.geometricError : tileset._geometricError;
var geometricError = useParentGeometricError ? parentGeometricError : this.geometricError;
if (geometricError === 0.0) {
// Leaf tiles do not have any error so save the computation
return 0.0;
}
var camera = frameState.camera;
var frustum = camera.frustum;
var context = frameState.context;
var width = context.drawingBufferWidth;
var height = context.drawingBufferHeight;
var error;
if (frameState.mode === SceneMode.SCENE2D || frustum instanceof OrthographicFrustum) {
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
}
var pixelSize = Math.max(frustum.top - frustum.bottom, frustum.right - frustum.left) / Math.max(width, height);
error = geometricError / pixelSize;
} else {
// Avoid divide by zero when viewer is inside the tile
var distance = Math.max(this._distanceToCamera, CesiumMath.EPSILON7);
var sseDenominator = camera.frustum.sseDenominator;
error = (geometricError * height) / (distance * sseDenominator);
if (tileset.dynamicScreenSpaceError) {
var density = tileset._dynamicScreenSpaceErrorComputedDensity;
var factor = tileset.dynamicScreenSpaceErrorFactor;
var dynamicError = CesiumMath.fog(distance, density) * factor;
error -= dynamicError;
}
}
return error;
};
/**
lilleyse marked this conversation as resolved.
Show resolved Hide resolved
* Update the tile's visibility.
*
* @private
*/
Cesium3DTile.prototype.updateVisibility = function(frameState) {
var parent = this.parent;
var parentTransform = defined(parent) ? parent.computedTransform : this._tileset.modelMatrix;
var parentVisibilityPlaneMask = defined(parent) ? parent._visibilityPlaneMask : CullingVolume.MASK_INDETERMINATE;
this.updateTransform(parentTransform);
this._distanceToCamera = this.distanceToTile(frameState);
this._centerZDepth = this.distanceToTileCenter(frameState);
this._screenSpaceError = this.getScreenSpaceError(frameState);
this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask); // Use parent's plane mask to speed up visibility test
this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE;
this._inRequestVolume = this.insideViewerRequestVolume(frameState);
};

/**
* Update whether the tile has expired.
*
Expand Down Expand Up @@ -846,6 +905,12 @@ define([
return Intersect.INSIDE;
}

if (this._visibilityPlaneMask === CullingVolume.MASK_INSIDE) {
// The tile's bounding volume is completely inside the culling volume so
// the content bounding volume must also be inside.
return Intersect.INSIDE;
}

// PERFORMANCE_IDEA: is it possible to burn less CPU on this test since we know the
// tile's (not the content's) bounding volume intersects the culling volume?
var cullingVolume = frameState.cullingVolume;
Expand Down Expand Up @@ -1055,6 +1120,10 @@ define([
};

function applyDebugSettings(tile, tileset, frameState) {
if (!frameState.passes.render) {
return;
}

var hasContentBoundingVolume = defined(tile._header.content) && defined(tile._header.content.boundingVolume);
var empty = tile.hasEmptyContent || tile.hasTilesetContent;

Expand Down
82 changes: 43 additions & 39 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ define([
this._modelMatrix = defined(options.modelMatrix) ? Matrix4.clone(options.modelMatrix) : Matrix4.clone(Matrix4.IDENTITY);

this._statistics = new Cesium3DTilesetStatistics();
this._statisticsLastColor = new Cesium3DTilesetStatistics();
this._statisticsLastRender = new Cesium3DTilesetStatistics();
this._statisticsLastPick = new Cesium3DTilesetStatistics();

this._tilesLoaded = false;
Expand Down Expand Up @@ -1461,7 +1461,7 @@ define([
destroySubtree(tileset, tile);
} else {
statistics.decrementLoadCounts(tile.content);
--tileset._statistics.numberOfTilesWithContentReady;
--statistics.numberOfTilesWithContentReady;
}
}

Expand Down Expand Up @@ -1689,6 +1689,8 @@ define([
function updateTiles(tileset, frameState) {
tileset._styleEngine.applyStyle(tileset, frameState);

var passes = frameState.passes;
var isRender = passes.render;
var statistics = tileset._statistics;
var commandList = frameState.commandList;
var numberOfInitialCommands = commandList.length;
Expand All @@ -1713,7 +1715,9 @@ define([
tile = selectedTiles[i];
// Raise the tileVisible event before update in case the tileVisible event
// handler makes changes that update needs to apply to WebGL resources
tileVisible.raiseEvent(tile);
if (isRender) {
tileVisible.raiseEvent(tile);
}
tile.update(tileset, frameState);
statistics.incrementSelectionCounts(tile.content);
++statistics.selected;
Expand All @@ -1723,8 +1727,7 @@ define([
tile.update(tileset, frameState);
}

var lengthAfterUpdate = commandList.length;
var addedCommandsLength = lengthAfterUpdate - lengthBeforeUpdate;
var addedCommandsLength = commandList.length - lengthBeforeUpdate;

tileset._backfaceCommands.trim();

Expand Down Expand Up @@ -1770,30 +1773,33 @@ define([
}

// Number of commands added by each update above
statistics.numberOfCommands = (commandList.length - numberOfInitialCommands);
addedCommandsLength = commandList.length - numberOfInitialCommands;
statistics.numberOfCommands = addedCommandsLength;

// Only run EDL if simple attenuation is on
if (tileset.pointCloudShading.attenuation &&
if (isRender &&
tileset.pointCloudShading.attenuation &&
tileset.pointCloudShading.eyeDomeLighting &&
(addedCommandsLength > 0)) {
tileset._pointCloudEyeDomeLighting.update(frameState, numberOfInitialCommands, tileset.pointCloudShading);
}

if (tileset.debugShowGeometricError || tileset.debugShowRenderingStatistics || tileset.debugShowMemoryUsage || tileset.debugShowUrl) {
if (!defined(tileset._tileDebugLabels)) {
tileset._tileDebugLabels = new LabelCollection();
if (isRender) {
if (tileset.debugShowGeometricError || tileset.debugShowRenderingStatistics || tileset.debugShowMemoryUsage || tileset.debugShowUrl) {
if (!defined(tileset._tileDebugLabels)) {
tileset._tileDebugLabels = new LabelCollection();
}
updateTileDebugLabels(tileset, frameState);
} else {
tileset._tileDebugLabels = tileset._tileDebugLabels && tileset._tileDebugLabels.destroy();
}
updateTileDebugLabels(tileset, frameState);
} else {
tileset._tileDebugLabels = tileset._tileDebugLabels && tileset._tileDebugLabels.destroy();
}
}

var scratchStack = [];

function destroySubtree(tileset, tile) {
var root = tile;
var statistics = tileset._statistics;
var stack = scratchStack;
stack.push(tile);
while (stack.length > 0) {
Expand All @@ -1805,7 +1811,7 @@ define([
}
if (tile !== root) {
destroyTile(tileset, tile);
--statistics.numberOfTilesTotal;
--tileset._statistics.numberOfTilesTotal;
}
}
root.children = [];
Expand Down Expand Up @@ -1844,7 +1850,7 @@ define([

function raiseLoadProgressEvent(tileset, frameState) {
var statistics = tileset._statistics;
var statisticsLast = tileset._statisticsLastColor;
var statisticsLast = tileset._statisticsLastRender;
var numberOfPendingRequests = statistics.numberOfPendingRequests;
var numberOfTilesProcessing = statistics.numberOfTilesProcessing;
var lastNumberOfPendingRequest = statisticsLast.numberOfPendingRequests;
Expand Down Expand Up @@ -1904,12 +1910,11 @@ define([

this._skipLevelOfDetail = this.skipLevelOfDetail && !defined(this._classificationType) && !this._disableSkipLevelOfDetail && !this._allTilesAdditive;

// Do not do out-of-core operations (new content requests, cache removal,
// process new tiles) during the pick pass.
// Do out-of-core operations (new content requests, cache removal,
// process new tiles) only during the render pass.
var passes = frameState.passes;
var isRender = passes.render;
var isPick = passes.pick;
var outOfCore = isRender;

var statistics = this._statistics;
statistics.clear();
Expand All @@ -1918,42 +1923,41 @@ define([
updateDynamicScreenSpaceError(this, frameState);
}

if (outOfCore) {
if (isRender) {
this._cache.reset();
}

this._requestedTiles.length = 0;
Cesium3DTilesetTraversal.selectTiles(this, frameState);

if (outOfCore) {
if (isRender) {
requestTiles(this);
processTiles(this, frameState);
}

updateTiles(this, frameState);

if (outOfCore) {
if (isRender) {
unloadTiles(this);
}

// Events are raised (added to the afterRender queue) here since promises
// may resolve outside of the update loop that then raise events, e.g.,
// model's readyPromise.
raiseLoadProgressEvent(this, frameState);

// Update last statistics
var statisticsLast = isPick ? this._statisticsLastPick : this._statisticsLastColor;
Cesium3DTilesetStatistics.clone(statistics, statisticsLast);

if (statistics.selected !== 0) {
var credits = this._credits;
if (defined(credits)) {
var length = credits.length;
for (var i = 0; i < length; i++) {
frameState.creditDisplay.addCredit(credits[i]);
// Events are raised (added to the afterRender queue) here since promises
// may resolve outside of the update loop that then raise events, e.g.,
// model's readyPromise.
raiseLoadProgressEvent(this, frameState);

if (statistics.selected !== 0) {
var credits = this._credits;
if (defined(credits)) {
var length = credits.length;
for (var i = 0; i < length; i++) {
frameState.creditDisplay.addCredit(credits[i]);
}
}
}
}

// Update last statistics
var statisticsLast = isPick ? this._statisticsLastPick : this._statisticsLastRender;
Cesium3DTilesetStatistics.clone(statistics, statisticsLast);
};

/**
Expand Down
Loading