用 viewer.loadModel() 加载一个 blob?

问题描述 投票:0回答:0

我正在处理一个更大的项目,我想在其中使用 viewer.loadModel() 函数加载 GLTF。 问题是,我在一家独立的公司工作。我从他们的 API 中获取 GLTF 作为包含 gltf 和二进制文件的 zip 文件。我的客户端是用打字稿(使用 React)编写的。 现在我正在尝试像这样加载 gltf:

const gltfBytes = Uint8Array.from(window.atob(response), (c) => c.charCodeAt(0)); const zip = new JSZip(); await zip.loadAsync(gltfBytes); const files = zip.files; const gltf = await files["scene.gltf"].async("uint8array"); const bin = await files["scene.bin"].async("uint8array"); const gltfBlob = new Blob([gltf], {type: "model/gltf+json"}); const binBlob = new Blob([bin], {type: "application/octet-stream"}); const gltfUrl = URL.createObjectURL(gltfBlob); //const binUrl = URL.createObjectURL(binBlob); viewer.loadModel(gltfUrl.substring("blob:".length) + ".gltf", null);

我已经为 viewer.loadModel 参数尝试了不同的东西,但我似乎没有做对。 url 看起来像这样“http://localhost:3000/05bff201-dd63-47fb-800d-3860dd3c676b.gltf”,当我将其用作参数时,查看器开始加载一段时间后退出说有“网络问题”。

问题是:我在客户端做错了吗?或者通过 API 发送 gltf 及其二进制文件的整个方法是否真的不正确?

到目前为止,我试过这样调用函数:

    viewer.loadModel(gltfUrl + ".gltf", null); viewer.loadModel(gltfUrl.substring("blob:".length) + ".gltf", null); viewer.loadModel(gltfUrl.substring("blob:".length), {binary: binUrl.substring("blob:".length)}, null);

autodesk-forge autodesk-viewer gltf
© www.soinside.com 2019 - 2024. All rights reserved.