parseStructuralMetadata.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import PropertyTable from "./PropertyTable.js";
  5. import PropertyTexture from "./PropertyTexture.js";
  6. import PropertyAttribute from "./PropertyAttribute.js";
  7. import StructuralMetadata from "./StructuralMetadata.js";
  8. import MetadataTable from "./MetadataTable.js";
  9. /**
  10. * Parse the <code>EXT_structural_metadata</code> glTF extension to create a
  11. * structural metadata object.
  12. *
  13. * @param {object} options Object with the following properties:
  14. * @param {object} options.extension The extension JSON object.
  15. * @param {MetadataSchema} options.schema The parsed schema.
  16. * @param {Object<string, Uint8Array>} [options.bufferViews] An object mapping bufferView IDs to Uint8Array objects.
  17. * @param {Object<string, Texture>} [options.textures] An object mapping texture IDs to {@link Texture} objects.
  18. * @return {StructuralMetadata} A structural metadata object
  19. * @private
  20. * @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.
  21. */
  22. function parseStructuralMetadata(options) {
  23. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  24. const extension = options.extension;
  25. // The calling code is responsible for loading the schema.
  26. // This keeps metadata parsing synchronous.
  27. const schema = options.schema;
  28. //>>includeStart('debug', pragmas.debug);
  29. Check.typeOf.object("options.extension", extension);
  30. Check.typeOf.object("options.schema", schema);
  31. //>>includeEnd('debug');
  32. const propertyTables = [];
  33. if (defined(extension.propertyTables)) {
  34. for (let i = 0; i < extension.propertyTables.length; i++) {
  35. const propertyTable = extension.propertyTables[i];
  36. const classDefinition = schema.classes[propertyTable.class];
  37. const metadataTable = new MetadataTable({
  38. count: propertyTable.count,
  39. properties: propertyTable.properties,
  40. class: classDefinition,
  41. bufferViews: options.bufferViews,
  42. });
  43. propertyTables.push(
  44. new PropertyTable({
  45. id: i,
  46. name: propertyTable.name,
  47. count: propertyTable.count,
  48. metadataTable: metadataTable,
  49. extras: propertyTable.extras,
  50. extensions: propertyTable.extensions,
  51. })
  52. );
  53. }
  54. }
  55. const propertyTextures = [];
  56. if (defined(extension.propertyTextures)) {
  57. for (let i = 0; i < extension.propertyTextures.length; i++) {
  58. const propertyTexture = extension.propertyTextures[i];
  59. propertyTextures.push(
  60. new PropertyTexture({
  61. id: i,
  62. name: propertyTexture.name,
  63. propertyTexture: propertyTexture,
  64. class: schema.classes[propertyTexture.class],
  65. textures: options.textures,
  66. })
  67. );
  68. }
  69. }
  70. const propertyAttributes = [];
  71. if (defined(extension.propertyAttributes)) {
  72. for (let i = 0; i < extension.propertyAttributes.length; i++) {
  73. const propertyAttribute = extension.propertyAttributes[i];
  74. propertyAttributes.push(
  75. new PropertyAttribute({
  76. id: i,
  77. name: propertyAttribute.name,
  78. class: schema.classes[propertyAttribute.class],
  79. propertyAttribute: propertyAttribute,
  80. })
  81. );
  82. }
  83. }
  84. return new StructuralMetadata({
  85. schema: schema,
  86. propertyTables: propertyTables,
  87. propertyTextures: propertyTextures,
  88. propertyAttributes: propertyAttributes,
  89. statistics: extension.statistics,
  90. extras: extension.extras,
  91. extensions: extension.extensions,
  92. });
  93. }
  94. export default parseStructuralMetadata;