Threejs

From UCSB-NLP-Chang/Skill-Usage · View interactive version

Threejs is an AI agent skill from the GitHub repository UCSB-NLP-Chang/Skill-Usage. Three.js scene-graph parsing and export workflows for mesh baking, InstancedMesh expansion, part partitioning, per-link OBJ export, and URDF articulation.

How to use this skill

Skill file

Three.js Scene Graph + Export

Quick start

1) Load the module, call createScene(), then updateMatrixWorld(true).

2) Treat named THREE.Group nodes as parts/links.

3) Assign each mesh to its nearest named ancestor.

4) Bake world transforms into geometry before export.

5) Export per-part OBJ (and optionally URDF) using deterministic ordering.

Scene graph essentials

Object3D (root)
├── Group (part)
│   ├── Mesh
│   └── Group (child part)
│       └── Mesh
└── Group (another part)
    └── Mesh

Part partitioning rules

function buildPartMap(root) {
  const parts = new Map();
  root.traverse((obj) => {
    if (obj.isGroup && obj.name) parts.set(obj.name, { group: obj, meshes: [] });
  });
  root.traverse((obj) => {
    if (!obj.isMesh) return;
    let parent = obj.parent;
    while (parent && !(parent.isGroup && parent.name)) parent = parent.parent;
    if (parent && parts.has(parent.name)) parts.get(parent.name).meshes.push(obj);
  });
  return Array.from(parts.values()).filter((p) => p.meshes.length > 0);
}

Mesh baking (world transforms)

Always bake transforms before export:

root.updateMatrixWorld(true);
let geom = mesh.geometry.clone();
geom.applyMatrix4(mesh.matrixWorld);
if (geom.index) geom = geom.toNonIndexed();
if (!geom.attributes.normal) geom.computeVertexNormals();

InstancedMesh expansion

const tempMatrix = new THREE.Matrix4();
const instanceMatrix = new THREE.Matrix4();
obj.getMatrixAt(i, instanceMatrix);
tempMatrix.copy(obj.matrixWorld).multiply(instanceMatrix);

Axis conversion (Y-up to Z-up)

const axisMatrix = new THREE.Matrix4().makeRotationX(-Math.PI / 2);
geom.applyMatrix4(axisMatrix);

Per-part OBJ export

Reference: references/link-export-rules.md.

Relation between Three.js and URDF articulation

References:

Scripts

Adjust inputs/outputs inside scripts as needed.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.