@babylonjs/loaders 5.0.0-rc.0 → 5.0.0-rc.11
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.
- package/OBJ/index.d.ts +4 -4
- package/OBJ/index.js +4 -4
- package/OBJ/index.js.map +1 -1
- package/OBJ/mtlFileLoader.d.ts +41 -40
- package/OBJ/mtlFileLoader.js +232 -231
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +126 -133
- package/OBJ/objFileLoader.js +296 -300
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/OBJ/solidParser.d.ts +154 -153
- package/OBJ/solidParser.js +693 -699
- package/OBJ/solidParser.js.map +1 -1
- package/STL/index.d.ts +1 -1
- package/STL/index.js +1 -1
- package/STL/index.js.map +1 -1
- package/STL/stlFileLoader.d.ts +64 -71
- package/STL/stlFileLoader.js +233 -239
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -61
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.d.ts +136 -106
- package/glTF/1.0/glTFLoader.js +1814 -1696
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -232
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -127
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/1.0/index.d.ts +5 -5
- package/glTF/1.0/index.js +5 -5
- package/glTF/1.0/index.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -36
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -110
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -28
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -80
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -27
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -42
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -21
- package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -32
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -32
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -55
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -101
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -28
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -81
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -86
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -45
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -34
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -54
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -72
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -76
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -66
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -76
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -277
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -65
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -76
- package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -243
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -78
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -19
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -21
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -21
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -32
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -25
- package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -53
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -29
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -46
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -38
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -216
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -75
- package/glTF/2.0/Extensions/MSFT_lod.js +369 -333
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +26 -26
- package/glTF/2.0/Extensions/index.js +26 -26
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +406 -357
- package/glTF/2.0/glTFLoader.js +2366 -2266
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -209
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +5 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +433 -373
- package/glTF/glTFFileLoader.js +927 -870
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -121
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +6 -5
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +15 -14
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -2
- package/legacy/legacy-glTF1FileLoader.js.map +1 -1
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +33 -32
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -2
- package/legacy/legacy-glTF2FileLoader.js.map +1 -1
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -3
- package/legacy/legacy-glTFFileLoader.js.map +1 -1
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +13 -12
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +13 -12
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +8 -6
- package/legacy/legacy.js.map +1 -1
- package/package.json +23 -198
- package/readme.md +2 -2
package/OBJ/objFileLoader.js
CHANGED
@@ -1,301 +1,297 @@
|
|
1
|
-
import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
|
2
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
3
|
-
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
4
|
-
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
|
-
import { MTLFileLoader } from
|
6
|
-
import { SolidParser } from "./solidParser
|
7
|
-
/**
|
8
|
-
* OBJ file type loader.
|
9
|
-
* This is a babylon scene loader plugin.
|
10
|
-
*/
|
11
|
-
var OBJFileLoader = /** @class */ (function () {
|
12
|
-
/**
|
13
|
-
* Creates loader for .OBJ files
|
14
|
-
*
|
15
|
-
* @param loadingOptions options for loading and parsing OBJ/MTL files.
|
16
|
-
*/
|
17
|
-
function OBJFileLoader(loadingOptions) {
|
18
|
-
/**
|
19
|
-
* Defines the name of the plugin.
|
20
|
-
*/
|
21
|
-
this.name = "obj";
|
22
|
-
/**
|
23
|
-
* Defines the extension the plugin is able to load.
|
24
|
-
*/
|
25
|
-
this.extensions = ".obj";
|
26
|
-
this._assetContainer = null;
|
27
|
-
this._loadingOptions = loadingOptions || OBJFileLoader.
|
28
|
-
}
|
29
|
-
Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
|
30
|
-
/**
|
31
|
-
* Invert Y-Axis of referenced textures on load
|
32
|
-
*/
|
33
|
-
get: function () {
|
34
|
-
return MTLFileLoader.INVERT_TEXTURE_Y;
|
35
|
-
},
|
36
|
-
set: function (value) {
|
37
|
-
MTLFileLoader.INVERT_TEXTURE_Y = value;
|
38
|
-
},
|
39
|
-
enumerable: false,
|
40
|
-
configurable: true
|
41
|
-
});
|
42
|
-
Object.defineProperty(OBJFileLoader, "
|
43
|
-
get: function () {
|
44
|
-
return {
|
45
|
-
computeNormals: OBJFileLoader.COMPUTE_NORMALS,
|
46
|
-
optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
|
47
|
-
importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
|
48
|
-
invertY: OBJFileLoader.INVERT_Y,
|
49
|
-
invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
*
|
62
|
-
*
|
63
|
-
*
|
64
|
-
*
|
65
|
-
*
|
66
|
-
* @param
|
67
|
-
* @param
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
//
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
*
|
88
|
-
* @returns if the data can be loaded directly
|
89
|
-
*/
|
90
|
-
OBJFileLoader.prototype.canDirectLoad = function (
|
91
|
-
return false;
|
92
|
-
};
|
93
|
-
/**
|
94
|
-
* Imports one or more meshes from the loaded OBJ data and adds them to the scene
|
95
|
-
* @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
96
|
-
* @param scene the scene the meshes should be added to
|
97
|
-
* @param data the OBJ data to load
|
98
|
-
* @param rootUrl root url to load from
|
99
|
-
* @
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
*
|
119
|
-
* @param
|
120
|
-
* @
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
*
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
*
|
172
|
-
*
|
173
|
-
*
|
174
|
-
* @
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
var
|
182
|
-
|
183
|
-
var
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
/**
|
260
|
-
*
|
261
|
-
*/
|
262
|
-
OBJFileLoader.
|
263
|
-
/**
|
264
|
-
*
|
265
|
-
*/
|
266
|
-
OBJFileLoader.
|
267
|
-
/**
|
268
|
-
*
|
269
|
-
*/
|
270
|
-
OBJFileLoader.
|
271
|
-
/**
|
272
|
-
*
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
*
|
278
|
-
*/
|
279
|
-
OBJFileLoader.
|
280
|
-
/**
|
281
|
-
*
|
282
|
-
*/
|
283
|
-
OBJFileLoader.
|
284
|
-
/**
|
285
|
-
*
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
if (SceneLoader) {
|
298
|
-
//Add this loader into the register plugin
|
299
|
-
SceneLoader.RegisterPlugin(new OBJFileLoader());
|
300
|
-
}
|
1
|
+
import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
|
2
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
3
|
+
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
4
|
+
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
|
+
import { MTLFileLoader } from "./mtlFileLoader";
|
6
|
+
import { SolidParser } from "./solidParser";
|
7
|
+
/**
|
8
|
+
* OBJ file type loader.
|
9
|
+
* This is a babylon scene loader plugin.
|
10
|
+
*/
|
11
|
+
var OBJFileLoader = /** @class */ (function () {
|
12
|
+
/**
|
13
|
+
* Creates loader for .OBJ files
|
14
|
+
*
|
15
|
+
* @param loadingOptions options for loading and parsing OBJ/MTL files.
|
16
|
+
*/
|
17
|
+
function OBJFileLoader(loadingOptions) {
|
18
|
+
/**
|
19
|
+
* Defines the name of the plugin.
|
20
|
+
*/
|
21
|
+
this.name = "obj";
|
22
|
+
/**
|
23
|
+
* Defines the extension the plugin is able to load.
|
24
|
+
*/
|
25
|
+
this.extensions = ".obj";
|
26
|
+
this._assetContainer = null;
|
27
|
+
this._loadingOptions = loadingOptions || OBJFileLoader._DefaultLoadingOptions;
|
28
|
+
}
|
29
|
+
Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
|
30
|
+
/**
|
31
|
+
* Invert Y-Axis of referenced textures on load
|
32
|
+
*/
|
33
|
+
get: function () {
|
34
|
+
return MTLFileLoader.INVERT_TEXTURE_Y;
|
35
|
+
},
|
36
|
+
set: function (value) {
|
37
|
+
MTLFileLoader.INVERT_TEXTURE_Y = value;
|
38
|
+
},
|
39
|
+
enumerable: false,
|
40
|
+
configurable: true
|
41
|
+
});
|
42
|
+
Object.defineProperty(OBJFileLoader, "_DefaultLoadingOptions", {
|
43
|
+
get: function () {
|
44
|
+
return {
|
45
|
+
computeNormals: OBJFileLoader.COMPUTE_NORMALS,
|
46
|
+
optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
|
47
|
+
importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
|
48
|
+
invertY: OBJFileLoader.INVERT_Y,
|
49
|
+
invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
|
50
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
51
|
+
UVScaling: OBJFileLoader.UV_SCALING,
|
52
|
+
materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
|
53
|
+
optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
|
54
|
+
skipMaterials: OBJFileLoader.SKIP_MATERIALS,
|
55
|
+
};
|
56
|
+
},
|
57
|
+
enumerable: false,
|
58
|
+
configurable: true
|
59
|
+
});
|
60
|
+
/**
|
61
|
+
* Calls synchronously the MTL file attached to this obj.
|
62
|
+
* Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
|
63
|
+
* Without this function materials are not displayed in the first frame (but displayed after).
|
64
|
+
* In consequence it is impossible to get material information in your HTML file
|
65
|
+
*
|
66
|
+
* @param url The URL of the MTL file
|
67
|
+
* @param rootUrl defines where to load data from
|
68
|
+
* @param onSuccess Callback function to be called when the MTL file is loaded
|
69
|
+
* @param onFailure
|
70
|
+
*/
|
71
|
+
OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
|
72
|
+
//The complete path to the mtl file
|
73
|
+
var pathOfFile = rootUrl + url;
|
74
|
+
// Loads through the babylon tools to allow fileInput search.
|
75
|
+
Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
|
76
|
+
onFailure(pathOfFile, exception);
|
77
|
+
});
|
78
|
+
};
|
79
|
+
/**
|
80
|
+
* Instantiates a OBJ file loader plugin.
|
81
|
+
* @returns the created plugin
|
82
|
+
*/
|
83
|
+
OBJFileLoader.prototype.createPlugin = function () {
|
84
|
+
return new OBJFileLoader(OBJFileLoader._DefaultLoadingOptions);
|
85
|
+
};
|
86
|
+
/**
|
87
|
+
* If the data string can be loaded directly.
|
88
|
+
* @returns if the data can be loaded directly
|
89
|
+
*/
|
90
|
+
OBJFileLoader.prototype.canDirectLoad = function () {
|
91
|
+
return false;
|
92
|
+
};
|
93
|
+
/**
|
94
|
+
* Imports one or more meshes from the loaded OBJ data and adds them to the scene
|
95
|
+
* @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
96
|
+
* @param scene the scene the meshes should be added to
|
97
|
+
* @param data the OBJ data to load
|
98
|
+
* @param rootUrl root url to load from
|
99
|
+
* @returns a promise containing the loaded meshes, particles, skeletons and animations
|
100
|
+
*/
|
101
|
+
OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl) {
|
102
|
+
//get the meshes from OBJ file
|
103
|
+
return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
|
104
|
+
return {
|
105
|
+
meshes: meshes,
|
106
|
+
particleSystems: [],
|
107
|
+
skeletons: [],
|
108
|
+
animationGroups: [],
|
109
|
+
transformNodes: [],
|
110
|
+
geometries: [],
|
111
|
+
lights: [],
|
112
|
+
};
|
113
|
+
});
|
114
|
+
};
|
115
|
+
/**
|
116
|
+
* Imports all objects from the loaded OBJ data and adds them to the scene
|
117
|
+
* @param scene the scene the objects should be added to
|
118
|
+
* @param data the OBJ data to load
|
119
|
+
* @param rootUrl root url to load from
|
120
|
+
* @returns a promise which completes when objects have been loaded to the scene
|
121
|
+
*/
|
122
|
+
OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl) {
|
123
|
+
//Get the 3D model
|
124
|
+
return this.importMeshAsync(null, scene, data, rootUrl).then(function () {
|
125
|
+
// return void
|
126
|
+
});
|
127
|
+
};
|
128
|
+
/**
|
129
|
+
* Load into an asset container.
|
130
|
+
* @param scene The scene to load into
|
131
|
+
* @param data The data to import
|
132
|
+
* @param rootUrl The root url for scene and resources
|
133
|
+
* @returns The loaded asset container
|
134
|
+
*/
|
135
|
+
OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl) {
|
136
|
+
var _this = this;
|
137
|
+
var container = new AssetContainer(scene);
|
138
|
+
this._assetContainer = container;
|
139
|
+
return this.importMeshAsync(null, scene, data, rootUrl)
|
140
|
+
.then(function (result) {
|
141
|
+
result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
|
142
|
+
result.meshes.forEach(function (mesh) {
|
143
|
+
var material = mesh.material;
|
144
|
+
if (material) {
|
145
|
+
// Materials
|
146
|
+
if (container.materials.indexOf(material) == -1) {
|
147
|
+
container.materials.push(material);
|
148
|
+
// Textures
|
149
|
+
var textures = material.getActiveTextures();
|
150
|
+
textures.forEach(function (t) {
|
151
|
+
if (container.textures.indexOf(t) == -1) {
|
152
|
+
container.textures.push(t);
|
153
|
+
}
|
154
|
+
});
|
155
|
+
}
|
156
|
+
}
|
157
|
+
});
|
158
|
+
_this._assetContainer = null;
|
159
|
+
return container;
|
160
|
+
})
|
161
|
+
.catch(function (ex) {
|
162
|
+
_this._assetContainer = null;
|
163
|
+
throw ex;
|
164
|
+
});
|
165
|
+
};
|
166
|
+
/**
|
167
|
+
* Read the OBJ file and create an Array of meshes.
|
168
|
+
* Each mesh contains all information given by the OBJ and the MTL file.
|
169
|
+
* i.e. vertices positions and indices, optional normals values, optional UV values, optional material
|
170
|
+
* @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file
|
171
|
+
* @param scene defines the scene where are displayed the data
|
172
|
+
* @param data defines the content of the obj file
|
173
|
+
* @param rootUrl defines the path to the folder
|
174
|
+
* @returns the list of loaded meshes
|
175
|
+
*/
|
176
|
+
OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
|
177
|
+
var _this = this;
|
178
|
+
var fileToLoad = ""; //The name of the mtlFile to load
|
179
|
+
var materialsFromMTLFile = new MTLFileLoader();
|
180
|
+
var materialToUse = new Array();
|
181
|
+
var babylonMeshesArray = []; //The mesh for babylon
|
182
|
+
// Main function
|
183
|
+
var solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);
|
184
|
+
solidParser.parse(meshesNames, data, scene, this._assetContainer, function (fileName) {
|
185
|
+
fileToLoad = fileName;
|
186
|
+
});
|
187
|
+
// load the materials
|
188
|
+
var mtlPromises = [];
|
189
|
+
// Check if we have a file to load
|
190
|
+
if (fileToLoad !== "" && !this._loadingOptions.skipMaterials) {
|
191
|
+
//Load the file synchronously
|
192
|
+
mtlPromises.push(new Promise(function (resolve, reject) {
|
193
|
+
_this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
|
194
|
+
try {
|
195
|
+
//Create materials thanks MTLLoader function
|
196
|
+
materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._assetContainer);
|
197
|
+
//Look at each material loaded in the mtl file
|
198
|
+
for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
|
199
|
+
//Three variables to get all meshes with the same material
|
200
|
+
var startIndex = 0;
|
201
|
+
var _indices = [];
|
202
|
+
var _index = void 0;
|
203
|
+
//The material from MTL file is used in the meshes loaded
|
204
|
+
//Push the indice in an array
|
205
|
+
//Check if the material is not used for another mesh
|
206
|
+
while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
|
207
|
+
_indices.push(_index);
|
208
|
+
startIndex = _index + 1;
|
209
|
+
}
|
210
|
+
//If the material is not used dispose it
|
211
|
+
if (_index === -1 && _indices.length === 0) {
|
212
|
+
//If the material is not needed, remove it
|
213
|
+
materialsFromMTLFile.materials[n].dispose();
|
214
|
+
}
|
215
|
+
else {
|
216
|
+
for (var o = 0; o < _indices.length; o++) {
|
217
|
+
//Apply the material to the Mesh for each mesh with the material
|
218
|
+
var mesh = babylonMeshesArray[_indices[o]];
|
219
|
+
var material = materialsFromMTLFile.materials[n];
|
220
|
+
mesh.material = material;
|
221
|
+
if (!mesh.getTotalIndices()) {
|
222
|
+
// No indices, we need to turn on point cloud
|
223
|
+
material.pointsCloud = true;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
}
|
228
|
+
resolve();
|
229
|
+
}
|
230
|
+
catch (e) {
|
231
|
+
Tools.Warn("Error processing MTL file: '".concat(fileToLoad, "'"));
|
232
|
+
if (_this._loadingOptions.materialLoadingFailsSilently) {
|
233
|
+
resolve();
|
234
|
+
}
|
235
|
+
else {
|
236
|
+
reject(e);
|
237
|
+
}
|
238
|
+
}
|
239
|
+
}, function (pathOfFile, exception) {
|
240
|
+
Tools.Warn("Error downloading MTL file: '".concat(fileToLoad, "'"));
|
241
|
+
if (_this._loadingOptions.materialLoadingFailsSilently) {
|
242
|
+
resolve();
|
243
|
+
}
|
244
|
+
else {
|
245
|
+
reject(exception);
|
246
|
+
}
|
247
|
+
});
|
248
|
+
}));
|
249
|
+
}
|
250
|
+
//Return an array with all Mesh
|
251
|
+
return Promise.all(mtlPromises).then(function () {
|
252
|
+
return babylonMeshesArray;
|
253
|
+
});
|
254
|
+
};
|
255
|
+
/**
|
256
|
+
* Defines if UVs are optimized by default during load.
|
257
|
+
*/
|
258
|
+
OBJFileLoader.OPTIMIZE_WITH_UV = true;
|
259
|
+
/**
|
260
|
+
* Invert model on y-axis (does a model scaling inversion)
|
261
|
+
*/
|
262
|
+
OBJFileLoader.INVERT_Y = false;
|
263
|
+
/**
|
264
|
+
* Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
|
265
|
+
*/
|
266
|
+
OBJFileLoader.IMPORT_VERTEX_COLORS = false;
|
267
|
+
/**
|
268
|
+
* Compute the normals for the model, even if normals are present in the file.
|
269
|
+
*/
|
270
|
+
OBJFileLoader.COMPUTE_NORMALS = false;
|
271
|
+
/**
|
272
|
+
* Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.
|
273
|
+
* Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.
|
274
|
+
*/
|
275
|
+
OBJFileLoader.OPTIMIZE_NORMALS = false;
|
276
|
+
/**
|
277
|
+
* Defines custom scaling of UV coordinates of loaded meshes.
|
278
|
+
*/
|
279
|
+
OBJFileLoader.UV_SCALING = new Vector2(1, 1);
|
280
|
+
/**
|
281
|
+
* Skip loading the materials even if defined in the OBJ file (materials are ignored).
|
282
|
+
*/
|
283
|
+
OBJFileLoader.SKIP_MATERIALS = false;
|
284
|
+
/**
|
285
|
+
* When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
|
286
|
+
*
|
287
|
+
* Defaults to true for backwards compatibility.
|
288
|
+
*/
|
289
|
+
OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
|
290
|
+
return OBJFileLoader;
|
291
|
+
}());
|
292
|
+
export { OBJFileLoader };
|
293
|
+
if (SceneLoader) {
|
294
|
+
//Add this loader into the register plugin
|
295
|
+
SceneLoader.RegisterPlugin(new OBJFileLoader());
|
296
|
+
}
|
301
297
|
//# sourceMappingURL=objFileLoader.js.map
|