@babylonjs/loaders 5.19.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/objFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"objFileLoader.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/objFileLoader.ts"],"names":[],"m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EACD,UAAC,UAAkB,EAAE,SAAe;oBAChC,KAAK,CAAC,IAAI,CAAC,uCAAgC,UAAU,MAAG,CAAC,CAAC;oBAC1D,IAAI,KAAI,CAAC,eAAe,CAAC,4BAA4B,EAAE;wBACnD,OAAO,EAAE,CAAC;qBACb;yBAAM;wBACH,MAAM,CAAC,SAAS,CAAC,CAAC;qBACrB;gBACL,CAAC,CACJ,CAAC;YACN,CAAC,CAAC,CACL,CAAC;SACL;QACD,+BAA+B;QAC/B,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;YACjC,OAAO,kBAAkB,CAAC;QAC9B,CAAC,CAAC,CAAC;IACP,CAAC;IA1SD;;OAEG;IACW,8BAAgB,GAAG,IAAI,CAAC;IACtC;;OAEG;IACW,sBAAQ,GAAG,KAAK,CAAC;IAY/B;;OAEG;IACW,kCAAoB,GAAG,KAAK,CAAC;IAC3C;;OAEG;IACW,6BAAe,GAAG,KAAK,CAAC;IACtC;;;OAGG;IACW,8BAAgB,GAAG,KAAK,CAAC;IACvC;;OAEG;IACW,wBAAU,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C;;OAEG;IACW,4BAAc,GAAG,KAAK,CAAC;IAErC;;;;OAIG;IACW,6CAA+B,GAAG,IAAI,CAAC;IA6PzD,oBAAC;CAAA,AA5SD,IA4SC;SA5SY,aAAa;AA8S1B,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\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 * Defines the name of the plugin.\r\n */\r\n public name = \"obj\";\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public 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 };\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 };\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 = new Array<string>();\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\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 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","sourceRoot":"","sources":["../../../../../lts/loaders/generated/OBJ/objFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAGxC,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;GAGG;AACH,MAAM,OAAO,aAAa;IA6DtB;;;;OAIG;IACH,YAAY,cAAkC;QAlB9C;;WAEG;QACI,SAAI,GAAG,KAAK,CAAC;QACpB;;WAEG;QACI,eAAU,GAAG,MAAM,CAAC;QAEnB,oBAAe,GAA6B,IAAI,CAAC;QAUrD,IAAI,CAAC,eAAe,GAAG,cAAc,IAAI,aAAa,CAAC,sBAAsB,CAAC;IAClF,CAAC;IA3DD;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,OAAO,aAAa,CAAC,gBAAgB,CAAC;IAC1C,CAAC;IAEM,MAAM,KAAK,gBAAgB,CAAC,KAAc;QAC7C,aAAa,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAC3C,CAAC;IAoDO,MAAM,KAAK,sBAAsB;QACrC,OAAO;YACH,cAAc,EAAE,aAAa,CAAC,eAAe;YAC7C,eAAe,EAAE,aAAa,CAAC,gBAAgB;YAC/C,kBAAkB,EAAE,aAAa,CAAC,oBAAoB;YACtD,OAAO,EAAE,aAAa,CAAC,QAAQ;YAC/B,cAAc,EAAE,aAAa,CAAC,gBAAgB;YAC9C,gEAAgE;YAChE,SAAS,EAAE,aAAa,CAAC,UAAU;YACnC,4BAA4B,EAAE,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/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\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 * Defines the name of the plugin.\r\n */\r\n public name = \"obj\";\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public 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 };\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 };\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 = new Array<string>();\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\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 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"]}
|
package/OBJ/solidParser.js
CHANGED
@@ -8,14 +8,14 @@ import { VertexData } from "@babylonjs/core/Meshes/mesh.vertexData.js";
|
|
8
8
|
/**
|
9
9
|
* Class used to load mesh data from OBJ content
|
10
10
|
*/
|
11
|
-
|
11
|
+
export class SolidParser {
|
12
12
|
/**
|
13
13
|
* Creates a new SolidParser
|
14
14
|
* @param materialToUse defines the array to fill with the list of materials to use (it will be filled by the parse function)
|
15
15
|
* @param babylonMeshesArray defines the array to fill with the list of loaded meshes (it will be filled by the parse function)
|
16
16
|
* @param loadingOptions defines the loading options to use
|
17
17
|
*/
|
18
|
-
|
18
|
+
constructor(materialToUse, babylonMeshesArray, loadingOptions) {
|
19
19
|
this._positions = []; //values for the positions of vertices
|
20
20
|
this._normals = []; //Values for the normals
|
21
21
|
this._uvs = []; //Values for the textures
|
@@ -52,23 +52,23 @@ var SolidParser = /** @class */ (function () {
|
|
52
52
|
* @param obj Array<number>
|
53
53
|
* @returns {boolean}
|
54
54
|
*/
|
55
|
-
|
55
|
+
_isInArray(arr, obj) {
|
56
56
|
if (!arr[obj[0]]) {
|
57
57
|
arr[obj[0]] = { normals: [], idx: [] };
|
58
58
|
}
|
59
|
-
|
59
|
+
const idx = arr[obj[0]].normals.indexOf(obj[1]);
|
60
60
|
return idx === -1 ? -1 : arr[obj[0]].idx[idx];
|
61
|
-
}
|
62
|
-
|
61
|
+
}
|
62
|
+
_isInArrayUV(arr, obj) {
|
63
63
|
if (!arr[obj[0]]) {
|
64
64
|
arr[obj[0]] = { normals: [], idx: [], uv: [] };
|
65
65
|
}
|
66
|
-
|
66
|
+
const idx = arr[obj[0]].normals.indexOf(obj[1]);
|
67
67
|
if (idx != 1 && obj[2] === arr[obj[0]].uv[idx]) {
|
68
68
|
return arr[obj[0]].idx[idx];
|
69
69
|
}
|
70
70
|
return -1;
|
71
|
-
}
|
71
|
+
}
|
72
72
|
/**
|
73
73
|
* This function set the data for each triangle.
|
74
74
|
* Data are position, normals and uvs
|
@@ -83,9 +83,9 @@ var SolidParser = /** @class */ (function () {
|
|
83
83
|
* @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
|
84
84
|
* @param positionColorsFromOBJ
|
85
85
|
*/
|
86
|
-
|
86
|
+
_setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
|
87
87
|
//Check if this tuple already exists in the list of tuples
|
88
|
-
|
88
|
+
let _index;
|
89
89
|
if (this._loadingOptions.optimizeWithUV) {
|
90
90
|
_index = this._isInArrayUV(this._tuplePosNorm, [indicePositionFromObj, indiceNormalFromObj, indiceUvsFromObj]);
|
91
91
|
}
|
@@ -125,13 +125,13 @@ var SolidParser = /** @class */ (function () {
|
|
125
125
|
//At this index we can get the value of position, normal, color and uvs of vertex
|
126
126
|
this._indicesForBabylon.push(_index);
|
127
127
|
}
|
128
|
-
}
|
128
|
+
}
|
129
129
|
/**
|
130
130
|
* Transform Vector() and BABYLON.Color() objects into numbers in an array
|
131
131
|
*/
|
132
|
-
|
132
|
+
_unwrapData() {
|
133
133
|
//Every array has the same length
|
134
|
-
for (
|
134
|
+
for (let l = 0; l < this._wrappedPositionForBabylon.length; l++) {
|
135
135
|
//Push the x, y, z values of each element in the unwrapped array
|
136
136
|
this._unwrappedPositionsForBabylon.push(this._wrappedPositionForBabylon[l].x, this._wrappedPositionForBabylon[l].y, this._wrappedPositionForBabylon[l].z);
|
137
137
|
this._unwrappedNormalsForBabylon.push(this._wrappedNormalsForBabylon[l].x, this._wrappedNormalsForBabylon[l].y, this._wrappedNormalsForBabylon[l].z);
|
@@ -148,7 +148,7 @@ var SolidParser = /** @class */ (function () {
|
|
148
148
|
this._wrappedColorsForBabylon.length = 0;
|
149
149
|
this._tuplePosNorm.length = 0;
|
150
150
|
this._curPositionInIndices = 0;
|
151
|
-
}
|
151
|
+
}
|
152
152
|
/**
|
153
153
|
* Create triangles from polygons
|
154
154
|
* It is important to notice that a triangle is a polygon
|
@@ -162,9 +162,9 @@ var SolidParser = /** @class */ (function () {
|
|
162
162
|
* @param faces Array[String] The indices of elements
|
163
163
|
* @param v Integer The variable to increment
|
164
164
|
*/
|
165
|
-
|
165
|
+
_getTriangles(faces, v) {
|
166
166
|
//Work for each element of the array
|
167
|
-
for (
|
167
|
+
for (let faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
|
168
168
|
//Add on the triangle variable the indexes to obtain triangles
|
169
169
|
this._triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
|
170
170
|
}
|
@@ -174,21 +174,21 @@ var SolidParser = /** @class */ (function () {
|
|
174
174
|
//Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
|
175
175
|
//Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
|
176
176
|
//Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
|
177
|
-
}
|
177
|
+
}
|
178
178
|
/**
|
179
179
|
* Create triangles and push the data for each polygon for the pattern 1
|
180
180
|
* In this pattern we get vertice positions
|
181
181
|
* @param face
|
182
182
|
* @param v
|
183
183
|
*/
|
184
|
-
|
184
|
+
_setDataForCurrentFaceWithPattern1(face, v) {
|
185
185
|
//Get the indices of triangles for each polygon
|
186
186
|
this._getTriangles(face, v);
|
187
187
|
//For each element in the triangles array.
|
188
188
|
//This var could contains 1 to an infinity of triangles
|
189
|
-
for (
|
189
|
+
for (let k = 0; k < this._triangles.length; k++) {
|
190
190
|
// Set position indice
|
191
|
-
|
191
|
+
const indicePositionFromObj = parseInt(this._triangles[k]) - 1;
|
192
192
|
this._setData(indicePositionFromObj, 0, 0, // In the pattern 1, normals and uvs are not defined
|
193
193
|
this._positions[indicePositionFromObj], // Get the vectors data
|
194
194
|
Vector2.Zero(), Vector3.Up(), // Create default vectors
|
@@ -196,24 +196,24 @@ var SolidParser = /** @class */ (function () {
|
|
196
196
|
}
|
197
197
|
//Reset variable for the next line
|
198
198
|
this._triangles.length = 0;
|
199
|
-
}
|
199
|
+
}
|
200
200
|
/**
|
201
201
|
* Create triangles and push the data for each polygon for the pattern 2
|
202
202
|
* In this pattern we get vertice positions and uvsu
|
203
203
|
* @param face
|
204
204
|
* @param v
|
205
205
|
*/
|
206
|
-
|
206
|
+
_setDataForCurrentFaceWithPattern2(face, v) {
|
207
207
|
//Get the indices of triangles for each polygon
|
208
208
|
this._getTriangles(face, v);
|
209
|
-
for (
|
209
|
+
for (let k = 0; k < this._triangles.length; k++) {
|
210
210
|
//triangle[k] = "1/1"
|
211
211
|
//Split the data for getting position and uv
|
212
|
-
|
212
|
+
const point = this._triangles[k].split("/"); // ["1", "1"]
|
213
213
|
//Set position indice
|
214
|
-
|
214
|
+
const indicePositionFromObj = parseInt(point[0]) - 1;
|
215
215
|
//Set uv indice
|
216
|
-
|
216
|
+
const indiceUvsFromObj = parseInt(point[1]) - 1;
|
217
217
|
this._setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
|
218
218
|
this._positions[indicePositionFromObj], //Get the values for each element
|
219
219
|
this._uvs[indiceUvsFromObj], Vector3.Up(), //Default value for normals
|
@@ -221,80 +221,80 @@ var SolidParser = /** @class */ (function () {
|
|
221
221
|
}
|
222
222
|
//Reset variable for the next line
|
223
223
|
this._triangles.length = 0;
|
224
|
-
}
|
224
|
+
}
|
225
225
|
/**
|
226
226
|
* Create triangles and push the data for each polygon for the pattern 3
|
227
227
|
* In this pattern we get vertice positions, uvs and normals
|
228
228
|
* @param face
|
229
229
|
* @param v
|
230
230
|
*/
|
231
|
-
|
231
|
+
_setDataForCurrentFaceWithPattern3(face, v) {
|
232
232
|
//Get the indices of triangles for each polygon
|
233
233
|
this._getTriangles(face, v);
|
234
|
-
for (
|
234
|
+
for (let k = 0; k < this._triangles.length; k++) {
|
235
235
|
//triangle[k] = "1/1/1"
|
236
236
|
//Split the data for getting position, uv, and normals
|
237
|
-
|
237
|
+
const point = this._triangles[k].split("/"); // ["1", "1", "1"]
|
238
238
|
// Set position indice
|
239
|
-
|
239
|
+
const indicePositionFromObj = parseInt(point[0]) - 1;
|
240
240
|
// Set uv indice
|
241
|
-
|
241
|
+
const indiceUvsFromObj = parseInt(point[1]) - 1;
|
242
242
|
// Set normal indice
|
243
|
-
|
243
|
+
const indiceNormalFromObj = parseInt(point[2]) - 1;
|
244
244
|
this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj], this._normals[indiceNormalFromObj] //Set the vector for each component
|
245
245
|
);
|
246
246
|
}
|
247
247
|
//Reset variable for the next line
|
248
248
|
this._triangles.length = 0;
|
249
|
-
}
|
249
|
+
}
|
250
250
|
/**
|
251
251
|
* Create triangles and push the data for each polygon for the pattern 4
|
252
252
|
* In this pattern we get vertice positions and normals
|
253
253
|
* @param face
|
254
254
|
* @param v
|
255
255
|
*/
|
256
|
-
|
256
|
+
_setDataForCurrentFaceWithPattern4(face, v) {
|
257
257
|
this._getTriangles(face, v);
|
258
|
-
for (
|
258
|
+
for (let k = 0; k < this._triangles.length; k++) {
|
259
259
|
//triangle[k] = "1//1"
|
260
260
|
//Split the data for getting position and normals
|
261
|
-
|
261
|
+
const point = this._triangles[k].split("//"); // ["1", "1"]
|
262
262
|
// We check indices, and normals
|
263
|
-
|
264
|
-
|
263
|
+
const indicePositionFromObj = parseInt(point[0]) - 1;
|
264
|
+
const indiceNormalFromObj = parseInt(point[1]) - 1;
|
265
265
|
this._setData(indicePositionFromObj, 1, //Default value for uv
|
266
266
|
indiceNormalFromObj, this._positions[indicePositionFromObj], //Get each vector of data
|
267
267
|
Vector2.Zero(), this._normals[indiceNormalFromObj], this._loadingOptions.importVertexColors ? this._colors[indicePositionFromObj] : undefined);
|
268
268
|
}
|
269
269
|
//Reset variable for the next line
|
270
270
|
this._triangles.length = 0;
|
271
|
-
}
|
271
|
+
}
|
272
272
|
/*
|
273
273
|
* Create triangles and push the data for each polygon for the pattern 3
|
274
274
|
* In this pattern we get vertice positions, uvs and normals
|
275
275
|
* @param face
|
276
276
|
* @param v
|
277
277
|
*/
|
278
|
-
|
278
|
+
_setDataForCurrentFaceWithPattern5(face, v) {
|
279
279
|
//Get the indices of triangles for each polygon
|
280
280
|
this._getTriangles(face, v);
|
281
|
-
for (
|
281
|
+
for (let k = 0; k < this._triangles.length; k++) {
|
282
282
|
//triangle[k] = "-1/-1/-1"
|
283
283
|
//Split the data for getting position, uv, and normals
|
284
|
-
|
284
|
+
const point = this._triangles[k].split("/"); // ["-1", "-1", "-1"]
|
285
285
|
// Set position indice
|
286
|
-
|
286
|
+
const indicePositionFromObj = this._positions.length + parseInt(point[0]);
|
287
287
|
// Set uv indice
|
288
|
-
|
288
|
+
const indiceUvsFromObj = this._uvs.length + parseInt(point[1]);
|
289
289
|
// Set normal indice
|
290
|
-
|
290
|
+
const indiceNormalFromObj = this._normals.length + parseInt(point[2]);
|
291
291
|
this._setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, this._positions[indicePositionFromObj], this._uvs[indiceUvsFromObj], this._normals[indiceNormalFromObj], //Set the vector for each component
|
292
292
|
this._loadingOptions.importVertexColors ? this._colors[indicePositionFromObj] : undefined);
|
293
293
|
}
|
294
294
|
//Reset variable for the next line
|
295
295
|
this._triangles.length = 0;
|
296
|
-
}
|
297
|
-
|
296
|
+
}
|
297
|
+
_addPreviousObjMesh() {
|
298
298
|
//Check if it is not the first mesh. Otherwise we don't have data.
|
299
299
|
if (this._meshesFromObj.length > 0) {
|
300
300
|
//Get the previous mesh for applying the data about the faces
|
@@ -320,50 +320,50 @@ var SolidParser = /** @class */ (function () {
|
|
320
320
|
this._unwrappedNormalsForBabylon.length = 0;
|
321
321
|
this._unwrappedUVForBabylon.length = 0;
|
322
322
|
}
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
323
|
+
}
|
324
|
+
_optimizeNormals(mesh) {
|
325
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
326
|
+
const normals = mesh.getVerticesData(VertexBuffer.NormalKind);
|
327
|
+
const mapVertices = {};
|
328
328
|
if (!positions || !normals) {
|
329
329
|
return;
|
330
330
|
}
|
331
|
-
for (
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
331
|
+
for (let i = 0; i < positions.length / 3; i++) {
|
332
|
+
const x = positions[i * 3 + 0];
|
333
|
+
const y = positions[i * 3 + 1];
|
334
|
+
const z = positions[i * 3 + 2];
|
335
|
+
const key = x + "_" + y + "_" + z;
|
336
|
+
let lst = mapVertices[key];
|
337
337
|
if (!lst) {
|
338
338
|
lst = [];
|
339
339
|
mapVertices[key] = lst;
|
340
340
|
}
|
341
341
|
lst.push(i);
|
342
342
|
}
|
343
|
-
|
344
|
-
for (
|
345
|
-
|
343
|
+
const normal = new Vector3();
|
344
|
+
for (const key in mapVertices) {
|
345
|
+
const lst = mapVertices[key];
|
346
346
|
if (lst.length < 2) {
|
347
347
|
continue;
|
348
348
|
}
|
349
|
-
|
350
|
-
for (
|
351
|
-
|
349
|
+
const v0Idx = lst[0];
|
350
|
+
for (let i = 1; i < lst.length; ++i) {
|
351
|
+
const vIdx = lst[i];
|
352
352
|
normals[v0Idx * 3 + 0] += normals[vIdx * 3 + 0];
|
353
353
|
normals[v0Idx * 3 + 1] += normals[vIdx * 3 + 1];
|
354
354
|
normals[v0Idx * 3 + 2] += normals[vIdx * 3 + 2];
|
355
355
|
}
|
356
356
|
normal.copyFromFloats(normals[v0Idx * 3 + 0], normals[v0Idx * 3 + 1], normals[v0Idx * 3 + 2]);
|
357
357
|
normal.normalize();
|
358
|
-
for (
|
359
|
-
|
358
|
+
for (let i = 0; i < lst.length; ++i) {
|
359
|
+
const vIdx = lst[i];
|
360
360
|
normals[vIdx * 3 + 0] = normal.x;
|
361
361
|
normals[vIdx * 3 + 1] = normal.y;
|
362
362
|
normals[vIdx * 3 + 2] = normal.z;
|
363
363
|
}
|
364
364
|
}
|
365
365
|
mesh.setVerticesData(VertexBuffer.NormalKind, normals);
|
366
|
-
}
|
366
|
+
}
|
367
367
|
/**
|
368
368
|
* Function used to parse an OBJ string
|
369
369
|
* @param meshesNames defines the list of meshes to load (all if not defined)
|
@@ -372,14 +372,13 @@ var SolidParser = /** @class */ (function () {
|
|
372
372
|
* @param assetContainer defines the asset container to load data in
|
373
373
|
* @param onFileToLoadFound defines a callback that will be called if a MTL file is found
|
374
374
|
*/
|
375
|
-
|
376
|
-
var _a;
|
375
|
+
parse(meshesNames, data, scene, assetContainer, onFileToLoadFound) {
|
377
376
|
// Split the file into lines
|
378
|
-
|
377
|
+
const lines = data.split("\n");
|
379
378
|
// Look at each line
|
380
|
-
for (
|
381
|
-
|
382
|
-
|
379
|
+
for (let i = 0; i < lines.length; i++) {
|
380
|
+
const line = lines[i].trim().replace(/\s\s/g, " ");
|
381
|
+
let result;
|
383
382
|
// Comment or newLine
|
384
383
|
if (line.length === 0 || line.charAt(0) === "#") {
|
385
384
|
continue;
|
@@ -393,9 +392,9 @@ var SolidParser = /** @class */ (function () {
|
|
393
392
|
this._positions.push(new Vector3(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
|
394
393
|
if (this._loadingOptions.importVertexColors) {
|
395
394
|
if (result.length >= 7) {
|
396
|
-
|
397
|
-
|
398
|
-
|
395
|
+
const r = parseFloat(result[4]);
|
396
|
+
const g = parseFloat(result[5]);
|
397
|
+
const b = parseFloat(result[6]);
|
399
398
|
this._colors.push(new Color4(r > 1 ? r / 255 : r, g > 1 ? g / 255 : g, b > 1 ? b / 255 : b, result.length === 7 || result[7] === undefined ? 1 : parseFloat(result[7])));
|
400
399
|
}
|
401
400
|
else {
|
@@ -460,7 +459,7 @@ var SolidParser = /** @class */ (function () {
|
|
460
459
|
else if (SolidParser.GroupDescriptor.test(line) || SolidParser.ObjectDescriptor.test(line)) {
|
461
460
|
// Create a new mesh corresponding to the name of the group.
|
462
461
|
// Definition of the mesh
|
463
|
-
|
462
|
+
const objMesh = {
|
464
463
|
name: line.substring(2).trim(),
|
465
464
|
indices: undefined,
|
466
465
|
positions: undefined,
|
@@ -486,7 +485,7 @@ var SolidParser = /** @class */ (function () {
|
|
486
485
|
//Set the data for the previous mesh
|
487
486
|
this._addPreviousObjMesh();
|
488
487
|
//Create a new mesh
|
489
|
-
|
488
|
+
const objMesh =
|
490
489
|
//Set the name of the current obj mesh
|
491
490
|
{
|
492
491
|
name: (this._objMeshName || "mesh") + "_mm" + this._increment.toString(),
|
@@ -544,7 +543,7 @@ var SolidParser = /** @class */ (function () {
|
|
544
543
|
}
|
545
544
|
// If any o or g keyword not found, create a mesh with a random id
|
546
545
|
if (!this._hasMeshes) {
|
547
|
-
|
546
|
+
let newMaterial = null;
|
548
547
|
if (this._indicesForBabylon.length) {
|
549
548
|
// reverse tab of indices
|
550
549
|
this._indicesForBabylon.reverse();
|
@@ -553,25 +552,21 @@ var SolidParser = /** @class */ (function () {
|
|
553
552
|
}
|
554
553
|
else {
|
555
554
|
// There is no indices in the file. We will have to switch to point cloud rendering
|
556
|
-
for (
|
557
|
-
var pos = _b[_i];
|
555
|
+
for (const pos of this._positions) {
|
558
556
|
this._unwrappedPositionsForBabylon.push(pos.x, pos.y, pos.z);
|
559
557
|
}
|
560
558
|
if (this._normals.length) {
|
561
|
-
for (
|
562
|
-
var normal = _d[_c];
|
559
|
+
for (const normal of this._normals) {
|
563
560
|
this._unwrappedNormalsForBabylon.push(normal.x, normal.y, normal.z);
|
564
561
|
}
|
565
562
|
}
|
566
563
|
if (this._uvs.length) {
|
567
|
-
for (
|
568
|
-
var uv = _f[_e];
|
564
|
+
for (const uv of this._uvs) {
|
569
565
|
this._unwrappedUVForBabylon.push(uv.x, uv.y);
|
570
566
|
}
|
571
567
|
}
|
572
568
|
if (this._colors.length) {
|
573
|
-
for (
|
574
|
-
var color = _h[_g];
|
569
|
+
for (const color of this._colors) {
|
575
570
|
this._unwrappedColorsForBabylon.push(color.r, color.g, color.b, color.a);
|
576
571
|
}
|
577
572
|
}
|
@@ -599,7 +594,7 @@ var SolidParser = /** @class */ (function () {
|
|
599
594
|
});
|
600
595
|
}
|
601
596
|
//Set data for each mesh
|
602
|
-
for (
|
597
|
+
for (let j = 0; j < this._meshesFromObj.length; j++) {
|
603
598
|
//check meshesNames (stlFileLoader)
|
604
599
|
if (meshesNames && this._meshesFromObj[j].name) {
|
605
600
|
if (meshesNames instanceof Array) {
|
@@ -618,24 +613,24 @@ var SolidParser = /** @class */ (function () {
|
|
618
613
|
this._handledMesh = this._meshesFromObj[j];
|
619
614
|
//Create a Mesh with the name of the obj mesh
|
620
615
|
scene._blockEntityCollection = !!assetContainer;
|
621
|
-
|
616
|
+
const babylonMesh = new Mesh(this._meshesFromObj[j].name, scene);
|
622
617
|
babylonMesh._parentContainer = assetContainer;
|
623
618
|
scene._blockEntityCollection = false;
|
624
619
|
//Push the name of the material to an array
|
625
620
|
//This is indispensable for the importMesh function
|
626
621
|
this._materialToUse.push(this._meshesFromObj[j].materialName);
|
627
|
-
if (
|
622
|
+
if (this._handledMesh.positions?.length === 0) {
|
628
623
|
//Push the mesh into an array
|
629
624
|
this._babylonMeshesArray.push(babylonMesh);
|
630
625
|
continue;
|
631
626
|
}
|
632
|
-
|
627
|
+
const vertexData = new VertexData(); //The container for the values
|
633
628
|
//Set the data for the babylonMesh
|
634
629
|
vertexData.uvs = this._handledMesh.uvs;
|
635
630
|
vertexData.indices = this._handledMesh.indices;
|
636
631
|
vertexData.positions = this._handledMesh.positions;
|
637
632
|
if (this._loadingOptions.computeNormals) {
|
638
|
-
|
633
|
+
const normals = new Array();
|
639
634
|
VertexData.ComputeNormals(this._handledMesh.positions, this._handledMesh.indices, normals);
|
640
635
|
vertexData.normals = normals;
|
641
636
|
}
|
@@ -659,36 +654,34 @@ var SolidParser = /** @class */ (function () {
|
|
659
654
|
babylonMesh.material = this._handledMesh.directMaterial;
|
660
655
|
}
|
661
656
|
}
|
662
|
-
}
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
}());
|
693
|
-
export { SolidParser };
|
657
|
+
}
|
658
|
+
}
|
659
|
+
// Descriptor
|
660
|
+
/** Object descriptor */
|
661
|
+
SolidParser.ObjectDescriptor = /^o/;
|
662
|
+
/** Group descriptor */
|
663
|
+
SolidParser.GroupDescriptor = /^g/;
|
664
|
+
/** Material lib descriptor */
|
665
|
+
SolidParser.MtlLibGroupDescriptor = /^mtllib /;
|
666
|
+
/** Use a material descriptor */
|
667
|
+
SolidParser.UseMtlDescriptor = /^usemtl /;
|
668
|
+
/** Smooth descriptor */
|
669
|
+
SolidParser.SmoothDescriptor = /^s /;
|
670
|
+
// Patterns
|
671
|
+
/** Pattern used to detect a vertex */
|
672
|
+
SolidParser.VertexPattern = /v(\s+[\d|.|+|\-|e|E]+){3,7}/;
|
673
|
+
/** Pattern used to detect a normal */
|
674
|
+
SolidParser.NormalPattern = /vn(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/;
|
675
|
+
/** Pattern used to detect a UV set */
|
676
|
+
SolidParser.UVPattern = /vt(\s+[\d|.|+|\-|e|E]+)( +[\d|.|+|\-|e|E]+)/;
|
677
|
+
/** Pattern used to detect a first kind of face (f vertex vertex vertex) */
|
678
|
+
SolidParser.FacePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
|
679
|
+
/** Pattern used to detect a second kind of face (f vertex/uvs vertex/uvs vertex/uvs) */
|
680
|
+
SolidParser.FacePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
|
681
|
+
/** Pattern used to detect a third kind of face (f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal) */
|
682
|
+
SolidParser.FacePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
|
683
|
+
/** Pattern used to detect a fourth kind of face (f vertex//normal vertex//normal vertex//normal)*/
|
684
|
+
SolidParser.FacePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
|
685
|
+
/** Pattern used to detect a fifth kind of face (f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal) */
|
686
|
+
SolidParser.FacePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
|
694
687
|
//# sourceMappingURL=solidParser.js.map
|