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

3D Tiles - Batch Table Hierarchy #4625

Merged
merged 27 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d97e9a8
Initial batch table hierarchy support
lilleyse Nov 8, 2016
1f39c51
Remove hasProperty and getPropertyNames
lilleyse Nov 9, 2016
2043bff
Change root node condition to be when the parentId equals itself
lilleyse Nov 9, 2016
1a833f7
Naming isExactClass and isClass
lilleyse Nov 9, 2016
4fb68fe
Check for circular dependencies
lilleyse Nov 9, 2016
0a725f7
Added getClassName built-in function
lilleyse Nov 10, 2016
26bc421
Support multiple parents
lilleyse Nov 15, 2016
d70d618
Add hasPropertyName and getPropertyNames back
lilleyse Nov 15, 2016
55baed7
Merge branch '3d-tiles' into batch-table-hierarchy
lilleyse Nov 15, 2016
ccb8bab
Cleanup and more comments
lilleyse Nov 17, 2016
2e24750
Small fixes and doc
lilleyse Nov 17, 2016
e3ea1bb
Initial tests
lilleyse Nov 17, 2016
3862829
Updated tests, some issues with checking circular dependencies
lilleyse Nov 18, 2016
1470a45
Share visited array
lilleyse Nov 21, 2016
425a0e6
Refactored validateHierarchy
lilleyse Nov 21, 2016
e2baefe
Merge branch '3d-tiles' into batch-table-hierarchy
lilleyse Nov 21, 2016
6ee0915
Added Sandcastle image
lilleyse Nov 21, 2016
1aa313c
Added back styling tests
lilleyse Nov 22, 2016
c0852de
Fixes
lilleyse Nov 22, 2016
77419bb
Remove unneeded check
lilleyse Nov 22, 2016
ecf3a87
Add more tests
lilleyse Nov 22, 2016
e4622c7
Update Sandcastle
lilleyse Nov 22, 2016
1d759ca
Code and Sandcastle updates
lilleyse Dec 12, 2016
98853d4
Merge branch '3d-tiles' into batch-table-hierarchy
lilleyse Dec 12, 2016
9899571
Remove comma
lilleyse Dec 12, 2016
7bb29fe
Throw error when setting an inherited property
lilleyse Dec 12, 2016
75cdf2f
Add comment for scratchVisited
lilleyse Dec 12, 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
248 changes: 248 additions & 0 deletions Apps/Sandcastle/gallery/3D Tiles Hierarchy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
<!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.

Can you make a screenshot for this when ready?

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, but can you please rename this to "3D Tiles Batch Table Hierarchy" or "3D Tiles Semantic Hierarchy", which ever you think is better aligned with the spec and what common 3D Tiles terminology will be.

<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="Use Viewer to start building new applications or easily embed Cesium into existing applications.">
<meta name="cesium-sandcastle-labels" content="Showcases">
<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 button { display: block; }
</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', {
scene3DOnly : true
});

var scene = viewer.scene;
var tilesetUrl = '../../../Specs/Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyMultipleParents';
var tileset = scene.primitives.add(new Cesium.Cesium3DTileset({
url : tilesetUrl
}));

tileset.readyPromise.then(function(tileset) {
var boundingSphere = tileset.boundingSphere;
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0, -2.0, 0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});

var styles = [];
function addStyle(name, style) {
styles.push({
name : name,
style : style
});
}

addStyle('No style', {});

addStyle('Color by building', {
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 an example using getClassName?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think this example needs more context; it is a bit hard to hack on without knowing what the semantic hierarchy looks like. Perhaps there should be comments in this example with similar info to what you put in the opening comment of this PR.

"color" : {
"conditions" : [
["${building_name} === 'building0'", "color('purple')"],
["${building_name} === 'building1'", "color('red')"],
["${building_name} === 'building2'", "color('orange')"],
["true", "color('blue')"]
]
}
});

addStyle('Color all doors', {
"color" : {
"conditions" : [
["isExactClass('door')", "color('orange')"],
["true", "color('white')"]
]
}
});

addStyle('Color all features derived from door', {
"color" : {
"conditions" : [
["isClass('door')", "color('orange')"],
["true", "color('white')"]
]
}
});

addStyle('Style by height', {
"color" : {
"conditions" : [
["${height} >= 10", "color('purple')"],
["${height} >= 6", "color('red')"],
["${height} >= 5", "color('orange')"],
["true", "color('blue')"]
]
}
});

addStyle('Style by classifier', {
"color" : {
"conditions" : [
["isClass('classifier_new') && isClass('classifier_old')", "color('purple')"],
["isClass('classifier_new')", "color('red')"],
["isClass('classifier_old')", "color('blue')"],
["true", "color()"]
]
}
});

function setStyle(style) {
return function() {
tileset.style = new Cesium.Cesium3DTileStyle(style);
};
}

var styleOptions = [];
for (var j = 0; j < styles.length; ++j) {
var style = styles[j];
styleOptions.push({
text : style.name,
onselect : setStyle(style.style)
});
}

Sandcastle.addToolbarMenu(styleOptions);

var canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
canvas.onclick = function() {
// To get key events
canvas.focus();
};

var handler = new Cesium.ScreenSpaceEventHandler(canvas);

var pickingEnabled = true;
var flags = {
// Mouse
leftDown : false,
middleDown : false,
rightDown : false
};

handler.setInputAction(function(movement) {
flags.leftDown = true;
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);

handler.setInputAction(function(movement) {
flags.middleDown = true;
}, Cesium.ScreenSpaceEventType.MIDDLE_DOWN);

handler.setInputAction(function(movement) {
flags.rightDown = true;
}, Cesium.ScreenSpaceEventType.RIGHT_DOWN);

handler.setInputAction(function(movement) {
flags.leftDown = false;
}, Cesium.ScreenSpaceEventType.LEFT_UP);

handler.setInputAction(function(movement) {
flags.middleDown = false;
}, Cesium.ScreenSpaceEventType.MIDDLE_UP);

handler.setInputAction(function(movement) {
flags.rightDown = false;
}, Cesium.ScreenSpaceEventType.RIGHT_UP);

var current = {
feature : undefined,
originalColor : new Cesium.Color()
};

var HIGHLIGHT_COLOR = new Cesium.Color(1.0, 1.0, 0.0, 0.4);

// Highlight feature on mouse over
handler.setInputAction(function(movement) {
if (!pickingEnabled) {
return;
}

if (flags.leftDown || flags.middleDown || flags.rightDown) {
// Don't highlight when panning and zooming
return;
}

var pickedFeature = scene.pick(movement.endPosition);

if (Cesium.defined(current.feature) && (current.feature !== pickedFeature)) {
// Restore original color to feature that is no longer selected

// This assignment is necessary to work with the set property
current.feature.color = Cesium.Color.clone(current.originalColor, current.feature.color);
current.feature = undefined;
}

if (Cesium.defined(pickedFeature) && (pickedFeature !== current.feature)) {
// For testing re-evaluating a style when a property changes
//pickedFeature.setProperty('id', 1);

current.feature = pickedFeature;
Cesium.Color.clone(pickedFeature.color, current.originalColor);

// Highlight newly selected feature
pickedFeature.color = Cesium.Color.clone(HIGHLIGHT_COLOR, pickedFeature.color);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

// When a feature is left clicked, print it's class name and properties
handler.setInputAction(function(movement) {
if (!pickingEnabled) {
return;
}

var feature = current.feature;
if (Cesium.defined(feature)) {
console.log('Class: ' + feature.getClassName());
console.log('Properties:');
var propertyNames = feature.getPropertyNames();
var length = propertyNames.length;
for (var i = 0; i < length; ++i) {
var name = propertyNames[i];
var value = feature.getProperty(name);
console.log(' ' + name + ': ' + value);
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

// When a feature is double middle clicked, hide it
handler.setInputAction(function(movement) {
if (!pickingEnabled) {
return;
}

if (Cesium.defined(current.feature)) {
current.feature.show = false;
}
}, Cesium.ScreenSpaceEventType.MIDDLE_DOUBLE_CLICK);

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/3D Tiles Hierarchy.jpg
Loading
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 Source/Core/IndexDatatype.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ define([
* or <code>Uint32Array</code> depending on the number of vertices.
*
* @param {Number} numberOfVertices Number of vertices that the indices will reference.
* @param {Any} indicesLengthOrArray Passed through to the typed array constructor.
* @param {*} indicesLengthOrArray Passed through to the typed array constructor.
* @returns {Uint16Array|Uint32Array} A <code>Uint16Array</code> or <code>Uint32Array</code> constructed with <code>indicesLengthOrArray</code>.
*
* @example
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/PropertyBag.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ define([
* Adds a property to this object.
*
* @param {String} propertyName The name of the property to add.
* @param {Any} [value] The value of the new property, if provided.
* @param {*} [value] The value of the new property, if provided.
* @param {Function} [createPropertyCallback] A function that will be called when the value of this new property is set to a value that is not a Property.
*
* @exception {DeveloperError} "propertyName" is already a registered property.
Expand Down
6 changes: 3 additions & 3 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ define([
}
}

/**
/**
* Part of the {@link Cesium3DTileContent} interface.
*/
Batched3DModel3DTileContent.prototype.hasProperty = function(name) {
return this.batchTable.hasProperty(name);
Batched3DModel3DTileContent.prototype.hasProperty = function(batchId, name) {
return this.batchTable.hasProperty(batchId, name);
};

/**
Expand Down
Loading