import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'

let dracoLoader: DRACOLoader | null = null

/** 带 Draco 解码的 GLTFLoader（压缩 glb 必需） */
export function createGLTFLoader(): GLTFLoader {
  const loader = new GLTFLoader()
  if (!dracoLoader) {
    dracoLoader = new DRACOLoader()
    dracoLoader.setDecoderPath('/draco/gltf/')
  }
  loader.setDRACOLoader(dracoLoader)
  return loader
}

export function disposeDracoLoader() {
  dracoLoader?.dispose()
  dracoLoader = null
}
