@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,862 @@
1
+ import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
2
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
3
+ import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
4
+ import { Vector2, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
5
+ import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
6
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
7
+ import { VertexData } from "@babylonjs/core/Meshes/mesh.vertexData.js";
8
+ import { Logger } from "@babylonjs/core/Misc/logger.js";
9
+ /**
10
+ * Class used to load mesh data from OBJ content
11
+ */
12
+ export class SolidParser {
13
+ /**
14
+ * Creates a new SolidParser
15
+ * @param materialToUse defines the array to fill with the list of materials to use (it will be filled by the parse function)
16
+ * @param babylonMeshesArray defines the array to fill with the list of loaded meshes (it will be filled by the parse function)
17
+ * @param loadingOptions defines the loading options to use
18
+ */
19
+ constructor(materialToUse, babylonMeshesArray, loadingOptions) {
20
+ this._positions = []; //values for the positions of vertices
21
+ this._normals = []; //Values for the normals
22
+ this._uvs = []; //Values for the textures
23
+ this._colors = [];
24
+ this._extColors = []; //Extension color
25
+ this._meshesFromObj = []; //[mesh] Contains all the obj meshes
26
+ this._indicesForBabylon = []; //The list of indices for VertexData
27
+ this._wrappedPositionForBabylon = []; //The list of position in vectors
28
+ this._wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
29
+ this._wrappedColorsForBabylon = []; // Array with all color values to match with the indices
30
+ this._wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
31
+ this._tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
32
+ this._curPositionInIndices = 0;
33
+ this._hasMeshes = false; //Meshes are defined in the file
34
+ this._unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
35
+ this._unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
36
+ this._unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
37
+ this._unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
38
+ this._triangles = []; //Indices from new triangles coming from polygons
39
+ this._materialNameFromObj = ""; //The name of the current material
40
+ this._objMeshName = ""; //The name of the current obj mesh
41
+ this._increment = 1; //Id for meshes created by the multimaterial
42
+ this._isFirstMaterial = true;
43
+ this._grayColor = new Color4(0.5, 0.5, 0.5, 1);
44
+ this._hasLineData = false; //If this mesh has line segment(l) data
45
+ this._materialToUse = materialToUse;
46
+ this._babylonMeshesArray = babylonMeshesArray;
47
+ this._loadingOptions = loadingOptions;
48
+ }
49
+ /**
50
+ * Search for obj in the given array.
51
+ * This function is called to check if a couple of data already exists in an array.
52
+ *
53
+ * If found, returns the index of the founded tuple index. Returns -1 if not found
54
+ * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
55
+ * @param obj Array<number>
56
+ * @returns {boolean}
57
+ */
58
+ _isInArray(arr, obj) {
59
+ if (!arr[obj[0]]) {
60
+ arr[obj[0]] = { normals: [], idx: [] };
61
+ }
62
+ const idx = arr[obj[0]].normals.indexOf(obj[1]);
63
+ return idx === -1 ? -1 : arr[obj[0]].idx[idx];
64
+ }
65
+ _isInArrayUV(arr, obj) {
66
+ if (!arr[obj[0]]) {
67
+ arr[obj[0]] = { normals: [], idx: [], uv: [] };
68
+ }
69
+ const idx = arr[obj[0]].normals.indexOf(obj[1]);
70
+ if (idx != 1 && obj[2] === arr[obj[0]].uv[idx]) {
71
+ return arr[obj[0]].idx[idx];
72
+ }
73
+ return -1;
74
+ }
75
+ /**
76
+ * This function set the data for each triangle.
77
+ * Data are position, normals and uvs
78
+ * If a tuple of (position, normal) is not set, add the data into the corresponding array
79
+ * If the tuple already exist, add only their indice
80
+ *
81
+ * @param indicePositionFromObj Integer The index in positions array
82
+ * @param indiceUvsFromObj Integer The index in uvs array
83
+ * @param indiceNormalFromObj Integer The index in normals array
84
+ * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
85
+ * @param textureVectorFromOBJ Vector3 The value of uvs
86
+ * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
87
+ * @param positionColorsFromOBJ
88
+ */
89
+ _setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
90
+ //Check if this tuple already exists in the list of tuples
91
+ let _index;
92
+ if (this._loadingOptions.optimizeWithUV) {
93
+ _index = this._isInArrayUV(this._tuplePosNorm, [indicePositionFromObj, indiceNormalFromObj, indiceUvsFromObj]);
94
+ }
95
+ else {
96
+ _index = this._isInArray(this._tuplePosNorm, [indicePositionFromObj, indiceNormalFromObj]);
97
+ }
98
+ //If it not exists
99
+ if (_index === -1) {
100
+ //Add an new indice.
101
+ //The array of indices is only an array with his length equal to the number of triangles - 1.
102
+ //We add vertices data in this order
103
+ this._indicesForBabylon.push(this._wrappedPositionForBabylon.length);
104
+ //Push the position of vertice for Babylon
105
+ //Each element is a Vector3(x,y,z)
106
+ this._wrappedPositionForBabylon.push(positionVectorFromOBJ);
107
+ //Push the uvs for Babylon
108
+ //Each element is a Vector2(u,v)
109
+ //If the UVs are missing, set (u,v)=(0,0)
110
+ textureVectorFromOBJ = textureVectorFromOBJ ?? new Vector2(0, 0);
111
+ this._wrappedUvsForBabylon.push(textureVectorFromOBJ);
112
+ //Push the normals for Babylon
113
+ //Each element is a Vector3(x,y,z)
114
+ this._wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
115
+ if (positionColorsFromOBJ !== undefined) {
116
+ //Push the colors for Babylon
117
+ //Each element is a BABYLON.Color4(r,g,b,a)
118
+ this._wrappedColorsForBabylon.push(positionColorsFromOBJ);
119
+ }
120
+ //Add the tuple in the comparison list
121
+ this._tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
122
+ this._tuplePosNorm[indicePositionFromObj].idx.push(this._curPositionInIndices++);
123
+ if (this._loadingOptions.optimizeWithUV) {
124
+ this._tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
125
+ }
126
+ }
127
+ else {
128
+ //The tuple already exists
129
+ //Add the index of the already existing tuple
130
+ //At this index we can get the value of position, normal, color and uvs of vertex
131
+ this._indicesForBabylon.push(_index);
132
+ }
133
+ }
134
+ /**
135
+ * Transform Vector() and BABYLON.Color() objects into numbers in an array
136
+ */
137
+ _unwrapData() {
138
+ try {
139
+ //Every array has the same length
140
+ for (let l = 0; l < this._wrappedPositionForBabylon.length; l++) {
141
+ //Push the x, y, z values of each element in the unwrapped array
142
+ this._unwrappedPositionsForBabylon.push(this._wrappedPositionForBabylon[l].x * this._handednessSign, this._wrappedPositionForBabylon[l].y, this._wrappedPositionForBabylon[l].z);
143
+ this._unwrappedNormalsForBabylon.push(this._wrappedNormalsForBabylon[l].x * this._handednessSign, this._wrappedNormalsForBabylon[l].y, this._wrappedNormalsForBabylon[l].z);
144
+ this._unwrappedUVForBabylon.push(this._wrappedUvsForBabylon[l].x, this._wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
145
+ if (this._loadingOptions.importVertexColors) {
146
+ //Push the r, g, b, a values of each element in the unwrapped array
147
+ this._unwrappedColorsForBabylon.push(this._wrappedColorsForBabylon[l].r, this._wrappedColorsForBabylon[l].g, this._wrappedColorsForBabylon[l].b, this._wrappedColorsForBabylon[l].a);
148
+ }
149
+ }
150
+ // Reset arrays for the next new meshes
151
+ this._wrappedPositionForBabylon.length = 0;
152
+ this._wrappedNormalsForBabylon.length = 0;
153
+ this._wrappedUvsForBabylon.length = 0;
154
+ this._wrappedColorsForBabylon.length = 0;
155
+ this._tuplePosNorm.length = 0;
156
+ this._curPositionInIndices = 0;
157
+ }
158
+ catch (e) {
159
+ throw new Error("Unable to unwrap data while parsing OBJ data.");
160
+ }
161
+ }
162
+ /**
163
+ * Create triangles from polygons
164
+ * It is important to notice that a triangle is a polygon
165
+ * We get 5 patterns of face defined in OBJ File :
166
+ * facePattern1 = ["1","2","3","4","5","6"]
167
+ * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
168
+ * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
169
+ * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
170
+ * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
171
+ * Each pattern is divided by the same method
172
+ * @param faces Array[String] The indices of elements
173
+ * @param v Integer The variable to increment
174
+ */
175
+ _getTriangles(faces, v) {
176
+ //Work for each element of the array
177
+ for (let faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
178
+ //Add on the triangle variable the indexes to obtain triangles
179
+ this._pushTriangle(faces, faceIndex);
180
+ }
181
+ //Result obtained after 2 iterations:
182
+ //Pattern1 => triangle = ["1","2","3","1","3","4"];
183
+ //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
184
+ //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
185
+ //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
186
+ //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
187
+ }
188
+ /**
189
+ * To get color between color and extension color
190
+ * @param index Integer The index of the element in the array
191
+ * @returns value of target color
192
+ */
193
+ _getColor(index) {
194
+ if (this._loadingOptions.importVertexColors) {
195
+ return this._extColors[index] ?? this._colors[index];
196
+ }
197
+ else {
198
+ return undefined;
199
+ }
200
+ }
201
+ /**
202
+ * Create triangles and push the data for each polygon for the pattern 1
203
+ * In this pattern we get vertice positions
204
+ * @param face
205
+ * @param v
206
+ */
207
+ _setDataForCurrentFaceWithPattern1(face, v) {
208
+ //Get the indices of triangles for each polygon
209
+ this._getTriangles(face, v);
210
+ //For each element in the triangles array.
211
+ //This var could contains 1 to an infinity of triangles
212
+ for (let k = 0; k < this._triangles.length; k++) {
213
+ // Set position indice
214
+ const indicePositionFromObj = parseInt(this._triangles[k]) - 1;
215
+ this._setData(indicePositionFromObj, 0, 0, // In the pattern 1, normals and uvs are not defined
216
+ this._positions[indicePositionFromObj], // Get the vectors data
217
+ Vector2.Zero(), Vector3.Up(), // Create default vectors
218
+ this._getColor(indicePositionFromObj));
219
+ }
220
+ //Reset variable for the next line
221
+ this._triangles.length = 0;
222
+ }
223
+ /**
224
+ * Create triangles and push the data for each polygon for the pattern 2
225
+ * In this pattern we get vertice positions and uvs
226
+ * @param face
227
+ * @param v
228
+ */
229
+ _setDataForCurrentFaceWithPattern2(face, v) {
230
+ //Get the indices of triangles for each polygon
231
+ this._getTriangles(face, v);
232
+ for (let k = 0; k < this._triangles.length; k++) {
233
+ //triangle[k] = "1/1"
234
+ //Split the data for getting position and uv
235
+ const point = this._triangles[k].split("/"); // ["1", "1"]
236
+ //Set position indice
237
+ const indicePositionFromObj = parseInt(point[0]) - 1;
238
+ //Set uv indice
239
+ const indiceUvsFromObj = parseInt(point[1]) - 1;
240
+ this._setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
241
+ this._positions[indicePositionFromObj], //Get the values for each element
242
+ this._uvs[indiceUvsFromObj] ?? Vector2.Zero(), Vector3.Up(), //Default value for normals
243
+ this._getColor(indicePositionFromObj));
244
+ }
245
+ //Reset variable for the next line
246
+ this._triangles.length = 0;
247
+ }
248
+ /**
249
+ * Create triangles and push the data for each polygon for the pattern 3
250
+ * In this pattern we get vertice positions, uvs and normals
251
+ * @param face
252
+ * @param v
253
+ */
254
+ _setDataForCurrentFaceWithPattern3(face, v) {
255
+ //Get the indices of triangles for each polygon
256
+ this._getTriangles(face, v);
257
+ for (let k = 0; k < this._triangles.length; k++) {
258
+ //triangle[k] = "1/1/1"
259
+ //Split the data for getting position, uv, and normals
260
+ const point = this._triangles[k].split("/"); // ["1", "1", "1"]
261
+ // Set position indice
262
+ const indicePositionFromObj = parseInt(point[0]) - 1;
263
+ // Set uv indice
264
+ const indiceUvsFromObj = parseInt(point[1]) - 1;
265
+ // Set normal indice
266
+ const indiceNormalFromObj = parseInt(point[2]) - 1;
267
+ this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj] ?? Vector2.Zero(), this._normals[indiceNormalFromObj] ?? Vector3.Up() //Set the vector for each component
268
+ );
269
+ }
270
+ //Reset variable for the next line
271
+ this._triangles.length = 0;
272
+ }
273
+ /**
274
+ * Create triangles and push the data for each polygon for the pattern 4
275
+ * In this pattern we get vertice positions and normals
276
+ * @param face
277
+ * @param v
278
+ */
279
+ _setDataForCurrentFaceWithPattern4(face, v) {
280
+ this._getTriangles(face, v);
281
+ for (let k = 0; k < this._triangles.length; k++) {
282
+ //triangle[k] = "1//1"
283
+ //Split the data for getting position and normals
284
+ const point = this._triangles[k].split("//"); // ["1", "1"]
285
+ // We check indices, and normals
286
+ const indicePositionFromObj = parseInt(point[0]) - 1;
287
+ const indiceNormalFromObj = parseInt(point[1]) - 1;
288
+ this._setData(indicePositionFromObj, 1, //Default value for uv
289
+ indiceNormalFromObj, this._positions[indicePositionFromObj], //Get each vector of data
290
+ Vector2.Zero(), this._normals[indiceNormalFromObj], this._getColor(indicePositionFromObj));
291
+ }
292
+ //Reset variable for the next line
293
+ this._triangles.length = 0;
294
+ }
295
+ /*
296
+ * Create triangles and push the data for each polygon for the pattern 3
297
+ * In this pattern we get vertice positions, uvs and normals
298
+ * @param face
299
+ * @param v
300
+ */
301
+ _setDataForCurrentFaceWithPattern5(face, v) {
302
+ //Get the indices of triangles for each polygon
303
+ this._getTriangles(face, v);
304
+ for (let k = 0; k < this._triangles.length; k++) {
305
+ //triangle[k] = "-1/-1/-1"
306
+ //Split the data for getting position, uv, and normals
307
+ const point = this._triangles[k].split("/"); // ["-1", "-1", "-1"]
308
+ // Set position indice
309
+ const indicePositionFromObj = this._positions.length + parseInt(point[0]);
310
+ // Set uv indice
311
+ const indiceUvsFromObj = this._uvs.length + parseInt(point[1]);
312
+ // Set normal indice
313
+ const indiceNormalFromObj = this._normals.length + parseInt(point[2]);
314
+ this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj], this._normals[indiceNormalFromObj], //Set the vector for each component
315
+ this._getColor(indicePositionFromObj));
316
+ }
317
+ //Reset variable for the next line
318
+ this._triangles.length = 0;
319
+ }
320
+ _addPreviousObjMesh() {
321
+ //Check if it is not the first mesh. Otherwise we don't have data.
322
+ if (this._meshesFromObj.length > 0) {
323
+ //Get the previous mesh for applying the data about the faces
324
+ //=> in obj file, faces definition append after the name of the mesh
325
+ this._handledMesh = this._meshesFromObj[this._meshesFromObj.length - 1];
326
+ //Set the data into Array for the mesh
327
+ this._unwrapData();
328
+ if (this._loadingOptions.useLegacyBehavior) {
329
+ // Reverse tab. Otherwise face are displayed in the wrong sens
330
+ this._indicesForBabylon.reverse();
331
+ }
332
+ //Set the information for the mesh
333
+ //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
334
+ this._handledMesh.indices = this._indicesForBabylon.slice();
335
+ this._handledMesh.positions = this._unwrappedPositionsForBabylon.slice();
336
+ this._handledMesh.normals = this._unwrappedNormalsForBabylon.slice();
337
+ this._handledMesh.uvs = this._unwrappedUVForBabylon.slice();
338
+ this._handledMesh.hasLines = this._hasLineData;
339
+ if (this._loadingOptions.importVertexColors) {
340
+ this._handledMesh.colors = this._unwrappedColorsForBabylon.slice();
341
+ }
342
+ //Reset the array for the next mesh
343
+ this._indicesForBabylon.length = 0;
344
+ this._unwrappedPositionsForBabylon.length = 0;
345
+ this._unwrappedColorsForBabylon.length = 0;
346
+ this._unwrappedNormalsForBabylon.length = 0;
347
+ this._unwrappedUVForBabylon.length = 0;
348
+ this._hasLineData = false;
349
+ }
350
+ }
351
+ _optimizeNormals(mesh) {
352
+ const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
353
+ const normals = mesh.getVerticesData(VertexBuffer.NormalKind);
354
+ const mapVertices = {};
355
+ if (!positions || !normals) {
356
+ return;
357
+ }
358
+ for (let i = 0; i < positions.length / 3; i++) {
359
+ const x = positions[i * 3 + 0];
360
+ const y = positions[i * 3 + 1];
361
+ const z = positions[i * 3 + 2];
362
+ const key = x + "_" + y + "_" + z;
363
+ let lst = mapVertices[key];
364
+ if (!lst) {
365
+ lst = [];
366
+ mapVertices[key] = lst;
367
+ }
368
+ lst.push(i);
369
+ }
370
+ const normal = new Vector3();
371
+ for (const key in mapVertices) {
372
+ const lst = mapVertices[key];
373
+ if (lst.length < 2) {
374
+ continue;
375
+ }
376
+ const v0Idx = lst[0];
377
+ for (let i = 1; i < lst.length; ++i) {
378
+ const vIdx = lst[i];
379
+ normals[v0Idx * 3 + 0] += normals[vIdx * 3 + 0];
380
+ normals[v0Idx * 3 + 1] += normals[vIdx * 3 + 1];
381
+ normals[v0Idx * 3 + 2] += normals[vIdx * 3 + 2];
382
+ }
383
+ normal.copyFromFloats(normals[v0Idx * 3 + 0], normals[v0Idx * 3 + 1], normals[v0Idx * 3 + 2]);
384
+ normal.normalize();
385
+ for (let i = 0; i < lst.length; ++i) {
386
+ const vIdx = lst[i];
387
+ normals[vIdx * 3 + 0] = normal.x;
388
+ normals[vIdx * 3 + 1] = normal.y;
389
+ normals[vIdx * 3 + 2] = normal.z;
390
+ }
391
+ }
392
+ mesh.setVerticesData(VertexBuffer.NormalKind, normals);
393
+ }
394
+ static _IsLineElement(line) {
395
+ return line.startsWith("l");
396
+ }
397
+ static _IsObjectElement(line) {
398
+ return line.startsWith("o");
399
+ }
400
+ static _IsGroupElement(line) {
401
+ return line.startsWith("g");
402
+ }
403
+ static _GetZbrushMRGB(line, notParse) {
404
+ if (!line.startsWith("mrgb")) {
405
+ return null;
406
+ }
407
+ line = line.replace("mrgb", "").trim();
408
+ // if include vertex color , not load mrgb anymore
409
+ if (notParse) {
410
+ return [];
411
+ }
412
+ const regex = /[a-z0-9]/g;
413
+ const regArray = line.match(regex);
414
+ if (!regArray || regArray.length % 8 !== 0) {
415
+ return [];
416
+ }
417
+ const array = [];
418
+ for (let regIndex = 0; regIndex < regArray.length / 8; regIndex++) {
419
+ //each item is MMRRGGBB, m is material index
420
+ // const m = regArray[regIndex * 8 + 0] + regArray[regIndex * 8 + 1];
421
+ const r = regArray[regIndex * 8 + 2] + regArray[regIndex * 8 + 3];
422
+ const g = regArray[regIndex * 8 + 4] + regArray[regIndex * 8 + 5];
423
+ const b = regArray[regIndex * 8 + 6] + regArray[regIndex * 8 + 7];
424
+ array.push(new Color4(parseInt(r, 16) / 255, parseInt(g, 16) / 255, parseInt(b, 16) / 255, 1));
425
+ }
426
+ return array;
427
+ }
428
+ /**
429
+ * Function used to parse an OBJ string
430
+ * @param meshesNames defines the list of meshes to load (all if not defined)
431
+ * @param data defines the OBJ string
432
+ * @param scene defines the hosting scene
433
+ * @param assetContainer defines the asset container to load data in
434
+ * @param onFileToLoadFound defines a callback that will be called if a MTL file is found
435
+ */
436
+ parse(meshesNames, data, scene, assetContainer, onFileToLoadFound) {
437
+ //Move Santitize here to forbid delete zbrush data
438
+ // Sanitize data
439
+ data = data.replace(/#MRGB/g, "mrgb");
440
+ data = data.replace(/#.*$/gm, "").trim();
441
+ if (this._loadingOptions.useLegacyBehavior) {
442
+ this._pushTriangle = (faces, faceIndex) => this._triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
443
+ this._handednessSign = 1;
444
+ }
445
+ else if (scene.useRightHandedSystem) {
446
+ this._pushTriangle = (faces, faceIndex) => this._triangles.push(faces[0], faces[faceIndex + 1], faces[faceIndex]);
447
+ this._handednessSign = 1;
448
+ }
449
+ else {
450
+ this._pushTriangle = (faces, faceIndex) => this._triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
451
+ this._handednessSign = -1;
452
+ }
453
+ // Split the file into lines
454
+ // Preprocess line data
455
+ const linesOBJ = data.split("\n");
456
+ const lineLines = [];
457
+ let currentGroup = [];
458
+ lineLines.push(currentGroup);
459
+ for (let i = 0; i < linesOBJ.length; i++) {
460
+ const line = linesOBJ[i].trim().replace(/\s\s/g, " ");
461
+ // Comment or newLine
462
+ if (line.length === 0 || line.charAt(0) === "#") {
463
+ continue;
464
+ }
465
+ if (SolidParser._IsGroupElement(line) || SolidParser._IsObjectElement(line)) {
466
+ currentGroup = [];
467
+ lineLines.push(currentGroup);
468
+ }
469
+ if (SolidParser._IsLineElement(line)) {
470
+ const lineValues = line.split(" ");
471
+ // create line elements with two vertices only
472
+ for (let i = 1; i < lineValues.length - 1; i++) {
473
+ currentGroup.push(`l ${lineValues[i]} ${lineValues[i + 1]}`);
474
+ }
475
+ }
476
+ else {
477
+ currentGroup.push(line);
478
+ }
479
+ }
480
+ const lines = lineLines.flat();
481
+ // Look at each line
482
+ for (let i = 0; i < lines.length; i++) {
483
+ const line = lines[i].trim().replace(/\s\s/g, " ");
484
+ let result;
485
+ // Comment or newLine
486
+ if (line.length === 0 || line.charAt(0) === "#") {
487
+ continue;
488
+ }
489
+ else if (SolidParser.VertexPattern.test(line)) {
490
+ //Get information about one position possible for the vertices
491
+ result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
492
+ // Value of result with line: "v 1.0 2.0 3.0"
493
+ // ["v", "1.0", "2.0", "3.0"]
494
+ // Create a Vector3 with the position x, y, z
495
+ this._positions.push(new Vector3(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
496
+ if (this._loadingOptions.importVertexColors) {
497
+ if (result.length >= 7) {
498
+ const r = parseFloat(result[4]);
499
+ const g = parseFloat(result[5]);
500
+ const b = parseFloat(result[6]);
501
+ this._colors.push(new Color4(r > 1 ? r / 255 : r, g > 1 ? g / 255 : g, b > 1 ? b / 255 : b, result.length === 7 || result[7] === undefined ? 1 : parseFloat(result[7])));
502
+ }
503
+ else {
504
+ // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
505
+ this._colors.push(this._grayColor);
506
+ }
507
+ }
508
+ }
509
+ else if ((result = SolidParser.NormalPattern.exec(line)) !== null) {
510
+ //Create a Vector3 with the normals x, y, z
511
+ //Value of result
512
+ // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
513
+ //Add the Vector in the list of normals
514
+ this._normals.push(new Vector3(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
515
+ }
516
+ else if ((result = SolidParser.UVPattern.exec(line)) !== null) {
517
+ //Create a Vector2 with the normals u, v
518
+ //Value of result
519
+ // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
520
+ //Add the Vector in the list of uvs
521
+ this._uvs.push(new Vector2(parseFloat(result[1]) * this._loadingOptions.UVScaling.x, parseFloat(result[2]) * this._loadingOptions.UVScaling.y));
522
+ //Identify patterns of faces
523
+ //Face could be defined in different type of pattern
524
+ }
525
+ else if ((result = SolidParser.FacePattern3.exec(line)) !== null) {
526
+ //Value of result:
527
+ //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
528
+ //Set the data for this face
529
+ this._setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
530
+ 1);
531
+ }
532
+ else if ((result = SolidParser.FacePattern4.exec(line)) !== null) {
533
+ //Value of result:
534
+ //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
535
+ //Set the data for this face
536
+ this._setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
537
+ 1);
538
+ }
539
+ else if ((result = SolidParser.FacePattern5.exec(line)) !== null) {
540
+ //Value of result:
541
+ //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
542
+ //Set the data for this face
543
+ this._setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
544
+ 1);
545
+ }
546
+ else if ((result = SolidParser.FacePattern2.exec(line)) !== null) {
547
+ //Value of result:
548
+ //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
549
+ //Set the data for this face
550
+ this._setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
551
+ 1);
552
+ }
553
+ else if ((result = SolidParser.FacePattern1.exec(line)) !== null) {
554
+ //Value of result
555
+ //["f 1 2 3", "1 2 3"...]
556
+ //Set the data for this face
557
+ this._setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
558
+ 1);
559
+ // Define a mesh or an object
560
+ // Each time this keyword is analyzed, create a new Object with all data for creating a babylonMesh
561
+ }
562
+ else if ((result = SolidParser.LinePattern1.exec(line)) !== null) {
563
+ //Value of result
564
+ //["l 1 2"]
565
+ //Set the data for this face
566
+ this._setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2"]
567
+ 0);
568
+ this._hasLineData = true;
569
+ // Define a mesh or an object
570
+ // Each time this keyword is analyzed, create a new Object with all data for creating a babylonMesh
571
+ }
572
+ else if ((result = SolidParser.LinePattern2.exec(line)) !== null) {
573
+ //Value of result
574
+ //["l 1/1 2/2"]
575
+ //Set the data for this face
576
+ this._setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2"]
577
+ 0);
578
+ this._hasLineData = true;
579
+ // Define a mesh or an object
580
+ // Each time this keyword is analyzed, create a new Object with all data for creating a babylonMesh
581
+ }
582
+ else if ((result = SolidParser._GetZbrushMRGB(line, !this._loadingOptions.importVertexColors))) {
583
+ for (const element of result) {
584
+ this._extColors.push(element);
585
+ }
586
+ }
587
+ else if ((result = SolidParser.LinePattern3.exec(line)) !== null) {
588
+ //Value of result
589
+ //["l 1/1/1 2/2/2"]
590
+ //Set the data for this face
591
+ this._setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2"]
592
+ 0);
593
+ this._hasLineData = true;
594
+ // Define a mesh or an object
595
+ // Each time this keyword is analyzed, create a new Object with all data for creating a babylonMesh
596
+ }
597
+ else if (SolidParser.GroupDescriptor.test(line) || SolidParser.ObjectDescriptor.test(line)) {
598
+ // Create a new mesh corresponding to the name of the group.
599
+ // Definition of the mesh
600
+ const objMesh = {
601
+ name: line.substring(2).trim(), //Set the name of the current obj mesh
602
+ indices: null,
603
+ positions: null,
604
+ normals: null,
605
+ uvs: null,
606
+ colors: null,
607
+ materialName: this._materialNameFromObj,
608
+ isObject: SolidParser.ObjectDescriptor.test(line),
609
+ };
610
+ this._addPreviousObjMesh();
611
+ //Push the last mesh created with only the name
612
+ this._meshesFromObj.push(objMesh);
613
+ //Set this variable to indicate that now meshesFromObj has objects defined inside
614
+ this._hasMeshes = true;
615
+ this._isFirstMaterial = true;
616
+ this._increment = 1;
617
+ //Keyword for applying a material
618
+ }
619
+ else if (SolidParser.UseMtlDescriptor.test(line)) {
620
+ //Get the name of the material
621
+ this._materialNameFromObj = line.substring(7).trim();
622
+ //If this new material is in the same mesh
623
+ if (!this._isFirstMaterial || !this._hasMeshes) {
624
+ //Set the data for the previous mesh
625
+ this._addPreviousObjMesh();
626
+ //Create a new mesh
627
+ const objMesh =
628
+ //Set the name of the current obj mesh
629
+ {
630
+ name: (this._objMeshName || "mesh") + "_mm" + this._increment.toString(), //Set the name of the current obj mesh
631
+ indices: null,
632
+ positions: null,
633
+ normals: null,
634
+ uvs: null,
635
+ colors: null,
636
+ materialName: this._materialNameFromObj,
637
+ isObject: false,
638
+ };
639
+ this._increment++;
640
+ //If meshes are already defined
641
+ this._meshesFromObj.push(objMesh);
642
+ this._hasMeshes = true;
643
+ }
644
+ //Set the material name if the previous line define a mesh
645
+ if (this._hasMeshes && this._isFirstMaterial) {
646
+ //Set the material name to the previous mesh (1 material per mesh)
647
+ this._meshesFromObj[this._meshesFromObj.length - 1].materialName = this._materialNameFromObj;
648
+ this._isFirstMaterial = false;
649
+ }
650
+ // Keyword for loading the mtl file
651
+ }
652
+ else if (SolidParser.MtlLibGroupDescriptor.test(line)) {
653
+ // Get the name of mtl file
654
+ onFileToLoadFound(line.substring(7).trim());
655
+ // Apply smoothing
656
+ }
657
+ else if (SolidParser.SmoothDescriptor.test(line)) {
658
+ // smooth shading => apply smoothing
659
+ // Today I don't know it work with babylon and with obj.
660
+ // With the obj file an integer is set
661
+ }
662
+ else {
663
+ //If there is another possibility
664
+ Logger.Log("Unhandled expression at line : " + line);
665
+ }
666
+ }
667
+ // At the end of the file, add the last mesh into the meshesFromObj array
668
+ if (this._hasMeshes) {
669
+ // Set the data for the last mesh
670
+ this._handledMesh = this._meshesFromObj[this._meshesFromObj.length - 1];
671
+ if (this._loadingOptions.useLegacyBehavior) {
672
+ //Reverse indices for displaying faces in the good sense
673
+ this._indicesForBabylon.reverse();
674
+ }
675
+ //Get the good array
676
+ this._unwrapData();
677
+ //Set array
678
+ this._handledMesh.indices = this._indicesForBabylon;
679
+ this._handledMesh.positions = this._unwrappedPositionsForBabylon;
680
+ this._handledMesh.normals = this._unwrappedNormalsForBabylon;
681
+ this._handledMesh.uvs = this._unwrappedUVForBabylon;
682
+ this._handledMesh.hasLines = this._hasLineData;
683
+ if (this._loadingOptions.importVertexColors) {
684
+ this._handledMesh.colors = this._unwrappedColorsForBabylon;
685
+ }
686
+ }
687
+ // If any o or g keyword not found, create a mesh with a random id
688
+ if (!this._hasMeshes) {
689
+ let newMaterial = null;
690
+ if (this._indicesForBabylon.length) {
691
+ if (this._loadingOptions.useLegacyBehavior) {
692
+ // reverse tab of indices
693
+ this._indicesForBabylon.reverse();
694
+ }
695
+ //Get positions normals uvs
696
+ this._unwrapData();
697
+ }
698
+ else {
699
+ // There is no indices in the file. We will have to switch to point cloud rendering
700
+ for (const pos of this._positions) {
701
+ this._unwrappedPositionsForBabylon.push(pos.x, pos.y, pos.z);
702
+ }
703
+ if (this._normals.length) {
704
+ for (const normal of this._normals) {
705
+ this._unwrappedNormalsForBabylon.push(normal.x, normal.y, normal.z);
706
+ }
707
+ }
708
+ if (this._uvs.length) {
709
+ for (const uv of this._uvs) {
710
+ this._unwrappedUVForBabylon.push(uv.x, uv.y);
711
+ }
712
+ }
713
+ if (this._extColors.length) {
714
+ for (const color of this._extColors) {
715
+ this._unwrappedColorsForBabylon.push(color.r, color.g, color.b, color.a);
716
+ }
717
+ }
718
+ else {
719
+ if (this._colors.length) {
720
+ for (const color of this._colors) {
721
+ this._unwrappedColorsForBabylon.push(color.r, color.g, color.b, color.a);
722
+ }
723
+ }
724
+ }
725
+ if (!this._materialNameFromObj) {
726
+ // Create a material with point cloud on
727
+ newMaterial = new StandardMaterial(Geometry.RandomId(), scene);
728
+ newMaterial.pointsCloud = true;
729
+ this._materialNameFromObj = newMaterial.name;
730
+ if (!this._normals.length) {
731
+ newMaterial.disableLighting = true;
732
+ newMaterial.emissiveColor = Color3.White();
733
+ }
734
+ }
735
+ }
736
+ //Set data for one mesh
737
+ this._meshesFromObj.push({
738
+ name: Geometry.RandomId(),
739
+ indices: this._indicesForBabylon,
740
+ positions: this._unwrappedPositionsForBabylon,
741
+ colors: this._unwrappedColorsForBabylon,
742
+ normals: this._unwrappedNormalsForBabylon,
743
+ uvs: this._unwrappedUVForBabylon,
744
+ materialName: this._materialNameFromObj,
745
+ directMaterial: newMaterial,
746
+ isObject: true,
747
+ hasLines: this._hasLineData,
748
+ });
749
+ }
750
+ //Set data for each mesh
751
+ for (let j = 0; j < this._meshesFromObj.length; j++) {
752
+ //check meshesNames (stlFileLoader)
753
+ if (meshesNames && this._meshesFromObj[j].name) {
754
+ if (meshesNames instanceof Array) {
755
+ if (meshesNames.indexOf(this._meshesFromObj[j].name) === -1) {
756
+ continue;
757
+ }
758
+ }
759
+ else {
760
+ if (this._meshesFromObj[j].name !== meshesNames) {
761
+ continue;
762
+ }
763
+ }
764
+ }
765
+ //Get the current mesh
766
+ //Set the data with VertexBuffer for each mesh
767
+ this._handledMesh = this._meshesFromObj[j];
768
+ //Create a Mesh with the name of the obj mesh
769
+ scene._blockEntityCollection = !!assetContainer;
770
+ const babylonMesh = new Mesh(this._meshesFromObj[j].name, scene);
771
+ babylonMesh._parentContainer = assetContainer;
772
+ scene._blockEntityCollection = false;
773
+ this._handledMesh._babylonMesh = babylonMesh;
774
+ // If this is a group mesh, it should have an object mesh as a parent. So look for the first object mesh that appears before it.
775
+ if (!this._handledMesh.isObject) {
776
+ for (let k = j - 1; k >= 0; --k) {
777
+ if (this._meshesFromObj[k].isObject && this._meshesFromObj[k]._babylonMesh) {
778
+ babylonMesh.parent = this._meshesFromObj[k]._babylonMesh;
779
+ break;
780
+ }
781
+ }
782
+ }
783
+ //Push the name of the material to an array
784
+ //This is indispensable for the importMesh function
785
+ this._materialToUse.push(this._meshesFromObj[j].materialName);
786
+ //If the mesh is a line mesh
787
+ if (this._handledMesh.hasLines) {
788
+ babylonMesh._internalMetadata ?? (babylonMesh._internalMetadata = {});
789
+ babylonMesh._internalMetadata["_isLine"] = true; //this is a line mesh
790
+ }
791
+ if (this._handledMesh.positions?.length === 0) {
792
+ //Push the mesh into an array
793
+ this._babylonMeshesArray.push(babylonMesh);
794
+ continue;
795
+ }
796
+ const vertexData = new VertexData(); //The container for the values
797
+ //Set the data for the babylonMesh
798
+ vertexData.uvs = this._handledMesh.uvs;
799
+ vertexData.indices = this._handledMesh.indices;
800
+ vertexData.positions = this._handledMesh.positions;
801
+ if (this._loadingOptions.computeNormals) {
802
+ const normals = new Array();
803
+ VertexData.ComputeNormals(this._handledMesh.positions, this._handledMesh.indices, normals);
804
+ vertexData.normals = normals;
805
+ }
806
+ else {
807
+ vertexData.normals = this._handledMesh.normals;
808
+ }
809
+ if (this._loadingOptions.importVertexColors) {
810
+ vertexData.colors = this._handledMesh.colors;
811
+ }
812
+ //Set the data from the VertexBuffer to the current Mesh
813
+ vertexData.applyToMesh(babylonMesh);
814
+ if (this._loadingOptions.invertY) {
815
+ babylonMesh.scaling.y *= -1;
816
+ }
817
+ if (this._loadingOptions.optimizeNormals) {
818
+ this._optimizeNormals(babylonMesh);
819
+ }
820
+ //Push the mesh into an array
821
+ this._babylonMeshesArray.push(babylonMesh);
822
+ if (this._handledMesh.directMaterial) {
823
+ babylonMesh.material = this._handledMesh.directMaterial;
824
+ }
825
+ }
826
+ }
827
+ }
828
+ // Descriptor
829
+ /** Object descriptor */
830
+ SolidParser.ObjectDescriptor = /^o/;
831
+ /** Group descriptor */
832
+ SolidParser.GroupDescriptor = /^g/;
833
+ /** Material lib descriptor */
834
+ SolidParser.MtlLibGroupDescriptor = /^mtllib /;
835
+ /** Use a material descriptor */
836
+ SolidParser.UseMtlDescriptor = /^usemtl /;
837
+ /** Smooth descriptor */
838
+ SolidParser.SmoothDescriptor = /^s /;
839
+ // Patterns
840
+ /** Pattern used to detect a vertex */
841
+ SolidParser.VertexPattern = /^v(\s+[\d|.|+|\-|e|E]+){3,7}/;
842
+ /** Pattern used to detect a normal */
843
+ SolidParser.NormalPattern = /^vn(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/;
844
+ /** Pattern used to detect a UV set */
845
+ SolidParser.UVPattern = /^vt(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/;
846
+ /** Pattern used to detect a first kind of face (f vertex vertex vertex) */
847
+ SolidParser.FacePattern1 = /^f\s+(([\d]{1,}[\s]?){3,})+/;
848
+ /** Pattern used to detect a second kind of face (f vertex/uvs vertex/uvs vertex/uvs) */
849
+ SolidParser.FacePattern2 = /^f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
850
+ /** Pattern used to detect a third kind of face (f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal) */
851
+ SolidParser.FacePattern3 = /^f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
852
+ /** Pattern used to detect a fourth kind of face (f vertex//normal vertex//normal vertex//normal)*/
853
+ SolidParser.FacePattern4 = /^f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
854
+ /** Pattern used to detect a fifth kind of face (f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal) */
855
+ SolidParser.FacePattern5 = /^f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
856
+ /** Pattern used to detect a line(l vertex vertex) */
857
+ SolidParser.LinePattern1 = /^l\s+(([\d]{1,}[\s]?){2,})+/;
858
+ /** Pattern used to detect a second kind of line (l vertex/uvs vertex/uvs) */
859
+ SolidParser.LinePattern2 = /^l\s+((([\d]{1,}\/[\d]{1,}[\s]?){2,})+)/;
860
+ /** Pattern used to detect a third kind of line (l vertex/uvs/normal vertex/uvs/normal) */
861
+ SolidParser.LinePattern3 = /^l\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){2,})+)/;
862
+ //# sourceMappingURL=solidParser.js.map