1+ import { unzipSync } from "fflate" ;
12import { FileLoader , Loader , type LoadingManager } from "three" ;
23import { PackedSplats } from "./PackedSplats" ;
34import { SplatMesh } from "./SplatMesh" ;
@@ -138,6 +139,7 @@ export enum SplatFileType {
138139 SPLAT = "splat" ,
139140 KSPLAT = "ksplat" ,
140141 PCSOGS = "pcsogs" ,
142+ PCSOGSZIP = "pcsogszip" ,
141143}
142144
143145export function getSplatFileType (
@@ -157,6 +159,14 @@ export function getSplatFileType(
157159 // Unknown Gzipped file type
158160 return undefined ;
159161 }
162+ if ( view . getUint32 ( 0 , true ) === 0x04034b50 ) {
163+ // PKZip file
164+ if ( tryPcSogsZip ( fileBytes ) ) {
165+ return SplatFileType . PCSOGSZIP ;
166+ }
167+ // Unknown PKZip file type
168+ return undefined ;
169+ }
160170 // Unknown file type
161171 return undefined ;
162172}
@@ -218,7 +228,7 @@ export type PcSogsJson = {
218228 maxs : number [ ] ;
219229 files : string [ ] ;
220230 } ;
221- shN : {
231+ shN ? : {
222232 shape : number [ ] ;
223233 dtype : string ;
224234 mins : number ;
@@ -277,6 +287,37 @@ export function tryPcSogs(
277287 }
278288}
279289
290+ export function tryPcSogsZip (
291+ input : ArrayBuffer | Uint8Array ,
292+ ) : { name : string ; json : PcSogsJson } | undefined {
293+ try {
294+ const fileBytes =
295+ input instanceof ArrayBuffer ? new Uint8Array ( input ) : input ;
296+ let metaFilename : string | null = null ;
297+
298+ const unzipped = unzipSync ( fileBytes , {
299+ filter : ( { name } ) => {
300+ const filename = name . split ( / [ \\ / ] / ) . pop ( ) as string ;
301+ if ( filename === "meta.json" ) {
302+ metaFilename = name ;
303+ return true ;
304+ }
305+ return false ;
306+ } ,
307+ } ) ;
308+ if ( ! metaFilename ) {
309+ return undefined ;
310+ }
311+ const json = tryPcSogs ( unzipped [ metaFilename ] ) ;
312+ if ( ! json ) {
313+ return undefined ;
314+ }
315+ return { name : metaFilename , json } ;
316+ } catch {
317+ return undefined ;
318+ }
319+ }
320+
280321export async function unpackSplats ( {
281322 input,
282323 extraFiles,
@@ -373,6 +414,19 @@ export async function unpackSplats({
373414 return { packedArray, numSplats, extra } ;
374415 } ) ;
375416 }
417+ case SplatFileType . PCSOGSZIP : {
418+ return await withWorker ( async ( worker ) => {
419+ const { packedArray, numSplats, extra } = ( await worker . call (
420+ "decodePcSogsZip" ,
421+ { fileBytes } ,
422+ ) ) as {
423+ packedArray : Uint32Array ;
424+ numSplats : number ;
425+ extra : Record < string , unknown > ;
426+ } ;
427+ return { packedArray, numSplats, extra } ;
428+ } ) ;
429+ }
376430 default : {
377431 throw new Error ( `Unknown splat file type: ${ splatFileType } ` ) ;
378432 }
0 commit comments