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

Support for model outlining #4314

Merged
merged 42 commits into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9f58e9c
Working on drawing highlighted models
jasonbeverage Aug 31, 2016
de364e9
Changed demo to be able to modify the highlight size
jasonbeverage Aug 31, 2016
cea7291
Better outlining algorithm
jasonbeverage Aug 31, 2016
c72757b
Documentation and slight tweaks
jasonbeverage Sep 1, 2016
b8a2c44
Changed Cartesian4 to Color
jasonbeverage Sep 1, 2016
6a532d1
Making vertex shader for highlighting more generic, works with animat…
jasonbeverage Sep 1, 2016
2362111
Terrible code for looking up the projection matrix uniform name
jasonbeverage Sep 1, 2016
aa759ac
Merge branch 'master' into modelhighlight
jasonbeverage Sep 8, 2016
590bafc
Spelling and added a highlightCommand2D
jasonbeverage Sep 8, 2016
73d9fb2
Comment
jasonbeverage Sep 9, 2016
116bdfc
Moved outline example to it's own sandcastle example and reverted the…
jasonbeverage Sep 9, 2016
fa23733
Fix jshint issues
jasonbeverage Sep 13, 2016
751fbda
Added new getUniformNameForSemantic function
jasonbeverage Sep 13, 2016
f41bb6e
Changed the highlightSize parameter to be in pixels instead of clip s…
jasonbeverage Sep 13, 2016
36f046d
Simplified highlight shader just using cesium builtins
jasonbeverage Sep 13, 2016
d247a65
Merge branch 'master' into modelhighlight
jasonbeverage Sep 13, 2016
32d74a1
Merge branch 'master' into modelhighlight
jasonbeverage Oct 17, 2016
af86c9a
Defaulting highlight to true in 3D Models Outline example. Changed h…
jasonbeverage Oct 17, 2016
817da19
Changed highlightColor default to default constructed color and highl…
jasonbeverage Oct 17, 2016
a492379
Changed hilightSize default to 2.0 in Model.js and highlightColor to …
jasonbeverage Oct 17, 2016
20a7149
Removed extra whitespace
jasonbeverage Oct 17, 2016
d98e0ea
Not setting face in highlightRS, just enabled: false
jasonbeverage Oct 17, 2016
aa62d4d
Whitespace
jasonbeverage Oct 17, 2016
c2a8ed1
Whitespace
jasonbeverage Oct 17, 2016
df36205
Enabling ALPHA_BLEND blending on highlight state
jasonbeverage Oct 17, 2016
fa3c2e9
Added opacity slider to 3D Models Outline demo.
jasonbeverage Oct 17, 2016
1bcce58
Explicitly requesting a stencil buffer in the 3D Models Outline demo …
jasonbeverage Oct 17, 2016
fee0674
Only rendering highlight commands if stencilBits is greater than 0, o…
jasonbeverage Oct 17, 2016
508b14d
ModelGraphicSpec tests for model highlighting
jasonbeverage Oct 17, 2016
1c33371
Model testing
jasonbeverage Oct 17, 2016
bd77f27
Merge branch 'master' into modelhighlight
lilleyse Dec 6, 2016
5f93bf1
Reorganized silhouetting
lilleyse Dec 6, 2016
93d4e68
Prevent divide-by-zero during unpremultiply
lilleyse Dec 7, 2016
d7ae242
Issue clear command
lilleyse Dec 7, 2016
5e1e9cf
More accurate translucencly check
lilleyse Dec 8, 2016
246dc83
Fix spec
lilleyse Dec 8, 2016
60caefa
Change order of stencilReference
lilleyse Dec 8, 2016
11fc0da
Doc and stencil clear after ground pass
lilleyse Dec 12, 2016
cb35414
No longer hardcoding v_normal
lilleyse Dec 12, 2016
95d024e
Updated CHANGES.md
lilleyse Dec 12, 2016
077e225
Added tests
lilleyse Dec 12, 2016
7a399f2
Merge branch 'master' into modelhighlight
lilleyse Dec 13, 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
155 changes: 155 additions & 0 deletions Apps/Sandcastle/gallery/development/3D Models Outline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!DOCTYPE html>
Copy link
Contributor

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.

<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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Default this to true so the example is obvious as soon as it loads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Apps/Sandcastle/gallery/development/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Copy link
Contributor

Choose a reason for hiding this comment

The 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';
Expand Down
38 changes: 37 additions & 1 deletion Source/DataSources/ModelGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just default this to the default constructed color?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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')
});

/**
Expand All @@ -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;
};
Expand Down Expand Up @@ -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)) {
Expand Down
8 changes: 8 additions & 0 deletions Source/DataSources/ModelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define([
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Matrix4',
'../Core/Color',
'../Scene/HeightReference',
'../Scene/Model',
'../Scene/ModelAnimationLoop',
Expand All @@ -19,6 +20,7 @@ define([
destroyObject,
DeveloperError,
Matrix4,
Color,
HeightReference,
Model,
ModelAnimationLoop,
Expand All @@ -32,6 +34,9 @@ define([
var defaultIncrementallyLoadTextures = true;
var defaultShadows = ShadowMode.ENABLED;
var defaultHeightReference = HeightReference.NONE;
var defaultHighlightColor = new Color(1.0, 0.0, 0.0, 1.0);
var defaultHighlightSize = 0.002;
var defaultHighlight = false;

var modelMatrixScratch = new Matrix4();
var nodeMatrixScratch = new Matrix4();
Expand Down Expand Up @@ -147,6 +152,9 @@ define([
model.modelMatrix = Matrix4.clone(modelMatrix, model.modelMatrix);
model.shadows = shadows;
model.heightReference = Property.getValueOrDefault(modelGraphics._heightReference, time, defaultHeightReference);
model.highlight = Property.getValueOrDefault(modelGraphics.highlight, time, defaultHighlight);
model.highlightColor = Property.getValueOrDefault(modelGraphics.highlightColor, time, defaultHighlightColor);
model.highlightSize = Property.getValueOrDefault(modelGraphics.highlightSize, time, defaultHighlightSize);

if (model.ready) {
var runAnimations = Property.getValueOrDefault(modelGraphics._runAnimations, time, true);
Expand Down
Loading