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

@likang233/mujoco-viewer

v0.1.0

Published

Framework-agnostic TypeScript MuJoCo/MJCF viewer for browsers.

Readme

@likang233/mujoco-viewer

Framework-agnostic TypeScript MuJoCo/MJCF viewer for browsers. It uses the official @mujoco/mujoco WASM runtime and renders the compiled model with Three.js.

This package does not depend on Vue, Element Plus, React, or any UI framework.

Install

npm install @likang233/mujoco-viewer

@mujoco/mujoco and three are regular dependencies, so the package works without extra peer dependency setup. The default loader serves the bundled single-threaded mujoco.wasm from dist/assets/mujoco.wasm.

Quick Start

import { MujocoThreeViewer, type MujocoBundle } from '@likang233/mujoco-viewer'

const host = document.querySelector<HTMLDivElement>('#viewer')
if (!host) throw new Error('Missing viewer host')

const bundle: MujocoBundle = {
  mjcf: `
<mujoco model="minimal">
  <option timestep="0.01"/>
  <worldbody>
    <light pos="0 0 2"/>
    <body name="box" pos="0 0 0.2">
      <joint name="hinge" type="hinge" axis="0 1 0" range="-1.57 1.57"/>
      <geom type="box" size="0.1 0.1 0.1" rgba="0.45 0.7 1 1"/>
    </body>
  </worldbody>
  <actuator>
    <position name="hinge_act" joint="hinge" kp="20"/>
  </actuator>
</mujoco>`,
}

const viewer = new MujocoThreeViewer({ autoRun: true })
viewer.mount(host)

const runtime = await viewer.loadBundle(bundle)
const unsubscribe = runtime.subscribe((snapshot) => {
  console.log(snapshot.timeSeconds)
})

window.addEventListener('beforeunload', () => {
  unsubscribe()
  viewer.dispose()
})

mount() appends the canvas, starts the render loop, binds pointer/wheel/double-click/context-menu events, and observes host resize. Call dispose() to clean up all event listeners, the MuJoCo runtime, and Three.js resources.

Loading a Folder

Use buildMujocoBundleFromFiles() when users upload a directory containing .mjcf / MuJoCo XML and mesh or texture resources.

import { buildMujocoBundleFromFiles, MujocoThreeViewer, type MujocoFileEntry } from '@likang233/mujoco-viewer'

const entries: MujocoFileEntry[] = Array.from(input.files ?? []).map((file) => ({
  path: file.webkitRelativePath || file.name,
  file,
}))

const bundle = await buildMujocoBundleFromFiles(entries)
const viewer = new MujocoThreeViewer()
viewer.mount(document.querySelector('#viewer')!)
await viewer.loadBundle(bundle)

The asset resolver follows include, compiler assetdir, meshdir, texturedir, mesh file, texture file, and six-file cube texture references. It writes referenced resources into MuJoCo's VFS using stable virtual paths.

Controls

The runtime exposes descriptors for UI controls. Frameworks can render these however they like.

const runtime = await viewer.loadBundle(bundle)

for (const control of runtime.getControlDescriptors()) {
  console.log(control.id, control.label, control.range)
}

runtime.setRunState('running')
runtime.setControlValue('joint:0', 0.3)
viewer.setVisualizerOption('contact-point', true)

For UI state projection, use MujocoRuntimeFacade.

import { MujocoRuntimeFacade } from '@likang233/mujoco-viewer'

const facade = new MujocoRuntimeFacade()
facade.attachRuntime(runtime)
const unsubscribe = facade.subscribe((state) => {
  renderControls(state.jointItems, state.actuatorItems, state.viewerOptionItems)
})

React

React does not need a special adapter:

import { useEffect, useRef } from 'react'
import { MujocoThreeViewer, type MujocoBundle } from '@likang233/mujoco-viewer'

export function MujocoCanvas({ bundle }: { bundle: MujocoBundle }) {
  const hostRef = useRef<HTMLDivElement>(null)

  useEffect(() => {
    if (!hostRef.current) return
    const viewer = new MujocoThreeViewer({ autoRun: true })
    viewer.mount(hostRef.current)
    void viewer.loadBundle(bundle)
    return () => viewer.dispose()
  }, [bundle])

  return <div ref={hostRef} style={{ width: '100%', height: '100%' }} />
}

See examples/react-vite for a working app.

To run an example locally:

npm --prefix examples/vanilla-vite install
npm --prefix examples/vanilla-vite run dev

Examples

  • examples/vanilla-vite: plain TypeScript + Vite app with upload, run/pause/step/reset, sliders, and viewer options.
  • examples/react-vite: React + Vite app proving the package has no Vue or Element Plus dependency.
  • examples/assets: small MJCF assets used by the examples.

API Documentation

Browser Support

This is a browser package. It requires DOM, WebGL, ResizeObserver, File/Blob for upload helpers, and modern ESM bundler support.

License

MIT