How to make a loading screen in three.js?

前端 未结 2 1567
粉色の甜心
粉色の甜心 2021-02-01 20:21

I have a large amount of textures and models to load into my project. I am trying to show a progress bars while everything is loading. I think the LoadingManager

2条回答
  •  一整个雨季
    2021-02-01 21:27

    Docs: http://threejs.org/docs/#Reference/Loaders/TextureLoader

    Example: http://threejs.org/examples/#webgl_loader_obj

    Code:

      var sphereMaterial = new THREE.MeshBasicMaterial();
    
      var onProgress = function ( xhr ) {
        if ( xhr.lengthComputable ) {
          var percentComplete = xhr.loaded / xhr.total * 100;
          console.log( Math.round(percentComplete, 2) + '% downloaded' );
        }
      };
    
      var loader = new THREE.TextureLoader();
      var texture = loader.load("___4MB_IMAGE.JPG___", undefined, onProgress);
      sphereMaterial.map = texture;
    

    It solves a similar problem I had - 4MB texture that takes some time to load over the wire...

提交回复
热议问题