1
1
import { 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' ;
3
4
import { 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' ;
4
8
import { NgtpBloom , NgtpEffectComposer } from 'angular-three-postprocessing' ;
5
9
import { NgtsGrid } from 'angular-three-soba/abstractions' ;
6
10
import { NgtsOrbitControls } from 'angular-three-soba/controls' ;
@@ -10,6 +14,82 @@ import * as THREE from 'three';
10
14
11
15
extend ( THREE ) ;
12
16
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
+
13
93
@Component ( {
14
94
standalone : true ,
15
95
template : `
@@ -48,8 +128,15 @@ export class Scene {
48
128
standalone : true ,
49
129
imports : [ NgtCanvas , NgIf ] ,
50
130
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
+ ` ,
52
139
} )
53
140
export class AppComponent {
54
- readonly Scene = Scene ;
141
+ readonly Scene = CannonScene ;
55
142
}
0 commit comments