@babylonjs/loaders 5.21.0 → 5.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/mtlFileLoader.js +25 -27
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.js +112 -124
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/solidParser.js +118 -125
- package/OBJ/solidParser.js.map +1 -1
- package/STL/stlFileLoader.js +61 -63
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.js +26 -30
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.js +409 -432
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.js +33 -37
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.js +27 -31
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +48 -59
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +24 -29
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +13 -16
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +13 -16
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +22 -26
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +63 -76
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js +90 -120
- package/glTF/2.0/Extensions/KHR_animation_pointer.map.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +25 -28
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +27 -30
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +25 -28
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +15 -18
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js +21 -24
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +27 -31
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +24 -27
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +23 -26
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +23 -26
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +20 -23
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +82 -86
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +19 -22
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +79 -97
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +20 -23
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +6 -8
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +13 -16
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +12 -15
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +12 -15
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +77 -95
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +114 -139
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +12 -15
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +12 -15
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/glTFLoader.js +739 -823
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.js +337 -404
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +32 -39
- package/glTF/glTFValidation.js.map +1 -1
- package/legacy/legacy-glTF.js +3 -3
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.js +2 -2
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF2.js +12 -12
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-objFileLoader.js +2 -2
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.js +2 -2
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/package.json +3 -6
package/OBJ/mtlFileLoader.js
CHANGED
@@ -4,8 +4,8 @@ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js"
|
|
4
4
|
/**
|
5
5
|
* Class reading and parsing the MTL file bundled with the obj file.
|
6
6
|
*/
|
7
|
-
|
8
|
-
|
7
|
+
export class MTLFileLoader {
|
8
|
+
constructor() {
|
9
9
|
/**
|
10
10
|
* All material loaded from the mtl will be set here
|
11
11
|
*/
|
@@ -22,31 +22,31 @@ var MTLFileLoader = /** @class */ (function () {
|
|
22
22
|
* @param rootUrl defines the rooturl to use in order to load relative dependencies
|
23
23
|
* @param assetContainer defines the asset container to store the material in (can be null)
|
24
24
|
*/
|
25
|
-
|
25
|
+
parseMTL(scene, data, rootUrl, assetContainer) {
|
26
26
|
if (data instanceof ArrayBuffer) {
|
27
27
|
return;
|
28
28
|
}
|
29
29
|
//Split the lines from the file
|
30
|
-
|
30
|
+
const lines = data.split("\n");
|
31
31
|
// whitespace char ie: [ \t\r\n\f]
|
32
|
-
|
32
|
+
const delimiter_pattern = /\s+/;
|
33
33
|
//Array with RGB colors
|
34
|
-
|
34
|
+
let color;
|
35
35
|
//New material
|
36
|
-
|
36
|
+
let material = null;
|
37
37
|
//Look at each line
|
38
|
-
for (
|
39
|
-
|
38
|
+
for (let i = 0; i < lines.length; i++) {
|
39
|
+
const line = lines[i].trim();
|
40
40
|
// Blank line or comment
|
41
41
|
if (line.length === 0 || line.charAt(0) === "#") {
|
42
42
|
continue;
|
43
43
|
}
|
44
44
|
//Get the first parameter (keyword)
|
45
|
-
|
46
|
-
|
45
|
+
const pos = line.indexOf(" ");
|
46
|
+
let key = pos >= 0 ? line.substring(0, pos) : line;
|
47
47
|
key = key.toLowerCase();
|
48
48
|
//Get the data following the key
|
49
|
-
|
49
|
+
const value = pos >= 0 ? line.substring(pos + 1).trim() : "";
|
50
50
|
//This mtl keyword will create the new material
|
51
51
|
if (key === "newmtl") {
|
52
52
|
//Check if it is the first material.
|
@@ -126,9 +126,9 @@ var MTLFileLoader = /** @class */ (function () {
|
|
126
126
|
}
|
127
127
|
else if (key === "map_bump" && material) {
|
128
128
|
//The bump texture
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
const values = value.split(delimiter_pattern);
|
130
|
+
const bumpMultiplierIndex = values.indexOf("-bm");
|
131
|
+
let bumpMultiplier = null;
|
132
132
|
if (bumpMultiplierIndex >= 0) {
|
133
133
|
bumpMultiplier = values[bumpMultiplierIndex + 1];
|
134
134
|
values.splice(bumpMultiplierIndex, 2); // remove
|
@@ -187,7 +187,7 @@ var MTLFileLoader = /** @class */ (function () {
|
|
187
187
|
if (material) {
|
188
188
|
this.materials.push(material);
|
189
189
|
}
|
190
|
-
}
|
190
|
+
}
|
191
191
|
/**
|
192
192
|
* Gets the texture for the material.
|
193
193
|
*
|
@@ -199,14 +199,14 @@ var MTLFileLoader = /** @class */ (function () {
|
|
199
199
|
* @param scene
|
200
200
|
* @return The Texture
|
201
201
|
*/
|
202
|
-
|
202
|
+
static _GetTexture(rootUrl, value, scene) {
|
203
203
|
if (!value) {
|
204
204
|
return null;
|
205
205
|
}
|
206
|
-
|
206
|
+
let url = rootUrl;
|
207
207
|
// Load from input file.
|
208
208
|
if (rootUrl === "file:") {
|
209
|
-
|
209
|
+
let lastDelimiter = value.lastIndexOf("\\");
|
210
210
|
if (lastDelimiter === -1) {
|
211
211
|
lastDelimiter = value.lastIndexOf("/");
|
212
212
|
}
|
@@ -222,12 +222,10 @@ var MTLFileLoader = /** @class */ (function () {
|
|
222
222
|
url += value;
|
223
223
|
}
|
224
224
|
return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
|
225
|
-
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
}());
|
232
|
-
export { MTLFileLoader };
|
225
|
+
}
|
226
|
+
}
|
227
|
+
/**
|
228
|
+
* Invert Y-Axis of referenced textures on load
|
229
|
+
*/
|
230
|
+
MTLFileLoader.INVERT_TEXTURE_Y = true;
|
233
231
|
//# sourceMappingURL=mtlFileLoader.js.map
|
package/OBJ/mtlFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mtlFileLoader.js","sourceRo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AG,CAAC,CAAC;aAC1C;YAED,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE;gBACpB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;aAC1C;iBAAM;gBACH,GAAG,IAAI,KAAK,CAAC;aAChB;SACJ;QACD,uBAAuB;aAClB;YACD,GAAG,IAAI,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IAtND;;OAEG;IACW,8BAAgB,GAAG,IAAI,CAAC;IAoN1C,oBAAC;CAAA,AAxND,IAwNC;SAxNY,aAAa","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n const lines = data.split(\"\\n\");\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n const delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n let color: number[];\r\n //New material\r\n let material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (let i = 0; i < lines.length; i++) {\r\n const line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === \"#\") {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n const pos = line.indexOf(\" \");\r\n let key = pos >= 0 ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n const value: string = pos >= 0 ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n const values = value.split(delimiter_pattern);\r\n const bumpMultiplierIndex = values.indexOf(\"-bm\");\r\n let bumpMultiplier: Nullable<string> = null;\r\n\r\n if (bumpMultiplierIndex >= 0) {\r\n bumpMultiplier = values[bumpMultiplierIndex + 1];\r\n values.splice(bumpMultiplierIndex, 2); // remove\r\n }\r\n\r\n material.bumpTexture = MTLFileLoader._GetTexture(rootUrl, values.join(\" \"), scene);\r\n if (material.bumpTexture && bumpMultiplier !== null) {\r\n material.bumpTexture.level = parseFloat(bumpMultiplier);\r\n }\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the texture from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @param scene\r\n * @return The Texture\r\n */\r\n private static _GetTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n let url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n let lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substr(lastDelimiter + 1);\r\n } else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"mtlFileLoader.js","sourceRo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AAW,CAAC,GAAG,CAAC,CAAC;aAC1C;YAED,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE;gBACpB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;aAC1C;iBAAM;gBACH,GAAG,IAAI,KAAK,CAAC;aAChB;SACJ;QACD,uBAAuB;aAClB;YACD,GAAG,IAAI,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC;;AAtND;;GAEG;AACW,8BAAgB,GAAG,IAAI,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n const lines = data.split(\"\\n\");\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n const delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n let color: number[];\r\n //New material\r\n let material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (let i = 0; i < lines.length; i++) {\r\n const line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === \"#\") {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n const pos = line.indexOf(\" \");\r\n let key = pos >= 0 ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n const value: string = pos >= 0 ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n const values = value.split(delimiter_pattern);\r\n const bumpMultiplierIndex = values.indexOf(\"-bm\");\r\n let bumpMultiplier: Nullable<string> = null;\r\n\r\n if (bumpMultiplierIndex >= 0) {\r\n bumpMultiplier = values[bumpMultiplierIndex + 1];\r\n values.splice(bumpMultiplierIndex, 2); // remove\r\n }\r\n\r\n material.bumpTexture = MTLFileLoader._GetTexture(rootUrl, values.join(\" \"), scene);\r\n if (material.bumpTexture && bumpMultiplier !== null) {\r\n material.bumpTexture.level = parseFloat(bumpMultiplier);\r\n }\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the texture from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @param scene\r\n * @return The Texture\r\n */\r\n private static _GetTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n let url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n let lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substr(lastDelimiter + 1);\r\n } else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\n}\r\n"]}
|
package/OBJ/objFileLoader.js
CHANGED
@@ -8,13 +8,13 @@ import { SolidParser } from "./solidParser.js";
|
|
8
8
|
* OBJ file type loader.
|
9
9
|
* This is a babylon scene loader plugin.
|
10
10
|
*/
|
11
|
-
|
11
|
+
export class OBJFileLoader {
|
12
12
|
/**
|
13
13
|
* Creates loader for .OBJ files
|
14
14
|
*
|
15
15
|
* @param loadingOptions options for loading and parsing OBJ/MTL files.
|
16
16
|
*/
|
17
|
-
|
17
|
+
constructor(loadingOptions) {
|
18
18
|
/**
|
19
19
|
* Defines the name of the plugin.
|
20
20
|
*/
|
@@ -26,37 +26,29 @@ var OBJFileLoader = /** @class */ (function () {
|
|
26
26
|
this._assetContainer = null;
|
27
27
|
this._loadingOptions = loadingOptions || OBJFileLoader._DefaultLoadingOptions;
|
28
28
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
});
|
29
|
+
/**
|
30
|
+
* Invert Y-Axis of referenced textures on load
|
31
|
+
*/
|
32
|
+
static get INVERT_TEXTURE_Y() {
|
33
|
+
return MTLFileLoader.INVERT_TEXTURE_Y;
|
34
|
+
}
|
35
|
+
static set INVERT_TEXTURE_Y(value) {
|
36
|
+
MTLFileLoader.INVERT_TEXTURE_Y = value;
|
37
|
+
}
|
38
|
+
static get _DefaultLoadingOptions() {
|
39
|
+
return {
|
40
|
+
computeNormals: OBJFileLoader.COMPUTE_NORMALS,
|
41
|
+
optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
|
42
|
+
importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
|
43
|
+
invertY: OBJFileLoader.INVERT_Y,
|
44
|
+
invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
|
45
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
46
|
+
UVScaling: OBJFileLoader.UV_SCALING,
|
47
|
+
materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
|
48
|
+
optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
|
49
|
+
skipMaterials: OBJFileLoader.SKIP_MATERIALS,
|
50
|
+
};
|
51
|
+
}
|
60
52
|
/**
|
61
53
|
* Calls synchronously the MTL file attached to this obj.
|
62
54
|
* Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
|
@@ -68,28 +60,28 @@ var OBJFileLoader = /** @class */ (function () {
|
|
68
60
|
* @param onSuccess Callback function to be called when the MTL file is loaded
|
69
61
|
* @param onFailure
|
70
62
|
*/
|
71
|
-
|
63
|
+
_loadMTL(url, rootUrl, onSuccess, onFailure) {
|
72
64
|
//The complete path to the mtl file
|
73
|
-
|
65
|
+
const pathOfFile = rootUrl + url;
|
74
66
|
// Loads through the babylon tools to allow fileInput search.
|
75
|
-
Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false,
|
67
|
+
Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, (request, exception) => {
|
76
68
|
onFailure(pathOfFile, exception);
|
77
69
|
});
|
78
|
-
}
|
70
|
+
}
|
79
71
|
/**
|
80
72
|
* Instantiates a OBJ file loader plugin.
|
81
73
|
* @returns the created plugin
|
82
74
|
*/
|
83
|
-
|
75
|
+
createPlugin() {
|
84
76
|
return new OBJFileLoader(OBJFileLoader._DefaultLoadingOptions);
|
85
|
-
}
|
77
|
+
}
|
86
78
|
/**
|
87
79
|
* If the data string can be loaded directly.
|
88
80
|
* @returns if the data can be loaded directly
|
89
81
|
*/
|
90
|
-
|
82
|
+
canDirectLoad() {
|
91
83
|
return false;
|
92
|
-
}
|
84
|
+
}
|
93
85
|
/**
|
94
86
|
* Imports one or more meshes from the loaded OBJ data and adds them to the scene
|
95
87
|
* @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
@@ -98,9 +90,9 @@ var OBJFileLoader = /** @class */ (function () {
|
|
98
90
|
* @param rootUrl root url to load from
|
99
91
|
* @returns a promise containing the loaded meshes, particles, skeletons and animations
|
100
92
|
*/
|
101
|
-
|
93
|
+
importMeshAsync(meshesNames, scene, data, rootUrl) {
|
102
94
|
//get the meshes from OBJ file
|
103
|
-
return this._parseSolid(meshesNames, scene, data, rootUrl).then(
|
95
|
+
return this._parseSolid(meshesNames, scene, data, rootUrl).then((meshes) => {
|
104
96
|
return {
|
105
97
|
meshes: meshes,
|
106
98
|
particleSystems: [],
|
@@ -111,7 +103,7 @@ var OBJFileLoader = /** @class */ (function () {
|
|
111
103
|
lights: [],
|
112
104
|
};
|
113
105
|
});
|
114
|
-
}
|
106
|
+
}
|
115
107
|
/**
|
116
108
|
* Imports all objects from the loaded OBJ data and adds them to the scene
|
117
109
|
* @param scene the scene the objects should be added to
|
@@ -119,12 +111,12 @@ var OBJFileLoader = /** @class */ (function () {
|
|
119
111
|
* @param rootUrl root url to load from
|
120
112
|
* @returns a promise which completes when objects have been loaded to the scene
|
121
113
|
*/
|
122
|
-
|
114
|
+
loadAsync(scene, data, rootUrl) {
|
123
115
|
//Get the 3D model
|
124
|
-
return this.importMeshAsync(null, scene, data, rootUrl).then(
|
116
|
+
return this.importMeshAsync(null, scene, data, rootUrl).then(() => {
|
125
117
|
// return void
|
126
118
|
});
|
127
|
-
}
|
119
|
+
}
|
128
120
|
/**
|
129
121
|
* Load into an asset container.
|
130
122
|
* @param scene The scene to load into
|
@@ -132,22 +124,21 @@ var OBJFileLoader = /** @class */ (function () {
|
|
132
124
|
* @param rootUrl The root url for scene and resources
|
133
125
|
* @returns The loaded asset container
|
134
126
|
*/
|
135
|
-
|
136
|
-
|
137
|
-
var container = new AssetContainer(scene);
|
127
|
+
loadAssetContainerAsync(scene, data, rootUrl) {
|
128
|
+
const container = new AssetContainer(scene);
|
138
129
|
this._assetContainer = container;
|
139
130
|
return this.importMeshAsync(null, scene, data, rootUrl)
|
140
|
-
.then(
|
141
|
-
result.meshes.forEach(
|
142
|
-
result.meshes.forEach(
|
143
|
-
|
131
|
+
.then((result) => {
|
132
|
+
result.meshes.forEach((mesh) => container.meshes.push(mesh));
|
133
|
+
result.meshes.forEach((mesh) => {
|
134
|
+
const material = mesh.material;
|
144
135
|
if (material) {
|
145
136
|
// Materials
|
146
137
|
if (container.materials.indexOf(material) == -1) {
|
147
138
|
container.materials.push(material);
|
148
139
|
// Textures
|
149
|
-
|
150
|
-
textures.forEach(
|
140
|
+
const textures = material.getActiveTextures();
|
141
|
+
textures.forEach((t) => {
|
151
142
|
if (container.textures.indexOf(t) == -1) {
|
152
143
|
container.textures.push(t);
|
153
144
|
}
|
@@ -155,14 +146,14 @@ var OBJFileLoader = /** @class */ (function () {
|
|
155
146
|
}
|
156
147
|
}
|
157
148
|
});
|
158
|
-
|
149
|
+
this._assetContainer = null;
|
159
150
|
return container;
|
160
151
|
})
|
161
|
-
.catch(
|
162
|
-
|
152
|
+
.catch((ex) => {
|
153
|
+
this._assetContainer = null;
|
163
154
|
throw ex;
|
164
155
|
});
|
165
|
-
}
|
156
|
+
}
|
166
157
|
/**
|
167
158
|
* Read the OBJ file and create an Array of meshes.
|
168
159
|
* Each mesh contains all information given by the OBJ and the MTL file.
|
@@ -173,33 +164,32 @@ var OBJFileLoader = /** @class */ (function () {
|
|
173
164
|
* @param rootUrl defines the path to the folder
|
174
165
|
* @returns the list of loaded meshes
|
175
166
|
*/
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
var babylonMeshesArray = []; //The mesh for babylon
|
167
|
+
_parseSolid(meshesNames, scene, data, rootUrl) {
|
168
|
+
let fileToLoad = ""; //The name of the mtlFile to load
|
169
|
+
const materialsFromMTLFile = new MTLFileLoader();
|
170
|
+
const materialToUse = new Array();
|
171
|
+
const babylonMeshesArray = []; //The mesh for babylon
|
182
172
|
// Main function
|
183
|
-
|
184
|
-
solidParser.parse(meshesNames, data, scene, this._assetContainer,
|
173
|
+
const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);
|
174
|
+
solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName) => {
|
185
175
|
fileToLoad = fileName;
|
186
176
|
});
|
187
177
|
// load the materials
|
188
|
-
|
178
|
+
const mtlPromises = [];
|
189
179
|
// Check if we have a file to load
|
190
180
|
if (fileToLoad !== "" && !this._loadingOptions.skipMaterials) {
|
191
181
|
//Load the file synchronously
|
192
|
-
mtlPromises.push(new Promise(
|
193
|
-
|
182
|
+
mtlPromises.push(new Promise((resolve, reject) => {
|
183
|
+
this._loadMTL(fileToLoad, rootUrl, (dataLoaded) => {
|
194
184
|
try {
|
195
185
|
//Create materials thanks MTLLoader function
|
196
|
-
materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl,
|
186
|
+
materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);
|
197
187
|
//Look at each material loaded in the mtl file
|
198
|
-
for (
|
188
|
+
for (let n = 0; n < materialsFromMTLFile.materials.length; n++) {
|
199
189
|
//Three variables to get all meshes with the same material
|
200
|
-
|
201
|
-
|
202
|
-
|
190
|
+
let startIndex = 0;
|
191
|
+
const _indices = [];
|
192
|
+
let _index;
|
203
193
|
//The material from MTL file is used in the meshes loaded
|
204
194
|
//Push the indice in an array
|
205
195
|
//Check if the material is not used for another mesh
|
@@ -213,10 +203,10 @@ var OBJFileLoader = /** @class */ (function () {
|
|
213
203
|
materialsFromMTLFile.materials[n].dispose();
|
214
204
|
}
|
215
205
|
else {
|
216
|
-
for (
|
206
|
+
for (let o = 0; o < _indices.length; o++) {
|
217
207
|
//Apply the material to the Mesh for each mesh with the material
|
218
|
-
|
219
|
-
|
208
|
+
const mesh = babylonMeshesArray[_indices[o]];
|
209
|
+
const material = materialsFromMTLFile.materials[n];
|
220
210
|
mesh.material = material;
|
221
211
|
if (!mesh.getTotalIndices()) {
|
222
212
|
// No indices, we need to turn on point cloud
|
@@ -228,17 +218,17 @@ var OBJFileLoader = /** @class */ (function () {
|
|
228
218
|
resolve();
|
229
219
|
}
|
230
220
|
catch (e) {
|
231
|
-
Tools.Warn(
|
232
|
-
if (
|
221
|
+
Tools.Warn(`Error processing MTL file: '${fileToLoad}'`);
|
222
|
+
if (this._loadingOptions.materialLoadingFailsSilently) {
|
233
223
|
resolve();
|
234
224
|
}
|
235
225
|
else {
|
236
226
|
reject(e);
|
237
227
|
}
|
238
228
|
}
|
239
|
-
},
|
240
|
-
Tools.Warn(
|
241
|
-
if (
|
229
|
+
}, (pathOfFile, exception) => {
|
230
|
+
Tools.Warn(`Error downloading MTL file: '${fileToLoad}'`);
|
231
|
+
if (this._loadingOptions.materialLoadingFailsSilently) {
|
242
232
|
resolve();
|
243
233
|
}
|
244
234
|
else {
|
@@ -248,48 +238,46 @@ var OBJFileLoader = /** @class */ (function () {
|
|
248
238
|
}));
|
249
239
|
}
|
250
240
|
//Return an array with all Mesh
|
251
|
-
return Promise.all(mtlPromises).then(
|
241
|
+
return Promise.all(mtlPromises).then(() => {
|
252
242
|
return babylonMeshesArray;
|
253
243
|
});
|
254
|
-
}
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
}());
|
292
|
-
export { OBJFileLoader };
|
244
|
+
}
|
245
|
+
}
|
246
|
+
/**
|
247
|
+
* Defines if UVs are optimized by default during load.
|
248
|
+
*/
|
249
|
+
OBJFileLoader.OPTIMIZE_WITH_UV = true;
|
250
|
+
/**
|
251
|
+
* Invert model on y-axis (does a model scaling inversion)
|
252
|
+
*/
|
253
|
+
OBJFileLoader.INVERT_Y = false;
|
254
|
+
/**
|
255
|
+
* Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
|
256
|
+
*/
|
257
|
+
OBJFileLoader.IMPORT_VERTEX_COLORS = false;
|
258
|
+
/**
|
259
|
+
* Compute the normals for the model, even if normals are present in the file.
|
260
|
+
*/
|
261
|
+
OBJFileLoader.COMPUTE_NORMALS = false;
|
262
|
+
/**
|
263
|
+
* 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.
|
264
|
+
* Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.
|
265
|
+
*/
|
266
|
+
OBJFileLoader.OPTIMIZE_NORMALS = false;
|
267
|
+
/**
|
268
|
+
* Defines custom scaling of UV coordinates of loaded meshes.
|
269
|
+
*/
|
270
|
+
OBJFileLoader.UV_SCALING = new Vector2(1, 1);
|
271
|
+
/**
|
272
|
+
* Skip loading the materials even if defined in the OBJ file (materials are ignored).
|
273
|
+
*/
|
274
|
+
OBJFileLoader.SKIP_MATERIALS = false;
|
275
|
+
/**
|
276
|
+
* When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
|
277
|
+
*
|
278
|
+
* Defaults to true for backwards compatibility.
|
279
|
+
*/
|
280
|
+
OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
|
293
281
|
if (SceneLoader) {
|
294
282
|
//Add this loader into the register plugin
|
295
283
|
SceneLoader.RegisterPlugin(new OBJFileLoader());
|