# How the Mesh Exporter Node Handles GLB Export in Modly

> Discover how the Modly Mesh Exporter node efficiently handles GLB export using glTF-Transform, preserving extensions and binary data without conversion. Learn the process now.

- Repository: [lightningpixel/modly](https://github.com/lightningpixel/modly)
- Tags: internals
- Published: 2026-08-20

---

**The Mesh Exporter node handles GLB export by leveraging glTF-Transform's `NodeIO` to read the source mesh and write it directly as a binary GLB file, preserving all extensions and binary data without geometry conversion.**

In the `lightningpixel/modly` repository, the **mesh exporter node GLB export** functionality provides a streamlined pathway for converting 3D assets into the binary glTF format. Unlike other export formats that require manual geometry extraction, the GLB pathway operates as a thin wrapper around the glTF-Transform library. This implementation ensures maximum fidelity for complex scenes while handling input validation, pipeline configuration, and progress reporting through a dedicated processor module.

## GLB Export Pipeline Overview

The Mesh Exporter workflow node converts input meshes into multiple 3D formats, with GLB receiving optimized treatment. When configured for **GLB** export, the node bypasses geometry conversion logic used for STL, OBJ, or PLY formats. Instead, it utilizes the `@gltf-transform/core` library to perform a direct binary serialization of the loaded glTF document.

## Step-by-Step GLB Export Process

### Input Validation

The export process begins with strict validation of required parameters. The node checks for `input.filePath`, which specifies the source mesh location, and throws an error immediately if this value is missing. This validation occurs early in the execution flow to prevent unnecessary processing of invalid requests.

According to the source code in [`src/areas/workflows/nodes/mesh-exporter/processor.ts`](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-exporter/processor.ts) at line 86, the processor verifies the file path existence before proceeding to format detection.

### Format Resolution

Once validation passes, the node reads the `export_format` parameter, which defaults to **glb** when not explicitly specified. The processor matches this value against an internal map of supported extensions to determine the appropriate export strategy. This branching logic ensures that GLB exports follow the optimized pathway while other formats trigger geometry extraction routines.

The format lookup logic is implemented at lines 88-92 in [`processor.ts`](https://github.com/lightningpixel/modly/blob/main/processor.ts).

### GLTF-Transform Pipeline Setup

For GLB exports, the node initializes a glTF-Transform pipeline using the `NodeIO` class from `@gltf-transform/core`. The instantiation occurs with all standard extensions registered via the `ALL_EXTENSIONS` constant, enabling full support for the complete glTF feature set including materials, animations, and binary buffers.

This setup is found at lines 96-99 in [`src/areas/workflows/nodes/mesh-exporter/processor.ts`](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-exporter/processor.ts), where the processor creates the IO instance capable of reading and writing the full glTF specification.

### Document Loading and Path Preparation

The processor loads the source mesh file—whether GLB, GLTF, or other supported formats—into a `Document` object representing the complete scene graph. Concurrently, the node prepares the output destination: if the user provides an `output_path`, the exporter creates that directory structure; otherwise, it falls back to a workspace-wide `Exports` folder.

The file reading operation occurs at line 200, while output path handling spans lines 103-111 in [`processor.ts`](https://github.com/lightningpixel/modly/blob/main/processor.ts).

### Binary GLB Serialization

Because the requested format is GLB, the node skips the geometry extraction phase required for other formats. Instead, it writes the loaded `Document` directly to disk using `io.write`, producing a binary GLB file that preserves the original mesh's extensions, materials, and binary data.

This direct write operation is implemented at lines 16-18 in [`src/areas/workflows/nodes/mesh-exporter/processor.ts`](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-exporter/processor.ts), representing the final step in the export pipeline.

### Progress Reporting

Throughout the export process, the node fires progress callbacks to update the UI or calling process. The workflow reports 20% during loading, 50% during export preparation, and 100% upon completion, returning the final file path to the caller.

## Implementation Examples

### Minimal Workflow Configuration

The following JSON configuration triggers a GLB export using the Mesh Exporter node:

```json
{
  "nodes": [
    {
      "id": "mesh-exporter",
      "type": "process",
      "params": {
        "export_format": "glb",
        "output_path": ""
      },
      "input": {
        "filePath": "/workspace/models/myModel.glb"
      }
    }
  ]
}

```

When `output_path` remains empty, the node automatically uses the workspace's `Exports` folder as the destination.

### Programmatic Node Execution

For TypeScript applications integrating with Modly's workflow engine:

```typescript
import { runNode } from '@modly/workflows'
import type { ProcessContext } from '@modly/types'

const ctx: ProcessContext = {
  workspaceDir: '/home/user/modly-workspace',
  tempDir: '/tmp/modly',
  log: console.log,
  progress: (pct, label) => console.log(`${pct}% – ${label}`)
}

await runNode('mesh-exporter', {
  filePath: '/workspace/models/input.glb',
}, { export_format: 'glb', output_path: '' }, ctx)

```

This pattern provides full control over logging and progress tracking while executing the export operation.

### Electron IPC Integration

The Electron main process exposes the `model:export` channel for UI-triggered exports:

```typescript
// Renderer process
window.ipc.invoke('model:export', { 
  outputUrl: '/workspace/models/input.glb', 
  format: 'glb' 
})

```

This IPC handler forwards requests to the backend `mesh-exporter` node, presenting a save dialog via the main process handler defined in [`electron/main/ipc-handlers.ts`](https://github.com/lightningpixel/modly/blob/main/electron/main/ipc-handlers.ts) at lines 599-624.

## Key Source Files

Three critical files define the mesh exporter node's GLB functionality:

- **[`src/areas/workflows/nodes/mesh-exporter/processor.ts`](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-exporter/processor.ts)**: Contains the core implementation including input validation, GLTF-Transform pipeline setup, and the GLB write operation.
- **[`src/areas/workflows/nodes/mesh-exporter/manifest.json`](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-exporter/manifest.json)**: Declares node parameters including `export_format` and `output_path`, identifying [`processor.js`](https://github.com/lightningpixel/modly/blob/main/processor.js) as the entry point.
- **[`electron/main/ipc-handlers.ts`](https://github.com/lightningpixel/modly/blob/main/electron/main/ipc-handlers.ts)**: Provides the Electron IPC handler `model:export` (lines 599-624) that bridges UI requests to the backend exporter.

## Summary

- The **mesh exporter node GLB export** pathway uses glTF-Transform's `NodeIO` for direct binary serialization without geometry conversion.
- Input validation requires `input.filePath` and throws immediately if missing (`processor.ts:86`).
- The GLB format bypasses manual geometry extraction, utilizing `io.write` to preserve original extensions and binary data (`processor.ts:16-18`).
- Output directories are created dynamically based on user-supplied `output_path` or default to a workspace `Exports` folder (`processor.ts:103-111`).
- Progress reporting occurs at 20%, 50%, and 100% completion intervals during the export workflow.

## Frequently Asked Questions

### What library handles the actual GLB serialization in the mesh exporter node?

The node uses **glTF-Transform** (`@gltf-transform/core`) to handle GLB serialization. Specifically, it instantiates the `NodeIO` class with `ALL_EXTENSIONS` registered, then calls `io.write` to serialize the `Document` object directly to binary GLB format. This approach preserves all glTF extensions and binary data without intermediate geometry conversion.

### Does the GLB export pathway convert or modify the mesh geometry?

No. Unlike the STL, OBJ, or PLY export pathways, the GLB export does not perform geometry extraction or conversion. As implemented in [`src/areas/workflows/nodes/mesh-exporter/processor.ts`](https://github.com/lightningpixel/modly/blob/main/src/areas/workflows/nodes/mesh-exporter/processor.ts), the node loads the source file into a glTF-Transform `Document` and writes it directly to disk, maintaining the original mesh structure, materials, and extensions.

### How does the node determine the output location for GLB files?

The node checks the `output_path` parameter first. If provided, it creates that directory structure using filesystem utilities. If the parameter is empty or omitted, the exporter falls back to a default `Exports` folder within the current workspace directory. This logic is implemented at lines 103-111 in [`processor.ts`](https://github.com/lightningpixel/modly/blob/main/processor.ts).

### Can the mesh exporter node handle GLB files as input as well as output?

Yes. The GLTF-Transform `NodeIO` instance configured with `ALL_EXTENSIONS` can read various glTF formats including GLB, GLTF, and related binary containers. The processor loads these into a `Document` object at line 200 of [`processor.ts`](https://github.com/lightningpixel/modly/blob/main/processor.ts), making the node capable of processing existing GLB files for re-export or format conversion to other supported types.