fileFormats.importObj

Polygon geometry from an OBJ file’s vertices and faces, quads and n-gons kept, in metres and the kernel’s frame, with ids in file order.

GeometricSince 0.18.0

Usage

TypeScript
FileFormats.importObj(file: Uint8Array, options?: FileImportOptions): Result<FileImport>

Parameters

  • fileUint8Array

    The OBJ file; text is read as bytes and only numbers must be UTF-8.

    Required

  • options.scopestring

    The importing node’s id; ids are minted under it. Default undefined (index ids, minter 0).

  • options.sourceUnit'mm' | 'cm' | 'm' | 'in' | 'ft'

    The file’s unit. Default 'mm'. One of mm, cm, m, in, ft.

  • options.sourceUp'y' | 'z'

    The file’s up axis. Default 'z'. One of y, z.

Returns

Ok with a FileImport, as importStl. Points are every v line, used or not; vertex uv and N (Float32) when every face gives vt and vn at every corner.

Errors

Guarantees

  • the faces keep the file’s corner counts and order
  • the same bytes and options give the same transport and ref on every target
  • The same result on every machine.

Example

TypeScript
const r = FileFormats.importObj(new TextEncoder().encode('v 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n'))
r.ok || r.diagnostics[0].code // → 3 points and 1 face once loadKernelIo() has run

See also