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 29 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>
113 changes: 113 additions & 0 deletions Source/Core/DistanceDisplayCondition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*global define*/
define([
'./Cartesian3',
'./defaultValue',
'./defined',
'./defineProperties',
'./Matrix4'
], function(
Cartesian3,
defaultValue,
defined,
defineProperties,
Matrix4) {
'use strict';

/**
* DOC_TBA
*
* @alias DistanceDisplayCondition
* @constructor
*/
function DistanceDisplayCondition(near, far) {
near = defaultValue(near, 0.0);
this._near = near;
this._near2 = near * near;

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

defineProperties(DistanceDisplayCondition.prototype, {
/**
* DOC_TBA
* @memberof DistanceDisplayCondition.prototype
* @type {Number}
*/
near : {
get : function() {
return this._near;
},
set : function(value) {
this._near = value;
this._near2 = value * value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicky, but as a generate practice, we would normally call this nearSquared.

}
},
/**
* DOC_TBA
* @memberof DistanceDisplayCondition.prototype
* @type {Number}
*/
far : {
get : function() {
return this._far;
},
set : function(value) {
this._far = value;
this._far2 = value * value;
}
}
});

var scratchPosition = new Cartesian3();

/**
* DOC_TBA
*/
DistanceDisplayCondition.prototype.isVisible = function(primitive, frameState) {
// TODO: need to consider positions, e.g., for a polyline

// Distance to center of primitive's reference frame
var position = Matrix4.getTranslation(primitive.modelMatrix, scratchPosition);
var distance2 = Cartesian3.distanceSquared(position, frameState.camera.positionWC);
return (distance2 >= this._near2) && (distance2 <= this._far2);
};

/**
* DOC_TBA
*/
DistanceDisplayCondition.equals = function(left, right) {
return left === right ||
(defined(left) &&
defined(right) &&
left.near === right.near &&
left.far === right.far);
};

/**
* DOC_TBA
*/
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;
};

/**
* DOC_TBA
*/
DistanceDisplayCondition.prototype.equals = function(other) {
return DistanceDisplayCondition.equals(this, other);
};

return DistanceDisplayCondition;
});
Loading