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