-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
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 28bf84c
Add distance display conditions to billboards.
bagnell 396548a
Add distance display conditions to labels.
bagnell f19aa4d
Add distance display condition to point primitives.
bagnell 108cdcf
Add development Sandcastle example.
bagnell d27b1ad
Merge branch 'master' into distance-display-condition
bagnell b7a3997
Add DistanceDisplayCondition and DistanceDisplayConditionGeometryInst…
bagnell 9efeb5a
Add distance display condition tests for billboards, points and labels.
bagnell 00a2e10
Add model distance display condition tests.
bagnell 366522b
Fix distance display conditions for primitives in 2D.
bagnell 91d56c1
Add tests for primitives with distance display conditions.
bagnell 0035a66
Add DistanceDisplayCondition.clone and have models, billboards, point…
bagnell e1ee9fe
Add entity support for distance display conditions to labels, billboa…
bagnell 9ed2ab0
Modify GroundPrimitive shader to support distance display conditions …
bagnell 5a8068c
Add distance display condition support to all entity geometries but p…
bagnell 090f57e
Fix jsHint errors.
bagnell 22c156f
Merge branch 'master' into distance-display-condition
bagnell d7c442f
Merge branch 'batch-table' into distance-display-condition
bagnell 93d8d4b
Add distance display conditions to polylines.
bagnell b768d5a
Merge branch 'batch-table' into distance-display-condition
bagnell 71df48c
Fixes after merge.
bagnell 500c400
Fix normalized unsigned byte attributes when using a floating point t…
bagnell 953b963
Add polyline distance display condition test.
bagnell 017db41
Add distance display condition support to path and polyline entities.
bagnell e8a2be8
Merge branch 'master' into distance-display-condition
bagnell f7f8192
Merge branch 'batch-table-primitive' into distance-display-condition
bagnell 29905a0
Update after merge and make distance display conditions use the batch…
bagnell 74f73a5
Check for 3D only when generating the shader function for getting the…
bagnell 0138c83
Add distance display condition Sandcastle example that uses entities.
bagnell 17b3956
Merge branch 'batch-table-primitive' into distance-display-condition
bagnell 4d28c69
Updates from review.
bagnell 189aa65
Update all distance display condition documentation.
bagnell 0d79c09
Merge branch 'master' into distance-display-condition
bagnell ac57dbd
Update CHANGES.md.
bagnell 34a2d6c
Add missing distance display condition option doc to model constructor.
bagnell a72dfd1
Fix model distance display conditions in 2D/CV.
bagnell 380bbf6
Update ellipsoid distance display condition when it changes for dynam…
bagnell 1ea0f48
Merge branch 'master' into distance-display-condition
bagnell 6dedebe
Update GroundPrimitive distance display condition test.
bagnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
Apps/Sandcastle/gallery/development/Display Conditions.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}, | ||
/** | ||
* 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
161
Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.