Skip to content

Commit b712ad3

Browse files
authored
Merge pull request #6780 from AnalyticalGraphicsInc/batch-table-hierarchy-ext
Move batch table hierarchy to extension
2 parents af2e382 + ab89ce1 commit b712ad3

File tree

16 files changed

+210
-77
lines changed

16 files changed

+210
-77
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Change Log
1010

1111
##### Deprecated :hourglass_flowing_sand:
1212
* 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)
13+
* 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)
1314

1415
#### Fixes :wrench:
1516
* Fixed bug causing billboards and labels to appear the wrong size when switching scene modes [#6745](https://github.com/AnalyticalGraphicsInc/cesium/issues/6745)

Source/Scene/Cesium3DTileBatchTable.js

+80-60
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ define([
1010
'../Core/defaultValue',
1111
'../Core/defined',
1212
'../Core/defineProperties',
13+
'../Core/deprecationWarning',
1314
'../Core/destroyObject',
1415
'../Core/DeveloperError',
1516
'../Core/Math',
@@ -44,6 +45,7 @@ define([
4445
defaultValue,
4546
defined,
4647
defineProperties,
48+
deprecationWarning,
4749
destroyObject,
4850
DeveloperError,
4951
CesiumMath,
@@ -82,31 +84,17 @@ define([
8284

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

85-
/**
86-
* @private
87-
*/
88-
this.batchTableJson = batchTableJson;
89-
90-
/**
91-
* @private
92-
*/
93-
this.batchTableBinary = batchTableBinary;
94-
95-
var batchTableHierarchy;
96-
var batchTableBinaryProperties;
87+
var extensions;
9788
if (defined(batchTableJson)) {
98-
// Extract the hierarchy and remove it from the batch table json
99-
batchTableHierarchy = batchTableJson.HIERARCHY;
100-
if (defined(batchTableHierarchy)) {
101-
delete batchTableJson.HIERARCHY;
102-
batchTableHierarchy = initializeHierarchy(batchTableHierarchy, batchTableBinary);
103-
}
104-
// Get the binary properties
105-
batchTableBinaryProperties = Cesium3DTileBatchTable.getBinaryProperties(featuresLength, batchTableJson, batchTableBinary);
89+
extensions = batchTableJson.extensions;
10690
}
91+
this._extensions = defaultValue(extensions, {});
92+
93+
var properties = initializeProperties(batchTableJson);
94+
this._properties = properties;
10795

108-
this._batchTableHierarchy = batchTableHierarchy;
109-
this._batchTableBinaryProperties = batchTableBinaryProperties;
96+
this._batchTableHierarchy = initializeHierarchy(this, batchTableJson, batchTableBinary);
97+
this._batchTableBinaryProperties = getBinaryProperties(featuresLength, properties, batchTableBinary);
11098

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

137+
// This can be overridden for testing purposes
138+
Cesium3DTileBatchTable._deprecationWarning = deprecationWarning;
139+
149140
defineProperties(Cesium3DTileBatchTable.prototype, {
150141
memorySizeInBytes : {
151142
get : function() {
@@ -161,23 +152,63 @@ define([
161152
}
162153
});
163154

164-
function initializeHierarchy(json, binary) {
155+
function initializeProperties(jsonHeader) {
156+
var properties = {};
157+
158+
if (!defined(jsonHeader)) {
159+
return properties;
160+
}
161+
162+
for (var propertyName in jsonHeader) {
163+
if (jsonHeader.hasOwnProperty(propertyName)
164+
&& propertyName !== 'HIERARCHY' // Deprecated HIERARCHY property
165+
&& propertyName !== 'extensions'
166+
&& propertyName !== 'extras') {
167+
properties[propertyName] = clone(jsonHeader[propertyName], true);
168+
}
169+
}
170+
171+
return properties;
172+
}
173+
174+
function initializeHierarchy(batchTable, jsonHeader, binaryBody) {
175+
if (!defined(jsonHeader)) {
176+
return;
177+
}
178+
179+
var hierarchy = batchTable._extensions['3DTILES_batch_table_hierarchy'];
180+
181+
var legacyHierarchy = jsonHeader.HIERARCHY;
182+
if (defined(legacyHierarchy)) {
183+
Cesium3DTileBatchTable._deprecationWarning('batchTableHierarchyExtension', 'The batch table HIERARCHY property has been moved to an extension. Use extensions.3DTILES_batch_table_hierarchy instead.');
184+
batchTable._extensions['3DTILES_batch_table_hierarchy'] = legacyHierarchy;
185+
hierarchy = legacyHierarchy;
186+
}
187+
188+
if (!defined(hierarchy)) {
189+
return;
190+
}
191+
192+
return initializeHierarchyValues(hierarchy, binaryBody);
193+
}
194+
195+
function initializeHierarchyValues(hierarchyJson, binaryBody) {
165196
var i;
166197
var classId;
167198
var binaryAccessor;
168199

169-
var instancesLength = json.instancesLength;
170-
var classes = json.classes;
171-
var classIds = json.classIds;
172-
var parentCounts = json.parentCounts;
173-
var parentIds = json.parentIds;
200+
var instancesLength = hierarchyJson.instancesLength;
201+
var classes = hierarchyJson.classes;
202+
var classIds = hierarchyJson.classIds;
203+
var parentCounts = hierarchyJson.parentCounts;
204+
var parentIds = hierarchyJson.parentIds;
174205
var parentIdsLength = instancesLength;
175206

176207
if (defined(classIds.byteOffset)) {
177208
classIds.componentType = defaultValue(classIds.componentType, ComponentDatatype.UNSIGNED_SHORT);
178209
classIds.type = AttributeType.SCALAR;
179210
binaryAccessor = getBinaryAccessor(classIds);
180-
classIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + classIds.byteOffset, instancesLength);
211+
classIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + classIds.byteOffset, instancesLength);
181212
}
182213

183214
var parentIndexes;
@@ -186,7 +217,7 @@ define([
186217
parentCounts.componentType = defaultValue(parentCounts.componentType, ComponentDatatype.UNSIGNED_SHORT);
187218
parentCounts.type = AttributeType.SCALAR;
188219
binaryAccessor = getBinaryAccessor(parentCounts);
189-
parentCounts = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentCounts.byteOffset, instancesLength);
220+
parentCounts = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentCounts.byteOffset, instancesLength);
190221
}
191222
parentIndexes = new Uint16Array(instancesLength);
192223
parentIdsLength = 0;
@@ -200,14 +231,14 @@ define([
200231
parentIds.componentType = defaultValue(parentIds.componentType, ComponentDatatype.UNSIGNED_SHORT);
201232
parentIds.type = AttributeType.SCALAR;
202233
binaryAccessor = getBinaryAccessor(parentIds);
203-
parentIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentIds.byteOffset, parentIdsLength);
234+
parentIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentIds.byteOffset, parentIdsLength);
204235
}
205236

206237
var classesLength = classes.length;
207238
for (i = 0; i < classesLength; ++i) {
208239
var classInstancesLength = classes[i].length;
209240
var properties = classes[i].instances;
210-
var binaryProperties = Cesium3DTileBatchTable.getBinaryProperties(classInstancesLength, properties, binary);
241+
var binaryProperties = getBinaryProperties(classInstancesLength, properties, binaryBody);
211242
classes[i].instances = combine(binaryProperties, properties);
212243
}
213244

@@ -282,11 +313,11 @@ define([
282313
}
283314
//>>includeEnd('debug');
284315

285-
Cesium3DTileBatchTable.getBinaryProperties = function(featuresLength, json, binary) {
316+
function getBinaryProperties(featuresLength, properties, binaryBody) {
286317
var binaryProperties;
287-
for (var name in json) {
288-
if (json.hasOwnProperty(name)) {
289-
var property = json[name];
318+
for (var name in properties) {
319+
if (properties.hasOwnProperty(name)) {
320+
var property = properties[name];
290321
var byteOffset = property.byteOffset;
291322
if (defined(byteOffset)) {
292323
// This is a binary property
@@ -298,14 +329,14 @@ define([
298329
if (!defined(type)) {
299330
throw new RuntimeError('type is required.');
300331
}
301-
if (!defined(binary)) {
332+
if (!defined(binaryBody)) {
302333
throw new RuntimeError('Property ' + name + ' requires a batch table binary.');
303334
}
304335

305336
var binaryAccessor = getBinaryAccessor(property);
306337
var componentCount = binaryAccessor.componentsPerAttribute;
307338
var classType = binaryAccessor.classType;
308-
var typedArray = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + byteOffset, featuresLength);
339+
var typedArray = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + byteOffset, featuresLength);
309340

310341
if (!defined(binaryProperties)) {
311342
binaryProperties = {};
@@ -322,6 +353,10 @@ define([
322353
}
323354
}
324355
return binaryProperties;
356+
}
357+
358+
Cesium3DTileBatchTable.getBinaryProperties = function(featuresLength, batchTableJson, batchTableBinary) {
359+
return getBinaryProperties(featuresLength, batchTableJson, batchTableBinary);
325360
};
326361

327362
function getByteLength(batchTable) {
@@ -738,8 +773,7 @@ define([
738773
Check.typeOf.string('name', name);
739774
//>>includeEnd('debug');
740775

741-
var json = this.batchTableJson;
742-
return (defined(json) && defined(json[name])) || (defined(this._batchTableHierarchy) && hasPropertyInHierarchy(this, batchId, name));
776+
return (defined(this._properties[name])) || (defined(this._batchTableHierarchy) && hasPropertyInHierarchy(this, batchId, name));
743777
};
744778

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

753-
var json = this.batchTableJson;
754-
for (var name in json) {
755-
if (json.hasOwnProperty(name)) {
756-
results.push(name);
757-
}
758-
}
787+
var propertyNames = Object.keys(this._properties);
788+
results.push.apply(results, propertyNames);
759789

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

773-
if (!defined(this.batchTableJson)) {
774-
return undefined;
775-
}
776-
777803
if (defined(this._batchTableBinaryProperties)) {
778804
var binaryProperty = this._batchTableBinaryProperties[name];
779805
if (defined(binaryProperty)) {
780806
return getBinaryProperty(binaryProperty, batchId);
781807
}
782808
}
783809

784-
var propertyValues = this.batchTableJson[name];
810+
var propertyValues = this._properties[name];
785811
if (defined(propertyValues)) {
786812
return clone(propertyValues[batchId], true);
787813
}
@@ -817,17 +843,11 @@ define([
817843
}
818844
}
819845

820-
if (!defined(this.batchTableJson)) {
821-
// Tile payload did not have a batch table. Create one for new user-defined properties.
822-
this.batchTableJson = {};
823-
}
824-
825-
var propertyValues = this.batchTableJson[name];
826-
846+
var propertyValues = this._properties[name];
827847
if (!defined(propertyValues)) {
828848
// Property does not exist. Create it.
829-
this.batchTableJson[name] = new Array(featuresLength);
830-
propertyValues = this.batchTableJson[name];
849+
this._properties[name] = new Array(featuresLength);
850+
propertyValues = this._properties[name];
831851
}
832852

833853
propertyValues[batchId] = clone(value, true);

Source/Scene/Cesium3DTileset.js

+16
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ define([
167167
this._asset = undefined; // Metadata for the entire tileset
168168
this._properties = undefined; // Metadata for per-model/point/etc properties
169169
this._geometricError = undefined; // Geometric error when the tree is not rendered at all
170+
this._extensionsUsed = undefined;
170171
this._gltfUpAxis = undefined;
171172
this._processingQueue = [];
172173
this._selectedTiles = [];
@@ -715,6 +716,7 @@ define([
715716
that._asset = tilesetJson.asset;
716717
that._properties = tilesetJson.properties;
717718
that._geometricError = tilesetJson.geometricError;
719+
that._extensionsUsed = tilesetJson.extensionsUsed;
718720
that._gltfUpAxis = gltfUpAxis;
719721
that._readyPromise.resolve(that);
720722
}).otherwise(function(error) {
@@ -1916,6 +1918,20 @@ define([
19161918
}
19171919
};
19181920

1921+
/**
1922+
* <code>true</code> if the tileset JSON file lists the extension in extensionsUsed; otherwise, <code>false</code>.
1923+
* @param {String} extensionName The name of the extension to check.
1924+
*
1925+
* @returns {Boolean} <code>true</code> if the tileset JSON file lists the extension in extensionsUsed; otherwise, <code>false</code>.
1926+
*/
1927+
Cesium3DTileset.prototype.hasExtension = function(extensionName) {
1928+
if (!defined(this._extensionsUsed)) {
1929+
return false;
1930+
}
1931+
1932+
return (this._extensionsUsed.indexOf(extensionName) > -1);
1933+
};
1934+
19191935
/**
19201936
* Returns true if this object was destroyed; otherwise, false.
19211937
* <br /><br />
Binary file not shown.

Specs/Data/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141
},
4242
"geometricError": 0,
4343
"content": {
44-
"url": "tile.b3dm"
44+
"uri": "tile.b3dm"
4545
}
46-
}
46+
},
47+
"extensionsUsed": [
48+
"3DTILES_batch_table_hierarchy"
49+
],
50+
"extensionsRequired": [
51+
"3DTILES_batch_table_hierarchy"
52+
]
4753
}
Binary file not shown.

Specs/Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyBinary/tileset.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141
},
4242
"geometricError": 0,
4343
"content": {
44-
"url": "tile.b3dm"
44+
"uri": "tile.b3dm"
4545
}
46-
}
46+
},
47+
"extensionsUsed": [
48+
"3DTILES_batch_table_hierarchy"
49+
],
50+
"extensionsRequired": [
51+
"3DTILES_batch_table_hierarchy"
52+
]
4753
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"asset": {
3+
"version": "0.0"
4+
},
5+
"geometricError": 70,
6+
"root": {
7+
"transform": [
8+
0.9686356343768792,
9+
0.24848542777253735,
10+
0,
11+
0,
12+
-0.15986460744966327,
13+
0.623177611820219,
14+
0.765567091384559,
15+
0,
16+
0.19023226619126932,
17+
-0.7415555652213445,
18+
0.6433560667227647,
19+
0,
20+
1215011.9317263428,
21+
-4736309.3434217675,
22+
4081602.0044800863,
23+
1
24+
],
25+
"refine": "ADD",
26+
"boundingVolume": {
27+
"box": [
28+
0,
29+
0,
30+
10,
31+
50,
32+
0,
33+
0,
34+
0,
35+
50,
36+
0,
37+
0,
38+
0,
39+
10
40+
]
41+
},
42+
"geometricError": 0,
43+
"content": {
44+
"uri": "tile.b3dm"
45+
}
46+
}
47+
}
Binary file not shown.

0 commit comments

Comments
 (0)