【问题标题】:Can I compress the glb file using the draco encoder with node.js?我可以使用带有 node.js 的 draco 编码器压缩 glb 文件吗?
【发布时间】:2019-10-10 17:07:06
【问题描述】:

我上传了一个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);
        });
  });

我希望你也能解决这个问题。加油!

【问题讨论】:

    标签: node.js three.js gltf


    【解决方案1】:

    使用npm module

    DRACOExporter/examples/js/exporters转换为模块

    【讨论】:

      猜你喜欢
      • 2020-07-15
      • 2019-11-25
      • 2019-09-07
      • 2019-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多