TextureLoader in ThreeJs

Class for loading a texture. This uses the ImageLoader internally for loading files.

Code Example

const texture = new THREE.TextureLoader().load('textures/land_ocean_ice_cloud_2048.jpg' );

// immediately use the texture for material creation

const material = new THREE.MeshBasicMaterial( { map:texture } );

Code Example with Callbacks

// instantiate a loader

const loader = new THREE.TextureLoader();

// load a resource

loader.load(

// resource URL

'textures/land_ocean_ice_cloud_2048.jpg',

// onLoad callback

function ( texture ) {

// in this example we create the material when the texture is loaded

const material = new THREE.MeshBasicMaterial( {

map: texture

} );

},

// onProgress callback currently not supported

undefined,

// onError callback

function ( err ) {

console.error( 'An error happened.' );

}

);

Please note three.js r84 dropped support for TextureLoader progress events. For a TextureLoader that supports progress events, see this thread.

Constructor

TextureLoader( manager : LoadingManager )

manager — The loadingManager for the loader to use. Default is THREE.DefaultLoadingManager.

Creates a new TextureLoader.

Properties

See the base Loader class for common properties.

Methods

See the base Loader class for common methods.

.load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : Texture

url — the path or URL to the file. This can also be a Data URI.

onLoad (optional) — Will be called when load completes. The argument will be the loaded texture.

onProgress (optional) — This callback function is currently not supported.

onError (optional) — Will be called when load errors.

Begin loading from the given URL and pass the fully loaded texture to onLoad. 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.

Source

src/loaders/TextureLoader.js

Leave a comment

Your email address will not be published. Required fields are marked *