@@ -11,17 +11,18 @@ import {
11
11
inject ,
12
12
input ,
13
13
output ,
14
- signal ,
15
14
viewChild ,
16
15
} from '@angular/core' ;
17
16
import { ConeTwistConstraintOpts , Triplet } from '@pmndrs/cannon-worker-api' ;
18
- import { NgtArgs , NgtThreeEvent , extend , injectBeforeRender } from 'angular-three' ;
17
+ import { NgtArgs , NgtThreeEvent , NgtVector3 , extend , injectBeforeRender , injectObjectEvents } from 'angular-three' ;
19
18
import { NgtcPhysics } from 'angular-three-cannon' ;
20
19
import { injectBox , injectCompound , injectCylinder , injectSphere } from 'angular-three-cannon/body' ;
21
20
import { NgtcConstraintApi , injectConeTwist , injectPointToPoint } from 'angular-three-cannon/constraint' ;
22
21
import { NgtcDebug } from 'angular-three-cannon/debug' ;
22
+ import { NgtsRoundedBox } from 'angular-three-soba/abstractions' ;
23
23
import { injectGLTF } from 'angular-three-soba/loaders' ;
24
- import { createInjectionToken , createNoopInjectionToken } from 'ngxtension/create-injection-token' ;
24
+ import { NgtsSpotLight } from 'angular-three-soba/staging' ;
25
+ import { createNoopInjectionToken } from 'ngxtension/create-injection-token' ;
25
26
import * as THREE from 'three' ;
26
27
import { Group , Material , Mesh , Object3D } from 'three' ;
27
28
import { GLTF } from 'three-stdlib' ;
@@ -30,8 +31,6 @@ import { createRagdoll } from './config';
30
31
31
32
extend ( THREE ) ;
32
33
33
- const [ injectCursorRef , provideCursorRef ] = createInjectionToken ( ( ) => signal < ElementRef < Mesh > | null > ( null ) ) ;
34
-
35
34
function injectDragConstraint ( ref : Signal < ElementRef < Object3D > | undefined > ) {
36
35
const cursorRef = inject ( Cursor ) ;
37
36
const injector = inject ( Injector ) ;
@@ -63,36 +62,52 @@ function injectDragConstraint(ref: Signal<ElementRef<Object3D> | undefined>) {
63
62
selector : 'app-box' ,
64
63
standalone : true ,
65
64
template : `
66
- <ngt-mesh
67
- #mesh
68
- [castShadow]="true"
69
- [receiveShadow]="true"
70
- [position]="position()"
71
- [scale]="scale()"
72
- (pointerdown)="pointerdown.emit($any($event))"
73
- (pointerup)="pointerup.emit()"
65
+ <ngts-rounded-box
66
+ [options]="{
67
+ width: width(),
68
+ height: height(),
69
+ depth: depth(),
70
+ castShadow: true,
71
+ receiveShadow: true,
72
+ position: position(),
73
+ scale: scale(),
74
+ }"
74
75
>
75
- <ngt-box-geometry *args="args()" />
76
76
<ngt-mesh-standard-material [color]="color()" [opacity]="opacity()" [transparent]="transparent()" />
77
77
<ng-content />
78
- </ngt-mesh >
78
+ </ngts-rounded-box >
79
79
` ,
80
- imports : [ NgtArgs ] ,
80
+ imports : [ NgtArgs , NgtsRoundedBox ] ,
81
81
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
82
82
changeDetection : ChangeDetectionStrategy . OnPush ,
83
83
} )
84
84
export class Box {
85
+ width = input ( 1 ) ;
86
+ height = input ( 1 ) ;
87
+ depth = input ( 1 ) ;
85
88
color = input ( 'white' ) ;
86
89
opacity = input ( 1 ) ;
87
90
transparent = input ( false ) ;
88
91
args = input ( [ 1 , 1 , 1 ] ) ;
89
- position = input ( [ 0 , 0 , 0 ] ) ;
90
- scale = input ( [ 1 , 1 , 1 ] ) ;
92
+ position = input < NgtVector3 > ( [ 0 , 0 , 0 ] ) ;
93
+ scale = input < NgtVector3 > ( [ 1 , 1 , 1 ] ) ;
91
94
92
95
pointerdown = output < NgtThreeEvent < PointerEvent > > ( ) ;
93
96
pointerup = output < void > ( ) ;
94
97
95
- meshRef = viewChild . required < ElementRef < Mesh > > ( 'mesh' ) ;
98
+ roundedBoxRef = viewChild . required ( NgtsRoundedBox ) ;
99
+ meshRef = computed ( ( ) => this . roundedBoxRef ( ) . meshRef ( ) ) ;
100
+
101
+ constructor ( ) {
102
+ injectObjectEvents ( this . meshRef , {
103
+ pointerdown : ( event ) => {
104
+ this . pointerdown . emit ( event as NgtThreeEvent < PointerEvent > ) ;
105
+ } ,
106
+ pointerup : ( ) => {
107
+ this . pointerup . emit ( ) ;
108
+ } ,
109
+ } ) ;
110
+ }
96
111
}
97
112
98
113
const { joints, shapes } = createRagdoll ( 4.8 , Math . PI / 16 , Math . PI / 16 , 0 ) ;
@@ -171,13 +186,19 @@ export class BodyPart {
171
186
<ngt-group #eyes>
172
187
<app-box
173
188
color="black"
189
+ [width]="0.2"
190
+ [height]="0.1"
191
+ [depth]="0.1"
174
192
[args]="[0.3, 0.01, 0.1]"
175
193
[opacity]="0.8"
176
194
[position]="[-0.3, 0.1, 0.5]"
177
195
[transparent]="true"
178
196
/>
179
197
<app-box
180
198
color="black"
199
+ [width]="0.2"
200
+ [height]="0.1"
201
+ [depth]="0.1"
181
202
[args]="[0.3, 0.01, 0.1]"
182
203
[opacity]="0.8"
183
204
[position]="[0.3, 0.1, 0.5]"
@@ -186,7 +207,10 @@ export class BodyPart {
186
207
</ngt-group>
187
208
<app-box
188
209
#mouth
189
- color="#270000"
210
+ [width]="0.3"
211
+ [height]="0.05"
212
+ [depth]="0.1"
213
+ color="#700000"
190
214
[args]="[0.3, 0.05, 0.1]"
191
215
[opacity]="0.8"
192
216
[position]="[0, -0.2, 0.5]"
@@ -226,7 +250,7 @@ export class RagDoll {
226
250
const [ eyes , mouth ] = [ this . eyes ( ) , this . mouth ( ) ] ;
227
251
if ( eyes && mouth ) {
228
252
eyes . nativeElement . position . y = Math . sin ( clock . getElapsedTime ( ) * 1 ) * 0.06 ;
229
- mouth . meshRef ( ) . nativeElement . scale . y = ( 1 + Math . sin ( clock . getElapsedTime ( ) ) ) * 1.5 ;
253
+ mouth . meshRef ( ) . nativeElement . scale . y = ( 1 + Math . sin ( clock . getElapsedTime ( ) ) ) * 0.6 ;
230
254
}
231
255
} ) ;
232
256
}
@@ -425,18 +449,29 @@ export class Cursor {
425
449
<ngt-cone-geometry *args="[2, 2.5, 32]" />
426
450
<ngt-mesh-standard-material />
427
451
428
- <ngt-point-light [decay]="5" [intensity]="10 * Math.PI" />
429
- <ngt-spot-light
430
- [angle]="0.4"
431
- [decay]="0"
432
- [penumbra]="1"
433
- [position]="[0, 20, 0]"
434
- [intensity]="0.6 * Math.PI"
435
- [castShadow]="true"
452
+ <!-- <ngt-point-light [decay]="5" [intensity]="10 * Math.PI" />-->
453
+ <ngts-spot-light
454
+ [options]="{
455
+ intensity: Math.PI,
456
+ angle: 0.45,
457
+ distance: 80,
458
+ radiusTop: 0.4,
459
+ radiusBottom: 40,
460
+ penumbra: 0.2,
461
+ anglePower: 5,
462
+ opacity: 0.2,
463
+ color: 'white',
464
+ castShadow: true,
465
+ target: $any(target),
466
+ decay: 0,
467
+ }"
436
468
/>
469
+
470
+ <ngt-object3D #target [position]="[0, -1, 0]" />
437
471
</ngt-mesh>
438
472
` ,
439
- imports : [ NgtArgs ] ,
473
+
474
+ imports : [ NgtArgs , NgtsSpotLight ] ,
440
475
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
441
476
changeDetection : ChangeDetectionStrategy . OnPush ,
442
477
} )
@@ -492,7 +527,6 @@ export class Lamp {
492
527
</ngtc-physics>
493
528
` ,
494
529
imports : [ NgtArgs , NgtcPhysics , NgtcDebug , Cursor , Lamp , UiPlane , Chair , Table , RagDoll ] ,
495
- providers : [ provideCursorRef ( ) ] ,
496
530
changeDetection : ChangeDetectionStrategy . OnPush ,
497
531
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
498
532
host : { class : 'monday-morning-experience' } ,
0 commit comments