home / skills / benchflow-ai / skillsbench / obj-exporter

This skill exports Three.js scenes and geometries to Wavefront OBJ format, enabling seamless transfer to Blender, Maya, or MeshLab.

npx playbooks add skill benchflow-ai/skillsbench --skill obj-exporter

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.0 KB
---
name: obj-exporter
description: Three.js OBJExporter utility for exporting 3D geometry to Wavefront OBJ format. Use when converting Three.js scenes, meshes, or geometries to OBJ files for use in other 3D software like Blender, Maya, or MeshLab.
---

# OBJExporter Guide

## Basic Structure

OBJ is a text-based 3D geometry format:

```
# Comment
v x y z        # Vertex position
vn x y z       # Vertex normal
f v1 v2 v3     # Face (triangle)
f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3  # Face with texture/normal indices
```

Example:
```
# Cube
v 0 0 0
v 1 0 0
v 1 1 0
v 0 1 0
f 1 2 3
f 1 3 4
```

## Three.js OBJExporter

Three.js provides `OBJExporter` in examples:

```javascript
import { OBJExporter } from 'three/examples/jsm/exporters/OBJExporter.js';

const exporter = new OBJExporter();
const objString = exporter.parse(object3D);

// Write to file (Node.js)
import fs from 'fs';
fs.writeFileSync('output.obj', objString);
```

## Exporting with World Transforms

To export geometry in world coordinates:

```javascript
// Update world matrices first
root.updateMatrixWorld(true);

// Clone and transform geometry
const worldGeometry = mesh.geometry.clone();
worldGeometry.applyMatrix4(mesh.matrixWorld);

// Create new mesh for export
const exportMesh = new THREE.Mesh(worldGeometry);
const objData = exporter.parse(exportMesh);
```

## Merging Multiple Geometries

```javascript
import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js';

const geometries = [];
root.traverse((obj) => {
  if (obj instanceof THREE.Mesh) {
    const geom = obj.geometry.clone();
    geom.applyMatrix4(obj.matrixWorld);
    geometries.push(geom);
  }
});

const merged = mergeGeometries(geometries);
const mergedMesh = new THREE.Mesh(merged);
const objData = exporter.parse(mergedMesh);
```

## Node.js ES Module Setup

For running Three.js in Node.js:

```json
// package.json
{ "type": "module" }
```

```javascript
// script.js
import * as THREE from 'three';
import { OBJExporter } from 'three/examples/jsm/exporters/OBJExporter.js';
```

Overview

This skill provides a Three.js OBJExporter utility for converting Three.js scenes, meshes, or geometries into Wavefront OBJ text files. It produces standard OBJ output containing vertex positions, normals, and face indices so models can be imported into Blender, Maya, MeshLab, or other 3D tools. The exporter supports exporting individual objects, world-transformed geometry, and merged geometries for streamlined workflows.

How this skill works

The exporter traverses a Three.js Object3D (or accepts a single Mesh) and generates an OBJ-format string with lines for vertices (v), normals (vn), and faces (f). To preserve world-space placement, updateMatrixWorld and apply each mesh's matrixWorld to its geometry before parsing. Multiple geometries can be merged into a single BufferGeometry prior to export to reduce file complexity and preserve topology.

When to use it

  • You need to move models from a Three.js scene into DCC apps like Blender or Maya.
  • You want a human-readable OBJ text file for debugging geometry or sharing with others.
  • You need a single merged mesh exported from multiple scene meshes.
  • You must export geometries with their world transforms applied for correct placement.

Best practices

  • Call root.updateMatrixWorld(true) before transforming or exporting to ensure correct world matrices.
  • Clone geometries before applying transforms to avoid mutating the original scene data.
  • Merge geometries with BufferGeometryUtils.mergeGeometries when exporting many small meshes.
  • Set package.json type to 'module' when running Three.js exporters in Node.js ES module environments.
  • Validate exported OBJ in the target application and include normals if smooth shading is required.

Example use cases

  • Export a single mesh: clone the mesh geometry, apply matrixWorld, then exporter.parse to get OBJ string.
  • Export an entire scene: traverse the scene, collect transformed geometries, merge them, and export a single OBJ file.
  • Prepare assets for photogrammetry post-processing by exporting cleaned, world-aligned geometry.
  • Automate server-side exports in Node.js by writing the exporter.parse result to a file with fs.writeFileSync.

FAQ

Does the exporter include textures or material references?

OBJExporter writes geometry, normals, and faces. It does not embed textures; you must export/use companion MTL files or reassign materials in the target application.

How do I ensure the exported model has correct world position and orientation?

Call updateMatrixWorld(true) on the scene root and apply each mesh's matrixWorld to a cloned geometry before parsing or merging.