@babylonjs/loaders 5.0.0-rc.0 → 5.0.0-rc.11
Sign up to get free protection for your applications and to get access to all the features.
- 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/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export * from "./mtlFileLoader";
|
2
|
-
export * from "./objLoadingOptions";
|
3
|
-
export * from "./solidParser";
|
4
|
-
export * from "./objFileLoader";
|
1
|
+
export * from "./mtlFileLoader";
|
2
|
+
export * from "./objLoadingOptions";
|
3
|
+
export * from "./solidParser";
|
4
|
+
export * from "./objFileLoader";
|
package/OBJ/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
export * from "./mtlFileLoader.js";
|
2
|
-
export * from "./objLoadingOptions.js";
|
3
|
-
export * from "./solidParser.js";
|
4
|
-
export * from "./objFileLoader.js";
|
1
|
+
export * from "./mtlFileLoader.js";
|
2
|
+
export * from "./objLoadingOptions.js";
|
3
|
+
export * from "./solidParser.js";
|
4
|
+
export * from "./objFileLoader.js";
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/OBJ/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./mtlFileLoader\";\r\nexport * from \"./objLoadingOptions\";\r\nexport * from \"./solidParser\";\r\nexport * from \"./objFileLoader\";\r\n"]}
|
package/OBJ/mtlFileLoader.d.ts
CHANGED
@@ -1,40 +1,41 @@
|
|
1
|
-
import { Nullable } from "@babylonjs/core/types";
|
2
|
-
import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial";
|
3
|
-
import { Scene } from "@babylonjs/core/scene";
|
4
|
-
import { AssetContainer } from "@babylonjs/core/assetContainer";
|
5
|
-
/**
|
6
|
-
* Class reading and parsing the MTL file bundled with the obj file.
|
7
|
-
*/
|
8
|
-
export declare class MTLFileLoader {
|
9
|
-
/**
|
10
|
-
* Invert Y-Axis of referenced textures on load
|
11
|
-
*/
|
12
|
-
static INVERT_TEXTURE_Y: boolean;
|
13
|
-
/**
|
14
|
-
* All material loaded from the mtl will be set here
|
15
|
-
*/
|
16
|
-
materials: StandardMaterial[];
|
17
|
-
/**
|
18
|
-
* This function will read the mtl file and create each material described inside
|
19
|
-
* This function could be improve by adding :
|
20
|
-
* -some component missing (Ni, Tf...)
|
21
|
-
* -including the specific options available
|
22
|
-
*
|
23
|
-
* @param scene defines the scene the material will be created in
|
24
|
-
* @param data defines the mtl data to parse
|
25
|
-
* @param rootUrl defines the rooturl to use in order to load relative dependencies
|
26
|
-
* @param assetContainer defines the asset container to store the material in (can be null)
|
27
|
-
*/
|
28
|
-
parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void;
|
29
|
-
/**
|
30
|
-
* Gets the texture for the material.
|
31
|
-
*
|
32
|
-
* If the material is imported from input file,
|
33
|
-
* We sanitize the url to ensure it takes the
|
34
|
-
*
|
35
|
-
* @param rootUrl The root url to load from
|
36
|
-
* @param value The value stored in the mtl
|
37
|
-
* @
|
38
|
-
|
39
|
-
|
40
|
-
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
2
|
+
import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
|
3
|
+
import type { Scene } from "@babylonjs/core/scene.js";
|
4
|
+
import type { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
|
+
/**
|
6
|
+
* Class reading and parsing the MTL file bundled with the obj file.
|
7
|
+
*/
|
8
|
+
export declare class MTLFileLoader {
|
9
|
+
/**
|
10
|
+
* Invert Y-Axis of referenced textures on load
|
11
|
+
*/
|
12
|
+
static INVERT_TEXTURE_Y: boolean;
|
13
|
+
/**
|
14
|
+
* All material loaded from the mtl will be set here
|
15
|
+
*/
|
16
|
+
materials: StandardMaterial[];
|
17
|
+
/**
|
18
|
+
* This function will read the mtl file and create each material described inside
|
19
|
+
* This function could be improve by adding :
|
20
|
+
* -some component missing (Ni, Tf...)
|
21
|
+
* -including the specific options available
|
22
|
+
*
|
23
|
+
* @param scene defines the scene the material will be created in
|
24
|
+
* @param data defines the mtl data to parse
|
25
|
+
* @param rootUrl defines the rooturl to use in order to load relative dependencies
|
26
|
+
* @param assetContainer defines the asset container to store the material in (can be null)
|
27
|
+
*/
|
28
|
+
parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void;
|
29
|
+
/**
|
30
|
+
* Gets the texture for the material.
|
31
|
+
*
|
32
|
+
* If the material is imported from input file,
|
33
|
+
* We sanitize the url to ensure it takes the texture from aside the material.
|
34
|
+
*
|
35
|
+
* @param rootUrl The root url to load from
|
36
|
+
* @param value The value stored in the mtl
|
37
|
+
* @param scene
|
38
|
+
* @return The Texture
|
39
|
+
*/
|
40
|
+
private static _GetTexture;
|
41
|
+
}
|
package/OBJ/mtlFileLoader.js
CHANGED
@@ -1,232 +1,233 @@
|
|
1
|
-
import { Color3 } from
|
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(
|
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 =
|
47
|
-
key = key.toLowerCase();
|
48
|
-
//Get the data following the key
|
49
|
-
var value =
|
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.
|
108
|
-
}
|
109
|
-
else if (key === "map_kd" && material) {
|
110
|
-
// Diffuse texture map with a loaded image
|
111
|
-
material.diffuseTexture = MTLFileLoader.
|
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.
|
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(
|
131
|
-
var bumpMultiplier = null;
|
132
|
-
if (bumpMultiplierIndex >= 0) {
|
133
|
-
bumpMultiplier = values[bumpMultiplierIndex + 1];
|
134
|
-
values.splice(bumpMultiplierIndex, 2); // remove
|
135
|
-
}
|
136
|
-
material.bumpTexture = MTLFileLoader.
|
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.
|
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
|
196
|
-
*
|
197
|
-
* @param rootUrl The root url to load from
|
198
|
-
* @param value The value stored in the mtl
|
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
|
-
|
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 };
|
232
233
|
//# sourceMappingURL=mtlFileLoader.js.map
|