@babylonjs/loaders 6.39.0 → 6.41.0
Sign up to get free protection for your applications and to get access to all the features.
- package/SPLAT/splatFileLoader.d.ts +7 -5
- package/SPLAT/splatFileLoader.js +23 -11
- package/SPLAT/splatFileLoader.js.map +1 -1
- package/glTF/1.0/glTFLoader.d.ts +7 -0
- package/glTF/1.0/glTFLoader.js +19 -1
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +6 -0
- package/glTF/1.0/glTFLoaderUtils.js +6 -0
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +2 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.d.ts +3 -0
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.js +3 -0
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +3 -3
- package/glTF/2.0/glTFLoader.js +15 -5
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +7 -1
- package/glTF/glTFFileLoader.js +2 -1
- package/glTF/glTFFileLoader.js.map +1 -1
- package/package.json +3 -3
@@ -34,11 +34,13 @@ export declare class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneL
|
|
34
34
|
* Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license
|
35
35
|
* Loads a .ply from data array buffer
|
36
36
|
* if data array buffer is not ply, returns the original buffer
|
37
|
+
* @param data the data to load
|
38
|
+
* @returns the loaded buffer
|
37
39
|
*/
|
38
40
|
private _loadPLY;
|
39
41
|
/**
|
40
42
|
* Imports from the loaded gaussian splatting data and adds them to the scene
|
41
|
-
* @param
|
43
|
+
* @param _meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
42
44
|
* @param scene the scene the meshes should be added to
|
43
45
|
* @param data the gaussian splatting data to load
|
44
46
|
* @param rootUrl root url to load from
|
@@ -49,15 +51,15 @@ export declare class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneL
|
|
49
51
|
* Imports all objects from the loaded gaussian splatting data and adds them to the scene
|
50
52
|
* @param scene the scene the objects should be added to
|
51
53
|
* @param data the gaussian splatting data to load
|
52
|
-
* @param
|
54
|
+
* @param _rootUrl root url to load from
|
53
55
|
* @returns a promise which completes when objects have been loaded to the scene
|
54
56
|
*/
|
55
57
|
loadAsync(scene: Scene, data: any, _rootUrl: string): Promise<void>;
|
56
58
|
/**
|
57
59
|
* Load into an asset container.
|
58
|
-
* @param
|
59
|
-
* @param
|
60
|
-
* @param
|
60
|
+
* @param _scene The scene to load into
|
61
|
+
* @param _data The data to import
|
62
|
+
* @param _rootUrl The root url for scene and resources
|
61
63
|
* @returns The loaded asset container
|
62
64
|
*/
|
63
65
|
loadAssetContainerAsync(_scene: Scene, _data: string, _rootUrl: string): Promise<AssetContainer>;
|
package/SPLAT/splatFileLoader.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
2
2
|
import { Quaternion } from "@babylonjs/core/Maths/math.vector.js";
|
3
|
-
import {
|
3
|
+
import { GaussianSplattingMesh } from "@babylonjs/core/Meshes/GaussianSplatting/gaussianSplattingMesh.js";
|
4
4
|
/**
|
5
5
|
* @experimental
|
6
6
|
* SPLAT file type loader.
|
@@ -45,6 +45,8 @@ export class SPLATFileLoader {
|
|
45
45
|
* Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license
|
46
46
|
* Loads a .ply from data array buffer
|
47
47
|
* if data array buffer is not ply, returns the original buffer
|
48
|
+
* @param data the data to load
|
49
|
+
* @returns the loaded buffer
|
48
50
|
*/
|
49
51
|
_loadPLY(data) {
|
50
52
|
const ubuf = new Uint8Array(data);
|
@@ -71,7 +73,7 @@ export class SPLATFileLoader {
|
|
71
73
|
.split("\n")
|
72
74
|
.filter((k) => k.startsWith("property "));
|
73
75
|
for (const prop of filtered) {
|
74
|
-
const [
|
76
|
+
const [, type, name] = prop.split(" ");
|
75
77
|
properties.push({ name, type, offset: rowOffset });
|
76
78
|
if (!offsets[type])
|
77
79
|
throw new Error(`Unsupported property type: ${type}`);
|
@@ -172,32 +174,42 @@ export class SPLATFileLoader {
|
|
172
174
|
}
|
173
175
|
/**
|
174
176
|
* Imports from the loaded gaussian splatting data and adds them to the scene
|
175
|
-
* @param
|
177
|
+
* @param _meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
176
178
|
* @param scene the scene the meshes should be added to
|
177
179
|
* @param data the gaussian splatting data to load
|
178
180
|
* @param rootUrl root url to load from
|
179
181
|
* @returns a promise containing the loaded meshes, particles, skeletons and animations
|
180
182
|
*/
|
181
|
-
importMeshAsync(_meshesNames, scene, data, rootUrl) {
|
182
|
-
const gaussianSplatting = new
|
183
|
-
|
183
|
+
async importMeshAsync(_meshesNames, scene, data, rootUrl) {
|
184
|
+
const gaussianSplatting = new GaussianSplattingMesh("GaussianSplatting", null, scene);
|
185
|
+
await gaussianSplatting.loadFileAsync(rootUrl);
|
186
|
+
return {
|
187
|
+
meshes: [gaussianSplatting],
|
188
|
+
particleSystems: [],
|
189
|
+
skeletons: [],
|
190
|
+
animationGroups: [],
|
191
|
+
transformNodes: [],
|
192
|
+
geometries: [],
|
193
|
+
lights: [],
|
194
|
+
};
|
184
195
|
}
|
185
196
|
/**
|
186
197
|
* Imports all objects from the loaded gaussian splatting data and adds them to the scene
|
187
198
|
* @param scene the scene the objects should be added to
|
188
199
|
* @param data the gaussian splatting data to load
|
189
|
-
* @param
|
200
|
+
* @param _rootUrl root url to load from
|
190
201
|
* @returns a promise which completes when objects have been loaded to the scene
|
191
202
|
*/
|
192
203
|
loadAsync(scene, data, _rootUrl) {
|
193
|
-
const gaussianSplatting = new
|
204
|
+
const gaussianSplatting = new GaussianSplattingMesh("GaussianSplatting", null, scene);
|
194
205
|
return gaussianSplatting.loadDataAsync(this._loadPLY(data));
|
195
206
|
}
|
207
|
+
// eslint-disable-next-line jsdoc/require-returns-check
|
196
208
|
/**
|
197
209
|
* Load into an asset container.
|
198
|
-
* @param
|
199
|
-
* @param
|
200
|
-
* @param
|
210
|
+
* @param _scene The scene to load into
|
211
|
+
* @param _data The data to import
|
212
|
+
* @param _rootUrl The root url for scene and resources
|
201
213
|
* @returns The loaded asset container
|
202
214
|
*/
|
203
215
|
loadAssetContainerAsync(_scene, _data, _rootUrl) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/splatFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,UAAU,EAAE,6CAA+B;AACpD,OAAO,EAAE,iBAAiB,EAAE,yEAA2D;AAIvF;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAiBxB,+CAA+C;IAC/C;;OAEG;IACH;QApBA;;WAEG;QACI,SAAI,GAAG,OAAO,CAAC;QAEtB;;;WAGG;QACI,eAAU,GAAiC;YAC9C,gEAAgE;YAChE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC5B,gEAAgE;YAChE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC7B,CAAC;IAMa,CAAC;IAEhB;;;OAGG;IACH,YAAY;QACR,OAAO,IAAI,eAAe,EAAE,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,aAAa;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACK,QAAQ,CAAC,IAAS;Q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AC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;YACzB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;YACzB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;YACzB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;SAC5B;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;;;;OAOG;IACI,eAAe,CAAC,YAAiB,EAAE,KAAY,EAAE,IAAS,EAAE,OAAe;QAC9E,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,iBAAiB,CAAC,aAAa,CAAC,OAAO,CAAQ,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACI,SAAS,CAAC,KAAY,EAAE,IAAS,EAAE,QAAgB;QACtD,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAC5E,OAAO,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,CAAC;IAED;;;;;;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 { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult, ISceneLoaderPluginExtensions } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { Quaternion } from \"core/Maths/math.vector\";\r\nimport { GaussianSplatting } from \"core/Rendering/GaussianSplatting/gaussianSplatting\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\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 name = \"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 extensions: ISceneLoaderPluginExtensions = {\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 };\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 * Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license\r\n * Loads a .ply from data array buffer\r\n * if data array buffer is not ply, returns the original buffer\r\n */\r\n private _loadPLY(data: any): ArrayBuffer {\r\n const ubuf = new Uint8Array(data);\r\n const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));\r\n const headerEnd = \"end_header\\n\";\r\n const headerEndIndex = header.indexOf(headerEnd);\r\n if (headerEndIndex < 0 || !header) {\r\n return data;\r\n }\r\n const vertexCount = parseInt(/element vertex (\\d+)\\n/.exec(header)![1]);\r\n\r\n let rowOffset = 0;\r\n const offsets: Record<string, number> = {\r\n double: 8,\r\n int: 4,\r\n uint: 4,\r\n float: 4,\r\n short: 2,\r\n ushort: 2,\r\n uchar: 1,\r\n };\r\n\r\n type PlyProperty = {\r\n name: string;\r\n type: string;\r\n offset: number;\r\n };\r\n const properties: PlyProperty[] = [];\r\n const filtered = header\r\n .slice(0, headerEndIndex)\r\n .split(\"\\n\")\r\n .filter((k) => k.startsWith(\"property \"));\r\n for (const prop of filtered) {\r\n const [_p, type, name] = prop.split(\" \");\r\n properties.push({ name, type, offset: rowOffset });\r\n if (!offsets[type]) throw new Error(`Unsupported property type: ${type}`);\r\n rowOffset += offsets[type];\r\n }\r\n\r\n const rowLength = 3 * 4 + 3 * 4 + 4 + 4;\r\n const SH_C0 = 0.28209479177387814;\r\n\r\n const dataView = new DataView(data, headerEndIndex + headerEnd.length);\r\n const buffer = new ArrayBuffer(rowLength * vertexCount);\r\n const q = new Quaternion();\r\n\r\n for (let i = 0; i < vertexCount; i++) {\r\n const position = new Float32Array(buffer, i * rowLength, 3);\r\n const scale = new Float32Array(buffer, i * rowLength + 12, 3);\r\n const rgba = new Uint8ClampedArray(buffer, i * rowLength + 24, 4);\r\n const rot = new Uint8ClampedArray(buffer, i * rowLength + 28, 4);\r\n\r\n let r0: number = 255;\r\n let r1: number = 0;\r\n let r2: number = 0;\r\n let r3: number = 0;\r\n\r\n for (let propertyIndex = 0; propertyIndex < properties.length; propertyIndex++) {\r\n const property = properties[propertyIndex];\r\n let value;\r\n switch (property.type) {\r\n case \"float\":\r\n value = dataView.getFloat32(property.offset + i * rowOffset, true);\r\n break;\r\n case \"int\":\r\n value = dataView.getInt32(property.offset + i * rowOffset, true);\r\n break;\r\n default:\r\n throw new Error(`Unsupported property type: ${property.type}`);\r\n }\r\n\r\n switch (property.name) {\r\n case \"x\":\r\n position[0] = value;\r\n break;\r\n case \"y\":\r\n position[1] = value;\r\n break;\r\n case \"z\":\r\n position[2] = value;\r\n break;\r\n case \"scale_0\":\r\n scale[0] = Math.exp(value);\r\n break;\r\n case \"scale_1\":\r\n scale[1] = Math.exp(value);\r\n break;\r\n case \"scale_2\":\r\n scale[2] = Math.exp(value);\r\n break;\r\n case \"red\":\r\n rgba[0] = value;\r\n break;\r\n case \"green\":\r\n rgba[1] = value;\r\n break;\r\n case \"blue\":\r\n rgba[2] = value;\r\n break;\r\n case \"f_dc_0\":\r\n rgba[0] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_1\":\r\n rgba[1] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_2\":\r\n rgba[2] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_3\":\r\n rgba[3] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"opacity\":\r\n rgba[3] = (1 / (1 + Math.exp(-value))) * 255;\r\n break;\r\n case \"rot_0\":\r\n r0 = value;\r\n break;\r\n case \"rot_1\":\r\n r1 = value;\r\n break;\r\n case \"rot_2\":\r\n r2 = value;\r\n break;\r\n case \"rot_3\":\r\n r3 = value;\r\n break;\r\n }\r\n }\r\n\r\n q.set(r1, r2, r3, r0);\r\n q.normalize();\r\n rot[0] = q.w * 128 + 128;\r\n rot[1] = q.x * 128 + 128;\r\n rot[2] = q.y * 128 + 128;\r\n rot[3] = q.z * 128 + 128;\r\n }\r\n\r\n return buffer;\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 * @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 const gaussianSplatting = new GaussianSplatting(\"\", scene);\r\n return gaussianSplatting.loadFileAsync(rootUrl) as any;\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 GaussianSplatting(\"GaussianSplatting\", scene);\r\n return gaussianSplatting.loadDataAsync(this._loadPLY(data));\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 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"]}
|
1
|
+
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/splatFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,UAAU,EAAE,6CAA+B;AACpD,OAAO,EAAE,qBAAqB,EAAE,0EAA4D;AAI5F;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAiBxB,+CAA+C;IAC/C;;OAEG;IACH;QApBA;;WAEG;QACI,SAAI,GAAG,OAAO,CAAC;QAEtB;;;WAGG;QACI,eAAU,GAAiC;YAC9C,gEAAgE;YAChE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC5B,gEAAgE;YAChE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC7B,CAAC;IAMa,CAAC;IAEhB;;;OAGG;IACH,YAAY;QACR,OAAO,IAAI,eAAe,EAAE,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,aAAa;QAChB,OAAO,KAAK,CAAC;IACjB,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CACJ;AAED,IAAI,WAAW,EAAE;IACb,0CAA0C;IAC1C,WAAW,CAAC,cAAc,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC;CACrD","sourcesContent":["import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult, ISceneLoaderPluginExtensions } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { Quaternion } from \"core/Maths/math.vector\";\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/**\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 name = \"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 extensions: ISceneLoaderPluginExtensions = {\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 };\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 * Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license\r\n * Loads a .ply from data array buffer\r\n * if data array buffer is not ply, returns the original buffer\r\n * @param data the data to load\r\n * @returns the loaded buffer\r\n */\r\n private _loadPLY(data: any): ArrayBuffer {\r\n const ubuf = new Uint8Array(data);\r\n const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));\r\n const headerEnd = \"end_header\\n\";\r\n const headerEndIndex = header.indexOf(headerEnd);\r\n if (headerEndIndex < 0 || !header) {\r\n return data;\r\n }\r\n const vertexCount = parseInt(/element vertex (\\d+)\\n/.exec(header)![1]);\r\n\r\n let rowOffset = 0;\r\n const offsets: Record<string, number> = {\r\n double: 8,\r\n int: 4,\r\n uint: 4,\r\n float: 4,\r\n short: 2,\r\n ushort: 2,\r\n uchar: 1,\r\n };\r\n\r\n type PlyProperty = {\r\n name: string;\r\n type: string;\r\n offset: number;\r\n };\r\n const properties: PlyProperty[] = [];\r\n const filtered = header\r\n .slice(0, headerEndIndex)\r\n .split(\"\\n\")\r\n .filter((k) => k.startsWith(\"property \"));\r\n for (const prop of filtered) {\r\n const [, type, name] = prop.split(\" \");\r\n properties.push({ name, type, offset: rowOffset });\r\n if (!offsets[type]) throw new Error(`Unsupported property type: ${type}`);\r\n rowOffset += offsets[type];\r\n }\r\n\r\n const rowLength = 3 * 4 + 3 * 4 + 4 + 4;\r\n const SH_C0 = 0.28209479177387814;\r\n\r\n const dataView = new DataView(data, headerEndIndex + headerEnd.length);\r\n const buffer = new ArrayBuffer(rowLength * vertexCount);\r\n const q = new Quaternion();\r\n\r\n for (let i = 0; i < vertexCount; i++) {\r\n const position = new Float32Array(buffer, i * rowLength, 3);\r\n const scale = new Float32Array(buffer, i * rowLength + 12, 3);\r\n const rgba = new Uint8ClampedArray(buffer, i * rowLength + 24, 4);\r\n const rot = new Uint8ClampedArray(buffer, i * rowLength + 28, 4);\r\n\r\n let r0: number = 255;\r\n let r1: number = 0;\r\n let r2: number = 0;\r\n let r3: number = 0;\r\n\r\n for (let propertyIndex = 0; propertyIndex < properties.length; propertyIndex++) {\r\n const property = properties[propertyIndex];\r\n let value;\r\n switch (property.type) {\r\n case \"float\":\r\n value = dataView.getFloat32(property.offset + i * rowOffset, true);\r\n break;\r\n case \"int\":\r\n value = dataView.getInt32(property.offset + i * rowOffset, true);\r\n break;\r\n default:\r\n throw new Error(`Unsupported property type: ${property.type}`);\r\n }\r\n\r\n switch (property.name) {\r\n case \"x\":\r\n position[0] = value;\r\n break;\r\n case \"y\":\r\n position[1] = value;\r\n break;\r\n case \"z\":\r\n position[2] = value;\r\n break;\r\n case \"scale_0\":\r\n scale[0] = Math.exp(value);\r\n break;\r\n case \"scale_1\":\r\n scale[1] = Math.exp(value);\r\n break;\r\n case \"scale_2\":\r\n scale[2] = Math.exp(value);\r\n break;\r\n case \"red\":\r\n rgba[0] = value;\r\n break;\r\n case \"green\":\r\n rgba[1] = value;\r\n break;\r\n case \"blue\":\r\n rgba[2] = value;\r\n break;\r\n case \"f_dc_0\":\r\n rgba[0] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_1\":\r\n rgba[1] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_2\":\r\n rgba[2] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_3\":\r\n rgba[3] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"opacity\":\r\n rgba[3] = (1 / (1 + Math.exp(-value))) * 255;\r\n break;\r\n case \"rot_0\":\r\n r0 = value;\r\n break;\r\n case \"rot_1\":\r\n r1 = value;\r\n break;\r\n case \"rot_2\":\r\n r2 = value;\r\n break;\r\n case \"rot_3\":\r\n r3 = value;\r\n break;\r\n }\r\n }\r\n\r\n q.set(r1, r2, r3, r0);\r\n q.normalize();\r\n rot[0] = q.w * 128 + 128;\r\n rot[1] = q.x * 128 + 128;\r\n rot[2] = q.y * 128 + 128;\r\n rot[3] = q.z * 128 + 128;\r\n }\r\n\r\n return buffer;\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 * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public async importMeshAsync(_meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene);\r\n await gaussianSplatting.loadFileAsync(rootUrl);\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 };\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(this._loadPLY(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/glTF/1.0/glTFLoader.d.ts
CHANGED
@@ -68,6 +68,7 @@ export declare abstract class GLTFLoaderExtension {
|
|
68
68
|
* @param rootUrl
|
69
69
|
* @param onSuccess
|
70
70
|
* @param onError
|
71
|
+
* @returns true to stop further extensions from loading the runtime
|
71
72
|
*/
|
72
73
|
loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): boolean;
|
73
74
|
/**
|
@@ -76,6 +77,7 @@ export declare abstract class GLTFLoaderExtension {
|
|
76
77
|
* @param gltfRuntime
|
77
78
|
* @param onSuccess
|
78
79
|
* @param onError
|
80
|
+
* @returns true to stop further extensions from creating the runtime
|
79
81
|
*/
|
80
82
|
loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError?: (message: string) => void): boolean;
|
81
83
|
/**
|
@@ -86,6 +88,7 @@ export declare abstract class GLTFLoaderExtension {
|
|
86
88
|
* @param onSuccess
|
87
89
|
* @param onError
|
88
90
|
* @param onProgress
|
91
|
+
* @returns true to stop further extensions from loading this buffer
|
89
92
|
*/
|
90
93
|
loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void, onProgress?: () => void): boolean;
|
91
94
|
/**
|
@@ -95,6 +98,7 @@ export declare abstract class GLTFLoaderExtension {
|
|
95
98
|
* @param id
|
96
99
|
* @param onSuccess
|
97
100
|
* @param onError
|
101
|
+
* @returns true to stop further extensions from loading this texture data
|
98
102
|
*/
|
99
103
|
loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
|
100
104
|
/**
|
@@ -105,6 +109,7 @@ export declare abstract class GLTFLoaderExtension {
|
|
105
109
|
* @param buffer
|
106
110
|
* @param onSuccess
|
107
111
|
* @param onError
|
112
|
+
* @returns true to stop further extensions from loading this texture
|
108
113
|
*/
|
109
114
|
createTextureAsync(gltfRuntime: IGLTFRuntime, id: string, buffer: ArrayBufferView, onSuccess: (texture: Texture) => void, onError: (message: string) => void): boolean;
|
110
115
|
/**
|
@@ -114,6 +119,7 @@ export declare abstract class GLTFLoaderExtension {
|
|
114
119
|
* @param id
|
115
120
|
* @param onSuccess
|
116
121
|
* @param onError
|
122
|
+
* @returns true to stop further extensions from loading this shader data
|
117
123
|
*/
|
118
124
|
loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void, onError: (message: string) => void): boolean;
|
119
125
|
/**
|
@@ -123,6 +129,7 @@ export declare abstract class GLTFLoaderExtension {
|
|
123
129
|
* @param id
|
124
130
|
* @param onSuccess
|
125
131
|
* @param onError
|
132
|
+
* @returns true to stop further extensions from loading this material
|
126
133
|
*/
|
127
134
|
loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
|
128
135
|
static LoadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess?: (gltfRuntime: IGLTFRuntime) => void, onError?: (message: string) => void): void;
|
package/glTF/1.0/glTFLoader.js
CHANGED
@@ -269,7 +269,7 @@ const loadAnimations = (gltfRuntime) => {
|
|
269
269
|
}
|
270
270
|
};
|
271
271
|
/**
|
272
|
-
*
|
272
|
+
* @returns the bones transformation matrix
|
273
273
|
* @param node
|
274
274
|
*/
|
275
275
|
const configureBoneTransformation = (node) => {
|
@@ -291,6 +291,7 @@ const configureBoneTransformation = (node) => {
|
|
291
291
|
* @param skins
|
292
292
|
* @param jointName
|
293
293
|
* @param newSkeleton
|
294
|
+
* @returns the parent bone
|
294
295
|
*/
|
295
296
|
const getParentBone = (gltfRuntime, skins, jointName, newSkeleton) => {
|
296
297
|
// Try to find
|
@@ -326,6 +327,7 @@ const getParentBone = (gltfRuntime, skins, jointName, newSkeleton) => {
|
|
326
327
|
* Returns the appropriate root node
|
327
328
|
* @param nodesToRoot
|
328
329
|
* @param id
|
330
|
+
* @returns the root node
|
329
331
|
*/
|
330
332
|
const getNodeToRoot = (nodesToRoot, id) => {
|
331
333
|
for (let i = 0; i < nodesToRoot.length; i++) {
|
@@ -343,6 +345,7 @@ const getNodeToRoot = (nodesToRoot, id) => {
|
|
343
345
|
* Returns the node with the joint name
|
344
346
|
* @param gltfRuntime
|
345
347
|
* @param jointName
|
348
|
+
* @returns the node with the joint name
|
346
349
|
*/
|
347
350
|
const getJointNode = (gltfRuntime, jointName) => {
|
348
351
|
const nodes = gltfRuntime.nodes;
|
@@ -368,6 +371,7 @@ const getJointNode = (gltfRuntime, jointName) => {
|
|
368
371
|
* Checks if a nodes is in joints
|
369
372
|
* @param skins
|
370
373
|
* @param id
|
374
|
+
* @returns true if the node is in joints, else false
|
371
375
|
*/
|
372
376
|
const nodeIsInJoints = (skins, id) => {
|
373
377
|
for (let i = 0; i < skins.jointNames.length; i++) {
|
@@ -423,6 +427,7 @@ const getNodesToRoot = (gltfRuntime, newSkeleton, skins, nodesToRoot) => {
|
|
423
427
|
* @param skins
|
424
428
|
* @param mesh
|
425
429
|
* @param newSkeleton
|
430
|
+
* @returns the bone name
|
426
431
|
*/
|
427
432
|
const importSkeleton = (gltfRuntime, skins, mesh, newSkeleton) => {
|
428
433
|
if (!newSkeleton) {
|
@@ -525,6 +530,7 @@ const importSkeleton = (gltfRuntime, skins, mesh, newSkeleton) => {
|
|
525
530
|
* @param meshes
|
526
531
|
* @param id
|
527
532
|
* @param newMesh
|
533
|
+
* @returns the new mesh
|
528
534
|
*/
|
529
535
|
const importMesh = (gltfRuntime, node, meshes, id, newMesh) => {
|
530
536
|
if (!newMesh) {
|
@@ -718,6 +724,7 @@ const configureNodeFromMatrix = (newNode, node) => {
|
|
718
724
|
* @param gltfRuntime
|
719
725
|
* @param node
|
720
726
|
* @param id
|
727
|
+
* @returns the newly imported node
|
721
728
|
*/
|
722
729
|
const importNode = (gltfRuntime, node, id) => {
|
723
730
|
let lastNode = null;
|
@@ -1018,6 +1025,7 @@ const prepareShaderMaterialUniforms = (gltfRuntime, shaderMaterial, technique, m
|
|
1018
1025
|
* @param program
|
1019
1026
|
* @param shaderMaterial
|
1020
1027
|
* @param onError
|
1028
|
+
* @returns callback when shader is compiled
|
1021
1029
|
*/
|
1022
1030
|
const onShaderCompileError = (program, shaderMaterial, onError) => {
|
1023
1031
|
return (effect, error) => {
|
@@ -1033,6 +1041,7 @@ const onShaderCompileError = (program, shaderMaterial, onError) => {
|
|
1033
1041
|
* @param material
|
1034
1042
|
* @param unTreatedUniforms
|
1035
1043
|
* @param onSuccess
|
1044
|
+
* @returns callback when shader is compiled
|
1036
1045
|
*/
|
1037
1046
|
const onShaderCompileSuccess = (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) => {
|
1038
1047
|
return (_) => {
|
@@ -1046,6 +1055,8 @@ const onShaderCompileSuccess = (gltfRuntime, shaderMaterial, technique, material
|
|
1046
1055
|
* Returns the appropriate uniform if already handled by babylon
|
1047
1056
|
* @param tokenizer
|
1048
1057
|
* @param technique
|
1058
|
+
* @param unTreatedUniforms
|
1059
|
+
* @returns the name of the uniform handled by babylon
|
1049
1060
|
*/
|
1050
1061
|
const parseShaderUniforms = (tokenizer, technique, unTreatedUniforms) => {
|
1051
1062
|
for (const unif in technique.uniforms) {
|
@@ -1642,6 +1653,7 @@ export class GLTFLoaderExtension {
|
|
1642
1653
|
* @param rootUrl
|
1643
1654
|
* @param onSuccess
|
1644
1655
|
* @param onError
|
1656
|
+
* @returns true to stop further extensions from loading the runtime
|
1645
1657
|
*/
|
1646
1658
|
loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError) {
|
1647
1659
|
return false;
|
@@ -1652,6 +1664,7 @@ export class GLTFLoaderExtension {
|
|
1652
1664
|
* @param gltfRuntime
|
1653
1665
|
* @param onSuccess
|
1654
1666
|
* @param onError
|
1667
|
+
* @returns true to stop further extensions from creating the runtime
|
1655
1668
|
*/
|
1656
1669
|
loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError) {
|
1657
1670
|
return false;
|
@@ -1664,6 +1677,7 @@ export class GLTFLoaderExtension {
|
|
1664
1677
|
* @param onSuccess
|
1665
1678
|
* @param onError
|
1666
1679
|
* @param onProgress
|
1680
|
+
* @returns true to stop further extensions from loading this buffer
|
1667
1681
|
*/
|
1668
1682
|
loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress) {
|
1669
1683
|
return false;
|
@@ -1675,6 +1689,7 @@ export class GLTFLoaderExtension {
|
|
1675
1689
|
* @param id
|
1676
1690
|
* @param onSuccess
|
1677
1691
|
* @param onError
|
1692
|
+
* @returns true to stop further extensions from loading this texture data
|
1678
1693
|
*/
|
1679
1694
|
loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError) {
|
1680
1695
|
return false;
|
@@ -1687,6 +1702,7 @@ export class GLTFLoaderExtension {
|
|
1687
1702
|
* @param buffer
|
1688
1703
|
* @param onSuccess
|
1689
1704
|
* @param onError
|
1705
|
+
* @returns true to stop further extensions from loading this texture
|
1690
1706
|
*/
|
1691
1707
|
createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError) {
|
1692
1708
|
return false;
|
@@ -1698,6 +1714,7 @@ export class GLTFLoaderExtension {
|
|
1698
1714
|
* @param id
|
1699
1715
|
* @param onSuccess
|
1700
1716
|
* @param onError
|
1717
|
+
* @returns true to stop further extensions from loading this shader data
|
1701
1718
|
*/
|
1702
1719
|
loadShaderStringAsync(gltfRuntime, id, onSuccess, onError) {
|
1703
1720
|
return false;
|
@@ -1709,6 +1726,7 @@ export class GLTFLoaderExtension {
|
|
1709
1726
|
* @param id
|
1710
1727
|
* @param onSuccess
|
1711
1728
|
* @param onError
|
1729
|
+
* @returns true to stop further extensions from loading this material
|
1712
1730
|
*/
|
1713
1731
|
loadMaterialAsync(gltfRuntime, id, onSuccess, onError) {
|
1714
1732
|
return false;
|