Skip to main content

PLY loader

Read a classic mesh file into the shape your renderer needs.

PLYLoader parses Polygon File Format files and can return either the legacy Mesh object or a Mesh Arrow table. Choose the output shape at the boundary so downstream geometry code can stay consistent.

The PLY path

Parse vertices and faces. Select a legacy or columnar result.

PLY is a flexible mesh container. loaders.gl keeps the parser focused on its records while letting applications choose the representation that best fits existing rendering or columnar pipelines.

Input

ASCII or binary PLY mesh data

Records

Vertices, faces, normals, colors, and UVs

Output

Mesh object or Mesh Arrow table

Streaming

Batched parsing for Arrow table output

Detailed guide

PLY parsing and output details

The reference below covers output shapes, attributes, batched parsing, and loader options.

From-v1.0

PLYLoader parses simple meshes in the Polygon File Format or the Stanford Triangle Format and returns a Mesh Arrow table by default.

Set ply.shape: 'mesh' to return the legacy Mesh object.

ShapeOutputUse when
meshMeshYou want the legacy mesh object.
arrowMesh Arrow tableYou want columnar mesh attributes.

Usage​

import {PLYLoader} from '@loaders.gl/pointclouds/ply';
import {load} from '@loaders.gl/core';

const data = await load(url, PLYLoader, options);
const table = await load(url, PLYLoader, {ply: {shape: 'arrow'}});

Batched Parsing​

PLYLoader supports loadInBatches and parseInBatches. When ply.shape: 'arrow' is set, 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 {PLYLoader} from '@loaders.gl/pointclouds/ply';

const batches = await loadInBatches(url, PLYLoader, {
ply: {shape: 'arrow'}
});

for await (const batch of batches) {
console.log(batch.length, batch.data);
}

Options​

OptionTypeDefaultDescription
ply.shape'mesh' | 'arrow''arrow'Selects Mesh Arrow table or legacy Mesh output.

Worker batches​

PLYLoader 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. loaderData on Arrow batches retains the parsed source header, including comments and elements. Its element counts describe the source; use batch.length for the current batch row count. 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, PLYLoader, {
core: {worker: true, batchSize: 1000},
ply: {shape: 'arrow', pointCloud: true}
});
for await (const batch of batches) {
consume(batch.data);
}

Use ply.pointCloud: true for incremental vertex batches in ASCII and binary PLY. General meshes may require the remaining elements before they can be returned.

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/pointclouds/ply.