我上传了一个obj文件,并在three.js上将其转换为glb文件。所以我想使用Draco encoder压缩文件,但我只知道如何使用cmd压缩它。有没有使用node.js压缩的方法?
编辑过的
我自己解决的。该方法简单、快速。我只是在安装this。并且,我的代码在这里。
const gltfPipeline = require('gltf-pipeline');
const fsExtra = require('fs-extra');
const path = require('path');
const glbToGltf = gltfPipeline.glbToGltf;
const processGltf = gltfPipeline.processGltf;
const glb = fsExtra.readFileSync(path.resolve(__dirname+'/../public/glbFiles/' + req.filename));
const options = {
dracoOptions: {
compressionLevel: 10
}
};
glbToGltf(glb)
.then(gltf => {
processGltf(gltf.gltf, options)
.then(results => {
fsExtra.writeJsonSync(path.resolve(__dirname + '/../public/compressionFiles/' + req.filename.split('.')[0] + '.gltf'), results.gltf);
});
});我希望你也能解决这个问题。勇敢点儿!
发布于 2019-05-24 15:51:30
https://stackoverflow.com/questions/56286827
复制相似问题