OBJLoader2

A loader for loading a .obj resource.
The OBJ file format is a simple data-format that represents 3D geometry in a human redeable 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 var loader = new v3d.OBJLoader2(); // function called on successful load var callbackOnLoad = function(event) { scene.add(event.detail.loaderRootNode); }; // load a resource from provided URL synchronously loader.load('obj/female02/female02.obj', callbackOnLoad, null, null, null, false); webgl_loader_obj2 - Simple example
webgl_loader_obj2_options - Example for multiple use-cases (parse, load and run with instructions (sync and async)
webgl_loader_obj2_run_director - Advanced example using LoaderSupport.LoaderWorkerDirector for orchestration of multiple workers.

Constructor

OBJLoader2(manager : LoadingManager, logger : LoaderSupport.ConsoleLogger)

manager - The loadingManager for the loader to use. Default is v3d.DefaultLoadingManager.
logger - logger to be used

Use OBJLoader2 to load OBJ data from files or to parse OBJ data from arraybuffer or text.

Methods

.parse ({content : arraybuffer|content : String]) : Object3D

[content|content] OBJ data as Uint8Array or String

Parses OBJ data synchronously from arraybuffer or string and returns the loaderRoorNode.

.parseAsync (content : arraybuffer, onLoad : Function) : Object3D

content - OBJ data as Uint8Array
onLoad - Called after worker successfully completed loading

Parses OBJ content asynchronously from arraybuffer.

.load (url : String, onLoad : Function, onProgress : Function, onError : Function, onMeshAlter : Function, useAsync : boolean) : null

url - A string containing the path/URL of the file to be loaded.
onLoad - A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument.
onProgress - (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains total and loaded bytes.
onError - (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.
onMeshAlter - (optional) A function to be called after a new mesh raw data becomes available for alteration.
useAsync - (optional) If true, uses async loading with worker, if false loads data synchronously.

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

.run (params : LoaderSupport.PrepData, workerSupportExternal : LoaderSupport.WorkerSupport) : null

params - prepData All parameters and resources required for execution
workerSupportExternal - Use pre-existing WorkerSupport

Run the loader according the provided instructions.

.setLogging (enabled : Boolean, debug : Boolean) : null

enabled True or false.
debug True or false.

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

.setModelName (modelName : String) : null

modelName

Set the name of the model.

.setPath (path : String) : null

path - URL

The URL of the base path.

.setResourcePath (resourcePath : String) : null

resourcePath - URL

Allows to specify resourcePath for dependencies of specified resource.

.setStreamMeshesTo (streamMeshesTo : Object3D) : null

streamMeshesTo - Object already attached to scenegraph where new meshes will be attached to

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

.setMaterials (Array of materials : Material) : null

Array of materials - Array of Materials

Set materials loaded by MTLLoader or any other supplier of an Array of Materials.

.setUseIndices (useIndices : Boolean) : null

useIndices

Instructs loaders to create indexed BufferGeometry.

.setDisregardNormals (disregardNormals : Boolean) : null

disregardNormals

Tells whether normals should be completely disregarded and regenerated.

.setMaterialPerSmoothingGroup (materialPerSmoothingGroup : boolean) : null

materialPerSmoothingGroup

Tells whether a material shall be created per smoothing group.

.onProgress (type : String, text : String, numericalValue : Number) : null

type - The type of event
text - Textual description of the event
numericalValue - Numerical value describing the progress

Announce feedback which is give to the registered LoaderSupport.Callbacks.

.loadMtl (url : String, content : Object, callbackOnLoad : Function, crossOrigin : String, materialOptions : Object) : null

url - URL to the file
content - The file content as arraybuffer or text
onLoad - Callback to be called after successful load
onProgress - (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains total and loaded bytes.
onError - (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.
crossOrigin - (optional) CORS value
materialOptions - (optional) Set material loading options for MTLLoader

Utility method for loading an mtl file according resource description. Provide url or content.

Source

For more info on how to obtain the source code of this module see this page.