无法使用forge-convert-utils转换gltf

时间:2019-10-10 11:14:20

标签: autodesk-forge autodesk-viewer

我使用以下命令从库中创建了带有示例代码的文件“ convert.js” 运行(“模型n”,“路径/到/输出/文件夹”);在gltf中获取模型。在控制台中运行“ node convert.js”时,出现错误。

我的步骤:1.创建项目2.npm安装forge-convert-utils 3.npm安装dotenv。 4.npm install forge-server-utils 5.创建文件convert.js,文件夹“文件夹”和配置文件.env 6。 节点convert.js

convert.js

const { ModelDerivativeClient, ManifestHelper } = require('forge-server-utils');
const { SvfReader, GltfWriter } = require('forge-convert-utils');
require('dotenv/config');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;

async function run (urn, outputDir) {
    const auth = { client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET };
    try{
        const modelDerivativeClient = new ModelDerivativeClient(auth);
        // crashed
        const helper = new ManifestHelper(await modelDerivativeClient.getManifest(urn));
        const derivatives = helper.search({ type: 'resource', role: 'graphics' });
        const writer = new GltfWriter(outputDir);
        for (const derivative of derivatives.filter(d => d.mime === 'application/autodesk-svf')) {
            const reader = await SvfReader.FromDerivativeService(urn, derivative.guid, auth);
            const svf = await reader.read();
            writer.write(svf);
        }
        writer.close();
    }
    catch (e) {
        console.log(e);
    }
}


run('dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6b3QwanRnamF3aGFoaWV0bDljYjkyZmNtZWZlcGkyZ2YtY3VzdG9tZXItZGVtb3MvQVMlMjBNQURFJTIwTUFJTSUyMFNIQUJBWkktMTkwMjE5LmR3Zw==', 'folder');

C:\ Users \ Bioro \ WebstormProjects \ svf-to-gltf \ forge-convert-custom>节点convert.js (节点:12108)UnhandledPromiseRejectionWarning:错误:请求失败,状态码为404

at createError (C:\Users\Bioro\WebstormProjects\svf-to-gltf\forge-convert-custom\node_modules\axios\lib\core\createError.js:16:15)
at settle (C:\Users\Bioro\WebstormProjects\svf-to-gltf\forge-convert-custom\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (C:\Users\Bioro\WebstormProjects\svf-to-gltf\forge-convert-custom\node_modules\axios\lib\adapters\http.js:237:11)
at IncomingMessage.emit (events.js:194:15)
at endReadableNT (_stream_readable.js:1125:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

(节点:12108)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。该错误是由于抛出没有catch块的异步函数而引起的,或者是由于拒绝了不是 与.catch()并存。 (拒绝ID:2)

(节点:12108)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝。将来,未处理的承诺拒绝将以非零退出代码终止Node.js进程。

1 个答案:

答案 0 :(得分:0)

堆栈跟踪说明的不多,只是Forge中缺少某些内容。尝试将run函数的内部包装在try-catch块中,以获取更多有关抛出异常的信息。

请注意,forge-convert-utils库假定已使用模型导数服务(使用POST job)翻译了URN。