Skip to content

Commit f9c9e72

Browse files
committed
update monday morning with rounded box
1 parent aed72ab commit f9c9e72

File tree

2 files changed

+66
-37
lines changed

2 files changed

+66
-37
lines changed

apps/kitchen-sink/src/app/cannon/monday-morning/experience.ts

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ import {
1111
inject,
1212
input,
1313
output,
14-
signal,
1514
viewChild,
1615
} from '@angular/core';
1716
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';
1918
import { NgtcPhysics } from 'angular-three-cannon';
2019
import { injectBox, injectCompound, injectCylinder, injectSphere } from 'angular-three-cannon/body';
2120
import { NgtcConstraintApi, injectConeTwist, injectPointToPoint } from 'angular-three-cannon/constraint';
2221
import { NgtcDebug } from 'angular-three-cannon/debug';
22+
import { NgtsRoundedBox } from 'angular-three-soba/abstractions';
2323
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';
2526
import * as THREE from 'three';
2627
import { Group, Material, Mesh, Object3D } from 'three';
2728
import { GLTF } from 'three-stdlib';
@@ -30,8 +31,6 @@ import { createRagdoll } from './config';
3031

3132
extend(THREE);
3233

33-
const [injectCursorRef, provideCursorRef] = createInjectionToken(() => signal<ElementRef<Mesh> | null>(null));
34-
3534
function injectDragConstraint(ref: Signal<ElementRef<Object3D> | undefined>) {
3635
const cursorRef = inject(Cursor);
3736
const injector = inject(Injector);
@@ -63,36 +62,52 @@ function injectDragConstraint(ref: Signal<ElementRef<Object3D> | undefined>) {
6362
selector: 'app-box',
6463
standalone: true,
6564
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+
}"
7475
>
75-
<ngt-box-geometry *args="args()" />
7676
<ngt-mesh-standard-material [color]="color()" [opacity]="opacity()" [transparent]="transparent()" />
7777
<ng-content />
78-
</ngt-mesh>
78+
</ngts-rounded-box>
7979
`,
80-
imports: [NgtArgs],
80+
imports: [NgtArgs, NgtsRoundedBox],
8181
schemas: [CUSTOM_ELEMENTS_SCHEMA],
8282
changeDetection: ChangeDetectionStrategy.OnPush,
8383
})
8484
export class Box {
85+
width = input(1);
86+
height = input(1);
87+
depth = input(1);
8588
color = input('white');
8689
opacity = input(1);
8790
transparent = input(false);
8891
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]);
9194

9295
pointerdown = output<NgtThreeEvent<PointerEvent>>();
9396
pointerup = output<void>();
9497

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+
}
96111
}
97112

98113
const { joints, shapes } = createRagdoll(4.8, Math.PI / 16, Math.PI / 16, 0);
@@ -171,13 +186,19 @@ export class BodyPart {
171186
<ngt-group #eyes>
172187
<app-box
173188
color="black"
189+
[width]="0.2"
190+
[height]="0.1"
191+
[depth]="0.1"
174192
[args]="[0.3, 0.01, 0.1]"
175193
[opacity]="0.8"
176194
[position]="[-0.3, 0.1, 0.5]"
177195
[transparent]="true"
178196
/>
179197
<app-box
180198
color="black"
199+
[width]="0.2"
200+
[height]="0.1"
201+
[depth]="0.1"
181202
[args]="[0.3, 0.01, 0.1]"
182203
[opacity]="0.8"
183204
[position]="[0.3, 0.1, 0.5]"
@@ -186,7 +207,10 @@ export class BodyPart {
186207
</ngt-group>
187208
<app-box
188209
#mouth
189-
color="#270000"
210+
[width]="0.3"
211+
[height]="0.05"
212+
[depth]="0.1"
213+
color="#700000"
190214
[args]="[0.3, 0.05, 0.1]"
191215
[opacity]="0.8"
192216
[position]="[0, -0.2, 0.5]"
@@ -226,7 +250,7 @@ export class RagDoll {
226250
const [eyes, mouth] = [this.eyes(), this.mouth()];
227251
if (eyes && mouth) {
228252
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;
230254
}
231255
});
232256
}
@@ -425,18 +449,29 @@ export class Cursor {
425449
<ngt-cone-geometry *args="[2, 2.5, 32]" />
426450
<ngt-mesh-standard-material />
427451
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+
}"
436468
/>
469+
470+
<ngt-object3D #target [position]="[0, -1, 0]" />
437471
</ngt-mesh>
438472
`,
439-
imports: [NgtArgs],
473+
474+
imports: [NgtArgs, NgtsSpotLight],
440475
schemas: [CUSTOM_ELEMENTS_SCHEMA],
441476
changeDetection: ChangeDetectionStrategy.OnPush,
442477
})
@@ -492,7 +527,6 @@ export class Lamp {
492527
</ngtc-physics>
493528
`,
494529
imports: [NgtArgs, NgtcPhysics, NgtcDebug, Cursor, Lamp, UiPlane, Chair, Table, RagDoll],
495-
providers: [provideCursorRef()],
496530
changeDetection: ChangeDetectionStrategy.OnPush,
497531
schemas: [CUSTOM_ELEMENTS_SCHEMA],
498532
host: { class: 'monday-morning-experience' },

apps/kitchen-sink/src/app/cannon/monday-morning/monday-morning.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { NgtCanvas } from 'angular-three';
33
import { Experience } from './experience';
44

5-
// camera={{ far: 100, near: 1, position: [-25, 20, 25], zoom: 25 }}
6-
// orthographic
7-
// shadows
8-
// style={{ cursor: 'none' }}
9-
105
@Component({
116
standalone: true,
127
template: `
138
<ngt-canvas
149
[sceneGraph]="scene"
15-
[camera]="{ far: 100, near: 1, position: [-25, 20, 25], zoom: 25 }"
10+
[camera]="{ far: 100, near: 1, position: [-25, 20, 25], zoom: 35 }"
1611
[orthographic]="true"
1712
[shadows]="true"
1813
/>

0 commit comments

Comments
 (0)