[name]

A loader for loading a .obj resource.
The OBJ file format is a simple data-format that represents 3D geometry in a human readable format as, the position of each vertex, the UV position of each texture coordinate vertex, vertex normals, and the faces that make each polygon defined as a list of vertices, and texture vertices.

Examples

// instantiate the loader let loader = new THREE.OBJLoader2(); // function called on successful load function callbackOnLoad ( object3d ) { scene.add( object3d ); } // load a resource from provided URL synchronously loader.load( 'obj/female02/female02.obj', callbackOnLoad, null, null, null ); [example:webgl_loader_obj2] - Simple example
[example:webgl_loader_obj2_options] - Example for multiple use-cases (parse and load, sync or in parallel to main (see [page:OBJLoader2Parallel]))

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]. Use it to load OBJ data from files or to parse OBJ data from arraybuffer or text.

Properties

See the base [page:Loader] class for common properties.

Methods

See the base [page:Loader] class for common methods.

[method:Object3D parse]( [param:arraybuffer content]|[param:String content] )

[[page:arraybuffer content]|[page:String content]] OBJ data as Uint8Array or String

Parses OBJ data synchronously from arraybuffer or string and returns the [page:Object3D baseObject3d].

[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:Function onMeshAlter] )

[page:String url] - A string containing the path/URL of the file to be loaded.
[page:Function onLoad] - A function to be called after loading is successfully completed. The function receives loaded [page:Object3D] as an argument.
[page:Function onProgress] - (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes.
[page:Function onError] - (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.
[page:Function onMeshAlter] - (optional) A function to be called after a new mesh raw data becomes available for alteration.

Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer.

[method:OBJLoader2 setLogging]( [param:Boolean enabled], [param:Boolean debug] )

[page:Boolean enabled] True or false.
[page:Boolean debug] True or false.

Enable or disable logging in general (except warn and error), plus enable or disable debug logging.

[method:OBJLoader2 addMaterialPerSmoothingGroup] ( [param:boolean materialPerSmoothingGroup] )

[page:boolean materialPerSmoothingGroup]

Tells whether a material shall be created per smoothing group.

[method:OBJLoader2 setUseOAsMesh] ( [param:boolean useOAsMesh] )

[page:boolean useOAsMesh]

Usually 'o' is meta-information and does not result in creation of new meshes, but mesh creation on occurrence of "o" can be enforced.

[method:OBJLoader2 setUseIndices]( [param:Boolean useIndices] )

[page:Boolean useIndices]

Instructs loaders to create indexed [page:BufferGeometry].

[method:OBJLoader2 setDisregardNormals]( [param:Boolean disregardNormals] )

[page:Boolean disregardNormals]

Tells whether normals should be completely disregarded and regenerated.

[method:OBJLoader2 setModelName] ( [param:String modelName] )

[page:String modelName]

Set the name of the model.

[method:OBJLoader2 setBaseObject3d] ( [param:Object3d baseObject3d] )

[page:Object3D baseObject3d - Object already attached to scenegraph where new meshes will be attached to

Set the node where the loaded objects will be attached directly.

[method:OBJLoader2 setMaterials] ( [param:Object materials] )

[page:Object materials] - materials Object with named [page:Material Materials]

Add materials as associated array.

[method:OBJLoader2 setCallbackOnLoad] ( [param:Function onLoad] )

[page:Function onLoad]

Register a function that is called when parsing was completed.

[method:OBJLoader2 setCallbackOnAssetAvailable] ( [param:Function onAssetAvailable] )

[page:Function onAssetAvailable]

Register a function that is called once an asset (mesh/material) becomes available.

[method:OBJLoader2 setCallbackOnProgress] ( [param:Function onProgress] )

[page:Function onProgress]

Register a function that is used to report overall processing progress.

[method:OBJLoader2 setCallbackOnError] ( [param:Function onError] )

[page:Function onError]

Register an error handler function that is called if errors occur. It can decide to just log or to throw an exception.

[method:OBJLoader2 setCallbackOnMeshAlter] ( [param:Function onMeshAlter] )

[page:Function onMeshAlter]

Register a function that is called once a single mesh is available and it could be altered by the supplied function.

Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/OBJLoader2.js examples/jsm/loaders/OBJLoader2.js]