总的来说,我对javascript和编程很陌生。我想使用这个:https://github.com/CesiumGS/gltf-pipeline,它是一个将模型转换成压缩格式的工具。这是我的密码:
const gltfPipeline = require("gltf-pipeline");
const fsExtra = require("fs-extra");
const processGltf = gltfPipeline.processGltf;
const gltf = fsExtra.readJsonSync("model.gltf");
const options = {
dracoOptions: {
compressionLevel: 10,
},
separateTextures: true,
};
processGltf(gltf, options).then(function (results) {
fsExtra.writeJsonSync("modeldraco.gltf", results.gltf);
console.log('done');
const separateResources = results.separateResources;
for (const relativePath in separateResources) {
if (separateResources.hasOwnProperty(relativePath)) {
const resource = separateResources[relativePath];
fsExtra.writeFileSync(relativePath, resource);
}
}
}); 我复制了这个文件,并将其保存为compress.js (因为它押韵),然后使用node compress.js运行它--这就是我运行python文件的方式。
错误是:Cannot find module 'gltf-pipeline',这是合理的。所以,我做了
node -r gltf-pipeline compress.js,但我也有同样的错误。
因此,我转到了HTML/JS,在那里我创建了一个index.html文件,并与一个<script>标记compress.js和gltf-pipeline index.js文件链接。这些都是错误:
index.js:3 Uncaught ReferenceError: module is not defined
at index.js:3
(anonymous) @ index.js:3
compress.js:3 Uncaught ReferenceError: require is not defined这是怎么做的?无论是作为网页还是命令行都是有帮助的。这是我的文件夹结构,也许这就是问题所在。
basefolder|
|- gltf-pipeline| library files in here
|- compress.js
|- index.html
|- model.gltf当用作命令行工具时,管道可以工作。
https://stackoverflow.com/questions/69699534
复制相似问题