The OBJ path
Read text geometry. Preserve the representation you need.
OBJ is human-readable and widely supported, but its records are not columnar. The loader resolves faces, materials, and attributes before exposing a renderer-friendly or Arrow-backed result.
Input
OBJ geometry with optional MTL materials
Records
Vertices, normals, UVs, colors, and faces
Output
Mesh object or Mesh Arrow table
Streaming
Batched vertex parsing for point clouds
Detailed guide
OBJ parsing and output details
The reference below covers output shapes, material and geometry records, batched parsing, and loader options.
OBJLoader parses the OBJ half of the classic Wavefront OBJ/MTL format and returns a Mesh Arrow table by default.
Set obj.shape: 'mesh' when a legacy Mesh object is required.
| Shape | Output | Use when |
|---|---|---|
arrow | Mesh Arrow table | You want columnar mesh attributes. |
mesh | Mesh | You need the legacy mesh object. |
Usage
import {OBJLoader} from '@loaders.gl/scene/obj';
import {load} from '@loaders.gl/core';
const data = await load(url, OBJLoader, options);
const table = await load(url, OBJLoader, {obj: {shape: 'arrow'}});
Batched Parsing
OBJLoader supports loadInBatches and parseInBatches for vertex-only OBJ point clouds. By default, the loader scans the OBJ text before batching; if f face records or l line records are present, it falls back to atomic parsing and yields one batch.
Set obj.pointCloud: true when the input is known to be a point cloud and should stream v vertex records without waiting for a whole-file geometry scan. With obj.shape: 'arrow', the loader yields native Apache Arrow RecordBatch objects. Their schema metadata carries cumulative bounds. Read the bounds for an individual batch from batch.metadata.get('boundingBox').
import {loadInBatches} from '@loaders.gl/core';
import {OBJLoader} from '@loaders.gl/scene/obj';
const batches = await loadInBatches(url, OBJLoader, {
batchSize: 100_000,
obj: {shape: 'arrow', pointCloud: true}
});
for await (const batch of batches) {
console.log(batch.length, batch.data);
}
Options
| Option | Type | Default | Description |
|---|---|---|---|
obj.shape | 'mesh' | 'arrow' | 'arrow' | Selects Mesh or Mesh Arrow table output. |
obj.pointCloud | boolean | false | Streams OBJ v records as point-cloud batches. Use only for known point-cloud OBJ inputs. |
Remarks:
- vertex colors are parsed as a
COLOR_0attribute when red, green and blue values are included after x y and z (this precludes specifying w). The color values range from 0 to 1.
Attribution
OBJLoader is a port of three.js's OBJLoader under MIT License.
Worker batches
OBJLoader supports parseInBatches() on its built-in browser worker. The worker stays
leased for the input iterator and transfers owned Arrow column buffers. The caller
hydrates Mesh Arrow tables and performs any requested legacy shape: 'mesh' conversion.
Schemas and small loader/batch descriptors accompany the binary buffers; decoded row objects
are not sent from the worker. JSON conversion, if needed by an application, happens on the caller.
const batches = await parseInBatches(input, OBJLoader, {
core: {worker: true, batchSize: 1000},
obj: {shape: 'arrow', pointCloud: true}
});
for await (const batch of batches) {
consume(batch.data);
}
With obj.pointCloud: true, vertex batches can arrive before input ends. General OBJ geometry is collected before parsing so faces can reference earlier vertices.
Cancellation uses the shared signal option. Aborting or ending iteration releases the worker;
transferred input buffers remain detached. Self-hosted workers must implement the batch protocol
and opt in with core.workerInBatches: true. Custom workers must use the current Arrow column wire format. This module ships a browser worker; Node workers require a compatible Node artifact.
The parser-bearing loader is available from @loaders.gl/scene/obj.