JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28870
  • Score
    100M100P100Q164572F
  • License MIT

Wireframe debugger for use with cannon-es https://github.com/react-spring/cannon-es

Package Exports

  • cannon-es-debugger

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cannon-es-debugger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Demo Image

This is a debugger for use with cannon-es. It was adapted from the original cannon.js debugger written by Stefan Hedman @schteppe.

Note: This debugger currently does not work with use-cannon.

Usage

Give cannon-es-debugger references to your Three scene object and Cannon physics bodies:

import { Scene } from 'three'
import { World } from 'cannon-es'
import debug from 'cannon-es-debugger'

const scene = new Scene()
const world = new World()
debug(scene, world.bodies, options)

New meshes with wireframe textures will be generated from your physics body geometries and added into the scene. A mesh will be created for every shape in the physics body. The position of the meshes will be synched with the Cannon physics body simulation on every animation frame.

API

The available properties of the options object are listed below.

import type { Scene, Color } from 'three'
import type { Body } from 'cannon-es'

type DebugOptions = {
  color?: string | number | Color,
  onInit?: (body: Body, mesh: Mesh, shape: Shape) => void,
  onUpdate?: (body: Body, mesh: Mesh, shape: Shape) => void,
}

export default function renderWireframes (scene: Scene, bodies: Body[], options: DebugOptions): void
  • color - a Three Color argument that sets the wireframe color, defaults to 0x00ff00

  • onInit - callback function that runs once, right after a new wireframe mesh is added

  • onUpdate - callback function that runs on every subsequent animation frame