@onerjs/loaders 8.23.1

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 (280) hide show
  1. package/OBJ/index.d.ts +4 -0
  2. package/OBJ/index.js +5 -0
  3. package/OBJ/index.js.map +1 -0
  4. package/OBJ/mtlFileLoader.d.ts +41 -0
  5. package/OBJ/mtlFileLoader.js +231 -0
  6. package/OBJ/mtlFileLoader.js.map +1 -0
  7. package/OBJ/objFileLoader.d.ts +136 -0
  8. package/OBJ/objFileLoader.js +318 -0
  9. package/OBJ/objFileLoader.js.map +1 -0
  10. package/OBJ/objFileLoader.metadata.d.ts +4 -0
  11. package/OBJ/objFileLoader.metadata.js +5 -0
  12. package/OBJ/objFileLoader.metadata.js.map +1 -0
  13. package/OBJ/objLoadingOptions.d.ts +47 -0
  14. package/OBJ/objLoadingOptions.js +2 -0
  15. package/OBJ/objLoadingOptions.js.map +1 -0
  16. package/OBJ/solidParser.d.ts +174 -0
  17. package/OBJ/solidParser.js +862 -0
  18. package/OBJ/solidParser.js.map +1 -0
  19. package/SPLAT/index.d.ts +2 -0
  20. package/SPLAT/index.js +4 -0
  21. package/SPLAT/index.js.map +1 -0
  22. package/SPLAT/splatFileLoader.d.ts +88 -0
  23. package/SPLAT/splatFileLoader.js +562 -0
  24. package/SPLAT/splatFileLoader.js.map +1 -0
  25. package/SPLAT/splatFileLoader.metadata.d.ts +14 -0
  26. package/SPLAT/splatFileLoader.metadata.js +12 -0
  27. package/SPLAT/splatFileLoader.metadata.js.map +1 -0
  28. package/SPLAT/splatLoadingOptions.d.ts +13 -0
  29. package/SPLAT/splatLoadingOptions.js +2 -0
  30. package/SPLAT/splatLoadingOptions.js.map +1 -0
  31. package/STL/index.d.ts +1 -0
  32. package/STL/index.js +2 -0
  33. package/STL/index.js.map +1 -0
  34. package/STL/stlFileLoader.d.ts +78 -0
  35. package/STL/stlFileLoader.js +239 -0
  36. package/STL/stlFileLoader.js.map +1 -0
  37. package/STL/stlFileLoader.metadata.d.ts +8 -0
  38. package/STL/stlFileLoader.metadata.js +8 -0
  39. package/STL/stlFileLoader.metadata.js.map +1 -0
  40. package/bvh/bvhFileLoader.d.ts +69 -0
  41. package/bvh/bvhFileLoader.js +133 -0
  42. package/bvh/bvhFileLoader.js.map +1 -0
  43. package/bvh/bvhFileLoader.metadata.d.ts +8 -0
  44. package/bvh/bvhFileLoader.metadata.js +8 -0
  45. package/bvh/bvhFileLoader.metadata.js.map +1 -0
  46. package/bvh/bvhLoader.d.ts +14 -0
  47. package/bvh/bvhLoader.js +329 -0
  48. package/bvh/bvhLoader.js.map +1 -0
  49. package/bvh/bvhLoadingOptions.d.ts +9 -0
  50. package/bvh/bvhLoadingOptions.js +2 -0
  51. package/bvh/bvhLoadingOptions.js.map +1 -0
  52. package/bvh/index.d.ts +2 -0
  53. package/bvh/index.js +4 -0
  54. package/bvh/index.js.map +1 -0
  55. package/bvh/license.md +21 -0
  56. package/dynamic.d.ts +5 -0
  57. package/dynamic.js +57 -0
  58. package/dynamic.js.map +1 -0
  59. package/glTF/1.0/glTFBinaryExtension.d.ts +16 -0
  60. package/glTF/1.0/glTFBinaryExtension.js +65 -0
  61. package/glTF/1.0/glTFBinaryExtension.js.map +1 -0
  62. package/glTF/1.0/glTFLoader.d.ts +144 -0
  63. package/glTF/1.0/glTFLoader.js +1841 -0
  64. package/glTF/1.0/glTFLoader.js.map +1 -0
  65. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -0
  66. package/glTF/1.0/glTFLoaderInterfaces.js +96 -0
  67. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -0
  68. package/glTF/1.0/glTFLoaderUtils.d.ts +71 -0
  69. package/glTF/1.0/glTFLoaderUtils.js +255 -0
  70. package/glTF/1.0/glTFLoaderUtils.js.map +1 -0
  71. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +13 -0
  72. package/glTF/1.0/glTFMaterialsCommonExtension.js +131 -0
  73. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -0
  74. package/glTF/1.0/index.d.ts +5 -0
  75. package/glTF/1.0/index.js +6 -0
  76. package/glTF/1.0/index.js.map +1 -0
  77. package/glTF/2.0/Extensions/EXT_lights_ies.d.ts +41 -0
  78. package/glTF/2.0/Extensions/EXT_lights_ies.js +84 -0
  79. package/glTF/2.0/Extensions/EXT_lights_ies.js.map +1 -0
  80. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +48 -0
  81. package/glTF/2.0/Extensions/EXT_lights_image_based.js +116 -0
  82. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -0
  83. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.d.ts +43 -0
  84. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js +69 -0
  85. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +1 -0
  86. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +39 -0
  87. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +82 -0
  88. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -0
  89. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +39 -0
  90. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +51 -0
  91. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -0
  92. package/glTF/2.0/Extensions/EXT_texture_avif.d.ts +34 -0
  93. package/glTF/2.0/Extensions/EXT_texture_avif.js +39 -0
  94. package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -0
  95. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +33 -0
  96. package/glTF/2.0/Extensions/EXT_texture_webp.js +38 -0
  97. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -0
  98. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +48 -0
  99. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +63 -0
  100. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -0
  101. package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +47 -0
  102. package/glTF/2.0/Extensions/KHR_animation_pointer.data.d.ts +1 -0
  103. package/glTF/2.0/Extensions/KHR_animation_pointer.data.js +239 -0
  104. package/glTF/2.0/Extensions/KHR_animation_pointer.data.js.map +1 -0
  105. package/glTF/2.0/Extensions/KHR_animation_pointer.js +78 -0
  106. package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -0
  107. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +47 -0
  108. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +93 -0
  109. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -0
  110. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.d.ts +352 -0
  111. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js +1700 -0
  112. package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js.map +1 -0
  113. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.d.ts +33 -0
  114. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.js +20 -0
  115. package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.js.map +1 -0
  116. package/glTF/2.0/Extensions/KHR_interactivity/index.d.ts +3 -0
  117. package/glTF/2.0/Extensions/KHR_interactivity/index.js +4 -0
  118. package/glTF/2.0/Extensions/KHR_interactivity/index.js.map +1 -0
  119. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.d.ts +70 -0
  120. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js +450 -0
  121. package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js.map +1 -0
  122. package/glTF/2.0/Extensions/KHR_interactivity.d.ts +38 -0
  123. package/glTF/2.0/Extensions/KHR_interactivity.js +151 -0
  124. package/glTF/2.0/Extensions/KHR_interactivity.js.map +1 -0
  125. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +41 -0
  126. package/glTF/2.0/Extensions/KHR_lights_punctual.js +92 -0
  127. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -0
  128. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +42 -0
  129. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +61 -0
  130. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -0
  131. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +43 -0
  132. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -0
  133. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -0
  134. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +43 -0
  135. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +95 -0
  136. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -0
  137. package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +43 -0
  138. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +60 -0
  139. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -0
  140. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +42 -0
  141. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +52 -0
  142. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
  143. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +46 -0
  144. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -0
  145. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -0
  146. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +42 -0
  147. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +71 -0
  148. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -0
  149. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +42 -0
  150. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +81 -0
  151. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -0
  152. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +43 -0
  153. package/glTF/2.0/Extensions/KHR_materials_sheen.js +85 -0
  154. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -0
  155. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +42 -0
  156. package/glTF/2.0/Extensions/KHR_materials_specular.js +85 -0
  157. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -0
  158. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +42 -0
  159. package/glTF/2.0/Extensions/KHR_materials_transmission.js +306 -0
  160. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -0
  161. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +42 -0
  162. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -0
  163. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -0
  164. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +112 -0
  165. package/glTF/2.0/Extensions/KHR_materials_variants.js +263 -0
  166. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -0
  167. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +43 -0
  168. package/glTF/2.0/Extensions/KHR_materials_volume.js +86 -0
  169. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
  170. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +29 -0
  171. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -0
  172. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -0
  173. package/glTF/2.0/Extensions/KHR_node_hoverability.d.ts +31 -0
  174. package/glTF/2.0/Extensions/KHR_node_hoverability.js +190 -0
  175. package/glTF/2.0/Extensions/KHR_node_hoverability.js.map +1 -0
  176. package/glTF/2.0/Extensions/KHR_node_selectability.d.ts +30 -0
  177. package/glTF/2.0/Extensions/KHR_node_selectability.js +124 -0
  178. package/glTF/2.0/Extensions/KHR_node_selectability.js.map +1 -0
  179. package/glTF/2.0/Extensions/KHR_node_visibility.d.ts +30 -0
  180. package/glTF/2.0/Extensions/KHR_node_visibility.js +69 -0
  181. package/glTF/2.0/Extensions/KHR_node_visibility.js.map +1 -0
  182. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +33 -0
  183. package/glTF/2.0/Extensions/KHR_texture_basisu.js +38 -0
  184. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -0
  185. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +37 -0
  186. package/glTF/2.0/Extensions/KHR_texture_transform.js +59 -0
  187. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -0
  188. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +39 -0
  189. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +48 -0
  190. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -0
  191. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +56 -0
  192. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +227 -0
  193. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -0
  194. package/glTF/2.0/Extensions/MSFT_lod.d.ts +104 -0
  195. package/glTF/2.0/Extensions/MSFT_lod.js +338 -0
  196. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -0
  197. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +27 -0
  198. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +41 -0
  199. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -0
  200. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +27 -0
  201. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +42 -0
  202. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -0
  203. package/glTF/2.0/Extensions/dynamic.d.ts +4 -0
  204. package/glTF/2.0/Extensions/dynamic.js +156 -0
  205. package/glTF/2.0/Extensions/dynamic.js.map +1 -0
  206. package/glTF/2.0/Extensions/gltfPathToObjectConverter.d.ts +45 -0
  207. package/glTF/2.0/Extensions/gltfPathToObjectConverter.js +101 -0
  208. package/glTF/2.0/Extensions/gltfPathToObjectConverter.js.map +1 -0
  209. package/glTF/2.0/Extensions/index.d.ts +39 -0
  210. package/glTF/2.0/Extensions/index.js +41 -0
  211. package/glTF/2.0/Extensions/index.js.map +1 -0
  212. package/glTF/2.0/Extensions/objectModelMapping.d.ts +289 -0
  213. package/glTF/2.0/Extensions/objectModelMapping.js +828 -0
  214. package/glTF/2.0/Extensions/objectModelMapping.js.map +1 -0
  215. package/glTF/2.0/glTFLoader.d.ts +429 -0
  216. package/glTF/2.0/glTFLoader.js +2408 -0
  217. package/glTF/2.0/glTFLoader.js.map +1 -0
  218. package/glTF/2.0/glTFLoaderAnimation.d.ts +42 -0
  219. package/glTF/2.0/glTFLoaderAnimation.js +80 -0
  220. package/glTF/2.0/glTFLoaderAnimation.js.map +1 -0
  221. package/glTF/2.0/glTFLoaderExtension.d.ts +165 -0
  222. package/glTF/2.0/glTFLoaderExtension.js +2 -0
  223. package/glTF/2.0/glTFLoaderExtension.js.map +1 -0
  224. package/glTF/2.0/glTFLoaderExtensionRegistry.d.ts +25 -0
  225. package/glTF/2.0/glTFLoaderExtensionRegistry.js +33 -0
  226. package/glTF/2.0/glTFLoaderExtensionRegistry.js.map +1 -0
  227. package/glTF/2.0/glTFLoaderInterfaces.d.ts +257 -0
  228. package/glTF/2.0/glTFLoaderInterfaces.js +2 -0
  229. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -0
  230. package/glTF/2.0/index.d.ts +6 -0
  231. package/glTF/2.0/index.js +8 -0
  232. package/glTF/2.0/index.js.map +1 -0
  233. package/glTF/glTFFileLoader.d.ts +516 -0
  234. package/glTF/glTFFileLoader.js +968 -0
  235. package/glTF/glTFFileLoader.js.map +1 -0
  236. package/glTF/glTFFileLoader.metadata.d.ts +15 -0
  237. package/glTF/glTFFileLoader.metadata.js +18 -0
  238. package/glTF/glTFFileLoader.metadata.js.map +1 -0
  239. package/glTF/glTFValidation.d.ts +29 -0
  240. package/glTF/glTFValidation.js +126 -0
  241. package/glTF/glTFValidation.js.map +1 -0
  242. package/glTF/index.d.ts +5 -0
  243. package/glTF/index.js +7 -0
  244. package/glTF/index.js.map +1 -0
  245. package/index.d.ts +5 -0
  246. package/index.js +7 -0
  247. package/index.js.map +1 -0
  248. package/legacy/legacy-bvhFileLoader.d.ts +1 -0
  249. package/legacy/legacy-bvhFileLoader.js +16 -0
  250. package/legacy/legacy-bvhFileLoader.js.map +1 -0
  251. package/legacy/legacy-glTF.d.ts +2 -0
  252. package/legacy/legacy-glTF.js +19 -0
  253. package/legacy/legacy-glTF.js.map +1 -0
  254. package/legacy/legacy-glTF1.d.ts +2 -0
  255. package/legacy/legacy-glTF1.js +16 -0
  256. package/legacy/legacy-glTF1.js.map +1 -0
  257. package/legacy/legacy-glTF1FileLoader.d.ts +2 -0
  258. package/legacy/legacy-glTF1FileLoader.js +4 -0
  259. package/legacy/legacy-glTF1FileLoader.js.map +1 -0
  260. package/legacy/legacy-glTF2.d.ts +2 -0
  261. package/legacy/legacy-glTF2.js +35 -0
  262. package/legacy/legacy-glTF2.js.map +1 -0
  263. package/legacy/legacy-glTF2FileLoader.d.ts +2 -0
  264. package/legacy/legacy-glTF2FileLoader.js +4 -0
  265. package/legacy/legacy-glTF2FileLoader.js.map +1 -0
  266. package/legacy/legacy-glTFFileLoader.d.ts +3 -0
  267. package/legacy/legacy-glTFFileLoader.js +5 -0
  268. package/legacy/legacy-glTFFileLoader.js.map +1 -0
  269. package/legacy/legacy-objFileLoader.d.ts +1 -0
  270. package/legacy/legacy-objFileLoader.js +16 -0
  271. package/legacy/legacy-objFileLoader.js.map +1 -0
  272. package/legacy/legacy-stlFileLoader.d.ts +1 -0
  273. package/legacy/legacy-stlFileLoader.js +16 -0
  274. package/legacy/legacy-stlFileLoader.js.map +1 -0
  275. package/legacy/legacy.d.ts +7 -0
  276. package/legacy/legacy.js +10 -0
  277. package/legacy/legacy.js.map +1 -0
  278. package/license.md +71 -0
  279. package/package.json +49 -0
  280. package/readme.md +23 -0
@@ -0,0 +1,318 @@
1
+ import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
3
+ import { RegisterSceneLoaderPlugin } from "@babylonjs/core/Loading/sceneLoader.js";
4
+ import { AssetContainer } from "@babylonjs/core/assetContainer.js";
5
+ import { OBJFileLoaderMetadata } from "./objFileLoader.metadata.js";
6
+ import { MTLFileLoader } from "./mtlFileLoader.js";
7
+ import { SolidParser } from "./solidParser.js";
8
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
9
+ /**
10
+ * OBJ file type loader.
11
+ * This is a babylon scene loader plugin.
12
+ */
13
+ export class OBJFileLoader {
14
+ /**
15
+ * Invert Y-Axis of referenced textures on load
16
+ */
17
+ static get INVERT_TEXTURE_Y() {
18
+ return MTLFileLoader.INVERT_TEXTURE_Y;
19
+ }
20
+ static set INVERT_TEXTURE_Y(value) {
21
+ MTLFileLoader.INVERT_TEXTURE_Y = value;
22
+ }
23
+ /**
24
+ * Creates loader for .OBJ files
25
+ *
26
+ * @param loadingOptions options for loading and parsing OBJ/MTL files.
27
+ */
28
+ constructor(loadingOptions) {
29
+ /**
30
+ * Defines the name of the plugin.
31
+ */
32
+ this.name = OBJFileLoaderMetadata.name;
33
+ /**
34
+ * Defines the extension the plugin is able to load.
35
+ */
36
+ this.extensions = OBJFileLoaderMetadata.extensions;
37
+ this._assetContainer = null;
38
+ this._loadingOptions = { ...OBJFileLoader._DefaultLoadingOptions, ...(loadingOptions ?? {}) };
39
+ }
40
+ static get _DefaultLoadingOptions() {
41
+ return {
42
+ computeNormals: OBJFileLoader.COMPUTE_NORMALS,
43
+ optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
44
+ importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
45
+ invertY: OBJFileLoader.INVERT_Y,
46
+ invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
47
+ // eslint-disable-next-line @typescript-eslint/naming-convention
48
+ UVScaling: OBJFileLoader.UV_SCALING,
49
+ materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
50
+ optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
51
+ skipMaterials: OBJFileLoader.SKIP_MATERIALS,
52
+ useLegacyBehavior: OBJFileLoader.USE_LEGACY_BEHAVIOR,
53
+ };
54
+ }
55
+ /**
56
+ * Calls synchronously the MTL file attached to this obj.
57
+ * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
58
+ * Without this function materials are not displayed in the first frame (but displayed after).
59
+ * In consequence it is impossible to get material information in your HTML file
60
+ *
61
+ * @param url The URL of the MTL file
62
+ * @param rootUrl defines where to load data from
63
+ * @param onSuccess Callback function to be called when the MTL file is loaded
64
+ * @param onFailure
65
+ */
66
+ _loadMTL(url, rootUrl, onSuccess, onFailure) {
67
+ //The complete path to the mtl file
68
+ const pathOfFile = rootUrl + url;
69
+ // Loads through the babylon tools to allow fileInput search.
70
+ Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, (request, exception) => {
71
+ onFailure(pathOfFile, exception);
72
+ });
73
+ }
74
+ /** @internal */
75
+ createPlugin(options) {
76
+ return new OBJFileLoader(options[OBJFileLoaderMetadata.name]);
77
+ }
78
+ /**
79
+ * If the data string can be loaded directly.
80
+ * @returns if the data can be loaded directly
81
+ */
82
+ canDirectLoad() {
83
+ return false;
84
+ }
85
+ /**
86
+ * Imports one or more meshes from the loaded OBJ data and adds them to the scene
87
+ * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
88
+ * @param scene the scene the meshes should be added to
89
+ * @param data the OBJ data to load
90
+ * @param rootUrl root url to load from
91
+ * @returns a promise containing the loaded meshes, particles, skeletons and animations
92
+ */
93
+ // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
94
+ importMeshAsync(meshesNames, scene, data, rootUrl) {
95
+ //get the meshes from OBJ file
96
+ // eslint-disable-next-line github/no-then
97
+ return this._parseSolidAsync(meshesNames, scene, data, rootUrl).then((meshes) => {
98
+ return {
99
+ meshes: meshes,
100
+ particleSystems: [],
101
+ skeletons: [],
102
+ animationGroups: [],
103
+ transformNodes: [],
104
+ geometries: [],
105
+ lights: [],
106
+ spriteManagers: [],
107
+ };
108
+ });
109
+ }
110
+ /**
111
+ * Imports all objects from the loaded OBJ data and adds them to the scene
112
+ * @param scene the scene the objects should be added to
113
+ * @param data the OBJ data to load
114
+ * @param rootUrl root url to load from
115
+ * @returns a promise which completes when objects have been loaded to the scene
116
+ */
117
+ // eslint-disable-next-line no-restricted-syntax
118
+ loadAsync(scene, data, rootUrl) {
119
+ //Get the 3D model
120
+ // eslint-disable-next-line github/no-then
121
+ return this.importMeshAsync(null, scene, data, rootUrl).then(() => {
122
+ // return void
123
+ });
124
+ }
125
+ /**
126
+ * Load into an asset container.
127
+ * @param scene The scene to load into
128
+ * @param data The data to import
129
+ * @param rootUrl The root url for scene and resources
130
+ * @returns The loaded asset container
131
+ */
132
+ // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
133
+ loadAssetContainerAsync(scene, data, rootUrl) {
134
+ const container = new AssetContainer(scene);
135
+ this._assetContainer = container;
136
+ return (this.importMeshAsync(null, scene, data, rootUrl)
137
+ // eslint-disable-next-line github/no-then
138
+ .then((result) => {
139
+ result.meshes.forEach((mesh) => container.meshes.push(mesh));
140
+ result.meshes.forEach((mesh) => {
141
+ const material = mesh.material;
142
+ if (material) {
143
+ // Materials
144
+ if (container.materials.indexOf(material) == -1) {
145
+ container.materials.push(material);
146
+ // Textures
147
+ const textures = material.getActiveTextures();
148
+ textures.forEach((t) => {
149
+ if (container.textures.indexOf(t) == -1) {
150
+ container.textures.push(t);
151
+ }
152
+ });
153
+ }
154
+ }
155
+ });
156
+ this._assetContainer = null;
157
+ return container;
158
+ })
159
+ // eslint-disable-next-line github/no-then
160
+ .catch((ex) => {
161
+ this._assetContainer = null;
162
+ throw ex;
163
+ }));
164
+ }
165
+ /**
166
+ * Read the OBJ file and create an Array of meshes.
167
+ * Each mesh contains all information given by the OBJ and the MTL file.
168
+ * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
169
+ * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file
170
+ * @param scene defines the scene where are displayed the data
171
+ * @param data defines the content of the obj file
172
+ * @param rootUrl defines the path to the folder
173
+ * @returns the list of loaded meshes
174
+ */
175
+ // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
176
+ _parseSolidAsync(meshesNames, scene, data, rootUrl) {
177
+ let fileToLoad = ""; //The name of the mtlFile to load
178
+ const materialsFromMTLFile = new MTLFileLoader();
179
+ const materialToUse = [];
180
+ const babylonMeshesArray = []; //The mesh for babylon
181
+ // Sanitize data
182
+ data = data.replace(/#.*$/gm, "").trim();
183
+ // Main function
184
+ const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);
185
+ solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName) => {
186
+ fileToLoad = fileName;
187
+ });
188
+ // load the materials
189
+ const mtlPromises = [];
190
+ // Check if we have a file to load
191
+ if (fileToLoad !== "" && !this._loadingOptions.skipMaterials) {
192
+ //Load the file synchronously
193
+ mtlPromises.push(new Promise((resolve, reject) => {
194
+ this._loadMTL(fileToLoad, rootUrl, (dataLoaded) => {
195
+ try {
196
+ //Create materials thanks MTLLoader function
197
+ materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);
198
+ //Look at each material loaded in the mtl file
199
+ for (let n = 0; n < materialsFromMTLFile.materials.length; n++) {
200
+ //Three variables to get all meshes with the same material
201
+ let startIndex = 0;
202
+ const _indices = [];
203
+ let _index;
204
+ //The material from MTL file is used in the meshes loaded
205
+ //Push the indice in an array
206
+ //Check if the material is not used for another mesh
207
+ while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
208
+ _indices.push(_index);
209
+ startIndex = _index + 1;
210
+ }
211
+ //If the material is not used dispose it
212
+ if (_index === -1 && _indices.length === 0) {
213
+ //If the material is not needed, remove it
214
+ materialsFromMTLFile.materials[n].dispose();
215
+ }
216
+ else {
217
+ for (let o = 0; o < _indices.length; o++) {
218
+ //Apply the material to the Mesh for each mesh with the material
219
+ const mesh = babylonMeshesArray[_indices[o]];
220
+ const material = materialsFromMTLFile.materials[n];
221
+ mesh.material = material;
222
+ if (!mesh.getTotalIndices()) {
223
+ // No indices, we need to turn on point cloud
224
+ material.pointsCloud = true;
225
+ }
226
+ }
227
+ }
228
+ }
229
+ resolve();
230
+ }
231
+ catch (e) {
232
+ Tools.Warn(`Error processing MTL file: '${fileToLoad}'`);
233
+ if (this._loadingOptions.materialLoadingFailsSilently) {
234
+ resolve();
235
+ }
236
+ else {
237
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
238
+ reject(e);
239
+ }
240
+ }
241
+ }, (pathOfFile, exception) => {
242
+ Tools.Warn(`Error downloading MTL file: '${fileToLoad}'`);
243
+ if (this._loadingOptions.materialLoadingFailsSilently) {
244
+ resolve();
245
+ }
246
+ else {
247
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
248
+ reject(exception);
249
+ }
250
+ });
251
+ }));
252
+ }
253
+ //Return an array with all Mesh
254
+ // eslint-disable-next-line github/no-then
255
+ return Promise.all(mtlPromises).then(() => {
256
+ const isLine = (mesh) => Boolean(mesh._internalMetadata?.["_isLine"] ?? false);
257
+ // Iterate over the mesh, determine if it is a line mesh, clone or modify the material to line rendering.
258
+ babylonMeshesArray.forEach((mesh) => {
259
+ if (isLine(mesh)) {
260
+ let mat = mesh.material ?? new StandardMaterial(mesh.name + "_line", scene);
261
+ // If another mesh is using this material and it is not a line then we need to clone it.
262
+ const needClone = mat.getBindedMeshes().filter((e) => !isLine(e)).length > 0;
263
+ if (needClone) {
264
+ mat = mat.clone(mat.name + "_line") ?? mat;
265
+ }
266
+ mat.wireframe = true;
267
+ mesh.material = mat;
268
+ if (mesh._internalMetadata) {
269
+ mesh._internalMetadata["_isLine"] = undefined;
270
+ }
271
+ }
272
+ });
273
+ return babylonMeshesArray;
274
+ });
275
+ }
276
+ }
277
+ /**
278
+ * Defines if UVs are optimized by default during load.
279
+ */
280
+ OBJFileLoader.OPTIMIZE_WITH_UV = true;
281
+ /**
282
+ * Invert model on y-axis (does a model scaling inversion)
283
+ */
284
+ OBJFileLoader.INVERT_Y = false;
285
+ /**
286
+ * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
287
+ */
288
+ OBJFileLoader.IMPORT_VERTEX_COLORS = false;
289
+ /**
290
+ * Compute the normals for the model, even if normals are present in the file.
291
+ */
292
+ OBJFileLoader.COMPUTE_NORMALS = false;
293
+ /**
294
+ * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.
295
+ * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.
296
+ */
297
+ OBJFileLoader.OPTIMIZE_NORMALS = false;
298
+ /**
299
+ * Defines custom scaling of UV coordinates of loaded meshes.
300
+ */
301
+ OBJFileLoader.UV_SCALING = new Vector2(1, 1);
302
+ /**
303
+ * Skip loading the materials even if defined in the OBJ file (materials are ignored).
304
+ */
305
+ OBJFileLoader.SKIP_MATERIALS = false;
306
+ /**
307
+ * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
308
+ *
309
+ * Defaults to true for backwards compatibility.
310
+ */
311
+ OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
312
+ /**
313
+ * Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.
314
+ */
315
+ OBJFileLoader.USE_LEGACY_BEHAVIOR = false;
316
+ //Add this loader into the register plugin
317
+ RegisterSceneLoaderPlugin(new OBJFileLoader());
318
+ //# sourceMappingURL=objFileLoader.js.map
@@ -0,0 +1 @@
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C;;;GAGG;AACW,8BAAgB,GAAG,KAAK,AAAR,CAAS;AACvC;;GAEG;AACW,wBAAU,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,AAApB,CAAqB;AAC7C;;GAEG;AACW,4BAAc,GAAG,KAAK,AAAR,CAAS;AAErC;;;;GAIG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ;AAErD;;GAEG;AACW,iCAAmB,GAAG,KAAK,AAAR,CAAS;AAkS9C,0CAA0C;AAC1C,yBAAyB,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/promise-function-async */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult, SceneLoaderPluginOptions } from \"core/Loading/sceneLoader\";\r\nimport { RegisterSceneLoaderPlugin } from \"core/Loading/sceneLoader\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { WebRequest } from \"core/Misc/webRequest\";\r\nimport { OBJFileLoaderMetadata } from \"./objFileLoader.metadata\";\r\nimport { MTLFileLoader } from \"./mtlFileLoader\";\r\nimport type { OBJLoadingOptions } from \"./objLoadingOptions\";\r\nimport { SolidParser } from \"./solidParser\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\ndeclare module \"core/Loading/sceneLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc, @typescript-eslint/naming-convention\r\n export interface SceneLoaderPluginOptions {\r\n /**\r\n * Defines options for the obj loader.\r\n */\r\n [OBJFileLoaderMetadata.name]: Partial<OBJLoadingOptions>;\r\n }\r\n}\r\n\r\n/**\r\n * OBJ file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n public static OPTIMIZE_WITH_UV = true;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n public static INVERT_Y = false;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static get INVERT_TEXTURE_Y() {\r\n return MTLFileLoader.INVERT_TEXTURE_Y;\r\n }\r\n\r\n public static set INVERT_TEXTURE_Y(value: boolean) {\r\n MTLFileLoader.INVERT_TEXTURE_Y = value;\r\n }\r\n\r\n /**\r\n * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.\r\n */\r\n public static IMPORT_VERTEX_COLORS = false;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n public static COMPUTE_NORMALS = false;\r\n /**\r\n * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.\r\n * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.\r\n */\r\n public static OPTIMIZE_NORMALS = false;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n public static UV_SCALING = new Vector2(1, 1);\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n public static SKIP_MATERIALS = false;\r\n\r\n /**\r\n * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.\r\n *\r\n * Defaults to true for backwards compatibility.\r\n */\r\n public static MATERIAL_LOADING_FAILS_SILENTLY = true;\r\n\r\n /**\r\n * Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.\r\n */\r\n public static USE_LEGACY_BEHAVIOR = false;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public readonly name = OBJFileLoaderMetadata.name;\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public readonly extensions = OBJFileLoaderMetadata.extensions;\r\n\r\n private _assetContainer: Nullable<AssetContainer> = null;\r\n\r\n private _loadingOptions: OBJLoadingOptions;\r\n\r\n /**\r\n * Creates loader for .OBJ files\r\n *\r\n * @param loadingOptions options for loading and parsing OBJ/MTL files.\r\n */\r\n constructor(loadingOptions?: Partial<Readonly<OBJLoadingOptions>>) {\r\n this._loadingOptions = { ...OBJFileLoader._DefaultLoadingOptions, ...(loadingOptions ?? {}) };\r\n }\r\n\r\n private static get _DefaultLoadingOptions(): OBJLoadingOptions {\r\n return {\r\n computeNormals: OBJFileLoader.COMPUTE_NORMALS,\r\n optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,\r\n importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,\r\n invertY: OBJFileLoader.INVERT_Y,\r\n invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: OBJFileLoader.UV_SCALING,\r\n materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,\r\n optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,\r\n skipMaterials: OBJFileLoader.SKIP_MATERIALS,\r\n useLegacyBehavior: OBJFileLoader.USE_LEGACY_BEHAVIOR,\r\n };\r\n }\r\n\r\n /**\r\n * Calls synchronously the MTL file attached to this obj.\r\n * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.\r\n * Without this function materials are not displayed in the first frame (but displayed after).\r\n * In consequence it is impossible to get material information in your HTML file\r\n *\r\n * @param url The URL of the MTL file\r\n * @param rootUrl defines where to load data from\r\n * @param onSuccess Callback function to be called when the MTL file is loaded\r\n * @param onFailure\r\n */\r\n private _loadMTL(\r\n url: string,\r\n rootUrl: string,\r\n onSuccess: (response: string | ArrayBuffer, responseUrl?: string) => any,\r\n onFailure: (pathOfFile: string, exception?: any) => void\r\n ) {\r\n //The complete path to the mtl file\r\n const pathOfFile = rootUrl + url;\r\n\r\n // Loads through the babylon tools to allow fileInput search.\r\n Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, (request?: WebRequest, exception?: any) => {\r\n onFailure(pathOfFile, exception);\r\n });\r\n }\r\n\r\n /** @internal */\r\n createPlugin(options: SceneLoaderPluginOptions): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new OBJFileLoader(options[OBJFileLoaderMetadata.name]);\r\n }\r\n\r\n /**\r\n * If the data string can be loaded directly.\r\n * @returns if the data can be loaded directly\r\n */\r\n public canDirectLoad(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Imports one or more meshes from the loaded OBJ data and adds them to the scene\r\n * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n //get the meshes from OBJ file\r\n // eslint-disable-next-line github/no-then\r\n return this._parseSolidAsync(meshesNames, scene, data, rootUrl).then((meshes) => {\r\n return {\r\n meshes: meshes,\r\n particleSystems: [],\r\n skeletons: [],\r\n animationGroups: [],\r\n transformNodes: [],\r\n geometries: [],\r\n lights: [],\r\n spriteManagers: [],\r\n };\r\n });\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded OBJ data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n // eslint-disable-next-line github/no-then\r\n return this.importMeshAsync(null, scene, data, rootUrl).then(() => {\r\n // return void\r\n });\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer> {\r\n const container = new AssetContainer(scene);\r\n this._assetContainer = container;\r\n\r\n return (\r\n this.importMeshAsync(null, scene, data, rootUrl)\r\n // eslint-disable-next-line github/no-then\r\n .then((result) => {\r\n result.meshes.forEach((mesh) => container.meshes.push(mesh));\r\n result.meshes.forEach((mesh) => {\r\n const material = mesh.material;\r\n if (material) {\r\n // Materials\r\n if (container.materials.indexOf(material) == -1) {\r\n container.materials.push(material);\r\n\r\n // Textures\r\n const textures = material.getActiveTextures();\r\n textures.forEach((t) => {\r\n if (container.textures.indexOf(t) == -1) {\r\n container.textures.push(t);\r\n }\r\n });\r\n }\r\n }\r\n });\r\n this._assetContainer = null;\r\n return container;\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Read the OBJ file and create an Array of meshes.\r\n * Each mesh contains all information given by the OBJ and the MTL file.\r\n * i.e. vertices positions and indices, optional normals values, optional UV values, optional material\r\n * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene defines the scene where are displayed the data\r\n * @param data defines the content of the obj file\r\n * @param rootUrl defines the path to the folder\r\n * @returns the list of loaded meshes\r\n */\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n private _parseSolidAsync(meshesNames: any, scene: Scene, data: string, rootUrl: string): Promise<Array<AbstractMesh>> {\r\n let fileToLoad: string = \"\"; //The name of the mtlFile to load\r\n const materialsFromMTLFile: MTLFileLoader = new MTLFileLoader();\r\n const materialToUse: string[] = [];\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\r\n\r\n // Sanitize data\r\n data = data.replace(/#.*$/gm, \"\").trim();\r\n\r\n // Main function\r\n const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);\r\n\r\n solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName: string) => {\r\n fileToLoad = fileName;\r\n });\r\n\r\n // load the materials\r\n const mtlPromises: Array<Promise<void>> = [];\r\n // Check if we have a file to load\r\n if (fileToLoad !== \"\" && !this._loadingOptions.skipMaterials) {\r\n //Load the file synchronously\r\n mtlPromises.push(\r\n new Promise((resolve, reject) => {\r\n this._loadMTL(\r\n fileToLoad,\r\n rootUrl,\r\n (dataLoaded) => {\r\n try {\r\n //Create materials thanks MTLLoader function\r\n materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);\r\n //Look at each material loaded in the mtl file\r\n for (let n = 0; n < materialsFromMTLFile.materials.length; n++) {\r\n //Three variables to get all meshes with the same material\r\n let startIndex = 0;\r\n const _indices = [];\r\n let _index;\r\n\r\n //The material from MTL file is used in the meshes loaded\r\n //Push the indice in an array\r\n //Check if the material is not used for another mesh\r\n while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {\r\n _indices.push(_index);\r\n startIndex = _index + 1;\r\n }\r\n //If the material is not used dispose it\r\n if (_index === -1 && _indices.length === 0) {\r\n //If the material is not needed, remove it\r\n materialsFromMTLFile.materials[n].dispose();\r\n } else {\r\n for (let o = 0; o < _indices.length; o++) {\r\n //Apply the material to the Mesh for each mesh with the material\r\n const mesh = babylonMeshesArray[_indices[o]];\r\n const material = materialsFromMTLFile.materials[n];\r\n mesh.material = material;\r\n\r\n if (!mesh.getTotalIndices()) {\r\n // No indices, we need to turn on point cloud\r\n material.pointsCloud = true;\r\n }\r\n }\r\n }\r\n }\r\n resolve();\r\n } catch (e) {\r\n Tools.Warn(`Error processing MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(e);\r\n }\r\n }\r\n },\r\n (pathOfFile: string, exception?: any) => {\r\n Tools.Warn(`Error downloading MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(exception);\r\n }\r\n }\r\n );\r\n })\r\n );\r\n }\r\n //Return an array with all Mesh\r\n // eslint-disable-next-line github/no-then\r\n return Promise.all(mtlPromises).then(() => {\r\n const isLine = (mesh: AbstractMesh) => Boolean(mesh._internalMetadata?.[\"_isLine\"] ?? false);\r\n\r\n // Iterate over the mesh, determine if it is a line mesh, clone or modify the material to line rendering.\r\n babylonMeshesArray.forEach((mesh) => {\r\n if (isLine(mesh)) {\r\n let mat = mesh.material ?? new StandardMaterial(mesh.name + \"_line\", scene);\r\n // If another mesh is using this material and it is not a line then we need to clone it.\r\n const needClone = mat.getBindedMeshes().filter((e) => !isLine(e)).length > 0;\r\n if (needClone) {\r\n mat = mat.clone(mat.name + \"_line\") ?? mat;\r\n }\r\n mat.wireframe = true;\r\n mesh.material = mat;\r\n if (mesh._internalMetadata) {\r\n mesh._internalMetadata[\"_isLine\"] = undefined;\r\n }\r\n }\r\n });\r\n\r\n return babylonMeshesArray;\r\n });\r\n }\r\n}\r\n\r\n//Add this loader into the register plugin\r\nRegisterSceneLoaderPlugin(new OBJFileLoader());\r\n"]}
@@ -0,0 +1,4 @@
1
+ export declare const OBJFileLoaderMetadata: {
2
+ readonly name: "obj";
3
+ readonly extensions: ".obj";
4
+ };
@@ -0,0 +1,5 @@
1
+ export const OBJFileLoaderMetadata = {
2
+ name: "obj",
3
+ extensions: ".obj",
4
+ };
5
+ //# sourceMappingURL=objFileLoader.metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objFileLoader.metadata.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/objFileLoader.metadata.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACjC,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,MAAM;CACyB,CAAC","sourcesContent":["import type { ISceneLoaderPluginMetadata } from \"core/index\";\r\n\r\nexport const OBJFileLoaderMetadata = {\r\n name: \"obj\",\r\n extensions: \".obj\",\r\n} as const satisfies ISceneLoaderPluginMetadata;\r\n"]}
@@ -0,0 +1,47 @@
1
+ import type { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
2
+ /**
3
+ * Options for loading OBJ/MTL files
4
+ */
5
+ export type OBJLoadingOptions = {
6
+ /**
7
+ * Defines if UVs are optimized by default during load.
8
+ */
9
+ optimizeWithUV: boolean;
10
+ /**
11
+ * Defines custom scaling of UV coordinates of loaded meshes.
12
+ */
13
+ UVScaling: Vector2;
14
+ /**
15
+ * Invert model on y-axis (does a model scaling inversion)
16
+ */
17
+ invertY: boolean;
18
+ /**
19
+ * Invert Y-Axis of referenced textures on load
20
+ */
21
+ invertTextureY: boolean;
22
+ /**
23
+ * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
24
+ */
25
+ importVertexColors: boolean;
26
+ /**
27
+ * Compute the normals for the model, even if normals are present in the file.
28
+ */
29
+ computeNormals: boolean;
30
+ /**
31
+ * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.
32
+ * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.
33
+ */
34
+ optimizeNormals: boolean;
35
+ /**
36
+ * Skip loading the materials even if defined in the OBJ file (materials are ignored).
37
+ */
38
+ skipMaterials: boolean;
39
+ /**
40
+ * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
41
+ */
42
+ materialLoadingFailsSilently: boolean;
43
+ /**
44
+ * Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.
45
+ */
46
+ useLegacyBehavior: boolean;
47
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=objLoadingOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objLoadingOptions.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/objLoadingOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { Vector2 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Options for loading OBJ/MTL files\r\n */\r\nexport type OBJLoadingOptions = {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n optimizeWithUV: boolean;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: Vector2;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n invertY: boolean;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n invertTextureY: boolean;\r\n /**\r\n * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.\r\n */\r\n importVertexColors: boolean;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n computeNormals: boolean;\r\n /**\r\n * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.\r\n * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.\r\n */\r\n optimizeNormals: boolean;\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n skipMaterials: boolean;\r\n /**\r\n * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.\r\n */\r\n materialLoadingFailsSilently: boolean;\r\n /**\r\n * Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.\r\n */\r\n useLegacyBehavior: boolean;\r\n};\r\n"]}
@@ -0,0 +1,174 @@
1
+ import type { AssetContainer } from "@babylonjs/core/assetContainer.js";
2
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
3
+ import type { Scene } from "@babylonjs/core/scene.js";
4
+ import type { Nullable } from "@babylonjs/core/types.js";
5
+ import type { OBJLoadingOptions } from "./objLoadingOptions.js";
6
+ /**
7
+ * Class used to load mesh data from OBJ content
8
+ */
9
+ export declare class SolidParser {
10
+ /** Object descriptor */
11
+ static ObjectDescriptor: RegExp;
12
+ /** Group descriptor */
13
+ static GroupDescriptor: RegExp;
14
+ /** Material lib descriptor */
15
+ static MtlLibGroupDescriptor: RegExp;
16
+ /** Use a material descriptor */
17
+ static UseMtlDescriptor: RegExp;
18
+ /** Smooth descriptor */
19
+ static SmoothDescriptor: RegExp;
20
+ /** Pattern used to detect a vertex */
21
+ static VertexPattern: RegExp;
22
+ /** Pattern used to detect a normal */
23
+ static NormalPattern: RegExp;
24
+ /** Pattern used to detect a UV set */
25
+ static UVPattern: RegExp;
26
+ /** Pattern used to detect a first kind of face (f vertex vertex vertex) */
27
+ static FacePattern1: RegExp;
28
+ /** Pattern used to detect a second kind of face (f vertex/uvs vertex/uvs vertex/uvs) */
29
+ static FacePattern2: RegExp;
30
+ /** Pattern used to detect a third kind of face (f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal) */
31
+ static FacePattern3: RegExp;
32
+ /** Pattern used to detect a fourth kind of face (f vertex//normal vertex//normal vertex//normal)*/
33
+ static FacePattern4: RegExp;
34
+ /** Pattern used to detect a fifth kind of face (f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal) */
35
+ static FacePattern5: RegExp;
36
+ /** Pattern used to detect a line(l vertex vertex) */
37
+ static LinePattern1: RegExp;
38
+ /** Pattern used to detect a second kind of line (l vertex/uvs vertex/uvs) */
39
+ static LinePattern2: RegExp;
40
+ /** Pattern used to detect a third kind of line (l vertex/uvs/normal vertex/uvs/normal) */
41
+ static LinePattern3: RegExp;
42
+ private _loadingOptions;
43
+ private _positions;
44
+ private _normals;
45
+ private _uvs;
46
+ private _colors;
47
+ private _extColors;
48
+ private _meshesFromObj;
49
+ private _handledMesh;
50
+ private _indicesForBabylon;
51
+ private _wrappedPositionForBabylon;
52
+ private _wrappedUvsForBabylon;
53
+ private _wrappedColorsForBabylon;
54
+ private _wrappedNormalsForBabylon;
55
+ private _tuplePosNorm;
56
+ private _curPositionInIndices;
57
+ private _hasMeshes;
58
+ private _unwrappedPositionsForBabylon;
59
+ private _unwrappedColorsForBabylon;
60
+ private _unwrappedNormalsForBabylon;
61
+ private _unwrappedUVForBabylon;
62
+ private _triangles;
63
+ private _materialNameFromObj;
64
+ private _objMeshName;
65
+ private _increment;
66
+ private _isFirstMaterial;
67
+ private _grayColor;
68
+ private _materialToUse;
69
+ private _babylonMeshesArray;
70
+ private _pushTriangle;
71
+ private _handednessSign;
72
+ private _hasLineData;
73
+ /**
74
+ * Creates a new SolidParser
75
+ * @param materialToUse defines the array to fill with the list of materials to use (it will be filled by the parse function)
76
+ * @param babylonMeshesArray defines the array to fill with the list of loaded meshes (it will be filled by the parse function)
77
+ * @param loadingOptions defines the loading options to use
78
+ */
79
+ constructor(materialToUse: string[], babylonMeshesArray: Array<Mesh>, loadingOptions: OBJLoadingOptions);
80
+ /**
81
+ * Search for obj in the given array.
82
+ * This function is called to check if a couple of data already exists in an array.
83
+ *
84
+ * If found, returns the index of the founded tuple index. Returns -1 if not found
85
+ * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
86
+ * @param obj Array<number>
87
+ * @returns {boolean}
88
+ */
89
+ private _isInArray;
90
+ private _isInArrayUV;
91
+ /**
92
+ * This function set the data for each triangle.
93
+ * Data are position, normals and uvs
94
+ * If a tuple of (position, normal) is not set, add the data into the corresponding array
95
+ * If the tuple already exist, add only their indice
96
+ *
97
+ * @param indicePositionFromObj Integer The index in positions array
98
+ * @param indiceUvsFromObj Integer The index in uvs array
99
+ * @param indiceNormalFromObj Integer The index in normals array
100
+ * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
101
+ * @param textureVectorFromOBJ Vector3 The value of uvs
102
+ * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
103
+ * @param positionColorsFromOBJ
104
+ */
105
+ private _setData;
106
+ /**
107
+ * Transform Vector() and BABYLON.Color() objects into numbers in an array
108
+ */
109
+ private _unwrapData;
110
+ /**
111
+ * Create triangles from polygons
112
+ * It is important to notice that a triangle is a polygon
113
+ * We get 5 patterns of face defined in OBJ File :
114
+ * facePattern1 = ["1","2","3","4","5","6"]
115
+ * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
116
+ * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
117
+ * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
118
+ * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
119
+ * Each pattern is divided by the same method
120
+ * @param faces Array[String] The indices of elements
121
+ * @param v Integer The variable to increment
122
+ */
123
+ private _getTriangles;
124
+ /**
125
+ * To get color between color and extension color
126
+ * @param index Integer The index of the element in the array
127
+ * @returns value of target color
128
+ */
129
+ private _getColor;
130
+ /**
131
+ * Create triangles and push the data for each polygon for the pattern 1
132
+ * In this pattern we get vertice positions
133
+ * @param face
134
+ * @param v
135
+ */
136
+ private _setDataForCurrentFaceWithPattern1;
137
+ /**
138
+ * Create triangles and push the data for each polygon for the pattern 2
139
+ * In this pattern we get vertice positions and uvs
140
+ * @param face
141
+ * @param v
142
+ */
143
+ private _setDataForCurrentFaceWithPattern2;
144
+ /**
145
+ * Create triangles and push the data for each polygon for the pattern 3
146
+ * In this pattern we get vertice positions, uvs and normals
147
+ * @param face
148
+ * @param v
149
+ */
150
+ private _setDataForCurrentFaceWithPattern3;
151
+ /**
152
+ * Create triangles and push the data for each polygon for the pattern 4
153
+ * In this pattern we get vertice positions and normals
154
+ * @param face
155
+ * @param v
156
+ */
157
+ private _setDataForCurrentFaceWithPattern4;
158
+ private _setDataForCurrentFaceWithPattern5;
159
+ private _addPreviousObjMesh;
160
+ private _optimizeNormals;
161
+ private static _IsLineElement;
162
+ private static _IsObjectElement;
163
+ private static _IsGroupElement;
164
+ private static _GetZbrushMRGB;
165
+ /**
166
+ * Function used to parse an OBJ string
167
+ * @param meshesNames defines the list of meshes to load (all if not defined)
168
+ * @param data defines the OBJ string
169
+ * @param scene defines the hosting scene
170
+ * @param assetContainer defines the asset container to load data in
171
+ * @param onFileToLoadFound defines a callback that will be called if a MTL file is found
172
+ */
173
+ parse(meshesNames: any, data: string, scene: Scene, assetContainer: Nullable<AssetContainer>, onFileToLoadFound: (fileToLoad: string) => void): void;
174
+ }