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

Distance display conditions #4309

Merged
merged 39 commits into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
960234f
Add distance display conditions to geometry primitives.
bagnell Sep 8, 2016
28bf84c
Add distance display conditions to billboards.
bagnell Sep 8, 2016
396548a
Add distance display conditions to labels.
bagnell Sep 8, 2016
f19aa4d
Add distance display condition to point primitives.
bagnell Sep 8, 2016
108cdcf
Add development Sandcastle example.
bagnell Sep 9, 2016
d27b1ad
Merge branch 'master' into distance-display-condition
bagnell Sep 9, 2016
b7a3997
Add DistanceDisplayCondition and DistanceDisplayConditionGeometryInst…
bagnell Sep 9, 2016
9efeb5a
Add distance display condition tests for billboards, points and labels.
bagnell Sep 9, 2016
00a2e10
Add model distance display condition tests.
bagnell Sep 12, 2016
366522b
Fix distance display conditions for primitives in 2D.
bagnell Sep 12, 2016
91d56c1
Add tests for primitives with distance display conditions.
bagnell Sep 12, 2016
0035a66
Add DistanceDisplayCondition.clone and have models, billboards, point…
bagnell Sep 12, 2016
e1ee9fe
Add entity support for distance display conditions to labels, billboa…
bagnell Sep 12, 2016
9ed2ab0
Modify GroundPrimitive shader to support distance display conditions …
bagnell Sep 13, 2016
5a8068c
Add distance display condition support to all entity geometries but p…
bagnell Sep 14, 2016
090f57e
Fix jsHint errors.
bagnell Sep 14, 2016
22c156f
Merge branch 'master' into distance-display-condition
bagnell Sep 19, 2016
d7c442f
Merge branch 'batch-table' into distance-display-condition
bagnell Sep 19, 2016
93d8d4b
Add distance display conditions to polylines.
bagnell Sep 20, 2016
b768d5a
Merge branch 'batch-table' into distance-display-condition
bagnell Sep 20, 2016
71df48c
Fixes after merge.
bagnell Sep 20, 2016
500c400
Fix normalized unsigned byte attributes when using a floating point t…
bagnell Sep 20, 2016
953b963
Add polyline distance display condition test.
bagnell Sep 20, 2016
017db41
Add distance display condition support to path and polyline entities.
bagnell Sep 20, 2016
e8a2be8
Merge branch 'master' into distance-display-condition
bagnell Sep 22, 2016
f7f8192
Merge branch 'batch-table-primitive' into distance-display-condition
bagnell Sep 26, 2016
29905a0
Update after merge and make distance display conditions use the batch…
bagnell Sep 26, 2016
74f73a5
Check for 3D only when generating the shader function for getting the…
bagnell Sep 26, 2016
0138c83
Add distance display condition Sandcastle example that uses entities.
bagnell Sep 26, 2016
17b3956
Merge branch 'batch-table-primitive' into distance-display-condition
bagnell Sep 26, 2016
4d28c69
Updates from review.
bagnell Sep 26, 2016
189aa65
Update all distance display condition documentation.
bagnell Sep 27, 2016
0d79c09
Merge branch 'master' into distance-display-condition
bagnell Sep 27, 2016
ac57dbd
Update CHANGES.md.
bagnell Sep 27, 2016
34a2d6c
Add missing distance display condition option doc to model constructor.
bagnell Sep 27, 2016
a72dfd1
Fix model distance display conditions in 2D/CV.
bagnell Sep 28, 2016
380bbf6
Update ellipsoid distance display condition when it changes for dynam…
bagnell Sep 28, 2016
1ea0f48
Merge branch 'master' into distance-display-condition
bagnell Sep 29, 2016
6dedebe
Update GroundPrimitive distance display condition test.
bagnell Sep 29, 2016
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
103 changes: 103 additions & 0 deletions Apps/Sandcastle/gallery/Distance Display Conditions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Distance display conditions">
<meta name="cesium-sandcastle-labels" content="Showcases">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');

function addBillboardAndRectangle() {
Sandcastle.declare(addBillboardAndRectangle);

viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-77, 40.5),
billboard : {
image : '../images/facility.gif',
distanceDisplayCondition : new Cesium.DistanceDisplayCondition(5.5e6)
},
rectangle : {
coordinates : Cesium.Rectangle.fromDegrees(-80.5, 39.7, -75.1, 42.0),
height : 0.0,
material : Cesium.Color.RED.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.RED,
distanceDisplayCondition : new Cesium.DistanceDisplayCondition(0.0, 5.5e6)
}
});
}

function addPointAndModel() {
Sandcastle.declare(addPointAndModel);

var position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, 0.0);
var heading = Cesium.Math.toRadians(135);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, heading, 0.0, 0.0);

viewer.entities.add({
position : position,
orientation : orientation,
point : {
pixelSize : 10,
color : Cesium.Color.YELLOW,
distanceDisplayCondition : new Cesium.DistanceDisplayCondition(250.5)
},
model : {
uri : '../../SampleData/models/CesiumGround/Cesium_Ground.glb',
distanceDisplayCondition : new Cesium.DistanceDisplayCondition(0.0, 250.5)
}
});
}

Sandcastle.addToolbarMenu([{
text : 'Billboard and Primitive',
onselect : function() {
addBillboardAndRectangle();
Sandcastle.highlight(addBillboardAndRectangle);
}
}, {
text : 'Point and Model',
onselect : function() {
addPointAndModel();
Sandcastle.highlight(addPointAndModel);
}
}]);

Sandcastle.reset = function () {
viewer.camera.flyHome(0);
viewer.entities.removeAll();
};

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions Apps/Sandcastle/gallery/development/Display Conditions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Display conditions">
<meta name="cesium-sandcastle-labels" content="Development">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

function addBillboardAndPrimitive() {
Sandcastle.declare(addBillboardAndPrimitive);

var billboards = scene.primitives.add(new Cesium.BillboardCollection());
billboards.add({
image : '../images/facility.gif',
position : Cesium.Cartesian3.fromDegrees(-77, 40.5),
distanceDisplayCondition : new Cesium.DistanceDisplayCondition(5.5e6)
});

scene.primitives.add(new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(-80.5, 39.7, -75.1, 42.0),
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
}),
attributes: {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.5)),
distanceDisplayCondition : new Cesium.DistanceDisplayConditionGeometryInstanceAttribute(0.0, 5.5e6)
}
}),
appearance : new Cesium.PerInstanceColorAppearance({
closed : true
})
}));
}

function addPointAndModel() {
Sandcastle.declare(addPointAndModel);

var position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);

var pointPrimitives = scene.primitives.add(new Cesium.PointPrimitiveCollection());
pointPrimitives.add({
color : Cesium.Color.YELLOW,
position : position,
distanceDisplayCondition : new Cesium.DistanceDisplayCondition(250.5)
});

scene.primitives.add(Cesium.Model.fromGltf({
url : '../../SampleData/models/CesiumGround/Cesium_Ground.glb',
modelMatrix : Cesium.Transforms.eastNorthUpToFixedFrame(position),
distanceDisplayCondition : new Cesium.DistanceDisplayCondition(0.0, 250.5)
}));
}

Sandcastle.addToolbarMenu([{
text : 'Billboard and Primitive',
onselect : function() {
addBillboardAndPrimitive();
Sandcastle.highlight(addBillboardAndPrimitive);
}
}, {
text : 'Point and Model',
onselect : function() {
addPointAndModel();
Sandcastle.highlight(addPointAndModel);
}
}]);

Sandcastle.reset = function () {
viewer.camera.flyHome(0);
scene.primitives.removeAll();
};

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Change Log
* Fixed a bug in `AttributeCompression.compressTextureCoordinates` and `decompressTextureCoordinates` that could cause a small inaccuracy in the encoded texture coordinates.
* Added `DebugCameraPrimitive` to visualize the view frustum of a camera.
* Added support for clustering `Billboard`, `Label` and `Point` entities. [#4240](https://github.com/AnalyticalGraphicsInc/cesium/pull/4240)
* Added `DistanceDisplayCondition`s to all primitives to determine the range interval from the camera for when it will be visible.

### 1.25 - 2016-09-01

Expand Down
123 changes: 123 additions & 0 deletions Source/Core/DistanceDisplayCondition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*global define*/
define([
'./Cartesian3',
'./defaultValue',
'./defined',
'./defineProperties'
], function(
Cartesian3,
defaultValue,
defined,
defineProperties) {
'use strict';

/**
* Determines visibility based on the distance to the camera.
*
* @alias DistanceDisplayCondition
* @constructor
*
* @param {Number} [near=0.0] The smallest distance in the interval where the object is visible.
* @param {Number} [far=Number.MAX_VALUE] The largest distance in the interval where the object is visible.
*
* @example
* // Make a billboard that is only visible when the distance to the camera is between 10 and 20 meters.
* billboard.distanceDisplayCondition = new DistanceDisplayCondition(10.0 20.0);
*/
function DistanceDisplayCondition(near, far) {
near = defaultValue(near, 0.0);
this._near = near;

far = defaultValue(far, Number.MAX_VALUE);
this._far = far;
}

defineProperties(DistanceDisplayCondition.prototype, {
/**
* The smallest distance in the interval where the object is visible.
* @memberof DistanceDisplayCondition.prototype
* @type {Number}
* @default 0.0
*/
near : {
get : function() {
return this._near;
},
set : function(value) {
this._near = value;
}
},
/**
* The largest distance in the interval where the object is visible.
* @memberof DistanceDisplayCondition.prototype
* @type {Number}
* @default Number.MAX_VALUE
*/
far : {
get : function() {
return this._far;
},
set : function(value) {
this._far = value;
}
}
});

/**
* Determines if two distance display conditions are equal.
*
* @param {DistanceDisplayCondition} left A distance display condition.
* @param {DistanceDisplayCondition} right Another distance display condition.
* @return {Boolean} Whether the two distance display conditions are equal.
*/
DistanceDisplayCondition.equals = function(left, right) {
return left === right ||
(defined(left) &&
defined(right) &&
left.near === right.near &&
left.far === right.far);
};

/**
* Duplicates a distance display condition instance.
*
* @param {DistanceDisplayCondition} [value] The distance display condition to duplicate.
* @param {DistanceDisplayCondition} [result] The result onto which to store the result.
* @return {DistanceDisplayCondition} The duplicated instance.
*/
DistanceDisplayCondition.clone = function(value, result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is used directly by the Entity api as well, it should have a prototype clone too. Right now the Entity API ends up making a new instance every time get value is called because no prototype clone is defined.

if (!defined(value)) {
return undefined;
}

if (!defined(result)) {
result = new DistanceDisplayCondition();
}

result.near = value.near;
result.far = value.far;
return result;
};

/**
* Duplicates this instance.
*
* @param {DistanceDisplayCondition} [result] The result onto which to store the result.
* @return {DistanceDisplayCondition} The duplicated instance.
*/
DistanceDisplayCondition.prototype.clone = function(result) {
return DistanceDisplayCondition.clone(this, result);
};

/**
* Determines if this distance display condition is equal to another.
*
* @param {DistanceDisplayCondition} other Another distance display condition.
* @return {Boolean} Whether this distance display condition is equal to the other.
*/
DistanceDisplayCondition.prototype.equals = function(other) {
return DistanceDisplayCondition.equals(this, other);
};

return DistanceDisplayCondition;
});
Loading