npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

three-urdf

v0.1.1

Published

URDF parser and Three.js scene builder with joint controls

Downloads

365

Readme

three-urdf

A lightweight TypeScript library for parsing URDF files and rendering interactive Three.js robot models.

Features

  • Parse URDF XML into strongly-typed TypeScript objects
  • Build Three.js Object3D hierarchies with proper kinematic chains
  • Load STL meshes with correct transforms and materials
  • Control joint angles programmatically
  • Automatic Z-up to Y-up coordinate conversion
  • Debug visualization mode (spheres and lines)

Installation

npm install three-urdf three

three is a peer dependency - you need to install it separately.

Quick Start

Basic Usage

import { parseURDF, loadRobot } from 'three-urdf';

// fetch and parse the URDF
const response = await fetch('/models/robot.urdf');
const urdfText = await response.text();

const robotModel = parseURDF(urdfText, {
  packageMap: {
    // map ROS package names to actual paths
    'my_robot_description': '/models/my_robot',
  },
});

// build the Three.js object with meshes
const robot = await loadRobot(robotModel);

// add to your scene
scene.add(robot);

Controlling Joints

// set individual joint
const joint = robot.joints.get('shoulder_pan_joint');
joint?.setJointValue(Math.PI / 4); // radians

// set multiple joints at once
robot.setJointValues({
  shoulder_pan_joint: 0.5,
  shoulder_lift_joint: -0.3,
  elbow_joint: 1.2,
});

Debug Visualization

Use buildRobot for a lightweight debug view without loading meshes:

import { parseURDF, buildRobot } from 'three-urdf';

const robotModel = parseURDF(urdfText);
const robot = buildRobot(robotModel, {
  jointRadius: 0.03,    // size of joint spheres
  jointColor: 0xff0000, // red
  linkColor: 0x00ff00,  // green lines
});

React Three Fiber Example

import { useEffect, useState } from 'react';
import { Canvas } from '@react-three/fiber';
import { OrbitControls } from '@react-three/drei';
import { parseURDF, loadRobot } from 'three-urdf';
import type { URDFRobot } from 'three-urdf';

function Robot() {
  const [robot, setRobot] = useState<URDFRobot | null>(null);

  useEffect(() => {
    async function load() {
      const res = await fetch('/models/robot.urdf');
      const urdf = await res.text();
      const model = parseURDF(urdf, {
        packageMap: { robot_description: '/models' },
      });
      const obj = await loadRobot(model);
      setRobot(obj);
    }
    load();
  }, []);

  if (!robot) return null;
  return <primitive object={robot} />;
}

export default function App() {
  return (
    <Canvas camera={{ position: [2, 2, 2] }}>
      <ambientLight intensity={0.5} />
      <directionalLight position={[5, 5, 5]} />
      <Robot />
      <OrbitControls />
    </Canvas>
  );
}

API Reference

parseURDF(urdfString, options?)

Parse a URDF XML string into a RobotModel object.

Options:

  • packageMap?: Record<string, string> - Map ROS package names to URL paths

Returns: RobotModel with links, joints, and materials

buildRobot(model, options?)

Build a Three.js Object3D hierarchy with debug visualization (no mesh loading).

Options:

  • jointRadius?: number - Radius of joint spheres (default: 0.02)
  • jointColor?: number - Color of joint spheres (default: 0xff0000)
  • linkColor?: number - Color of link lines (default: 0x00ff00)
  • convertToYUp?: boolean - Convert Z-up to Y-up (default: true)
  • showDebug?: boolean - Show debug visualization (default: true)

Returns: URDFRobot

loadRobot(model, options?)

Build a Three.js Object3D hierarchy and load STL meshes.

Options: Same as buildRobot, plus:

  • showDebug?: boolean - Show debug visualization (default: false)

Returns: Promise<URDFRobot>

URDFRobot

The root robot object extending THREE.Group:

interface URDFRobot extends Group {
  joints: Map<string, URDFJoint>;
  links: Map<string, Object3D>;
  setJointValues: (values: Record<string, number>) => void;
}

URDFJoint

Joint object extending THREE.Object3D:

interface URDFJoint extends Object3D {
  jointType: 'revolute' | 'continuous' | 'prismatic' | 'fixed' | 'floating' | 'planar';
  axis: Vector3;
  jointName: string;
  limits?: { lower?: number; upper?: number };
  jointValue: number;
  setJointValue: (value: number) => void;
}

Coordinate Systems

URDF uses Z-up coordinates while Three.js uses Y-up. By default, loadRobot and buildRobot apply a -90° rotation around X to convert coordinates. Disable with convertToYUp: false.

URDF Euler Angles

URDF specifies rotations as RPY (roll-pitch-yaw) using extrinsic XYZ order ("fixed axis"). This is equivalent to intrinsic ZYX in Three.js Euler angles.

Supported URDF Features

  • Links with visual and collision geometry
  • Joints: revolute, continuous, prismatic, fixed
  • Joint limits (upper/lower bounds)
  • Materials with colors
  • STL mesh loading
  • Package path resolution

Development

# install dependencies
npm install

# run tests
npm test

# build library
npm run build

# run demo
cd demo && npm install && npm run dev

License

MIT