Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ObjectLoader

A loader for loading a JSON resource in the JSON Object/Scene format. This uses the FileLoader internally for loading files.

Examples

WebGL / materials / lightmap

Code Example

const loader = new THREE.ObjectLoader();
loader.load(
'models/json/example.json', // resource URL
function ( obj ) { // onLoad callback
// Here the loaded data is assumed to be an object.
// Add the loaded object to the scene
scene.add( obj );
},
function ( xhr ) { // onProgress callback
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
function ( err ) { // onError callback
console.error( 'An error happened' );
}
);
// Alternatively, to parse a previously loaded JSON structure
const object = loader.parse( a_json_object );
scene.add( object );

Ngx3Js Code Example

Hierarchy

Index

Constructors

constructor

Properties

crossOrigin

crossOrigin: string

The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS. Default is anonymous.

default

'anonymous'

manager

The loadingManager the loader is using. Default is DefaultLoadingManager.

path

path: string

The base path from which the asset will be loaded. Default is the empty string.

default

''

requestHeader

requestHeader: {}

The request header used in HTTP request. See .setRequestHeader. Default is empty object.

default

{}

Type declaration

  • [header: string]: string

resourcePath

resourcePath: string

The base path from which additional resources like textures will be loaded. Default is the empty string.

default

''

withCredentials

withCredentials: boolean

Whether the XMLHttpRequest uses credentials. See .setWithCredentials. Default is false.

default:

false

Methods

load

  • load(url: string, onLoad?: <ObjectType>(object: ObjectType) => void, onProgress?: (event: ProgressEvent<EventTarget>) => void, onError?: (event: ErrorEvent | Error) => void): void
  • Begin loading from url and call onLoad with the parsed response content.

    Parameters

    • url: string

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

    • Optional onLoad: <ObjectType>(object: ObjectType) => void

      Will be called when load completes. The argument will be the loaded object.

        • <ObjectType>(object: ObjectType): void
        • Type parameters

          Parameters

          • object: ObjectType

          Returns void

    • Optional onProgress: (event: ProgressEvent<EventTarget>) => void

      Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. If the server does not set the Content-Length header; .total will be 0.

        • (event: ProgressEvent<EventTarget>): void
        • Parameters

          • event: ProgressEvent<EventTarget>

          Returns void

    • Optional onError: (event: ErrorEvent | Error) => void

      Will be called when load errors.

        • (event: ErrorEvent | Error): void
        • Parameters

          • event: ErrorEvent | Error

          Returns void

    Returns void

loadAsync

  • loadAsync<ObjectType>(url: string, onProgress?: (event: ProgressEvent<EventTarget>) => void): Promise<ObjectType>
  • Begin loading from url and call onLoad with the parsed response content.

    Type parameters

    Parameters

    • url: string

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

    • Optional onProgress: (event: ProgressEvent<EventTarget>) => void

      Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. If the server does not set the Content-Length header; .total will be 0.

        • (event: ProgressEvent<EventTarget>): void
        • Parameters

          • event: ProgressEvent<EventTarget>

          Returns void

    Returns Promise<ObjectType>

parse

parseAnimations

parseAsync

  • parseAsync<T>(json: any): Promise<T>
  • Parse a JSON structure and return a threejs object. This is used internally by .load() but can also be used directly to parse a previously loaded JSON structure.

    Type parameters

    Parameters

    • json: any

      required. The JSON source to parse.

    Returns Promise<T>

parseGeometries

  • parseGeometries(json: any): {}

parseImages

  • parseImages(json: any, onLoad: () => void): {}

parseImagesAsync

  • parseImagesAsync(json: any): Promise<{}>

parseMaterials

parseObject

parseTextures

setCrossOrigin

setPath

setRequestHeader

setResourcePath

setWithCredentials

Generated using TypeDoc