Skip to main content

OBJ writer

Write common mesh data into a format every 3D tool knows.

OBJWriter accepts legacy Mesh objects and Mesh Arrow tables, then emits Wavefront OBJ text with the standard vertex attributes and faces that downstream tools expect.

The OBJ writing path

Start with common mesh data. Emit portable geometry text.

The writer normalizes the legacy and Arrow-backed mesh inputs at the boundary, then writes positions, optional attributes, and indexed or sequential triangle faces.

Input

Mesh or Mesh Arrow table

Attributes

Position, normal, UV, color, and custom scalars

Topology

Indexed or sequential triangle faces

Output

Wavefront OBJ text or encoded bytes

Detailed guide

OBJ output details

The reference below covers accepted mesh shapes, written attributes, face output, and encoding entry points.

From-v5.0Status: Experimental

The OBJWriter writes Mesh or Mesh Arrow table data as Wavefront OBJ text.

Usage​

import {encode} from '@loaders.gl/core';
import type {Mesh, MeshArrowTable} from '@loaders.gl/core/schema';
import {OBJWriter} from '@loaders.gl/scene/obj';

declare const mesh: Mesh | MeshArrowTable;

const arrayBuffer = await encode(mesh, OBJWriter);
const text = OBJWriter.encodeTextSync(mesh);

Data Format​

OBJWriter accepts Mesh Arrow tables and legacy Mesh objects. Legacy Mesh input is normalized through the Mesh Arrow table conversion path before OBJ text is encoded.

The writer requires a POSITION attribute. It writes NORMAL, TEXCOORD_0, and COLOR_0 attributes when present. Indexed meshes are written as OBJ faces; non-indexed triangle-list meshes are written as sequential triangle faces.

Options​

OBJWriter does not currently define format-specific options.