removeUnusedElements.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. import ForEach from "./ForEach.js";
  2. import forEachTextureInMaterial from "./forEachTextureInMaterial.js";
  3. import usesExtension from "./usesExtension.js";
  4. import defaultValue from "../../Core/defaultValue.js";
  5. import defined from "../../Core/defined.js";
  6. const allElementTypes = [
  7. "mesh",
  8. "node",
  9. "material",
  10. "accessor",
  11. "bufferView",
  12. "buffer",
  13. "texture",
  14. "sampler",
  15. "image",
  16. ];
  17. /**
  18. * Removes unused elements from gltf.
  19. *
  20. * @param {Object} gltf A javascript object containing a glTF asset.
  21. * @param {String[]} [elementTypes=['mesh', 'node', 'material', 'accessor', 'bufferView', 'buffer']] Element types to be removed. Needs to be a subset of ['mesh', 'node', 'material', 'accessor', 'bufferView', 'buffer'], other items will be ignored.
  22. *
  23. * @private
  24. */
  25. function removeUnusedElements(gltf, elementTypes) {
  26. elementTypes = defaultValue(elementTypes, allElementTypes);
  27. allElementTypes.forEach(function (type) {
  28. if (elementTypes.indexOf(type) > -1) {
  29. removeUnusedElementsByType(gltf, type);
  30. }
  31. });
  32. return gltf;
  33. }
  34. const TypeToGltfElementName = {
  35. accessor: "accessors",
  36. buffer: "buffers",
  37. bufferView: "bufferViews",
  38. image: "images",
  39. node: "nodes",
  40. material: "materials",
  41. mesh: "meshes",
  42. sampler: "samplers",
  43. texture: "textures",
  44. };
  45. function removeUnusedElementsByType(gltf, type) {
  46. const name = TypeToGltfElementName[type];
  47. const arrayOfObjects = gltf[name];
  48. if (defined(arrayOfObjects)) {
  49. let removed = 0;
  50. const usedIds = getListOfElementsIdsInUse[type](gltf);
  51. const length = arrayOfObjects.length;
  52. for (let i = 0; i < length; ++i) {
  53. if (!usedIds[i]) {
  54. Remove[type](gltf, i - removed);
  55. removed++;
  56. }
  57. }
  58. }
  59. }
  60. /**
  61. * Contains functions for removing elements from a glTF hierarchy.
  62. * Since top-level glTF elements are arrays, when something is removed, referring
  63. * indices need to be updated.
  64. * @constructor
  65. *
  66. * @private
  67. */
  68. function Remove() {}
  69. Remove.accessor = function (gltf, accessorId) {
  70. const accessors = gltf.accessors;
  71. accessors.splice(accessorId, 1);
  72. ForEach.mesh(gltf, function (mesh) {
  73. ForEach.meshPrimitive(mesh, function (primitive) {
  74. // Update accessor ids for the primitives.
  75. ForEach.meshPrimitiveAttribute(
  76. primitive,
  77. function (attributeAccessorId, semantic) {
  78. if (attributeAccessorId > accessorId) {
  79. primitive.attributes[semantic]--;
  80. }
  81. }
  82. );
  83. // Update accessor ids for the targets.
  84. ForEach.meshPrimitiveTarget(primitive, function (target) {
  85. ForEach.meshPrimitiveTargetAttribute(
  86. target,
  87. function (attributeAccessorId, semantic) {
  88. if (attributeAccessorId > accessorId) {
  89. target[semantic]--;
  90. }
  91. }
  92. );
  93. });
  94. const indices = primitive.indices;
  95. if (defined(indices) && indices > accessorId) {
  96. primitive.indices--;
  97. }
  98. });
  99. });
  100. ForEach.skin(gltf, function (skin) {
  101. if (
  102. defined(skin.inverseBindMatrices) &&
  103. skin.inverseBindMatrices > accessorId
  104. ) {
  105. skin.inverseBindMatrices--;
  106. }
  107. });
  108. ForEach.animation(gltf, function (animation) {
  109. ForEach.animationSampler(animation, function (sampler) {
  110. if (defined(sampler.input) && sampler.input > accessorId) {
  111. sampler.input--;
  112. }
  113. if (defined(sampler.output) && sampler.output > accessorId) {
  114. sampler.output--;
  115. }
  116. });
  117. });
  118. };
  119. Remove.buffer = function (gltf, bufferId) {
  120. const buffers = gltf.buffers;
  121. buffers.splice(bufferId, 1);
  122. ForEach.bufferView(gltf, function (bufferView) {
  123. if (defined(bufferView.buffer) && bufferView.buffer > bufferId) {
  124. bufferView.buffer--;
  125. }
  126. if (
  127. defined(bufferView.extensions) &&
  128. defined(bufferView.extensions.EXT_meshopt_compression)
  129. ) {
  130. bufferView.extensions.EXT_meshopt_compression.buffer--;
  131. }
  132. });
  133. };
  134. Remove.bufferView = function (gltf, bufferViewId) {
  135. const bufferViews = gltf.bufferViews;
  136. bufferViews.splice(bufferViewId, 1);
  137. ForEach.accessor(gltf, function (accessor) {
  138. if (defined(accessor.bufferView) && accessor.bufferView > bufferViewId) {
  139. accessor.bufferView--;
  140. }
  141. });
  142. ForEach.shader(gltf, function (shader) {
  143. if (defined(shader.bufferView) && shader.bufferView > bufferViewId) {
  144. shader.bufferView--;
  145. }
  146. });
  147. ForEach.image(gltf, function (image) {
  148. if (defined(image.bufferView) && image.bufferView > bufferViewId) {
  149. image.bufferView--;
  150. }
  151. });
  152. if (usesExtension(gltf, "KHR_draco_mesh_compression")) {
  153. ForEach.mesh(gltf, function (mesh) {
  154. ForEach.meshPrimitive(mesh, function (primitive) {
  155. if (
  156. defined(primitive.extensions) &&
  157. defined(primitive.extensions.KHR_draco_mesh_compression)
  158. ) {
  159. if (
  160. primitive.extensions.KHR_draco_mesh_compression.bufferView >
  161. bufferViewId
  162. ) {
  163. primitive.extensions.KHR_draco_mesh_compression.bufferView--;
  164. }
  165. }
  166. });
  167. });
  168. }
  169. if (usesExtension(gltf, "EXT_feature_metadata")) {
  170. const extension = gltf.extensions.EXT_feature_metadata;
  171. const featureTables = extension.featureTables;
  172. for (const featureTableId in featureTables) {
  173. if (featureTables.hasOwnProperty(featureTableId)) {
  174. const featureTable = featureTables[featureTableId];
  175. const properties = featureTable.properties;
  176. if (defined(properties)) {
  177. for (const propertyId in properties) {
  178. if (properties.hasOwnProperty(propertyId)) {
  179. const property = properties[propertyId];
  180. if (
  181. defined(property.bufferView) &&
  182. property.bufferView > bufferViewId
  183. ) {
  184. property.bufferView--;
  185. }
  186. if (
  187. defined(property.arrayOffsetBufferView) &&
  188. property.arrayOffsetBufferView > bufferViewId
  189. ) {
  190. property.arrayOffsetBufferView--;
  191. }
  192. if (
  193. defined(property.stringOffsetBufferView) &&
  194. property.stringOffsetBufferView > bufferViewId
  195. ) {
  196. property.stringOffsetBufferView--;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. };
  205. Remove.image = function (gltf, imageId) {
  206. const images = gltf.images;
  207. images.splice(imageId, 1);
  208. ForEach.texture(gltf, function (texture) {
  209. if (defined(texture.source)) {
  210. if (texture.source > imageId) {
  211. --texture.source;
  212. }
  213. }
  214. const ext = texture.extensions;
  215. if (
  216. defined(ext) &&
  217. defined(ext.EXT_texture_webp) &&
  218. ext.EXT_texture_webp.source > imageId
  219. ) {
  220. --texture.extensions.EXT_texture_webp.source;
  221. } else if (
  222. defined(ext) &&
  223. defined(ext.KHR_texture_basisu) &&
  224. ext.KHR_texture_basisu.source > imageId
  225. ) {
  226. --texture.extensions.KHR_texture_basisu.source;
  227. }
  228. });
  229. };
  230. Remove.mesh = function (gltf, meshId) {
  231. const meshes = gltf.meshes;
  232. meshes.splice(meshId, 1);
  233. ForEach.node(gltf, function (node) {
  234. if (defined(node.mesh)) {
  235. if (node.mesh > meshId) {
  236. node.mesh--;
  237. } else if (node.mesh === meshId) {
  238. // Remove reference to deleted mesh
  239. delete node.mesh;
  240. }
  241. }
  242. });
  243. };
  244. Remove.node = function (gltf, nodeId) {
  245. const nodes = gltf.nodes;
  246. nodes.splice(nodeId, 1);
  247. // Shift all node references
  248. ForEach.skin(gltf, function (skin) {
  249. if (defined(skin.skeleton) && skin.skeleton > nodeId) {
  250. skin.skeleton--;
  251. }
  252. skin.joints = skin.joints.map(function (x) {
  253. return x > nodeId ? x - 1 : x;
  254. });
  255. });
  256. ForEach.animation(gltf, function (animation) {
  257. ForEach.animationChannel(animation, function (channel) {
  258. if (
  259. defined(channel.target) &&
  260. defined(channel.target.node) &&
  261. channel.target.node > nodeId
  262. ) {
  263. channel.target.node--;
  264. }
  265. });
  266. });
  267. ForEach.technique(gltf, function (technique) {
  268. ForEach.techniqueUniform(technique, function (uniform) {
  269. if (defined(uniform.node) && uniform.node > nodeId) {
  270. uniform.node--;
  271. }
  272. });
  273. });
  274. ForEach.node(gltf, function (node) {
  275. if (!defined(node.children)) {
  276. return;
  277. }
  278. node.children = node.children
  279. .filter(function (x) {
  280. return x !== nodeId; // Remove
  281. })
  282. .map(function (x) {
  283. return x > nodeId ? x - 1 : x; // Shift indices
  284. });
  285. });
  286. ForEach.scene(gltf, function (scene) {
  287. scene.nodes = scene.nodes
  288. .filter(function (x) {
  289. return x !== nodeId; // Remove
  290. })
  291. .map(function (x) {
  292. return x > nodeId ? x - 1 : x; // Shift indices
  293. });
  294. });
  295. };
  296. Remove.material = function (gltf, materialId) {
  297. const materials = gltf.materials;
  298. materials.splice(materialId, 1);
  299. // Shift other material ids
  300. ForEach.mesh(gltf, function (mesh) {
  301. ForEach.meshPrimitive(mesh, function (primitive) {
  302. if (defined(primitive.material) && primitive.material > materialId) {
  303. primitive.material--;
  304. }
  305. });
  306. });
  307. };
  308. Remove.sampler = function (gltf, samplerId) {
  309. const samplers = gltf.samplers;
  310. samplers.splice(samplerId, 1);
  311. ForEach.texture(gltf, function (texture) {
  312. if (defined(texture.sampler)) {
  313. if (texture.sampler > samplerId) {
  314. --texture.sampler;
  315. }
  316. }
  317. });
  318. };
  319. Remove.texture = function (gltf, textureId) {
  320. const textures = gltf.textures;
  321. textures.splice(textureId, 1);
  322. ForEach.material(gltf, function (material) {
  323. forEachTextureInMaterial(material, function (textureIndex, textureInfo) {
  324. if (textureInfo.index > textureId) {
  325. --textureInfo.index;
  326. }
  327. });
  328. });
  329. if (usesExtension(gltf, "EXT_feature_metadata")) {
  330. ForEach.mesh(gltf, function (mesh) {
  331. ForEach.meshPrimitive(mesh, function (primitive) {
  332. const extensions = primitive.extensions;
  333. if (defined(extensions) && defined(extensions.EXT_feature_metadata)) {
  334. const extension = extensions.EXT_feature_metadata;
  335. const featureIdTextures = extension.featureIdTextures;
  336. if (defined(featureIdTextures)) {
  337. const featureIdTexturesLength = featureIdTextures.length;
  338. for (let i = 0; i < featureIdTexturesLength; ++i) {
  339. const featureIdTexture = featureIdTextures[i];
  340. const textureInfo = featureIdTexture.featureIds.texture;
  341. if (textureInfo.index > textureId) {
  342. --textureInfo.index;
  343. }
  344. }
  345. }
  346. }
  347. });
  348. });
  349. const extension = gltf.extensions.EXT_feature_metadata;
  350. const featureTextures = extension.featureTextures;
  351. for (const featureTextureId in featureTextures) {
  352. if (featureTextures.hasOwnProperty(featureTextureId)) {
  353. const featureTexture = featureTextures[featureTextureId];
  354. const properties = featureTexture.properties;
  355. if (defined(properties)) {
  356. for (const propertyId in properties) {
  357. if (properties.hasOwnProperty(propertyId)) {
  358. const property = properties[propertyId];
  359. const textureInfo = property.texture;
  360. if (textureInfo.index > textureId) {
  361. --textureInfo.index;
  362. }
  363. }
  364. }
  365. }
  366. }
  367. }
  368. }
  369. };
  370. /**
  371. * Contains functions for getting a list of element ids in use by the glTF asset.
  372. * @constructor
  373. *
  374. * @private
  375. */
  376. function getListOfElementsIdsInUse() {}
  377. getListOfElementsIdsInUse.accessor = function (gltf) {
  378. // Calculate accessor's that are currently in use.
  379. const usedAccessorIds = {};
  380. ForEach.mesh(gltf, function (mesh) {
  381. ForEach.meshPrimitive(mesh, function (primitive) {
  382. ForEach.meshPrimitiveAttribute(primitive, function (accessorId) {
  383. usedAccessorIds[accessorId] = true;
  384. });
  385. ForEach.meshPrimitiveTarget(primitive, function (target) {
  386. ForEach.meshPrimitiveTargetAttribute(target, function (accessorId) {
  387. usedAccessorIds[accessorId] = true;
  388. });
  389. });
  390. const indices = primitive.indices;
  391. if (defined(indices)) {
  392. usedAccessorIds[indices] = true;
  393. }
  394. });
  395. });
  396. ForEach.skin(gltf, function (skin) {
  397. if (defined(skin.inverseBindMatrices)) {
  398. usedAccessorIds[skin.inverseBindMatrices] = true;
  399. }
  400. });
  401. ForEach.animation(gltf, function (animation) {
  402. ForEach.animationSampler(animation, function (sampler) {
  403. if (defined(sampler.input)) {
  404. usedAccessorIds[sampler.input] = true;
  405. }
  406. if (defined(sampler.output)) {
  407. usedAccessorIds[sampler.output] = true;
  408. }
  409. });
  410. });
  411. if (usesExtension(gltf, "EXT_mesh_gpu_instancing")) {
  412. ForEach.node(gltf, function (node) {
  413. if (
  414. defined(node.extensions) &&
  415. defined(node.extensions.EXT_mesh_gpu_instancing)
  416. ) {
  417. Object.keys(node.extensions.EXT_mesh_gpu_instancing.attributes).forEach(
  418. function (key) {
  419. const attributeAccessorId =
  420. node.extensions.EXT_mesh_gpu_instancing.attributes[key];
  421. usedAccessorIds[attributeAccessorId] = true;
  422. }
  423. );
  424. }
  425. });
  426. }
  427. return usedAccessorIds;
  428. };
  429. getListOfElementsIdsInUse.buffer = function (gltf) {
  430. // Calculate buffer's that are currently in use.
  431. const usedBufferIds = {};
  432. ForEach.bufferView(gltf, function (bufferView) {
  433. if (defined(bufferView.buffer)) {
  434. usedBufferIds[bufferView.buffer] = true;
  435. }
  436. if (
  437. defined(bufferView.extensions) &&
  438. defined(bufferView.extensions.EXT_meshopt_compression)
  439. ) {
  440. usedBufferIds[
  441. bufferView.extensions.EXT_meshopt_compression.buffer
  442. ] = true;
  443. }
  444. });
  445. return usedBufferIds;
  446. };
  447. getListOfElementsIdsInUse.bufferView = function (gltf) {
  448. // Calculate bufferView's that are currently in use.
  449. const usedBufferViewIds = {};
  450. ForEach.accessor(gltf, function (accessor) {
  451. if (defined(accessor.bufferView)) {
  452. usedBufferViewIds[accessor.bufferView] = true;
  453. }
  454. });
  455. ForEach.shader(gltf, function (shader) {
  456. if (defined(shader.bufferView)) {
  457. usedBufferViewIds[shader.bufferView] = true;
  458. }
  459. });
  460. ForEach.image(gltf, function (image) {
  461. if (defined(image.bufferView)) {
  462. usedBufferViewIds[image.bufferView] = true;
  463. }
  464. });
  465. if (usesExtension(gltf, "KHR_draco_mesh_compression")) {
  466. ForEach.mesh(gltf, function (mesh) {
  467. ForEach.meshPrimitive(mesh, function (primitive) {
  468. if (
  469. defined(primitive.extensions) &&
  470. defined(primitive.extensions.KHR_draco_mesh_compression)
  471. ) {
  472. usedBufferViewIds[
  473. primitive.extensions.KHR_draco_mesh_compression.bufferView
  474. ] = true;
  475. }
  476. });
  477. });
  478. }
  479. if (usesExtension(gltf, "EXT_feature_metadata")) {
  480. const extension = gltf.extensions.EXT_feature_metadata;
  481. const featureTables = extension.featureTables;
  482. for (const featureTableId in featureTables) {
  483. if (featureTables.hasOwnProperty(featureTableId)) {
  484. const featureTable = featureTables[featureTableId];
  485. const properties = featureTable.properties;
  486. if (defined(properties)) {
  487. for (const propertyId in properties) {
  488. if (properties.hasOwnProperty(propertyId)) {
  489. const property = properties[propertyId];
  490. if (defined(property.bufferView)) {
  491. usedBufferViewIds[property.bufferView] = true;
  492. }
  493. if (defined(property.arrayOffsetBufferView)) {
  494. usedBufferViewIds[property.arrayOffsetBufferView] = true;
  495. }
  496. if (defined(property.stringOffsetBufferView)) {
  497. usedBufferViewIds[property.stringOffsetBufferView] = true;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. }
  505. return usedBufferViewIds;
  506. };
  507. getListOfElementsIdsInUse.image = function (gltf) {
  508. const usedImageIds = {};
  509. ForEach.texture(gltf, function (texture) {
  510. if (defined(texture.source)) {
  511. usedImageIds[texture.source] = true;
  512. }
  513. if (
  514. defined(texture.extensions) &&
  515. defined(texture.extensions.EXT_texture_webp)
  516. ) {
  517. usedImageIds[texture.extensions.EXT_texture_webp.source] = true;
  518. } else if (
  519. defined(texture.extensions) &&
  520. defined(texture.extensions.KHR_texture_basisu)
  521. ) {
  522. usedImageIds[texture.extensions.KHR_texture_basisu.source] = true;
  523. }
  524. });
  525. return usedImageIds;
  526. };
  527. getListOfElementsIdsInUse.mesh = function (gltf) {
  528. const usedMeshIds = {};
  529. ForEach.node(gltf, function (node) {
  530. if (defined(node.mesh && defined(gltf.meshes))) {
  531. const mesh = gltf.meshes[node.mesh];
  532. if (
  533. defined(mesh) &&
  534. defined(mesh.primitives) &&
  535. mesh.primitives.length > 0
  536. ) {
  537. usedMeshIds[node.mesh] = true;
  538. }
  539. }
  540. });
  541. return usedMeshIds;
  542. };
  543. // Check if node is empty. It is considered empty if neither referencing
  544. // mesh, camera, extensions and has no children
  545. function nodeIsEmpty(gltf, nodeId, usedNodeIds) {
  546. const node = gltf.nodes[nodeId];
  547. if (
  548. defined(node.mesh) ||
  549. defined(node.camera) ||
  550. defined(node.skin) ||
  551. defined(node.weights) ||
  552. defined(node.extras) ||
  553. (defined(node.extensions) && Object.keys(node.extensions).length !== 0) ||
  554. defined(usedNodeIds[nodeId])
  555. ) {
  556. return false;
  557. }
  558. // Empty if no children or children are all empty nodes
  559. return (
  560. !defined(node.children) ||
  561. node.children.filter(function (n) {
  562. return !nodeIsEmpty(gltf, n, usedNodeIds);
  563. }).length === 0
  564. );
  565. }
  566. getListOfElementsIdsInUse.node = function (gltf) {
  567. const usedNodeIds = {};
  568. ForEach.skin(gltf, function (skin) {
  569. if (defined(skin.skeleton)) {
  570. usedNodeIds[skin.skeleton] = true;
  571. }
  572. ForEach.skinJoint(skin, function (joint) {
  573. usedNodeIds[joint] = true;
  574. });
  575. });
  576. ForEach.animation(gltf, function (animation) {
  577. ForEach.animationChannel(animation, function (channel) {
  578. if (defined(channel.target) && defined(channel.target.node)) {
  579. usedNodeIds[channel.target.node] = true;
  580. }
  581. });
  582. });
  583. ForEach.technique(gltf, function (technique) {
  584. ForEach.techniqueUniform(technique, function (uniform) {
  585. if (defined(uniform.node)) {
  586. usedNodeIds[uniform.node] = true;
  587. }
  588. });
  589. });
  590. ForEach.node(gltf, function (node, nodeId) {
  591. if (!nodeIsEmpty(gltf, nodeId, usedNodeIds)) {
  592. usedNodeIds[nodeId] = true;
  593. }
  594. });
  595. return usedNodeIds;
  596. };
  597. getListOfElementsIdsInUse.material = function (gltf) {
  598. const usedMaterialIds = {};
  599. ForEach.mesh(gltf, function (mesh) {
  600. ForEach.meshPrimitive(mesh, function (primitive) {
  601. if (defined(primitive.material)) {
  602. usedMaterialIds[primitive.material] = true;
  603. }
  604. });
  605. });
  606. return usedMaterialIds;
  607. };
  608. getListOfElementsIdsInUse.texture = function (gltf) {
  609. const usedTextureIds = {};
  610. ForEach.material(gltf, function (material) {
  611. forEachTextureInMaterial(material, function (textureId) {
  612. usedTextureIds[textureId] = true;
  613. });
  614. });
  615. if (usesExtension(gltf, "EXT_feature_metadata")) {
  616. ForEach.mesh(gltf, function (mesh) {
  617. ForEach.meshPrimitive(mesh, function (primitive) {
  618. const extensions = primitive.extensions;
  619. if (defined(extensions) && defined(extensions.EXT_feature_metadata)) {
  620. const extension = extensions.EXT_feature_metadata;
  621. const featureIdTextures = extension.featureIdTextures;
  622. if (defined(featureIdTextures)) {
  623. const featureIdTexturesLength = featureIdTextures.length;
  624. for (let i = 0; i < featureIdTexturesLength; ++i) {
  625. const featureIdTexture = featureIdTextures[i];
  626. const textureInfo = featureIdTexture.featureIds.texture;
  627. usedTextureIds[textureInfo.index] = true;
  628. }
  629. }
  630. }
  631. });
  632. });
  633. const extension = gltf.extensions.EXT_feature_metadata;
  634. const featureTextures = extension.featureTextures;
  635. for (const featureTextureId in featureTextures) {
  636. if (featureTextures.hasOwnProperty(featureTextureId)) {
  637. const featureTexture = featureTextures[featureTextureId];
  638. const properties = featureTexture.properties;
  639. if (defined(properties)) {
  640. for (const propertyId in properties) {
  641. if (properties.hasOwnProperty(propertyId)) {
  642. const property = properties[propertyId];
  643. const textureInfo = property.texture;
  644. usedTextureIds[textureInfo.index] = true;
  645. }
  646. }
  647. }
  648. }
  649. }
  650. }
  651. return usedTextureIds;
  652. };
  653. getListOfElementsIdsInUse.sampler = function (gltf) {
  654. const usedSamplerIds = {};
  655. ForEach.texture(gltf, function (texture) {
  656. if (defined(texture.sampler)) {
  657. usedSamplerIds[texture.sampler] = true;
  658. }
  659. });
  660. return usedSamplerIds;
  661. };
  662. export default removeUnusedElements;