How to make a loading screen while using three.js and jsonLoader?

前端 未结 2 1072
天命终不由人
天命终不由人 2021-01-01 02:05

I have a very large amount of texture files and models to load into my project. I am trying to show a status bar or some sort of loading screen while everything is loading.

相关标签:
2条回答
  • 2021-01-01 02:33

    The minimum required code is just this:

    THREE.DefaultLoadingManager.onProgress = function ( item, loaded, total ) {
        console.log( item, loaded, total );
    };
    

    Instead of printing to the console you can for example start the rendering loop "if loaded == total". Or/And you can update any loading indicater. (The code is from one of the examples.)

    0 讨论(0)
  • 2021-01-01 02:33

    You can use a pattern like this to manage the loading process:

    var manager = new THREE.LoadingManager();
    
    manager.onStart = function( item, loaded, total ) {
    
        console.log( 'Loading started' );
    
    };
    
    manager.onLoad = function() {
    
        console.log( 'Loading complete' );
    
    };
    
    manager.onProgress = function( item, loaded, total ) {
    
        console.log( item, loaded, total );
    
    };
    
    manager.onError = function( url ) {
    
        console.log( 'Error loading' );
    
    };
    
    var loader = new THREE.TextureLoader( manager );
    
    var texture = loader.load( 'texture.jpg', function ( texture ) {
    
        texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
        texture.repeat.set( 2, 2 );
    
    } );
    
    var loader = new THREE.OBJLoader( manager );
    
    loader.load( 'file.obj', function( object ) {
    
        // your code
    
     } );
    

    three.js r.85

    0 讨论(0)
提交回复
热议问题