Skip to content

Commit

Permalink
Merge pull request #4309 from AnalyticalGraphicsInc/distance-display-…
Browse files Browse the repository at this point in the history
…condition

Distance display conditions
  • Loading branch information
mramato authored Sep 29, 2016
2 parents 5a4b5ea + 6dedebe commit f1a5ff4
Show file tree
Hide file tree
Showing 91 changed files with 2,685 additions and 136 deletions.
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) {
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

0 comments on commit f1a5ff4

Please sign in to comment.