@@ -10,6 +10,7 @@ define([
10
10
'../Core/defaultValue' ,
11
11
'../Core/defined' ,
12
12
'../Core/defineProperties' ,
13
+ '../Core/deprecationWarning' ,
13
14
'../Core/destroyObject' ,
14
15
'../Core/DeveloperError' ,
15
16
'../Core/Math' ,
@@ -44,6 +45,7 @@ define([
44
45
defaultValue ,
45
46
defined ,
46
47
defineProperties ,
48
+ deprecationWarning ,
47
49
destroyObject ,
48
50
DeveloperError ,
49
51
CesiumMath ,
@@ -82,31 +84,17 @@ define([
82
84
83
85
this . _translucentFeaturesLength = 0 ; // Number of features in the tile that are translucent
84
86
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 ;
97
88
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 ;
106
90
}
91
+ this . _extensions = defaultValue ( extensions , { } ) ;
92
+
93
+ var properties = initializeProperties ( batchTableJson ) ;
94
+ this . _properties = properties ;
107
95
108
- this . _batchTableHierarchy = batchTableHierarchy ;
109
- this . _batchTableBinaryProperties = batchTableBinaryProperties ;
96
+ this . _batchTableHierarchy = initializeHierarchy ( this , batchTableJson , batchTableBinary ) ;
97
+ this . _batchTableBinaryProperties = getBinaryProperties ( featuresLength , properties , batchTableBinary ) ;
110
98
111
99
// PERFORMANCE_IDEA: These parallel arrays probably generate cache misses in get/set color/show
112
100
// and use A LOT of memory. How can we use less memory?
@@ -146,6 +134,9 @@ define([
146
134
this . _textureStep = textureStep ;
147
135
}
148
136
137
+ // This can be overridden for testing purposes
138
+ Cesium3DTileBatchTable . _deprecationWarning = deprecationWarning ;
139
+
149
140
defineProperties ( Cesium3DTileBatchTable . prototype , {
150
141
memorySizeInBytes : {
151
142
get : function ( ) {
@@ -161,23 +152,63 @@ define([
161
152
}
162
153
} ) ;
163
154
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 ) {
165
196
var i ;
166
197
var classId ;
167
198
var binaryAccessor ;
168
199
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 ;
174
205
var parentIdsLength = instancesLength ;
175
206
176
207
if ( defined ( classIds . byteOffset ) ) {
177
208
classIds . componentType = defaultValue ( classIds . componentType , ComponentDatatype . UNSIGNED_SHORT ) ;
178
209
classIds . type = AttributeType . SCALAR ;
179
210
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 ) ;
181
212
}
182
213
183
214
var parentIndexes ;
@@ -186,7 +217,7 @@ define([
186
217
parentCounts . componentType = defaultValue ( parentCounts . componentType , ComponentDatatype . UNSIGNED_SHORT ) ;
187
218
parentCounts . type = AttributeType . SCALAR ;
188
219
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 ) ;
190
221
}
191
222
parentIndexes = new Uint16Array ( instancesLength ) ;
192
223
parentIdsLength = 0 ;
@@ -200,14 +231,14 @@ define([
200
231
parentIds . componentType = defaultValue ( parentIds . componentType , ComponentDatatype . UNSIGNED_SHORT ) ;
201
232
parentIds . type = AttributeType . SCALAR ;
202
233
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 ) ;
204
235
}
205
236
206
237
var classesLength = classes . length ;
207
238
for ( i = 0 ; i < classesLength ; ++ i ) {
208
239
var classInstancesLength = classes [ i ] . length ;
209
240
var properties = classes [ i ] . instances ;
210
- var binaryProperties = Cesium3DTileBatchTable . getBinaryProperties ( classInstancesLength , properties , binary ) ;
241
+ var binaryProperties = getBinaryProperties ( classInstancesLength , properties , binaryBody ) ;
211
242
classes [ i ] . instances = combine ( binaryProperties , properties ) ;
212
243
}
213
244
@@ -282,11 +313,11 @@ define([
282
313
}
283
314
//>>includeEnd('debug');
284
315
285
- Cesium3DTileBatchTable . getBinaryProperties = function ( featuresLength , json , binary ) {
316
+ function getBinaryProperties ( featuresLength , properties , binaryBody ) {
286
317
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 ] ;
290
321
var byteOffset = property . byteOffset ;
291
322
if ( defined ( byteOffset ) ) {
292
323
// This is a binary property
@@ -298,14 +329,14 @@ define([
298
329
if ( ! defined ( type ) ) {
299
330
throw new RuntimeError ( 'type is required.' ) ;
300
331
}
301
- if ( ! defined ( binary ) ) {
332
+ if ( ! defined ( binaryBody ) ) {
302
333
throw new RuntimeError ( 'Property ' + name + ' requires a batch table binary.' ) ;
303
334
}
304
335
305
336
var binaryAccessor = getBinaryAccessor ( property ) ;
306
337
var componentCount = binaryAccessor . componentsPerAttribute ;
307
338
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 ) ;
309
340
310
341
if ( ! defined ( binaryProperties ) ) {
311
342
binaryProperties = { } ;
@@ -322,6 +353,10 @@ define([
322
353
}
323
354
}
324
355
return binaryProperties ;
356
+ }
357
+
358
+ Cesium3DTileBatchTable . getBinaryProperties = function ( featuresLength , batchTableJson , batchTableBinary ) {
359
+ return getBinaryProperties ( featuresLength , batchTableJson , batchTableBinary ) ;
325
360
} ;
326
361
327
362
function getByteLength ( batchTable ) {
@@ -738,8 +773,7 @@ define([
738
773
Check . typeOf . string ( 'name' , name ) ;
739
774
//>>includeEnd('debug');
740
775
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 ) ) ;
743
777
} ;
744
778
745
779
Cesium3DTileBatchTable . prototype . getPropertyNames = function ( batchId , results ) {
@@ -750,12 +784,8 @@ define([
750
784
results = defined ( results ) ? results : [ ] ;
751
785
results . length = 0 ;
752
786
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 ) ;
759
789
760
790
if ( defined ( this . _batchTableHierarchy ) ) {
761
791
getPropertyNamesInHierarchy ( this , batchId , results ) ;
@@ -770,18 +800,14 @@ define([
770
800
Check . typeOf . string ( 'name' , name ) ;
771
801
//>>includeEnd('debug');
772
802
773
- if ( ! defined ( this . batchTableJson ) ) {
774
- return undefined ;
775
- }
776
-
777
803
if ( defined ( this . _batchTableBinaryProperties ) ) {
778
804
var binaryProperty = this . _batchTableBinaryProperties [ name ] ;
779
805
if ( defined ( binaryProperty ) ) {
780
806
return getBinaryProperty ( binaryProperty , batchId ) ;
781
807
}
782
808
}
783
809
784
- var propertyValues = this . batchTableJson [ name ] ;
810
+ var propertyValues = this . _properties [ name ] ;
785
811
if ( defined ( propertyValues ) ) {
786
812
return clone ( propertyValues [ batchId ] , true ) ;
787
813
}
@@ -817,17 +843,11 @@ define([
817
843
}
818
844
}
819
845
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 ] ;
827
847
if ( ! defined ( propertyValues ) ) {
828
848
// 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 ] ;
831
851
}
832
852
833
853
propertyValues [ batchId ] = clone ( value , true ) ;
0 commit comments