Skip to content

Commit db6415b

Browse files
committed
docs: update routed examples
1 parent 18094f2 commit db6415b

File tree

22 files changed

+325
-184
lines changed

22 files changed

+325
-184
lines changed

apps/examples/src/app/rapier/basic/basic.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,43 @@
11
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, signal } from '@angular/core';
22
import { injectBeforeRender } from 'angular-three';
3-
import { NgtrCuboidCollider, NgtrPhysics, NgtrRigidBody } from 'angular-three-rapier';
3+
import { NgtrCuboidCollider, NgtrRigidBody } from 'angular-three-rapier';
44
import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';
5-
import { NgtsOrbitControls } from 'angular-three-soba/controls';
65

76
@Component({
7+
selector: 'app-rapier-basic',
88
template: `
9-
<ngts-perspective-camera [options]="{ makeDefault: true, position: [5, 5, 5] }" />
9+
<ngt-object3D rigidBody [options]="{ colliders: 'hull' }" [position]="[0, 5, 0]">
10+
<ngt-mesh>
11+
<ngt-torus-geometry />
12+
</ngt-mesh>
13+
</ngt-object3D>
1014
11-
<ngtr-physics [options]="{ debug: true }">
12-
<ng-template>
13-
<ngt-object3D rigidBody [options]="{ colliders: 'hull' }" [position]="[0, 5, 0]">
14-
<ngt-mesh>
15-
<ngt-torus-geometry />
16-
</ngt-mesh>
17-
</ngt-object3D>
18-
19-
@if (currentCollider() === 1) {
20-
<ngt-object3D cuboidCollider [args]="[1, 0.5, 1]" (collisionExit)="currentCollider.set(2)" />
21-
} @else if (currentCollider() === 2) {
22-
<ngt-object3D
23-
cuboidCollider
24-
[position]="[0, -1, 0]"
25-
[args]="[3, 0.5, 3]"
26-
(collisionExit)="currentCollider.set(3)"
27-
/>
28-
} @else if (currentCollider() === 3) {
29-
<ngt-object3D
30-
cuboidCollider
31-
[position]="[0, -3, 0]"
32-
[args]="[6, 0.5, 6]"
33-
(collisionExit)="currentCollider.set(4)"
34-
/>
35-
} @else {
36-
<ngt-object3D cuboidCollider [position]="[0, -6, 0]" [args]="[20, 0.5, 20]" />
37-
}
38-
</ng-template>
39-
</ngtr-physics>
40-
41-
<ngts-orbit-controls />
15+
@if (currentCollider() === 1) {
16+
<ngt-object3D cuboidCollider [args]="[1, 0.5, 1]" (collisionExit)="currentCollider.set(2)" />
17+
} @else if (currentCollider() === 2) {
18+
<ngt-object3D
19+
cuboidCollider
20+
[position]="[0, -1, 0]"
21+
[args]="[3, 0.5, 3]"
22+
(collisionExit)="currentCollider.set(3)"
23+
/>
24+
} @else if (currentCollider() === 3) {
25+
<ngt-object3D
26+
cuboidCollider
27+
[position]="[0, -3, 0]"
28+
[args]="[6, 0.5, 6]"
29+
(collisionExit)="currentCollider.set(4)"
30+
/>
31+
} @else {
32+
<ngt-object3D cuboidCollider [position]="[0, -6, 0]" [args]="[20, 0.5, 20]" />
33+
}
4234
`,
4335
schemas: [CUSTOM_ELEMENTS_SCHEMA],
4436
changeDetection: ChangeDetectionStrategy.OnPush,
4537
host: { class: 'experience-basic-rapier' },
46-
imports: [NgtrPhysics, NgtrRigidBody, NgtrCuboidCollider, NgtsOrbitControls, NgtsPerspectiveCamera],
38+
imports: [NgtrRigidBody, NgtrCuboidCollider, NgtsPerspectiveCamera],
4739
})
48-
export class Basic {
40+
export default class Basic {
4941
protected currentCollider = signal(1);
5042

5143
constructor() {

apps/examples/src/app/rapier/cluster/cluster.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Color, InstancedMesh, Vector3 } from 'three';
1414
const BALLS = 1000;
1515

1616
@Component({
17+
selector: 'app-cluster-rapier',
1718
template: `
1819
<ngt-group>
1920
<ngt-object3D [instancedRigidBodies]="bodies" [options]="{ colliders: 'ball', linearDamping: 5 }">
@@ -29,7 +30,7 @@ const BALLS = 1000;
2930
host: { class: 'cluster-rapier' },
3031
imports: [NgtrInstancedRigidBodies, NgtArgs],
3132
})
32-
export class ClusterExample {
33+
export default class ClusterExample {
3334
protected readonly BALLS = BALLS;
3435
protected bodies = Array.from({ length: BALLS }, (_, index) => {
3536
return {

apps/examples/src/app/rapier/constants.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

apps/examples/src/app/rapier/instanced-mesh/instanced-mesh.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { injectSuzanne } from '../suzanne';
1515
const MAX_COUNT = 2000;
1616

1717
@Component({
18+
selector: 'app-rapier-instanced-mesh',
1819
template: `
1920
<ngt-group>
2021
@if (gltf(); as gltf) {
@@ -41,7 +42,7 @@ const MAX_COUNT = 2000;
4142
host: { class: 'instanced-mesh-rapier' },
4243
imports: [NgtrInstancedRigidBodies, NgtArgs],
4344
})
44-
export class InstancedMeshExample {
45+
export default class InstancedMeshExample {
4546
protected readonly MAX_COUNT = MAX_COUNT;
4647

4748
private instancedMeshRef = viewChild<ElementRef<InstancedMesh>>('instancedMesh');

apps/examples/src/app/rapier/joints/joints.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class Prismatic {
130130
}
131131

132132
@Component({
133+
selector: 'app-rapier-joints',
133134
template: `
134135
<ngt-group>
135136
<app-rope [length]="40" />
@@ -141,4 +142,4 @@ export class Prismatic {
141142
host: { class: 'joints-rapier' },
142143
imports: [Rope, Prismatic],
143144
})
144-
export class JointsExample {}
145+
export default class JointsExample {}

apps/examples/src/app/rapier/performance/performance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class Bendy {
126126
}
127127

128128
@Component({
129+
selector: 'app-rapier-performance',
129130
template: `
130131
<ngt-group>
131132
<app-bendy />
@@ -140,4 +141,4 @@ export class Bendy {
140141
host: { class: 'performance-rapier' },
141142
imports: [Bendy, MonkeySwarm],
142143
})
143-
export class PerformanceExample {}
144+
export default class PerformanceExample {}

apps/examples/src/app/rapier/rapier.routes.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,43 @@ import { Routes } from '@angular/router';
22

33
const routes: Routes = [
44
{
5-
path: ':scene',
5+
path: '',
66
loadComponent: () => import('./wrapper'),
7+
children: [
8+
{
9+
path: 'basic',
10+
loadComponent: () => import('./basic/basic'),
11+
},
12+
{
13+
path: 'rope-joint',
14+
loadComponent: () => import('./rope-joint/rope-joint'),
15+
},
16+
{
17+
path: 'spring',
18+
loadComponent: () => import('./spring/spring'),
19+
},
20+
{
21+
path: 'cluster',
22+
loadComponent: () => import('./cluster/cluster'),
23+
},
24+
{
25+
path: 'instanced-mesh',
26+
loadComponent: () => import('./instanced-mesh/instanced-mesh'),
27+
},
28+
{
29+
path: 'joints',
30+
loadComponent: () => import('./joints/joints'),
31+
},
32+
{
33+
path: 'performance',
34+
loadComponent: () => import('./performance/performance'),
35+
},
36+
{
37+
path: '',
38+
redirectTo: 'basic',
39+
pathMatch: 'full',
40+
},
41+
],
742
data: {
843
credits: {
944
title: 'React Three Rapier',
@@ -12,11 +47,6 @@ const routes: Routes = [
1247
},
1348
},
1449
},
15-
{
16-
path: '',
17-
redirectTo: 'basic',
18-
pathMatch: 'full',
19-
},
2050
];
2151

2252
export default routes;

apps/examples/src/app/rapier/rapier.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
33
import { extend } from 'angular-three';
44
import * as THREE from 'three';
55

6-
import { SCENES_MAP } from './constants';
7-
86
extend(THREE);
97

108
@Component({
@@ -34,5 +32,5 @@ extend(THREE);
3432
host: { class: 'rapier' },
3533
})
3634
export default class Rapier {
37-
protected examples = Object.keys(SCENES_MAP);
35+
protected examples = ['basic', 'rope-joint', 'spring', 'cluster', 'instanced-mesh', 'joints', 'performance'];
3836
}

apps/examples/src/app/rapier/rope-joint/rope-joint.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class RopeJoint {
111111
}
112112

113113
@Component({
114+
selector: 'app-rapier-rope-joint',
114115
template: `
115116
<ngt-group [scale]="3">
116117
<app-floor />
@@ -123,4 +124,4 @@ export class RopeJoint {
123124
host: { class: 'rope-joint-rapier' },
124125
imports: [Floor, BoxWall, RopeJoint],
125126
})
126-
export class RopeJointExample {}
127+
export default class RopeJointExample {}

apps/examples/src/app/rapier/spring/spring.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class BallSpring {
9090
}
9191

9292
@Component({
93+
selector: 'app-rapier-spring',
9394
template: `
9495
<ngt-object3D #floor="rigidBody" rigidBody="fixed" [position]="[0, 0, 0]" />
9596
@@ -114,7 +115,7 @@ export class BallSpring {
114115
host: { class: 'spring-rapier' },
115116
imports: [NgtrRigidBody, BallSpring, Box],
116117
})
117-
export class SpringExample {
118+
export default class SpringExample {
118119
protected readonly COLORS_ARR = ['#335C67', '#FFF3B0', '#E09F3E', '#9E2A2B', '#540B0E'];
119120
protected balls = Array.from({ length: 30 }, (_, i) => [-20 + 1.5 * (i + 1), 7.5, -30] as [number, number, number]);
120121
}

0 commit comments

Comments
 (0)