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 7 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
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>
89 changes: 89 additions & 0 deletions Source/Core/DistanceDisplayCondition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*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);
};

return DistanceDisplayCondition;
});
161 changes: 161 additions & 0 deletions Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*global define*/
define([
'./ComponentDatatype',
'./defaultValue',
'./defined',
'./defineProperties',
'./DeveloperError'
], function(
ComponentDatatype,
defaultValue,
defined,
defineProperties,
DeveloperError) {
'use strict';

/**
* Value and type information for per-instance geometry attribute that determines if the geometry instance has a distance display condition.
*
* @alias DistanceDisplayConditionGeometryInstanceAttribute
* @constructor
*
* @param {Number} [near=0.0] The near distance.
* @param {Number} [far=Number.MAX_VALUE] The far distance.
*
* @example
* var instance = new Cesium.GeometryInstance({
* geometry : new Cesium.BoxGeometry({
* vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
* minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0),
* maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0)
* }),
* modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
* Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
* id : 'box',
* attributes : {
* show : new Cesium.DistanceDisplayConditionGeometryInstanceAttribute(100.0, 10000.0)
* }
* });
*
* @see GeometryInstance
* @see GeometryInstanceAttribute
*/
function DistanceDisplayConditionGeometryInstanceAttribute(near, far) {
near = defaultValue(near, 0.0);
far = defaultValue(far, Number.MAX_VALUE);

/**
* The values for the attributes stored in a typed array.
*
* @type Float32Array
*
* @default [0.0, 0.0, Number.MAX_VALUE]
*/
this.value = new Float32Array([near, far]);
}

defineProperties(DistanceDisplayConditionGeometryInstanceAttribute.prototype, {
/**
* The datatype of each component in the attribute, e.g., individual elements in
* {@link DistanceDisplayConditionGeometryInstanceAttribute#value}.
*
* @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype
*
* @type {ComponentDatatype}
* @readonly
*
* @default {@link ComponentDatatype.FLOAT}
*/
componentDatatype : {
get : function() {
return ComponentDatatype.FLOAT;
}
},

/**
* The number of components in the attributes, i.e., {@link DistanceDisplayConditionGeometryInstanceAttribute#value}.
*
* @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype
*
* @type {Number}
* @readonly
*
* @default 3
*/
componentsPerAttribute : {
get : function() {
return 2;
}
},

/**
* When <code>true</code> and <code>componentDatatype</code> is an integer format,
* indicate that the components should be mapped to the range [0, 1] (unsigned)
* or [-1, 1] (signed) when they are accessed as floating-point for rendering.
*
* @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype
*
* @type {Boolean}
* @readonly
*
* @default false
*/
normalize : {
get : function() {
return false;
}
}
});

/**
* Creates a new {@link DistanceDisplayConditionGeometryInstanceAttribute} instance given the provided an enabled flag and {@link DistanceDisplayCondition}.
*
* @param {DistanceDisplayCondition} distanceDisplayCondition The distance display condition.
* @returns {DistanceDisplayConditionGeometryInstanceAttribute} The new {@link DistanceDisplayConditionGeometryInstanceAttribute} instance.
*
* @example
* var instance = new Cesium.GeometryInstance({
* geometry : geometry,
* attributes : {
* color : Cesium.DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition),
* }
* });
*/
DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition = function(distanceDisplayCondition) {
//>>includeStart('debug', pragmas.debug);
if (!defined(distanceDisplayCondition)) {
throw new DeveloperError('distanceDisplayCondition is required.');
}
//>>includeEnd('debug');

return new DistanceDisplayConditionGeometryInstanceAttribute(distanceDisplayCondition.near, distanceDisplayCondition.far);
};

/**
* Converts a distance display condition to a typed array that can be used to assign a distance display condition attribute.
*
* @param {DistanceDisplayCondition} distanceDisplayCondition The distance display condition value.
* @param {Float32Array} [result] The array to store the result in, if undefined a new instance will be created.
* @returns {Float32Array} The modified result parameter or a new instance if result was undefined.
*
* @example
* var attributes = primitive.getGeometryInstanceAttributes('an id');
* attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition);
*/
DistanceDisplayConditionGeometryInstanceAttribute.toValue = function(distanceDisplayCondition, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(distanceDisplayCondition)) {
throw new DeveloperError('distanceDisplayCondition is required.');
}
//>>includeEnd('debug');

if (!defined(result)) {
return new Float32Array([distanceDisplayCondition.near, distanceDisplayCondition.far]);
}
result[0] = distanceDisplayCondition.near;
result[1] = distanceDisplayCondition.far;
return result;
};

return DistanceDisplayConditionGeometryInstanceAttribute;
});
1 change: 1 addition & 0 deletions Source/Core/GeometryInstanceAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ define([
*
* @see ColorGeometryInstanceAttribute
* @see ShowGeometryInstanceAttribute
* @see DistanceDisplayConditionGeometryInstanceAttribute
*/
function GeometryInstanceAttribute(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
Expand Down
Loading