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

Use b3dm tilesets for classification #6033

Merged
merged 56 commits into from Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
27972ff
Add option to make a b3dm tileset classify another tileset.
bagnell Dec 1, 2017
b4f367a
Add a separate pass for classification on both terrain and 3D Tiles. …
bagnell Dec 1, 2017
e7ec3be
Optimize b3dm classification fragment shader.
bagnell Dec 1, 2017
2b0f52f
Initial rework.
bagnell Dec 4, 2017
f1ab457
Remove unneeded code.
bagnell Dec 4, 2017
33ff56e
Only create classification commands. Only create basic vertex and fra…
bagnell Dec 4, 2017
7fe3e37
Only use position and batch id attributes.
bagnell Dec 4, 2017
b3993b5
Remove more unneeded code.
bagnell Dec 4, 2017
cc7a228
Remove shader parsing.
bagnell Dec 4, 2017
fad8860
Remove unused uniform semantics.
bagnell Dec 4, 2017
a2a1e2f
Mostly working. Needs clean up. There are issues with model matrices,…
bagnell Dec 5, 2017
0d2f1e1
Fix model matrix.
bagnell Dec 5, 2017
6981a68
Fix rebatching and remove derived commands.
bagnell Dec 5, 2017
e1218d7
Clean up.
bagnell Dec 6, 2017
9173555
Fix test.
bagnell Dec 6, 2017
c1ad375
Revert Sandcastle example.
bagnell Dec 6, 2017
b448116
Remove mesh support from vector tiles.
bagnell Dec 6, 2017
f15d07f
Add Geometry tile.
bagnell Dec 6, 2017
1f8fb07
Remove geometry from vector tile.
bagnell Dec 6, 2017
9c054da
Update point cloud classification example. Tweak geometry tile to pre…
bagnell Dec 6, 2017
db85153
Update Vector tile specs.
bagnell Dec 6, 2017
124d290
Add Geometry3DTileContent tests.
bagnell Dec 6, 2017
1fe9fc8
Remove height reference.
bagnell Dec 6, 2017
8eabdad
Remove more unneeded code.
bagnell Dec 6, 2017
67cdf82
Fix failing test.
bagnell Dec 6, 2017
15b58e4
Remove unused cache.
bagnell Dec 6, 2017
0cefab9
Remove more unneeded code.
bagnell Dec 7, 2017
3e88765
Fix broken test again.
bagnell Dec 7, 2017
bc232cd
Clamp volumes to the far plane.
bagnell Dec 7, 2017
764267a
Add Sandcastle example.
bagnell Dec 7, 2017
00f1792
Updates from review.
bagnell Dec 7, 2017
3ffd232
Merge branch 'vector-tiles' into b3dm-class
bagnell Dec 7, 2017
d377603
Update CHANGES.md after merge.
bagnell Dec 7, 2017
eb07e44
Update Sandcastle tileset url.
bagnell Dec 8, 2017
ea49b72
Remove node hierarchy.
bagnell Dec 8, 2017
12283c4
Update doc.
bagnell Dec 8, 2017
79ed093
Add tests. Fix quantization extension. Remove some more unneeded code.
bagnell Dec 8, 2017
0ab3156
Merge branch 'b3dm-class' into vector-split
bagnell Dec 11, 2017
5fdf1ad
Fix after merge.
bagnell Dec 11, 2017
772a9c3
Updates from review.
bagnell Dec 11, 2017
9fbc848
Merge branch 'b3dm-class' into vector-split
bagnell Dec 11, 2017
612c5f5
Update CHANGES.md.
bagnell Dec 11, 2017
618a892
Merge pull request #6034 from AnalyticalGraphicsInc/vector-split
pjcozzi Dec 12, 2017
d566de4
Remove some code expecting multiple primitives. Move glTF checks to c…
bagnell Dec 12, 2017
045e458
Only create one primitive.
bagnell Dec 12, 2017
6e57010
Don't parse shaders since they are generated.
bagnell Dec 12, 2017
15380ef
Remove runtimeNode.
bagnell Dec 12, 2017
92709e8
Create only one uniform map.
bagnell Dec 12, 2017
36b2b53
Factor out common code.
bagnell Dec 13, 2017
a4c4506
Factor out gltf semantic uniforms.
bagnell Dec 13, 2017
5232f88
Remove unused requires.
bagnell Dec 13, 2017
029abad
Pass debug settings to the vector primitive.
bagnell Dec 13, 2017
1fa1976
Add ClassificationModel tests.
bagnell Dec 13, 2017
8f389cb
Update restrictions in the doc.
bagnell Dec 13, 2017
5f4ed4c
Merge branch 'vector-tiles' into b3dm-class
bagnell Dec 13, 2017
2385d20
Update function name.
bagnell Dec 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Sample photogrammetry and classification datasets both rendered with 3D Tiles.">
<meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles">
<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>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');

var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : 'https://beta.cesium.com/api/assets/1458?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxYmJiNTAxOC1lOTg5LTQzN2EtODg1OC0zMWJjM2IxNGNlYmMiLCJpZCI6NDQsImFzc2V0cyI6WzE0NThdLCJpYXQiOjE0OTkyNjM4MjB9.1WKijRa-ILkmG6utrhDWX6rDgasjD7dZv-G5ZyCmkKg'
}));

tileset.readyPromise.then(function() {
var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
}).otherwise(function(error) {
throw(error);
});

var classification = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this tileset look like without classification. Is it worth adding a comment to say to comment out the classificationType line to see the geometry used to classify?

The other option is to create two tilesets, one with and without the classification, and then change their show via a checkbox, but that could make the example too complex.

url: 'https://beta.cesium.com/api/assets/3486?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzZjM4MjljZi0xNTAzLTQ0MzctODhlZi0zOTU3Njg5ODA1Y2QiLCJpZCI6OCwiaWF0IjoxNDgxODI5ODMyfQ.dYlV8_PoXcFNlPHGook5kMzuJMS-Bb9DCMzI1mFVvgE',
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE,
skipLevelOfDetail : false
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be omitted?

I thought the plan was to update the documentation for skipLevelOfDetail so that it was a "hint" - and then to just implicitly disable it when a tileset is used for classification.

}));

classification.readyPromise.then(function() {
classification.style = new Cesium.Cesium3DTileStyle({
color : 'rgba(255, 0, 0, 0.5)'
});
}).otherwise(function(error) {
throw(error);
});
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/3D Tiles Photogrammetry.html
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="A sample photgrammetry dataset rendered with 3D Tiles.">
<meta name="description" content="A sample photogrammetry dataset rendered with 3D Tiles.">
<meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
Expand Down
14 changes: 7 additions & 7 deletions CHANGES.md
Expand Up @@ -9,6 +9,13 @@ Change Log
* Added `Plane.transformPlane` function to apply a transformation to a plane. [#5966](https://github.com/AnalyticalGraphicsInc/cesium/pull/5966)
* Added `PlaneGeometry`, `PlaneOutlineGeometry`, `PlaneGeometryUpdater`, and `PlaneOutlineGeometryUpdater` classes to render plane primitives. [#5996](https://github.com/AnalyticalGraphicsInc/cesium/pull/5996)
* Added `PlaneGraphics` class and `plane` property to `Entity`. [#5996](https://github.com/AnalyticalGraphicsInc/cesium/pull/5996)
* Added `AttributeCompression.zigZagDeltaDecode` which will decode delta and ZigZag encoded buffers in place.
* Added `pack` and `unpack` functions to `OrientedBoundingBox` for packing to and unpacking from a flat buffer.
* Added experimental support for [3D Tiles Vector Data](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/vector-tiles/TileFormats/VectorData) ([#4665](https://github.com/AnalyticalGraphicsInc/cesium/pull/4665)). The new and modified Cesium APIs are:
* `Cesium3DTileStyle` has expanded for styling point features. See the [styling specification](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/vector-tiles/Styling#vector-data) for details.
* `Cesium3DTileFeature` can modify `color` and `show` properties for polygon, polyline, geometry, and mesh features.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still right? I thought mesh features were removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were removed in the other PR.

* `Cesium3DTilePointFeature` can modify the styling options for a point feature.
* Added `Cesium3DTileset.classificationType` to specify if a tileset classifies terrain, another 3D Tiles tileset, or both. This only applies to vector, geometry and batched 3D model tilesets. See [#6033](https://github.com/AnalyticalGraphicsInc/cesium/pull/6033) for limitations on the glTF contained in the b3dm tile.

### 1.40 - 2017-12-01

Expand All @@ -29,13 +36,6 @@ Change Log
* Added ability to support touch event in Imagery Layers Split Sandcastle example. [#5948](https://github.com/AnalyticalGraphicsInc/cesium/pull/5948)
* Added a new `@experimental` tag to the documentation. A small subset of the Cesium API tagged as such are subject to breaking changes without deprecation. See the [Coding Guide](https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/CodingGuide#deprecation-and-breaking-changes) for further explanation. [#6010](https://github.com/AnalyticalGraphicsInc/cesium/pull/6010)
* Moved terrain and imagery credits to a lightbox that pops up when you click a link in the onscreen credits [#3013](https://github.com/AnalyticalGraphicsInc/cesium/issues/3013)
* Added `AttributeCompression.zigZagDeltaDecode` which will decode delta and ZigZag encoded buffers in place.
* Added `pack` and `unpack` functions to `OrientedBoundingBox` for packing to and unpacking from a flat buffer.
* Added experimental support for [3D Tiles Vector Data](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/vector-tiles/TileFormats/VectorData) ([#4665](https://github.com/AnalyticalGraphicsInc/cesium/pull/4665)). The new and modified Cesium APIs are:
* `Cesium3DTileset.classificationType` to specify if a vector tileset classifies terrain, another 3D Tiles tileset, or both.
* `Cesium3DTileStyle` has expanded for styling point features. See the [styling specification](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/vector-tiles/Styling#vector-data) for details.
* `Cesium3DTileFeature` can modify `color` and `show` properties for polygon, polyline, geometry, and mesh features.
* `Cesium3DTilePointFeature` can modify the styling options for a point feature.

### 1.39 - 2017-11-01

Expand Down
9 changes: 5 additions & 4 deletions Source/Renderer/Pass.js
Expand Up @@ -24,10 +24,11 @@ define([
CESIUM_3D_TILE : 4,
CESIUM_3D_TILE_CLASSIFICATION : 5,
CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW : 6,
OPAQUE : 7,
TRANSLUCENT : 8,
OVERLAY : 9,
NUMBER_OF_PASSES : 10
CLASSIFICATION : 7,
OPAQUE : 8,
TRANSLUCENT : 9,
OVERLAY : 10,
NUMBER_OF_PASSES : 11
};

return freezeObject(Pass);
Expand Down
110 changes: 77 additions & 33 deletions Source/Scene/Batched3DModel3DTileContent.js
Expand Up @@ -16,6 +16,7 @@ define([
'./Cesium3DTileBatchTable',
'./Cesium3DTileFeature',
'./Cesium3DTileFeatureTable',
'./ClassificationModel',
'./ClippingPlaneCollection',
'./getAttributeOrUniformBySemantic',
'./Model'
Expand All @@ -37,6 +38,7 @@ define([
Cesium3DTileBatchTable,
Cesium3DTileFeature,
Cesium3DTileFeatureTable,
ClassificationModel,
ClippingPlaneCollection,
getAttributeOrUniformBySemantic,
Model) {
Expand Down Expand Up @@ -207,8 +209,9 @@ define([
return function(vs) {
var batchTable = content._batchTable;
var gltf = content._model.gltf;
var handleTranslucent = !defined(content._tileset.classificationType);
var batchIdAttributeName = getBatchIdAttributeName(gltf);
var callback = batchTable.getVertexShaderCallback(true, batchIdAttributeName);
var callback = batchTable.getVertexShaderCallback(handleTranslucent, batchIdAttributeName);
return defined(callback) ? callback(vs) : vs;
};
}
Expand All @@ -227,12 +230,27 @@ define([
return function(fs) {
var batchTable = content._batchTable;
var gltf = content._model.gltf;
var handleTranslucent = !defined(content._tileset.classificationType);
var diffuseUniformName = getAttributeOrUniformBySemantic(gltf, '_3DTILESDIFFUSE');
var callback = batchTable.getFragmentShaderCallback(true, diffuseUniformName);
var callback = batchTable.getFragmentShaderCallback(handleTranslucent, diffuseUniformName);
return defined(callback) ? callback(fs) : fs;
};
}

function getClassificationFragmentShaderCallback(content) {
return function(fs) {
var batchTable = content._batchTable;
var callback = batchTable.getClassificationFragmentShaderCallback();
return defined(callback) ? callback(fs) : fs;
};
}

function createColorChangedCallback(content) {
return function(batchId, color) {
content._model.updateCommands(batchId, color);
};
}

function initialize(content, arrayBuffer, byteOffset) {
var tileset = content._tileset;
var tile = content._tile;
Expand Down Expand Up @@ -334,7 +352,12 @@ define([
}
}

var batchTable = new Cesium3DTileBatchTable(content, batchLength, batchTableJson, batchTableBinary);
var colorChangeCallback;
if (defined(tileset.classificationType)) {
colorChangeCallback = createColorChangedCallback(content);
}

var batchTable = new Cesium3DTileBatchTable(content, batchLength, batchTableJson, batchTableBinary, colorChangeCallback);
content._batchTable = batchTable;

var gltfByteLength = byteStart + byteLength - byteOffset;
Expand All @@ -356,35 +379,56 @@ define([
primitive : tileset
};

// PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes.
// The pick shader still needs to be patched.
content._model = new Model({
gltf : gltfView,
cull : false, // The model is already culled by 3D Tiles
releaseGltfJson : true, // Models are unique and will not benefit from caching so save memory
opaquePass : Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass
basePath : basePath,
requestType : RequestType.TILES3D,
modelMatrix : tile.computedTransform,
upAxis : tileset._gltfUpAxis,
shadows: tileset.shadows,
debugWireframe: tileset.debugWireframe,
incrementallyLoadTextures : false,
vertexShaderLoaded : getVertexShaderCallback(content),
fragmentShaderLoaded : getFragmentShaderCallback(content),
uniformMapLoaded : batchTable.getUniformMapCallback(),
pickVertexShaderLoaded : getPickVertexShaderCallback(content),
pickFragmentShaderLoaded : batchTable.getPickFragmentShaderCallback(),
pickUniformMapLoaded : batchTable.getPickUniformMapCallback(),
addBatchIdToGeneratedShaders : (batchLength > 0), // If the batch table has values in it, generated shaders will need a batchId attribute
pickObject : pickObject,
clippingPlanes : new ClippingPlaneCollection({
enabled : false
})
});

if (defined(tileset.clippingPlanes)) {
content._model.clippingPlanes = tileset.clippingPlanes.clone();
if (!defined(tileset.classificationType)) {
// PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes.
// The pick shader still needs to be patched.
content._model = new Model({
gltf : gltfView,
cull : false, // The model is already culled by 3D Tiles
releaseGltfJson : true, // Models are unique and will not benefit from caching so save memory
opaquePass : Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass
basePath : basePath,
requestType : RequestType.TILES3D,
modelMatrix : tile.computedTransform,
upAxis : tileset._gltfUpAxis,
shadows: tileset.shadows,
debugWireframe: tileset.debugWireframe,
incrementallyLoadTextures : false,
vertexShaderLoaded : getVertexShaderCallback(content),
fragmentShaderLoaded : getFragmentShaderCallback(content),
classificationShaderLoaded : getClassificationFragmentShaderCallback(content),
uniformMapLoaded : batchTable.getUniformMapCallback(),
pickVertexShaderLoaded : getPickVertexShaderCallback(content),
pickFragmentShaderLoaded : batchTable.getPickFragmentShaderCallback(),
pickUniformMapLoaded : batchTable.getPickUniformMapCallback(),
addBatchIdToGeneratedShaders : (batchLength > 0), // If the batch table has values in it, generated shaders will need a batchId attribute
pickObject : pickObject,
clippingPlanes : new ClippingPlaneCollection({
enabled : false
})
});
if (defined(tileset.clippingPlanes)) {
content._model.clippingPlanes = tileset.clippingPlanes.clone();
}
} else {
// This transcodes glTF to an internal representation for geometry so we can take advantage of the re-batching of vector a geometry data.
// For a list of limitations on the input glTF, see the documentation for classificationType of Cesium3DTileset.
content._model = new ClassificationModel({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a code comment about how this is a transcode - with limitations on the input glTF - so that we can use the geom rebatching rendering pipeline?

gltf : gltfView,
cull : false, // The model is already culled by 3D Tiles
basePath : basePath,
modelMatrix : tile.computedTransform,
upAxis : tileset._gltfUpAxis,
debugWireframe : tileset.debugWireframe,
vertexShaderLoaded : getVertexShaderCallback(content),
classificationShaderLoaded : getClassificationFragmentShaderCallback(content),
uniformMapLoaded : batchTable.getUniformMapCallback(),
pickVertexShaderLoaded : getPickVertexShaderCallback(content),
pickFragmentShaderLoaded : batchTable.getPickFragmentShaderCallback(),
pickUniformMapLoaded : batchTable.getPickUniformMapCallback(),
classificationType : tileset._classificationType,
batchTable : batchTable
});
}
}

Expand Down Expand Up @@ -466,7 +510,7 @@ define([

// If any commands were pushed, add derived commands
var commandEnd = frameState.commandList.length;
if ((commandStart < commandEnd) && frameState.passes.render) {
if ((commandStart < commandEnd) && frameState.passes.render && !(this._model instanceof ClassificationModel)) {
var finalResolution = this._tile._finalResolution;
this._batchTable.addDerivedCommands(frameState, commandStart, finalResolution);
}
Expand Down
31 changes: 31 additions & 0 deletions Source/Scene/Cesium3DTileBatchTable.js
Expand Up @@ -1049,6 +1049,37 @@ define([
};
};

Cesium3DTileBatchTable.prototype.getClassificationFragmentShaderCallback = function() {
if (this.featuresLength === 0) {
return;
}
return function(source) {
source = ShaderSource.replaceMain(source, 'tile_main');
if (ContextLimits.maximumVertexTextureImageUnits > 0) {
// When VTF is supported, per-feature show/hide already happened in the fragment shader
source +=
'varying vec4 tile_featureColor; \n' +
'void main() \n' +
'{ \n' +
' gl_FragColor = tile_featureColor; \n' +
'}';
} else {
source +=
'uniform sampler2D tile_batchTexture; \n' +
'varying vec2 tile_featureSt; \n' +
'void main() \n' +
'{ \n' +
' vec4 featureProperties = texture2D(tile_batchTexture, tile_featureSt); \n' +
' if (featureProperties.a == 0.0) { \n' + // show: alpha == 0 - false, non-zeo - true
' discard; \n' +
' } \n' +
' gl_FragColor = featureProperties; \n' +
'} \n';
}
return source;
};
};

function getColorBlend(batchTable) {
var tileset = batchTable._content._tileset;
var colorBlendMode = tileset.colorBlendMode;
Expand Down