-
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
Support for model outlining #4314
Changes from 16 commits
9f58e9c
de364e9
cea7291
c72757b
b8a2c44
6a532d1
2362111
aa759ac
590bafc
73d9fb2
116bdfc
fa23733
751fbda
f41bb6e
36f046d
d247a65
32d74a1
af86c9a
817da19
a492379
20a7149
d98e0ea
aa62d4d
c2a8ed1
df36205
fa3c2e9
1bcce58
fee0674
508b14d
1c33371
bd77f27
5f93bf1
93d4e68
d7ae242
5e1e9cf
246dc83
60caefa
11fc0da
cb35414
95d024e
077e225
7a399f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<!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="Create 3D models using glTF."> | ||
<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); | ||
#toolbar { | ||
background: rgba(42, 42, 42, 0.8); | ||
padding: 4px; | ||
border-radius: 4px; | ||
} | ||
#toolbar input { | ||
vertical-align: middle; | ||
padding-top: 2px; | ||
padding-bottom: 2px; | ||
} | ||
</style> | ||
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"><h1>Loading...</h1></div> | ||
<div id="toolbar"> | ||
<table> | ||
<tbody><tr> | ||
<td>Highlight Size</td> | ||
<td> | ||
<input type="range" min="0" max="20" step="1" data-bind="value: highlightSize, valueUpdate: 'input'"> | ||
<input type="text" size="5" data-bind="value: highlightSize"> | ||
</td> | ||
</tr> | ||
|
||
</tbody></table> | ||
</div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
//Sandcastle_Begin | ||
var viewer = new Cesium.Viewer('cesiumContainer', { | ||
infoBox : false, | ||
selectionIndicator : false, | ||
shadows : true | ||
}); | ||
|
||
var entity = null; | ||
|
||
// The viewModel tracks the state of our mini application. | ||
var viewModel = { | ||
highlight: false, | ||
highlightSize: 2 | ||
}; | ||
|
||
// Convert the viewModel members into knockout observables. | ||
Cesium.knockout.track(viewModel); | ||
|
||
// Bind the viewModel to the DOM elements of the UI that call for it. | ||
var toolbar = document.getElementById('toolbar'); | ||
Cesium.knockout.applyBindings(viewModel, toolbar); | ||
|
||
|
||
function createModel(url, height) { | ||
viewer.entities.removeAll(); | ||
|
||
var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height); | ||
var heading = Cesium.Math.toRadians(135); | ||
var pitch = 0; | ||
var roll = 0; | ||
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, heading, pitch, roll); | ||
|
||
entity = viewer.entities.add({ | ||
name : url, | ||
position : position, | ||
orientation : orientation, | ||
model : { | ||
uri : url, | ||
minimumPixelSize : 128, | ||
maximumScale : 20000, | ||
highlight: viewModel.highlight, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
highlightSize: viewModel.highlightSize | ||
} | ||
}); | ||
viewer.trackedEntity = entity; | ||
} | ||
|
||
var options = [{ | ||
text : 'Aircraft', | ||
onselect : function() { | ||
createModel('../../SampleData/models/CesiumAir/Cesium_Air.glb', 5000.0); | ||
} | ||
}, { | ||
text : 'Ground vehicle', | ||
onselect : function() { | ||
createModel('../../SampleData/models/CesiumGround/Cesium_Ground.glb', 0); | ||
} | ||
}, { | ||
text : 'Hot Air Balloon', | ||
onselect : function() { | ||
createModel('../../SampleData/models/CesiumBalloon/CesiumBalloon.glb', 1000.0); | ||
} | ||
}, { | ||
text : 'Milk truck', | ||
onselect : function() { | ||
createModel('../../SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.glb', 0); | ||
} | ||
}, { | ||
text : 'Skinned character', | ||
onselect : function() { | ||
createModel('../../SampleData/models/CesiumMan/Cesium_Man.glb', 0); | ||
} | ||
}]; | ||
|
||
Sandcastle.addToolbarMenu(options); | ||
|
||
Sandcastle.addToolbarButton('Toggle Highlight', function() { | ||
viewModel.highlight = !viewModel.highlight; | ||
entity.model.highlight = new Cesium.ConstantProperty(viewModel.highlight); | ||
}); | ||
|
||
Sandcastle.addToolbarButton('Change Highlight Color', function() { | ||
entity.model.highlightColor = new Cesium.ConstantProperty(Cesium.Color.fromRandom({ | ||
alpha : 1.0 | ||
})); | ||
}); | ||
|
||
Cesium.knockout.getObservable(viewModel, "highlightSize").subscribe( | ||
function(newValue) { | ||
entity.model.highlightSize = newValue; | ||
} | ||
); | ||
|
||
|
||
|
||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== "undefined") { | ||
startup(Cesium); | ||
} else if (typeof require === "function") { | ||
require(["Cesium"], startup); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ | |
</style> | ||
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"><h1>Loading...</h1></div> | ||
<div id="toolbar"></div> | ||
<div id="toolbar"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Undo this change. |
||
Hello | ||
</div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,9 @@ define([ | |
* @param {Property} [options.receiveShadows=true] Deprecated, use options.shadows instead. A boolean Property specifying whether the model receives shadows from shadow casters in the scene. | ||
* @param {Property} [options.shadows=ShadowMode.ENABLED] An enum Property specifying whether the model casts or receives shadows from each light source. | ||
* @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to. | ||
* @param {Property} [options.highlight=false] Whether to highlight the model using an outline | ||
* @param {Property} [options.highlightColor=Color(1.0, 0.0, 0.0, 1.0)] The highlight color for the outline. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just default this to the default constructed color? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
* @param {Property} [options.highlightSize=0.002] The highlight color for the outline. | ||
* | ||
* @see {@link http://cesiumjs.org/2014/03/03/Cesium-3D-Models-Tutorial/|3D Models Tutorial} | ||
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=3D%20Models.html|Cesium Sandcastle 3D Models Demo} | ||
|
@@ -80,6 +83,9 @@ define([ | |
this._nodeTransformationsSubscription = undefined; | ||
this._heightReference = undefined; | ||
this._heightReferenceSubscription = undefined; | ||
this._highlight = undefined; | ||
this._highlightColor = undefined; | ||
this._highlightSize = undefined; | ||
this._definitionChanged = new Event(); | ||
|
||
this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); | ||
|
@@ -200,7 +206,31 @@ define([ | |
* @type {Property} | ||
* @default HeightReference.NONE | ||
*/ | ||
heightReference : createPropertyDescriptor('heightReference') | ||
heightReference : createPropertyDescriptor('heightReference'), | ||
|
||
/** | ||
* Gets or sets the boolean Property specifying whether this model should be highlighted or not. | ||
* @memberof ModelGraphics.prototype | ||
* @type {Property} | ||
* @default false | ||
*/ | ||
highlight: createPropertyDescriptor('highlight'), | ||
|
||
/** | ||
* Gets or sets the Color Property specifying the highlight color of this model. | ||
* @memberof ModelGraphics.prototype | ||
* @type {Property} | ||
* @default Color(1.0,0.0,1.0,1.0) | ||
*/ | ||
highlightColor: createPropertyDescriptor('highlightColor'), | ||
|
||
/** | ||
* Gets or sets the float Property specifying the size of the highlight of this model. | ||
* @memberof ModelGraphics.prototype | ||
* @type {Property} | ||
* @default 0.002 | ||
*/ | ||
highlightSize: createPropertyDescriptor('highlightSize') | ||
}); | ||
|
||
/** | ||
|
@@ -225,6 +255,9 @@ define([ | |
result.runAnimations = this.runAnimations; | ||
result.nodeTransformations = this.nodeTransformations; | ||
result.heightReference = this._heightReference; | ||
result.highlight = this.highlight; | ||
result.highlightColor = this.highlightColor; | ||
result.highlightSize = this.highlightSize; | ||
|
||
return result; | ||
}; | ||
|
@@ -253,6 +286,9 @@ define([ | |
this.uri = defaultValue(this.uri, source.uri); | ||
this.runAnimations = defaultValue(this.runAnimations, source.runAnimations); | ||
this.heightReference = defaultValue(this.heightReference, source.heightReference); | ||
this.highlight = defaultValue(this.highlight, source.highlight); | ||
this.highlightColor = defaultValue(this.highlightColor, source.highlightColor); | ||
this.highlightSize = defaultValue(this.highlightSize, source.highlightSize); | ||
|
||
var sourceNodeTransformations = source.nodeTransformations; | ||
if (defined(sourceNodeTransformations)) { | ||
|
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.
@lilleyse it could be cool to combine this example with #4547 and then fade in/out both coloring the model and exlarging the silhouette over time. Tweens are not part of the public API so we might want to expose them if time permits.