perf: reduce 3D runtime artifacts (#7)
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
// Copies Draco + KTX2/Basis decoder WASM from three.js into public/ so the
|
||||
// runtime paths /draco/ and /basis/ resolve (version-matched to installed three).
|
||||
// Also copies the web-ifc single-thread WASM to public/web-ifc/ for the IFC path.
|
||||
// Runs automatically via `npm install` (postinstall). Safe to re-run.
|
||||
// IFC single-thread WASM을 public/에 staging합니다.
|
||||
// `npm install`의 postinstall에서 자동 실행되며 반복 실행해도 같은 결과를 만듭니다.
|
||||
import {
|
||||
chmodSync,
|
||||
cpSync,
|
||||
copyFileSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
readdirSync,
|
||||
rmSync,
|
||||
} from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
@@ -17,54 +13,18 @@ import { fileURLToPath } from 'node:url';
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const root = resolve(__dirname, '..');
|
||||
|
||||
function normalizePublicModes(directory) {
|
||||
chmodSync(directory, 0o755);
|
||||
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||||
const path = resolve(directory, entry.name);
|
||||
if (entry.isDirectory()) normalizePublicModes(path);
|
||||
else if (entry.isFile()) chmodSync(path, 0o644);
|
||||
}
|
||||
}
|
||||
|
||||
const threeEntry = fileURLToPath(import.meta.resolve('three'));
|
||||
const threeRoot = resolve(dirname(threeEntry), '..');
|
||||
const libs = resolve(threeRoot, 'examples/jsm/libs');
|
||||
const targets = [
|
||||
[resolve(libs, 'draco/gltf'), resolve(root, 'public/draco')],
|
||||
[resolve(libs, 'basis'), resolve(root, 'public/basis')],
|
||||
];
|
||||
|
||||
if (!existsSync(libs)) {
|
||||
console.warn('[copy-decoders] three not installed yet — skipping (will run on next install).');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
for (const [src, dest] of targets) {
|
||||
if (!existsSync(src)) {
|
||||
console.warn(`[copy-decoders] source missing: ${src}`);
|
||||
continue;
|
||||
}
|
||||
rmSync(dest, { force: true, recursive: true });
|
||||
mkdirSync(dest, { recursive: true });
|
||||
cpSync(src, dest, { recursive: true });
|
||||
normalizePublicModes(dest);
|
||||
console.log(`[copy-decoders] ${src} -> ${dest}`);
|
||||
}
|
||||
|
||||
// web-ifc single-thread WASM (+ MT build if present) for the IFC load path.
|
||||
// 현재 IFC 경로는 COOP/COEP가 필요 없는 single-thread WASM만 사용합니다.
|
||||
const ifcEntry = fileURLToPath(import.meta.resolve('web-ifc'));
|
||||
const ifcSrcDir = dirname(ifcEntry);
|
||||
const ifcDest = resolve(root, 'public/web-ifc');
|
||||
if (existsSync(ifcSrcDir)) {
|
||||
rmSync(ifcDest, { force: true, recursive: true });
|
||||
mkdirSync(ifcDest, { recursive: true });
|
||||
for (const wasm of ['web-ifc.wasm', 'web-ifc-mt.wasm']) {
|
||||
const src = resolve(ifcSrcDir, wasm);
|
||||
if (!existsSync(src)) continue;
|
||||
const dest = resolve(ifcDest, wasm);
|
||||
copyFileSync(src, dest);
|
||||
chmodSync(dest, 0o644);
|
||||
console.log(`[copy-decoders] ${src} -> ${dest}`);
|
||||
}
|
||||
const src = resolve(ifcSrcDir, 'web-ifc.wasm');
|
||||
const dest = resolve(ifcDest, 'web-ifc.wasm');
|
||||
copyFileSync(src, dest);
|
||||
chmodSync(dest, 0o644);
|
||||
console.log(`[copy-decoders] ${src} -> ${dest}`);
|
||||
} else {
|
||||
console.warn('[copy-decoders] web-ifc not installed yet — skipping IFC wasm.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user