Skip to content

Commit 10a9a20

Browse files
committed
docs: pull toggle button up; add toggle debug to bruno simons example
1 parent c853b9a commit 10a9a20

File tree

5 files changed

+50
-29
lines changed

5 files changed

+50
-29
lines changed

apps/kitchen-sink/src/app/app.routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ export const appRoutes: Route[] = [
55
path: 'cannon',
66
loadComponent: () => import('./cannon/cannon'),
77
loadChildren: () => import('./cannon/cannon.routes'),
8+
title: 'Cannon - Angular Three Demo',
89
},
910
{
1011
path: 'postprocessing',
1112
loadComponent: () => import('./postprocessing/postprocessing'),
1213
loadChildren: () => import('./postprocessing/postprocessing.routes'),
14+
title: 'Postprocessing - Angular Three Demo',
1315
},
1416
{
1517
path: 'soba',
1618
loadComponent: () => import('./soba/soba'),
1719
loadChildren: () => import('./soba/soba.routes'),
20+
title: 'Soba - Angular Three Demo',
1821
},
1922
{
2023
path: 'rapier',
2124
loadComponent: () => import('./rapier/rapier'),
2225
loadChildren: () => import('./rapier/rapier.routes'),
26+
title: 'Rapier - Angular Three Demo',
2327
},
2428
{
2529
path: '',

apps/kitchen-sink/src/app/rapier/wrapper.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
import { ChangeDetectionStrategy, Component, computed, Directive, model } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { NgtCanvas } from 'angular-three';
3+
import { ToggleButton } from '../toggle-button';
34
import { debug, interpolate, paused, RapierWrapperDefault } from './wrapper-default';
45

5-
@Directive({
6-
selector: 'button[toggleButton]',
7-
standalone: true,
8-
host: {
9-
class: 'border rounded px-2 py-1',
10-
'(click)': 'onClick()',
11-
'[class]': 'hbClass()',
12-
},
13-
})
14-
export class ToggleButton {
15-
value = model.required<boolean>({ alias: 'toggleButton' });
16-
17-
hbClass = computed(() => {
18-
return this.value() ? ['text-white', 'bg-red-600', 'border-red-400'] : ['text-black', 'border-black'];
19-
});
20-
21-
onClick() {
22-
this.value.update((prev) => !prev);
23-
}
24-
}
25-
266
@Component({
277
standalone: true,
288
template: `
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { NgtCanvas } from 'angular-three';
3-
import { Experience } from './experience';
3+
import { ToggleButton } from '../../toggle-button';
4+
import { debug, Experience } from './experience';
45

56
@Component({
67
standalone: true,
@@ -12,14 +13,24 @@ import { Experience } from './experience';
1213
[gl]="{ antialias: false }"
1314
[camera]="{ position: [-30, 35, -15], near: 30, far: 55, fov: 12 }"
1415
/>
15-
<pre class="absolute top-2 right-2">
16-
Credits: <a class="underline" href="https://pmndrs.github.io/examples/demos/bruno-simons-20k-challenge" target="_blank">Bruno Simons 20K Challenge with R3F</a>
17-
</pre>
16+
17+
<div class="absolute top-2 right-2 flex flex-col gap-2">
18+
<code>
19+
Credits:
20+
<a class="underline" href="https://pmndrs.github.io/examples/demos/bruno-simons-20k-challenge" target="_blank">
21+
Bruno Simons 20K Challenge with R3F
22+
</a>
23+
</code>
24+
<div class="flex gap-2 items-center">
25+
<button [(toggleButton)]="debug">Toggle debug</button>
26+
</div>
27+
</div>
1828
`,
1929
changeDetection: ChangeDetectionStrategy.OnPush,
2030
host: { class: 'bruno-simons-2k-soba' },
21-
imports: [NgtCanvas],
31+
imports: [NgtCanvas, ToggleButton],
2232
})
2333
export default class BrunoSimons20k {
2434
protected sceneGraph = Experience;
35+
protected debug = debug;
2536
}

apps/kitchen-sink/src/app/soba/bruno-simons-20k/experience.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, input, Signal } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, input, signal, Signal } from '@angular/core';
22
import { NgtArgs, NgtEuler, NgtVector3 } from 'angular-three';
33
import { NgtpDepthOfField, NgtpEffectComposer, NgtpToneMapping } from 'angular-three-postprocessing';
44
import { NgtpN8AO } from 'angular-three-postprocessing/n8ao';
@@ -14,6 +14,8 @@ import {
1414
import { MathUtils, Mesh, MeshStandardMaterial } from 'three';
1515
import { GLTF } from 'three-stdlib';
1616

17+
export const debug = signal(false);
18+
1719
type HatGLTF = GLTF & {
1820
nodes: { Plane006: Mesh; Plane006_1: Mesh };
1921
materials: { Material: MeshStandardMaterial; boxCap: MeshStandardMaterial };
@@ -118,7 +120,7 @@ export class Model {
118120
</ng-template>
119121
</ngts-environment>
120122
121-
<ngtr-physics [options]="{ gravity: [0, -4, 0] }">
123+
<ngtr-physics [options]="{ debug: debug(), gravity: [0, -4, 0] }">
122124
<app-model [position]="[1, 0, -1.5]" />
123125
<app-hats />
124126
<ngt-object3D ngtrRigidBody="fixed" [options]="{ colliders: false }" [position]="[0, -1, 0]">
@@ -183,4 +185,6 @@ export class Model {
183185
export class Experience {
184186
protected readonly Infinity = Infinity;
185187
protected readonly Math = Math;
188+
189+
protected debug = debug;
186190
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { computed, Directive, model } from '@angular/core';
2+
3+
@Directive({
4+
selector: 'button[toggleButton]',
5+
standalone: true,
6+
host: {
7+
class: 'border rounded px-2 py-1',
8+
'(click)': 'onClick()',
9+
'[class]': 'hbClass()',
10+
},
11+
})
12+
export class ToggleButton {
13+
value = model.required<boolean>({ alias: 'toggleButton' });
14+
15+
hbClass = computed(() => {
16+
return this.value() ? ['text-white', 'bg-red-600', 'border-red-400'] : ['text-black', 'border-black'];
17+
});
18+
19+
onClick() {
20+
this.value.update((prev) => !prev);
21+
}
22+
}

0 commit comments

Comments
 (0)