Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | 1052x 1051x 1050x 1050x 1050x 1050x 1050x 1050x 1x 1049x 1049x 1019x 1049x 4x 1049x 1049x 1049x 21x 21x 21x 21x 1028x 1027x 1027x 1027x 1027x 1048x 1048x 1027x 1027x 1048x 1048x 1049x 1049x 1049x 1049x 1x 1x 1048x 8x 1049x 1049x 3964x 10x 3954x 3954x 3863x 3863x 91x 1049x 1028x 1028x 1028x 1028x 1028x 36x 36x 1x 35x 35x 35x 35x 35x 35x 1027x 1027x 1027x 1027x 1027x 21x 21x 21x 21x 55x 55x 55x 55x 55x 1x 1x 55x 55x 55x 55x 55x 53x 55x 55x 41x 41x 55x 55x 55x 55x 55x 55x 1x 1x 55x 55x 55x 55x 21x 21x 21x 21x 21x 90x 90x 90x 1x 3x 1x 16x 2x 12x 51x 4x 1x 1x | import Check from "../Core/Check.js";
import ComponentDatatype from "../Core/ComponentDatatype.js";
import defined from "../Core/defined.js";
import deprecationWarning from "../Core/deprecationWarning.js";
import DeveloperError from "../Core/DeveloperError.js";
import RuntimeError from "../Core/RuntimeError.js";
import BatchTableHierarchy from "./BatchTableHierarchy.js";
import StructuralMetadata from "./StructuralMetadata.js";
import PropertyAttribute from "./PropertyAttribute.js";
import PropertyTable from "./PropertyTable.js";
import getBinaryAccessor from "./getBinaryAccessor.js";
import JsonMetadataTable from "./JsonMetadataTable.js";
import MetadataClass from "./MetadataClass.js";
import MetadataSchema from "./MetadataSchema.js";
import MetadataTable from "./MetadataTable.js";
import ModelComponents from "./ModelComponents.js";
import ModelUtility from "./Model/ModelUtility.js";
import oneTimeWarning from "../Core/oneTimeWarning.js";
/**
* An object that parses the the 3D Tiles 1.0 batch table and transcodes it to
* be compatible with structural metadata from the <code>EXT_structural_metadata</code> glTF extension
* <p>
* See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} for glTF.
* </p>
*
* @param {object} options Object with the following properties:
* @param {number} options.count The number of features in the batch table.
* @param {object} options.batchTable The batch table JSON
* @param {Uint8Array} [options.binaryBody] The batch table binary body
* @param {boolean} [options.parseAsPropertyAttributes=false] If true, binary properties are parsed as property attributes instead of a property table. This is used for .pnts models for GPU styling.
* @param {ModelComponents.Attribute[]} [options.customAttributeOutput] Pass in an empty array here and this method will populate it with a list of custom attributes that will store the values of the property attributes. The attributes will be created with typed arrays, the caller is responsible for uploading them to the GPU. This option is required when options.parseAsPropertyAttributes is true.
* @return {StructuralMetadata} A transcoded structural metadata object
*
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
function parseBatchTable(options) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.number("options.count", options.count);
Check.typeOf.object("options.batchTable", options.batchTable);
//>>includeEnd('debug');
const featureCount = options.count;
const batchTable = options.batchTable;
const binaryBody = options.binaryBody;
const parseAsPropertyAttributes = options.parseAsPropertyAttributes ?? false;
const customAttributeOutput = options.customAttributeOutput;
//>>includeStart('debug', pragmas.debug);
if (parseAsPropertyAttributes && !defined(customAttributeOutput)) {
throw new DeveloperError(
"customAttributeOutput is required when parsing batch table as property attributes",
);
}
//>>includeEnd('debug');
// divide properties into binary, json and hierarchy
const partitionResults = partitionProperties(batchTable);
let jsonMetadataTable;
if (defined(partitionResults.jsonProperties)) {
jsonMetadataTable = new JsonMetadataTable({
count: featureCount,
properties: partitionResults.jsonProperties,
});
}
let hierarchy;
if (defined(partitionResults.hierarchy)) {
hierarchy = new BatchTableHierarchy({
extension: partitionResults.hierarchy,
binaryBody: binaryBody,
});
}
const className = MetadataClass.BATCH_TABLE_CLASS_NAME;
const binaryProperties = partitionResults.binaryProperties;
let metadataTable;
let propertyAttributes;
let transcodedSchema;
if (parseAsPropertyAttributes) {
const attributeResults = transcodeBinaryPropertiesAsPropertyAttributes(
featureCount,
className,
binaryProperties,
binaryBody,
customAttributeOutput,
);
transcodedSchema = attributeResults.transcodedSchema;
const propertyAttribute = new PropertyAttribute({
propertyAttribute: attributeResults.propertyAttributeJson,
class: attributeResults.transcodedClass,
});
propertyAttributes = [propertyAttribute];
} else {
const binaryResults = transcodeBinaryProperties(
featureCount,
className,
binaryProperties,
binaryBody,
);
transcodedSchema = binaryResults.transcodedSchema;
const featureTableJson = binaryResults.featureTableJson;
metadataTable = new MetadataTable({
count: featureTableJson.count,
properties: featureTableJson.properties,
class: binaryResults.transcodedClass,
bufferViews: binaryResults.bufferViewsTypedArrays,
});
propertyAttributes = [];
}
const propertyTables = [];
if (
defined(metadataTable) ||
defined(jsonMetadataTable) ||
defined(hierarchy)
) {
const propertyTable = new PropertyTable({
id: 0,
name: "Batch Table",
count: featureCount,
metadataTable: metadataTable,
jsonMetadataTable: jsonMetadataTable,
batchTableHierarchy: hierarchy,
});
propertyTables.push(propertyTable);
}
const metadataOptions = {
schema: transcodedSchema,
propertyTables: propertyTables,
propertyAttributes: propertyAttributes,
extensions: partitionResults.extensions,
extras: partitionResults.extras,
};
return new StructuralMetadata(metadataOptions);
}
/**
* Divide the batch table's properties into binary, JSON and hierarchy
* extension as each is handled separately
*
* @param {object} batchTable The batch table JSON
* @returns {object} The batch table divided into binary, JSON and hierarchy portions. Extras and extensions are also divided out for ease of processing.
*
* @private
*/
function partitionProperties(batchTable) {
const legacyHierarchy = batchTable.HIERARCHY;
const extras = batchTable.extras;
const extensions = batchTable.extensions;
let hierarchyExtension;
if (defined(legacyHierarchy)) {
parseBatchTable._deprecationWarning(
"batchTableHierarchyExtension",
"The batch table HIERARCHY property has been moved to an extension. Use extensions.3DTILES_batch_table_hierarchy instead.",
);
hierarchyExtension = legacyHierarchy;
} else if (defined(extensions)) {
hierarchyExtension = extensions["3DTILES_batch_table_hierarchy"];
}
// A JsonMetadataTable is only allocated as needed.
let jsonProperties;
// A MetadataTable or PropertyAttribute will always be created, even if
// there are no properties.
const binaryProperties = {};
for (const propertyId in batchTable) {
if (
!batchTable.hasOwnProperty(propertyId) ||
// these cases were handled above;
propertyId === "HIERARCHY" ||
propertyId === "extensions" ||
propertyId === "extras"
) {
continue;
}
const property = batchTable[propertyId];
if (Array.isArray(property)) {
jsonProperties = defined(jsonProperties) ? jsonProperties : {};
jsonProperties[propertyId] = property;
} else {
binaryProperties[propertyId] = property;
}
}
return {
binaryProperties: binaryProperties,
jsonProperties: jsonProperties,
hierarchy: hierarchyExtension,
extras: extras,
extensions: extensions,
};
}
/**
* Transcode the binary properties of the batch table to be compatible with
* <code>EXT_structural_metadata</code>
*
* @param {number} featureCount The number of features in the batch table
* @param {string} className The name of the metadata class to be created.
* @param {Object<string, Object>} binaryProperties A dictionary of property ID to property definition
* @param {Uint8Array} [binaryBody] The binary body of the batch table
* @return {object} Transcoded data needed for constructing a {@link StructuralMetadata} object.
*
* @private
*/
function transcodeBinaryProperties(
featureCount,
className,
binaryProperties,
binaryBody,
) {
const classProperties = {};
const featureTableProperties = {};
const bufferViewsTypedArrays = {};
let bufferViewCount = 0;
for (const propertyId in binaryProperties) {
Iif (!binaryProperties.hasOwnProperty(propertyId)) {
continue;
}
if (!defined(binaryBody)) {
throw new RuntimeError(
`Property ${propertyId} requires a batch table binary.`,
);
}
const property = binaryProperties[propertyId];
const binaryAccessor = getBinaryAccessor(property);
featureTableProperties[propertyId] = {
bufferView: bufferViewCount,
};
classProperties[propertyId] = transcodePropertyType(property);
bufferViewsTypedArrays[bufferViewCount] =
binaryAccessor.createArrayBufferView(
binaryBody.buffer,
binaryBody.byteOffset + property.byteOffset,
featureCount,
);
bufferViewCount++;
}
const schemaJson = {
classes: {},
};
schemaJson.classes[className] = {
properties: classProperties,
};
const transcodedSchema = MetadataSchema.fromJson(schemaJson);
const featureTableJson = {
class: className,
count: featureCount,
properties: featureTableProperties,
};
return {
featureTableJson: featureTableJson,
bufferViewsTypedArrays: bufferViewsTypedArrays,
transcodedSchema: transcodedSchema,
transcodedClass: transcodedSchema.classes[className],
};
}
function transcodeBinaryPropertiesAsPropertyAttributes(
featureCount,
className,
binaryProperties,
binaryBody,
customAttributeOutput,
) {
const classProperties = {};
const propertyAttributeProperties = {};
let nextPlaceholderId = 0;
for (const propertyId in binaryProperties) {
Iif (!binaryProperties.hasOwnProperty(propertyId)) {
continue;
}
// For draco-compressed attributes from .pnts files, the results will be
// stored in separate typed arrays. These will be used in place of the
// binary body
const property = binaryProperties[propertyId];
Iif (!defined(binaryBody) && !defined(property.typedArray)) {
throw new RuntimeError(
`Property ${propertyId} requires a batch table binary.`,
);
}
let sanitizedPropertyId = ModelUtility.sanitizeGlslIdentifier(propertyId);
// If the sanitized string is empty or a duplicate, use a placeholder
// name instead. This will work for styling, but it may lead to undefined
// behavior in CustomShader, since
// - different tiles may pick a different placeholder ID due to the
// collection being unordered
// - different tiles may have different number of properties.
if (
sanitizedPropertyId === "" ||
classProperties.hasOwnProperty(sanitizedPropertyId)
) {
sanitizedPropertyId = `property_${nextPlaceholderId}`;
nextPlaceholderId++;
}
const classProperty = transcodePropertyType(property);
classProperty.name = propertyId;
classProperties[sanitizedPropertyId] = classProperty;
// Extract the typed array and create a custom attribute as a typed array.
// The caller must add the results to the ModelComponents, and upload the
// typed array to the GPU. The attribute name is converted to all capitals
// and underscores, like a glTF custom attribute.
//
// For example, if the original property ID was 'Temperature ℃', the result
// is _TEMPERATURE
let customAttributeName = sanitizedPropertyId.toUpperCase();
if (!customAttributeName.startsWith("_")) {
customAttributeName = `_${customAttributeName}`;
}
// for .pnts with draco compression, property.typedArray is used
// instead of the binary body.
let attributeTypedArray = property.typedArray;
if (!defined(attributeTypedArray)) {
const binaryAccessor = getBinaryAccessor(property);
attributeTypedArray = binaryAccessor.createArrayBufferView(
binaryBody.buffer,
binaryBody.byteOffset + property.byteOffset,
featureCount,
);
}
const attribute = new ModelComponents.Attribute();
attribute.name = customAttributeName;
attribute.count = featureCount;
attribute.type = property.type;
const componentDatatype =
ComponentDatatype.fromTypedArray(attributeTypedArray);
if (
componentDatatype === ComponentDatatype.INT ||
componentDatatype === ComponentDatatype.UNSIGNED_INT ||
componentDatatype === ComponentDatatype.DOUBLE
) {
parseBatchTable._oneTimeWarning(
"Cast pnts property to floats",
`Point cloud property "${customAttributeName}" will be cast to a float array because INT, UNSIGNED_INT, and DOUBLE are not valid WebGL vertex attribute types. Some precision may be lost.`,
);
attributeTypedArray = new Float32Array(attributeTypedArray);
}
attribute.componentDatatype =
ComponentDatatype.fromTypedArray(attributeTypedArray);
attribute.typedArray = attributeTypedArray;
customAttributeOutput.push(attribute);
// Refer to the custom attribute name from the property attribute
propertyAttributeProperties[sanitizedPropertyId] = {
attribute: customAttributeName,
};
}
const schemaJson = {
classes: {},
};
schemaJson.classes[className] = {
properties: classProperties,
};
const transcodedSchema = MetadataSchema.fromJson(schemaJson);
const propertyAttributeJson = {
properties: propertyAttributeProperties,
};
return {
class: className,
propertyAttributeJson: propertyAttributeJson,
transcodedSchema: transcodedSchema,
transcodedClass: transcodedSchema.classes[className],
};
}
/**
* Given a property definition from the batch table, compute the equivalent
* <code>EXT_structural_metadata</code> type definition
*
* @param {object} property The batch table property definition
* @return {object} The corresponding structural metadata property definition
* @private
*/
function transcodePropertyType(property) {
const componentType = transcodeComponentType(property.componentType);
return {
type: property.type,
componentType: componentType,
};
}
/**
* Convert the component type of a batch table property to the corresponding
* type used with structural metadata
*
* @property {string} componentType the batch table's component type
* @return {string} The corresponding structural metadata data type
*
* @private
*/
function transcodeComponentType(componentType) {
switch (componentType) {
case "BYTE":
return "INT8";
case "UNSIGNED_BYTE":
return "UINT8";
case "SHORT":
return "INT16";
case "UNSIGNED_SHORT":
return "UINT16";
case "INT":
return "INT32";
case "UNSIGNED_INT":
return "UINT32";
case "FLOAT":
return "FLOAT32";
case "DOUBLE":
return "FLOAT64";
}
}
// exposed for testing
parseBatchTable._deprecationWarning = deprecationWarning;
parseBatchTable._oneTimeWarning = oneTimeWarning;
export default parseBatchTable;
|