[name]
A loader for loading a JSON resource. Unlike the [page:JSONLoader], this one make use of the
.type attributes of objects to map them to their original classes.
Note that this loader can't load [page:Geometries]. Use [page:JSONLoader] instead for that.
This uses the [page:FileLoader] internally for loading files.
Example
[example:webgl_animation_scene WebGL / animation / scene]
[example:webgl_loader_json_claraio WebGL / loader / json / claraio]
[example:webgl_loader_msgpack WebGL / loader / msgpack]
var loader = new THREE.ObjectLoader();
loader.load(
// resource URL
"models/json/example.json",
// onLoad callback
// Here the loaded data is assumed to be an object
function ( obj ) {
// Add the loaded object to the scene
scene.add( obj );
},
// onProgress callback
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// onError callback
function ( err ) {
console.error( 'An error happened' );
}
);
// Alternatively, to parse a previously loaded JSON structure
var object = loader.parse( a_json_object );
scene.add( object );
Constructor
[name]( [param:LoadingManager manager] )
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
Creates a new [name].
Properties
[property:String crossOrigin]
If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
attribute of the image to the value of *crossOrigin*,
prior to starting the load. Default is *undefined*.
[property:LoadingManager manager]
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
[property:String texturePath]
The base path or URL from which textures will be loaded. See [page:.setTexturePath].
Default is the empty string.
Methods
[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )
[page:String url] — the path or URL to the file. This can also be a
[link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].
[page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes.
[page:Function onError] — Will be called when load errors.
Begin loading from url and call onLoad with the parsed response content.
[method:Object3D parse]( [param:Object json], [param:Function onLoad] )
[page:Object json] — required. The JSON source to parse.
[page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].
Parse a JSON structure and return a threejs object.
This is used internally by [page:.load], but can also be used directly to parse
a previously loaded JSON structure.
[method:Object3D parseGeometries]( [param:Object json] )
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.
Internally it uses [page:JSONLoader] for geometries and [page:BufferGeometryLoader] for buffer geometries.
[method:Object3D parseMaterials]( [param:Object json] )
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any materials in the JSON structure using [page:MaterialLoader].
[method:Object3D parseAnimations]( [param:Object json] )
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any animations in the JSON structure, using [page:AnimationClip.parse].
[method:Object3D parseImages]( [param:Object json] )
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].
[method:Object3D parseTextures]( [param:Object json] )
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any textures in the JSON structure.
[method:Object3D parseObject]( [param:Object json] )
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any objects in the JSON structure.
Objects can be of the following types:
-
[page:Scene]
-
[page:PerspectiveCamera]
-
[page:OrthographicCamera]
-
[page:AmbientLight]
-
[page:DirectionalLight]
-
[page:PointLight]
-
[page:SpotLight]
-
[page:HemisphereLight]
-
[page:Mesh]
-
[page:LOD]
-
[page:Line]
-
[page:LineSegments]
-
[page:Points]
-
[page:Sprite]
-
[page:Group]
-
[page:Object3D]
[method:null setCrossOrigin]( [param:String value] )
[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
[method:null setTexturePath]( [param:String value] )
[page:String value] — The base path or URL from which textures will be loaded.
Source
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]