|
62 | 62 | RgbaArray, |
63 | 63 | readRgbaArray, |
64 | 64 | SparkControls, |
65 | | - SpzWriter, |
| 65 | + writeSpz, |
66 | 66 | unpackSplat, |
67 | 67 | PackedSplats, |
68 | 68 | } from "@sparkjsdev/spark"; |
|
405 | 405 | alert("No splat mesh loaded for export."); |
406 | 406 | return; |
407 | 407 | } |
408 | | - |
| 408 | + |
409 | 409 | try { |
410 | 410 | console.log("Starting SPZ export with painted changes..."); |
411 | 411 |
|
|
416 | 416 | }); |
417 | 417 | currentSplatMesh.updateGenerator(); |
418 | 418 | } |
419 | | - |
| 419 | + |
420 | 420 | const rgba = new RgbaArray(); |
421 | 421 | rgba.render({ |
422 | 422 | renderer, |
|
470 | 470 | unpacked.color.g = rgbaBytes[rgbaOffset + 1] / 255; |
471 | 471 | unpacked.color.b = rgbaBytes[rgbaOffset + 2] / 255; |
472 | 472 | unpacked.opacity = opacity; |
473 | | - |
| 473 | + |
474 | 474 | // Push to new PackedSplats |
475 | 475 | newPackedSplats.pushSplat( |
476 | 476 | unpacked.center, |
|
482 | 482 |
|
483 | 483 | processedCount++; |
484 | 484 | } |
485 | | - |
| 485 | + |
486 | 486 | console.log(`Processed ${processedCount} splats`); |
487 | 487 |
|
488 | 488 | // Now export the PackedSplats to SPZ |
489 | | - console.log("Creating SPZ writer..."); |
490 | | - const maxSh = ioOptions.maxSh; |
491 | | - const spzWriter = new SpzWriter({ |
492 | | - numSplats: nonZeroCount, |
493 | | - shDegree: maxSh, |
494 | | - fractionalBits: ioOptions.fractionalBits, |
495 | | - flagAntiAlias: true, |
496 | | - }); |
497 | | - |
498 | 489 | console.log("Writing splats to SPZ..."); |
499 | | - // Iterate through the new packed array |
500 | | - for (let i = 0; i < nonZeroCount; i++) { |
501 | | - const unpacked = unpackSplat( |
502 | | - newPackedSplats.packedArray, |
503 | | - i, |
504 | | - newPackedSplats.splatEncoding |
505 | | - ); |
506 | | - |
507 | | - spzWriter.setCenter(i, unpacked.center.x, unpacked.center.y, unpacked.center.z); |
508 | | - spzWriter.setScale(i, unpacked.scales.x, unpacked.scales.y, unpacked.scales.z); |
509 | | - spzWriter.setQuat(i, unpacked.quaternion.x, unpacked.quaternion.y, unpacked.quaternion.z, unpacked.quaternion.w); |
510 | | - spzWriter.setAlpha(i, unpacked.opacity); |
511 | | - spzWriter.setRgb(i, unpacked.color.r, unpacked.color.g, unpacked.color.b); |
512 | | - } |
513 | | - const spzBytes = await spzWriter.finalize(); |
514 | | - if (spzWriter.clippedCount > 0) { |
515 | | - console.log(`Clipped ${spzWriter.clippedCount} splats. Consider decreasing fractional-bits from ${ioOptions.fractionalBits} to reduce clipping.`); |
516 | | - } |
517 | | - |
| 490 | + const { fileBytes: spzBytes } = writeSpz(newPackedSplats, ioOptions.maxSh, ioOptions.fractionalBits); |
| 491 | + |
518 | 492 | console.log("Creating download..."); |
519 | 493 | const blob = new Blob([spzBytes], { type: "application/octet-stream" }); |
520 | 494 | const url = URL.createObjectURL(blob); |
|
531 | 505 | } |
532 | 506 | }, |
533 | 507 | }; |
534 | | - |
| 508 | + |
535 | 509 | const ioFolder = gui.addFolder("I/O"); |
536 | 510 | ioFolder.add(ioOptions, "loadFile").name("Load Splats (SPZ/PLY)"); |
537 | 511 | ioFolder.add(ioOptions, "saveToSpz").name("Save Splats (SPZ)"); |
|
0 commit comments