Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/dev/loaders/src/SPLAT/splatFileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,24 @@ export class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPlu

// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax, @typescript-eslint/naming-convention
private async _unzipWithFFlateAsync(data: Uint8Array): Promise<Map<string, Uint8Array>> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
let fflate = this._loadingOptions.fflate as typeof import("fflate");
// ensure fflate is loaded
if (typeof (window as any).fflate === "undefined") {
await Tools.LoadScriptAsync(this._loadingOptions.deflateURL ?? "https://unpkg.com/fflate/umd/index.js");
if (!fflate) {
if (typeof (window as any).fflate === "undefined") {
await Tools.LoadScriptAsync(this._loadingOptions.deflateURL ?? "https://unpkg.com/fflate/umd/index.js");
}
fflate = (window as any).fflate as typeof fflate;
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { unzipSync } = (window as any).fflate as typeof import("fflate");
const { unzipSync } = fflate;

const unzipped = unzipSync(data); // { [filename: string]: Uint8Array }
const unzipped = unzipSync(data) as Record<string, Uint8Array>; // { [filename: string]: Uint8Array }

const files = new Map<string, Uint8Array>();
for (const [name, content] of Object.entries(unzipped)) {
files.set(name, content as Uint8Array);
files.set(name, content);
}
return files;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/dev/loaders/src/SPLAT/splatLoadingOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ export type SPLATLoadingOptions = {
* (https://unpkg.com/fflate/umd/index.js)
*/
deflateURL?: string;
/**
* Instance of [fflate](https://github.com/101arrowz/fflate) to avoid
* dynamically loading of the lib to global if needed, useful for bundler users.
* @example import * as fflate from 'fflate';
*/
fflate?: unknown;
};
Loading