@babylonjs/loaders 7.19.0 → 7.20.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/objFileLoader.d.ts +12 -2
- package/OBJ/objFileLoader.js +5 -1
- package/OBJ/objFileLoader.js.map +1 -1
- package/SPLAT/splatFileLoader.d.ts +20 -3
- package/SPLAT/splatFileLoader.js +3 -1
- package/SPLAT/splatFileLoader.js.map +1 -1
- package/STL/stlFileLoader.d.ts +17 -3
- package/STL/stlFileLoader.js +2 -1
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +15 -0
- package/glTF/2.0/Extensions/MSFT_lod.js +3 -0
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/glTFLoader.js +17 -5
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +74 -31
- package/glTF/glTFFileLoader.js +32 -15
- package/glTF/glTFFileLoader.js.map +1 -1
- package/package.json +3 -3
package/OBJ/objFileLoader.d.ts
CHANGED
@@ -3,6 +3,15 @@ import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPl
|
|
3
3
|
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
4
4
|
import type { Scene } from "@babylonjs/core/scene.js";
|
5
5
|
import type { OBJLoadingOptions } from "./objLoadingOptions";
|
6
|
+
declare const PLUGIN_OBJ = "obj";
|
7
|
+
declare module "core/Loading/sceneLoader" {
|
8
|
+
interface SceneLoaderPluginOptions {
|
9
|
+
/**
|
10
|
+
* Defines options for the obj loader.
|
11
|
+
*/
|
12
|
+
[PLUGIN_OBJ]?: {};
|
13
|
+
}
|
14
|
+
}
|
6
15
|
/**
|
7
16
|
* OBJ file type loader.
|
8
17
|
* This is a babylon scene loader plugin.
|
@@ -55,11 +64,11 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
|
|
55
64
|
/**
|
56
65
|
* Defines the name of the plugin.
|
57
66
|
*/
|
58
|
-
name
|
67
|
+
readonly name = "obj";
|
59
68
|
/**
|
60
69
|
* Defines the extension the plugin is able to load.
|
61
70
|
*/
|
62
|
-
extensions
|
71
|
+
readonly extensions = ".obj";
|
63
72
|
private _assetContainer;
|
64
73
|
private _loadingOptions;
|
65
74
|
/**
|
@@ -128,3 +137,4 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
|
|
128
137
|
*/
|
129
138
|
private _parseSolid;
|
130
139
|
}
|
140
|
+
export {};
|
package/OBJ/objFileLoader.js
CHANGED
@@ -5,6 +5,8 @@ import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
|
5
5
|
import { MTLFileLoader } from "./mtlFileLoader.js";
|
6
6
|
import { SolidParser } from "./solidParser.js";
|
7
7
|
import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
|
8
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
9
|
+
const PLUGIN_OBJ = "obj";
|
8
10
|
/**
|
9
11
|
* OBJ file type loader.
|
10
12
|
* This is a babylon scene loader plugin.
|
@@ -28,7 +30,7 @@ export class OBJFileLoader {
|
|
28
30
|
/**
|
29
31
|
* Defines the name of the plugin.
|
30
32
|
*/
|
31
|
-
this.name =
|
33
|
+
this.name = PLUGIN_OBJ;
|
32
34
|
/**
|
33
35
|
* Defines the extension the plugin is able to load.
|
34
36
|
*/
|
@@ -172,6 +174,8 @@ export class OBJFileLoader {
|
|
172
174
|
const materialsFromMTLFile = new MTLFileLoader();
|
173
175
|
const materialToUse = [];
|
174
176
|
const babylonMeshesArray = []; //The mesh for babylon
|
177
|
+
// Sanitize data
|
178
|
+
data = data.replace(/#.*$/gm, "").trim();
|
175
179
|
// Main function
|
176
180
|
const solidParser = new SolidParser(materialToUse, babylonMeshesArray, this._loadingOptions);
|
177
181
|
solidParser.parse(meshesNames, data, scene, this._assetContainer, (fileName) => {
|
package/OBJ/objFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"objFileLo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AAI,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;;AArUD;;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;AAqR9C,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/**\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 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 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 // 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","sourceRoot":"","sources":["../../../../dev/loaders/src/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;AAE5C,OAAO,EAAE,gBAAgB,EAAE,sDAAwC;AAEnE,gEAAgE;AAChE,MAAM,UAAU,GAAG,KAAK,CAAC;AAYzB;;;GAGG;AACH,MAAM,OAAO,aAAa;IAStB;;OAEG;IACI,MAAM,KAA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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,6 +1,15 @@
|
|
1
|
-
import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult,
|
1
|
+
import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult, ISceneLoaderProgressEvent } from "@babylonjs/core/Loading/sceneLoader.js";
|
2
2
|
import type { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
3
3
|
import type { Scene } from "@babylonjs/core/scene.js";
|
4
|
+
declare const PLUGIN_SPLAT = "splat";
|
5
|
+
declare module "core/Loading/sceneLoader" {
|
6
|
+
interface SceneLoaderPluginOptions {
|
7
|
+
/**
|
8
|
+
* Defines options for the splat loader.
|
9
|
+
*/
|
10
|
+
[PLUGIN_SPLAT]?: {};
|
11
|
+
}
|
12
|
+
}
|
4
13
|
/**
|
5
14
|
* @experimental
|
6
15
|
* SPLAT file type loader.
|
@@ -10,12 +19,19 @@ export declare class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneL
|
|
10
19
|
/**
|
11
20
|
* Defines the name of the plugin.
|
12
21
|
*/
|
13
|
-
name
|
22
|
+
readonly name = "splat";
|
14
23
|
/**
|
15
24
|
* Defines the extensions the splat loader is able to load.
|
16
25
|
* force data to come in as an ArrayBuffer
|
17
26
|
*/
|
18
|
-
extensions:
|
27
|
+
readonly extensions: {
|
28
|
+
readonly ".splat": {
|
29
|
+
readonly isBinary: true;
|
30
|
+
};
|
31
|
+
readonly ".ply": {
|
32
|
+
readonly isBinary: true;
|
33
|
+
};
|
34
|
+
};
|
19
35
|
/**
|
20
36
|
* Creates loader for gaussian splatting files
|
21
37
|
*/
|
@@ -58,3 +74,4 @@ export declare class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneL
|
|
58
74
|
*/
|
59
75
|
loadAssetContainerAsync(_scene: Scene, _data: string, _rootUrl: string): Promise<AssetContainer>;
|
60
76
|
}
|
77
|
+
export {};
|
package/SPLAT/splatFileLoader.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
2
2
|
import { GaussianSplattingMesh } from "@babylonjs/core/Meshes/GaussianSplatting/gaussianSplattingMesh.js";
|
3
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
4
|
+
const PLUGIN_SPLAT = "splat";
|
3
5
|
/**
|
4
6
|
* @experimental
|
5
7
|
* SPLAT file type loader.
|
@@ -14,7 +16,7 @@ export class SPLATFileLoader {
|
|
14
16
|
/**
|
15
17
|
* Defines the name of the plugin.
|
16
18
|
*/
|
17
|
-
this.name =
|
19
|
+
this.name = PLUGIN_SPLAT;
|
18
20
|
/**
|
19
21
|
* Defines the extensions the splat loader is able to load.
|
20
22
|
* force data to come in as an ArrayBuffer
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/splatFileLoader.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,qBAAqB,EAAE,0EAA4D;AAI5F;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAiBxB,+CAA+C;IAC/C;;OAEG;IACH;QApBA;;WAEG;
|
1
|
+
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/splatFileLoader.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,qBAAqB,EAAE,0EAA4D;AAI5F,gEAAgE;AAChE,MAAM,YAAY,GAAG,OAAO,CAAC;AAY7B;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAiBxB,+CAA+C;IAC/C;;OAEG;IACH;QApBA;;WAEG;QACa,SAAI,GAAG,YAAY,CAAC;QAEpC;;;WAGG;QACa,eAAU,GAAG;YACzB,gEAAgE;YAChE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC5B,gEAAgE;YAChE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SACmB,CAAC;IAMnC,CAAC;IAEhB;;;OAGG;IACH,YAAY;QACR,OAAO,IAAI,eAAe,EAAE,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,aAAa;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,eAAe,CACxB,YAAiB,EACjB,KAAY,EACZ,IAAS,EACT,OAAe,EACf,UAAuD,EACvD,QAAiB;QAEjB,MAAM,iBAAiB,GAAG,IAAI,qBAAqB,CAAC,mBAAmB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACtF,MAAM,iBAAiB,CAAC,aAAa,CAAC,OAAO,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;QAClE,OAAO;YACH,MAAM,EAAE,CAAC,iBAAiB,CAAC;YAC3B,eAAe,EAAE,EAAE;YACnB,SAAS,EAAE,EAAE;YACb,eAAe,EAAE,EAAE;YACnB,cAAc,EAAE,EAAE;YAClB,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,EAAE;YACV,cAAc,EAAE,EAAE;SACrB,CAAC;IACN,CAAC;IAED;;;;;;OAMG;IACI,SAAS,CAAC,KAAY,EAAE,IAAS,EAAE,QAAgB;QACtD,MAAM,iBAAiB,GAAG,IAAI,qBAAqB,CAAC,mBAAmB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACtF,OAAO,iBAAiB,CAAC,aAAa,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,uDAAuD;IACvD;;;;;;OAMG;IACI,uBAAuB,CAAC,MAAa,EAAE,KAAa,EAAE,QAAgB;QACzE,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;IAC9F,CAAC;CACJ;AAED,IAAI,WAAW,EAAE;IACb,0CAA0C;IAC1C,WAAW,CAAC,cAAc,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC;CACrD","sourcesContent":["import type {\r\n ISceneLoaderPluginAsync,\r\n ISceneLoaderPluginFactory,\r\n ISceneLoaderPlugin,\r\n ISceneLoaderAsyncResult,\r\n ISceneLoaderPluginExtensions,\r\n ISceneLoaderProgressEvent,\r\n} from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nconst PLUGIN_SPLAT = \"splat\";\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 splat loader.\r\n */\r\n [PLUGIN_SPLAT]?: {};\r\n }\r\n}\r\n\r\n/**\r\n * @experimental\r\n * SPLAT file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public readonly name = PLUGIN_SPLAT;\r\n\r\n /**\r\n * Defines the extensions the splat loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n */\r\n public readonly extensions = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \".splat\": { isBinary: true },\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \".ply\": { isBinary: true },\r\n } as const satisfies ISceneLoaderPluginExtensions;\r\n\r\n //private _loadingOptions: SPLATLoadingOptions;\r\n /**\r\n * Creates loader for gaussian splatting files\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Instantiates a gaussian splatting file loader plugin.\r\n * @returns the created plugin\r\n */\r\n createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new SPLATFileLoader();\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 from the loaded gaussian splatting 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 gaussian splatting data to load\r\n * @param rootUrl root url to load from\r\n * @param onProgress callback called while file is loading\r\n * @param fileName Defines the name of the file to load\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public async importMeshAsync(\r\n _meshesNames: any,\r\n scene: Scene,\r\n data: any,\r\n rootUrl: string,\r\n onProgress?: (event: ISceneLoaderProgressEvent) => void,\r\n fileName?: string\r\n ): Promise<ISceneLoaderAsyncResult> {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene);\r\n await gaussianSplatting.loadFileAsync(rootUrl + (fileName ?? \"\"));\r\n return {\r\n meshes: [gaussianSplatting],\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 * Imports all objects from the loaded gaussian splatting data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the gaussian splatting 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: any, _rootUrl: string): Promise<void> {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene);\r\n return gaussianSplatting.loadDataAsync(GaussianSplattingMesh.ConvertPLYToSplat(data));\r\n }\r\n\r\n // eslint-disable-next-line jsdoc/require-returns-check\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 throw new Error(\"loadAssetContainerAsync not implemented for Gaussian Splatting loading\");\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n //Add this loader into the register plugin\r\n SceneLoader.RegisterPlugin(new SPLATFileLoader());\r\n}\r\n"]}
|
package/STL/stlFileLoader.d.ts
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
import type { Nullable } from "@babylonjs/core/types.js";
|
2
2
|
import type { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
|
3
|
-
import type { ISceneLoaderPlugin
|
3
|
+
import type { ISceneLoaderPlugin } from "@babylonjs/core/Loading/sceneLoader.js";
|
4
4
|
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
5
|
import type { Scene } from "@babylonjs/core/scene.js";
|
6
|
+
declare const PLUGIN_STL = "stl";
|
7
|
+
declare module "core/Loading/sceneLoader" {
|
8
|
+
interface SceneLoaderPluginOptions {
|
9
|
+
/**
|
10
|
+
* Defines options for the stl loader.
|
11
|
+
*/
|
12
|
+
[PLUGIN_STL]?: {};
|
13
|
+
}
|
14
|
+
}
|
6
15
|
/**
|
7
16
|
* STL file type loader.
|
8
17
|
* This is a babylon scene loader plugin.
|
@@ -19,13 +28,17 @@ export declare class STLFileLoader implements ISceneLoaderPlugin {
|
|
19
28
|
/**
|
20
29
|
* Defines the name of the plugin.
|
21
30
|
*/
|
22
|
-
name
|
31
|
+
readonly name = "stl";
|
23
32
|
/**
|
24
33
|
* Defines the extensions the stl loader is able to load.
|
25
34
|
* force data to come in as an ArrayBuffer
|
26
35
|
* we'll convert to string if it looks like it's an ASCII .stl
|
27
36
|
*/
|
28
|
-
extensions:
|
37
|
+
readonly extensions: {
|
38
|
+
readonly ".stl": {
|
39
|
+
readonly isBinary: true;
|
40
|
+
};
|
41
|
+
};
|
29
42
|
/**
|
30
43
|
* Defines if Y and Z axes are swapped or not when loading an STL file.
|
31
44
|
* The default is false to maintain backward compatibility. When set to
|
@@ -62,3 +75,4 @@ export declare class STLFileLoader implements ISceneLoaderPlugin {
|
|
62
75
|
private _parseBinary;
|
63
76
|
private _parseASCII;
|
64
77
|
}
|
78
|
+
export {};
|
package/STL/stlFileLoader.js
CHANGED
@@ -3,6 +3,7 @@ import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
|
3
3
|
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
4
4
|
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
5
5
|
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
6
|
+
const PLUGIN_STL = "stl";
|
6
7
|
/**
|
7
8
|
* STL file type loader.
|
8
9
|
* This is a babylon scene loader plugin.
|
@@ -20,7 +21,7 @@ export class STLFileLoader {
|
|
20
21
|
/**
|
21
22
|
* Defines the name of the plugin.
|
22
23
|
*/
|
23
|
-
this.name =
|
24
|
+
this.name = PLUGIN_STL;
|
24
25
|
/**
|
25
26
|
* Defines the extensions the stl loader is able to load.
|
26
27
|
* force data to come in as an ArrayBuffer
|
package/STL/stlFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stlFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/STL/stlFileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AAExC,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAGrD;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACI,gBAAgB;QACT,iBAAY,GAAG,yCAAyC,CAAC;QAEhE,gBAAgB;QACT,kBAAa,GAAG,0BAA0B,CAAC;QAClD,gBAAgB;QACT,kBAAa,GAAG,mJAAmJ,CAAC;QAC3K,gBAAgB;QACT,kBAAa,GAAG,mJAAmJ,CAAC;QAE3K;;WAEG;QACI,SAAI,GAAG,KAAK,CAAC;QAEpB;;;;WAIG;QACI,eAAU,GAAiC;YAC9C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC7B,CAAC;IA6ON,CAAC;IApOG;;;;;;;;OAQG;IACI,UAAU,CAAC,WAAgB,EAAE,KAAY,EAAE,IAAS,EAAE,OAAe,EAAE,MAAgC;QAC1G,IAAI,OAAO,CAAC;QAEZ,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC1B,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBACtB,cAAc;gBACd,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;gBAC/C,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBACr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AAC,SAAS,GAAG,CAAC,CAAC;SACpC;QAED,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;;AA1OD;;;;GAIG;AACW,2CAA6B,GAAG,KAAK,AAAR,CAAS;AAwOxD,IAAI,WAAW,EAAE;IACb,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } 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\n\r\n/**\r\n * STL file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class STLFileLoader implements ISceneLoaderPlugin {\r\n /** @internal */\r\n public solidPattern = /solid (\\S*)([\\S\\s]*?)endsolid[ ]*(\\S*)/g;\r\n\r\n /** @internal */\r\n public facetsPattern = /facet([\\s\\S]*?)endfacet/g;\r\n /** @internal */\r\n public normalPattern = /normal[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n /** @internal */\r\n public vertexPattern = /vertex[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public name = \"stl\";\r\n\r\n /**\r\n * Defines the extensions the stl loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n * we'll convert to string if it looks like it's an ASCII .stl\r\n */\r\n public extensions: ISceneLoaderPluginExtensions = {\r\n \".stl\": { isBinary: true },\r\n };\r\n\r\n /**\r\n * Defines if Y and Z axes are swapped or not when loading an STL file.\r\n * The default is false to maintain backward compatibility. When set to\r\n * true, coordinates from the STL file are used without change.\r\n */\r\n public static DO_NOT_ALTER_FILE_COORDINATES = false;\r\n\r\n /**\r\n * Import meshes into a scene.\r\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param scene The scene to import into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param meshes The meshes array to import into\r\n * @returns True if successful or false otherwise\r\n */\r\n public importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>): boolean {\r\n let matches;\r\n\r\n if (typeof data !== \"string\") {\r\n if (this._isBinary(data)) {\r\n // binary .stl\r\n const babylonMesh = new Mesh(\"stlmesh\", scene);\r\n this._parseBinary(babylonMesh, data);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n return true;\r\n }\r\n\r\n // ASCII .stl\r\n\r\n // convert to string\r\n data = new TextDecoder().decode(new Uint8Array(data));\r\n }\r\n\r\n //if arrived here, data is a string, containing the STLA data.\r\n\r\n while ((matches = this.solidPattern.exec(data))) {\r\n let meshName = matches[1];\r\n const meshNameFromEnd = matches[3];\r\n if (meshNameFromEnd && meshName != meshNameFromEnd) {\r\n Tools.Error(\"Error in STL, solid name != endsolid name\");\r\n return false;\r\n }\r\n\r\n // check meshesNames\r\n if (meshesNames && meshName) {\r\n if (meshesNames instanceof Array) {\r\n if (!meshesNames.indexOf(meshName)) {\r\n continue;\r\n }\r\n } else {\r\n if (meshName !== meshesNames) {\r\n continue;\r\n }\r\n }\r\n }\r\n\r\n // stl mesh name can be empty as well\r\n meshName = meshName || \"stlmesh\";\r\n\r\n const babylonMesh = new Mesh(meshName, scene);\r\n this._parseASCII(babylonMesh, matches[2]);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Load into a scene.\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 true if successful or false otherwise\r\n */\r\n public load(scene: Scene, data: any, rootUrl: string): boolean {\r\n const result = this.importMesh(null, scene, data, rootUrl, null);\r\n return result;\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 loadAssetContainer(scene: Scene, data: string, rootUrl: string): AssetContainer {\r\n const container = new AssetContainer(scene);\r\n scene._blockEntityCollection = true;\r\n this.importMesh(null, scene, data, rootUrl, container.meshes);\r\n scene._blockEntityCollection = false;\r\n return container;\r\n }\r\n\r\n private _isBinary(data: any) {\r\n // check if file size is correct for binary stl\r\n const reader = new DataView(data);\r\n\r\n // A Binary STL header is 80 bytes, if the data size is not great than\r\n // that then it's not a binary STL.\r\n if (reader.byteLength <= 80) {\r\n return false;\r\n }\r\n\r\n const faceSize = (32 / 8) * 3 + (32 / 8) * 3 * 3 + 16 / 8;\r\n const nFaces = reader.getUint32(80, true);\r\n\r\n if (80 + 32 / 8 + nFaces * faceSize === reader.byteLength) {\r\n return true;\r\n }\r\n\r\n // US-ASCII begin with 's', 'o', 'l', 'i', 'd'\r\n const ascii = [115, 111, 108, 105, 100];\r\n for (let off = 0; off < 5; off++) {\r\n if (reader.getUint8(off) !== ascii[off]) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _parseBinary(mesh: Mesh, data: ArrayBuffer) {\r\n const reader = new DataView(data);\r\n const faces = reader.getUint32(80, true);\r\n\r\n const dataOffset = 84;\r\n const faceLength = 12 * 4 + 2;\r\n\r\n let offset = 0;\r\n\r\n const positions = new Float32Array(faces * 3 * 3);\r\n const normals = new Float32Array(faces * 3 * 3);\r\n const indices = new Uint32Array(faces * 3);\r\n let indicesCount = 0;\r\n\r\n for (let face = 0; face < faces; face++) {\r\n const start = dataOffset + face * faceLength;\r\n const normalX = reader.getFloat32(start, true);\r\n const normalY = reader.getFloat32(start + 4, true);\r\n const normalZ = reader.getFloat32(start + 8, true);\r\n\r\n for (let i = 1; i <= 3; i++) {\r\n const vertexstart = start + i * 12;\r\n\r\n // ordering is intentional to match ascii import\r\n positions[offset] = reader.getFloat32(vertexstart, true);\r\n normals[offset] = normalX;\r\n\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 2] = normalY;\r\n normals[offset + 1] = normalZ;\r\n } else {\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 1] = normalY;\r\n normals[offset + 2] = normalZ;\r\n }\r\n\r\n offset += 3;\r\n }\r\n\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices[indicesCount] = indicesCount;\r\n indices[indicesCount + 1] = indicesCount + 2;\r\n indices[indicesCount + 2] = indicesCount + 1;\r\n indicesCount += 3;\r\n } else {\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n }\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n\r\n private _parseASCII(mesh: Mesh, solidData: string) {\r\n const positions = [];\r\n const normals = [];\r\n const indices = [];\r\n let indicesCount = 0;\r\n\r\n //load facets, ignoring loop as the standard doesn't define it can contain more than vertices\r\n let matches;\r\n while ((matches = this.facetsPattern.exec(solidData))) {\r\n const facet = matches[1];\r\n //one normal per face\r\n const normalMatches = this.normalPattern.exec(facet);\r\n this.normalPattern.lastIndex = 0;\r\n if (!normalMatches) {\r\n continue;\r\n }\r\n const normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];\r\n\r\n let vertexMatch;\r\n while ((vertexMatch = this.vertexPattern.exec(facet))) {\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));\r\n normals.push(normal[0], normal[1], normal[2]);\r\n } else {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));\r\n\r\n // Flipping the second and third component because inverted\r\n // when normal was declared.\r\n normals.push(normal[0], normal[2], normal[1]);\r\n }\r\n }\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices.push(indicesCount, indicesCount + 2, indicesCount + 1);\r\n indicesCount += 3;\r\n } else {\r\n indices.push(indicesCount++, indicesCount++, indicesCount++);\r\n }\r\n this.vertexPattern.lastIndex = 0;\r\n }\r\n\r\n this.facetsPattern.lastIndex = 0;\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n SceneLoader.RegisterPlugin(new STLFileLoader());\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"stlFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/STL/stlFileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AAExC,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAGrD,MAAM,UAAU,GAAG,KAAK,CAAC;AAYzB;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACI,gBAAgB;QACT,iBAAY,GAAG,yCAAyC,CAAC;QAEhE,gBAAgB;QACT,kBAAa,GAAG,0BAA0B,CAAC;QAClD,gBAAgB;QACT,kBAAa,GAAG,mJAAmJ,CAAC;QAC3K,gBAAgB;QACT,kBAAa,GAAG,mJAAmJ,CAAC;QAE3K;;WAEG;QACa,SAAI,GAAG,UAAU,CAAC;QAElC;;;;WAIG;QACa,eAAU,GAAG;YACzB,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SACmB,CAAC;IA6OtD,CAAC;IApOG;;;;;;;;OAQG;IACI,UAAU,CAAC,WAAgB,EAAE,KAAY,EAAE,IAAS,EAAE,OAAe,EAAE,MAAgC;QAC1G,IAAI,OAAO,CAAC;QAEZ,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC1B,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBACtB,cAAc;gBACd,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;gBAC/C,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBACrC,IAAI,MAAM,EAAE;oBACR,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;iBAC5B;gBACD,OAAO,IAAI,CAAC;aACf;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eAAe,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;;AA1OD;;;;GAIG;AACW,2CAA6B,GAAG,KAAK,AAAR,CAAS;AAwOxD,IAAI,WAAW,EAAE;IACb,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } 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\n\r\nconst PLUGIN_STL = \"stl\";\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 stl loader.\r\n */\r\n [PLUGIN_STL]?: {};\r\n }\r\n}\r\n\r\n/**\r\n * STL file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class STLFileLoader implements ISceneLoaderPlugin {\r\n /** @internal */\r\n public solidPattern = /solid (\\S*)([\\S\\s]*?)endsolid[ ]*(\\S*)/g;\r\n\r\n /** @internal */\r\n public facetsPattern = /facet([\\s\\S]*?)endfacet/g;\r\n /** @internal */\r\n public normalPattern = /normal[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n /** @internal */\r\n public vertexPattern = /vertex[\\s]+([-+]?[0-9]+\\.?[0-9]*([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+[\\s]+([-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public readonly name = PLUGIN_STL;\r\n\r\n /**\r\n * Defines the extensions the stl loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n * we'll convert to string if it looks like it's an ASCII .stl\r\n */\r\n public readonly extensions = {\r\n \".stl\": { isBinary: true },\r\n } as const satisfies ISceneLoaderPluginExtensions;\r\n\r\n /**\r\n * Defines if Y and Z axes are swapped or not when loading an STL file.\r\n * The default is false to maintain backward compatibility. When set to\r\n * true, coordinates from the STL file are used without change.\r\n */\r\n public static DO_NOT_ALTER_FILE_COORDINATES = false;\r\n\r\n /**\r\n * Import meshes into a scene.\r\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param scene The scene to import into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param meshes The meshes array to import into\r\n * @returns True if successful or false otherwise\r\n */\r\n public importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>): boolean {\r\n let matches;\r\n\r\n if (typeof data !== \"string\") {\r\n if (this._isBinary(data)) {\r\n // binary .stl\r\n const babylonMesh = new Mesh(\"stlmesh\", scene);\r\n this._parseBinary(babylonMesh, data);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n return true;\r\n }\r\n\r\n // ASCII .stl\r\n\r\n // convert to string\r\n data = new TextDecoder().decode(new Uint8Array(data));\r\n }\r\n\r\n //if arrived here, data is a string, containing the STLA data.\r\n\r\n while ((matches = this.solidPattern.exec(data))) {\r\n let meshName = matches[1];\r\n const meshNameFromEnd = matches[3];\r\n if (meshNameFromEnd && meshName != meshNameFromEnd) {\r\n Tools.Error(\"Error in STL, solid name != endsolid name\");\r\n return false;\r\n }\r\n\r\n // check meshesNames\r\n if (meshesNames && meshName) {\r\n if (meshesNames instanceof Array) {\r\n if (!meshesNames.indexOf(meshName)) {\r\n continue;\r\n }\r\n } else {\r\n if (meshName !== meshesNames) {\r\n continue;\r\n }\r\n }\r\n }\r\n\r\n // stl mesh name can be empty as well\r\n meshName = meshName || \"stlmesh\";\r\n\r\n const babylonMesh = new Mesh(meshName, scene);\r\n this._parseASCII(babylonMesh, matches[2]);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Load into a scene.\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 true if successful or false otherwise\r\n */\r\n public load(scene: Scene, data: any, rootUrl: string): boolean {\r\n const result = this.importMesh(null, scene, data, rootUrl, null);\r\n return result;\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 loadAssetContainer(scene: Scene, data: string, rootUrl: string): AssetContainer {\r\n const container = new AssetContainer(scene);\r\n scene._blockEntityCollection = true;\r\n this.importMesh(null, scene, data, rootUrl, container.meshes);\r\n scene._blockEntityCollection = false;\r\n return container;\r\n }\r\n\r\n private _isBinary(data: any) {\r\n // check if file size is correct for binary stl\r\n const reader = new DataView(data);\r\n\r\n // A Binary STL header is 80 bytes, if the data size is not great than\r\n // that then it's not a binary STL.\r\n if (reader.byteLength <= 80) {\r\n return false;\r\n }\r\n\r\n const faceSize = (32 / 8) * 3 + (32 / 8) * 3 * 3 + 16 / 8;\r\n const nFaces = reader.getUint32(80, true);\r\n\r\n if (80 + 32 / 8 + nFaces * faceSize === reader.byteLength) {\r\n return true;\r\n }\r\n\r\n // US-ASCII begin with 's', 'o', 'l', 'i', 'd'\r\n const ascii = [115, 111, 108, 105, 100];\r\n for (let off = 0; off < 5; off++) {\r\n if (reader.getUint8(off) !== ascii[off]) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _parseBinary(mesh: Mesh, data: ArrayBuffer) {\r\n const reader = new DataView(data);\r\n const faces = reader.getUint32(80, true);\r\n\r\n const dataOffset = 84;\r\n const faceLength = 12 * 4 + 2;\r\n\r\n let offset = 0;\r\n\r\n const positions = new Float32Array(faces * 3 * 3);\r\n const normals = new Float32Array(faces * 3 * 3);\r\n const indices = new Uint32Array(faces * 3);\r\n let indicesCount = 0;\r\n\r\n for (let face = 0; face < faces; face++) {\r\n const start = dataOffset + face * faceLength;\r\n const normalX = reader.getFloat32(start, true);\r\n const normalY = reader.getFloat32(start + 4, true);\r\n const normalZ = reader.getFloat32(start + 8, true);\r\n\r\n for (let i = 1; i <= 3; i++) {\r\n const vertexstart = start + i * 12;\r\n\r\n // ordering is intentional to match ascii import\r\n positions[offset] = reader.getFloat32(vertexstart, true);\r\n normals[offset] = normalX;\r\n\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 2] = normalY;\r\n normals[offset + 1] = normalZ;\r\n } else {\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 1] = normalY;\r\n normals[offset + 2] = normalZ;\r\n }\r\n\r\n offset += 3;\r\n }\r\n\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices[indicesCount] = indicesCount;\r\n indices[indicesCount + 1] = indicesCount + 2;\r\n indices[indicesCount + 2] = indicesCount + 1;\r\n indicesCount += 3;\r\n } else {\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n }\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n\r\n private _parseASCII(mesh: Mesh, solidData: string) {\r\n const positions = [];\r\n const normals = [];\r\n const indices = [];\r\n let indicesCount = 0;\r\n\r\n //load facets, ignoring loop as the standard doesn't define it can contain more than vertices\r\n let matches;\r\n while ((matches = this.facetsPattern.exec(solidData))) {\r\n const facet = matches[1];\r\n //one normal per face\r\n const normalMatches = this.normalPattern.exec(facet);\r\n this.normalPattern.lastIndex = 0;\r\n if (!normalMatches) {\r\n continue;\r\n }\r\n const normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];\r\n\r\n let vertexMatch;\r\n while ((vertexMatch = this.vertexPattern.exec(facet))) {\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));\r\n normals.push(normal[0], normal[1], normal[2]);\r\n } else {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));\r\n\r\n // Flipping the second and third component because inverted\r\n // when normal was declared.\r\n normals.push(normal[0], normal[2], normal[1]);\r\n }\r\n }\r\n if (STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n indices.push(indicesCount, indicesCount + 2, indicesCount + 1);\r\n indicesCount += 3;\r\n } else {\r\n indices.push(indicesCount++, indicesCount++, indicesCount++);\r\n }\r\n this.vertexPattern.lastIndex = 0;\r\n }\r\n\r\n this.facetsPattern.lastIndex = 0;\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n SceneLoader.RegisterPlugin(new STLFileLoader());\r\n}\r\n"]}
|
@@ -7,6 +7,20 @@ import type { INode, IMaterial, IBuffer, IScene } from "../glTFLoaderInterfaces"
|
|
7
7
|
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension";
|
8
8
|
import { GLTFLoader } from "../glTFLoader";
|
9
9
|
import type { IProperty } from "babylonjs-gltf2interface";
|
10
|
+
declare const NAME = "MSFT_lod";
|
11
|
+
declare module "../../glTFFileLoader" {
|
12
|
+
interface GLTFLoaderExtensionOptions {
|
13
|
+
/**
|
14
|
+
* Defines options for the MSFT_lod extension.
|
15
|
+
*/
|
16
|
+
[NAME]?: Partial<{
|
17
|
+
/**
|
18
|
+
* Maximum number of LODs to load, starting from the lowest LOD.
|
19
|
+
*/
|
20
|
+
maxLODsToLoad: number;
|
21
|
+
}>;
|
22
|
+
}
|
23
|
+
}
|
10
24
|
/**
|
11
25
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/MSFT_lod/README.md)
|
12
26
|
*/
|
@@ -89,3 +103,4 @@ export declare class MSFT_lod implements IGLTFLoaderExtension {
|
|
89
103
|
private _disposeTransformNode;
|
90
104
|
private _disposeMaterials;
|
91
105
|
}
|
106
|
+
export {};
|
@@ -45,6 +45,9 @@ export class MSFT_lod {
|
|
45
45
|
this._materialPromiseLODs = new Array();
|
46
46
|
this._materialBufferLODs = new Array();
|
47
47
|
this._loader = loader;
|
48
|
+
// Options takes precedence. The maxLODsToLoad extension property is retained for back compat.
|
49
|
+
// For new extensions, they should only use options.
|
50
|
+
this.maxLODsToLoad = this._loader.parent.extensionOptions[NAME]?.maxLODsToLoad ?? this.maxLODsToLoad;
|
48
51
|
this.enabled = this._loader.isExtensionUsed(NAME);
|
49
52
|
}
|
50
53
|
/** @internal */
|
@@ -1 +1 @@
|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QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { Deferred } from \"core/Misc/deferred\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { INode, IMaterial, IBuffer, IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IProperty, IMSFTLOD } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_lod\";\r\n\r\ninterface IBufferInfo {\r\n start: number;\r\n end: number;\r\n loaded: Deferred<ArrayBufferView>;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/MSFT_lod/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_lod implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 100;\r\n\r\n /**\r\n * Maximum number of LODs to load, starting from the lowest LOD.\r\n */\r\n public maxLODsToLoad = 10;\r\n\r\n /**\r\n * Observable raised when all node LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onNodeLODsLoadedObservable = new Observable<number>();\r\n\r\n /**\r\n * Observable raised when all material LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onMaterialLODsLoadedObservable = new Observable<number>();\r\n\r\n private _loader: GLTFLoader;\r\n\r\n private _bufferLODs = new Array<IBufferInfo>();\r\n\r\n private _nodeIndexLOD: Nullable<number> = null;\r\n private _nodeSignalLODs = new Array<Deferred<void>>();\r\n private _nodePromiseLODs = new Array<Array<Promise<any>>>();\r\n private _nodeBufferLODs = new Array<IBufferInfo>();\r\n\r\n private _materialIndexLOD: Nullable<number> = null;\r\n private _materialSignalLODs = new Array<Deferred<void>>();\r\n private _materialPromiseLODs = new Array<Array<Promise<any>>>();\r\n private _materialBufferLODs = new Array<IBufferInfo>();\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n\r\n this._nodeIndexLOD = null;\r\n this._nodeSignalLODs.length = 0;\r\n this._nodePromiseLODs.length = 0;\r\n this._nodeBufferLODs.length = 0;\r\n\r\n this._materialIndexLOD = null;\r\n this._materialSignalLODs.length = 0;\r\n this._materialPromiseLODs.length = 0;\r\n this._materialBufferLODs.length = 0;\r\n\r\n this.onMaterialLODsLoadedObservable.clear();\r\n this.onNodeLODsLoadedObservable.clear();\r\n }\r\n\r\n /** @internal */\r\n public onReady(): void {\r\n for (let indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._nodePromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Node LOD ${indexLOD}`);\r\n this._loader.log(`Loaded node LOD ${indexLOD}`);\r\n }\r\n\r\n this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._nodePromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Node LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._nodeBufferLODs, indexLOD + 1);\r\n if (this._nodeSignalLODs[indexLOD]) {\r\n this._nodeSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n\r\n for (let indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._materialPromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Material LOD ${indexLOD}`);\r\n this._loader.log(`Loaded material LOD ${indexLOD}`);\r\n }\r\n\r\n this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._materialPromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Material LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._materialBufferLODs, indexLOD + 1);\r\n if (this._materialSignalLODs[indexLOD]) {\r\n this._materialSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n const promise = this._loader.loadSceneAsync(context, scene);\r\n this._loadBufferLOD(this._bufferLODs, 0);\r\n return promise;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<TransformNode>;\r\n\r\n const nodeLODs = this._getLODs(extensionContext, node, this._loader.gltf.nodes, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {\r\n const nodeLOD = nodeLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._nodeIndexLOD = indexLOD;\r\n this._nodeSignalLODs[indexLOD] = this._nodeSignalLODs[indexLOD] || new Deferred();\r\n }\r\n\r\n const assignWrap = (babylonTransformNode: TransformNode) => {\r\n assign(babylonTransformNode);\r\n babylonTransformNode.setEnabled(false);\r\n };\r\n\r\n const promise = this._loader.loadNodeAsync(`/nodes/${nodeLOD.index}`, nodeLOD, assignWrap).then((babylonMesh) => {\r\n if (indexLOD !== 0) {\r\n // TODO: should not rely on _babylonTransformNode\r\n const previousNodeLOD = nodeLODs[indexLOD - 1];\r\n if (previousNodeLOD._babylonTransformNode) {\r\n this._disposeTransformNode(previousNodeLOD._babylonTransformNode);\r\n delete previousNodeLOD._babylonTransformNode;\r\n }\r\n }\r\n\r\n babylonMesh.setEnabled(true);\r\n return babylonMesh;\r\n });\r\n\r\n this._nodePromiseLODs[indexLOD] = this._nodePromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._nodeIndexLOD = null;\r\n this._nodePromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMaterialAsync(\r\n context: string,\r\n material: IMaterial,\r\n babylonMesh: Nullable<Mesh>,\r\n babylonDrawMode: number,\r\n assign: (babylonMaterial: Material) => void\r\n ): Nullable<Promise<Material>> {\r\n // Don't load material LODs if already loading a node LOD.\r\n if (this._nodeIndexLOD) {\r\n return null;\r\n }\r\n\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, Material>(context, material, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<Material>;\r\n\r\n const materialLODs = this._getLODs(extensionContext, material, this._loader.gltf.materials, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {\r\n const materialLOD = materialLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._materialIndexLOD = indexLOD;\r\n }\r\n\r\n const promise = this._loader\r\n ._loadMaterialAsync(`/materials/${materialLOD.index}`, materialLOD, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n if (indexLOD === 0) {\r\n assign(babylonMaterial);\r\n }\r\n })\r\n .then((babylonMaterial) => {\r\n if (indexLOD !== 0) {\r\n assign(babylonMaterial);\r\n\r\n // TODO: should not rely on _data\r\n const previousDataLOD = materialLODs[indexLOD - 1]._data!;\r\n if (previousDataLOD[babylonDrawMode]) {\r\n this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);\r\n delete previousDataLOD[babylonDrawMode];\r\n }\r\n }\r\n\r\n return babylonMaterial;\r\n });\r\n\r\n this._materialPromiseLODs[indexLOD] = this._materialPromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._materialIndexLOD = null;\r\n this._materialPromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>> {\r\n // Defer the loading of uris if loading a node or material LOD.\r\n if (this._nodeIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._nodeIndexLOD - 1;\r\n this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n } else if (this._materialIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._materialIndexLOD - 1;\r\n this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._materialSignalLODs[previousIndexLOD].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>> {\r\n if (this._loader.parent.useRangeRequests && !buffer.uri) {\r\n if (!this._loader.bin) {\r\n throw new Error(`${context}: Uri is missing or the binary glTF is missing its binary chunk`);\r\n }\r\n\r\n const loadAsync = (bufferLODs: Array<IBufferInfo>, indexLOD: number) => {\r\n const start = byteOffset;\r\n const end = start + byteLength - 1;\r\n let bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n bufferLOD.start = Math.min(bufferLOD.start, start);\r\n bufferLOD.end = Math.max(bufferLOD.end, end);\r\n } else {\r\n bufferLOD = { start: start, end: end, loaded: new Deferred() };\r\n bufferLODs[indexLOD] = bufferLOD;\r\n }\r\n\r\n return bufferLOD.loaded.promise.then((data) => {\r\n return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);\r\n });\r\n };\r\n\r\n this._loader.log(`deferred`);\r\n\r\n if (this._nodeIndexLOD !== null) {\r\n return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);\r\n } else if (this._materialIndexLOD !== null) {\r\n return loadAsync(this._materialBufferLODs, this._materialIndexLOD);\r\n } else {\r\n return loadAsync(this._bufferLODs, 0);\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private _loadBufferLOD(bufferLODs: Array<IBufferInfo>, indexLOD: number): void {\r\n const bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n this._loader.log(`Loading buffer range [${bufferLOD.start}-${bufferLOD.end}]`);\r\n this._loader.bin!.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(\r\n (data) => {\r\n bufferLOD.loaded.resolve(data);\r\n },\r\n (error) => {\r\n bufferLOD.loaded.reject(error);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * @returns an array of LOD properties from lowest to highest.\r\n * @param context\r\n * @param property\r\n * @param array\r\n * @param ids\r\n */\r\n private _getLODs<T>(context: string, property: T, array: ArrayLike<T> | undefined, ids: number[]): T[] {\r\n if (this.maxLODsToLoad <= 0) {\r\n throw new Error(\"maxLODsToLoad must be greater than zero\");\r\n }\r\n\r\n const properties: T[] = [];\r\n\r\n for (let i = ids.length - 1; i >= 0; i--) {\r\n properties.push(ArrayItem.Get(`${context}/ids/${ids[i]}`, array, ids[i]));\r\n if (properties.length === this.maxLODsToLoad) {\r\n return properties;\r\n }\r\n }\r\n\r\n properties.push(property);\r\n return properties;\r\n }\r\n\r\n private _disposeTransformNode(babylonTransformNode: TransformNode): void {\r\n const babylonMaterials: Material[] = [];\r\n const babylonMaterial = (babylonTransformNode as Mesh).material;\r\n if (babylonMaterial) {\r\n babylonMaterials.push(babylonMaterial);\r\n }\r\n for (const babylonMesh of babylonTransformNode.getChildMeshes()) {\r\n if (babylonMesh.material) {\r\n babylonMaterials.push(babylonMesh.material);\r\n }\r\n }\r\n\r\n babylonTransformNode.dispose();\r\n\r\n const babylonMaterialsToDispose = babylonMaterials.filter((babylonMaterial) => this._loader.babylonScene.meshes.every((mesh) => mesh.material != babylonMaterial));\r\n this._disposeMaterials(babylonMaterialsToDispose);\r\n }\r\n\r\n private _disposeMaterials(babylonMaterials: Material[]): void {\r\n const babylonTextures: { [uniqueId: number]: BaseTexture } = {};\r\n\r\n for (const babylonMaterial of babylonMaterials) {\r\n for (const babylonTexture of babylonMaterial.getActiveTextures()) {\r\n babylonTextures[babylonTexture.uniqueId] = babylonTexture;\r\n }\r\n\r\n babylonMaterial.dispose();\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n for (const babylonMaterial of this._loader.babylonScene.materials) {\r\n if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {\r\n delete babylonTextures[uniqueId];\r\n }\r\n }\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n babylonTextures[uniqueId].dispose();\r\n }\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_lod(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"MSFT_lod.js","sourceRoot":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C,OAAO,EAAE,CAAC;SACvC;IACL,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { Deferred } from \"core/Misc/deferred\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { INode, IMaterial, IBuffer, IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IProperty, IMSFTLOD } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_lod\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the MSFT_lod extension.\r\n */\r\n [NAME]?: Partial<{\r\n /**\r\n * Maximum number of LODs to load, starting from the lowest LOD.\r\n */\r\n maxLODsToLoad: number;\r\n }>;\r\n }\r\n}\r\n\r\ninterface IBufferInfo {\r\n start: number;\r\n end: number;\r\n loaded: Deferred<ArrayBufferView>;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/MSFT_lod/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_lod implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 100;\r\n\r\n /**\r\n * Maximum number of LODs to load, starting from the lowest LOD.\r\n */\r\n public maxLODsToLoad = 10;\r\n\r\n /**\r\n * Observable raised when all node LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onNodeLODsLoadedObservable = new Observable<number>();\r\n\r\n /**\r\n * Observable raised when all material LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onMaterialLODsLoadedObservable = new Observable<number>();\r\n\r\n private _loader: GLTFLoader;\r\n\r\n private _bufferLODs = new Array<IBufferInfo>();\r\n\r\n private _nodeIndexLOD: Nullable<number> = null;\r\n private _nodeSignalLODs = new Array<Deferred<void>>();\r\n private _nodePromiseLODs = new Array<Array<Promise<any>>>();\r\n private _nodeBufferLODs = new Array<IBufferInfo>();\r\n\r\n private _materialIndexLOD: Nullable<number> = null;\r\n private _materialSignalLODs = new Array<Deferred<void>>();\r\n private _materialPromiseLODs = new Array<Array<Promise<any>>>();\r\n private _materialBufferLODs = new Array<IBufferInfo>();\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n // Options takes precedence. The maxLODsToLoad extension property is retained for back compat.\r\n // For new extensions, they should only use options.\r\n this.maxLODsToLoad = this._loader.parent.extensionOptions[NAME]?.maxLODsToLoad ?? this.maxLODsToLoad;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n\r\n this._nodeIndexLOD = null;\r\n this._nodeSignalLODs.length = 0;\r\n this._nodePromiseLODs.length = 0;\r\n this._nodeBufferLODs.length = 0;\r\n\r\n this._materialIndexLOD = null;\r\n this._materialSignalLODs.length = 0;\r\n this._materialPromiseLODs.length = 0;\r\n this._materialBufferLODs.length = 0;\r\n\r\n this.onMaterialLODsLoadedObservable.clear();\r\n this.onNodeLODsLoadedObservable.clear();\r\n }\r\n\r\n /** @internal */\r\n public onReady(): void {\r\n for (let indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._nodePromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Node LOD ${indexLOD}`);\r\n this._loader.log(`Loaded node LOD ${indexLOD}`);\r\n }\r\n\r\n this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._nodePromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Node LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._nodeBufferLODs, indexLOD + 1);\r\n if (this._nodeSignalLODs[indexLOD]) {\r\n this._nodeSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n\r\n for (let indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._materialPromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Material LOD ${indexLOD}`);\r\n this._loader.log(`Loaded material LOD ${indexLOD}`);\r\n }\r\n\r\n this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._materialPromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Material LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._materialBufferLODs, indexLOD + 1);\r\n if (this._materialSignalLODs[indexLOD]) {\r\n this._materialSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n const promise = this._loader.loadSceneAsync(context, scene);\r\n this._loadBufferLOD(this._bufferLODs, 0);\r\n return promise;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<TransformNode>;\r\n\r\n const nodeLODs = this._getLODs(extensionContext, node, this._loader.gltf.nodes, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {\r\n const nodeLOD = nodeLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._nodeIndexLOD = indexLOD;\r\n this._nodeSignalLODs[indexLOD] = this._nodeSignalLODs[indexLOD] || new Deferred();\r\n }\r\n\r\n const assignWrap = (babylonTransformNode: TransformNode) => {\r\n assign(babylonTransformNode);\r\n babylonTransformNode.setEnabled(false);\r\n };\r\n\r\n const promise = this._loader.loadNodeAsync(`/nodes/${nodeLOD.index}`, nodeLOD, assignWrap).then((babylonMesh) => {\r\n if (indexLOD !== 0) {\r\n // TODO: should not rely on _babylonTransformNode\r\n const previousNodeLOD = nodeLODs[indexLOD - 1];\r\n if (previousNodeLOD._babylonTransformNode) {\r\n this._disposeTransformNode(previousNodeLOD._babylonTransformNode);\r\n delete previousNodeLOD._babylonTransformNode;\r\n }\r\n }\r\n\r\n babylonMesh.setEnabled(true);\r\n return babylonMesh;\r\n });\r\n\r\n this._nodePromiseLODs[indexLOD] = this._nodePromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._nodeIndexLOD = null;\r\n this._nodePromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMaterialAsync(\r\n context: string,\r\n material: IMaterial,\r\n babylonMesh: Nullable<Mesh>,\r\n babylonDrawMode: number,\r\n assign: (babylonMaterial: Material) => void\r\n ): Nullable<Promise<Material>> {\r\n // Don't load material LODs if already loading a node LOD.\r\n if (this._nodeIndexLOD) {\r\n return null;\r\n }\r\n\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, Material>(context, material, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<Material>;\r\n\r\n const materialLODs = this._getLODs(extensionContext, material, this._loader.gltf.materials, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {\r\n const materialLOD = materialLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._materialIndexLOD = indexLOD;\r\n }\r\n\r\n const promise = this._loader\r\n ._loadMaterialAsync(`/materials/${materialLOD.index}`, materialLOD, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n if (indexLOD === 0) {\r\n assign(babylonMaterial);\r\n }\r\n })\r\n .then((babylonMaterial) => {\r\n if (indexLOD !== 0) {\r\n assign(babylonMaterial);\r\n\r\n // TODO: should not rely on _data\r\n const previousDataLOD = materialLODs[indexLOD - 1]._data!;\r\n if (previousDataLOD[babylonDrawMode]) {\r\n this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);\r\n delete previousDataLOD[babylonDrawMode];\r\n }\r\n }\r\n\r\n return babylonMaterial;\r\n });\r\n\r\n this._materialPromiseLODs[indexLOD] = this._materialPromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._materialIndexLOD = null;\r\n this._materialPromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>> {\r\n // Defer the loading of uris if loading a node or material LOD.\r\n if (this._nodeIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._nodeIndexLOD - 1;\r\n this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n } else if (this._materialIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._materialIndexLOD - 1;\r\n this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._materialSignalLODs[previousIndexLOD].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>> {\r\n if (this._loader.parent.useRangeRequests && !buffer.uri) {\r\n if (!this._loader.bin) {\r\n throw new Error(`${context}: Uri is missing or the binary glTF is missing its binary chunk`);\r\n }\r\n\r\n const loadAsync = (bufferLODs: Array<IBufferInfo>, indexLOD: number) => {\r\n const start = byteOffset;\r\n const end = start + byteLength - 1;\r\n let bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n bufferLOD.start = Math.min(bufferLOD.start, start);\r\n bufferLOD.end = Math.max(bufferLOD.end, end);\r\n } else {\r\n bufferLOD = { start: start, end: end, loaded: new Deferred() };\r\n bufferLODs[indexLOD] = bufferLOD;\r\n }\r\n\r\n return bufferLOD.loaded.promise.then((data) => {\r\n return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);\r\n });\r\n };\r\n\r\n this._loader.log(`deferred`);\r\n\r\n if (this._nodeIndexLOD !== null) {\r\n return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);\r\n } else if (this._materialIndexLOD !== null) {\r\n return loadAsync(this._materialBufferLODs, this._materialIndexLOD);\r\n } else {\r\n return loadAsync(this._bufferLODs, 0);\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private _loadBufferLOD(bufferLODs: Array<IBufferInfo>, indexLOD: number): void {\r\n const bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n this._loader.log(`Loading buffer range [${bufferLOD.start}-${bufferLOD.end}]`);\r\n this._loader.bin!.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(\r\n (data) => {\r\n bufferLOD.loaded.resolve(data);\r\n },\r\n (error) => {\r\n bufferLOD.loaded.reject(error);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * @returns an array of LOD properties from lowest to highest.\r\n * @param context\r\n * @param property\r\n * @param array\r\n * @param ids\r\n */\r\n private _getLODs<T>(context: string, property: T, array: ArrayLike<T> | undefined, ids: number[]): T[] {\r\n if (this.maxLODsToLoad <= 0) {\r\n throw new Error(\"maxLODsToLoad must be greater than zero\");\r\n }\r\n\r\n const properties: T[] = [];\r\n\r\n for (let i = ids.length - 1; i >= 0; i--) {\r\n properties.push(ArrayItem.Get(`${context}/ids/${ids[i]}`, array, ids[i]));\r\n if (properties.length === this.maxLODsToLoad) {\r\n return properties;\r\n }\r\n }\r\n\r\n properties.push(property);\r\n return properties;\r\n }\r\n\r\n private _disposeTransformNode(babylonTransformNode: TransformNode): void {\r\n const babylonMaterials: Material[] = [];\r\n const babylonMaterial = (babylonTransformNode as Mesh).material;\r\n if (babylonMaterial) {\r\n babylonMaterials.push(babylonMaterial);\r\n }\r\n for (const babylonMesh of babylonTransformNode.getChildMeshes()) {\r\n if (babylonMesh.material) {\r\n babylonMaterials.push(babylonMesh.material);\r\n }\r\n }\r\n\r\n babylonTransformNode.dispose();\r\n\r\n const babylonMaterialsToDispose = babylonMaterials.filter((babylonMaterial) => this._loader.babylonScene.meshes.every((mesh) => mesh.material != babylonMaterial));\r\n this._disposeMaterials(babylonMaterialsToDispose);\r\n }\r\n\r\n private _disposeMaterials(babylonMaterials: Material[]): void {\r\n const babylonTextures: { [uniqueId: number]: BaseTexture } = {};\r\n\r\n for (const babylonMaterial of babylonMaterials) {\r\n for (const babylonTexture of babylonMaterial.getActiveTextures()) {\r\n babylonTextures[babylonTexture.uniqueId] = babylonTexture;\r\n }\r\n\r\n babylonMaterial.dispose();\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n for (const babylonMaterial of this._loader.babylonScene.materials) {\r\n if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {\r\n delete babylonTextures[uniqueId];\r\n }\r\n }\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n babylonTextures[uniqueId].dispose();\r\n }\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_lod(loader));\r\n"]}
|