@babylonjs/loaders 9.22.1 → 9.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OBJ/objFileLoader.metadata.d.ts +5 -1
- package/OBJ/objFileLoader.metadata.js +4 -1
- package/OBJ/objFileLoader.metadata.js.map +1 -1
- package/OBJ/objFileLoader.pure.d.ts +12 -3
- package/OBJ/objFileLoader.pure.js +30 -2
- package/OBJ/objFileLoader.pure.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +6 -0
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/SPLAT/gaussianSplattingStream.d.ts +162 -15
- package/SPLAT/gaussianSplattingStream.js +523 -96
- package/SPLAT/gaussianSplattingStream.js.map +1 -1
- package/SPLAT/splatFileLoader.pure.js +1 -0
- package/SPLAT/splatFileLoader.pure.js.map +1 -1
- package/dynamic.js +16 -6
- package/dynamic.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_interactivity.pure.d.ts +5 -0
- package/glTF/2.0/Extensions/KHR_interactivity.pure.js +15 -4
- package/glTF/2.0/Extensions/KHR_interactivity.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_node_hoverability.pure.d.ts +5 -0
- package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js +19 -6
- package/glTF/2.0/Extensions/KHR_node_hoverability.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_node_selectability.pure.d.ts +5 -0
- package/glTF/2.0/Extensions/KHR_node_selectability.pure.js +19 -6
- package/glTF/2.0/Extensions/KHR_node_selectability.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_node_visibility.pure.d.ts +5 -0
- package/glTF/2.0/Extensions/KHR_node_visibility.pure.js +19 -6
- package/glTF/2.0/Extensions/KHR_node_visibility.pure.js.map +1 -1
- package/glTF/2.0/Extensions/dynamic.js +54 -41
- package/glTF/2.0/Extensions/dynamic.js.map +1 -1
- package/glTF/2.0/glTFLoader.pure.d.ts +1 -1
- package/glTF/2.0/glTFLoader.pure.js +4 -3
- package/glTF/2.0/glTFLoader.pure.js.map +1 -1
- package/glTF/2.0/glTFLoaderAnimation.d.ts +1 -42
- package/glTF/2.0/glTFLoaderAnimation.js +3 -79
- package/glTF/2.0/glTFLoaderAnimation.js.map +1 -1
- package/glTF/2.0/glTFLoaderAnimation.pure.d.ts +47 -0
- package/glTF/2.0/glTFLoaderAnimation.pure.js +91 -0
- package/glTF/2.0/glTFLoaderAnimation.pure.js.map +1 -0
- package/glTF/2.0/pure.d.ts +1 -0
- package/glTF/2.0/pure.js +1 -0
- package/glTF/2.0/pure.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objFileLoader.metadata.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/objFileLoader.metadata.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACjC,IAAI,EAAE,KAAK;
|
|
1
|
+
{"version":3,"file":"objFileLoader.metadata.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/objFileLoader.metadata.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACjC,IAAI,EAAE,KAAK;IAEX,uEAAuE;IACvE,UAAU,EAAE;QACR,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;KACmB;CACN,CAAC","sourcesContent":["import { type ISceneLoaderPluginExtensions, type ISceneLoaderPluginMetadata } from \"core/index\";\r\n\r\nexport const OBJFileLoaderMetadata = {\r\n name: \"obj\",\r\n\r\n // Read the file as bytes so the loader can decode non-UTF-8 OBJ files.\r\n extensions: {\r\n \".obj\": { isBinary: true },\r\n } as const satisfies ISceneLoaderPluginExtensions,\r\n} as const satisfies ISceneLoaderPluginMetadata;\r\n"]}
|
|
@@ -8,6 +8,10 @@ import { type OBJLoadingOptions } from "./objLoadingOptions.js";
|
|
|
8
8
|
* This is a babylon scene loader plugin.
|
|
9
9
|
*/
|
|
10
10
|
export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {
|
|
11
|
+
/**
|
|
12
|
+
* Defines the character encoding used to decode OBJ and MTL files.
|
|
13
|
+
*/
|
|
14
|
+
static ENCODING: string;
|
|
11
15
|
/**
|
|
12
16
|
* Defines if UVs are optimized by default during load.
|
|
13
17
|
*/
|
|
@@ -59,7 +63,11 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
|
|
|
59
63
|
/**
|
|
60
64
|
* Defines the extension the plugin is able to load.
|
|
61
65
|
*/
|
|
62
|
-
readonly extensions:
|
|
66
|
+
readonly extensions: {
|
|
67
|
+
readonly ".obj": {
|
|
68
|
+
readonly isBinary: true;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
63
71
|
private _assetContainer;
|
|
64
72
|
private _loadingOptions;
|
|
65
73
|
/**
|
|
@@ -81,6 +89,7 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
|
|
|
81
89
|
* @param onFailure
|
|
82
90
|
*/
|
|
83
91
|
private _loadMTL;
|
|
92
|
+
private _decode;
|
|
84
93
|
/** @internal */
|
|
85
94
|
createPlugin(options: SceneLoaderPluginOptions): ISceneLoaderPluginAsync | ISceneLoaderPlugin;
|
|
86
95
|
/**
|
|
@@ -104,7 +113,7 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
|
|
|
104
113
|
* @param rootUrl root url to load from
|
|
105
114
|
* @returns a promise which completes when objects have been loaded to the scene
|
|
106
115
|
*/
|
|
107
|
-
loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void>;
|
|
116
|
+
loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string): Promise<void>;
|
|
108
117
|
/**
|
|
109
118
|
* Load into an asset container.
|
|
110
119
|
* @param scene The scene to load into
|
|
@@ -112,7 +121,7 @@ export declare class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoa
|
|
|
112
121
|
* @param rootUrl The root url for scene and resources
|
|
113
122
|
* @returns The loaded asset container
|
|
114
123
|
*/
|
|
115
|
-
loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer>;
|
|
124
|
+
loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string): Promise<AssetContainer>;
|
|
116
125
|
/**
|
|
117
126
|
* Read the OBJ file and create an Array of meshes.
|
|
118
127
|
* Each mesh contains all information given by the OBJ and the MTL file.
|
|
@@ -39,6 +39,7 @@ export class OBJFileLoader {
|
|
|
39
39
|
}
|
|
40
40
|
static get _DefaultLoadingOptions() {
|
|
41
41
|
return {
|
|
42
|
+
encoding: OBJFileLoader.ENCODING,
|
|
42
43
|
computeNormals: OBJFileLoader.COMPUTE_NORMALS,
|
|
43
44
|
optimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
|
|
44
45
|
importVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
|
|
@@ -67,10 +68,32 @@ export class OBJFileLoader {
|
|
|
67
68
|
//The complete path to the mtl file
|
|
68
69
|
const pathOfFile = rootUrl + url;
|
|
69
70
|
// Loads through the babylon tools to allow fileInput search.
|
|
70
|
-
Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined,
|
|
71
|
+
Tools.LoadFile(pathOfFile, onSuccess, undefined, undefined, true, (request, exception) => {
|
|
71
72
|
onFailure(pathOfFile, exception);
|
|
72
73
|
});
|
|
73
74
|
}
|
|
75
|
+
_decode(data) {
|
|
76
|
+
if (typeof data === "string") {
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
const bytes = new Uint8Array(data);
|
|
80
|
+
const encoding = this._loadingOptions.encoding ?? "auto";
|
|
81
|
+
if (encoding !== "auto") {
|
|
82
|
+
return new TextDecoder(encoding).decode(bytes);
|
|
83
|
+
}
|
|
84
|
+
if (bytes[0] === 0xff && bytes[1] === 0xfe) {
|
|
85
|
+
return new TextDecoder("utf-16le").decode(bytes);
|
|
86
|
+
}
|
|
87
|
+
if (bytes[0] === 0xfe && bytes[1] === 0xff) {
|
|
88
|
+
return new TextDecoder("utf-16be").decode(bytes);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return new TextDecoder("gb18030").decode(bytes);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
74
97
|
/** @internal */
|
|
75
98
|
createPlugin(options) {
|
|
76
99
|
return new OBJFileLoader(options[OBJFileLoaderMetadata.name]);
|
|
@@ -178,6 +201,7 @@ export class OBJFileLoader {
|
|
|
178
201
|
const materialsFromMTLFile = new MTLFileLoader();
|
|
179
202
|
const materialToUse = [];
|
|
180
203
|
const babylonMeshesArray = []; //The mesh for babylon
|
|
204
|
+
data = this._decode(data);
|
|
181
205
|
// Sanitize data
|
|
182
206
|
data = data.replace(/#.*$/gm, "").trim();
|
|
183
207
|
// Main function
|
|
@@ -194,7 +218,7 @@ export class OBJFileLoader {
|
|
|
194
218
|
this._loadMTL(fileToLoad, rootUrl, (dataLoaded) => {
|
|
195
219
|
try {
|
|
196
220
|
//Create materials thanks MTLLoader function
|
|
197
|
-
materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, this._assetContainer);
|
|
221
|
+
materialsFromMTLFile.parseMTL(scene, this._decode(dataLoaded), rootUrl, this._assetContainer);
|
|
198
222
|
//Look at each material loaded in the mtl file
|
|
199
223
|
for (let n = 0; n < materialsFromMTLFile.materials.length; n++) {
|
|
200
224
|
//Three variables to get all meshes with the same material
|
|
@@ -274,6 +298,10 @@ export class OBJFileLoader {
|
|
|
274
298
|
});
|
|
275
299
|
}
|
|
276
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Defines the character encoding used to decode OBJ and MTL files.
|
|
303
|
+
*/
|
|
304
|
+
OBJFileLoader.ENCODING = "auto";
|
|
277
305
|
/**
|
|
278
306
|
* Defines if UVs are optimized by default during load.
|
|
279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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,GAAiB,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,AAAlC,CAAmC;AAC3D;;GAEG;AACW,4BAAc,GAAG,KAAK,AAAR,CAAS;AAErC;;;;GAIG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ;AAErD;;GAEG;AACW,iCAAmB,GAAG,KAAK,AAAR,CAAS;AAkS9C,0CAA0C;AAE1C,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACjC,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,yBAAyB,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/promise-function-async */\r\nimport { type Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector.pure\";\r\nimport { Tools } from \"core/Misc/tools.pure\";\r\nimport { type AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport {\r\n type ISceneLoaderPluginAsync,\r\n type ISceneLoaderPluginFactory,\r\n type ISceneLoaderPlugin,\r\n type ISceneLoaderAsyncResult,\r\n type SceneLoaderPluginOptions,\r\n RegisterSceneLoaderPlugin,\r\n} 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 { OBJFileLoaderMetadata } from \"./objFileLoader.metadata\";\r\nimport { MTLFileLoader } from \"./mtlFileLoader\";\r\nimport { type OBJLoadingOptions } from \"./objLoadingOptions\";\r\nimport { SolidParser } from \"./solidParser\";\r\nimport { type Mesh } from \"core/Meshes/mesh.pure\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial.pure\";\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 = /*#__PURE__*/ 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 = OBJFileLoaderMetadata.name;\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public readonly extensions = OBJFileLoaderMetadata.extensions;\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?: Partial<Readonly<OBJLoadingOptions>>) {\r\n this._loadingOptions = { ...OBJFileLoader._DefaultLoadingOptions, ...(loadingOptions ?? {}) };\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, exception?: any) => {\r\n onFailure(pathOfFile, exception);\r\n });\r\n }\r\n\r\n /** @internal */\r\n createPlugin(options: SceneLoaderPluginOptions): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new OBJFileLoader(options[OBJFileLoaderMetadata.name]);\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 // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n //get the meshes from OBJ file\r\n // eslint-disable-next-line github/no-then\r\n return this._parseSolidAsync(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 // eslint-disable-next-line no-restricted-syntax\r\n public loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n // eslint-disable-next-line github/no-then\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 // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\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 (\r\n this.importMeshAsync(null, scene, data, rootUrl)\r\n // eslint-disable-next-line github/no-then\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 // eslint-disable-next-line github/no-then\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n })\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 // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n private _parseSolidAsync(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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\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 // eslint-disable-next-line github/no-then\r\n return Promise.all(mtlPromises).then(() => {\r\n const isLine = (mesh: AbstractMesh) => Boolean(mesh._internalMetadata?.[\"_isLine\"] ?? false);\r\n\r\n // Iterate over the mesh, determine if it is a line mesh, clone or modify the material to line rendering.\r\n babylonMeshesArray.forEach((mesh) => {\r\n if (isLine(mesh)) {\r\n let mat = mesh.material ?? new StandardMaterial(mesh.name + \"_line\", scene);\r\n // If another mesh is using this material and it is not a line then we need to clone it.\r\n const needClone = mat.getBindedMeshes().filter((e) => !isLine(e)).length > 0;\r\n if (needClone) {\r\n mat = mat.clone(mat.name + \"_line\") ?? mat;\r\n }\r\n mat.wireframe = true;\r\n mesh.material = mat;\r\n if (mesh._internalMetadata) {\r\n mesh._internalMetadata[\"_isLine\"] = undefined;\r\n }\r\n }\r\n });\r\n\r\n return babylonMeshesArray;\r\n });\r\n }\r\n}\r\n\r\n//Add this loader into the register plugin\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the OBJFileLoader scene loader plugin.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\nexport function RegisterOBJFileLoader(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n RegisterSceneLoaderPlugin(new OBJFileLoader());\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":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GAAG,KAAK,AAAR,CAAS;AACtC;;;GAGG;AACW,8BAAgB,GAAG,KAAK,AAAR,CAAS;AACvC;;GAEG;AACW,wBAAU,GAAiB,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,AAAlC,CAAmC;AAC3D;;GAEG;AACW,4BAAc,GAAG,KAAK,AAAR,CAAS;AAErC;;;;GAIG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ;AAErD;;GAEG;AACW,iCAAmB,GAAG,KAAK,AAAR,CAAS;AA8T9C,0CAA0C;AAE1C,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACjC,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,yBAAyB,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/promise-function-async */\r\nimport { type Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector.pure\";\r\nimport { Tools } from \"core/Misc/tools.pure\";\r\nimport { type AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport {\r\n type ISceneLoaderPluginAsync,\r\n type ISceneLoaderPluginFactory,\r\n type ISceneLoaderPlugin,\r\n type ISceneLoaderAsyncResult,\r\n type SceneLoaderPluginOptions,\r\n RegisterSceneLoaderPlugin,\r\n} 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 { OBJFileLoaderMetadata } from \"./objFileLoader.metadata\";\r\nimport { MTLFileLoader } from \"./mtlFileLoader\";\r\nimport { type OBJLoadingOptions } from \"./objLoadingOptions\";\r\nimport { SolidParser } from \"./solidParser\";\r\nimport { type Mesh } from \"core/Meshes/mesh.pure\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial.pure\";\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 the character encoding used to decode OBJ and MTL files.\r\n */\r\n public static ENCODING = \"auto\";\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 = /*#__PURE__*/ 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 = OBJFileLoaderMetadata.name;\r\n /**\r\n * Defines the extension the plugin is able to load.\r\n */\r\n public readonly extensions = OBJFileLoaderMetadata.extensions;\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?: Partial<Readonly<OBJLoadingOptions>>) {\r\n this._loadingOptions = { ...OBJFileLoader._DefaultLoadingOptions, ...(loadingOptions ?? {}) };\r\n }\r\n\r\n private static get _DefaultLoadingOptions(): OBJLoadingOptions {\r\n return {\r\n encoding: OBJFileLoader.ENCODING,\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, true, (request?: WebRequest, exception?: any) => {\r\n onFailure(pathOfFile, exception);\r\n });\r\n }\r\n\r\n private _decode(data: string | ArrayBuffer): string {\r\n if (typeof data === \"string\") {\r\n return data;\r\n }\r\n\r\n const bytes = new Uint8Array(data);\r\n const encoding = this._loadingOptions.encoding ?? \"auto\";\r\n if (encoding !== \"auto\") {\r\n return new TextDecoder(encoding).decode(bytes);\r\n }\r\n\r\n if (bytes[0] === 0xff && bytes[1] === 0xfe) {\r\n return new TextDecoder(\"utf-16le\").decode(bytes);\r\n }\r\n if (bytes[0] === 0xfe && bytes[1] === 0xff) {\r\n return new TextDecoder(\"utf-16be\").decode(bytes);\r\n }\r\n\r\n try {\r\n return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\r\n } catch {\r\n return new TextDecoder(\"gb18030\").decode(bytes);\r\n }\r\n }\r\n\r\n /** @internal */\r\n createPlugin(options: SceneLoaderPluginOptions): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new OBJFileLoader(options[OBJFileLoaderMetadata.name]);\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 // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n //get the meshes from OBJ file\r\n // eslint-disable-next-line github/no-then\r\n return this._parseSolidAsync(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 // eslint-disable-next-line no-restricted-syntax\r\n public loadAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n // eslint-disable-next-line github/no-then\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 // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public loadAssetContainerAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string): Promise<AssetContainer> {\r\n const container = new AssetContainer(scene);\r\n this._assetContainer = container;\r\n\r\n return (\r\n this.importMeshAsync(null, scene, data, rootUrl)\r\n // eslint-disable-next-line github/no-then\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 // eslint-disable-next-line github/no-then\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n })\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 // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n private _parseSolidAsync(meshesNames: any, scene: Scene, data: string | ArrayBuffer, 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 data = this._decode(data);\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, this._decode(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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\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 // eslint-disable-next-line github/no-then\r\n return Promise.all(mtlPromises).then(() => {\r\n const isLine = (mesh: AbstractMesh) => Boolean(mesh._internalMetadata?.[\"_isLine\"] ?? false);\r\n\r\n // Iterate over the mesh, determine if it is a line mesh, clone or modify the material to line rendering.\r\n babylonMeshesArray.forEach((mesh) => {\r\n if (isLine(mesh)) {\r\n let mat = mesh.material ?? new StandardMaterial(mesh.name + \"_line\", scene);\r\n // If another mesh is using this material and it is not a line then we need to clone it.\r\n const needClone = mat.getBindedMeshes().filter((e) => !isLine(e)).length > 0;\r\n if (needClone) {\r\n mat = mat.clone(mat.name + \"_line\") ?? mat;\r\n }\r\n mat.wireframe = true;\r\n mesh.material = mat;\r\n if (mesh._internalMetadata) {\r\n mesh._internalMetadata[\"_isLine\"] = undefined;\r\n }\r\n }\r\n });\r\n\r\n return babylonMeshesArray;\r\n });\r\n }\r\n}\r\n\r\n//Add this loader into the register plugin\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the OBJFileLoader scene loader plugin.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\nexport function RegisterOBJFileLoader(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n RegisterSceneLoaderPlugin(new OBJFileLoader());\r\n}\r\n"]}
|
|
@@ -3,6 +3,12 @@ import { type Vector2 } from "@babylonjs/core/Maths/math.vector.js";
|
|
|
3
3
|
* Options for loading OBJ/MTL files
|
|
4
4
|
*/
|
|
5
5
|
export type OBJLoadingOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Defines the character encoding used to decode OBJ and MTL files.
|
|
8
|
+
* Use "auto" to detect UTF-8/UTF-16 and fall back to GB18030, or provide an encoding label supported by TextDecoder.
|
|
9
|
+
* Defaults to "auto".
|
|
10
|
+
*/
|
|
11
|
+
encoding?: string;
|
|
6
12
|
/**
|
|
7
13
|
* Defines if UVs are optimized by default during load.
|
|
8
14
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objLoadingOptions.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/objLoadingOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { type Vector2 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Options for loading OBJ/MTL files\r\n */\r\nexport type OBJLoadingOptions = {\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n optimizeWithUV: boolean;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: Vector2;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n invertY: boolean;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n invertTextureY: boolean;\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 importVertexColors: boolean;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n computeNormals: boolean;\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 optimizeNormals: boolean;\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n skipMaterials: boolean;\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 materialLoadingFailsSilently: boolean;\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 useLegacyBehavior: boolean;\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"objLoadingOptions.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/objLoadingOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { type Vector2 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Options for loading OBJ/MTL files\r\n */\r\nexport type OBJLoadingOptions = {\r\n /**\r\n * Defines the character encoding used to decode OBJ and MTL files.\r\n * Use \"auto\" to detect UTF-8/UTF-16 and fall back to GB18030, or provide an encoding label supported by TextDecoder.\r\n * Defaults to \"auto\".\r\n */\r\n encoding?: string;\r\n /**\r\n * Defines if UVs are optimized by default during load.\r\n */\r\n optimizeWithUV: boolean;\r\n /**\r\n * Defines custom scaling of UV coordinates of loaded meshes.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n UVScaling: Vector2;\r\n /**\r\n * Invert model on y-axis (does a model scaling inversion)\r\n */\r\n invertY: boolean;\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n invertTextureY: boolean;\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 importVertexColors: boolean;\r\n /**\r\n * Compute the normals for the model, even if normals are present in the file.\r\n */\r\n computeNormals: boolean;\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 optimizeNormals: boolean;\r\n /**\r\n * Skip loading the materials even if defined in the OBJ file (materials are ignored).\r\n */\r\n skipMaterials: boolean;\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 materialLoadingFailsSilently: boolean;\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 useLegacyBehavior: boolean;\r\n};\r\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GaussianSplattingMesh } from "@babylonjs/core/Meshes/GaussianSplatting/gaussianSplattingMesh.js";
|
|
1
|
+
import { GaussianSplattingMesh, type IGaussianSplattingLodBudgetParticipant } from "@babylonjs/core/Meshes/GaussianSplatting/gaussianSplattingMesh.js";
|
|
2
2
|
import { type GaussianSplattingPartProxyMesh } from "@babylonjs/core/Meshes/GaussianSplatting/gaussianSplattingPartProxyMesh.js";
|
|
3
3
|
import { type Scene } from "@babylonjs/core/scene.js";
|
|
4
4
|
import { type Nullable } from "@babylonjs/core/types.js";
|
|
@@ -31,6 +31,9 @@ interface ISOGLODNode {
|
|
|
31
31
|
activeLod?: number;
|
|
32
32
|
/** Distance-based ideal LOD level for this node, recomputed per frame. */
|
|
33
33
|
optimalLod?: number;
|
|
34
|
+
/** Projected screen size (pixels) of the node's AABB — the max across active cameras. Larger nodes keep finer
|
|
35
|
+
* detail under the splat budget. Only computed while the budget is enabled. */
|
|
36
|
+
pixelSize?: number;
|
|
34
37
|
/** Available LOD levels for this leaf, sorted ascending (0 = finest). Set during the tree walk. */
|
|
35
38
|
availableLevels?: number[];
|
|
36
39
|
/** Coarsest available level (= max key), always streamed as the permanent base layer. */
|
|
@@ -132,6 +135,17 @@ export interface IGaussianSplattingStreamOptions {
|
|
|
132
135
|
* return to it avoids a re-download. Only used when a budget enables eviction. PlayCanvas default `100`.
|
|
133
136
|
*/
|
|
134
137
|
evictionCooldownFrames?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Enables budget-driven LOD: caps the total rendered splats by converging a screen-space (size + distance)
|
|
140
|
+
* pixel-size threshold to the budget. Selection is view-direction-independent, so it is consistent across any
|
|
141
|
+
* number of active cameras (each node takes the finest level and largest projected size any camera demands).
|
|
142
|
+
* A number is an explicit splat cap; `"auto"` picks a device-tiered default (desktop 2.5M / iOS 1.5M /
|
|
143
|
+
* other mobile 1M; XR shares the mobile tier). **Undefined (default) disables the cap** — LOD is pure
|
|
144
|
+
* distance, identical to prior behavior. Runtime-mutable via the {@link splatBudget} accessor. When this stream
|
|
145
|
+
* is hosted in a compound, the compound's {@link GaussianSplattingMesh.splatBudget} (if set) overrides this and
|
|
146
|
+
* apportions a shared budget across all its streams.
|
|
147
|
+
*/
|
|
148
|
+
splatBudget?: number | "auto";
|
|
135
149
|
/**
|
|
136
150
|
* When set, the stream does not render itself; instead it reserves a region of this compound mesh and
|
|
137
151
|
* decodes/sorts into it, so its splats are depth-sorted and drawn in ONE pass together with the compound's
|
|
@@ -171,7 +185,7 @@ export interface IGaussianSplattingStreamOptions {
|
|
|
171
185
|
*
|
|
172
186
|
* @experimental
|
|
173
187
|
*/
|
|
174
|
-
export declare class GaussianSplattingStream extends GaussianSplattingMesh {
|
|
188
|
+
export declare class GaussianSplattingStream extends GaussianSplattingMesh implements IGaussianSplattingLodBudgetParticipant {
|
|
175
189
|
private readonly _metadata;
|
|
176
190
|
private readonly _rootUrl;
|
|
177
191
|
private readonly _streamOptions;
|
|
@@ -186,9 +200,12 @@ export declare class GaussianSplattingStream extends GaussianSplattingMesh {
|
|
|
186
200
|
private _lodUpdateInterval;
|
|
187
201
|
private _lodUpdateDistance;
|
|
188
202
|
private _maxDetailLod;
|
|
203
|
+
private _lodPixelThreshold;
|
|
204
|
+
private _hostBudgetAllocation;
|
|
189
205
|
private _frustumCulling;
|
|
190
206
|
private readonly _frustumPlanes;
|
|
191
207
|
private readonly _cullViewProj;
|
|
208
|
+
private readonly _frustumScratch;
|
|
192
209
|
private _workBuffer;
|
|
193
210
|
private _decodeSh;
|
|
194
211
|
private _streamShDegree;
|
|
@@ -219,7 +236,8 @@ export declare class GaussianSplattingStream extends GaussianSplattingMesh {
|
|
|
219
236
|
private _lodObserver;
|
|
220
237
|
private _baseLayerReady;
|
|
221
238
|
private _framesSinceLodUpdate;
|
|
222
|
-
private readonly
|
|
239
|
+
private readonly _lastLodCamPositions;
|
|
240
|
+
private _lastLodSignature;
|
|
223
241
|
private _forceLodUpdate;
|
|
224
242
|
private readonly _boundsMin;
|
|
225
243
|
private readonly _boundsMax;
|
|
@@ -318,6 +336,66 @@ export declare class GaussianSplattingStream extends GaussianSplattingMesh {
|
|
|
318
336
|
*/
|
|
319
337
|
get maxDetailLod(): number;
|
|
320
338
|
set maxDetailLod(value: number);
|
|
339
|
+
/**
|
|
340
|
+
* This stream's own budget-driven LOD cap in splats (see {@link IGaussianSplattingStreamOptions.splatBudget}).
|
|
341
|
+
* `0` disables the budget (pure distance LOD). Setting it caps the rendered splat count, taking effect on the
|
|
342
|
+
* next frame. When this stream is hosted in a compound whose own budget is set, that shared budget overrides
|
|
343
|
+
* this value — read the actual runtime cap from {@link effectiveSplatBudget}, not this getter (which always
|
|
344
|
+
* reports the configured own cap).
|
|
345
|
+
* @experimental
|
|
346
|
+
*/
|
|
347
|
+
get splatBudget(): number;
|
|
348
|
+
set splatBudget(value: number);
|
|
349
|
+
/**
|
|
350
|
+
* The splat cap actually in force this frame: a hosting compound's apportioned allocation when this stream is
|
|
351
|
+
* coordinated, otherwise this stream's own {@link splatBudget}, clamped to what can be kept resident. `0` means
|
|
352
|
+
* no cap (pure distance LOD). Unlike {@link splatBudget}, this reflects the compound override, so it is the value
|
|
353
|
+
* to display or reason about at runtime.
|
|
354
|
+
* @experimental
|
|
355
|
+
*/
|
|
356
|
+
get effectiveSplatBudget(): number;
|
|
357
|
+
/**
|
|
358
|
+
* Resolves the raw {@link splatBudget} option to a concrete cap: `undefined` ⇒ 0 (disabled), `"auto"` ⇒ a
|
|
359
|
+
* device-tiered default, a positive number ⇒ itself (floored).
|
|
360
|
+
* @param option the raw option value
|
|
361
|
+
* @returns the resolved splat cap (0 = disabled)
|
|
362
|
+
*/
|
|
363
|
+
private _resolveSplatBudget;
|
|
364
|
+
/**
|
|
365
|
+
* Device-tiered default splat budget for {@link splatBudget} `"auto"`: desktop 2.5M, iOS 1.5M, other mobile
|
|
366
|
+
* (incl. Android/XR) 1M. XR is folded into the mobile tier (no reliable at-construction detection).
|
|
367
|
+
* @returns the default splat cap for this device
|
|
368
|
+
*/
|
|
369
|
+
private _computeDefaultSplatBudget;
|
|
370
|
+
/**
|
|
371
|
+
* The splat budget this stream converges against this frame: the compound's apportioned allocation when hosted
|
|
372
|
+
* and coordinated, else this stream's own resolved budget. Clamped to the resident budget so the stream never
|
|
373
|
+
* targets more splats than can be kept resident. `0` means the budget is disabled.
|
|
374
|
+
* @returns the effective splat cap (0 = disabled)
|
|
375
|
+
*/
|
|
376
|
+
private _effectiveSplatBudget;
|
|
377
|
+
/**
|
|
378
|
+
* Whether budget-driven LOD is active this frame.
|
|
379
|
+
* @returns true when a positive effective budget is in force
|
|
380
|
+
*/
|
|
381
|
+
private _splatBudgetEnabled;
|
|
382
|
+
/**
|
|
383
|
+
* {@link IGaussianSplattingLodBudgetParticipant}: the splats this stream would render at full (distance-optimal)
|
|
384
|
+
* detail — its demand on a host compound's shared budget. Computed from the current per-node distance-optimal
|
|
385
|
+
* levels (no pixel threshold), so it does not depend on the allocation it is helping to compute.
|
|
386
|
+
* @returns the full-detail rendered splat count (0 before the base layer is ready)
|
|
387
|
+
*/
|
|
388
|
+
getBudgetDemand(): number;
|
|
389
|
+
/**
|
|
390
|
+
* {@link IGaussianSplattingLodBudgetParticipant}: sets the compound's apportioned share of the shared budget.
|
|
391
|
+
* `null` releases coordination (revert to this stream's own {@link splatBudget}); a number (incl. 0, meaning
|
|
392
|
+
* "coordinated at the coarsest level") drives the pixel-threshold convergence. Any change to the (already integer)
|
|
393
|
+
* allocation forces a next-frame re-eval: a decrease may put the current selection over the new cap, and even a
|
|
394
|
+
* small increase can unlock a finer level that a stationary camera would otherwise never re-evaluate to. The
|
|
395
|
+
* apportioned demand is allocation-independent, so this settles in one step and does not churn frame to frame.
|
|
396
|
+
* @param splats the apportioned allocation, or null to release coordination
|
|
397
|
+
*/
|
|
398
|
+
setBudgetAllocation(splats: Nullable<number>): void;
|
|
321
399
|
/**
|
|
322
400
|
* Coarsest LOD level index in the scene (number of LOD levels minus one). Useful as the upper bound
|
|
323
401
|
* for {@link maxDetailLod}.
|
|
@@ -361,10 +439,17 @@ export declare class GaussianSplattingStream extends GaussianSplattingMesh {
|
|
|
361
439
|
*/
|
|
362
440
|
private _getEffectiveWorldMatrix;
|
|
363
441
|
/**
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
|
|
442
|
+
* The cameras the LOD should serve: `scene.activeCameras` when set (split-view / multi-view), else the single
|
|
443
|
+
* `scene.activeCamera`. Mirrors the sort path's multi-camera handling.
|
|
444
|
+
* @returns the non-null active cameras (may be empty)
|
|
445
|
+
*/
|
|
446
|
+
private _getActiveLodCameras;
|
|
447
|
+
/**
|
|
448
|
+
* Re-evaluates the optimal LOD for every node from the active cameras. Each node takes the finest level and the
|
|
449
|
+
* largest projected pixel size any active camera demands (so every pane of a split view is served), and the
|
|
450
|
+
* frustum bias uses the union of the frusta. Selection is view-direction-independent, so single- and multi-camera
|
|
451
|
+
* rendering are consistent. The results are stored in each node's `optimalLod` / `pixelSize`.
|
|
452
|
+
* @param camera when provided, evaluate against just this camera; otherwise use the active-camera set
|
|
368
453
|
*/
|
|
369
454
|
evaluateOptimalLods(camera?: Nullable<Camera>): void;
|
|
370
455
|
/**
|
|
@@ -548,10 +633,61 @@ export declare class GaussianSplattingStream extends GaussianSplattingMesh {
|
|
|
548
633
|
*/
|
|
549
634
|
private _cappedLevelForNode;
|
|
550
635
|
/**
|
|
551
|
-
* Computes each node's {@link ISOGLODNode.targetLevel}
|
|
552
|
-
*
|
|
636
|
+
* Computes each node's {@link ISOGLODNode.targetLevel}. With the splat budget disabled this is the
|
|
637
|
+
* distance-optimal level snapped to an available level (capped by {@link maxDetailLod}) — unchanged prior
|
|
638
|
+
* behavior. With the budget enabled it converges a global pixel-size threshold to the budget and coarsens each
|
|
639
|
+
* node from its distance-optimal ceiling by how far its projected size falls below that threshold.
|
|
553
640
|
*/
|
|
554
641
|
private _computeTargetLevels;
|
|
642
|
+
/**
|
|
643
|
+
* Splat count of the always-rendered environment layer (0 when none), coerced to a finite non-negative integer.
|
|
644
|
+
* Counted as a fixed cost in both the budget demand and the leaf convergence so it is never over-drawn.
|
|
645
|
+
* @returns the environment's rendered splat count
|
|
646
|
+
*/
|
|
647
|
+
private _environmentSplatCount;
|
|
648
|
+
/**
|
|
649
|
+
* The level a node renders at for a given pixel-size threshold `t`: its distance-optimal ceiling, coarsened by
|
|
650
|
+
* `round(log_mult(t / pixelSize))` geometric steps when its projected size is below `t`. Snapped to
|
|
651
|
+
* an available level honoring {@link maxDetailLod}.
|
|
652
|
+
* @param node leaf node
|
|
653
|
+
* @param t pixel-size threshold (pixels)
|
|
654
|
+
* @returns the chosen available LOD level
|
|
655
|
+
*/
|
|
656
|
+
private _budgetedLevel;
|
|
657
|
+
/**
|
|
658
|
+
* Splat count of a node's file at a given (already snapped) available level.
|
|
659
|
+
* @param node leaf node
|
|
660
|
+
* @param level available LOD level
|
|
661
|
+
* @returns the level's splat count (0 if absent)
|
|
662
|
+
*/
|
|
663
|
+
private _countAtLevel;
|
|
664
|
+
/**
|
|
665
|
+
* Sum of every leaf's rendered splat count at pixel-size threshold `t`.
|
|
666
|
+
* @param t pixel-size threshold (pixels)
|
|
667
|
+
* @returns total rendered splats
|
|
668
|
+
*/
|
|
669
|
+
private _totalSplatsAtThreshold;
|
|
670
|
+
/**
|
|
671
|
+
* Converges the global pixel-size threshold {@link _lodPixelThreshold} to the largest detail whose total rendered
|
|
672
|
+
* splats is still within `budget` (the pixel-scale cut, floored at the true sub-pixel limit of 1 px). The
|
|
673
|
+
* total is monotonically non-increasing in the threshold, so a bisection on `[floorT, ceilT]` — where `ceilT`
|
|
674
|
+
* coarsens every node to its coarsest available level — gives a GUARANTEED result at or under the cap. When even
|
|
675
|
+
* that coarsest state exceeds the budget (the budget is below the pinned minimum detail), the threshold is set to
|
|
676
|
+
* `ceilT` so every node renders at minimum detail — the best achievable; the cap is then unavoidable. O(leaves)
|
|
677
|
+
* per iteration; no decode.
|
|
678
|
+
* @param budget target maximum rendered splat count
|
|
679
|
+
*/
|
|
680
|
+
private _convergePixelThreshold;
|
|
681
|
+
/**
|
|
682
|
+
* The finest already-decoded level of a node that is at least as coarse as `level` (index >= level). Used to
|
|
683
|
+
* enforce the budget cap immediately without waiting for a download. Returns `null` when no such level is resident
|
|
684
|
+
* — including when eviction has freed the base layer — so the caller keeps the currently-visible (resident) file
|
|
685
|
+
* rather than switching to a non-resident one, which would render a hole.
|
|
686
|
+
* @param node leaf node
|
|
687
|
+
* @param level the minimum coarseness (level index) required
|
|
688
|
+
* @returns a resident level index >= level, or null when none is resident
|
|
689
|
+
*/
|
|
690
|
+
private _residentLevelAtLeast;
|
|
555
691
|
/**
|
|
556
692
|
* Applies each node's {@link ISOGLODNode.targetLevel}: switches a node to its target level when that
|
|
557
693
|
* level's file is already decoded, otherwise records a pending download request for the file and leaves
|
|
@@ -605,17 +741,28 @@ export declare class GaussianSplattingStream extends GaussianSplattingMesh {
|
|
|
605
741
|
*/
|
|
606
742
|
private _onLodFrame;
|
|
607
743
|
/**
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
744
|
+
* A cheap signature of the discrete inputs (besides camera translation, tracked separately) that affect projected
|
|
745
|
+
* pixel size: each camera's identity, FOV, FOV mode and viewport, plus the engine render size and the effective
|
|
746
|
+
* world matrix revision. A change invalidates the throttled budget LOD so a colocated camera swap / viewport
|
|
747
|
+
* resize / FOV change — or the stream (or its hosted proxy) being moved or scaled while still in frustum, which
|
|
748
|
+
* shifts every node's distance and projected size — can't leave it stale.
|
|
749
|
+
* @param cameras the active cameras
|
|
750
|
+
* @returns the signature string
|
|
751
|
+
*/
|
|
752
|
+
private _computeLodSignature;
|
|
753
|
+
/**
|
|
754
|
+
* Updates each leaf node's {@link ISOGLODNode.inFrustum} flag: a node is in-frustum if it is inside ANY
|
|
755
|
+
* active camera's frustum (the union). When {@link frustumCulling} is disabled (or there are no cameras)
|
|
756
|
+
* every node is marked in-frustum. Bounds are static (from the LOD tree), so flags are valid for all nodes
|
|
757
|
+
* regardless of decode state. Returns true when any node's in-frustum state changed (so the LOD bias must be re-applied).
|
|
612
758
|
* @returns whether any node's in-frustum state changed
|
|
613
759
|
*/
|
|
614
760
|
private _updateNodeFrustum;
|
|
615
761
|
/**
|
|
616
|
-
* Reads the splat count from SOG metadata
|
|
762
|
+
* Reads the splat count from SOG metadata, coerced to a finite non-negative integer (metadata is untrusted, so
|
|
763
|
+
* `count` / `shape[0]` may be a string or malformed — a non-numeric value must not leak into count arithmetic).
|
|
617
764
|
* @param data SOG metadata
|
|
618
|
-
* @returns the splat count
|
|
765
|
+
* @returns the splat count (0 when absent/invalid)
|
|
619
766
|
*/
|
|
620
767
|
private static _GetSplatCount;
|
|
621
768
|
/**
|