Skip to content

Commit a0ab8e5

Browse files
committed
add new story for scroll controls
1 parent 552b02b commit a0ab8e5

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ import { provideRouter } from '@angular/router';
33
import { appRoutes } from './app.routes';
44

55
export const appConfig: ApplicationConfig = {
6-
providers: [provideExperimentalZonelessChangeDetection(), provideRouter(appRoutes)],
6+
providers: [
7+
provideExperimentalZonelessChangeDetection(),
8+
// provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }),
9+
provideRouter(appRoutes),
10+
],
711
};
Binary file not shown.

libs/soba/src/controls/scroll-controls.stories.ts

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,108 @@
1-
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, input, signal, Signal } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
computed,
5+
CUSTOM_ELEMENTS_SCHEMA,
6+
inject,
7+
input,
8+
signal,
9+
Signal,
10+
} from '@angular/core';
211
import { Meta } from '@storybook/angular';
3-
import { injectStore, NgtHTML } from 'angular-three';
12+
import { injectBeforeRender, injectStore, NgtArgs, NgtHTML } from 'angular-three';
413
import {
514
NgtsScrollCanvas,
615
NgtsScrollControls,
716
NgtsScrollControlsOptions,
817
NgtsScrollHtml,
918
} from 'angular-three-soba/controls';
1019
import { injectGLTF } from 'angular-three-soba/loaders';
11-
import { makeDecorators, makeStoryObject } from '../setup-canvas';
20+
import { injectAnimations } from 'angular-three-soba/misc';
21+
import { NgtsSky } from 'angular-three-soba/staging';
22+
import { MathUtils, Mesh } from 'three';
23+
import { makeDecorators, makeStoryFunction, makeStoryObject } from '../setup-canvas';
24+
25+
@Component({
26+
selector: 'scroll-littlest-tokyo',
27+
standalone: true,
28+
template: `
29+
<ngt-primitive *args="[scene()]" [parameters]="{ position: [0, 2.5, 0], scale: 0.02 }" />
30+
`,
31+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
32+
imports: [NgtArgs],
33+
changeDetection: ChangeDetectionStrategy.OnPush,
34+
})
35+
class LittlestTokyo {
36+
private gltf = injectGLTF(() => './LittlestTokyo-transformed.glb');
37+
scene = computed(() => {
38+
const gltf = this.gltf();
39+
if (!gltf) return null;
40+
41+
const scene = gltf.scene;
42+
43+
scene.traverse((node) => {
44+
if ((node as Mesh).isMesh) {
45+
node.receiveShadow = node.castShadow = true;
46+
}
47+
});
48+
49+
return scene;
50+
});
51+
52+
constructor() {
53+
const scrollControls = inject(NgtsScrollControls);
54+
const animations = injectAnimations(this.gltf, this.scene);
55+
56+
injectBeforeRender(({ delta, camera }) => {
57+
const action = animations.actions['Take 001'];
58+
if (!action) return;
59+
60+
if (!action.paused) {
61+
action.play().paused = true;
62+
}
63+
64+
const offset = 1 - scrollControls.offset;
65+
action.time = MathUtils.damp(action.time, (action.getClip().duration / 2) * offset, 100, delta);
66+
camera.position.set(
67+
Math.sin(offset) * -10,
68+
Math.atan(offset * Math.PI * 2) * 5,
69+
Math.cos((offset * Math.PI) / 3) * -10,
70+
);
71+
camera.lookAt(0, 0, 0);
72+
});
73+
}
74+
}
75+
76+
@Component({
77+
standalone: true,
78+
template: `
79+
<ngt-fog *args="['#ff5020', 5, 18]" attach="fog" />
80+
<ngt-ambient-light [intensity]="0.03" />
81+
<ngt-spot-light
82+
[angle]="0.14"
83+
color="#ffd0d0"
84+
[penumbra]="1"
85+
[position]="[25, 50, -20]"
86+
[castShadow]="true"
87+
[intensity]="Math.PI"
88+
[decay]="0"
89+
>
90+
<ngt-value [rawValue]="-0.0001" attach="shadow.bias" />
91+
<ngt-vector2 *args="[2048, 2048]" attach="shadow.mapSize" />
92+
</ngt-spot-light>
93+
<ngts-sky [options]="{ scale: 1000, sunPosition: [2, 0.4, 10] }" />
94+
95+
<ngts-scroll-controls [options]="{ pages: 3 }">
96+
<scroll-littlest-tokyo />
97+
</ngts-scroll-controls>
98+
`,
99+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
100+
imports: [NgtArgs, NgtsSky, NgtsScrollControls, LittlestTokyo],
101+
changeDetection: ChangeDetectionStrategy.OnPush,
102+
})
103+
class LittlestTokyoStory {
104+
protected readonly Math = Math;
105+
}
12106

13107
@Component({
14108
selector: 'scroll-suzanne',
@@ -152,3 +246,9 @@ export const InsideAContainer = makeStoryObject(DefaultScrollControlsStory, {
152246
},
153247
},
154248
});
249+
250+
export const Model = makeStoryFunction(LittlestTokyoStory, {
251+
camera: { position: [0, 0, 10] },
252+
lights: false,
253+
controls: false,
254+
});

0 commit comments

Comments
 (0)