@babylonjs/loaders 7.30.0 → 7.31.0
Sign up to get free protection for your applications and to get access to all the features.
- package/SPLAT/splatFileLoader.js +10 -240
- package/SPLAT/splatFileLoader.js.map +1 -1
- package/glTF/2.0/glTFLoader.js +8 -0
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +5 -0
- package/glTF/glTFFileLoader.js +6 -0
- package/glTF/glTFFileLoader.js.map +1 -1
- package/package.json +3 -3
package/SPLAT/splatFileLoader.js
CHANGED
@@ -4,11 +4,10 @@ import { GaussianSplattingMesh } from "@babylonjs/core/Meshes/GaussianSplatting/
|
|
4
4
|
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
5
|
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
6
6
|
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
7
|
-
import {
|
7
|
+
import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
|
8
8
|
import { PointsCloudSystem } from "@babylonjs/core/Particles/pointsCloudSystem.js";
|
9
9
|
import { Color4 } from "@babylonjs/core/Maths/math.color.js";
|
10
10
|
import { VertexData } from "@babylonjs/core/Meshes/mesh.vertexData.js";
|
11
|
-
import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
|
12
11
|
/**
|
13
12
|
* Indicator of the parsed ply buffer. A standard ready to use splat or an array of positions for a point cloud
|
14
13
|
*/
|
@@ -18,12 +17,6 @@ var Mode;
|
|
18
17
|
Mode[Mode["PointCloud"] = 1] = "PointCloud";
|
19
18
|
Mode[Mode["Mesh"] = 2] = "Mesh";
|
20
19
|
})(Mode || (Mode = {}));
|
21
|
-
/** @internal */
|
22
|
-
var ElementMode;
|
23
|
-
(function (ElementMode) {
|
24
|
-
ElementMode[ElementMode["Vertex"] = 0] = "Vertex";
|
25
|
-
ElementMode[ElementMode["Chunk"] = 1] = "Chunk";
|
26
|
-
})(ElementMode || (ElementMode = {}));
|
27
20
|
/**
|
28
21
|
* @experimental
|
29
22
|
* SPLAT file type loader.
|
@@ -223,12 +216,12 @@ export class SPLATFileLoader {
|
|
223
216
|
}
|
224
217
|
const vertexCount = parseInt(/element vertex (\d+)\n/.exec(header)[1]);
|
225
218
|
const faceElement = /element face (\d+)\n/.exec(header);
|
226
|
-
const chunkElement = /element chunk (\d+)\n/.exec(header);
|
227
219
|
let faceCount = 0;
|
228
|
-
let chunkCount = 0;
|
229
220
|
if (faceElement) {
|
230
221
|
faceCount = parseInt(faceElement[1]);
|
231
222
|
}
|
223
|
+
const chunkElement = /element chunk (\d+)\n/.exec(header);
|
224
|
+
let chunkCount = 0;
|
232
225
|
if (chunkElement) {
|
233
226
|
chunkCount = parseInt(chunkElement[1]);
|
234
227
|
}
|
@@ -244,6 +237,11 @@ export class SPLATFileLoader {
|
|
244
237
|
uchar: 1,
|
245
238
|
list: 0,
|
246
239
|
};
|
240
|
+
let ElementMode;
|
241
|
+
(function (ElementMode) {
|
242
|
+
ElementMode[ElementMode["Vertex"] = 0] = "Vertex";
|
243
|
+
ElementMode[ElementMode["Chunk"] = 1] = "Chunk";
|
244
|
+
})(ElementMode || (ElementMode = {}));
|
247
245
|
let chunkMode = 1 /* ElementMode.Chunk */;
|
248
246
|
const vertexProperties = [];
|
249
247
|
const chunkProperties = [];
|
@@ -275,237 +273,9 @@ export class SPLATFileLoader {
|
|
275
273
|
}
|
276
274
|
const rowVertexLength = rowVertexOffset;
|
277
275
|
const rowChunkLength = rowChunkOffset;
|
278
|
-
const
|
279
|
-
const SH_C0 = 0.28209479177387814;
|
280
|
-
let offset = 0;
|
276
|
+
const buffer = GaussianSplattingMesh.ConvertPLYToSplat(data);
|
281
277
|
const dataView = new DataView(data, headerEndIndex + headerEnd.length);
|
282
|
-
|
283
|
-
const q = new Quaternion();
|
284
|
-
const temp3 = TmpVectors.Vector3[0];
|
285
|
-
const unpackUnorm = (value, bits) => {
|
286
|
-
const t = (1 << bits) - 1;
|
287
|
-
return (value & t) / t;
|
288
|
-
};
|
289
|
-
const unpack111011 = (value, result) => {
|
290
|
-
result.x = unpackUnorm(value >>> 21, 11);
|
291
|
-
result.y = unpackUnorm(value >>> 11, 10);
|
292
|
-
result.z = unpackUnorm(value, 11);
|
293
|
-
};
|
294
|
-
const unpack8888 = (value, result) => {
|
295
|
-
result[0] = unpackUnorm(value >>> 24, 8) * 255;
|
296
|
-
result[1] = unpackUnorm(value >>> 16, 8) * 255;
|
297
|
-
result[2] = unpackUnorm(value >>> 8, 8) * 255;
|
298
|
-
result[3] = unpackUnorm(value, 8) * 255;
|
299
|
-
};
|
300
|
-
// unpack quaternion with 2,10,10,10 format (largest element, 3x10bit element)
|
301
|
-
const unpackRot = (value, result) => {
|
302
|
-
const norm = 1.0 / (Math.sqrt(2) * 0.5);
|
303
|
-
const a = (unpackUnorm(value >>> 20, 10) - 0.5) * norm;
|
304
|
-
const b = (unpackUnorm(value >>> 10, 10) - 0.5) * norm;
|
305
|
-
const c = (unpackUnorm(value, 10) - 0.5) * norm;
|
306
|
-
const m = Math.sqrt(1.0 - (a * a + b * b + c * c));
|
307
|
-
switch (value >>> 30) {
|
308
|
-
case 0:
|
309
|
-
result.set(m, a, b, c);
|
310
|
-
break;
|
311
|
-
case 1:
|
312
|
-
result.set(a, m, b, c);
|
313
|
-
break;
|
314
|
-
case 2:
|
315
|
-
result.set(a, b, m, c);
|
316
|
-
break;
|
317
|
-
case 3:
|
318
|
-
result.set(a, b, c, m);
|
319
|
-
break;
|
320
|
-
}
|
321
|
-
};
|
322
|
-
const compressedChunks = new Array(chunkCount);
|
323
|
-
for (let i = 0; i < chunkCount; i++) {
|
324
|
-
const currentChunk = { min: new Vector3(), max: new Vector3(), minScale: new Vector3(), maxScale: new Vector3() };
|
325
|
-
compressedChunks[i] = currentChunk;
|
326
|
-
for (let propertyIndex = 0; propertyIndex < chunkProperties.length; propertyIndex++) {
|
327
|
-
const property = chunkProperties[propertyIndex];
|
328
|
-
let value;
|
329
|
-
switch (property.type) {
|
330
|
-
case "float":
|
331
|
-
value = dataView.getFloat32(property.offset + offset, true);
|
332
|
-
break;
|
333
|
-
default:
|
334
|
-
//throw new Error(`Unsupported property type: ${property.type}`);
|
335
|
-
continue;
|
336
|
-
}
|
337
|
-
switch (property.name) {
|
338
|
-
case "min_x":
|
339
|
-
currentChunk.min.x = value;
|
340
|
-
break;
|
341
|
-
case "min_y":
|
342
|
-
currentChunk.min.y = value;
|
343
|
-
break;
|
344
|
-
case "min_z":
|
345
|
-
currentChunk.min.z = value;
|
346
|
-
break;
|
347
|
-
case "max_x":
|
348
|
-
currentChunk.max.x = value;
|
349
|
-
break;
|
350
|
-
case "max_y":
|
351
|
-
currentChunk.max.y = value;
|
352
|
-
break;
|
353
|
-
case "max_z":
|
354
|
-
currentChunk.max.z = value;
|
355
|
-
break;
|
356
|
-
case "min_scale_x":
|
357
|
-
currentChunk.minScale.x = value;
|
358
|
-
break;
|
359
|
-
case "min_scale_y":
|
360
|
-
currentChunk.minScale.y = value;
|
361
|
-
break;
|
362
|
-
case "min_scale_z":
|
363
|
-
currentChunk.minScale.z = value;
|
364
|
-
break;
|
365
|
-
case "max_scale_x":
|
366
|
-
currentChunk.maxScale.x = value;
|
367
|
-
break;
|
368
|
-
case "max_scale_y":
|
369
|
-
currentChunk.maxScale.y = value;
|
370
|
-
break;
|
371
|
-
case "max_scale_z":
|
372
|
-
currentChunk.maxScale.z = value;
|
373
|
-
break;
|
374
|
-
}
|
375
|
-
}
|
376
|
-
offset += rowChunkLength;
|
377
|
-
}
|
378
|
-
for (let i = 0; i < vertexCount; i++) {
|
379
|
-
const position = new Float32Array(buffer, i * rowOutputLength, 3);
|
380
|
-
const scale = new Float32Array(buffer, i * rowOutputLength + 12, 3);
|
381
|
-
const rgba = new Uint8ClampedArray(buffer, i * rowOutputLength + 24, 4);
|
382
|
-
const rot = new Uint8ClampedArray(buffer, i * rowOutputLength + 28, 4);
|
383
|
-
const chunkIndex = i >> 8;
|
384
|
-
let r0 = 255;
|
385
|
-
let r1 = 0;
|
386
|
-
let r2 = 0;
|
387
|
-
let r3 = 0;
|
388
|
-
for (let propertyIndex = 0; propertyIndex < vertexProperties.length; propertyIndex++) {
|
389
|
-
const property = vertexProperties[propertyIndex];
|
390
|
-
let value;
|
391
|
-
switch (property.type) {
|
392
|
-
case "float":
|
393
|
-
value = dataView.getFloat32(offset + property.offset, true);
|
394
|
-
break;
|
395
|
-
case "int":
|
396
|
-
value = dataView.getInt32(offset + property.offset, true);
|
397
|
-
break;
|
398
|
-
case "uint":
|
399
|
-
value = dataView.getUint32(offset + property.offset, true);
|
400
|
-
break;
|
401
|
-
case "double":
|
402
|
-
value = dataView.getFloat64(offset + property.offset, true);
|
403
|
-
break;
|
404
|
-
case "uchar":
|
405
|
-
value = dataView.getUint8(offset + property.offset);
|
406
|
-
break;
|
407
|
-
default:
|
408
|
-
//throw new Error(`Unsupported property type: ${property.type}`);
|
409
|
-
continue;
|
410
|
-
}
|
411
|
-
switch (property.name) {
|
412
|
-
case "packed_position":
|
413
|
-
{
|
414
|
-
const compressedChunk = compressedChunks[chunkIndex];
|
415
|
-
unpack111011(value, temp3);
|
416
|
-
position[0] = Scalar.Lerp(compressedChunk.min.x, compressedChunk.max.x, temp3.x);
|
417
|
-
position[1] = -Scalar.Lerp(compressedChunk.min.y, compressedChunk.max.y, temp3.y);
|
418
|
-
position[2] = Scalar.Lerp(compressedChunk.min.z, compressedChunk.max.z, temp3.z);
|
419
|
-
}
|
420
|
-
break;
|
421
|
-
case "packed_rotation":
|
422
|
-
{
|
423
|
-
unpackRot(value, q);
|
424
|
-
r0 = q.w;
|
425
|
-
r1 = q.z;
|
426
|
-
r2 = q.y;
|
427
|
-
r3 = q.x;
|
428
|
-
}
|
429
|
-
break;
|
430
|
-
case "packed_scale":
|
431
|
-
{
|
432
|
-
const compressedChunk = compressedChunks[chunkIndex];
|
433
|
-
unpack111011(value, temp3);
|
434
|
-
scale[0] = Math.exp(Scalar.Lerp(compressedChunk.minScale.x, compressedChunk.maxScale.x, temp3.x));
|
435
|
-
scale[1] = Math.exp(Scalar.Lerp(compressedChunk.minScale.y, compressedChunk.maxScale.y, temp3.y));
|
436
|
-
scale[2] = Math.exp(Scalar.Lerp(compressedChunk.minScale.z, compressedChunk.maxScale.z, temp3.z));
|
437
|
-
}
|
438
|
-
break;
|
439
|
-
case "packed_color":
|
440
|
-
unpack8888(value, rgba);
|
441
|
-
break;
|
442
|
-
case "x":
|
443
|
-
position[0] = value;
|
444
|
-
break;
|
445
|
-
case "y":
|
446
|
-
position[1] = value;
|
447
|
-
break;
|
448
|
-
case "z":
|
449
|
-
position[2] = value;
|
450
|
-
break;
|
451
|
-
case "scale_0":
|
452
|
-
scale[0] = Math.exp(value);
|
453
|
-
break;
|
454
|
-
case "scale_1":
|
455
|
-
scale[1] = Math.exp(value);
|
456
|
-
break;
|
457
|
-
case "scale_2":
|
458
|
-
scale[2] = Math.exp(value);
|
459
|
-
break;
|
460
|
-
case "diffuse_red":
|
461
|
-
case "red":
|
462
|
-
rgba[0] = value;
|
463
|
-
break;
|
464
|
-
case "diffuse_green":
|
465
|
-
case "green":
|
466
|
-
rgba[1] = value;
|
467
|
-
break;
|
468
|
-
case "diffuse_blue":
|
469
|
-
case "blue":
|
470
|
-
rgba[2] = value;
|
471
|
-
break;
|
472
|
-
case "f_dc_0":
|
473
|
-
rgba[0] = (0.5 + SH_C0 * value) * 255;
|
474
|
-
break;
|
475
|
-
case "f_dc_1":
|
476
|
-
rgba[1] = (0.5 + SH_C0 * value) * 255;
|
477
|
-
break;
|
478
|
-
case "f_dc_2":
|
479
|
-
rgba[2] = (0.5 + SH_C0 * value) * 255;
|
480
|
-
break;
|
481
|
-
case "f_dc_3":
|
482
|
-
rgba[3] = (0.5 + SH_C0 * value) * 255;
|
483
|
-
break;
|
484
|
-
case "opacity":
|
485
|
-
rgba[3] = (1 / (1 + Math.exp(-value))) * 255;
|
486
|
-
break;
|
487
|
-
case "rot_0":
|
488
|
-
r0 = value;
|
489
|
-
break;
|
490
|
-
case "rot_1":
|
491
|
-
r1 = value;
|
492
|
-
break;
|
493
|
-
case "rot_2":
|
494
|
-
r2 = value;
|
495
|
-
break;
|
496
|
-
case "rot_3":
|
497
|
-
r3 = value;
|
498
|
-
break;
|
499
|
-
}
|
500
|
-
}
|
501
|
-
q.set(r1, r2, r3, r0);
|
502
|
-
q.normalize();
|
503
|
-
rot[0] = q.w * 128 + 128;
|
504
|
-
rot[1] = q.x * 128 + 128;
|
505
|
-
rot[2] = q.y * 128 + 128;
|
506
|
-
rot[3] = q.z * 128 + 128;
|
507
|
-
offset += rowVertexLength;
|
508
|
-
}
|
278
|
+
let offset = rowChunkLength * chunkCount + rowVertexLength * vertexCount;
|
509
279
|
// faces
|
510
280
|
const faces = [];
|
511
281
|
if (faceCount) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/splatFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,+CAAiC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,0EAA4D;AAC5F,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAIrD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AACxC,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,6CAA+B;AACzE,OAAO,EAAE,iBAAiB,EAAE,uDAAyC;AACrE,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,UAAU,EAAE,kDAAoC;AAEzD,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAYhD;;GAEG;AACH,IAAW,IAIV;AAJD,WAAW,IAAI;IACX,iCAAS,CAAA;IACT,2CAAc,CAAA;IACd,+BAAQ,CAAA;AACZ,CAAC,EAJU,IAAI,KAAJ,IAAI,QAId;AAoBD,gBAAgB;AAChB,IAAW,WAGV;AAHD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zC,aAAa,EAAE,CAAC;aACnB;YACD,IAAI,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBAC9C,kBAAkB,EAAE,CAAC;aACxB;SACJ;QACD,MAAM,sBAAsB,GAAG,aAAa,IAAI,eAAe,CAAC,MAAM,IAAI,kBAAkB,IAAI,CAAC,CAAC;QAClG,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,mBAAW,CAAC,CAAC,sBAAsB,CAAC,CAAC,oBAAY,CAAC,wBAAgB,CAAC;QAClG,2CAA2C;QAC3C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACpG,CAAC;;AApiBuB,sCAAsB,GAAG;IAC7C,SAAS,EAAE,KAAK;CACoB,AAFM,CAEL;AAqiB7C,2CAA2C;AAC3C,yBAAyB,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC","sourcesContent":["import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderAsyncResult, ISceneLoaderProgressEvent, SceneLoaderPluginOptions } from \"core/Loading/sceneLoader\";\r\nimport { registerSceneLoaderPlugin } from \"core/Loading/sceneLoader\";\r\nimport { SPLATFileLoaderMetadata } from \"./splatFileLoader.metadata\";\r\nimport { GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { Quaternion, TmpVectors, Vector3 } from \"core/Maths/math.vector\";\r\nimport { PointsCloudSystem } from \"core/Particles/pointsCloudSystem\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport { VertexData } from \"core/Meshes/mesh.vertexData\";\r\nimport type { SPLATLoadingOptions } from \"./splatLoadingOptions\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\n\r\ndeclare module \"core/Loading/sceneLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface SceneLoaderPluginOptions {\r\n /**\r\n * Defines options for the splat loader.\r\n */\r\n [SPLATFileLoaderMetadata.name]: Partial<SPLATLoadingOptions>;\r\n }\r\n}\r\n\r\n/**\r\n * Indicator of the parsed ply buffer. A standard ready to use splat or an array of positions for a point cloud\r\n */\r\nconst enum Mode {\r\n Splat = 0,\r\n PointCloud = 1,\r\n Mesh = 2,\r\n}\r\n\r\n/**\r\n * A parsed buffer and how to use it\r\n */\r\ninterface ParsedPLY {\r\n data: ArrayBuffer;\r\n mode: Mode;\r\n faces?: number[];\r\n hasVertexColors?: boolean;\r\n}\r\n\r\n/** @internal */\r\ninterface CompressedPLYChunk {\r\n min: Vector3;\r\n max: Vector3;\r\n minScale: Vector3;\r\n maxScale: Vector3;\r\n}\r\n\r\n/** @internal */\r\nconst enum ElementMode {\r\n Vertex = 0,\r\n Chunk = 1,\r\n}\r\n\r\n/**\r\n * @experimental\r\n * SPLAT file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public readonly name = SPLATFileLoaderMetadata.name;\r\n\r\n private _assetContainer: Nullable<AssetContainer> = null;\r\n\r\n private readonly _loadingOptions: Readonly<SPLATLoadingOptions>;\r\n /**\r\n * Defines the extensions the splat loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n */\r\n public readonly extensions = SPLATFileLoaderMetadata.extensions;\r\n\r\n /**\r\n * Creates loader for gaussian splatting files\r\n * @param loadingOptions options for loading and parsing splat and PLY files.\r\n */\r\n constructor(loadingOptions: Partial<Readonly<SPLATLoadingOptions>> = SPLATFileLoader._DefaultLoadingOptions) {\r\n this._loadingOptions = loadingOptions;\r\n }\r\n\r\n private static readonly _DefaultLoadingOptions = {\r\n keepInRam: false,\r\n } as const satisfies SPLATLoadingOptions;\r\n\r\n /** @internal */\r\n createPlugin(options: SceneLoaderPluginOptions): ISceneLoaderPluginAsync {\r\n return new SPLATFileLoader(options[SPLATFileLoaderMetadata.name]);\r\n }\r\n\r\n /**\r\n * Imports from the loaded gaussian splatting data and adds them to the scene\r\n * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the gaussian splatting data to load\r\n * @param rootUrl root url to load from\r\n * @param onProgress callback called while file is loading\r\n * @param fileName Defines the name of the file to load\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public async importMeshAsync(\r\n meshesNames: any,\r\n scene: Scene,\r\n data: any,\r\n rootUrl: string,\r\n onProgress?: (event: ISceneLoaderProgressEvent) => void,\r\n fileName?: string\r\n ): Promise<ISceneLoaderAsyncResult> {\r\n return this._parse(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 private static _BuildPointCloud(pointcloud: PointsCloudSystem, data: ArrayBuffer): boolean {\r\n if (!data.byteLength) {\r\n return false;\r\n }\r\n const uBuffer = new Uint8Array(data);\r\n const fBuffer = new Float32Array(data);\r\n\r\n // parsed array contains room for position(3floats), normal(3floats), color (4b), quantized quaternion (4b)\r\n const rowLength = 3 * 4 + 3 * 4 + 4 + 4;\r\n const vertexCount = uBuffer.length / rowLength;\r\n\r\n const pointcloudfunc = function (particle: any, i: number) {\r\n const x = fBuffer[8 * i + 0];\r\n const y = fBuffer[8 * i + 1];\r\n const z = fBuffer[8 * i + 2];\r\n particle.position = new Vector3(x, y, z);\r\n\r\n const r = uBuffer[rowLength * i + 24 + 0] / 255;\r\n const g = uBuffer[rowLength * i + 24 + 1] / 255;\r\n const b = uBuffer[rowLength * i + 24 + 2] / 255;\r\n particle.color = new Color4(r, g, b, 1);\r\n };\r\n\r\n pointcloud.addPoints(vertexCount, pointcloudfunc);\r\n return true;\r\n }\r\n\r\n private static _BuildMesh(scene: Scene, parsedPLY: ParsedPLY): Mesh {\r\n const mesh = new Mesh(\"PLYMesh\", scene);\r\n\r\n const uBuffer = new Uint8Array(parsedPLY.data);\r\n const fBuffer = new Float32Array(parsedPLY.data);\r\n\r\n const rowLength = 3 * 4 + 3 * 4 + 4 + 4;\r\n const vertexCount = uBuffer.length / rowLength;\r\n\r\n const positions = [];\r\n\r\n const vertexData = new VertexData();\r\n for (let i = 0; i < vertexCount; i++) {\r\n const x = fBuffer[8 * i + 0];\r\n const y = fBuffer[8 * i + 1];\r\n const z = fBuffer[8 * i + 2];\r\n positions.push(x, y, z);\r\n }\r\n\r\n if (parsedPLY.hasVertexColors) {\r\n const colors = new Float32Array(vertexCount * 4);\r\n for (let i = 0; i < vertexCount; i++) {\r\n const r = uBuffer[rowLength * i + 24 + 0] / 255;\r\n const g = uBuffer[rowLength * i + 24 + 1] / 255;\r\n const b = uBuffer[rowLength * i + 24 + 2] / 255;\r\n colors[i * 4 + 0] = r;\r\n colors[i * 4 + 1] = g;\r\n colors[i * 4 + 2] = b;\r\n colors[i * 4 + 3] = 1;\r\n }\r\n vertexData.colors = colors;\r\n }\r\n\r\n vertexData.positions = positions;\r\n vertexData.indices = parsedPLY.faces!;\r\n\r\n vertexData.applyToMesh(mesh);\r\n return mesh;\r\n }\r\n\r\n private _parse(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<Array<AbstractMesh>> {\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\r\n const parsedPLY = SPLATFileLoader._ConvertPLYToSplat(data as ArrayBuffer);\r\n switch (parsedPLY.mode) {\r\n case Mode.Splat:\r\n {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene, this._loadingOptions.keepInRam);\r\n gaussianSplatting._parentContainer = this._assetContainer;\r\n babylonMeshesArray.push(gaussianSplatting);\r\n gaussianSplatting.loadDataAsync(parsedPLY.data);\r\n }\r\n break;\r\n case Mode.PointCloud:\r\n {\r\n const pointcloud = new PointsCloudSystem(\"PointCloud\", 1, scene);\r\n if (SPLATFileLoader._BuildPointCloud(pointcloud, parsedPLY.data)) {\r\n return Promise.all([pointcloud.buildMeshAsync()]).then((mesh) => {\r\n babylonMeshesArray.push(mesh[0]);\r\n return babylonMeshesArray;\r\n });\r\n } else {\r\n pointcloud.dispose();\r\n }\r\n }\r\n break;\r\n case Mode.Mesh:\r\n {\r\n if (parsedPLY.faces) {\r\n babylonMeshesArray.push(SPLATFileLoader._BuildMesh(scene, parsedPLY));\r\n } else {\r\n throw new Error(\"PLY mesh doesn't contain face informations.\");\r\n }\r\n }\r\n break;\r\n default:\r\n throw new Error(\"Unsupported Splat mode\");\r\n }\r\n return Promise.resolve(babylonMeshesArray);\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer> {\r\n const container = new AssetContainer(scene);\r\n this._assetContainer = container;\r\n\r\n return this.importMeshAsync(null, scene, data, rootUrl)\r\n .then((result) => {\r\n result.meshes.forEach((mesh) => container.meshes.push(mesh));\r\n // mesh material will be null before 1st rendered frame.\r\n this._assetContainer = null;\r\n return container;\r\n })\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n });\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded OBJ data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n public loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n return this.importMeshAsync(null, scene, data, rootUrl).then(() => {\r\n // return void\r\n });\r\n }\r\n\r\n /**\r\n * Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license\r\n * Converts a .ply data array buffer to splat\r\n * if data array buffer is not ply, returns the original buffer\r\n * @param data the .ply data to load\r\n * @returns the loaded splat buffer\r\n */\r\n private static _ConvertPLYToSplat(data: ArrayBuffer): ParsedPLY {\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 // standard splat\r\n return { mode: Mode.Splat, data: data };\r\n }\r\n const vertexCount = parseInt(/element vertex (\\d+)\\n/.exec(header)![1]);\r\n const faceElement = /element face (\\d+)\\n/.exec(header);\r\n const chunkElement = /element chunk (\\d+)\\n/.exec(header);\r\n let faceCount = 0;\r\n let chunkCount = 0;\r\n if (faceElement) {\r\n faceCount = parseInt(faceElement[1]);\r\n }\r\n if (chunkElement) {\r\n chunkCount = parseInt(chunkElement[1]);\r\n }\r\n let rowVertexOffset = 0;\r\n let rowChunkOffset = 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 list: 0,\r\n };\r\n\r\n type PlyProperty = {\r\n name: string;\r\n type: string;\r\n offset: number;\r\n };\r\n let chunkMode = ElementMode.Chunk;\r\n const vertexProperties: PlyProperty[] = [];\r\n const chunkProperties: PlyProperty[] = [];\r\n const filtered = header.slice(0, headerEndIndex).split(\"\\n\");\r\n for (const prop of filtered) {\r\n if (prop.startsWith(\"property \")) {\r\n const [, type, name] = prop.split(\" \");\r\n\r\n if (chunkMode == ElementMode.Chunk) {\r\n chunkProperties.push({ name, type, offset: rowChunkOffset });\r\n rowChunkOffset += offsets[type];\r\n } else if (chunkMode == ElementMode.Vertex) {\r\n vertexProperties.push({ name, type, offset: rowVertexOffset });\r\n rowVertexOffset += offsets[type];\r\n }\r\n\r\n if (!offsets[type]) {\r\n Logger.Warn(`Unsupported property type: ${type}.`);\r\n }\r\n } else if (prop.startsWith(\"element \")) {\r\n const [, type] = prop.split(\" \");\r\n if (type == \"chunk\") {\r\n chunkMode = ElementMode.Chunk;\r\n } else if (type == \"vertex\") {\r\n chunkMode = ElementMode.Vertex;\r\n }\r\n }\r\n }\r\n\r\n const rowVertexLength = rowVertexOffset;\r\n const rowChunkLength = rowChunkOffset;\r\n\r\n const rowOutputLength = 3 * 4 + 3 * 4 + 4 + 4; // Vector3 position, Vector3 scale, 1 u8 quaternion, 1 color with alpha\r\n const SH_C0 = 0.28209479177387814;\r\n let offset = 0;\r\n\r\n const dataView = new DataView(data, headerEndIndex + headerEnd.length);\r\n const buffer = new ArrayBuffer(rowOutputLength * vertexCount);\r\n const q = new Quaternion();\r\n const temp3 = TmpVectors.Vector3[0];\r\n\r\n const unpackUnorm = (value: number, bits: number) => {\r\n const t = (1 << bits) - 1;\r\n return (value & t) / t;\r\n };\r\n\r\n const unpack111011 = (value: number, result: Vector3) => {\r\n result.x = unpackUnorm(value >>> 21, 11);\r\n result.y = unpackUnorm(value >>> 11, 10);\r\n result.z = unpackUnorm(value, 11);\r\n };\r\n\r\n const unpack8888 = (value: number, result: Uint8ClampedArray) => {\r\n result[0] = unpackUnorm(value >>> 24, 8) * 255;\r\n result[1] = unpackUnorm(value >>> 16, 8) * 255;\r\n result[2] = unpackUnorm(value >>> 8, 8) * 255;\r\n result[3] = unpackUnorm(value, 8) * 255;\r\n };\r\n\r\n // unpack quaternion with 2,10,10,10 format (largest element, 3x10bit element)\r\n const unpackRot = (value: number, result: Quaternion) => {\r\n const norm = 1.0 / (Math.sqrt(2) * 0.5);\r\n const a = (unpackUnorm(value >>> 20, 10) - 0.5) * norm;\r\n const b = (unpackUnorm(value >>> 10, 10) - 0.5) * norm;\r\n const c = (unpackUnorm(value, 10) - 0.5) * norm;\r\n const m = Math.sqrt(1.0 - (a * a + b * b + c * c));\r\n\r\n switch (value >>> 30) {\r\n case 0:\r\n result.set(m, a, b, c);\r\n break;\r\n case 1:\r\n result.set(a, m, b, c);\r\n break;\r\n case 2:\r\n result.set(a, b, m, c);\r\n break;\r\n case 3:\r\n result.set(a, b, c, m);\r\n break;\r\n }\r\n };\r\n\r\n const compressedChunks = new Array<CompressedPLYChunk>(chunkCount);\r\n for (let i = 0; i < chunkCount; i++) {\r\n const currentChunk = { min: new Vector3(), max: new Vector3(), minScale: new Vector3(), maxScale: new Vector3() };\r\n compressedChunks[i] = currentChunk;\r\n for (let propertyIndex = 0; propertyIndex < chunkProperties.length; propertyIndex++) {\r\n const property = chunkProperties[propertyIndex];\r\n let value;\r\n switch (property.type) {\r\n case \"float\":\r\n value = dataView.getFloat32(property.offset + offset, true);\r\n break;\r\n default:\r\n //throw new Error(`Unsupported property type: ${property.type}`);\r\n continue;\r\n }\r\n\r\n switch (property.name) {\r\n case \"min_x\":\r\n currentChunk.min.x = value;\r\n break;\r\n case \"min_y\":\r\n currentChunk.min.y = value;\r\n break;\r\n case \"min_z\":\r\n currentChunk.min.z = value;\r\n break;\r\n case \"max_x\":\r\n currentChunk.max.x = value;\r\n break;\r\n case \"max_y\":\r\n currentChunk.max.y = value;\r\n break;\r\n case \"max_z\":\r\n currentChunk.max.z = value;\r\n break;\r\n case \"min_scale_x\":\r\n currentChunk.minScale.x = value;\r\n break;\r\n case \"min_scale_y\":\r\n currentChunk.minScale.y = value;\r\n break;\r\n case \"min_scale_z\":\r\n currentChunk.minScale.z = value;\r\n break;\r\n case \"max_scale_x\":\r\n currentChunk.maxScale.x = value;\r\n break;\r\n case \"max_scale_y\":\r\n currentChunk.maxScale.y = value;\r\n break;\r\n case \"max_scale_z\":\r\n currentChunk.maxScale.z = value;\r\n break;\r\n }\r\n }\r\n offset += rowChunkLength;\r\n }\r\n\r\n for (let i = 0; i < vertexCount; i++) {\r\n const position = new Float32Array(buffer, i * rowOutputLength, 3);\r\n const scale = new Float32Array(buffer, i * rowOutputLength + 12, 3);\r\n const rgba = new Uint8ClampedArray(buffer, i * rowOutputLength + 24, 4);\r\n const rot = new Uint8ClampedArray(buffer, i * rowOutputLength + 28, 4);\r\n const chunkIndex = i >> 8;\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 < vertexProperties.length; propertyIndex++) {\r\n const property = vertexProperties[propertyIndex];\r\n let value;\r\n switch (property.type) {\r\n case \"float\":\r\n value = dataView.getFloat32(offset + property.offset, true);\r\n break;\r\n case \"int\":\r\n value = dataView.getInt32(offset + property.offset, true);\r\n break;\r\n case \"uint\":\r\n value = dataView.getUint32(offset + property.offset, true);\r\n break;\r\n case \"double\":\r\n value = dataView.getFloat64(offset + property.offset, true);\r\n break;\r\n case \"uchar\":\r\n value = dataView.getUint8(offset + property.offset);\r\n break;\r\n default:\r\n //throw new Error(`Unsupported property type: ${property.type}`);\r\n continue;\r\n }\r\n\r\n switch (property.name) {\r\n case \"packed_position\":\r\n {\r\n const compressedChunk = compressedChunks[chunkIndex];\r\n unpack111011(value, temp3);\r\n position[0] = Scalar.Lerp(compressedChunk.min.x, compressedChunk.max.x, temp3.x);\r\n position[1] = -Scalar.Lerp(compressedChunk.min.y, compressedChunk.max.y, temp3.y);\r\n position[2] = Scalar.Lerp(compressedChunk.min.z, compressedChunk.max.z, temp3.z);\r\n }\r\n break;\r\n case \"packed_rotation\":\r\n {\r\n unpackRot(value, q);\r\n r0 = q.w;\r\n r1 = q.z;\r\n r2 = q.y;\r\n r3 = q.x;\r\n }\r\n break;\r\n case \"packed_scale\":\r\n {\r\n const compressedChunk = compressedChunks[chunkIndex];\r\n unpack111011(value, temp3);\r\n scale[0] = Math.exp(Scalar.Lerp(compressedChunk.minScale.x, compressedChunk.maxScale.x, temp3.x));\r\n scale[1] = Math.exp(Scalar.Lerp(compressedChunk.minScale.y, compressedChunk.maxScale.y, temp3.y));\r\n scale[2] = Math.exp(Scalar.Lerp(compressedChunk.minScale.z, compressedChunk.maxScale.z, temp3.z));\r\n }\r\n break;\r\n case \"packed_color\":\r\n unpack8888(value, rgba);\r\n break;\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 \"diffuse_red\":\r\n case \"red\":\r\n rgba[0] = value;\r\n break;\r\n case \"diffuse_green\":\r\n case \"green\":\r\n rgba[1] = value;\r\n break;\r\n case \"diffuse_blue\":\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 offset += rowVertexLength;\r\n }\r\n\r\n // faces\r\n const faces = [];\r\n if (faceCount) {\r\n for (let i = 0; i < faceCount; i++) {\r\n const faceVertexCount = dataView.getUint8(offset);\r\n if (faceVertexCount != 3) {\r\n continue; // only support triangles\r\n }\r\n offset += 1;\r\n\r\n for (let j = 0; j < faceVertexCount; j++) {\r\n const vertexIndex = dataView.getUint32(offset + (2 - j) * 4, true); // change face winding\r\n faces.push(vertexIndex);\r\n }\r\n offset += 12;\r\n }\r\n }\r\n\r\n // early exit for chunked/quantized ply\r\n if (chunkCount) {\r\n return { mode: Mode.Splat, data: buffer, faces: faces, hasVertexColors: false };\r\n }\r\n // count available properties. if all necessary are present then it's a splat. Otherwise, it's a point cloud\r\n // if faces are found, then it's a standard mesh\r\n let propertyCount = 0;\r\n let propertyColorCount = 0;\r\n const splatProperties = [\"x\", \"y\", \"z\", \"scale_0\", \"scale_1\", \"scale_2\", \"opacity\", \"rot_0\", \"rot_1\", \"rot_2\", \"rot_3\"];\r\n const splatColorProperties = [\"red\", \"green\", \"blue\", \"f_dc_0\", \"f_dc_1\", \"f_dc_2\"];\r\n for (let propertyIndex = 0; propertyIndex < vertexProperties.length; propertyIndex++) {\r\n const property = vertexProperties[propertyIndex];\r\n if (splatProperties.includes(property.name)) {\r\n propertyCount++;\r\n }\r\n if (splatColorProperties.includes(property.name)) {\r\n propertyColorCount++;\r\n }\r\n }\r\n const hasMandatoryProperties = propertyCount == splatProperties.length && propertyColorCount == 3;\r\n const currentMode = faceCount ? Mode.Mesh : hasMandatoryProperties ? Mode.Splat : Mode.PointCloud;\r\n // parsed ready ready to be used as a splat\r\n return { mode: currentMode, data: buffer, faces: faces, hasVertexColors: !!propertyColorCount };\r\n }\r\n}\r\n\r\n// Add this loader into the register plugin\r\nregisterSceneLoaderPlugin(new SPLATFileLoader());\r\n"]}
|
1
|
+
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/splatFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,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AAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACxH,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACpF,KAAK,IAAI,aAAa,GAAG,CAAC,EAAE,aAAa,GAAG,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE;YAClF,MAAM,QAAQ,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACjD,IAAI,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACzC,aAAa,EAAE,CAAC;aACnB;YACD,IAAI,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBAC9C,kBAAkB,EAAE,CAAC;aACxB;SACJ;QACD,MAAM,sBAAsB,GAAG,aAAa,IAAI,eAAe,CAAC,MAAM,IAAI,kBAAkB,IAAI,CAAC,CAAC;QAClG,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,mBAAW,CAAC,CAAC,sBAAsB,CAAC,CAAC,oBAAY,CAAC,wBAAgB,CAAC;QAClG,2CAA2C;QAC3C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACpG,CAAC;;AA3TuB,sCAAsB,GAAG;IAC7C,SAAS,EAAE,KAAK;CACoB,AAFM,CAEL;AA4T7C,2CAA2C;AAC3C,yBAAyB,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC","sourcesContent":["import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderAsyncResult, ISceneLoaderProgressEvent, SceneLoaderPluginOptions } from \"core/Loading/sceneLoader\";\r\nimport { registerSceneLoaderPlugin } from \"core/Loading/sceneLoader\";\r\nimport { SPLATFileLoaderMetadata } from \"./splatFileLoader.metadata\";\r\nimport { GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { PointsCloudSystem } from \"core/Particles/pointsCloudSystem\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport { VertexData } from \"core/Meshes/mesh.vertexData\";\r\nimport type { SPLATLoadingOptions } from \"./splatLoadingOptions\";\r\n\r\ndeclare module \"core/Loading/sceneLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface SceneLoaderPluginOptions {\r\n /**\r\n * Defines options for the splat loader.\r\n */\r\n [SPLATFileLoaderMetadata.name]: Partial<SPLATLoadingOptions>;\r\n }\r\n}\r\n\r\n/**\r\n * Indicator of the parsed ply buffer. A standard ready to use splat or an array of positions for a point cloud\r\n */\r\nconst enum Mode {\r\n Splat = 0,\r\n PointCloud = 1,\r\n Mesh = 2,\r\n}\r\n\r\n/**\r\n * A parsed buffer and how to use it\r\n */\r\ninterface ParsedPLY {\r\n data: ArrayBuffer;\r\n mode: Mode;\r\n faces?: number[];\r\n hasVertexColors?: boolean;\r\n}\r\n\r\n/**\r\n * @experimental\r\n * SPLAT file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public readonly name = SPLATFileLoaderMetadata.name;\r\n\r\n private _assetContainer: Nullable<AssetContainer> = null;\r\n\r\n private readonly _loadingOptions: Readonly<SPLATLoadingOptions>;\r\n /**\r\n * Defines the extensions the splat loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n */\r\n public readonly extensions = SPLATFileLoaderMetadata.extensions;\r\n\r\n /**\r\n * Creates loader for gaussian splatting files\r\n * @param loadingOptions options for loading and parsing splat and PLY files.\r\n */\r\n constructor(loadingOptions: Partial<Readonly<SPLATLoadingOptions>> = SPLATFileLoader._DefaultLoadingOptions) {\r\n this._loadingOptions = loadingOptions;\r\n }\r\n\r\n private static readonly _DefaultLoadingOptions = {\r\n keepInRam: false,\r\n } as const satisfies SPLATLoadingOptions;\r\n\r\n /** @internal */\r\n createPlugin(options: SceneLoaderPluginOptions): ISceneLoaderPluginAsync {\r\n return new SPLATFileLoader(options[SPLATFileLoaderMetadata.name]);\r\n }\r\n\r\n /**\r\n * Imports from the loaded gaussian splatting data and adds them to the scene\r\n * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the gaussian splatting data to load\r\n * @param rootUrl root url to load from\r\n * @param onProgress callback called while file is loading\r\n * @param fileName Defines the name of the file to load\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public async importMeshAsync(\r\n meshesNames: any,\r\n scene: Scene,\r\n data: any,\r\n rootUrl: string,\r\n onProgress?: (event: ISceneLoaderProgressEvent) => void,\r\n fileName?: string\r\n ): Promise<ISceneLoaderAsyncResult> {\r\n return this._parse(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 private static _BuildPointCloud(pointcloud: PointsCloudSystem, data: ArrayBuffer): boolean {\r\n if (!data.byteLength) {\r\n return false;\r\n }\r\n const uBuffer = new Uint8Array(data);\r\n const fBuffer = new Float32Array(data);\r\n\r\n // parsed array contains room for position(3floats), normal(3floats), color (4b), quantized quaternion (4b)\r\n const rowLength = 3 * 4 + 3 * 4 + 4 + 4;\r\n const vertexCount = uBuffer.length / rowLength;\r\n\r\n const pointcloudfunc = function (particle: any, i: number) {\r\n const x = fBuffer[8 * i + 0];\r\n const y = fBuffer[8 * i + 1];\r\n const z = fBuffer[8 * i + 2];\r\n particle.position = new Vector3(x, y, z);\r\n\r\n const r = uBuffer[rowLength * i + 24 + 0] / 255;\r\n const g = uBuffer[rowLength * i + 24 + 1] / 255;\r\n const b = uBuffer[rowLength * i + 24 + 2] / 255;\r\n particle.color = new Color4(r, g, b, 1);\r\n };\r\n\r\n pointcloud.addPoints(vertexCount, pointcloudfunc);\r\n return true;\r\n }\r\n\r\n private static _BuildMesh(scene: Scene, parsedPLY: ParsedPLY): Mesh {\r\n const mesh = new Mesh(\"PLYMesh\", scene);\r\n\r\n const uBuffer = new Uint8Array(parsedPLY.data);\r\n const fBuffer = new Float32Array(parsedPLY.data);\r\n\r\n const rowLength = 3 * 4 + 3 * 4 + 4 + 4;\r\n const vertexCount = uBuffer.length / rowLength;\r\n\r\n const positions = [];\r\n\r\n const vertexData = new VertexData();\r\n for (let i = 0; i < vertexCount; i++) {\r\n const x = fBuffer[8 * i + 0];\r\n const y = fBuffer[8 * i + 1];\r\n const z = fBuffer[8 * i + 2];\r\n positions.push(x, y, z);\r\n }\r\n\r\n if (parsedPLY.hasVertexColors) {\r\n const colors = new Float32Array(vertexCount * 4);\r\n for (let i = 0; i < vertexCount; i++) {\r\n const r = uBuffer[rowLength * i + 24 + 0] / 255;\r\n const g = uBuffer[rowLength * i + 24 + 1] / 255;\r\n const b = uBuffer[rowLength * i + 24 + 2] / 255;\r\n colors[i * 4 + 0] = r;\r\n colors[i * 4 + 1] = g;\r\n colors[i * 4 + 2] = b;\r\n colors[i * 4 + 3] = 1;\r\n }\r\n vertexData.colors = colors;\r\n }\r\n\r\n vertexData.positions = positions;\r\n vertexData.indices = parsedPLY.faces!;\r\n\r\n vertexData.applyToMesh(mesh);\r\n return mesh;\r\n }\r\n\r\n private _parse(meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<Array<AbstractMesh>> {\r\n const babylonMeshesArray: Array<Mesh> = []; //The mesh for babylon\r\n const parsedPLY = SPLATFileLoader._ConvertPLYToSplat(data as ArrayBuffer);\r\n switch (parsedPLY.mode) {\r\n case Mode.Splat:\r\n {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene, this._loadingOptions.keepInRam);\r\n gaussianSplatting._parentContainer = this._assetContainer;\r\n babylonMeshesArray.push(gaussianSplatting);\r\n gaussianSplatting.loadDataAsync(parsedPLY.data);\r\n }\r\n break;\r\n case Mode.PointCloud:\r\n {\r\n const pointcloud = new PointsCloudSystem(\"PointCloud\", 1, scene);\r\n if (SPLATFileLoader._BuildPointCloud(pointcloud, parsedPLY.data)) {\r\n return Promise.all([pointcloud.buildMeshAsync()]).then((mesh) => {\r\n babylonMeshesArray.push(mesh[0]);\r\n return babylonMeshesArray;\r\n });\r\n } else {\r\n pointcloud.dispose();\r\n }\r\n }\r\n break;\r\n case Mode.Mesh:\r\n {\r\n if (parsedPLY.faces) {\r\n babylonMeshesArray.push(SPLATFileLoader._BuildMesh(scene, parsedPLY));\r\n } else {\r\n throw new Error(\"PLY mesh doesn't contain face informations.\");\r\n }\r\n }\r\n break;\r\n default:\r\n throw new Error(\"Unsupported Splat mode\");\r\n }\r\n return Promise.resolve(babylonMeshesArray);\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainerAsync(scene: Scene, data: string, rootUrl: string): Promise<AssetContainer> {\r\n const container = new AssetContainer(scene);\r\n this._assetContainer = container;\r\n\r\n return this.importMeshAsync(null, scene, data, rootUrl)\r\n .then((result) => {\r\n result.meshes.forEach((mesh) => container.meshes.push(mesh));\r\n // mesh material will be null before 1st rendered frame.\r\n this._assetContainer = null;\r\n return container;\r\n })\r\n .catch((ex) => {\r\n this._assetContainer = null;\r\n throw ex;\r\n });\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded OBJ data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the OBJ data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n public loadAsync(scene: Scene, data: string, rootUrl: string): Promise<void> {\r\n //Get the 3D model\r\n return this.importMeshAsync(null, scene, data, rootUrl).then(() => {\r\n // return void\r\n });\r\n }\r\n\r\n /**\r\n * Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license\r\n * Converts a .ply data array buffer to splat\r\n * if data array buffer is not ply, returns the original buffer\r\n * @param data the .ply data to load\r\n * @returns the loaded splat buffer\r\n */\r\n private static _ConvertPLYToSplat(data: ArrayBuffer): ParsedPLY {\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 // standard splat\r\n return { mode: Mode.Splat, data: data };\r\n }\r\n\r\n const vertexCount = parseInt(/element vertex (\\d+)\\n/.exec(header)![1]);\r\n const faceElement = /element face (\\d+)\\n/.exec(header);\r\n let faceCount = 0;\r\n if (faceElement) {\r\n faceCount = parseInt(faceElement[1]);\r\n }\r\n const chunkElement = /element chunk (\\d+)\\n/.exec(header);\r\n let chunkCount = 0;\r\n if (chunkElement) {\r\n chunkCount = parseInt(chunkElement[1]);\r\n }\r\n\r\n let rowVertexOffset = 0;\r\n let rowChunkOffset = 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 list: 0,\r\n };\r\n\r\n type PlyProperty = {\r\n name: string;\r\n type: string;\r\n offset: number;\r\n };\r\n\r\n const enum ElementMode {\r\n Vertex = 0,\r\n Chunk = 1,\r\n }\r\n\r\n let chunkMode = ElementMode.Chunk;\r\n const vertexProperties: PlyProperty[] = [];\r\n const chunkProperties: PlyProperty[] = [];\r\n const filtered = header.slice(0, headerEndIndex).split(\"\\n\");\r\n for (const prop of filtered) {\r\n if (prop.startsWith(\"property \")) {\r\n const [, type, name] = prop.split(\" \");\r\n\r\n if (chunkMode == ElementMode.Chunk) {\r\n chunkProperties.push({ name, type, offset: rowChunkOffset });\r\n rowChunkOffset += offsets[type];\r\n } else if (chunkMode == ElementMode.Vertex) {\r\n vertexProperties.push({ name, type, offset: rowVertexOffset });\r\n rowVertexOffset += offsets[type];\r\n }\r\n\r\n if (!offsets[type]) {\r\n Logger.Warn(`Unsupported property type: ${type}.`);\r\n }\r\n } else if (prop.startsWith(\"element \")) {\r\n const [, type] = prop.split(\" \");\r\n if (type == \"chunk\") {\r\n chunkMode = ElementMode.Chunk;\r\n } else if (type == \"vertex\") {\r\n chunkMode = ElementMode.Vertex;\r\n }\r\n }\r\n }\r\n\r\n const rowVertexLength = rowVertexOffset;\r\n const rowChunkLength = rowChunkOffset;\r\n\r\n const buffer = GaussianSplattingMesh.ConvertPLYToSplat(data);\r\n const dataView = new DataView(data, headerEndIndex + headerEnd.length);\r\n let offset = rowChunkLength * chunkCount + rowVertexLength * vertexCount;\r\n // faces\r\n const faces = [];\r\n if (faceCount) {\r\n for (let i = 0; i < faceCount; i++) {\r\n const faceVertexCount = dataView.getUint8(offset);\r\n if (faceVertexCount != 3) {\r\n continue; // only support triangles\r\n }\r\n offset += 1;\r\n\r\n for (let j = 0; j < faceVertexCount; j++) {\r\n const vertexIndex = dataView.getUint32(offset + (2 - j) * 4, true); // change face winding\r\n faces.push(vertexIndex);\r\n }\r\n offset += 12;\r\n }\r\n }\r\n\r\n // early exit for chunked/quantized ply\r\n if (chunkCount) {\r\n return { mode: Mode.Splat, data: buffer, faces: faces, hasVertexColors: false };\r\n }\r\n // count available properties. if all necessary are present then it's a splat. Otherwise, it's a point cloud\r\n // if faces are found, then it's a standard mesh\r\n let propertyCount = 0;\r\n let propertyColorCount = 0;\r\n const splatProperties = [\"x\", \"y\", \"z\", \"scale_0\", \"scale_1\", \"scale_2\", \"opacity\", \"rot_0\", \"rot_1\", \"rot_2\", \"rot_3\"];\r\n const splatColorProperties = [\"red\", \"green\", \"blue\", \"f_dc_0\", \"f_dc_1\", \"f_dc_2\"];\r\n for (let propertyIndex = 0; propertyIndex < vertexProperties.length; propertyIndex++) {\r\n const property = vertexProperties[propertyIndex];\r\n if (splatProperties.includes(property.name)) {\r\n propertyCount++;\r\n }\r\n if (splatColorProperties.includes(property.name)) {\r\n propertyColorCount++;\r\n }\r\n }\r\n const hasMandatoryProperties = propertyCount == splatProperties.length && propertyColorCount == 3;\r\n const currentMode = faceCount ? Mode.Mesh : hasMandatoryProperties ? Mode.Splat : Mode.PointCloud;\r\n // parsed ready ready to be used as a splat\r\n return { mode: currentMode, data: buffer, faces: faces, hasVertexColors: !!propertyColorCount };\r\n }\r\n}\r\n\r\n// Add this loader into the register plugin\r\nregisterSceneLoaderPlugin(new SPLATFileLoader());\r\n"]}
|
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -1898,10 +1898,18 @@ export class GLTFLoader {
|
|
1898
1898
|
const name = image.uri || `${this._fileName}#image${image.index}`;
|
1899
1899
|
const dataUrl = `data:${this._uniqueRootUrl}${name}`;
|
1900
1900
|
babylonTexture.updateURL(dataUrl, data);
|
1901
|
+
// Set the internal texture label.
|
1902
|
+
const internalTexture = babylonTexture.getInternalTexture();
|
1903
|
+
if (internalTexture) {
|
1904
|
+
internalTexture.label = image.name;
|
1905
|
+
}
|
1901
1906
|
}));
|
1902
1907
|
babylonTexture.wrapU = samplerData.wrapU;
|
1903
1908
|
babylonTexture.wrapV = samplerData.wrapV;
|
1904
1909
|
assign(babylonTexture);
|
1910
|
+
if (this._parent.useGltfTextureNames) {
|
1911
|
+
babylonTexture.name = image.name || image.uri || `image${image.index}`;
|
1912
|
+
}
|
1905
1913
|
return Promise.all(promises).then(() => {
|
1906
1914
|
return babylonTexture;
|
1907
1915
|
});
|