【问题标题】:Three JS: get progress of multiple file load三JS:获取多文件加载进度
【发布时间】:2021-05-31 23:02:15
【问题描述】:

我是三个 JS 的新手。

我在这里要做的是创建一个加载屏幕,该屏幕应显示场景所需资产的加载进度。

我有多种类型的资产(总共 7 个文件),例如-

  1. 4 个 GLB 文件
  2. 2 个纹理文件
  3. 还有 1 个 Obj 文件

现在我可以从三个 JS 文档中加载如下文件(显然我需要根据文件类型使用不同的加载器)-

const gltfLoder: EThree.GLTFLoader = new Three.GLTFLoader(this.loadingManager);
            gltfLoder.load("/res/three/models/gltf/multiple/cat.glb", (glb: Three.GLTF) => {
                console.log("THREE >> GLB Loaded ", glb);
            }, (xhr: any) => {
console.log ("loading progress >> " + xhr.loaded);
}

这会给我单个文件的进度,有没有一个解决方案可以让我获得所有文件的加载进度?即 100% 的进度应该是所有 7 个文件都加载完毕。

提前致谢

【问题讨论】:

    标签: javascript typescript three.js loading gltf


    【解决方案1】:

    LoadingManager 有 onProgress。例如

    this.loadingManager.onProgress = function ( url, itemsLoaded, itemsTotal ) {
        console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
    };
    

    还有onStartonLoadonError

    LoadingManager reference

    【讨论】:

    • 如果我有一个大小为 20MB 的文件怎么办?我如何显示为 TextureLoader 类加载的字节数可能会或可能不会使用 LoadingManager,因为它被称为文件加载而不是进度
    猜你喜欢
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 2018-07-23
    • 2013-05-19
    • 2022-08-09
    • 1970-01-01
    相关资源
    最近更新 更多