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

前端 未结 2 1074
天命终不由人
天命终不由人 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条回答
  •  萌比男神i
    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

提交回复
热议问题