Skip to content

Commit f4ebbbd

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
chore: add extrude example
1 parent a45804c commit f4ebbbd

File tree

5 files changed

+84
-10
lines changed

5 files changed

+84
-10
lines changed

apps/example/src/app/app.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ extend(THREE);
1818
Blue
1919
</a>
2020
</li>
21+
<li>
22+
<a routerLink="/routed/extrude" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }">
23+
Extrude
24+
</a>
25+
</li>
2126
</ul>
2227
<router-outlet />
2328
`,

apps/example/src/app/scene/blue-scene.component.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import { CursorPointer } from './cursor';
88
<ngt-spot-light [position]="5" />
99
<ngt-point-light [position]="-5" />
1010
11-
<ngt-mesh #cube cursorPointer (pointerover)="hovered = true" (pointerout)="hovered = false">
11+
<ngt-mesh
12+
#cube
13+
cursorPointer
14+
(pointerover)="hovered = true"
15+
(pointerout)="hovered = false"
16+
(click)="wireframe = !wireframe"
17+
>
1218
<ngt-icosahedron-geometry />
13-
<ngt-mesh-standard-material [color]="hovered ? 'green' : 'blue'" />
19+
<ngt-mesh-standard-material [color]="hovered ? 'green' : 'blue'" [wireframe]="wireframe" />
1420
</ngt-mesh>
1521
`,
1622
imports: [CursorPointer],
@@ -19,16 +25,15 @@ import { CursorPointer } from './cursor';
1925
export default class BlueScene {
2026
@ViewChild('cube', { static: true }) cube!: ElementRef<THREE.Mesh>;
2127

22-
readonly store = inject(NgtStore);
23-
2428
hovered = false;
29+
wireframe = false;
2530

2631
constructor() {
2732
injectBeforeRender(({ clock }) => {
2833
this.cube.nativeElement.rotation.x = clock.elapsedTime;
2934
this.cube.nativeElement.rotation.y = clock.elapsedTime;
3035
});
31-
console.log('blue instantiated', this.store.get('scene'));
36+
console.log('blue instantiated', inject(NgtStore).get('scene'));
3237
}
3338

3439
ngOnDestroy() {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2+
import { NgtArgs } from 'angular-three';
3+
import * as THREE from 'three';
4+
import { CursorPointer } from './cursor';
5+
6+
@Component({
7+
standalone: true,
8+
template: `
9+
<ngt-point-light [position]="5" />
10+
<ngt-spot-light [position]="-5" />
11+
12+
<ngt-mesh
13+
#mesh
14+
cursorPointer
15+
[scale]="0.1"
16+
(beforeRender)="onBeforeRender($any($event).object)"
17+
(pointerover)="hovered = true"
18+
(pointerout)="hovered = false"
19+
(click)="wireframe = !wireframe"
20+
>
21+
<ngt-extrude-geometry *args="[shape, extrudeSettings]" (afterAttach)="$any($event).node.center()" />
22+
<ngt-mesh-standard-material [color]="hovered ? 'goldenrod' : 'navy'" [wireframe]="wireframe" />
23+
</ngt-mesh>
24+
`,
25+
imports: [NgtArgs, CursorPointer],
26+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
27+
})
28+
export default class ExtrudeScene {
29+
shape = new THREE.Shape();
30+
readonly extrudeSettings = {
31+
steps: 2,
32+
depth: 16,
33+
bevelEnabled: true,
34+
bevelThickness: 1,
35+
bevelSize: 1,
36+
bevelOffset: 0,
37+
bevelSegments: 1,
38+
};
39+
40+
hovered = false;
41+
wireframe = false;
42+
43+
constructor() {
44+
this.shape.moveTo(0, 0);
45+
this.shape.lineTo(0, 8);
46+
this.shape.lineTo(12, 8);
47+
this.shape.lineTo(12, 0);
48+
this.shape.lineTo(0, 0);
49+
}
50+
51+
onBeforeRender(object: THREE.Mesh) {
52+
object.rotation.x += 0.01;
53+
object.rotation.y += 0.01;
54+
}
55+
}

apps/example/src/app/scene/red-scene.component.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import { CursorPointer } from './cursor';
88
<ngt-point-light [position]="5" />
99
<ngt-spot-light [position]="-5" />
1010
11-
<ngt-mesh #cube cursorPointer (pointerover)="hovered = true" (pointerout)="hovered = false">
11+
<ngt-mesh
12+
#cube
13+
cursorPointer
14+
(pointerover)="hovered = true"
15+
(pointerout)="hovered = false"
16+
(click)="wireframe = !wireframe"
17+
>
1218
<ngt-box-geometry />
13-
<ngt-mesh-standard-material [color]="hovered ? 'yellow' : 'red'" />
19+
<ngt-mesh-standard-material [color]="hovered ? 'yellow' : 'red'" [wireframe]="wireframe" />
1420
</ngt-mesh>
1521
`,
1622
imports: [CursorPointer],
@@ -19,16 +25,15 @@ import { CursorPointer } from './cursor';
1925
export default class RedScene {
2026
@ViewChild('cube', { static: true }) cube!: ElementRef<THREE.Mesh>;
2127

22-
readonly store = inject(NgtStore);
23-
2428
hovered = false;
29+
wireframe = false;
2530

2631
constructor() {
2732
injectBeforeRender(({ clock }) => {
2833
this.cube.nativeElement.rotation.x = clock.elapsedTime;
2934
this.cube.nativeElement.rotation.y = clock.elapsedTime;
3035
});
31-
console.log('red instantiated', this.store.get('scene'));
36+
console.log('red instantiated', inject(NgtStore).get('scene'));
3237
}
3338

3439
ngOnDestroy() {

apps/example/src/app/scene/scene.routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const routes: Routes = [
99
path: 'blue',
1010
loadComponent: () => import('./blue-scene.component'),
1111
},
12+
{
13+
path: 'extrude',
14+
loadComponent: () => import('./extrude-scene.component'),
15+
},
1216
];
1317

1418
export default routes;

0 commit comments

Comments
 (0)