Skip to content

Commit

Permalink
Merge pull request #6780 from AnalyticalGraphicsInc/batch-table-hiera…
Browse files Browse the repository at this point in the history
…rchy-ext

Move batch table hierarchy to extension
  • Loading branch information
lilleyse committed Jul 13, 2018
2 parents af2e382 + ab89ce1 commit b712ad3
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Change Log

##### Deprecated :hourglass_flowing_sand:
* Support for 3D Tiles `content.url` is deprecated to reflect updates to the [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/pull/301). Use `content.uri instead`. Support for `content.url` will remain for backwards compatibility. [#6744](https://github.com/AnalyticalGraphicsInc/cesium/pull/6744)
* Support for the 3D Tiles pre-version 1.0 Batch Table Hierarchy is deprecated to reflect updates to the [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/pull/301). Use the [`3DTILES_batch_table_hierarchy`](https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/1.0/extensions/3DTILES_batch_table_hierarchy) extension instead. Support for the deprecated batch table hierarchy will remain for backwards compatibility. [#6780](https://github.com/AnalyticalGraphicsInc/cesium/pull/6780)

#### Fixes :wrench:
* Fixed bug causing billboards and labels to appear the wrong size when switching scene modes [#6745](https://github.com/AnalyticalGraphicsInc/cesium/issues/6745)
Expand Down
140 changes: 80 additions & 60 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define([
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
'../Core/deprecationWarning',
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Math',
Expand Down Expand Up @@ -44,6 +45,7 @@ define([
defaultValue,
defined,
defineProperties,
deprecationWarning,
destroyObject,
DeveloperError,
CesiumMath,
Expand Down Expand Up @@ -82,31 +84,17 @@ define([

this._translucentFeaturesLength = 0; // Number of features in the tile that are translucent

/**
* @private
*/
this.batchTableJson = batchTableJson;

/**
* @private
*/
this.batchTableBinary = batchTableBinary;

var batchTableHierarchy;
var batchTableBinaryProperties;
var extensions;
if (defined(batchTableJson)) {
// Extract the hierarchy and remove it from the batch table json
batchTableHierarchy = batchTableJson.HIERARCHY;
if (defined(batchTableHierarchy)) {
delete batchTableJson.HIERARCHY;
batchTableHierarchy = initializeHierarchy(batchTableHierarchy, batchTableBinary);
}
// Get the binary properties
batchTableBinaryProperties = Cesium3DTileBatchTable.getBinaryProperties(featuresLength, batchTableJson, batchTableBinary);
extensions = batchTableJson.extensions;
}
this._extensions = defaultValue(extensions, {});

var properties = initializeProperties(batchTableJson);
this._properties = properties;

this._batchTableHierarchy = batchTableHierarchy;
this._batchTableBinaryProperties = batchTableBinaryProperties;
this._batchTableHierarchy = initializeHierarchy(this, batchTableJson, batchTableBinary);
this._batchTableBinaryProperties = getBinaryProperties(featuresLength, properties, batchTableBinary);

// PERFORMANCE_IDEA: These parallel arrays probably generate cache misses in get/set color/show
// and use A LOT of memory. How can we use less memory?
Expand Down Expand Up @@ -146,6 +134,9 @@ define([
this._textureStep = textureStep;
}

// This can be overridden for testing purposes
Cesium3DTileBatchTable._deprecationWarning = deprecationWarning;

defineProperties(Cesium3DTileBatchTable.prototype, {
memorySizeInBytes : {
get : function() {
Expand All @@ -161,23 +152,63 @@ define([
}
});

function initializeHierarchy(json, binary) {
function initializeProperties(jsonHeader) {
var properties = {};

if (!defined(jsonHeader)) {
return properties;
}

for (var propertyName in jsonHeader) {
if (jsonHeader.hasOwnProperty(propertyName)
&& propertyName !== 'HIERARCHY' // Deprecated HIERARCHY property
&& propertyName !== 'extensions'
&& propertyName !== 'extras') {
properties[propertyName] = clone(jsonHeader[propertyName], true);
}
}

return properties;
}

function initializeHierarchy(batchTable, jsonHeader, binaryBody) {
if (!defined(jsonHeader)) {
return;
}

var hierarchy = batchTable._extensions['3DTILES_batch_table_hierarchy'];

var legacyHierarchy = jsonHeader.HIERARCHY;
if (defined(legacyHierarchy)) {
Cesium3DTileBatchTable._deprecationWarning('batchTableHierarchyExtension', 'The batch table HIERARCHY property has been moved to an extension. Use extensions.3DTILES_batch_table_hierarchy instead.');
batchTable._extensions['3DTILES_batch_table_hierarchy'] = legacyHierarchy;
hierarchy = legacyHierarchy;
}

if (!defined(hierarchy)) {
return;
}

return initializeHierarchyValues(hierarchy, binaryBody);
}

function initializeHierarchyValues(hierarchyJson, binaryBody) {
var i;
var classId;
var binaryAccessor;

var instancesLength = json.instancesLength;
var classes = json.classes;
var classIds = json.classIds;
var parentCounts = json.parentCounts;
var parentIds = json.parentIds;
var instancesLength = hierarchyJson.instancesLength;
var classes = hierarchyJson.classes;
var classIds = hierarchyJson.classIds;
var parentCounts = hierarchyJson.parentCounts;
var parentIds = hierarchyJson.parentIds;
var parentIdsLength = instancesLength;

if (defined(classIds.byteOffset)) {
classIds.componentType = defaultValue(classIds.componentType, ComponentDatatype.UNSIGNED_SHORT);
classIds.type = AttributeType.SCALAR;
binaryAccessor = getBinaryAccessor(classIds);
classIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + classIds.byteOffset, instancesLength);
classIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + classIds.byteOffset, instancesLength);
}

var parentIndexes;
Expand All @@ -186,7 +217,7 @@ define([
parentCounts.componentType = defaultValue(parentCounts.componentType, ComponentDatatype.UNSIGNED_SHORT);
parentCounts.type = AttributeType.SCALAR;
binaryAccessor = getBinaryAccessor(parentCounts);
parentCounts = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentCounts.byteOffset, instancesLength);
parentCounts = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentCounts.byteOffset, instancesLength);
}
parentIndexes = new Uint16Array(instancesLength);
parentIdsLength = 0;
Expand All @@ -200,14 +231,14 @@ define([
parentIds.componentType = defaultValue(parentIds.componentType, ComponentDatatype.UNSIGNED_SHORT);
parentIds.type = AttributeType.SCALAR;
binaryAccessor = getBinaryAccessor(parentIds);
parentIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentIds.byteOffset, parentIdsLength);
parentIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentIds.byteOffset, parentIdsLength);
}

var classesLength = classes.length;
for (i = 0; i < classesLength; ++i) {
var classInstancesLength = classes[i].length;
var properties = classes[i].instances;
var binaryProperties = Cesium3DTileBatchTable.getBinaryProperties(classInstancesLength, properties, binary);
var binaryProperties = getBinaryProperties(classInstancesLength, properties, binaryBody);
classes[i].instances = combine(binaryProperties, properties);
}

Expand Down Expand Up @@ -282,11 +313,11 @@ define([
}
//>>includeEnd('debug');

Cesium3DTileBatchTable.getBinaryProperties = function(featuresLength, json, binary) {
function getBinaryProperties(featuresLength, properties, binaryBody) {
var binaryProperties;
for (var name in json) {
if (json.hasOwnProperty(name)) {
var property = json[name];
for (var name in properties) {
if (properties.hasOwnProperty(name)) {
var property = properties[name];
var byteOffset = property.byteOffset;
if (defined(byteOffset)) {
// This is a binary property
Expand All @@ -298,14 +329,14 @@ define([
if (!defined(type)) {
throw new RuntimeError('type is required.');
}
if (!defined(binary)) {
if (!defined(binaryBody)) {
throw new RuntimeError('Property ' + name + ' requires a batch table binary.');
}

var binaryAccessor = getBinaryAccessor(property);
var componentCount = binaryAccessor.componentsPerAttribute;
var classType = binaryAccessor.classType;
var typedArray = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + byteOffset, featuresLength);
var typedArray = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + byteOffset, featuresLength);

if (!defined(binaryProperties)) {
binaryProperties = {};
Expand All @@ -322,6 +353,10 @@ define([
}
}
return binaryProperties;
}

Cesium3DTileBatchTable.getBinaryProperties = function(featuresLength, batchTableJson, batchTableBinary) {
return getBinaryProperties(featuresLength, batchTableJson, batchTableBinary);
};

function getByteLength(batchTable) {
Expand Down Expand Up @@ -738,8 +773,7 @@ define([
Check.typeOf.string('name', name);
//>>includeEnd('debug');

var json = this.batchTableJson;
return (defined(json) && defined(json[name])) || (defined(this._batchTableHierarchy) && hasPropertyInHierarchy(this, batchId, name));
return (defined(this._properties[name])) || (defined(this._batchTableHierarchy) && hasPropertyInHierarchy(this, batchId, name));
};

Cesium3DTileBatchTable.prototype.getPropertyNames = function(batchId, results) {
Expand All @@ -750,12 +784,8 @@ define([
results = defined(results) ? results : [];
results.length = 0;

var json = this.batchTableJson;
for (var name in json) {
if (json.hasOwnProperty(name)) {
results.push(name);
}
}
var propertyNames = Object.keys(this._properties);
results.push.apply(results, propertyNames);

if (defined(this._batchTableHierarchy)) {
getPropertyNamesInHierarchy(this, batchId, results);
Expand All @@ -770,18 +800,14 @@ define([
Check.typeOf.string('name', name);
//>>includeEnd('debug');

if (!defined(this.batchTableJson)) {
return undefined;
}

if (defined(this._batchTableBinaryProperties)) {
var binaryProperty = this._batchTableBinaryProperties[name];
if (defined(binaryProperty)) {
return getBinaryProperty(binaryProperty, batchId);
}
}

var propertyValues = this.batchTableJson[name];
var propertyValues = this._properties[name];
if (defined(propertyValues)) {
return clone(propertyValues[batchId], true);
}
Expand Down Expand Up @@ -817,17 +843,11 @@ define([
}
}

if (!defined(this.batchTableJson)) {
// Tile payload did not have a batch table. Create one for new user-defined properties.
this.batchTableJson = {};
}

var propertyValues = this.batchTableJson[name];

var propertyValues = this._properties[name];
if (!defined(propertyValues)) {
// Property does not exist. Create it.
this.batchTableJson[name] = new Array(featuresLength);
propertyValues = this.batchTableJson[name];
this._properties[name] = new Array(featuresLength);
propertyValues = this._properties[name];
}

propertyValues[batchId] = clone(value, true);
Expand Down
16 changes: 16 additions & 0 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ define([
this._asset = undefined; // Metadata for the entire tileset
this._properties = undefined; // Metadata for per-model/point/etc properties
this._geometricError = undefined; // Geometric error when the tree is not rendered at all
this._extensionsUsed = undefined;
this._gltfUpAxis = undefined;
this._processingQueue = [];
this._selectedTiles = [];
Expand Down Expand Up @@ -715,6 +716,7 @@ define([
that._asset = tilesetJson.asset;
that._properties = tilesetJson.properties;
that._geometricError = tilesetJson.geometricError;
that._extensionsUsed = tilesetJson.extensionsUsed;
that._gltfUpAxis = gltfUpAxis;
that._readyPromise.resolve(that);
}).otherwise(function(error) {
Expand Down Expand Up @@ -1916,6 +1918,20 @@ define([
}
};

/**
* <code>true</code> if the tileset JSON file lists the extension in extensionsUsed; otherwise, <code>false</code>.
* @param {String} extensionName The name of the extension to check.
*
* @returns {Boolean} <code>true</code> if the tileset JSON file lists the extension in extensionsUsed; otherwise, <code>false</code>.
*/
Cesium3DTileset.prototype.hasExtension = function(extensionName) {
if (!defined(this._extensionsUsed)) {
return false;
}

return (this._extensionsUsed.indexOf(extensionName) > -1);
};

/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
},
"geometricError": 0,
"content": {
"url": "tile.b3dm"
"uri": "tile.b3dm"
}
}
},
"extensionsUsed": [
"3DTILES_batch_table_hierarchy"
],
"extensionsRequired": [
"3DTILES_batch_table_hierarchy"
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
},
"geometricError": 0,
"content": {
"url": "tile.b3dm"
"uri": "tile.b3dm"
}
}
},
"extensionsUsed": [
"3DTILES_batch_table_hierarchy"
],
"extensionsRequired": [
"3DTILES_batch_table_hierarchy"
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"asset": {
"version": "0.0"
},
"geometricError": 70,
"root": {
"transform": [
0.9686356343768792,
0.24848542777253735,
0,
0,
-0.15986460744966327,
0.623177611820219,
0.765567091384559,
0,
0.19023226619126932,
-0.7415555652213445,
0.6433560667227647,
0,
1215011.9317263428,
-4736309.3434217675,
4081602.0044800863,
1
],
"refine": "ADD",
"boundingVolume": {
"box": [
0,
0,
10,
50,
0,
0,
0,
50,
0,
0,
0,
10
]
},
"geometricError": 0,
"content": {
"uri": "tile.b3dm"
}
}
}
Binary file not shown.

0 comments on commit b712ad3

Please sign in to comment.