@babylonjs/loaders 7.20.1 → 7.21.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/objFileLoader.js +3 -5
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/solidParser.d.ts +3 -0
- package/OBJ/solidParser.js +43 -5
- package/OBJ/solidParser.js.map +1 -1
- package/SPLAT/splatFileLoader.js +3 -5
- package/SPLAT/splatFileLoader.js.map +1 -1
- package/STL/stlFileLoader.js +2 -4
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +1 -3
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +40 -3
- package/glTF/glTFFileLoader.js +46 -17
- package/glTF/glTFFileLoader.js.map +1 -1
- package/package.json +3 -3
package/OBJ/objFileLoader.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Vector2 } from "@babylonjs/core/Maths/math.vector.js";
|
2
2
|
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
3
|
-
import {
|
3
|
+
import { registerSceneLoaderPlugin } from "@babylonjs/core/Loading/sceneLoader.js";
|
4
4
|
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
5
|
import { MTLFileLoader } from "./mtlFileLoader.js";
|
6
6
|
import { SolidParser } from "./solidParser.js";
|
@@ -306,8 +306,6 @@ OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
|
|
306
306
|
* Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.
|
307
307
|
*/
|
308
308
|
OBJFileLoader.USE_LEGACY_BEHAVIOR = false;
|
309
|
-
|
310
|
-
|
311
|
-
SceneLoader.RegisterPlugin(new OBJFileLoader());
|
312
|
-
}
|
309
|
+
//Add this loader into the register plugin
|
310
|
+
registerSceneLoaderPlugin(new OBJFileLoader());
|
313
311
|
//# sourceMappingURL=objFileLoader.js.map
|
package/OBJ/objFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|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E,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;oBAC7E,IAAI,SAAS,EAAE;wBACX,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC;qBAC9C;oBACD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;oBACrB,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC;oBACpB,IAAI,IAAI,CAAC,iBAAiB,EAAE;wBACxB,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;qBACjD;iBACJ;YACL,CAAC,CAAC,CAAC;YAEH,OAAO,kBAAkB,CAAC;QAC9B,CAAC,CAAC,CAAC;IACP,CAAC;;AAxUD;;GAEG;AACW,8BAAgB,GAAG,IAAI,AAAP,CAAQ;AACtC;;GAEG;AACW,sBAAQ,GAAG,KAAK,AAAR,CAAS;AAY/B;;GAEG;AACW,kCAAoB,GAAG,KAAK,AAAR,CAAS;AAC3C;;GAEG;AACW,6BAAe,GAAG,KAAK,AAAR,CAAS;AACtC;;;GAGG;AACW,8BAAgB,GAAG,KAAK,AAAR,CAAS;AACvC;;GAEG;AACW,wBAAU,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,AAApB,CAAqB;AAC7C;;GAEG;AACW,4BAAc,GAAG,KAAK,AAAR,CAAS;AAErC;;;;GAIG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ;AAErD;;GAEG;AACW,iCAAmB,GAAG,KAAK,AAAR,CAAS;AAwR9C,IAAI,WAAW,EAAE;IACb,0CAA0C;IAC1C,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { WebRequest } from \"core/Misc/webRequest\";\r\nimport { MTLFileLoader } from \"./mtlFileLoader\";\r\nimport type { OBJLoadingOptions } from \"./objLoadingOptions\";\r\nimport { SolidParser } from \"./solidParser\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst PLUGIN_OBJ = \"obj\";\r\n\r\ndeclare module \"core/Loading/sceneLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface SceneLoaderPluginOptions {\r\n /**\r\n * Defines options for the obj loader.\r\n */\r\n [PLUGIN_OBJ]?: {};\r\n }\r\n}\r\n\r\n/**\r\n * OBJ file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n public static OPTIMIZE_WITH_UV = true;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n public static INVERT_Y = false;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static get INVERT_TEXTURE_Y() {\r\n return MTLFileLoader.INVERT_TEXTURE_Y;\r\n }\r\n\r\n public static set INVERT_TEXTURE_Y(value: boolean) {\r\n MTLFileLoader.INVERT_TEXTURE_Y = value;\r\n }\r\n\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 public static IMPORT_VERTEX_COLORS = false;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n public static COMPUTE_NORMALS = false;\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 public static OPTIMIZE_NORMALS = false;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n public static UV_SCALING = new Vector2(1, 1);\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n public static SKIP_MATERIALS = false;\r\n\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 * Defaults to true for backwards compatibility.\r\n */\r\n public static MATERIAL_LOADING_FAILS_SILENTLY = true;\r\n\r\n /**\r\n * Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.\r\n */\r\n public static USE_LEGACY_BEHAVIOR = false;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public readonly name = PLUGIN_OBJ;\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public readonly extensions = \".obj\";\r\n\r\n private _assetContainer: Nullable<AssetContainer> = null;\r\n\r\n private _loadingOptions: OBJLoadingOptions;\r\n\r\n /**\r\n * Creates loader for .OBJ files\r\n *\r\n * @param loadingOptions options for loading and parsing OBJ/MTL files.\r\n */\r\n constructor(loadingOptions?: OBJLoadingOptions) {\r\n this._loadingOptions = loadingOptions || OBJFileLoader._DefaultLoadingOptions;\r\n }\r\n\r\n private static get _DefaultLoadingOptions(): OBJLoadingOptions {\r\n return {\r\n computeNormals: OBJFileLoader.COMPUTE_NORMALS,\r\n optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,\r\n importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,\r\n invertY: OBJFileLoader.INVERT_Y,\r\n invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: OBJFileLoader.UV_SCALING,\r\n materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,\r\n optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,\r\n skipMaterials: OBJFileLoader.SKIP_MATERIALS,\r\n useLegacyBehavior: OBJFileLoader.USE_LEGACY_BEHAVIOR,\r\n };\r\n }\r\n\r\n /**\r\n * Calls synchronously the MTL file attached to this obj.\r\n * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.\r\n * Without this function materials are not displayed in the first frame (but displayed after).\r\n * In consequence it is impossible to get material information in your HTML file\r\n *\r\n * @param url The URL of the MTL file\r\n * @param rootUrl defines where to load data from\r\n * @param onSuccess Callback function to be called when the MTL file is loaded\r\n * @param onFailure\r\n */\r\n private _loadMTL(\r\n url: string,\r\n rootUrl: string,\r\n onSuccess: (response: string | ArrayBuffer, responseUrl?: string) => any,\r\n onFailure: (pathOfFile: string, exception?: any) => void\r\n ) {\r\n //The complete path to the mtl file\r\n const pathOfFile = rootUrl + url;\r\n\r\n // Loads through the babylon tools to allow fileInput search.\r\n Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, (request?: WebRequest | undefined, exception?: any) => {\r\n onFailure(pathOfFile, exception);\r\n });\r\n }\r\n\r\n /**\r\n * Instantiates a OBJ file loader plugin.\r\n * @returns the created plugin\r\n */\r\n createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new OBJFileLoader(OBJFileLoader._DefaultLoadingOptions);\r\n }\r\n\r\n /**\r\n * If the data string can be loaded directly.\r\n * @returns if the data can be loaded directly\r\n */\r\n public canDirectLoad(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Imports one or more meshes from the loaded OBJ data and adds them to the scene\r\n * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n //get the meshes from OBJ file\r\n return this._parseSolid(meshesNames, scene, data, rootUrl).then((meshes) => {\r\n return {\r\n meshes: meshes,\r\n particleSystems: [],\r\n skeletons: [],\r\n animationGroups: [],\r\n transformNodes: [],\r\n geometries: [],\r\n lights: [],\r\n spriteManagers: [],\r\n };\r\n });\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded OBJ data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n public loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n return this.importMeshAsync(null, scene, data, rootUrl).then(() => {\r\n // return void\r\n });\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer> {\r\n const container = new AssetContainer(scene);\r\n this._assetContainer = container;\r\n\r\n return this.importMeshAsync(null, scene, data, rootUrl)\r\n .then((result) => {\r\n result.meshes.forEach((mesh) => container.meshes.push(mesh));\r\n result.meshes.forEach((mesh) => {\r\n const material = mesh.material;\r\n if (material) {\r\n // Materials\r\n if (container.materials.indexOf(material) == -1) {\r\n container.materials.push(material);\r\n\r\n // Textures\r\n const textures = material.getActiveTextures();\r\n textures.forEach((t) => {\r\n if (container.textures.indexOf(t) == -1) {\r\n container.textures.push(t);\r\n }\r\n });\r\n }\r\n }\r\n });\r\n this._assetContainer = null;\r\n return container;\r\n })\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n });\r\n }\r\n\r\n /**\r\n * Read the OBJ file and create an Array of meshes.\r\n * Each mesh contains all information given by the OBJ and the MTL file.\r\n * i.e. vertices positions and indices, optional normals values, optional UV values, optional material\r\n * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene defines the scene where are displayed the data\r\n * @param data defines the content of the obj file\r\n * @param rootUrl defines the path to the folder\r\n * @returns the list of loaded meshes\r\n */\r\n private _parseSolid(meshesNames: any, scene: Scene, data: string, rootUrl: string): Promise<Array<AbstractMesh>> {\r\n let fileToLoad: string = \"\"; //The name of the mtlFile to load\r\n const materialsFromMTLFile: MTLFileLoader = new MTLFileLoader();\r\n const materialToUse: string[] = [];\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\r\n\r\n // Sanitize data\r\n data = data.replace(/#.*$/gm, \"\").trim();\r\n\r\n // Main function\r\n const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);\r\n\r\n solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName: string) => {\r\n fileToLoad = fileName;\r\n });\r\n\r\n // load the materials\r\n const mtlPromises: Array<Promise<void>> = [];\r\n // Check if we have a file to load\r\n if (fileToLoad !== \"\" && !this._loadingOptions.skipMaterials) {\r\n //Load the file synchronously\r\n mtlPromises.push(\r\n new Promise((resolve, reject) => {\r\n this._loadMTL(\r\n fileToLoad,\r\n rootUrl,\r\n (dataLoaded) => {\r\n try {\r\n //Create materials thanks MTLLoader function\r\n materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);\r\n //Look at each material loaded in the mtl file\r\n for (let n = 0; n < materialsFromMTLFile.materials.length; n++) {\r\n //Three variables to get all meshes with the same material\r\n let startIndex = 0;\r\n const _indices = [];\r\n let _index;\r\n\r\n //The material from MTL file is used in the meshes loaded\r\n //Push the indice in an array\r\n //Check if the material is not used for another mesh\r\n while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {\r\n _indices.push(_index);\r\n startIndex = _index + 1;\r\n }\r\n //If the material is not used dispose it\r\n if (_index === -1 && _indices.length === 0) {\r\n //If the material is not needed, remove it\r\n materialsFromMTLFile.materials[n].dispose();\r\n } else {\r\n for (let o = 0; o < _indices.length; o++) {\r\n //Apply the material to the Mesh for each mesh with the material\r\n const mesh = babylonMeshesArray[_indices[o]];\r\n const material = materialsFromMTLFile.materials[n];\r\n mesh.material = material;\r\n\r\n if (!mesh.getTotalIndices()) {\r\n // No indices, we need to turn on point cloud\r\n material.pointsCloud = true;\r\n }\r\n }\r\n }\r\n }\r\n resolve();\r\n } catch (e) {\r\n Tools.Warn(`Error processing MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n reject(e);\r\n }\r\n }\r\n },\r\n (pathOfFile: string, exception?: any) => {\r\n Tools.Warn(`Error downloading MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n reject(exception);\r\n }\r\n }\r\n );\r\n })\r\n );\r\n }\r\n //Return an array with all Mesh\r\n return Promise.all(mtlPromises).then(() => {\r\n const isLine = (mesh: AbstractMesh) => Boolean(mesh._internalMetadata?.[\"_isLine\"] ?? false);\r\n\r\n // Iterate over the mesh, determine if it is a line mesh, clone or modify the material to line rendering.\r\n babylonMeshesArray.forEach((mesh) => {\r\n if (isLine(mesh)) {\r\n let mat = mesh.material ?? new StandardMaterial(mesh.name + \"_line\", scene);\r\n // If another mesh is using this material and it is not a line then we need to clone it.\r\n const needClone = mat.getBindedMeshes().filter((e) => !isLine(e)).length > 0;\r\n if (needClone) {\r\n mat = mat.clone(mat.name + \"_line\") ?? mat;\r\n }\r\n mat.wireframe = true;\r\n mesh.material = mat;\r\n if (mesh._internalMetadata) {\r\n mesh._internalMetadata[\"_isLine\"] = undefined;\r\n }\r\n }\r\n });\r\n\r\n return babylonMeshesArray;\r\n });\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n //Add this loader into the register plugin\r\n SceneLoader.RegisterPlugin(new OBJFileLoader());\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"objFileLoader.js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AC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;oBAC7E,IAAI,SAAS,EAAE;wBACX,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC;qBAC9C;oBACD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;oBACrB,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC;oBACpB,IAAI,IAAI,CAAC,iBAAiB,EAAE;wBACxB,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;qBACjD;iBACJ;YACL,CAAC,CAAC,CAAC;YAEH,OAAO,kBAAkB,CAAC;QAC9B,CAAC,CAAC,CAAC;IACP,CAAC;;AAxUD;;GAEG;AACW,8BAAgB,GAAG,IAAI,AAAP,CAAQ;AACtC;;GAEG;AACW,sBAAQ,GAAG,KAAK,AAAR,CAAS;AAY/B;;GAEG;AACW,kCAAoB,GAAG,KAAK,AAAR,CAAS;AAC3C;;GAEG;AACW,6BAAe,GAAG,KAAK,AAAR,CAAS;AACtC;;;GAGG;AACW,8BAAgB,GAAG,KAAK,AAAR,CAAS;AACvC;;GAEG;AACW,wBAAU,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,AAApB,CAAqB;AAC7C;;GAEG;AACW,4BAAc,GAAG,KAAK,AAAR,CAAS;AAErC;;;;GAIG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ;AAErD;;GAEG;AACW,iCAAmB,GAAG,KAAK,AAAR,CAAS;AAwR9C,0CAA0C;AAC1C,yBAAyB,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult } from \"core/Loading/sceneLoader\";\r\nimport { registerSceneLoaderPlugin } from \"core/Loading/sceneLoader\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { WebRequest } from \"core/Misc/webRequest\";\r\nimport { MTLFileLoader } from \"./mtlFileLoader\";\r\nimport type { OBJLoadingOptions } from \"./objLoadingOptions\";\r\nimport { SolidParser } from \"./solidParser\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst PLUGIN_OBJ = \"obj\";\r\n\r\ndeclare module \"core/Loading/sceneLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface SceneLoaderPluginOptions {\r\n /**\r\n * Defines options for the obj loader.\r\n */\r\n [PLUGIN_OBJ]?: {};\r\n }\r\n}\r\n\r\n/**\r\n * OBJ file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n public static OPTIMIZE_WITH_UV = true;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n public static INVERT_Y = false;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static get INVERT_TEXTURE_Y() {\r\n return MTLFileLoader.INVERT_TEXTURE_Y;\r\n }\r\n\r\n public static set INVERT_TEXTURE_Y(value: boolean) {\r\n MTLFileLoader.INVERT_TEXTURE_Y = value;\r\n }\r\n\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 public static IMPORT_VERTEX_COLORS = false;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n public static COMPUTE_NORMALS = false;\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 public static OPTIMIZE_NORMALS = false;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n public static UV_SCALING = new Vector2(1, 1);\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n public static SKIP_MATERIALS = false;\r\n\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 * Defaults to true for backwards compatibility.\r\n */\r\n public static MATERIAL_LOADING_FAILS_SILENTLY = true;\r\n\r\n /**\r\n * Loads assets without handedness conversions. This flag is for compatibility. Use it only if absolutely required. Defaults to false.\r\n */\r\n public static USE_LEGACY_BEHAVIOR = false;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public readonly name = PLUGIN_OBJ;\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public readonly extensions = \".obj\";\r\n\r\n private _assetContainer: Nullable<AssetContainer> = null;\r\n\r\n private _loadingOptions: OBJLoadingOptions;\r\n\r\n /**\r\n * Creates loader for .OBJ files\r\n *\r\n * @param loadingOptions options for loading and parsing OBJ/MTL files.\r\n */\r\n constructor(loadingOptions?: OBJLoadingOptions) {\r\n this._loadingOptions = loadingOptions || OBJFileLoader._DefaultLoadingOptions;\r\n }\r\n\r\n private static get _DefaultLoadingOptions(): OBJLoadingOptions {\r\n return {\r\n computeNormals: OBJFileLoader.COMPUTE_NORMALS,\r\n optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,\r\n importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,\r\n invertY: OBJFileLoader.INVERT_Y,\r\n invertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: OBJFileLoader.UV_SCALING,\r\n materialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,\r\n optimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,\r\n skipMaterials: OBJFileLoader.SKIP_MATERIALS,\r\n useLegacyBehavior: OBJFileLoader.USE_LEGACY_BEHAVIOR,\r\n };\r\n }\r\n\r\n /**\r\n * Calls synchronously the MTL file attached to this obj.\r\n * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.\r\n * Without this function materials are not displayed in the first frame (but displayed after).\r\n * In consequence it is impossible to get material information in your HTML file\r\n *\r\n * @param url The URL of the MTL file\r\n * @param rootUrl defines where to load data from\r\n * @param onSuccess Callback function to be called when the MTL file is loaded\r\n * @param onFailure\r\n */\r\n private _loadMTL(\r\n url: string,\r\n rootUrl: string,\r\n onSuccess: (response: string | ArrayBuffer, responseUrl?: string) => any,\r\n onFailure: (pathOfFile: string, exception?: any) => void\r\n ) {\r\n //The complete path to the mtl file\r\n const pathOfFile = rootUrl + url;\r\n\r\n // Loads through the babylon tools to allow fileInput search.\r\n Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, false, (request?: WebRequest | undefined, exception?: any) => {\r\n onFailure(pathOfFile, exception);\r\n });\r\n }\r\n\r\n /**\r\n * Instantiates a OBJ file loader plugin.\r\n * @returns the created plugin\r\n */\r\n createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new OBJFileLoader(OBJFileLoader._DefaultLoadingOptions);\r\n }\r\n\r\n /**\r\n * If the data string can be loaded directly.\r\n * @returns if the data can be loaded directly\r\n */\r\n public canDirectLoad(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Imports one or more meshes from the loaded OBJ data and adds them to the scene\r\n * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n //get the meshes from OBJ file\r\n return this._parseSolid(meshesNames, scene, data, rootUrl).then((meshes) => {\r\n return {\r\n meshes: meshes,\r\n particleSystems: [],\r\n skeletons: [],\r\n animationGroups: [],\r\n transformNodes: [],\r\n geometries: [],\r\n lights: [],\r\n spriteManagers: [],\r\n };\r\n });\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded OBJ data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n public loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n return this.importMeshAsync(null, scene, data, rootUrl).then(() => {\r\n // return void\r\n });\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer> {\r\n const container = new AssetContainer(scene);\r\n this._assetContainer = container;\r\n\r\n return this.importMeshAsync(null, scene, data, rootUrl)\r\n .then((result) => {\r\n result.meshes.forEach((mesh) => container.meshes.push(mesh));\r\n result.meshes.forEach((mesh) => {\r\n const material = mesh.material;\r\n if (material) {\r\n // Materials\r\n if (container.materials.indexOf(material) == -1) {\r\n container.materials.push(material);\r\n\r\n // Textures\r\n const textures = material.getActiveTextures();\r\n textures.forEach((t) => {\r\n if (container.textures.indexOf(t) == -1) {\r\n container.textures.push(t);\r\n }\r\n });\r\n }\r\n }\r\n });\r\n this._assetContainer = null;\r\n return container;\r\n })\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n });\r\n }\r\n\r\n /**\r\n * Read the OBJ file and create an Array of meshes.\r\n * Each mesh contains all information given by the OBJ and the MTL file.\r\n * i.e. vertices positions and indices, optional normals values, optional UV values, optional material\r\n * @param meshesNames defines a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene defines the scene where are displayed the data\r\n * @param data defines the content of the obj file\r\n * @param rootUrl defines the path to the folder\r\n * @returns the list of loaded meshes\r\n */\r\n private _parseSolid(meshesNames: any, scene: Scene, data: string, rootUrl: string): Promise<Array<AbstractMesh>> {\r\n let fileToLoad: string = \"\"; //The name of the mtlFile to load\r\n const materialsFromMTLFile: MTLFileLoader = new MTLFileLoader();\r\n const materialToUse: string[] = [];\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\r\n\r\n // Sanitize data\r\n data = data.replace(/#.*$/gm, \"\").trim();\r\n\r\n // Main function\r\n const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);\r\n\r\n solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName: string) => {\r\n fileToLoad = fileName;\r\n });\r\n\r\n // load the materials\r\n const mtlPromises: Array<Promise<void>> = [];\r\n // Check if we have a file to load\r\n if (fileToLoad !== \"\" && !this._loadingOptions.skipMaterials) {\r\n //Load the file synchronously\r\n mtlPromises.push(\r\n new Promise((resolve, reject) => {\r\n this._loadMTL(\r\n fileToLoad,\r\n rootUrl,\r\n (dataLoaded) => {\r\n try {\r\n //Create materials thanks MTLLoader function\r\n materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);\r\n //Look at each material loaded in the mtl file\r\n for (let n = 0; n < materialsFromMTLFile.materials.length; n++) {\r\n //Three variables to get all meshes with the same material\r\n let startIndex = 0;\r\n const _indices = [];\r\n let _index;\r\n\r\n //The material from MTL file is used in the meshes loaded\r\n //Push the indice in an array\r\n //Check if the material is not used for another mesh\r\n while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {\r\n _indices.push(_index);\r\n startIndex = _index + 1;\r\n }\r\n //If the material is not used dispose it\r\n if (_index === -1 && _indices.length === 0) {\r\n //If the material is not needed, remove it\r\n materialsFromMTLFile.materials[n].dispose();\r\n } else {\r\n for (let o = 0; o < _indices.length; o++) {\r\n //Apply the material to the Mesh for each mesh with the material\r\n const mesh = babylonMeshesArray[_indices[o]];\r\n const material = materialsFromMTLFile.materials[n];\r\n mesh.material = material;\r\n\r\n if (!mesh.getTotalIndices()) {\r\n // No indices, we need to turn on point cloud\r\n material.pointsCloud = true;\r\n }\r\n }\r\n }\r\n }\r\n resolve();\r\n } catch (e) {\r\n Tools.Warn(`Error processing MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n reject(e);\r\n }\r\n }\r\n },\r\n (pathOfFile: string, exception?: any) => {\r\n Tools.Warn(`Error downloading MTL file: '${fileToLoad}'`);\r\n if (this._loadingOptions.materialLoadingFailsSilently) {\r\n resolve();\r\n } else {\r\n reject(exception);\r\n }\r\n }\r\n );\r\n })\r\n );\r\n }\r\n //Return an array with all Mesh\r\n return Promise.all(mtlPromises).then(() => {\r\n const isLine = (mesh: AbstractMesh) => Boolean(mesh._internalMetadata?.[\"_isLine\"] ?? false);\r\n\r\n // Iterate over the mesh, determine if it is a line mesh, clone or modify the material to line rendering.\r\n babylonMeshesArray.forEach((mesh) => {\r\n if (isLine(mesh)) {\r\n let mat = mesh.material ?? new StandardMaterial(mesh.name + \"_line\", scene);\r\n // If another mesh is using this material and it is not a line then we need to clone it.\r\n const needClone = mat.getBindedMeshes().filter((e) => !isLine(e)).length > 0;\r\n if (needClone) {\r\n mat = mat.clone(mat.name + \"_line\") ?? mat;\r\n }\r\n mat.wireframe = true;\r\n mesh.material = mat;\r\n if (mesh._internalMetadata) {\r\n mesh._internalMetadata[\"_isLine\"] = undefined;\r\n }\r\n }\r\n });\r\n\r\n return babylonMeshesArray;\r\n });\r\n }\r\n}\r\n\r\n//Add this loader into the register plugin\r\nregisterSceneLoaderPlugin(new OBJFileLoader());\r\n"]}
|
package/OBJ/solidParser.d.ts
CHANGED
@@ -151,6 +151,9 @@ export declare class SolidParser {
|
|
151
151
|
private _setDataForCurrentFaceWithPattern5;
|
152
152
|
private _addPreviousObjMesh;
|
153
153
|
private _optimizeNormals;
|
154
|
+
private static _IsLineElement;
|
155
|
+
private static _IsObjectElement;
|
156
|
+
private static _IsGroupElement;
|
154
157
|
/**
|
155
158
|
* Function used to parse an OBJ string
|
156
159
|
* @param meshesNames defines the list of meshes to load (all if not defined)
|
package/OBJ/solidParser.js
CHANGED
@@ -104,7 +104,9 @@ export class SolidParser {
|
|
104
104
|
//Each element is a Vector3(x,y,z)
|
105
105
|
this._wrappedPositionForBabylon.push(positionVectorFromOBJ);
|
106
106
|
//Push the uvs for Babylon
|
107
|
-
//Each element is a
|
107
|
+
//Each element is a Vector2(u,v)
|
108
|
+
//If the UVs are missing, set (u,v)=(0,0)
|
109
|
+
textureVectorFromOBJ = textureVectorFromOBJ ?? new Vector2(0, 0);
|
108
110
|
this._wrappedUvsForBabylon.push(textureVectorFromOBJ);
|
109
111
|
//Push the normals for Babylon
|
110
112
|
//Each element is a Vector3(x,y,z)
|
@@ -218,7 +220,7 @@ export class SolidParser {
|
|
218
220
|
const indiceUvsFromObj = parseInt(point[1]) - 1;
|
219
221
|
this._setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
|
220
222
|
this._positions[indicePositionFromObj], //Get the values for each element
|
221
|
-
this._uvs[indiceUvsFromObj], Vector3.Up(), //Default value for normals
|
223
|
+
this._uvs[indiceUvsFromObj] ?? Vector2.Zero(), Vector3.Up(), //Default value for normals
|
222
224
|
this._loadingOptions.importVertexColors ? this._colors[indicePositionFromObj] : undefined);
|
223
225
|
}
|
224
226
|
//Reset variable for the next line
|
@@ -243,7 +245,7 @@ export class SolidParser {
|
|
243
245
|
const indiceUvsFromObj = parseInt(point[1]) - 1;
|
244
246
|
// Set normal indice
|
245
247
|
const indiceNormalFromObj = parseInt(point[2]) - 1;
|
246
|
-
this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj], this._normals[indiceNormalFromObj] //Set the vector for each component
|
248
|
+
this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj] ?? Vector2.Zero(), this._normals[indiceNormalFromObj] ?? Vector3.Up() //Set the vector for each component
|
247
249
|
);
|
248
250
|
}
|
249
251
|
//Reset variable for the next line
|
@@ -370,6 +372,15 @@ export class SolidParser {
|
|
370
372
|
}
|
371
373
|
mesh.setVerticesData(VertexBuffer.NormalKind, normals);
|
372
374
|
}
|
375
|
+
static _IsLineElement(line) {
|
376
|
+
return line.startsWith("l");
|
377
|
+
}
|
378
|
+
static _IsObjectElement(line) {
|
379
|
+
return line.startsWith("o");
|
380
|
+
}
|
381
|
+
static _IsGroupElement(line) {
|
382
|
+
return line.startsWith("g");
|
383
|
+
}
|
373
384
|
/**
|
374
385
|
* Function used to parse an OBJ string
|
375
386
|
* @param meshesNames defines the list of meshes to load (all if not defined)
|
@@ -392,7 +403,33 @@ export class SolidParser {
|
|
392
403
|
this._handednessSign = -1;
|
393
404
|
}
|
394
405
|
// Split the file into lines
|
395
|
-
|
406
|
+
// Preprocess line data
|
407
|
+
const linesOBJ = data.split("\n");
|
408
|
+
const lineLines = [];
|
409
|
+
let currentGroup = [];
|
410
|
+
lineLines.push(currentGroup);
|
411
|
+
for (let i = 0; i < linesOBJ.length; i++) {
|
412
|
+
const line = linesOBJ[i].trim().replace(/\s\s/g, " ");
|
413
|
+
// Comment or newLine
|
414
|
+
if (line.length === 0 || line.charAt(0) === "#") {
|
415
|
+
continue;
|
416
|
+
}
|
417
|
+
if (SolidParser._IsGroupElement(line) || SolidParser._IsObjectElement(line)) {
|
418
|
+
currentGroup = [];
|
419
|
+
lineLines.push(currentGroup);
|
420
|
+
}
|
421
|
+
if (SolidParser._IsLineElement(line)) {
|
422
|
+
const lineValues = line.split(" ");
|
423
|
+
// create line elements with two vertices only
|
424
|
+
for (let i = 1; i < lineValues.length - 1; i++) {
|
425
|
+
currentGroup.push(`l ${lineValues[i]} ${lineValues[i + 1]}`);
|
426
|
+
}
|
427
|
+
}
|
428
|
+
else {
|
429
|
+
currentGroup.push(line);
|
430
|
+
}
|
431
|
+
}
|
432
|
+
const lines = lineLines.flat();
|
396
433
|
// Look at each line
|
397
434
|
for (let i = 0; i < lines.length; i++) {
|
398
435
|
const line = lines[i].trim().replace(/\s\s/g, " ");
|
@@ -400,9 +437,9 @@ export class SolidParser {
|
|
400
437
|
// Comment or newLine
|
401
438
|
if (line.length === 0 || line.charAt(0) === "#") {
|
402
439
|
continue;
|
403
|
-
//Get information about one position possible for the vertices
|
404
440
|
}
|
405
441
|
else if (SolidParser.VertexPattern.test(line)) {
|
442
|
+
//Get information about one position possible for the vertices
|
406
443
|
result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
|
407
444
|
// Value of result with line: "v 1.0 2.0 3.0"
|
408
445
|
// ["v", "1.0", "2.0", "3.0"]
|
@@ -647,6 +684,7 @@ export class SolidParser {
|
|
647
684
|
materialName: this._materialNameFromObj,
|
648
685
|
directMaterial: newMaterial,
|
649
686
|
isObject: true,
|
687
|
+
hasLines: this._hasLineData,
|
650
688
|
});
|
651
689
|
}
|
652
690
|
//Set data for each mesh
|