perf: reduce 3D runtime artifacts (#7)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import * as THREE from 'three';
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
||||
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
||||
import {
|
||||
DRACOLoader,
|
||||
DRACO_GLTF_CONFIG,
|
||||
} from 'three/examples/jsm/loaders/DRACOLoader.js';
|
||||
import { KTX2Loader } from 'three/examples/jsm/loaders/KTX2Loader.js';
|
||||
import { publicAssetUrl } from '../runtimeBase';
|
||||
|
||||
export interface ViewerLoaders {
|
||||
gltf: GLTFLoader;
|
||||
@@ -10,17 +12,14 @@ export interface ViewerLoaders {
|
||||
ktx2: KTX2Loader;
|
||||
}
|
||||
|
||||
// SINGLETON — multiple DRACOLoader/KTX2Loader instances crash (three.js #22445).
|
||||
// Reuse across every load. Decoder WASM lives under public/draco + public/basis
|
||||
// (version-matched to the installed three.js).
|
||||
// 여러 DRACOLoader/KTX2Loader instance를 만들면 충돌할 수 있으므로 하나를 공유합니다.
|
||||
// decoder URL은 Three.js import가 생성하는 version 일치 hashed asset을 사용합니다.
|
||||
let _cache: ViewerLoaders | null = null;
|
||||
|
||||
export function getLoaders(renderer: THREE.WebGLRenderer): ViewerLoaders {
|
||||
if (_cache) return _cache;
|
||||
const draco = new DRACOLoader().setDecoderPath(publicAssetUrl('draco/'));
|
||||
const ktx2 = new KTX2Loader()
|
||||
.setTranscoderPath(publicAssetUrl('basis/'))
|
||||
.detectSupport(renderer);
|
||||
const draco = new DRACOLoader().setDecoderPath(DRACO_GLTF_CONFIG);
|
||||
const ktx2 = new KTX2Loader().detectSupport(renderer);
|
||||
const gltf = new GLTFLoader().setDRACOLoader(draco).setKTX2Loader(ktx2);
|
||||
_cache = { gltf, draco, ktx2 };
|
||||
return _cache;
|
||||
|
||||
Reference in New Issue
Block a user