我们可以在服务器端编辑(位置、比例等)glTF 模型吗(没有 three.js)?

Can we edit (position, scale, etc) glTF models on the server side (without three.js)?

我正在尝试合并两个 gltf 资产,我正在使用 sayduck gltf 管道来实现它。问题是我需要其中一项资产远离其他资产。例如。 cat (0, 0, 0) 和 dog (10, 0, 0) 并排放置比较

我已经尝试在服务器端使用 three.js (node.js),但让 gltf 解析器在服务器端工作有点困难。如果不使用 three.js.

也能实现,那就太好了

您不需要使用像 threejs 这样的 3D 渲染库来编辑 glTF 文件服务器端。对于最简单的情况(在 .gltf 文件中重新定位对象),您可以这样做:

const fs = require('fs');

// Read and parse file.
const gltfContent = fs.readFileSync('file.gltf', {encoding: 'utf8'});
const gltf = JSON.parse(gltfContent);

// Edit glTF asset.
const node = gltf.nodes.filter((n) => n.name === 'Cat')[0];
node.translation = [10, 0, 5];

// Write to disk.
fs.writeFileSync('file.gltf', JSON.stringify(gltf));

要对文件进行更复杂的更改,您需要使用 existing parsing/writing tool or learn about the glTF specification