|
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'; |
2 | 11 | import { Meta } from '@storybook/angular';
|
3 |
| -import { injectStore, NgtHTML } from 'angular-three'; |
| 12 | +import { injectBeforeRender, injectStore, NgtArgs, NgtHTML } from 'angular-three'; |
4 | 13 | import {
|
5 | 14 | NgtsScrollCanvas,
|
6 | 15 | NgtsScrollControls,
|
7 | 16 | NgtsScrollControlsOptions,
|
8 | 17 | NgtsScrollHtml,
|
9 | 18 | } from 'angular-three-soba/controls';
|
10 | 19 | 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 | +} |
12 | 106 |
|
13 | 107 | @Component({
|
14 | 108 | selector: 'scroll-suzanne',
|
@@ -152,3 +246,9 @@ export const InsideAContainer = makeStoryObject(DefaultScrollControlsStory, {
|
152 | 246 | },
|
153 | 247 | },
|
154 | 248 | });
|
| 249 | + |
| 250 | +export const Model = makeStoryFunction(LittlestTokyoStory, { |
| 251 | + camera: { position: [0, 0, 10] }, |
| 252 | + lights: false, |
| 253 | + controls: false, |
| 254 | +}); |
0 commit comments