DRACOLoader模型压缩
Draco 是一个用于压缩和解压 3D 网格与点云的开源库。压缩后的几何数据体积可显著减小,但代价是客户端设备需要额外的解码时间。
独立的 Draco 文件使用 .drc 扩展名,包含顶点位置、法线、颜色及其他属性。Draco 文件不包含材质、纹理、动画或节点层级结构;如需使用这些功能,应将 Draco 几何数据嵌入到 glTF 文件中。可通过 glTF-Pipeline 将普通的 glTF 文件转换为使用 Draco 压缩的 glTF 文件。在 glTF 中使用 Draco 时,GLTFLoader 会内部调用 DRACOLoader 的实例。
下面是一个使用示例
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
// Instantiate a loader
const loader = new DRACOLoader();
// Specify path to a folder containing WASM/JS decoding libraries.
loader.setDecoderPath("/examples/jsm/libs/draco/");
// Optional: Pre-fetch Draco WASM/JS module.
loader.preload();
// Load a Draco geometry
loader.load(
// resource URL
"model.drc",
// called when the resource is loaded
function (geometry) {
const material = new THREE.MeshStandardMaterial({ color: 0x606060 });
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
},
// called as loading progresses
function (xhr) {
console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
},
// called when loading has errors
function (error) {
console.log("An error happened");
},
);