@babylonjs/loaders 5.0.0-beta.9 → 5.0.0-rc.10

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 (173) hide show
  1. package/OBJ/index.d.ts +4 -4
  2. package/OBJ/index.js +4 -4
  3. package/OBJ/index.js.map +1 -1
  4. package/OBJ/mtlFileLoader.d.ts +41 -40
  5. package/OBJ/mtlFileLoader.js +232 -221
  6. package/OBJ/mtlFileLoader.js.map +1 -1
  7. package/OBJ/objFileLoader.d.ts +126 -133
  8. package/OBJ/objFileLoader.js +296 -300
  9. package/OBJ/objFileLoader.js.map +1 -1
  10. package/OBJ/objLoadingOptions.d.ts +43 -43
  11. package/OBJ/objLoadingOptions.js +1 -1
  12. package/OBJ/objLoadingOptions.js.map +1 -1
  13. package/OBJ/solidParser.d.ts +154 -153
  14. package/OBJ/solidParser.js +693 -699
  15. package/OBJ/solidParser.js.map +1 -1
  16. package/STL/index.d.ts +1 -1
  17. package/STL/index.js +1 -1
  18. package/STL/index.js.map +1 -1
  19. package/STL/stlFileLoader.d.ts +64 -71
  20. package/STL/stlFileLoader.js +233 -239
  21. package/STL/stlFileLoader.js.map +1 -1
  22. package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
  23. package/glTF/1.0/glTFBinaryExtension.js +60 -61
  24. package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
  25. package/glTF/1.0/glTFLoader.d.ts +136 -106
  26. package/glTF/1.0/glTFLoader.js +1814 -1696
  27. package/glTF/1.0/glTFLoader.js.map +1 -1
  28. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
  29. package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
  30. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  31. package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
  32. package/glTF/1.0/glTFLoaderUtils.js +250 -232
  33. package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
  34. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
  35. package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -127
  36. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
  37. package/glTF/1.0/index.d.ts +5 -5
  38. package/glTF/1.0/index.js +5 -5
  39. package/glTF/1.0/index.js.map +1 -1
  40. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -36
  41. package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -110
  42. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  43. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -27
  44. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -79
  45. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  46. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -27
  47. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -42
  48. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  49. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -21
  50. package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -32
  51. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  52. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -32
  53. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -55
  54. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -31
  56. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -101
  57. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  58. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -28
  59. package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -81
  60. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  61. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -31
  62. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -86
  63. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  64. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -30
  65. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -45
  66. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  67. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -34
  68. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -54
  69. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  70. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -30
  71. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -72
  72. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  73. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -31
  74. package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -76
  75. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  76. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -30
  77. package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -66
  78. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  79. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -31
  80. package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -76
  81. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  82. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -30
  83. package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -277
  84. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  85. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -30
  86. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -65
  87. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  88. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -76
  89. package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -243
  90. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  91. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -31
  92. package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -78
  93. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  94. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -19
  95. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -21
  96. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  97. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -21
  98. package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -32
  99. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  100. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -25
  101. package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -53
  102. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  103. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -29
  104. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -46
  105. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  106. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -38
  107. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -216
  108. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  109. package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -75
  110. package/glTF/2.0/Extensions/MSFT_lod.js +369 -333
  111. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  112. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
  113. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
  114. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  115. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
  116. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
  117. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  118. package/glTF/2.0/Extensions/index.d.ts +26 -26
  119. package/glTF/2.0/Extensions/index.js +26 -26
  120. package/glTF/2.0/Extensions/index.js.map +1 -1
  121. package/glTF/2.0/glTFLoader.d.ts +406 -357
  122. package/glTF/2.0/glTFLoader.js +2366 -2249
  123. package/glTF/2.0/glTFLoader.js.map +1 -1
  124. package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
  125. package/glTF/2.0/glTFLoaderExtension.js +1 -1
  126. package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
  127. package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -209
  128. package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
  129. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  130. package/glTF/2.0/index.d.ts +4 -4
  131. package/glTF/2.0/index.js +5 -4
  132. package/glTF/2.0/index.js.map +1 -1
  133. package/glTF/glTFFileLoader.d.ts +433 -368
  134. package/glTF/glTFFileLoader.js +927 -869
  135. package/glTF/glTFFileLoader.js.map +1 -1
  136. package/glTF/glTFValidation.d.ts +29 -29
  137. package/glTF/glTFValidation.js +123 -121
  138. package/glTF/glTFValidation.js.map +1 -1
  139. package/glTF/index.d.ts +5 -5
  140. package/glTF/index.js +6 -5
  141. package/glTF/index.js.map +1 -1
  142. package/index.d.ts +3 -3
  143. package/index.js +4 -3
  144. package/index.js.map +1 -1
  145. package/legacy/legacy-glTF.d.ts +2 -2
  146. package/legacy/legacy-glTF.js +18 -18
  147. package/legacy/legacy-glTF.js.map +1 -1
  148. package/legacy/legacy-glTF1.d.ts +2 -2
  149. package/legacy/legacy-glTF1.js +15 -14
  150. package/legacy/legacy-glTF1.js.map +1 -1
  151. package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
  152. package/legacy/legacy-glTF1FileLoader.js +3 -2
  153. package/legacy/legacy-glTF1FileLoader.js.map +1 -1
  154. package/legacy/legacy-glTF2.d.ts +2 -2
  155. package/legacy/legacy-glTF2.js +33 -32
  156. package/legacy/legacy-glTF2.js.map +1 -1
  157. package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
  158. package/legacy/legacy-glTF2FileLoader.js +3 -2
  159. package/legacy/legacy-glTF2FileLoader.js.map +1 -1
  160. package/legacy/legacy-glTFFileLoader.d.ts +3 -3
  161. package/legacy/legacy-glTFFileLoader.js +4 -3
  162. package/legacy/legacy-glTFFileLoader.js.map +1 -1
  163. package/legacy/legacy-objFileLoader.d.ts +1 -1
  164. package/legacy/legacy-objFileLoader.js +13 -12
  165. package/legacy/legacy-objFileLoader.js.map +1 -1
  166. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  167. package/legacy/legacy-stlFileLoader.js +13 -12
  168. package/legacy/legacy-stlFileLoader.js.map +1 -1
  169. package/legacy/legacy.d.ts +6 -6
  170. package/legacy/legacy.js +8 -6
  171. package/legacy/legacy.js.map +1 -1
  172. package/package.json +23 -198
  173. package/readme.md +2 -2
package/OBJ/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./mtlFileLoader";
2
- export * from "./objLoadingOptions";
3
- export * from "./solidParser";
4
- export * from "./objFileLoader";
1
+ export * from "./mtlFileLoader";
2
+ export * from "./objLoadingOptions";
3
+ export * from "./solidParser";
4
+ export * from "./objFileLoader";
package/OBJ/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./mtlFileLoader.js";
2
- export * from "./objLoadingOptions.js";
3
- export * from "./solidParser.js";
4
- export * from "./objFileLoader.js";
1
+ export * from "./mtlFileLoader.js";
2
+ export * from "./objLoadingOptions.js";
3
+ export * from "./solidParser.js";
4
+ export * from "./objFileLoader.js";
5
5
  //# sourceMappingURL=index.js.map
package/OBJ/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../sourceES6/loaders/src/OBJ/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./mtlFileLoader\";\r\nexport * from \"./objLoadingOptions\";\r\nexport * from \"./solidParser\";\r\nexport * from \"./objFileLoader\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./mtlFileLoader\";\r\nexport * from \"./objLoadingOptions\";\r\nexport * from \"./solidParser\";\r\nexport * from \"./objFileLoader\";\r\n"]}
@@ -1,40 +1,41 @@
1
- import { Nullable } from "@babylonjs/core/types";
2
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
3
- import { Scene } from "@babylonjs/core/scene";
4
- import { AssetContainer } from "@babylonjs/core/assetContainer";
5
- /**
6
- * Class reading and parsing the MTL file bundled with the obj file.
7
- */
8
- export declare class MTLFileLoader {
9
- /**
10
- * Invert Y-Axis of referenced textures on load
11
- */
12
- static INVERT_TEXTURE_Y: boolean;
13
- /**
14
- * All material loaded from the mtl will be set here
15
- */
16
- materials: StandardMaterial[];
17
- /**
18
- * This function will read the mtl file and create each material described inside
19
- * This function could be improve by adding :
20
- * -some component missing (Ni, Tf...)
21
- * -including the specific options available
22
- *
23
- * @param scene defines the scene the material will be created in
24
- * @param data defines the mtl data to parse
25
- * @param rootUrl defines the rooturl to use in order to load relative dependencies
26
- * @param assetContainer defines the asset container to store the material in (can be null)
27
- */
28
- parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void;
29
- /**
30
- * Gets the texture for the material.
31
- *
32
- * If the material is imported from input file,
33
- * We sanitize the url to ensure it takes the textre from aside the material.
34
- *
35
- * @param rootUrl The root url to load from
36
- * @param value The value stored in the mtl
37
- * @return The Texture
38
- */
39
- private static _getTexture;
40
- }
1
+ import type { Nullable } from "@babylonjs/core/types.js";
2
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
3
+ import type { Scene } from "@babylonjs/core/scene.js";
4
+ import type { AssetContainer } from "@babylonjs/core/assetContainer.js";
5
+ /**
6
+ * Class reading and parsing the MTL file bundled with the obj file.
7
+ */
8
+ export declare class MTLFileLoader {
9
+ /**
10
+ * Invert Y-Axis of referenced textures on load
11
+ */
12
+ static INVERT_TEXTURE_Y: boolean;
13
+ /**
14
+ * All material loaded from the mtl will be set here
15
+ */
16
+ materials: StandardMaterial[];
17
+ /**
18
+ * This function will read the mtl file and create each material described inside
19
+ * This function could be improve by adding :
20
+ * -some component missing (Ni, Tf...)
21
+ * -including the specific options available
22
+ *
23
+ * @param scene defines the scene the material will be created in
24
+ * @param data defines the mtl data to parse
25
+ * @param rootUrl defines the rooturl to use in order to load relative dependencies
26
+ * @param assetContainer defines the asset container to store the material in (can be null)
27
+ */
28
+ parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void;
29
+ /**
30
+ * Gets the texture for the material.
31
+ *
32
+ * If the material is imported from input file,
33
+ * We sanitize the url to ensure it takes the texture from aside the material.
34
+ *
35
+ * @param rootUrl The root url to load from
36
+ * @param value The value stored in the mtl
37
+ * @param scene
38
+ * @return The Texture
39
+ */
40
+ private static _GetTexture;
41
+ }
@@ -1,222 +1,233 @@
1
- import { Color3 } from '@babylonjs/core/Maths/math.color.js';
2
- import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
3
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
4
- /**
5
- * Class reading and parsing the MTL file bundled with the obj file.
6
- */
7
- var MTLFileLoader = /** @class */ (function () {
8
- function MTLFileLoader() {
9
- /**
10
- * All material loaded from the mtl will be set here
11
- */
12
- this.materials = [];
13
- }
14
- /**
15
- * This function will read the mtl file and create each material described inside
16
- * This function could be improve by adding :
17
- * -some component missing (Ni, Tf...)
18
- * -including the specific options available
19
- *
20
- * @param scene defines the scene the material will be created in
21
- * @param data defines the mtl data to parse
22
- * @param rootUrl defines the rooturl to use in order to load relative dependencies
23
- * @param assetContainer defines the asset container to store the material in (can be null)
24
- */
25
- MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl, assetContainer) {
26
- if (data instanceof ArrayBuffer) {
27
- return;
28
- }
29
- //Split the lines from the file
30
- var lines = data.split('\n');
31
- //Space char
32
- var delimiter_pattern = /\s+/;
33
- //Array with RGB colors
34
- var color;
35
- //New material
36
- var material = null;
37
- //Look at each line
38
- for (var i = 0; i < lines.length; i++) {
39
- var line = lines[i].trim();
40
- // Blank line or comment
41
- if (line.length === 0 || line.charAt(0) === '#') {
42
- continue;
43
- }
44
- //Get the first parameter (keyword)
45
- var pos = line.indexOf(' ');
46
- var key = (pos >= 0) ? line.substring(0, pos) : line;
47
- key = key.toLowerCase();
48
- //Get the data following the key
49
- var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
50
- //This mtl keyword will create the new material
51
- if (key === "newmtl") {
52
- //Check if it is the first material.
53
- // Materials specifications are described after this keyword.
54
- if (material) {
55
- //Add the previous material in the material array.
56
- this.materials.push(material);
57
- }
58
- //Create a new material.
59
- // value is the name of the material read in the mtl file
60
- scene._blockEntityCollection = !!assetContainer;
61
- material = new StandardMaterial(value, scene);
62
- material._parentContainer = assetContainer;
63
- scene._blockEntityCollection = false;
64
- }
65
- else if (key === "kd" && material) {
66
- // Diffuse color (color under white light) using RGB values
67
- //value = "r g b"
68
- color = value.split(delimiter_pattern, 3).map(parseFloat);
69
- //color = [r,g,b]
70
- //Set tghe color into the material
71
- material.diffuseColor = Color3.FromArray(color);
72
- }
73
- else if (key === "ka" && material) {
74
- // Ambient color (color under shadow) using RGB values
75
- //value = "r g b"
76
- color = value.split(delimiter_pattern, 3).map(parseFloat);
77
- //color = [r,g,b]
78
- //Set tghe color into the material
79
- material.ambientColor = Color3.FromArray(color);
80
- }
81
- else if (key === "ks" && material) {
82
- // Specular color (color when light is reflected from shiny surface) using RGB values
83
- //value = "r g b"
84
- color = value.split(delimiter_pattern, 3).map(parseFloat);
85
- //color = [r,g,b]
86
- //Set the color into the material
87
- material.specularColor = Color3.FromArray(color);
88
- }
89
- else if (key === "ke" && material) {
90
- // Emissive color using RGB values
91
- color = value.split(delimiter_pattern, 3).map(parseFloat);
92
- material.emissiveColor = Color3.FromArray(color);
93
- }
94
- else if (key === "ns" && material) {
95
- //value = "Integer"
96
- material.specularPower = parseFloat(value);
97
- }
98
- else if (key === "d" && material) {
99
- //d is dissolve for current material. It mean alpha for BABYLON
100
- material.alpha = parseFloat(value);
101
- //Texture
102
- //This part can be improved by adding the possible options of texture
103
- }
104
- else if (key === "map_ka" && material) {
105
- // ambient texture map with a loaded image
106
- //We must first get the folder of the image
107
- material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
108
- }
109
- else if (key === "map_kd" && material) {
110
- // Diffuse texture map with a loaded image
111
- material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
112
- }
113
- else if (key === "map_ks" && material) {
114
- // Specular texture map with a loaded image
115
- //We must first get the folder of the image
116
- material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
117
- }
118
- else if (key === "map_ns") {
119
- //Specular
120
- //Specular highlight component
121
- //We must first get the folder of the image
122
- //
123
- //Not supported by BABYLON
124
- //
125
- // continue;
126
- }
127
- else if (key === "map_bump" && material) {
128
- //The bump texture
129
- material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
130
- }
131
- else if (key === "map_d" && material) {
132
- // The dissolve of the material
133
- material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
134
- //Options for illumination
135
- }
136
- else if (key === "illum") {
137
- //Illumination
138
- if (value === "0") {
139
- //That mean Kd == Kd
140
- }
141
- else if (value === "1") {
142
- //Color on and Ambient on
143
- }
144
- else if (value === "2") {
145
- //Highlight on
146
- }
147
- else if (value === "3") {
148
- //Reflection on and Ray trace on
149
- }
150
- else if (value === "4") {
151
- //Transparency: Glass on, Reflection: Ray trace on
152
- }
153
- else if (value === "5") {
154
- //Reflection: Fresnel on and Ray trace on
155
- }
156
- else if (value === "6") {
157
- //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
158
- }
159
- else if (value === "7") {
160
- //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
161
- }
162
- else if (value === "8") {
163
- //Reflection on and Ray trace off
164
- }
165
- else if (value === "9") {
166
- //Transparency: Glass on, Reflection: Ray trace off
167
- }
168
- else if (value === "10") {
169
- //Casts shadows onto invisible surfaces
170
- }
171
- }
172
- else {
173
- // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
174
- }
175
- }
176
- //At the end of the file, add the last material
177
- if (material) {
178
- this.materials.push(material);
179
- }
180
- };
181
- /**
182
- * Gets the texture for the material.
183
- *
184
- * If the material is imported from input file,
185
- * We sanitize the url to ensure it takes the textre from aside the material.
186
- *
187
- * @param rootUrl The root url to load from
188
- * @param value The value stored in the mtl
189
- * @return The Texture
190
- */
191
- MTLFileLoader._getTexture = function (rootUrl, value, scene) {
192
- if (!value) {
193
- return null;
194
- }
195
- var url = rootUrl;
196
- // Load from input file.
197
- if (rootUrl === "file:") {
198
- var lastDelimiter = value.lastIndexOf("\\");
199
- if (lastDelimiter === -1) {
200
- lastDelimiter = value.lastIndexOf("/");
201
- }
202
- if (lastDelimiter > -1) {
203
- url += value.substr(lastDelimiter + 1);
204
- }
205
- else {
206
- url += value;
207
- }
208
- }
209
- // Not from input file.
210
- else {
211
- url += value;
212
- }
213
- return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
214
- };
215
- /**
216
- * Invert Y-Axis of referenced textures on load
217
- */
218
- MTLFileLoader.INVERT_TEXTURE_Y = true;
219
- return MTLFileLoader;
220
- }());
221
- export { MTLFileLoader };
1
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
2
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
3
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
4
+ /**
5
+ * Class reading and parsing the MTL file bundled with the obj file.
6
+ */
7
+ var MTLFileLoader = /** @class */ (function () {
8
+ function MTLFileLoader() {
9
+ /**
10
+ * All material loaded from the mtl will be set here
11
+ */
12
+ this.materials = [];
13
+ }
14
+ /**
15
+ * This function will read the mtl file and create each material described inside
16
+ * This function could be improve by adding :
17
+ * -some component missing (Ni, Tf...)
18
+ * -including the specific options available
19
+ *
20
+ * @param scene defines the scene the material will be created in
21
+ * @param data defines the mtl data to parse
22
+ * @param rootUrl defines the rooturl to use in order to load relative dependencies
23
+ * @param assetContainer defines the asset container to store the material in (can be null)
24
+ */
25
+ MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl, assetContainer) {
26
+ if (data instanceof ArrayBuffer) {
27
+ return;
28
+ }
29
+ //Split the lines from the file
30
+ var lines = data.split("\n");
31
+ // whitespace char ie: [ \t\r\n\f]
32
+ var delimiter_pattern = /\s+/;
33
+ //Array with RGB colors
34
+ var color;
35
+ //New material
36
+ var material = null;
37
+ //Look at each line
38
+ for (var i = 0; i < lines.length; i++) {
39
+ var line = lines[i].trim();
40
+ // Blank line or comment
41
+ if (line.length === 0 || line.charAt(0) === "#") {
42
+ continue;
43
+ }
44
+ //Get the first parameter (keyword)
45
+ var pos = line.indexOf(" ");
46
+ var key = pos >= 0 ? line.substring(0, pos) : line;
47
+ key = key.toLowerCase();
48
+ //Get the data following the key
49
+ var value = pos >= 0 ? line.substring(pos + 1).trim() : "";
50
+ //This mtl keyword will create the new material
51
+ if (key === "newmtl") {
52
+ //Check if it is the first material.
53
+ // Materials specifications are described after this keyword.
54
+ if (material) {
55
+ //Add the previous material in the material array.
56
+ this.materials.push(material);
57
+ }
58
+ //Create a new material.
59
+ // value is the name of the material read in the mtl file
60
+ scene._blockEntityCollection = !!assetContainer;
61
+ material = new StandardMaterial(value, scene);
62
+ material._parentContainer = assetContainer;
63
+ scene._blockEntityCollection = false;
64
+ }
65
+ else if (key === "kd" && material) {
66
+ // Diffuse color (color under white light) using RGB values
67
+ //value = "r g b"
68
+ color = value.split(delimiter_pattern, 3).map(parseFloat);
69
+ //color = [r,g,b]
70
+ //Set tghe color into the material
71
+ material.diffuseColor = Color3.FromArray(color);
72
+ }
73
+ else if (key === "ka" && material) {
74
+ // Ambient color (color under shadow) using RGB values
75
+ //value = "r g b"
76
+ color = value.split(delimiter_pattern, 3).map(parseFloat);
77
+ //color = [r,g,b]
78
+ //Set tghe color into the material
79
+ material.ambientColor = Color3.FromArray(color);
80
+ }
81
+ else if (key === "ks" && material) {
82
+ // Specular color (color when light is reflected from shiny surface) using RGB values
83
+ //value = "r g b"
84
+ color = value.split(delimiter_pattern, 3).map(parseFloat);
85
+ //color = [r,g,b]
86
+ //Set the color into the material
87
+ material.specularColor = Color3.FromArray(color);
88
+ }
89
+ else if (key === "ke" && material) {
90
+ // Emissive color using RGB values
91
+ color = value.split(delimiter_pattern, 3).map(parseFloat);
92
+ material.emissiveColor = Color3.FromArray(color);
93
+ }
94
+ else if (key === "ns" && material) {
95
+ //value = "Integer"
96
+ material.specularPower = parseFloat(value);
97
+ }
98
+ else if (key === "d" && material) {
99
+ //d is dissolve for current material. It mean alpha for BABYLON
100
+ material.alpha = parseFloat(value);
101
+ //Texture
102
+ //This part can be improved by adding the possible options of texture
103
+ }
104
+ else if (key === "map_ka" && material) {
105
+ // ambient texture map with a loaded image
106
+ //We must first get the folder of the image
107
+ material.ambientTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
108
+ }
109
+ else if (key === "map_kd" && material) {
110
+ // Diffuse texture map with a loaded image
111
+ material.diffuseTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
112
+ }
113
+ else if (key === "map_ks" && material) {
114
+ // Specular texture map with a loaded image
115
+ //We must first get the folder of the image
116
+ material.specularTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
117
+ }
118
+ else if (key === "map_ns") {
119
+ //Specular
120
+ //Specular highlight component
121
+ //We must first get the folder of the image
122
+ //
123
+ //Not supported by BABYLON
124
+ //
125
+ // continue;
126
+ }
127
+ else if (key === "map_bump" && material) {
128
+ //The bump texture
129
+ var values = value.split(delimiter_pattern);
130
+ var bumpMultiplierIndex = values.indexOf("-bm");
131
+ var bumpMultiplier = null;
132
+ if (bumpMultiplierIndex >= 0) {
133
+ bumpMultiplier = values[bumpMultiplierIndex + 1];
134
+ values.splice(bumpMultiplierIndex, 2); // remove
135
+ }
136
+ material.bumpTexture = MTLFileLoader._GetTexture(rootUrl, values.join(" "), scene);
137
+ if (material.bumpTexture && bumpMultiplier !== null) {
138
+ material.bumpTexture.level = parseFloat(bumpMultiplier);
139
+ }
140
+ }
141
+ else if (key === "map_d" && material) {
142
+ // The dissolve of the material
143
+ material.opacityTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);
144
+ //Options for illumination
145
+ }
146
+ else if (key === "illum") {
147
+ //Illumination
148
+ if (value === "0") {
149
+ //That mean Kd == Kd
150
+ }
151
+ else if (value === "1") {
152
+ //Color on and Ambient on
153
+ }
154
+ else if (value === "2") {
155
+ //Highlight on
156
+ }
157
+ else if (value === "3") {
158
+ //Reflection on and Ray trace on
159
+ }
160
+ else if (value === "4") {
161
+ //Transparency: Glass on, Reflection: Ray trace on
162
+ }
163
+ else if (value === "5") {
164
+ //Reflection: Fresnel on and Ray trace on
165
+ }
166
+ else if (value === "6") {
167
+ //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
168
+ }
169
+ else if (value === "7") {
170
+ //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
171
+ }
172
+ else if (value === "8") {
173
+ //Reflection on and Ray trace off
174
+ }
175
+ else if (value === "9") {
176
+ //Transparency: Glass on, Reflection: Ray trace off
177
+ }
178
+ else if (value === "10") {
179
+ //Casts shadows onto invisible surfaces
180
+ }
181
+ }
182
+ else {
183
+ // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
184
+ }
185
+ }
186
+ //At the end of the file, add the last material
187
+ if (material) {
188
+ this.materials.push(material);
189
+ }
190
+ };
191
+ /**
192
+ * Gets the texture for the material.
193
+ *
194
+ * If the material is imported from input file,
195
+ * We sanitize the url to ensure it takes the texture from aside the material.
196
+ *
197
+ * @param rootUrl The root url to load from
198
+ * @param value The value stored in the mtl
199
+ * @param scene
200
+ * @return The Texture
201
+ */
202
+ MTLFileLoader._GetTexture = function (rootUrl, value, scene) {
203
+ if (!value) {
204
+ return null;
205
+ }
206
+ var url = rootUrl;
207
+ // Load from input file.
208
+ if (rootUrl === "file:") {
209
+ var lastDelimiter = value.lastIndexOf("\\");
210
+ if (lastDelimiter === -1) {
211
+ lastDelimiter = value.lastIndexOf("/");
212
+ }
213
+ if (lastDelimiter > -1) {
214
+ url += value.substr(lastDelimiter + 1);
215
+ }
216
+ else {
217
+ url += value;
218
+ }
219
+ }
220
+ // Not from input file.
221
+ else {
222
+ url += value;
223
+ }
224
+ return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
225
+ };
226
+ /**
227
+ * Invert Y-Axis of referenced textures on load
228
+ */
229
+ MTLFileLoader.INVERT_TEXTURE_Y = true;
230
+ return MTLFileLoader;
231
+ }());
232
+ export { MTLFileLoader };
222
233
  //# sourceMappingURL=mtlFileLoader.js.map