TextureLoader

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

Example

var texture = new v3d.TextureLoader().load('textures/land_ocean_ice_cloud_2048.jpg'); // immediately use the texture for material creation var material = new v3d.MeshBasicMaterial({ map: texture }); geometry / cube

Example with Callbacks

// instantiate a loader var loader = new v3d.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 var material = new v3d.MeshBasicMaterial({ map: texture }); }, // onProgress callback currently not supported undefined, // onError callback function(err) { console.error('An error happened.'); } ); Please note Verge3D 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 v3d.DefaultLoadingManager.

Creates a new TextureLoader.

Properties

.crossOrigin : String

If set, assigns the crossOrigin attribute of the image to the value of crossOrigin, prior to starting the load. Default is "anonymous".

.manager : LoadingManager

The loadingManager the loader is using. Default is DefaultLoadingManager.

.path : String

The base path from which files will be loaded. See .setPath. Default is undefined.

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 — Will be called when load completes. The argument will be the loaded texture.
onProgress — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes.
onError — 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.

.setCrossOrigin (value : String) : null

Set the .crossOrigin attribute.

.setPath (path : String) : FileLoader

Set the base path or URL from which to load files. This can be useful if you are loading many models from the same directory.

Source

For more info on how to obtain the source code of this module see this page.