import type { Triplet } from '@pmndrs/cannon-worker-api' ;
import { extend , injectStore , NgtArgs , NgtCanvas , type NgtVector3 } from 'angular-three' ;
import { NgtcPhysics } from 'angular-three-cannon' ;
import { injectBox , injectPlane } from 'angular-three-cannon/body' ;
import { NgtcDebug } from 'angular-three-cannon/debug' ;
import type { Mesh } from 'three' ;
import * as THREE from 'three' ;
< ngt-mesh #mesh [receiveShadow] = "true" >
< ngt-plane-geometry *args = "[1000, 1000]" />
< ngt-shadow-material color = "#171717" [transparent] = "true" [opacity] = "0.4" />
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
changeDetection: ChangeDetectionStrategy . OnPush ,
meshRef = viewChild . required < ElementRef < Mesh >>( 'mesh' );
injectPlane (() => ({ rotation: [- Math . PI / 2 , 0 , 0 ], position: [ 0 , - 2.5 , 0 ] }), this . meshRef );
< ngt-mesh #mesh [receiveShadow] = "true" [castShadow] = "true" >
< ngt-mesh-lambert-material color = "hotpink" />
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
changeDetection: ChangeDetectionStrategy . OnPush ,
position = input < NgtVector3 >([ 0 , 5 , 0 ]);
meshRef = viewChild . required < ElementRef < Mesh >>( 'mesh' );
() => ({ mass: 1 , position: this . position () as Triplet , rotation: [ 0.4 , 0.2 , 0.5 ], args: [ 1 , 1 , 1 ] }),
< ngt-color attach = "background" *args = "['lightblue']" />
< ngt-directional-light [position] = "10" [castShadow] = "true" >
< ngt-vector2 *args = "[2048, 2048]" attach = "shadow.mapSize" />
< ngtc-physics [debug] = "{ enabled: true, color: 'red', scale: 1.1 }" >
@for ( position of cubePositions ; track $index ) {
< app-cube [position] = "position" />
imports: [ Plane , Cube , NgtArgs , NgtcPhysics , NgtcDebug ],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
changeDetection: ChangeDetectionStrategy . OnPush ,
export class SceneGraph {
cubePositions : Triplet [] = [
cubes = viewChildren ( Cube );
const store = injectStore ();
const cubes = this . cubes ();
if (! cubes . length ) return ;
const sub = store . snapshot . pointerMissed$ . subscribe (() => {
cubes . forEach (( cube , index ) => {
cube . boxApi ()?. position . set (... this . cubePositions [ index ]);
cube . boxApi ()?. rotation . set ( 0.4 , 0.2 , 0.5 );
onCleanup (() => sub . unsubscribe ());
[sceneGraph] = "sceneGraph"
[camera] = "{ position: [-1, 5, 5], fov: 45 }"
< span class = "absolute bottom-0 right-0 font-mono text-black" > * click to reset the cubes </ span >
changeDetection: ChangeDetectionStrategy . OnPush ,
host: { class: 'cannon-sample relative inline' },
export default class CannonSampleDebug {