Loader

OBJLoader

A loader for the OBJ format.

The OBJ 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.

Code Example

const loader = new OBJLoader();
const object = await loader.loadAsync( 'models/monster.obj' );
scene.add( object );

Import

OBJLoader is an addon, and must be imported explicitly, see Installation#Addons.

import { OBJLoader } from 'three/addons/loaders/OBJLoader.js';

Constructor

new OBJLoader( manager : LoadingManager )

Constructs a new OBJ loader.

manager

The loading manager.

Properties

.materials : MaterialCreator

A reference to a material creator.

Default is null.

Methods

.load( url : string, onLoad : function, onProgress : onProgressCallback, onError : onErrorCallback )

Starts loading from the given URL and passes the loaded OBJ asset to the onLoad() callback.

url

The path/URL of the file to be loaded. This can also be a data URI.

onLoad

Executed when the loading process has been finished.

onProgress

Executed while the loading is in progress.

onError

Executed when errors occur.

Overrides: Loader#load

.parse( text : string ) : Group

Parses the given OBJ data and returns the resulting group.

text

The raw OBJ data as a string.

Overrides: Loader#parse
Returns: The parsed OBJ.

.setMaterials( materials : MaterialCreator ) : OBJLoader

Sets the material creator for this OBJ. This object is loaded via MTLLoader.

materials

An object that creates the materials for this OBJ.

Returns: A reference to this loader.

Source

examples/jsm/loaders/OBJLoader.js