Skip to content

⬅️ Back to Table of Contents

📄 TextureLoader.js

📊 Analysis Summary

Metric Count
🔧 Functions 1
🧱 Classes 1
📦 Imports 3
📊 Variables & Constants 2

📚 Table of Contents

🛠️ File Location:

📂 src/loaders/TextureLoader.js

📦 Imports

Name Source
ImageLoader ./ImageLoader.js
Texture ../textures/Texture.js
Loader ./Loader.js

Variables & Constants

Name Type Kind Value Exported
texture Texture let/var new Texture()
loader ImageLoader let/var new ImageLoader( this.manager )

Functions

TextureLoader.load(url: string, onLoad: (arg0: Texture) => any, onProgress: onProgressCallback, onError: onErrorCallback): Texture

JSDoc:

/**
     * Starts loading from the given URL and pass the fully loaded texture
     * to the `onLoad()` callback. The method also returns a new texture object which can
     * directly be used for material creation. If you do it this way, the texture
     * may pop up in your scene once the respective loading process is finished.
     *
     * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
     * @param {function(Texture)} onLoad - Executed when the loading process has been finished.
     * @param {onProgressCallback} onProgress - Unsupported in this loader.
     * @param {onErrorCallback} onError - Executed when errors occur.
     * @return {Texture} The texture.
     */

Parameters:

  • url string
  • onLoad (arg0: Texture) => any
  • onProgress onProgressCallback
  • onError onErrorCallback

Returns: Texture

Calls:

  • loader.setCrossOrigin
  • loader.setPath
  • loader.load
  • onLoad
Code
load( url, onLoad, onProgress, onError ) {

        const texture = new Texture();

        const loader = new ImageLoader( this.manager );
        loader.setCrossOrigin( this.crossOrigin );
        loader.setPath( this.path );

        loader.load( url, function ( image ) {

            texture.image = image;
            texture.needsUpdate = true;

            if ( onLoad !== undefined ) {

                onLoad( texture );

            }

        }, onProgress, onError );

        return texture;

    }

Classes

TextureLoader

Class Code
class TextureLoader extends Loader {

    /**
     * Constructs a new texture loader.
     *
     * @param {LoadingManager} [manager] - The loading manager.
     */
    constructor( manager ) {

        super( manager );

    }

    /**
     * Starts loading from the given URL and pass the fully loaded texture
     * to the `onLoad()` callback. The method also returns a new texture object which can
     * directly be used for material creation. If you do it this way, the texture
     * may pop up in your scene once the respective loading process is finished.
     *
     * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
     * @param {function(Texture)} onLoad - Executed when the loading process has been finished.
     * @param {onProgressCallback} onProgress - Unsupported in this loader.
     * @param {onErrorCallback} onError - Executed when errors occur.
     * @return {Texture} The texture.
     */
    load( url, onLoad, onProgress, onError ) {

        const texture = new Texture();

        const loader = new ImageLoader( this.manager );
        loader.setCrossOrigin( this.crossOrigin );
        loader.setPath( this.path );

        loader.load( url, function ( image ) {

            texture.image = image;
            texture.needsUpdate = true;

            if ( onLoad !== undefined ) {

                onLoad( texture );

            }

        }, onProgress, onError );

        return texture;

    }

}

Methods

load(url: string, onLoad: (arg0: Texture) => any, onProgress: onProgressCallback, onError: onErrorCallback): Texture
Code
load( url, onLoad, onProgress, onError ) {

        const texture = new Texture();

        const loader = new ImageLoader( this.manager );
        loader.setCrossOrigin( this.crossOrigin );
        loader.setPath( this.path );

        loader.load( url, function ( image ) {

            texture.image = image;
            texture.needsUpdate = true;

            if ( onLoad !== undefined ) {

                onLoad( texture );

            }

        }, onProgress, onError );

        return texture;

    }