@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 +1 @@
1
- {"version":3,"file":"KHR_materials_dispersion.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC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,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YAC3C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,wBAAwB,EAAE,CAAC,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsDispersion } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\n\r\nconst NAME = \"KHR_materials_dispersion\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/87bd64a7f5e23c84b6aef2e6082069583ed0ddb4/extensions/2.0/Khronos/KHR_materials_dispersion/README.md)\r\n * @experimental\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_dispersion implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n /** Constructor */\r\n constructor() {}\r\n\r\n /** Dispose */\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n // this extension requires refraction to be enabled.\r\n if (!subs.isRefractionEnabled && !subs.isDispersionEnabled) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise, resolves with the material\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const dispersion = subs.dispersion;\r\n\r\n const dispersionInfo: IKHRMaterialsDispersion = {\r\n dispersion: dispersion,\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = dispersionInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, () => new KHR_materials_dispersion());\r\n"]}
1
+ {"version":3,"file":"KHR_materials_dispersion.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,iCAAiC,CAAC;AAEhD,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,gCAAgC,EAAE,CAAC","sourcesContent":["/**\r\n * Re-exports the pure implementation and applies the runtime registration side effect.\r\n * Import \"./KHR_materials_dispersion.pure\" for tree-shakeable, side-effect-free usage.\r\n */\r\nexport * from \"./KHR_materials_dispersion.pure\";\r\n\r\nimport { RegisterKHR_materials_dispersion } from \"./KHR_materials_dispersion.pure\";\r\nRegisterKHR_materials_dispersion();\r\n"]}
@@ -0,0 +1,36 @@
1
+ import { type IMaterial } from "babylonjs-gltf2interface";
2
+ import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
3
+ import { type Material } from "@babylonjs/core/Materials/material.js";
4
+ /**
5
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/87bd64a7f5e23c84b6aef2e6082069583ed0ddb4/extensions/2.0/Khronos/KHR_materials_dispersion/README.md)
6
+ * @experimental
7
+ */
8
+ export declare class KHR_materials_dispersion implements IGLTFExporterExtensionV2 {
9
+ /** Name of this extension */
10
+ readonly name = "KHR_materials_dispersion";
11
+ /** Defines whether this extension is enabled */
12
+ enabled: boolean;
13
+ /** Defines whether this extension is required */
14
+ required: boolean;
15
+ private _wasUsed;
16
+ /** Constructor */
17
+ constructor();
18
+ /** Dispose */
19
+ dispose(): void;
20
+ /** @internal */
21
+ get wasUsed(): boolean;
22
+ private _isExtensionEnabled;
23
+ /**
24
+ * After exporting a material
25
+ * @param context GLTF context of the material
26
+ * @param node exported GLTF node
27
+ * @param babylonMaterial corresponding babylon material
28
+ * @returns promise, resolves with the material
29
+ */
30
+ postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
31
+ }
32
+ /**
33
+ * Registers the KHR_materials_dispersion glTF serializer extension with the {@link GLTFExporter}.
34
+ * Safe to call multiple times; only the first call has an effect.
35
+ */
36
+ export declare function RegisterKHR_materials_dispersion(): void;
@@ -0,0 +1,75 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.pure.js";
3
+ const NAME = "KHR_materials_dispersion";
4
+ /**
5
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/87bd64a7f5e23c84b6aef2e6082069583ed0ddb4/extensions/2.0/Khronos/KHR_materials_dispersion/README.md)
6
+ * @experimental
7
+ */
8
+ // eslint-disable-next-line @typescript-eslint/naming-convention
9
+ export class KHR_materials_dispersion {
10
+ /** Constructor */
11
+ constructor() {
12
+ /** Name of this extension */
13
+ this.name = NAME;
14
+ /** Defines whether this extension is enabled */
15
+ this.enabled = true;
16
+ /** Defines whether this extension is required */
17
+ this.required = false;
18
+ this._wasUsed = false;
19
+ }
20
+ /** Dispose */
21
+ dispose() { }
22
+ /** @internal */
23
+ get wasUsed() {
24
+ return this._wasUsed;
25
+ }
26
+ _isExtensionEnabled(mat) {
27
+ // This extension must not be used on a material that also uses KHR_materials_unlit
28
+ if (mat.unlit) {
29
+ return false;
30
+ }
31
+ const subs = mat.subSurface;
32
+ // this extension requires refraction to be enabled.
33
+ if (!subs.isRefractionEnabled && !subs.isDispersionEnabled) {
34
+ return false;
35
+ }
36
+ return true;
37
+ }
38
+ /**
39
+ * After exporting a material
40
+ * @param context GLTF context of the material
41
+ * @param node exported GLTF node
42
+ * @param babylonMaterial corresponding babylon material
43
+ * @returns promise, resolves with the material
44
+ */
45
+ // eslint-disable-next-line no-restricted-syntax
46
+ postExportMaterialAsync(context, node, babylonMaterial) {
47
+ return new Promise((resolve) => {
48
+ if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
49
+ this._wasUsed = true;
50
+ const subs = babylonMaterial.subSurface;
51
+ const dispersion = subs.dispersion;
52
+ const dispersionInfo = {
53
+ dispersion: dispersion,
54
+ };
55
+ node.extensions = node.extensions || {};
56
+ node.extensions[NAME] = dispersionInfo;
57
+ }
58
+ resolve(node);
59
+ });
60
+ }
61
+ }
62
+ let _Registered = false;
63
+ /**
64
+ * Registers the KHR_materials_dispersion glTF serializer extension with the {@link GLTFExporter}.
65
+ * Safe to call multiple times; only the first call has an effect.
66
+ */
67
+ // eslint-disable-next-line @typescript-eslint/naming-convention
68
+ export function RegisterKHR_materials_dispersion() {
69
+ if (_Registered) {
70
+ return;
71
+ }
72
+ _Registered = true;
73
+ GLTFExporter.RegisterExtension(NAME, () => new KHR_materials_dispersion());
74
+ }
75
+ //# sourceMappingURL=KHR_materials_dispersion.pure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_materials_dispersion.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_dispersion.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC;;;GAGG;AACH,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AAC,GAAG,cAAc,CAAC;YAC3C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,gCAAgC;IAC5C,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,wBAAwB,EAAE,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsDispersion } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial.pure\";\r\n\r\nconst NAME = \"KHR_materials_dispersion\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/87bd64a7f5e23c84b6aef2e6082069583ed0ddb4/extensions/2.0/Khronos/KHR_materials_dispersion/README.md)\r\n * @experimental\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_dispersion implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n /** Constructor */\r\n constructor() {}\r\n\r\n /** Dispose */\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n // this extension requires refraction to be enabled.\r\n if (!subs.isRefractionEnabled && !subs.isDispersionEnabled) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise, resolves with the material\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const dispersion = subs.dispersion;\r\n\r\n const dispersionInfo: IKHRMaterialsDispersion = {\r\n dispersion: dispersion,\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = dispersionInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_dispersion glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_dispersion(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, () => new KHR_materials_dispersion());\r\n}\r\n"]}
@@ -1,27 +1,5 @@
1
- import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
2
- import { type Material } from "@babylonjs/core/Materials/material.js";
3
- import { type IMaterial } from "babylonjs-gltf2interface";
4
1
  /**
5
- * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./KHR_materials_emissive_strength.pure" for tree-shakeable, side-effect-free usage.
6
4
  */
7
- export declare class KHR_materials_emissive_strength implements IGLTFExporterExtensionV2 {
8
- /** Name of this extension */
9
- readonly name = "KHR_materials_emissive_strength";
10
- /** Defines whether this extension is enabled */
11
- enabled: boolean;
12
- /** Defines whether this extension is required */
13
- required: boolean;
14
- private _wasUsed;
15
- /** Dispose */
16
- dispose(): void;
17
- /** @internal */
18
- get wasUsed(): boolean;
19
- /**
20
- * After exporting a material
21
- * @param context GLTF context of the material
22
- * @param node exported GLTF node
23
- * @param babylonMaterial corresponding babylon material
24
- * @returns promise, resolves with the material
25
- */
26
- postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
27
- }
5
+ export * from "./KHR_materials_emissive_strength.pure.js";
@@ -1,57 +1,8 @@
1
- import { GLTFExporter } from "../glTFExporter.js";
2
- import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
3
- const NAME = "KHR_materials_emissive_strength";
4
1
  /**
5
- * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./KHR_materials_emissive_strength.pure" for tree-shakeable, side-effect-free usage.
6
4
  */
7
- // eslint-disable-next-line @typescript-eslint/naming-convention
8
- export class KHR_materials_emissive_strength {
9
- constructor() {
10
- /** Name of this extension */
11
- this.name = NAME;
12
- /** Defines whether this extension is enabled */
13
- this.enabled = true;
14
- /** Defines whether this extension is required */
15
- this.required = false;
16
- this._wasUsed = false;
17
- }
18
- /** Dispose */
19
- dispose() { }
20
- /** @internal */
21
- get wasUsed() {
22
- return this._wasUsed;
23
- }
24
- /**
25
- * After exporting a material
26
- * @param context GLTF context of the material
27
- * @param node exported GLTF node
28
- * @param babylonMaterial corresponding babylon material
29
- * @returns promise, resolves with the material
30
- */
31
- async postExportMaterialAsync(context, node, babylonMaterial) {
32
- return await new Promise((resolve) => {
33
- if (!(babylonMaterial instanceof PBRMaterial)) {
34
- return resolve(node);
35
- }
36
- const emissiveColor = babylonMaterial.emissiveColor.scale(babylonMaterial.emissiveIntensity);
37
- const tempEmissiveStrength = Math.max(...emissiveColor.asArray());
38
- if (tempEmissiveStrength > 1) {
39
- // If the strength is greater than 1, normalize the color and store the strength
40
- node.emissiveFactor = emissiveColor.scale(1 / tempEmissiveStrength).asArray();
41
- this._wasUsed = true;
42
- const emissiveStrengthInfo = {
43
- emissiveStrength: tempEmissiveStrength,
44
- };
45
- node.extensions || (node.extensions = {});
46
- node.extensions[NAME] = emissiveStrengthInfo;
47
- }
48
- else {
49
- // Otherwise, just store the adjusted emissive color in emissiveFactor
50
- node.emissiveFactor = emissiveColor.asArray();
51
- }
52
- return resolve(node);
53
- });
54
- }
55
- }
56
- GLTFExporter.RegisterExtension(NAME, () => new KHR_materials_emissive_strength());
5
+ export * from "./KHR_materials_emissive_strength.pure.js";
6
+ import { RegisterKHR_materials_emissive_strength } from "./KHR_materials_emissive_strength.pure.js";
7
+ RegisterKHR_materials_emissive_strength();
57
8
  //# sourceMappingURL=KHR_materials_emissive_strength.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_emissive_strength.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_emissive_strength.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAG7D,MAAM,IAAI,GAAG,iCAAiC,CAAC;AAE/C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,+BAA+B;IAA5C;QACI,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAEhB,aAAQ,GAAG,KAAK,CAAC;IA4C7B,CAAC;IA1CG,cAAc;IACP,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAA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Extension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport { type IMaterial, type IKHRMaterialsEmissiveStrength } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_emissive_strength\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_emissive_strength implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n /** Dispose */\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise, resolves with the material\r\n */\r\n public async postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return await new Promise((resolve) => {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n return resolve(node);\r\n }\r\n\r\n const emissiveColor = babylonMaterial.emissiveColor.scale(babylonMaterial.emissiveIntensity);\r\n const tempEmissiveStrength = Math.max(...emissiveColor.asArray());\r\n\r\n if (tempEmissiveStrength > 1) {\r\n // If the strength is greater than 1, normalize the color and store the strength\r\n node.emissiveFactor = emissiveColor.scale(1 / tempEmissiveStrength).asArray();\r\n\r\n this._wasUsed = true;\r\n const emissiveStrengthInfo: IKHRMaterialsEmissiveStrength = {\r\n emissiveStrength: tempEmissiveStrength,\r\n };\r\n node.extensions ||= {};\r\n node.extensions[NAME] = emissiveStrengthInfo;\r\n } else {\r\n // Otherwise, just store the adjusted emissive color in emissiveFactor\r\n node.emissiveFactor = emissiveColor.asArray();\r\n }\r\n\r\n return resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, () => new KHR_materials_emissive_strength());\r\n"]}
1
+ {"version":3,"file":"KHR_materials_emissive_strength.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_emissive_strength.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,wCAAwC,CAAC;AAEvD,OAAO,EAAE,uCAAuC,EAAE,MAAM,wCAAwC,CAAC;AACjG,uCAAuC,EAAE,CAAC","sourcesContent":["/**\r\n * Re-exports the pure implementation and applies the runtime registration side effect.\r\n * Import \"./KHR_materials_emissive_strength.pure\" for tree-shakeable, side-effect-free usage.\r\n */\r\nexport * from \"./KHR_materials_emissive_strength.pure\";\r\n\r\nimport { RegisterKHR_materials_emissive_strength } from \"./KHR_materials_emissive_strength.pure\";\r\nRegisterKHR_materials_emissive_strength();\r\n"]}
@@ -0,0 +1,32 @@
1
+ import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
2
+ import { type Material } from "@babylonjs/core/Materials/material.js";
3
+ import { type IMaterial } from "babylonjs-gltf2interface";
4
+ /**
5
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)
6
+ */
7
+ export declare class KHR_materials_emissive_strength implements IGLTFExporterExtensionV2 {
8
+ /** Name of this extension */
9
+ readonly name = "KHR_materials_emissive_strength";
10
+ /** Defines whether this extension is enabled */
11
+ enabled: boolean;
12
+ /** Defines whether this extension is required */
13
+ required: boolean;
14
+ private _wasUsed;
15
+ /** Dispose */
16
+ dispose(): void;
17
+ /** @internal */
18
+ get wasUsed(): boolean;
19
+ /**
20
+ * After exporting a material
21
+ * @param context GLTF context of the material
22
+ * @param node exported GLTF node
23
+ * @param babylonMaterial corresponding babylon material
24
+ * @returns promise, resolves with the material
25
+ */
26
+ postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
27
+ }
28
+ /**
29
+ * Registers the KHR_materials_emissive_strength glTF serializer extension with the {@link GLTFExporter}.
30
+ * Safe to call multiple times; only the first call has an effect.
31
+ */
32
+ export declare function RegisterKHR_materials_emissive_strength(): void;
@@ -0,0 +1,69 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.pure.js";
3
+ const NAME = "KHR_materials_emissive_strength";
4
+ /**
5
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ export class KHR_materials_emissive_strength {
9
+ constructor() {
10
+ /** Name of this extension */
11
+ this.name = NAME;
12
+ /** Defines whether this extension is enabled */
13
+ this.enabled = true;
14
+ /** Defines whether this extension is required */
15
+ this.required = false;
16
+ this._wasUsed = false;
17
+ }
18
+ /** Dispose */
19
+ dispose() { }
20
+ /** @internal */
21
+ get wasUsed() {
22
+ return this._wasUsed;
23
+ }
24
+ /**
25
+ * After exporting a material
26
+ * @param context GLTF context of the material
27
+ * @param node exported GLTF node
28
+ * @param babylonMaterial corresponding babylon material
29
+ * @returns promise, resolves with the material
30
+ */
31
+ async postExportMaterialAsync(context, node, babylonMaterial) {
32
+ return await new Promise((resolve) => {
33
+ if (!(babylonMaterial instanceof PBRMaterial)) {
34
+ return resolve(node);
35
+ }
36
+ const emissiveColor = babylonMaterial.emissiveColor.scale(babylonMaterial.emissiveIntensity);
37
+ const tempEmissiveStrength = Math.max(...emissiveColor.asArray());
38
+ if (tempEmissiveStrength > 1) {
39
+ // If the strength is greater than 1, normalize the color and store the strength
40
+ node.emissiveFactor = emissiveColor.scale(1 / tempEmissiveStrength).asArray();
41
+ this._wasUsed = true;
42
+ const emissiveStrengthInfo = {
43
+ emissiveStrength: tempEmissiveStrength,
44
+ };
45
+ node.extensions || (node.extensions = {});
46
+ node.extensions[NAME] = emissiveStrengthInfo;
47
+ }
48
+ else {
49
+ // Otherwise, just store the adjusted emissive color in emissiveFactor
50
+ node.emissiveFactor = emissiveColor.asArray();
51
+ }
52
+ return resolve(node);
53
+ });
54
+ }
55
+ }
56
+ let _Registered = false;
57
+ /**
58
+ * Registers the KHR_materials_emissive_strength glTF serializer extension with the {@link GLTFExporter}.
59
+ * Safe to call multiple times; only the first call has an effect.
60
+ */
61
+ // eslint-disable-next-line @typescript-eslint/naming-convention
62
+ export function RegisterKHR_materials_emissive_strength() {
63
+ if (_Registered) {
64
+ return;
65
+ }
66
+ _Registered = true;
67
+ GLTFExporter.RegisterExtension(NAME, () => new KHR_materials_emissive_strength());
68
+ }
69
+ //# sourceMappingURL=KHR_materials_emissive_strength.pure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_materials_emissive_strength.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAGlE,MAAM,IAAI,GAAG,iCAAiC,CAAC;AAE/C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,+BAA+B;IAA5C;QACI,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAEhB,aAAQ,GAAG,KAAK,CAAC;IA4C7B,CAAC;IA1CG,cAAc;IACP,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,uBAAuB,CAAC,OA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AAC,IAAI,+BAA+B,EAAE,CAAC,CAAC;AACtF,CAAC","sourcesContent":["import { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial.pure\";\r\nimport { type IMaterial, type IKHRMaterialsEmissiveStrength } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_emissive_strength\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_emissive_strength implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n /** Dispose */\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise, resolves with the material\r\n */\r\n public async postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return await new Promise((resolve) => {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n return resolve(node);\r\n }\r\n\r\n const emissiveColor = babylonMaterial.emissiveColor.scale(babylonMaterial.emissiveIntensity);\r\n const tempEmissiveStrength = Math.max(...emissiveColor.asArray());\r\n\r\n if (tempEmissiveStrength > 1) {\r\n // If the strength is greater than 1, normalize the color and store the strength\r\n node.emissiveFactor = emissiveColor.scale(1 / tempEmissiveStrength).asArray();\r\n\r\n this._wasUsed = true;\r\n const emissiveStrengthInfo: IKHRMaterialsEmissiveStrength = {\r\n emissiveStrength: tempEmissiveStrength,\r\n };\r\n node.extensions ||= {};\r\n node.extensions[NAME] = emissiveStrengthInfo;\r\n } else {\r\n // Otherwise, just store the adjusted emissive color in emissiveFactor\r\n node.emissiveFactor = emissiveColor.asArray();\r\n }\r\n\r\n return resolve(node);\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_emissive_strength glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_emissive_strength(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, () => new KHR_materials_emissive_strength());\r\n}\r\n"]}
@@ -1,32 +1,5 @@
1
- import { type IMaterial } from "babylonjs-gltf2interface";
2
- import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
3
- import { GLTFExporter } from "../glTFExporter.js";
4
- import { type Material } from "@babylonjs/core/Materials/material.js";
5
- import { type BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
6
1
  /**
7
- * @internal
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./KHR_materials_fuzz.pure" for tree-shakeable, side-effect-free usage.
8
4
  */
9
- export declare class KHR_materials_fuzz implements IGLTFExporterExtensionV2 {
10
- /** Name of this extension */
11
- readonly name = "KHR_materials_fuzz";
12
- /** Defines whether this extension is enabled */
13
- enabled: boolean;
14
- /** Defines whether this extension is required */
15
- required: boolean;
16
- private _wasUsed;
17
- private _exporter;
18
- constructor(exporter: GLTFExporter);
19
- /**
20
- * Cache that holds temporary merged textures created during export
21
- */
22
- private _mergedTexturesMap;
23
- /**
24
- * Cache that holds internal textures of merged textures created during export
25
- */
26
- private _cachedInternalTexturesMap;
27
- dispose(): void;
28
- /** @internal */
29
- get wasUsed(): boolean;
30
- postExportMaterialAdditionalTexturesAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
31
- postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
32
- }
5
+ export * from "./KHR_materials_fuzz.pure.js";
@@ -1,194 +1,8 @@
1
- import { GLTFExporter } from "../glTFExporter.js";
2
- import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openpbrMaterial.js";
3
- import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@babylonjs/core/Materials/Textures/textureMerger.js";
4
- import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
5
- const NAME = "KHR_materials_fuzz";
6
1
  /**
7
- * Generate a unique ID for the merged coat textures based on the internal texture data.
8
- * This is used for caching merged textures.
9
- * @param babylonMaterial Source OpenPBR material
10
- * @returns A unique ID string for the merged coat textures
11
- * @internal
2
+ * Re-exports the pure implementation and applies the runtime registration side effect.
3
+ * Import "./KHR_materials_fuzz.pure" for tree-shakeable, side-effect-free usage.
12
4
  */
13
- function GetFuzzColorTextureId(babylonMaterial) {
14
- const fuzzColorTexture = babylonMaterial.fuzzColorTexture;
15
- const fuzzColorId = fuzzColorTexture && fuzzColorTexture.getInternalTexture() ? fuzzColorTexture.getInternalTexture().uniqueId : "NoFuzzColor";
16
- const fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;
17
- const fuzzRoughnessId = fuzzRoughnessTexture && fuzzRoughnessTexture.getInternalTexture() ? fuzzRoughnessTexture.getInternalTexture().uniqueId : "NoFuzzRoughness";
18
- return `FuzzColor_${fuzzColorId}_FuzzRoughness_${fuzzRoughnessId}`;
19
- }
20
- /**
21
- * Using the coat weight and coat roughness textures, create a merged internal texture that can be used
22
- * for multiple textures (with potentially different transforms) on export.
23
- * @param babylonMaterial The source OpenPBR material
24
- * @returns A new, internal texture with the coat weight in the red channel and coat roughness in the green channel
25
- * @internal
26
- */
27
- async function CreateMergedFuzzInternalTexture(babylonMaterial) {
28
- const scene = babylonMaterial.getScene();
29
- const fuzzColorTexture = babylonMaterial.fuzzColorTexture;
30
- const fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;
31
- // If we don't have any textures, we don't need to generate anything.
32
- if (!(fuzzColorTexture || fuzzRoughnessTexture)) {
33
- return null;
34
- }
35
- const texture = await MergeTexturesAsync("FuzzTexture", CreateRGBAConfiguration(fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 0) : CreateConstantInput(1.0), // fuzz color from red channel
36
- fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 1) : CreateConstantInput(1.0), // fuzz color from green channel
37
- fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 2) : CreateConstantInput(1.0), // fuzz color from blue channel
38
- // fuzz roughness goes in the alpha channel but may come from red or alpha channels in the source
39
- fuzzRoughnessTexture ? CreateTextureInput(fuzzRoughnessTexture, babylonMaterial._useFuzzRoughnessFromTextureAlpha ? 3 : 0) : CreateConstantInput(1.0)), scene);
40
- return texture.getInternalTexture();
41
- }
42
- /**
43
- * Creates a temporary texture based on the source texture.
44
- * @param internalTexture The source internal texture
45
- * @param sourceTexture The source of the new texture's name, and sampler info
46
- * @returns The new texture
47
- */
48
- function CreateTempTexture(internalTexture, sourceTexture) {
49
- const tempTexture = new Texture(sourceTexture.name, sourceTexture.getScene());
50
- tempTexture._texture = internalTexture;
51
- tempTexture.coordinatesIndex = sourceTexture.coordinatesIndex;
52
- if (sourceTexture instanceof Texture) {
53
- tempTexture.uOffset = sourceTexture.uOffset;
54
- tempTexture.vOffset = sourceTexture.vOffset;
55
- tempTexture.uScale = sourceTexture.uScale;
56
- tempTexture.vScale = sourceTexture.vScale;
57
- tempTexture.wAng = sourceTexture.wAng;
58
- }
59
- tempTexture.wrapU = sourceTexture.wrapU;
60
- tempTexture.wrapV = sourceTexture.wrapV;
61
- return tempTexture;
62
- }
63
- /**
64
- * @internal
65
- */
66
- // eslint-disable-next-line @typescript-eslint/naming-convention
67
- export class KHR_materials_fuzz {
68
- constructor(exporter) {
69
- /** Name of this extension */
70
- this.name = NAME;
71
- /** Defines whether this extension is enabled */
72
- this.enabled = true;
73
- /** Defines whether this extension is required */
74
- this.required = false;
75
- this._wasUsed = false;
76
- /**
77
- * Cache that holds temporary merged textures created during export
78
- */
79
- this._mergedTexturesMap = {};
80
- /**
81
- * Cache that holds internal textures of merged textures created during export
82
- */
83
- this._cachedInternalTexturesMap = {};
84
- this._exporter = exporter;
85
- }
86
- dispose() {
87
- for (const key of Object.keys(this._mergedTexturesMap)) {
88
- const texture = this._mergedTexturesMap[key];
89
- texture.dispose();
90
- }
91
- this._mergedTexturesMap = {};
92
- for (const key of Object.keys(this._cachedInternalTexturesMap)) {
93
- const internalTexture = this._cachedInternalTexturesMap[key];
94
- internalTexture.dispose();
95
- }
96
- this._cachedInternalTexturesMap = {};
97
- }
98
- /** @internal */
99
- get wasUsed() {
100
- return this._wasUsed;
101
- }
102
- async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
103
- if (babylonMaterial instanceof OpenPBRMaterial) {
104
- const additionalTextures = [];
105
- if (babylonMaterial.fuzzWeight > 0.0) {
106
- if (babylonMaterial.fuzzWeightTexture) {
107
- additionalTextures.push(babylonMaterial.fuzzWeightTexture);
108
- }
109
- let fuzzTexturesNeedMerge = false;
110
- if (babylonMaterial.fuzzRoughnessTexture) {
111
- if (babylonMaterial._useFuzzRoughnessFromTextureAlpha) {
112
- additionalTextures.push(babylonMaterial.fuzzRoughnessTexture);
113
- }
114
- else {
115
- fuzzTexturesNeedMerge = true;
116
- }
117
- }
118
- if (babylonMaterial.fuzzColorTexture && !fuzzTexturesNeedMerge) {
119
- additionalTextures.push(babylonMaterial.fuzzColorTexture);
120
- }
121
- if (fuzzTexturesNeedMerge) {
122
- const texId = GetFuzzColorTextureId(babylonMaterial);
123
- if (!this._cachedInternalTexturesMap[texId]) {
124
- const mergedInternalTexture = await CreateMergedFuzzInternalTexture(babylonMaterial);
125
- if (mergedInternalTexture) {
126
- this._cachedInternalTexturesMap[texId] = mergedInternalTexture;
127
- }
128
- }
129
- if (this._cachedInternalTexturesMap[texId]) {
130
- if (babylonMaterial.fuzzColorTexture) {
131
- this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId] = CreateTempTexture(this._cachedInternalTexturesMap[texId], babylonMaterial.fuzzColorTexture);
132
- additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]);
133
- }
134
- if (babylonMaterial.fuzzRoughnessTexture) {
135
- this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId] = CreateTempTexture(this._cachedInternalTexturesMap[texId], babylonMaterial.fuzzRoughnessTexture);
136
- additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]);
137
- }
138
- }
139
- }
140
- }
141
- return additionalTextures;
142
- }
143
- return [];
144
- }
145
- async postExportMaterialAsync(context, node, babylonMaterial) {
146
- return await new Promise((resolve) => {
147
- if (babylonMaterial instanceof OpenPBRMaterial) {
148
- if (babylonMaterial.fuzzWeight == 0.0) {
149
- resolve(node);
150
- return;
151
- }
152
- this._wasUsed = true;
153
- if (node.extensions == null) {
154
- node.extensions = {};
155
- }
156
- const fuzzInfo = {
157
- fuzzFactor: babylonMaterial.fuzzWeight,
158
- fuzzColorFactor: babylonMaterial.fuzzColor.asArray(),
159
- fuzzRoughnessFactor: babylonMaterial.fuzzRoughness,
160
- };
161
- if (babylonMaterial.fuzzWeightTexture) {
162
- fuzzInfo.fuzzTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.fuzzWeightTexture) ?? undefined;
163
- }
164
- let fuzzColorTexture;
165
- if (babylonMaterial.fuzzColorTexture) {
166
- if (this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]) {
167
- fuzzColorTexture = this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId];
168
- }
169
- else {
170
- fuzzColorTexture = babylonMaterial.fuzzColorTexture;
171
- }
172
- fuzzInfo.fuzzColorTexture = this._exporter._materialExporter.getTextureInfo(fuzzColorTexture) ?? undefined;
173
- }
174
- let fuzzRoughnessTexture;
175
- if (babylonMaterial.fuzzRoughnessTexture) {
176
- if (this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]) {
177
- fuzzRoughnessTexture = this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId];
178
- }
179
- else {
180
- fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;
181
- }
182
- fuzzInfo.fuzzRoughnessTexture = this._exporter._materialExporter.getTextureInfo(fuzzRoughnessTexture) ?? undefined;
183
- }
184
- if (fuzzInfo.fuzzColorTexture !== null || fuzzInfo.fuzzRoughnessTexture !== null) {
185
- this._exporter._materialNeedsUVsSet.add(babylonMaterial);
186
- }
187
- node.extensions[NAME] = fuzzInfo;
188
- }
189
- resolve(node);
190
- });
191
- }
192
- }
193
- GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_fuzz(exporter));
5
+ export * from "./KHR_materials_fuzz.pure.js";
6
+ import { RegisterKHR_materials_fuzz } from "./KHR_materials_fuzz.pure.js";
7
+ RegisterKHR_materials_fuzz();
194
8
  //# sourceMappingURL=KHR_materials_fuzz.js.map