@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
55 lines (54 loc) • 1.99 kB
JavaScript
;
import { LIBRARY_INSTALL_HINT } from "./../common";
import { Poly } from "../../../engine/Poly";
import { CoreBaseLoader, modifyUrl } from "../_Base";
import { sanitizeUrl } from "../../UrlHelper";
export class XAtlasLoaderHandler extends CoreBaseLoader {
// private static _module: XAtlasContainer | undefined;
// private static _wasmUrl: string | undefined;
// public static async xatlas(node: BaseNodeType) {
// if (!this._module) {
// await this._loadWasm({}, node);
// // const wasmurl = new URL('./UvUnwrap/xatlas-web.wasm', import.meta.url);
// // const wasmurl = new URL('../../../../node_modules/xatlas-web/dist/xatlas-web.wasm', import.meta.url);
// // const wasmurl = new URL('xatlas-web/dist/xatlas-web.wasm', import.meta.url);
// this._module = XAtlas({
// locateFile: (path: string) => {
// if (path.endsWith('.wasm')) {
// return this._wasmUrl;
// }
// return path;
// },
// });
// }
// return this._module ? this._module.ready : undefined;
// }
static async loadWasm(node) {
const root = Poly.libs.root();
const XATLASPath = Poly.libs.XATLASPath();
if (root || XATLASPath) {
const decoderPath = sanitizeUrl(`${root || ""}${XATLASPath || ""}/`);
const fileNames = ["xatlas.wasm", "xatlas.js"];
const fullUrls = fileNames.map((fileName) => {
return {
fullUrl: `${decoderPath}${fileName}`
};
});
await this._loadMultipleUrlsGlobal({
files: fullUrls,
node,
error: `failed to load xatlas libraries. Make sure to install them use the uvUnwrap (${LIBRARY_INSTALL_HINT})`
});
const _addOrigin = (url) => {
if (!url.startsWith("http")) {
return `${window.location.origin}/${url}`;
}
return url;
};
return {
wasm: _addOrigin(modifyUrl(fullUrls[0].fullUrl)),
js: _addOrigin(modifyUrl(fullUrls[1].fullUrl))
};
}
}
}