angular-three-cannon/body

December 31, 2025 ยท View on GitHub

This module provides functions to create physics bodies that link ngt-* objects in THREE.js with bodies in the Cannon.js physics world. These functions simplify the process of adding physics behavior to your 3D objects.

Available Body Functions

FunctionDescriptionargs Argumentsobject Type
boxCreates a box-shaped physics body.[width, height, depth]ElementRef
convexPolyhedronCreates a convex polyhedron-shaped physics body.[vertices, faces]ElementRef
cylinderCreates a cylinder-shaped physics body.[radiusTop, radiusBottom, height, numSegments]ElementRef
heightfieldCreates a heightfield-shaped physics body.[data, { elementSize }]ElementRef
particleCreates a particle physics body.(none)ElementRef
planeCreates a plane-shaped physics body.(none)ElementRef
sphereCreates a sphere-shaped physics body.[radius]ElementRef
trimeshCreates a trimesh-shaped physics body.[vertices, indices]ElementRef
compoundCreates a compound physics body.(uses shapes property instead)ElementRef

All functions also accept an optional options argument for additional customization.

Simple Usage of box()

import { Component, viewChild, ElementRef } from '@angular/core';
import { Mesh } from 'three';
import { NgtcPhysics } from 'angular-three-cannon';
import { box } from 'angular-three-cannon/body';

@Component({
	template: `
		<ngt-mesh #mesh>
			<ngt-box-geometry />
		</ngt-mesh>
	`,
})
export class Box {
	mesh = viewChild.required<ElementRef<Mesh>>('mesh');

	constructor() {
		// Make this mesh a Box body in Physics. Only works within ngtc-physics
		box(() => ({ mass: 10000, position: [0, 0, 0], args: [1, 1, 1] }), this.mesh);
	}
}

@Component({
	template: `
		<ngtc-physics>
			<app-box />
		</ngtc-physics>
	`,
	imports: [NgtcPhysics, Box],
})
export class SceneGraph {}

Deprecated Functions

The following inject* functions are deprecated and will be removed in v5.0.0. Use the new function names instead:

DeprecatedUse Instead
injectBoxbox
injectConvexPolyhedronconvexPolyhedron
injectCylindercylinder
injectHeightfieldheightfield
injectParticleparticle
injectPlaneplane
injectSpheresphere
injectTrimeshtrimesh
injectCompoundcompound