@babylonjs/serializers 9.13.0 → 9.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/3MF/core/model/pure.d.ts +8 -0
  2. package/3MF/core/model/pure.js +9 -0
  3. package/3MF/core/model/pure.js.map +1 -0
  4. package/3MF/core/pure.d.ts +3 -0
  5. package/3MF/core/pure.js +5 -0
  6. package/3MF/core/pure.js.map +1 -0
  7. package/3MF/core/xml/pure.d.ts +7 -0
  8. package/3MF/core/xml/pure.js +8 -0
  9. package/3MF/core/xml/pure.js.map +1 -0
  10. package/3MF/pure.d.ts +4 -0
  11. package/3MF/pure.js +6 -0
  12. package/3MF/pure.js.map +1 -0
  13. package/BVH/pure.d.ts +2 -0
  14. package/BVH/pure.js +3 -0
  15. package/BVH/pure.js.map +1 -0
  16. package/OBJ/pure.d.ts +2 -0
  17. package/OBJ/pure.js +3 -0
  18. package/OBJ/pure.js.map +1 -0
  19. package/USDZ/pure.d.ts +2 -0
  20. package/USDZ/pure.js +4 -0
  21. package/USDZ/pure.js.map +1 -0
  22. package/glTF/2.0/Extensions/EXT_lights_area.d.ts +3 -37
  23. package/glTF/2.0/Extensions/EXT_lights_area.js +5 -130
  24. package/glTF/2.0/Extensions/EXT_lights_area.js.map +1 -1
  25. package/glTF/2.0/Extensions/EXT_lights_area.pure.d.ts +44 -0
  26. package/glTF/2.0/Extensions/EXT_lights_area.pure.js +145 -0
  27. package/glTF/2.0/Extensions/EXT_lights_area.pure.js.map +1 -0
  28. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +4 -38
  29. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +6 -138
  30. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  31. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.d.ts +44 -0
  32. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js +151 -0
  33. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js.map +1 -0
  34. package/glTF/2.0/Extensions/EXT_texture_avif.d.ts +3 -15
  35. package/glTF/2.0/Extensions/EXT_texture_avif.js +5 -38
  36. package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -1
  37. package/glTF/2.0/Extensions/EXT_texture_avif.pure.d.ts +27 -0
  38. package/glTF/2.0/Extensions/EXT_texture_avif.pure.js +58 -0
  39. package/glTF/2.0/Extensions/EXT_texture_avif.pure.js.map +1 -0
  40. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +3 -14
  41. package/glTF/2.0/Extensions/EXT_texture_webp.js +5 -37
  42. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  43. package/glTF/2.0/Extensions/EXT_texture_webp.pure.d.ts +26 -0
  44. package/glTF/2.0/Extensions/EXT_texture_webp.pure.js +57 -0
  45. package/glTF/2.0/Extensions/EXT_texture_webp.pure.js.map +1 -0
  46. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +3 -30
  47. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +5 -128
  48. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  49. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.d.ts +37 -0
  50. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js +143 -0
  51. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js.map +1 -0
  52. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +3 -37
  53. package/glTF/2.0/Extensions/KHR_lights_punctual.js +5 -142
  54. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.d.ts +44 -0
  56. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js +157 -0
  57. package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js.map +1 -0
  58. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +3 -30
  59. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +5 -177
  60. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  61. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.d.ts +37 -0
  62. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js +192 -0
  63. package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js.map +1 -0
  64. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +3 -30
  65. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +5 -251
  66. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  67. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.d.ts +37 -0
  68. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js +266 -0
  69. package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js.map +1 -0
  70. package/glTF/2.0/Extensions/KHR_materials_coat.d.ts +3 -30
  71. package/glTF/2.0/Extensions/KHR_materials_coat.js +5 -380
  72. package/glTF/2.0/Extensions/KHR_materials_coat.js.map +1 -1
  73. package/glTF/2.0/Extensions/KHR_materials_coat.pure.d.ts +37 -0
  74. package/glTF/2.0/Extensions/KHR_materials_coat.pure.js +395 -0
  75. package/glTF/2.0/Extensions/KHR_materials_coat.pure.js.map +1 -0
  76. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.d.ts +3 -22
  77. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js +5 -75
  78. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js.map +1 -1
  79. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.d.ts +29 -0
  80. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js +90 -0
  81. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js.map +1 -0
  82. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +3 -38
  83. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +5 -115
  84. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
  85. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.d.ts +45 -0
  86. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js +130 -0
  87. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js.map +1 -0
  88. package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +3 -29
  89. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +5 -60
  90. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
  91. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.d.ts +36 -0
  92. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js +75 -0
  93. package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js.map +1 -0
  94. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +3 -25
  95. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +5 -54
  96. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  97. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.d.ts +32 -0
  98. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js +69 -0
  99. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js.map +1 -0
  100. package/glTF/2.0/Extensions/KHR_materials_fuzz.d.ts +3 -30
  101. package/glTF/2.0/Extensions/KHR_materials_fuzz.js +5 -191
  102. package/glTF/2.0/Extensions/KHR_materials_fuzz.js.map +1 -1
  103. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.d.ts +37 -0
  104. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js +206 -0
  105. package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js.map +1 -0
  106. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +3 -27
  107. package/glTF/2.0/Extensions/KHR_materials_ior.js +5 -67
  108. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  109. package/glTF/2.0/Extensions/KHR_materials_ior.pure.d.ts +34 -0
  110. package/glTF/2.0/Extensions/KHR_materials_ior.pure.js +81 -0
  111. package/glTF/2.0/Extensions/KHR_materials_ior.pure.js.map +1 -0
  112. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +3 -22
  113. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +5 -100
  114. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
  115. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.d.ts +29 -0
  116. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js +115 -0
  117. package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js.map +1 -0
  118. package/glTF/2.0/Extensions/KHR_materials_openpbr.d.ts +3 -25
  119. package/glTF/2.0/Extensions/KHR_materials_openpbr.js +5 -41
  120. package/glTF/2.0/Extensions/KHR_materials_openpbr.js.map +1 -1
  121. package/glTF/2.0/Extensions/KHR_materials_openpbr.pure.d.ts +32 -0
  122. package/glTF/2.0/Extensions/KHR_materials_openpbr.pure.js +56 -0
  123. package/glTF/2.0/Extensions/KHR_materials_openpbr.pure.js.map +1 -0
  124. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +3 -22
  125. package/glTF/2.0/Extensions/KHR_materials_sheen.js +5 -63
  126. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  127. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.d.ts +29 -0
  128. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js +78 -0
  129. package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js.map +1 -0
  130. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +3 -39
  131. package/glTF/2.0/Extensions/KHR_materials_specular.js +5 -123
  132. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  133. package/glTF/2.0/Extensions/KHR_materials_specular.pure.d.ts +46 -0
  134. package/glTF/2.0/Extensions/KHR_materials_specular.pure.js +138 -0
  135. package/glTF/2.0/Extensions/KHR_materials_specular.pure.js.map +1 -0
  136. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +3 -38
  137. package/glTF/2.0/Extensions/KHR_materials_transmission.js +5 -145
  138. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  139. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.d.ts +45 -0
  140. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js +160 -0
  141. package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js.map +1 -0
  142. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +3 -18
  143. package/glTF/2.0/Extensions/KHR_materials_unlit.js +5 -43
  144. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  145. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.d.ts +25 -0
  146. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js +58 -0
  147. package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js.map +1 -0
  148. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +3 -38
  149. package/glTF/2.0/Extensions/KHR_materials_volume.js +5 -169
  150. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  151. package/glTF/2.0/Extensions/KHR_materials_volume.pure.d.ts +45 -0
  152. package/glTF/2.0/Extensions/KHR_materials_volume.pure.js +184 -0
  153. package/glTF/2.0/Extensions/KHR_materials_volume.pure.js.map +1 -0
  154. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.d.ts +3 -38
  155. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js +5 -130
  156. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js.map +1 -1
  157. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.d.ts +45 -0
  158. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js +145 -0
  159. package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js.map +1 -0
  160. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +3 -14
  161. package/glTF/2.0/Extensions/KHR_texture_basisu.js +5 -37
  162. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  163. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.d.ts +26 -0
  164. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js +57 -0
  165. package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js.map +1 -0
  166. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +3 -19
  167. package/glTF/2.0/Extensions/KHR_texture_transform.js +5 -90
  168. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  169. package/glTF/2.0/Extensions/KHR_texture_transform.pure.d.ts +26 -0
  170. package/glTF/2.0/Extensions/KHR_texture_transform.pure.js +105 -0
  171. package/glTF/2.0/Extensions/KHR_texture_transform.pure.js.map +1 -0
  172. package/glTF/2.0/Extensions/pure.d.ts +26 -0
  173. package/glTF/2.0/Extensions/pure.js +27 -0
  174. package/glTF/2.0/Extensions/pure.js.map +1 -0
  175. package/glTF/2.0/pure.d.ts +5 -0
  176. package/glTF/2.0/pure.js +7 -0
  177. package/glTF/2.0/pure.js.map +1 -0
  178. package/glTF/pure.d.ts +3 -0
  179. package/glTF/pure.js +5 -0
  180. package/glTF/pure.js.map +1 -0
  181. package/package.json +30 -4
  182. package/pure.d.ts +7 -0
  183. package/pure.js +9 -0
  184. package/pure.js.map +1 -0
  185. package/stl/pure.d.ts +2 -0
  186. package/stl/pure.js +3 -0
  187. package/stl/pure.js.map +1 -0
@@ -1,40 +1,8 @@
1
- import { GLTFExporter } from "../glTFExporter.js";
2
- import { GetMimeType } from "@babylonjs/core/Misc/fileTools.js";
3
- const NAME = "EXT_texture_webp";
4
1
  /**
5
- * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_webp/README.md)
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./EXT_texture_webp.pure" for tree-shakeable, side-effect-free usage.
6
4
  */
7
- // eslint-disable-next-line @typescript-eslint/naming-convention
8
- export class EXT_texture_webp {
9
- get wasUsed() {
10
- return this._wasUsed;
11
- }
12
- constructor(exporter) {
13
- this.name = NAME;
14
- this.enabled = true;
15
- this.required = true;
16
- this._wasUsed = false;
17
- this._exporter = exporter;
18
- }
19
- dispose() { }
20
- postExportTexture(_, textureInfo) {
21
- const texture = this._exporter._textures[textureInfo.index];
22
- const imageIndex = texture.source;
23
- if (imageIndex === undefined) {
24
- return;
25
- }
26
- const image = this._exporter._images[imageIndex];
27
- const sourceMimeType = image.mimeType || GetMimeType(image.uri);
28
- if (sourceMimeType !== "image/webp" /* ImageMimeType.WEBP */) {
29
- return;
30
- }
31
- texture.source = undefined;
32
- texture.extensions || (texture.extensions = {});
33
- texture.extensions[NAME] = {
34
- source: imageIndex,
35
- };
36
- this._wasUsed = true;
37
- }
38
- }
39
- GLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_texture_webp(exporter));
5
+ export * from "./EXT_texture_webp.pure.js";
6
+ import { RegisterEXT_texture_webp } from "./EXT_texture_webp.pure.js";
7
+ RegisterEXT_texture_webp();
40
8
  //# sourceMappingURL=EXT_texture_webp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_texture_webp.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/EXT_texture_webp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEhC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,gBAAgB;IASzB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAID,YAAY,QAAsB;QAdlB,SAAI,GAAG,IAAI,CAAC;QAErB,YAAO,GAAG,IAAI,CAAC;QAEf,aAAQ,GAAG,IAAI,CAAC;QAEf,aAAQ,GAAG,KAAK,CAAC;QASrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,OAAO,KAAI,CAAC;IAEZ,iBAAiB,CAAC,CAAS,EAAE,WAAuC;QACvE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;QAClC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,cAAc,GAAG,KAAK,CAAC,QAAQ,IAAI,WAAW,CAAC,KAAK,CAAC,GAAI,CAAC,CAAC;QACjE,IAAI,cAAc,0CAAuB,EAAE,CAAC;YACxC,OAAO;QACX,CAAC;QAED,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;QAC3B,OAAO,CAAC,UAAU,KAAlB,OAAO,CAAC,UAAU,GAAK,EAAE,EAAC;QAC1B,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG;YACvB,MAAM,EAAE,UAAU;SACrB,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\n/* eslint-disable babylonjs/available */\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { GLTFExporter } from \"../glTFExporter\";\nimport { GetMimeType } from \"core/Misc/fileTools\";\nimport { ImageMimeType } from \"babylonjs-gltf2interface\";\n\nconst NAME = \"EXT_texture_webp\";\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_webp/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class EXT_texture_webp implements IGLTFExporterExtensionV2 {\n public readonly name = NAME;\n\n public enabled = true;\n\n public required = true;\n\n private _wasUsed = false;\n\n public get wasUsed() {\n return this._wasUsed;\n }\n\n private _exporter: GLTFExporter;\n\n constructor(exporter: GLTFExporter) {\n this._exporter = exporter;\n }\n\n public dispose() {}\n\n public postExportTexture(_: string, textureInfo: BABYLON.GLTF2.ITextureInfo): void {\n const texture = this._exporter._textures[textureInfo.index];\n const imageIndex = texture.source;\n if (imageIndex === undefined) {\n return;\n }\n\n const image = this._exporter._images[imageIndex];\n const sourceMimeType = image.mimeType || GetMimeType(image.uri!);\n if (sourceMimeType !== ImageMimeType.WEBP) {\n return;\n }\n\n texture.source = undefined;\n texture.extensions ||= {};\n texture.extensions[NAME] = {\n source: imageIndex,\n };\n\n this._wasUsed = true;\n }\n}\n\nGLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_texture_webp(exporter));\n"]}
1
+ {"version":3,"file":"EXT_texture_webp.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/EXT_texture_webp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,yBAAyB,CAAC;AAExC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,wBAAwB,EAAE,CAAC","sourcesContent":["/**\n * Re-exports the pure implementation and applies the runtime registration side effect.\n * Import \"./EXT_texture_webp.pure\" for tree-shakeable, side-effect-free usage.\n */\nexport * from \"./EXT_texture_webp.pure\";\n\nimport { RegisterEXT_texture_webp } from \"./EXT_texture_webp.pure\";\nRegisterEXT_texture_webp();\n"]}
@@ -0,0 +1,26 @@
1
+ import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
2
+ import { GLTFExporter } from "../glTFExporter.js";
3
+ /**
4
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_webp/README.md)
5
+ */
6
+ export declare class EXT_texture_webp implements IGLTFExporterExtensionV2 {
7
+ readonly name = "EXT_texture_webp";
8
+ enabled: boolean;
9
+ required: boolean;
10
+ private _wasUsed;
11
+ get wasUsed(): boolean;
12
+ private _exporter;
13
+ constructor(exporter: GLTFExporter);
14
+ dispose(): void;
15
+ /**
16
+ * Called after a texture is exported to register the encoded image MIME type.
17
+ * @param _ - the name of the exported babylon texture (unused)
18
+ * @param textureInfo - the glTF texture info for the exported texture
19
+ */
20
+ postExportTexture(_: string, textureInfo: BABYLON.GLTF2.ITextureInfo): void;
21
+ }
22
+ /**
23
+ * Registers the EXT_texture_webp glTF serializer extension with the {@link GLTFExporter}.
24
+ * Safe to call multiple times; only the first call has an effect.
25
+ */
26
+ export declare function RegisterEXT_texture_webp(): void;
@@ -0,0 +1,57 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { GetMimeType } from "@babylonjs/core/Misc/fileTools.pure.js";
3
+ const NAME = "EXT_texture_webp";
4
+ /**
5
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_webp/README.md)
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ export class EXT_texture_webp {
9
+ get wasUsed() {
10
+ return this._wasUsed;
11
+ }
12
+ constructor(exporter) {
13
+ this.name = NAME;
14
+ this.enabled = true;
15
+ this.required = true;
16
+ this._wasUsed = false;
17
+ this._exporter = exporter;
18
+ }
19
+ dispose() { }
20
+ /**
21
+ * Called after a texture is exported to register the encoded image MIME type.
22
+ * @param _ - the name of the exported babylon texture (unused)
23
+ * @param textureInfo - the glTF texture info for the exported texture
24
+ */
25
+ postExportTexture(_, textureInfo) {
26
+ const texture = this._exporter._textures[textureInfo.index];
27
+ const imageIndex = texture.source;
28
+ if (imageIndex === undefined) {
29
+ return;
30
+ }
31
+ const image = this._exporter._images[imageIndex];
32
+ const sourceMimeType = image.mimeType || GetMimeType(image.uri);
33
+ if (sourceMimeType !== "image/webp" /* ImageMimeType.WEBP */) {
34
+ return;
35
+ }
36
+ texture.source = undefined;
37
+ texture.extensions || (texture.extensions = {});
38
+ texture.extensions[NAME] = {
39
+ source: imageIndex,
40
+ };
41
+ this._wasUsed = true;
42
+ }
43
+ }
44
+ let _Registered = false;
45
+ /**
46
+ * Registers the EXT_texture_webp glTF serializer extension with the {@link GLTFExporter}.
47
+ * Safe to call multiple times; only the first call has an effect.
48
+ */
49
+ // eslint-disable-next-line @typescript-eslint/naming-convention
50
+ export function RegisterEXT_texture_webp() {
51
+ if (_Registered) {
52
+ return;
53
+ }
54
+ _Registered = true;
55
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_texture_webp(exporter));
56
+ }
57
+ //# sourceMappingURL=EXT_texture_webp.pure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EXT_texture_webp.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/EXT_texture_webp.pure.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEhC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,gBAAgB;IASzB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAID,YAAY,QAAsB;QAdlB,SAAI,GAAG,IAAI,CAAC;QAErB,YAAO,GAAG,IAAI,CAAC;QAEf,aAAQ,GAAG,IAAI,CAAC;QAEf,aAAQ,GAAG,KAAK,CAAC;QASrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,OAAO,KAAI,CAAC;IAEnB;;;;OAIG;IACI,iBAAiB,CAAC,CAAS,EAAE,WAAuC;QACvE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;QAClC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,cAAc,GAAG,KAAK,CAAC,QAAQ,IAAI,WAAW,CAAC,KAAK,CAAC,GAAI,CAAC,CAAC;QACjE,IAAI,cAAc,0CAAuB,EAAE,CAAC;YACxC,OAAO;QACX,CAAC;QAED,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;QAC3B,OAAO,CAAC,UAAU,KAAlB,OAAO,CAAC,UAAU,GAAK,EAAE,EAAC;QAC1B,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG;YACvB,MAAM,EAAE,UAAU;SACrB,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,wBAAwB;IACpC,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\n/* eslint-disable babylonjs/available */\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { GLTFExporter } from \"../glTFExporter\";\nimport { GetMimeType } from \"core/Misc/fileTools.pure\";\nimport { ImageMimeType } from \"babylonjs-gltf2interface\";\n\nconst NAME = \"EXT_texture_webp\";\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_webp/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class EXT_texture_webp implements IGLTFExporterExtensionV2 {\n public readonly name = NAME;\n\n public enabled = true;\n\n public required = true;\n\n private _wasUsed = false;\n\n public get wasUsed() {\n return this._wasUsed;\n }\n\n private _exporter: GLTFExporter;\n\n constructor(exporter: GLTFExporter) {\n this._exporter = exporter;\n }\n\n public dispose() {}\n\n /**\n * Called after a texture is exported to register the encoded image MIME type.\n * @param _ - the name of the exported babylon texture (unused)\n * @param textureInfo - the glTF texture info for the exported texture\n */\n public postExportTexture(_: string, textureInfo: BABYLON.GLTF2.ITextureInfo): void {\n const texture = this._exporter._textures[textureInfo.index];\n const imageIndex = texture.source;\n if (imageIndex === undefined) {\n return;\n }\n\n const image = this._exporter._images[imageIndex];\n const sourceMimeType = image.mimeType || GetMimeType(image.uri!);\n if (sourceMimeType !== ImageMimeType.WEBP) {\n return;\n }\n\n texture.source = undefined;\n texture.extensions ||= {};\n texture.extensions[NAME] = {\n source: imageIndex,\n };\n\n this._wasUsed = true;\n }\n}\n\nlet _Registered = false;\n/**\n * Registers the EXT_texture_webp glTF serializer extension with the {@link GLTFExporter}.\n * Safe to call multiple times; only the first call has an effect.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function RegisterEXT_texture_webp(): void {\n if (_Registered) {\n return;\n }\n _Registered = true;\n\n GLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_texture_webp(exporter));\n}\n"]}
@@ -1,32 +1,5 @@
1
- import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
2
- import { GLTFExporter } from "../glTFExporter.js";
3
- import { type IAccessor, type IMeshPrimitive } from "babylonjs-gltf2interface";
4
- import { type BufferManager } from "../bufferManager.js";
5
1
  /**
6
- * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./KHR_draco_mesh_compression.pure" for tree-shakeable, side-effect-free usage.
7
4
  */
8
- export declare class KHR_draco_mesh_compression implements IGLTFExporterExtensionV2 {
9
- /** Name of this extension */
10
- readonly name = "KHR_draco_mesh_compression";
11
- /** Defines whether this extension is enabled */
12
- enabled: boolean;
13
- /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */
14
- required: boolean;
15
- /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */
16
- private _bufferViewsUsed;
17
- /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */
18
- private _accessorsUsed;
19
- /** Promise pool for Draco encoding work */
20
- private _encodePromises;
21
- private _wasUsed;
22
- /** @internal */
23
- get wasUsed(): boolean;
24
- /** @internal */
25
- constructor(exporter: GLTFExporter);
26
- /** @internal */
27
- dispose(): void;
28
- /** @internal */
29
- postExportMeshPrimitive(primitive: IMeshPrimitive, bufferManager: BufferManager, accessors: IAccessor[]): void;
30
- /** @internal */
31
- preGenerateBinaryAsync(bufferManager: BufferManager): Promise<void>;
32
- }
5
+ export * from "./KHR_draco_mesh_compression.pure.js";
@@ -1,131 +1,8 @@
1
- import { GLTFExporter } from "../glTFExporter.js";
2
- import { DracoEncoder } from "@babylonjs/core/Meshes/Compression/dracoEncoder.js";
3
- import { GetTypedArrayData, GetTypeByteLength } from "@babylonjs/core/Buffers/bufferUtils.js";
4
- import { GetAccessorElementCount } from "../glTFUtilities.js";
5
- import { Logger } from "@babylonjs/core/Misc/logger.js";
6
- const NAME = "KHR_draco_mesh_compression";
7
- function GetDracoAttributeName(glTFName) {
8
- if (glTFName === "POSITION") {
9
- return "POSITION";
10
- }
11
- else if (glTFName === "NORMAL") {
12
- return "NORMAL";
13
- }
14
- else if (glTFName.startsWith("COLOR")) {
15
- return "COLOR";
16
- }
17
- else if (glTFName.startsWith("TEXCOORD")) {
18
- return "TEX_COORD";
19
- }
20
- return "GENERIC";
21
- }
22
1
  /**
23
- * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./KHR_draco_mesh_compression.pure" for tree-shakeable, side-effect-free usage.
24
4
  */
25
- // eslint-disable-next-line @typescript-eslint/naming-convention
26
- export class KHR_draco_mesh_compression {
27
- /** @internal */
28
- get wasUsed() {
29
- return this._wasUsed;
30
- }
31
- /** @internal */
32
- constructor(exporter) {
33
- /** Name of this extension */
34
- this.name = NAME;
35
- /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */
36
- this.required = true;
37
- /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */
38
- this._bufferViewsUsed = new Set();
39
- /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */
40
- this._accessorsUsed = new Set();
41
- /** Promise pool for Draco encoding work */
42
- this._encodePromises = [];
43
- this._wasUsed = false;
44
- this.enabled = exporter.options.meshCompressionMethod === "Draco" && DracoEncoder.DefaultAvailable;
45
- }
46
- /** @internal */
47
- dispose() { }
48
- /** @internal */
49
- postExportMeshPrimitive(primitive, bufferManager, accessors) {
50
- if (!this.enabled) {
51
- return;
52
- }
53
- if (primitive.mode !== 4 /* MeshPrimitiveMode.TRIANGLES */ && primitive.mode !== 5 /* MeshPrimitiveMode.TRIANGLE_STRIP */) {
54
- Logger.Warn("Cannot compress primitive with mode " + primitive.mode + ".");
55
- return;
56
- }
57
- // Collect bufferViews and accessors used by this primitive
58
- const primitiveBufferViews = [];
59
- const primitiveAccessors = [];
60
- // Prepare indices for Draco encoding
61
- let indices = null;
62
- if (primitive.indices !== undefined) {
63
- const accessor = accessors[primitive.indices];
64
- const bufferView = bufferManager.getBufferView(accessor);
65
- // Per exportIndices, indices must be either Uint16Array or Uint32Array
66
- indices = bufferManager.getData(bufferView).slice();
67
- primitiveBufferViews.push(bufferView);
68
- primitiveAccessors.push(accessor);
69
- }
70
- // Prepare attributes for Draco encoding
71
- const attributes = [];
72
- for (const [name, accessorIndex] of Object.entries(primitive.attributes)) {
73
- const accessor = accessors[accessorIndex];
74
- const bufferView = bufferManager.getBufferView(accessor);
75
- const size = GetAccessorElementCount(accessor.type);
76
- const data = GetTypedArrayData(bufferManager.getData(bufferView), size, accessor.componentType, accessor.byteOffset || 0, bufferView.byteStride || GetTypeByteLength(accessor.componentType) * size, accessor.count, true);
77
- attributes.push({ kind: name, dracoName: GetDracoAttributeName(name), size: GetAccessorElementCount(accessor.type), data: data });
78
- primitiveBufferViews.push(bufferView);
79
- primitiveAccessors.push(accessor);
80
- }
81
- // Use sequential encoding to preserve vertex order for cases like morph targets
82
- const options = {
83
- method: primitive.targets ? "MESH_SEQUENTIAL_ENCODING" : "MESH_EDGEBREAKER_ENCODING",
84
- };
85
- const promise = DracoEncoder.Default._encodeAsync(attributes, indices, options)
86
- // eslint-disable-next-line github/no-then
87
- .then((encodedData) => {
88
- const dracoInfo = {
89
- bufferView: -1, // bufferView will be set to a real index later, when we write the binary and decide bufferView ordering
90
- attributes: encodedData.attributeIds,
91
- };
92
- const bufferView = bufferManager.createBufferView(encodedData.data);
93
- bufferManager.setBufferView(dracoInfo, bufferView);
94
- for (const bufferView of primitiveBufferViews) {
95
- this._bufferViewsUsed.add(bufferView);
96
- }
97
- for (const accessor of primitiveAccessors) {
98
- this._accessorsUsed.add(accessor);
99
- }
100
- primitive.extensions || (primitive.extensions = {});
101
- primitive.extensions[NAME] = dracoInfo;
102
- })
103
- // eslint-disable-next-line github/no-then
104
- .catch((error) => {
105
- Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. " + error.message);
106
- });
107
- this._encodePromises.push(promise);
108
- this._wasUsed = true;
109
- }
110
- /** @internal */
111
- async preGenerateBinaryAsync(bufferManager) {
112
- if (!this.enabled) {
113
- return;
114
- }
115
- await Promise.all(this._encodePromises);
116
- // Cull obsolete bufferViews that were replaced with Draco data
117
- this._bufferViewsUsed.forEach((bufferView) => {
118
- const references = bufferManager.getPropertiesWithBufferView(bufferView);
119
- const onlyUsedByEncodedPrimitives = references.every((object) => {
120
- return this._accessorsUsed.has(object); // has() can handle any object, but TS doesn't know that
121
- });
122
- if (onlyUsedByEncodedPrimitives) {
123
- bufferManager.removeBufferView(bufferView);
124
- }
125
- });
126
- this._bufferViewsUsed.clear();
127
- this._accessorsUsed.clear();
128
- }
129
- }
130
- GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_draco_mesh_compression(exporter));
5
+ export * from "./KHR_draco_mesh_compression.pure.js";
6
+ import { RegisterKHR_draco_mesh_compression } from "./KHR_draco_mesh_compression.pure.js";
7
+ RegisterKHR_draco_mesh_compression();
131
8
  //# sourceMappingURL=KHR_draco_mesh_compression.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_draco_mesh_compression.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_draco_mesh_compression.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C,SAAS,qBAAqB,CAAC,QAAgB;IAC3C,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,UAAU,CAAC;IACtB,CAAC;SAAM,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,QAAQ,CAAC;IACpB,CAAC;SAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC;IACnB,CAAC;SAAM,IAAI,QAAQ,CAAC,U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,IAAI,CAAC,OAAO,CAAC,CAAC;QAEnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,gBAAgB;IACT,KAAK,CAAC,sBAAsB,CAAC,aAA4B;QAC5D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,OAAO;QACX,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAExC,+DAA+D;QAC/D,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACzC,MAAM,UAAU,GAAG,aAAa,CAAC,2BAA2B,CAAC,UAAU,CAAC,CAAC;YACzE,MAAM,2BAA2B,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;gBAC5D,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAmB,CAAC,CAAC,CAAC,wDAAwD;YACjH,CAAC,CAAC,CAAC;YACH,IAAI,2BAA2B,EAAE,CAAC;gBAC9B,aAAa,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { GLTFExporter } from \"../glTFExporter\";\nimport { MeshPrimitiveMode, type IAccessor, type IBufferView, type IKHRDracoMeshCompression, type IMeshPrimitive } from \"babylonjs-gltf2interface\";\nimport { type BufferManager } from \"../bufferManager\";\nimport { DracoEncoder } from \"core/Meshes/Compression/dracoEncoder\";\nimport { GetTypedArrayData, GetTypeByteLength } from \"core/Buffers/bufferUtils\";\nimport { GetAccessorElementCount } from \"../glTFUtilities\";\nimport { type DracoAttributeName, type IDracoAttributeData, type IDracoEncoderOptions } from \"core/Meshes/Compression/dracoEncoder.types\";\nimport { Logger } from \"core/Misc/logger\";\nimport { type Nullable } from \"core/types\";\n\nconst NAME = \"KHR_draco_mesh_compression\";\n\nfunction GetDracoAttributeName(glTFName: string): DracoAttributeName {\n if (glTFName === \"POSITION\") {\n return \"POSITION\";\n } else if (glTFName === \"NORMAL\") {\n return \"NORMAL\";\n } else if (glTFName.startsWith(\"COLOR\")) {\n return \"COLOR\";\n } else if (glTFName.startsWith(\"TEXCOORD\")) {\n return \"TEX_COORD\";\n }\n return \"GENERIC\";\n}\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_draco_mesh_compression implements IGLTFExporterExtensionV2 {\n /** Name of this extension */\n public readonly name = NAME;\n\n /** Defines whether this extension is enabled */\n public enabled;\n\n /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */\n public required = true;\n\n /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */\n private _bufferViewsUsed: Set<IBufferView> = new Set();\n\n /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */\n private _accessorsUsed: Set<IAccessor> = new Set();\n\n /** Promise pool for Draco encoding work */\n private _encodePromises: Promise<void>[] = [];\n\n private _wasUsed = false;\n\n /** @internal */\n public get wasUsed() {\n return this._wasUsed;\n }\n\n /** @internal */\n constructor(exporter: GLTFExporter) {\n this.enabled = exporter.options.meshCompressionMethod === \"Draco\" && DracoEncoder.DefaultAvailable;\n }\n\n /** @internal */\n public dispose() {}\n\n /** @internal */\n public postExportMeshPrimitive(primitive: IMeshPrimitive, bufferManager: BufferManager, accessors: IAccessor[]): void {\n if (!this.enabled) {\n return;\n }\n\n if (primitive.mode !== MeshPrimitiveMode.TRIANGLES && primitive.mode !== MeshPrimitiveMode.TRIANGLE_STRIP) {\n Logger.Warn(\"Cannot compress primitive with mode \" + primitive.mode + \".\");\n return;\n }\n\n // Collect bufferViews and accessors used by this primitive\n const primitiveBufferViews: IBufferView[] = [];\n const primitiveAccessors: IAccessor[] = [];\n\n // Prepare indices for Draco encoding\n let indices: Nullable<Uint32Array | Uint16Array> = null;\n if (primitive.indices !== undefined) {\n const accessor = accessors[primitive.indices];\n const bufferView = bufferManager.getBufferView(accessor);\n // Per exportIndices, indices must be either Uint16Array or Uint32Array\n indices = bufferManager.getData(bufferView).slice() as Uint32Array | Uint16Array;\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Prepare attributes for Draco encoding\n const attributes: IDracoAttributeData[] = [];\n for (const [name, accessorIndex] of Object.entries(primitive.attributes)) {\n const accessor = accessors[accessorIndex];\n const bufferView = bufferManager.getBufferView(accessor);\n\n const size = GetAccessorElementCount(accessor.type);\n const data = GetTypedArrayData(\n bufferManager.getData(bufferView),\n size,\n accessor.componentType,\n accessor.byteOffset || 0,\n bufferView.byteStride || GetTypeByteLength(accessor.componentType) * size,\n accessor.count,\n true\n );\n\n attributes.push({ kind: name, dracoName: GetDracoAttributeName(name), size: GetAccessorElementCount(accessor.type), data: data });\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Use sequential encoding to preserve vertex order for cases like morph targets\n const options: IDracoEncoderOptions = {\n method: primitive.targets ? \"MESH_SEQUENTIAL_ENCODING\" : \"MESH_EDGEBREAKER_ENCODING\",\n };\n\n const promise = DracoEncoder.Default._encodeAsync(attributes, indices, options)\n // eslint-disable-next-line github/no-then\n .then((encodedData) => {\n const dracoInfo: IKHRDracoMeshCompression = {\n bufferView: -1, // bufferView will be set to a real index later, when we write the binary and decide bufferView ordering\n attributes: encodedData.attributeIds,\n };\n const bufferView = bufferManager.createBufferView(encodedData.data);\n bufferManager.setBufferView(dracoInfo, bufferView);\n\n for (const bufferView of primitiveBufferViews) {\n this._bufferViewsUsed.add(bufferView);\n }\n for (const accessor of primitiveAccessors) {\n this._accessorsUsed.add(accessor);\n }\n\n primitive.extensions ||= {};\n primitive.extensions[NAME] = dracoInfo;\n })\n // eslint-disable-next-line github/no-then\n .catch((error) => {\n Logger.Error(\"KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. \" + error.message);\n });\n\n this._encodePromises.push(promise);\n\n this._wasUsed = true;\n }\n\n /** @internal */\n public async preGenerateBinaryAsync(bufferManager: BufferManager): Promise<void> {\n if (!this.enabled) {\n return;\n }\n\n await Promise.all(this._encodePromises);\n\n // Cull obsolete bufferViews that were replaced with Draco data\n this._bufferViewsUsed.forEach((bufferView) => {\n const references = bufferManager.getPropertiesWithBufferView(bufferView);\n const onlyUsedByEncodedPrimitives = references.every((object) => {\n return this._accessorsUsed.has(object as IAccessor); // has() can handle any object, but TS doesn't know that\n });\n if (onlyUsedByEncodedPrimitives) {\n bufferManager.removeBufferView(bufferView);\n }\n });\n\n this._bufferViewsUsed.clear();\n this._accessorsUsed.clear();\n }\n}\n\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_draco_mesh_compression(exporter));\n"]}
1
+ {"version":3,"file":"KHR_draco_mesh_compression.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_draco_mesh_compression.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,mCAAmC,CAAC;AAElD,OAAO,EAAE,kCAAkC,EAAE,MAAM,mCAAmC,CAAC;AACvF,kCAAkC,EAAE,CAAC","sourcesContent":["/**\n * Re-exports the pure implementation and applies the runtime registration side effect.\n * Import \"./KHR_draco_mesh_compression.pure\" for tree-shakeable, side-effect-free usage.\n */\nexport * from \"./KHR_draco_mesh_compression.pure\";\n\nimport { RegisterKHR_draco_mesh_compression } from \"./KHR_draco_mesh_compression.pure\";\nRegisterKHR_draco_mesh_compression();\n"]}
@@ -0,0 +1,37 @@
1
+ import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
2
+ import { GLTFExporter } from "../glTFExporter.js";
3
+ import { type IAccessor, type IMeshPrimitive } from "babylonjs-gltf2interface";
4
+ import { type BufferManager } from "../bufferManager.js";
5
+ /**
6
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)
7
+ */
8
+ export declare class KHR_draco_mesh_compression implements IGLTFExporterExtensionV2 {
9
+ /** Name of this extension */
10
+ readonly name = "KHR_draco_mesh_compression";
11
+ /** Defines whether this extension is enabled */
12
+ enabled: boolean;
13
+ /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */
14
+ required: boolean;
15
+ /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */
16
+ private _bufferViewsUsed;
17
+ /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */
18
+ private _accessorsUsed;
19
+ /** Promise pool for Draco encoding work */
20
+ private _encodePromises;
21
+ private _wasUsed;
22
+ /** @internal */
23
+ get wasUsed(): boolean;
24
+ /** @internal */
25
+ constructor(exporter: GLTFExporter);
26
+ /** @internal */
27
+ dispose(): void;
28
+ /** @internal */
29
+ postExportMeshPrimitive(primitive: IMeshPrimitive, bufferManager: BufferManager, accessors: IAccessor[]): void;
30
+ /** @internal */
31
+ preGenerateBinaryAsync(bufferManager: BufferManager): Promise<void>;
32
+ }
33
+ /**
34
+ * Registers the KHR_draco_mesh_compression glTF serializer extension with the {@link GLTFExporter}.
35
+ * Safe to call multiple times; only the first call has an effect.
36
+ */
37
+ export declare function RegisterKHR_draco_mesh_compression(): void;
@@ -0,0 +1,143 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { DracoEncoder } from "@babylonjs/core/Meshes/Compression/dracoEncoder.js";
3
+ import { GetTypedArrayData, GetTypeByteLength } from "@babylonjs/core/Buffers/bufferUtils.js";
4
+ import { GetAccessorElementCount } from "../glTFUtilities.js";
5
+ import { Logger } from "@babylonjs/core/Misc/logger.js";
6
+ const NAME = "KHR_draco_mesh_compression";
7
+ function GetDracoAttributeName(glTFName) {
8
+ if (glTFName === "POSITION") {
9
+ return "POSITION";
10
+ }
11
+ else if (glTFName === "NORMAL") {
12
+ return "NORMAL";
13
+ }
14
+ else if (glTFName.startsWith("COLOR")) {
15
+ return "COLOR";
16
+ }
17
+ else if (glTFName.startsWith("TEXCOORD")) {
18
+ return "TEX_COORD";
19
+ }
20
+ return "GENERIC";
21
+ }
22
+ /**
23
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)
24
+ */
25
+ // eslint-disable-next-line @typescript-eslint/naming-convention
26
+ export class KHR_draco_mesh_compression {
27
+ /** @internal */
28
+ get wasUsed() {
29
+ return this._wasUsed;
30
+ }
31
+ /** @internal */
32
+ constructor(exporter) {
33
+ /** Name of this extension */
34
+ this.name = NAME;
35
+ /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */
36
+ this.required = true;
37
+ /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */
38
+ this._bufferViewsUsed = new Set();
39
+ /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */
40
+ this._accessorsUsed = new Set();
41
+ /** Promise pool for Draco encoding work */
42
+ this._encodePromises = [];
43
+ this._wasUsed = false;
44
+ this.enabled = exporter.options.meshCompressionMethod === "Draco" && DracoEncoder.DefaultAvailable;
45
+ }
46
+ /** @internal */
47
+ dispose() { }
48
+ /** @internal */
49
+ postExportMeshPrimitive(primitive, bufferManager, accessors) {
50
+ if (!this.enabled) {
51
+ return;
52
+ }
53
+ if (primitive.mode !== 4 /* MeshPrimitiveMode.TRIANGLES */ && primitive.mode !== 5 /* MeshPrimitiveMode.TRIANGLE_STRIP */) {
54
+ Logger.Warn("Cannot compress primitive with mode " + primitive.mode + ".");
55
+ return;
56
+ }
57
+ // Collect bufferViews and accessors used by this primitive
58
+ const primitiveBufferViews = [];
59
+ const primitiveAccessors = [];
60
+ // Prepare indices for Draco encoding
61
+ let indices = null;
62
+ if (primitive.indices !== undefined) {
63
+ const accessor = accessors[primitive.indices];
64
+ const bufferView = bufferManager.getBufferView(accessor);
65
+ // Per exportIndices, indices must be either Uint16Array or Uint32Array
66
+ indices = bufferManager.getData(bufferView).slice();
67
+ primitiveBufferViews.push(bufferView);
68
+ primitiveAccessors.push(accessor);
69
+ }
70
+ // Prepare attributes for Draco encoding
71
+ const attributes = [];
72
+ for (const [name, accessorIndex] of Object.entries(primitive.attributes)) {
73
+ const accessor = accessors[accessorIndex];
74
+ const bufferView = bufferManager.getBufferView(accessor);
75
+ const size = GetAccessorElementCount(accessor.type);
76
+ const data = GetTypedArrayData(bufferManager.getData(bufferView), size, accessor.componentType, accessor.byteOffset || 0, bufferView.byteStride || GetTypeByteLength(accessor.componentType) * size, accessor.count, true);
77
+ attributes.push({ kind: name, dracoName: GetDracoAttributeName(name), size: GetAccessorElementCount(accessor.type), data: data });
78
+ primitiveBufferViews.push(bufferView);
79
+ primitiveAccessors.push(accessor);
80
+ }
81
+ // Use sequential encoding to preserve vertex order for cases like morph targets
82
+ const options = {
83
+ method: primitive.targets ? "MESH_SEQUENTIAL_ENCODING" : "MESH_EDGEBREAKER_ENCODING",
84
+ };
85
+ const promise = DracoEncoder.Default._encodeAsync(attributes, indices, options)
86
+ // eslint-disable-next-line github/no-then
87
+ .then((encodedData) => {
88
+ const dracoInfo = {
89
+ bufferView: -1, // bufferView will be set to a real index later, when we write the binary and decide bufferView ordering
90
+ attributes: encodedData.attributeIds,
91
+ };
92
+ const bufferView = bufferManager.createBufferView(encodedData.data);
93
+ bufferManager.setBufferView(dracoInfo, bufferView);
94
+ for (const bufferView of primitiveBufferViews) {
95
+ this._bufferViewsUsed.add(bufferView);
96
+ }
97
+ for (const accessor of primitiveAccessors) {
98
+ this._accessorsUsed.add(accessor);
99
+ }
100
+ primitive.extensions || (primitive.extensions = {});
101
+ primitive.extensions[NAME] = dracoInfo;
102
+ })
103
+ // eslint-disable-next-line github/no-then
104
+ .catch((error) => {
105
+ Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. " + error.message);
106
+ });
107
+ this._encodePromises.push(promise);
108
+ this._wasUsed = true;
109
+ }
110
+ /** @internal */
111
+ async preGenerateBinaryAsync(bufferManager) {
112
+ if (!this.enabled) {
113
+ return;
114
+ }
115
+ await Promise.all(this._encodePromises);
116
+ // Cull obsolete bufferViews that were replaced with Draco data
117
+ this._bufferViewsUsed.forEach((bufferView) => {
118
+ const references = bufferManager.getPropertiesWithBufferView(bufferView);
119
+ const onlyUsedByEncodedPrimitives = references.every((object) => {
120
+ return this._accessorsUsed.has(object); // has() can handle any object, but TS doesn't know that
121
+ });
122
+ if (onlyUsedByEncodedPrimitives) {
123
+ bufferManager.removeBufferView(bufferView);
124
+ }
125
+ });
126
+ this._bufferViewsUsed.clear();
127
+ this._accessorsUsed.clear();
128
+ }
129
+ }
130
+ let _Registered = false;
131
+ /**
132
+ * Registers the KHR_draco_mesh_compression glTF serializer extension with the {@link GLTFExporter}.
133
+ * Safe to call multiple times; only the first call has an effect.
134
+ */
135
+ // eslint-disable-next-line @typescript-eslint/naming-convention
136
+ export function RegisterKHR_draco_mesh_compression() {
137
+ if (_Registered) {
138
+ return;
139
+ }
140
+ _Registered = true;
141
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_draco_mesh_compression(exporter));
142
+ }
143
+ //# sourceMappingURL=KHR_draco_mesh_compression.pure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_draco_mesh_compression.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE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C,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,kCAAkC;IAC9C,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { GLTFExporter } from \"../glTFExporter\";\nimport { MeshPrimitiveMode, type IAccessor, type IBufferView, type IKHRDracoMeshCompression, type IMeshPrimitive } from \"babylonjs-gltf2interface\";\nimport { type BufferManager } from \"../bufferManager\";\nimport { DracoEncoder } from \"core/Meshes/Compression/dracoEncoder\";\nimport { GetTypedArrayData, GetTypeByteLength } from \"core/Buffers/bufferUtils\";\nimport { GetAccessorElementCount } from \"../glTFUtilities\";\nimport { type DracoAttributeName, type IDracoAttributeData, type IDracoEncoderOptions } from \"core/Meshes/Compression/dracoEncoder.types\";\nimport { Logger } from \"core/Misc/logger\";\nimport { type Nullable } from \"core/types\";\n\nconst NAME = \"KHR_draco_mesh_compression\";\n\nfunction GetDracoAttributeName(glTFName: string): DracoAttributeName {\n if (glTFName === \"POSITION\") {\n return \"POSITION\";\n } else if (glTFName === \"NORMAL\") {\n return \"NORMAL\";\n } else if (glTFName.startsWith(\"COLOR\")) {\n return \"COLOR\";\n } else if (glTFName.startsWith(\"TEXCOORD\")) {\n return \"TEX_COORD\";\n }\n return \"GENERIC\";\n}\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_draco_mesh_compression implements IGLTFExporterExtensionV2 {\n /** Name of this extension */\n public readonly name = NAME;\n\n /** Defines whether this extension is enabled */\n public enabled;\n\n /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */\n public required = true;\n\n /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */\n private _bufferViewsUsed: Set<IBufferView> = new Set();\n\n /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */\n private _accessorsUsed: Set<IAccessor> = new Set();\n\n /** Promise pool for Draco encoding work */\n private _encodePromises: Promise<void>[] = [];\n\n private _wasUsed = false;\n\n /** @internal */\n public get wasUsed() {\n return this._wasUsed;\n }\n\n /** @internal */\n constructor(exporter: GLTFExporter) {\n this.enabled = exporter.options.meshCompressionMethod === \"Draco\" && DracoEncoder.DefaultAvailable;\n }\n\n /** @internal */\n public dispose() {}\n\n /** @internal */\n public postExportMeshPrimitive(primitive: IMeshPrimitive, bufferManager: BufferManager, accessors: IAccessor[]): void {\n if (!this.enabled) {\n return;\n }\n\n if (primitive.mode !== MeshPrimitiveMode.TRIANGLES && primitive.mode !== MeshPrimitiveMode.TRIANGLE_STRIP) {\n Logger.Warn(\"Cannot compress primitive with mode \" + primitive.mode + \".\");\n return;\n }\n\n // Collect bufferViews and accessors used by this primitive\n const primitiveBufferViews: IBufferView[] = [];\n const primitiveAccessors: IAccessor[] = [];\n\n // Prepare indices for Draco encoding\n let indices: Nullable<Uint32Array | Uint16Array> = null;\n if (primitive.indices !== undefined) {\n const accessor = accessors[primitive.indices];\n const bufferView = bufferManager.getBufferView(accessor);\n // Per exportIndices, indices must be either Uint16Array or Uint32Array\n indices = bufferManager.getData(bufferView).slice() as Uint32Array | Uint16Array;\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Prepare attributes for Draco encoding\n const attributes: IDracoAttributeData[] = [];\n for (const [name, accessorIndex] of Object.entries(primitive.attributes)) {\n const accessor = accessors[accessorIndex];\n const bufferView = bufferManager.getBufferView(accessor);\n\n const size = GetAccessorElementCount(accessor.type);\n const data = GetTypedArrayData(\n bufferManager.getData(bufferView),\n size,\n accessor.componentType,\n accessor.byteOffset || 0,\n bufferView.byteStride || GetTypeByteLength(accessor.componentType) * size,\n accessor.count,\n true\n );\n\n attributes.push({ kind: name, dracoName: GetDracoAttributeName(name), size: GetAccessorElementCount(accessor.type), data: data });\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Use sequential encoding to preserve vertex order for cases like morph targets\n const options: IDracoEncoderOptions = {\n method: primitive.targets ? \"MESH_SEQUENTIAL_ENCODING\" : \"MESH_EDGEBREAKER_ENCODING\",\n };\n\n const promise = DracoEncoder.Default._encodeAsync(attributes, indices, options)\n // eslint-disable-next-line github/no-then\n .then((encodedData) => {\n const dracoInfo: IKHRDracoMeshCompression = {\n bufferView: -1, // bufferView will be set to a real index later, when we write the binary and decide bufferView ordering\n attributes: encodedData.attributeIds,\n };\n const bufferView = bufferManager.createBufferView(encodedData.data);\n bufferManager.setBufferView(dracoInfo, bufferView);\n\n for (const bufferView of primitiveBufferViews) {\n this._bufferViewsUsed.add(bufferView);\n }\n for (const accessor of primitiveAccessors) {\n this._accessorsUsed.add(accessor);\n }\n\n primitive.extensions ||= {};\n primitive.extensions[NAME] = dracoInfo;\n })\n // eslint-disable-next-line github/no-then\n .catch((error) => {\n Logger.Error(\"KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. \" + error.message);\n });\n\n this._encodePromises.push(promise);\n\n this._wasUsed = true;\n }\n\n /** @internal */\n public async preGenerateBinaryAsync(bufferManager: BufferManager): Promise<void> {\n if (!this.enabled) {\n return;\n }\n\n await Promise.all(this._encodePromises);\n\n // Cull obsolete bufferViews that were replaced with Draco data\n this._bufferViewsUsed.forEach((bufferView) => {\n const references = bufferManager.getPropertiesWithBufferView(bufferView);\n const onlyUsedByEncodedPrimitives = references.every((object) => {\n return this._accessorsUsed.has(object as IAccessor); // has() can handle any object, but TS doesn't know that\n });\n if (onlyUsedByEncodedPrimitives) {\n bufferManager.removeBufferView(bufferView);\n }\n });\n\n this._bufferViewsUsed.clear();\n this._accessorsUsed.clear();\n }\n}\n\nlet _Registered = false;\n/**\n * Registers the KHR_draco_mesh_compression glTF serializer extension with the {@link GLTFExporter}.\n * Safe to call multiple times; only the first call has an effect.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function RegisterKHR_draco_mesh_compression(): void {\n if (_Registered) {\n return;\n }\n _Registered = true;\n\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_draco_mesh_compression(exporter));\n}\n"]}
@@ -1,39 +1,5 @@
1
- import { type Nullable } from "@babylonjs/core/types.js";
2
- import { type Node } from "@babylonjs/core/node.js";
3
- import { type INode } from "babylonjs-gltf2interface";
4
- import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
5
- import { GLTFExporter } from "../glTFExporter.js";
6
1
  /**
7
- * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./KHR_lights_punctual.pure" for tree-shakeable, side-effect-free usage.
8
4
  */
9
- export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
10
- /** The name of this extension. */
11
- readonly name = "KHR_lights_punctual";
12
- /** Defines whether this extension is enabled. */
13
- enabled: boolean;
14
- /** Defines whether this extension is required */
15
- required: boolean;
16
- /** Reference to the glTF exporter */
17
- private _exporter;
18
- private _lights;
19
- /**
20
- * @internal
21
- */
22
- constructor(exporter: GLTFExporter);
23
- /** @internal */
24
- dispose(): void;
25
- /** @internal */
26
- get wasUsed(): boolean;
27
- /** @internal */
28
- onExporting(): void;
29
- /**
30
- * Define this method to modify the default behavior when exporting a node
31
- * @param context The context when exporting the node
32
- * @param node glTF node
33
- * @param babylonNode BabylonJS node
34
- * @param nodeMap Node mapping of babylon node to glTF node index
35
- * @param convertToRightHanded Flag to convert the values to right-handed
36
- * @returns nullable INode promise
37
- */
38
- postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>>;
39
- }
5
+ export * from "./KHR_lights_punctual.pure.js";