UNPKG

@vladkrutenyuk/cannon-es-debugger-pro

Version:

This is improved pro debugger for 'cannon-es' with 'three' to visualize all bodies and its shapes of physics world.

137 lines (135 loc) 6.08 kB
import * as CANNON from "cannon-es"; import * as THREE from "three"; export type CannonEsDebuggerProEventMap = { init: { body: CANNON.Body; obj3d: THREE.Object3D; shape: CANNON.Shape; }; update: { body: CANNON.Body; obj3d: THREE.Object3D; shape: CANNON.Shape; }; }; /** * {@link CannonEsDebuggerPro} is improved and reworked pro debugger for {@link https://github.com/pmndrs/cannon-es | cannon-es} * using {@link https://github.com/mrdoob/three.js | three.js} to visualize all bodies and its shapes of physics world. * @see {@link https://github.com/vladkrutenyuk/cannon-es-debugger-pro | Source} * @see {@link https://npmjs.com/@vladkrutenyuk/cannon-es-debugger-pro | The page of npm package} * @example * ```typescript * import * as THREE from 'three' * import * as CANNON from 'cannon-es' * import { CannonEsDebuggerPro } from '@vladkrutenyuk/cannon-es-debugger-pro' * * const world = new CANNON.World() * const scene = new THREE.Scene() * * const root = new THREE.Group() // or any another THREE.Object3D like * scene.add(root) * * const cannonDebugger = new CannonEsDebuggerPro(root, world, 0xe60c0c, 0.01) * ``` */ export class CannonEsDebuggerPro extends THREE.EventDispatcher<CannonEsDebuggerProEventMap> { /** * Flag to check instance's visibility. Read-only. Default is `true` * * Use method {@link CannonEsDebuggerPro.setVisible | setVisible()} to change it. * @readonly * @default true */ get isVisible(): boolean; /** * Flag to check if instance was destroyed. Read-only. Default is `false`. * * Use method {@link CannonEsDebuggerPro.destroy | destroy()} to destroy instance. * @readonly * @default false */ get isDestroyed(): boolean; /** * Current lines color of debug graphics objects. Read-only. Default is `0x00ff00` (green). * * Use method {@link CannonEsDebuggerPro.setColor | setColor()} to change it. * @readonly * @default 0x00ff00 */ get color(): THREE.ColorRepresentation; /** * Current value in meters to push up geometries vertices along its normals of debug graphics objects. * Read-only. Default is 0.005. * * Use method {@link CannonEsDebuggerPro.setOffset | setOffset()} to change it. * @readonly * @default 0.005 */ get offset(): number; /** * Create a new instance of {@link CannonEsDebuggerPro} * This is improved pro debugger for [cannon-es](https://github.com/pmndrs/cannon-es) * with [three](https://github.com/pmndrs/cannon-es) to visualize all bodies and its shapes of physics world. * @param {THREE.Object3D} root Root which is any implementation of {@link THREE.Object3D} to be parent container of debug graphic objects for this instance. * @param {CANNON.World} world Instance of {@link CANNON.World} you need to debug. * @param {THREE.ColorRepresentation} color (optional) Sets the lines color for debug graphic objects. * Expects a {@link THREE.ColorRepresentation}. Default is `0x00ff00` (green). * @param {number} offset (optional) Value in meters to push up geometries vertices along its normals of debug graphics objects * to prevent overlapping with source scene objects. Float value with recommended range of hundredths `~0.01` or thousandths `~0.001`. Expects a `Float`. Default is `0.005`. */ constructor(root: THREE.Object3D, world: CANNON.World, color?: THREE.ColorRepresentation, offset?: number); /** * The {@link CannonEsDebuggerPro.update | update()} method needs to be called * after `cannon` physics world's step * and before `three.js` render to update its state. * @example * ```typescript * const animate = () => { * requestAnimationFrame(animate) * * world.step(timeStep) // Update cannon-es physics * cannonDebugger.update() // Update the CannonEsDebuggerPro * renderer.render(scene, camera) // Render the three.js scene * } * animate()§ * ``` * @remarks It won't work after {@link CannonEsDebuggerPro.destroy | destroy()}. */ update(): void; /** * Set lines color of debug graphic objects. * * Use read-only {@link CannonEsDebuggerPro.color | color} property to know current value. * @param {THREE.ColorRepresentation} color */ setColor(color: THREE.ColorRepresentation): this; /** * Set visibility of debug graphic objects. It doesn't remove and dispose anything. * * Use read-only {@link CannonEsDebuggerPro.isVisible | isVisible} property to know current value. * @param {boolean} isVisible */ setVisible(isVisible: boolean): this; /** * Set value in meters to push up geometries vertices along its normals of debug graphics objects. * * Use read-only {@link CannonEsDebuggerPro.offset | offset} property to know current value. * @param {number} offset Float value with recommended range of hundredths `~0.01` or thousandths `~0.001`. */ setOffset(offset: number): this; /** * Removes all debug 3d objects and does `dispose` for all created geometries * of complex shapes. Shared materials won't be disposed and the {@link CannonEsDebuggerPro.update | update()} method will be still working. * You are able to continue using this instance after calling the method. * If you want to destroy instance fully not to use it anymore then use {@link CannonEsDebuggerPro.destroy | destroy()}. */ clear(): void; /** * The method is called to remove all created debug 3d objects and * dispose all created geometries for complex shapes and shared materials of this instance. * After calling {@link CannonEsDebuggerPro.destroy | destroy()} the method {@link CannonEsDebuggerPro.update | update()} won't work anymore * and property {@link CannonEsDebuggerPro.isDestroyed | isDestroyed} will become `true`. */ destroy(): void; } //# sourceMappingURL=types.d.ts.map