Skip to content

Commit 434c3ed

Browse files
committed
docs: add stars demo (gatsby stars)
1 parent c57dcea commit 434c3ed

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const routes: Routes = [
3333
path: 'lowpoly-earth',
3434
loadComponent: () => import('./lowpoly-earth/lowpoly-earth'),
3535
},
36+
{
37+
path: 'stars',
38+
loadComponent: () => import('./stars/stars'),
39+
},
3640
{
3741
path: '',
3842
redirectTo: 'basic',

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ extend(THREE);
3333
host: { class: 'soba' },
3434
})
3535
export default class Soba {
36-
examples = ['basic', 'hud', 'render-texture', 'shaky', 'lod', 'decal', 'html-chart', 'lowpoly-earth'];
36+
examples = ['basic', 'hud', 'render-texture', 'shaky', 'lod', 'decal', 'html-chart', 'lowpoly-earth', 'stars'];
3737
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, viewChild } from '@angular/core';
2+
import { injectBeforeRender } from 'angular-three';
3+
import { NgtsOrbitControls } from 'angular-three-soba/controls';
4+
import { NgtsPointMaterial } from 'angular-three-soba/materials';
5+
import { NgtsPointsBuffer } from 'angular-three-soba/performances';
6+
import { random } from 'maath';
7+
8+
@Component({
9+
standalone: true,
10+
template: `
11+
<ngt-group [rotation]="[0, 0, Math.PI / 4]">
12+
<ngts-points-buffer [positions]="sphere" [stride]="3" [options]="{ frustumCulled: false }">
13+
<ngts-point-material
14+
[options]="{ transparent: true, color: '#ccc', size: 0.005, sizeAttenuation: true, depthWrite: false }"
15+
/>
16+
</ngts-points-buffer>
17+
</ngt-group>
18+
19+
<ngts-orbit-controls [options]="{ enableZoom: false, enablePan: false }" />
20+
`,
21+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
22+
changeDetection: ChangeDetectionStrategy.OnPush,
23+
imports: [NgtsPointsBuffer, NgtsPointMaterial, NgtsOrbitControls],
24+
})
25+
export class Experience {
26+
protected readonly Math = Math;
27+
protected readonly sphere = random.inSphere(new Float32Array(5000), { radius: 1.5 }) as Float32Array;
28+
29+
pointsBufferRef = viewChild.required(NgtsPointsBuffer);
30+
31+
constructor() {
32+
injectBeforeRender(({ delta }) => {
33+
const points = this.pointsBufferRef().pointsRef().nativeElement;
34+
points.rotation.x -= delta / 10;
35+
points.rotation.y -= delta / 15;
36+
});
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { NgtCanvas } from 'angular-three';
3+
import { Experience } from './experience';
4+
5+
@Component({
6+
standalone: true,
7+
template: `
8+
<div style="position: absolute; top: 50%; left: 50%; transform: translate3d(-50%,-50%,0)">
9+
<h1
10+
style="margin: 0; padding: 0; font-size: 15em; font-weight: 500; letter-spacing: -0.05em; line-height: 1; text-align: center"
11+
>
12+
<code>angular three</code>
13+
</h1>
14+
</div>
15+
<ngt-canvas [sceneGraph]="sceneGraph" [camera]="{ position: [0, 0, 1] }" />
16+
`,
17+
changeDetection: ChangeDetectionStrategy.OnPush,
18+
host: { class: 'stars-soba' },
19+
styles: `
20+
:host {
21+
display: block;
22+
height: 100%;
23+
width: 100%;
24+
background: #12071f;
25+
}
26+
27+
h1 {
28+
background: linear-gradient(30deg, #c850c0, #ffcc70);
29+
-webkit-background-clip: text;
30+
-webkit-text-fill-color: transparent;
31+
}
32+
`,
33+
imports: [NgtCanvas],
34+
})
35+
export default class Stars {
36+
sceneGraph = Experience;
37+
}

0 commit comments

Comments
 (0)