Capítulo 179 de 859

Chapter 179: Loader

Core Idea

Abstract base class for loaders.

Key Concepts

  • crossOrigin : string: The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
  • manager : LoadingManager: The loading manager.
  • path : string: The base path from which the asset will be loaded.
  • requestHeader : Object.<string, any>: The request header used in HTTP request.
  • resourcePath : string: The base path from which additional resources like textures will be loaded.
  • withCredentials : boolean: Whether the XMLHttpRequest uses credentials.
  • DEFAULT_MATERIAL_NAME : string: The default material name that is used by loaders when creating materials for loaded 3D objects.

Reference Tables

Constructor

Signature
new Loader( manager : LoadingManager ) (abstract)

Properties

PropertyDescription
.crossOrigin : stringThe crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
.manager : LoadingManagerThe loading manager.
.path : stringThe base path from which the asset will be loaded.
.requestHeader : Object.<string, any>The request header used in HTTP request.
.resourcePath : stringThe base path from which additional resources like textures will be loaded.
.withCredentials : booleanWhether the XMLHttpRequest uses credentials.
.DEFAULT_MATERIAL_NAME : stringThe default material name that is used by loaders when creating materials for loaded 3D objects.

Methods

MethodDescription
.abort() : Loader (abstract)This method can be implemented in loaders for aborting ongoing requests.
.load( url : string, onLoad : function, onProgress : onProgressCallback, onError : onErrorCallback ) (abstract)This method needs to be implemented by all concrete loaders. It holds the logic for loading assets from the backend.
.loadAsync( url : string, onProgress : onProgressCallback ) : PromiseA async version of Loader#load.
.parse( data : any ) (abstract)This method needs to be implemented by all concrete loaders. It holds the logic for parsing the asset into three.js entities.
.setCrossOrigin( crossOrigin : string ) : LoaderSets the crossOrigin String to implement CORS for loading the URL from a different domain that allows CORS.
.setPath( path : string ) : LoaderSets the base path for the asset.
.setRequestHeader( requestHeader : Object ) : LoaderSets the given request header.
.setResourcePath( resourcePath : string ) : LoaderSets the base path for dependent resources like textures.
.setWithCredentials( value : boolean ) : LoaderWhether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS client certificates, see [XMLHttpRequest.withCredentials](https://developer.mozilla.org/en-US/docs/Web/API/XM…

Key Takeaways

  1. Most relevant properties: crossOrigin, manager, path, requestHeader.
  2. Key methods: abort, load, loadAsync, parse.

Connects To