Skip to content

Commit 1c310e8

Browse files
committed
docs(examples): update stars routes
1 parent 2c43c6f commit 1c310e8

File tree

4 files changed

+89
-12
lines changed

4 files changed

+89
-12
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ const routes: Routes = [
6969
},
7070
},
7171
},
72-
// {
73-
// path: 'stars',
74-
// loadComponent: () => import('./stars/stars'),
75-
// data: {
76-
// credits: {
77-
// title: 'Stars',
78-
// link: 'https://pmndrs.github.io/examples/demos/gatsby-stars',
79-
// class: 'text-white',
80-
// },
81-
// },
82-
// },
72+
{
73+
path: 'stars',
74+
loadComponent: () => import('./stars/stars'),
75+
data: {
76+
credits: {
77+
title: 'Stars',
78+
link: 'https://pmndrs.github.io/examples/demos/gatsby-stars',
79+
class: 'text-white',
80+
},
81+
},
82+
},
8383
{
8484
path: 'skydiving',
8585
loadComponent: () => import('./skydiving/skydiving'),
Lines changed: 38 additions & 0 deletions
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+
selector: 'app-stars-scene-graph',
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 SceneGraph {
26+
protected readonly Math = Math;
27+
protected readonly sphere = random.inSphere(new Float32Array(5000), { radius: 1.5 }) as Float32Array;
28+
29+
private 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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { NgtCanvas, NgtCanvasContent } from 'angular-three/dom';
3+
import { SceneGraph } from './scene';
4+
5+
@Component({
6+
template: `
7+
<div style="position: absolute; top: 50%; left: 50%; transform: translate3d(-50%,-50%,0)">
8+
<h1
9+
style="margin: 0; padding: 0; font-size: 15em; font-weight: 500; letter-spacing: -0.05em; line-height: 1; text-align: center;"
10+
>
11+
<code>angular three</code>
12+
</h1>
13+
</div>
14+
<ngt-canvas [camera]="{ position: [0, 0, 1] }">
15+
<app-stars-scene-graph *canvasContent />
16+
</ngt-canvas>
17+
`,
18+
changeDetection: ChangeDetectionStrategy.OnPush,
19+
host: { class: 'stars-soba' },
20+
styles: `
21+
:host {
22+
display: block;
23+
height: 100%;
24+
width: 100%;
25+
background: #12071f;
26+
}
27+
28+
h1 {
29+
background: linear-gradient(30deg, #c850c0, #ffcc70);
30+
-webkit-background-clip: text;
31+
-webkit-text-fill-color: transparent;
32+
}
33+
`,
34+
imports: [NgtCanvas, SceneGraph, NgtCanvasContent],
35+
})
36+
export default class Stars {}

libs/core/src/lib/renderer/renderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export class NgtRendererFactory2 implements RendererFactory2 {
5757
if (renderer) {
5858
if (renderer instanceof NgtRenderer2) {
5959
renderer.count += 1;
60+
if (renderer.delegateRenderer !== delegateRenderer) {
61+
renderer.delegateRenderer = delegateRenderer;
62+
}
6063
}
6164
return renderer;
6265
}
@@ -94,7 +97,7 @@ export class NgtRenderer2 implements Renderer2 {
9497
private portalInjectors: Array<Injector> = [];
9598

9699
constructor(
97-
private delegateRenderer: Renderer2,
100+
public delegateRenderer: Renderer2,
98101
private catalogue: Record<string, NgtConstructorRepresentation>,
99102
private document: Document,
100103
public count = 1,

0 commit comments

Comments
 (0)