@babylonjs/loaders 5.0.0-rc.7 → 5.0.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 (169) hide show
  1. package/OBJ/index.d.ts +4 -4
  2. package/OBJ/index.js +4 -4
  3. package/OBJ/mtlFileLoader.d.ts +41 -41
  4. package/OBJ/mtlFileLoader.js +232 -232
  5. package/OBJ/mtlFileLoader.js.map +1 -1
  6. package/OBJ/objFileLoader.d.ts +126 -126
  7. package/OBJ/objFileLoader.js +296 -296
  8. package/OBJ/objFileLoader.js.map +1 -1
  9. package/OBJ/objLoadingOptions.d.ts +43 -43
  10. package/OBJ/objLoadingOptions.js +1 -1
  11. package/OBJ/objLoadingOptions.js.map +1 -1
  12. package/OBJ/solidParser.d.ts +154 -154
  13. package/OBJ/solidParser.js +693 -693
  14. package/OBJ/solidParser.js.map +1 -1
  15. package/STL/index.d.ts +1 -1
  16. package/STL/index.js +1 -1
  17. package/STL/stlFileLoader.d.ts +64 -64
  18. package/STL/stlFileLoader.js +233 -233
  19. package/STL/stlFileLoader.js.map +1 -1
  20. package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
  21. package/glTF/1.0/glTFBinaryExtension.js +60 -60
  22. package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
  23. package/glTF/1.0/glTFLoader.d.ts +136 -136
  24. package/glTF/1.0/glTFLoader.js +1814 -1815
  25. package/glTF/1.0/glTFLoader.js.map +1 -1
  26. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
  27. package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
  28. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  29. package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
  30. package/glTF/1.0/glTFLoaderUtils.js +250 -250
  31. package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
  32. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
  33. package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
  34. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
  35. package/glTF/1.0/index.d.ts +5 -5
  36. package/glTF/1.0/index.js +5 -5
  37. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -43
  38. package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -117
  39. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  40. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -36
  41. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -88
  42. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  43. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -34
  44. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -49
  45. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  46. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -29
  47. package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -40
  48. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  49. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
  50. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
  51. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  52. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -39
  53. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -112
  54. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -36
  56. package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -89
  57. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  58. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -39
  59. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -94
  60. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  61. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -38
  62. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -53
  63. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  64. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -42
  65. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -62
  66. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  67. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -38
  68. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -80
  69. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  70. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -39
  71. package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -84
  72. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  73. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -38
  74. package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -74
  75. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  76. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -39
  77. package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -83
  78. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  79. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -38
  80. package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -288
  81. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  82. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -38
  83. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -73
  84. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  85. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -87
  86. package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -254
  87. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  88. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -39
  89. package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -85
  90. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  91. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -22
  92. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -23
  93. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  94. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -29
  95. package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -40
  96. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  97. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -33
  98. package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -61
  99. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  100. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -32
  101. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -49
  102. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  103. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -54
  104. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -240
  105. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  106. package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -109
  107. package/glTF/2.0/Extensions/MSFT_lod.js +369 -369
  108. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  109. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
  110. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
  111. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  112. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
  113. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
  114. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  115. package/glTF/2.0/Extensions/index.d.ts +26 -26
  116. package/glTF/2.0/Extensions/index.js +26 -26
  117. package/glTF/2.0/glTFLoader.d.ts +406 -405
  118. package/glTF/2.0/glTFLoader.js +2366 -2366
  119. package/glTF/2.0/glTFLoader.js.map +1 -1
  120. package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
  121. package/glTF/2.0/glTFLoaderExtension.js +1 -1
  122. package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
  123. package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
  124. package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
  125. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  126. package/glTF/2.0/index.d.ts +4 -4
  127. package/glTF/2.0/index.js +5 -4
  128. package/glTF/2.0/index.js.map +1 -1
  129. package/glTF/glTFFileLoader.d.ts +433 -433
  130. package/glTF/glTFFileLoader.js +927 -927
  131. package/glTF/glTFFileLoader.js.map +1 -1
  132. package/glTF/glTFValidation.d.ts +29 -29
  133. package/glTF/glTFValidation.js +123 -123
  134. package/glTF/glTFValidation.js.map +1 -1
  135. package/glTF/index.d.ts +5 -5
  136. package/glTF/index.js +6 -5
  137. package/glTF/index.js.map +1 -1
  138. package/index.d.ts +3 -3
  139. package/index.js +4 -3
  140. package/index.js.map +1 -1
  141. package/legacy/legacy-glTF.d.ts +2 -2
  142. package/legacy/legacy-glTF.js +18 -18
  143. package/legacy/legacy-glTF.js.map +1 -1
  144. package/legacy/legacy-glTF1.d.ts +2 -2
  145. package/legacy/legacy-glTF1.js +15 -14
  146. package/legacy/legacy-glTF1.js.map +1 -1
  147. package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
  148. package/legacy/legacy-glTF1FileLoader.js +3 -3
  149. package/legacy/legacy-glTF1FileLoader.js.map +1 -1
  150. package/legacy/legacy-glTF2.d.ts +2 -2
  151. package/legacy/legacy-glTF2.js +33 -32
  152. package/legacy/legacy-glTF2.js.map +1 -1
  153. package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
  154. package/legacy/legacy-glTF2FileLoader.js +3 -3
  155. package/legacy/legacy-glTF2FileLoader.js.map +1 -1
  156. package/legacy/legacy-glTFFileLoader.d.ts +3 -3
  157. package/legacy/legacy-glTFFileLoader.js +4 -4
  158. package/legacy/legacy-glTFFileLoader.js.map +1 -1
  159. package/legacy/legacy-objFileLoader.d.ts +1 -1
  160. package/legacy/legacy-objFileLoader.js +13 -12
  161. package/legacy/legacy-objFileLoader.js.map +1 -1
  162. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  163. package/legacy/legacy-stlFileLoader.js +13 -12
  164. package/legacy/legacy-stlFileLoader.js.map +1 -1
  165. package/legacy/legacy.d.ts +6 -6
  166. package/legacy/legacy.js +8 -7
  167. package/legacy/legacy.js.map +1 -1
  168. package/license.md +71 -0
  169. package/package.json +25 -6
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
@@ -1,41 +1,41 @@
1
- import { Nullable } from "@babylonjs/core/types.js";
2
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
3
- import { Scene } from "@babylonjs/core/scene.js";
4
- import { 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
+ 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,233 +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
- // 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 };
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 };
233
233
  //# sourceMappingURL=mtlFileLoader.js.map