11import { NgIf } from '@angular/common' ;
2- import { CUSTOM_ELEMENTS_SCHEMA , Component , computed , signal } from '@angular/core' ;
2+ import { CUSTOM_ELEMENTS_SCHEMA , Component , Input , computed , signal } from '@angular/core' ;
3+ import { Triplet } from '@pmndrs/cannon-worker-api' ;
34import { NgtArgs , NgtCanvas , extend } from 'angular-three' ;
5+ import { NgtcPhysics } from 'angular-three-cannon' ;
6+ import { NgtcDebug } from 'angular-three-cannon/debug' ;
7+ import { injectBox , injectPlane } from 'angular-three-cannon/services' ;
48import { NgtpBloom , NgtpEffectComposer } from 'angular-three-postprocessing' ;
59import { NgtsGrid } from 'angular-three-soba/abstractions' ;
610import { NgtsOrbitControls } from 'angular-three-soba/controls' ;
@@ -10,6 +14,82 @@ import * as THREE from 'three';
1014
1115extend ( THREE ) ;
1216
17+ @Component ( {
18+ selector : 'app-plane' ,
19+ standalone : true ,
20+ template : `
21+ <ngt-mesh [ref]="planeApi.ref" [receiveShadow]="true">
22+ <ngt-plane-geometry *args="[1000, 1000]" />
23+ <ngt-mesh-standard-material color="#171717" />
24+ </ngt-mesh>
25+ ` ,
26+ imports : [ NgtArgs ] ,
27+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
28+ } )
29+ export class Plane {
30+ Math = Math ;
31+ @Input ( ) position = [ 0 , 0 , 0 ] ;
32+
33+ planeApi = injectPlane ( ( ) => ( { mass : 0 , position : this . position as Triplet , args : [ 1000 , 1000 ] } ) ) ;
34+ }
35+
36+ @Component ( {
37+ selector : 'app-box' ,
38+ standalone : true ,
39+ template : `
40+ <ngt-mesh [ref]="boxApi.ref" [receiveShadow]="true" [castShadow]="true">
41+ <ngt-box-geometry *args="[2, 2, 2]" />
42+ <ngt-mesh-standard-material [roughness]="0.5" color="#575757" />
43+ </ngt-mesh>
44+ ` ,
45+ imports : [ NgtArgs ] ,
46+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
47+ } )
48+ export class Box {
49+ @Input ( ) position = [ 0 , 0 , 0 ] ;
50+
51+ boxApi = injectBox ( ( ) => ( { mass : 10000 , position : this . position as Triplet , args : [ 2 , 2 , 2 ] } ) ) ;
52+ }
53+
54+ @Component ( {
55+ standalone : true ,
56+ template : `
57+ <ngt-point-light [position]="[-10, -10, 30]" [intensity]="0.25 * Math.PI" />
58+ <ngt-spot-light
59+ [intensity]="0.3 * Math.PI"
60+ [position]="[30, 30, 50]"
61+ [angle]="0.2"
62+ [penumbra]="1"
63+ [castShadow]="true"
64+ />
65+ <ngtc-physics [gravity]="[0, 0, -25]" [iterations]="10">
66+ <ngtc-debug color="white" [disabled]="true">
67+ <app-plane [position]="[0, 0, -10]" />
68+ <app-plane *ngIf="showPlane()" />
69+ <app-box [position]="[1, 0, 1]" />
70+ <app-box [position]="[2, 1, 5]" />
71+ <app-box [position]="[0, 0, 6]" />
72+ <app-box [position]="[-1, 1, 8]" />
73+ <app-box [position]="[-2, 2, 13]" />
74+ <app-box [position]="[2, -1, 13]" />
75+ <app-box *ngIf="!showPlane()" [position]="[0.5, 1.0, 20]" />
76+ </ngtc-debug>
77+ </ngtc-physics>
78+ ` ,
79+ imports : [ Box , Plane , NgtcPhysics , NgIf , NgtcDebug ] ,
80+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
81+ } )
82+ export class CannonScene {
83+ Math = Math ;
84+ showPlane = signal ( true ) ;
85+
86+ ngOnInit ( ) {
87+ setTimeout ( ( ) => {
88+ this . showPlane . set ( false ) ;
89+ } , 5000 ) ;
90+ }
91+ }
92+
1393@Component ( {
1494 standalone : true ,
1595 template : `
@@ -48,8 +128,15 @@ export class Scene {
48128 standalone : true ,
49129 imports : [ NgtCanvas , NgIf ] ,
50130 selector : 'sandbox-root' ,
51- template : ` <ngt-canvas [sceneGraph]="Scene" [camera]="{ position: [0, 1, 3] }" /> ` ,
131+ template : `
132+ <ngt-canvas
133+ [sceneGraph]="Scene"
134+ [camera]="{ position: [0, 0, 15] }"
135+ [shadows]="true"
136+ [gl]="{ useLegacyLights: true }"
137+ />
138+ ` ,
52139} )
53140export class AppComponent {
54- readonly Scene = Scene ;
141+ readonly Scene = CannonScene ;
55142}
0 commit comments