|
| 1 | +import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core'; |
| 2 | +import { Meta, moduleMetadata } from '@storybook/angular'; |
| 3 | +import { NgtArgs, NgtBeforeRenderEvent } from 'angular-three'; |
| 4 | +import { NgtsOrbitControls } from 'angular-three-soba/controls'; |
| 5 | +import { NgtsCameraShake } from 'angular-three-soba/staging'; |
| 6 | +import * as THREE from 'three'; |
| 7 | +import { makeStoryObject, number, StorybookSetup } from '../setup-canvas'; |
| 8 | + |
| 9 | +const numberArgs = number(0.05, { range: true, max: 1, min: 0, step: 0.05 }); |
| 10 | +const frequencyArgs = number(0.8, { range: true, max: 10, min: 0, step: 0.1 }); |
| 11 | +const argsOptions = { |
| 12 | + maxPitch: numberArgs, |
| 13 | + maxRoll: numberArgs, |
| 14 | + maxYaw: numberArgs, |
| 15 | + pitchFrequency: frequencyArgs, |
| 16 | + rollFrequency: frequencyArgs, |
| 17 | + yawFrequency: frequencyArgs, |
| 18 | +}; |
| 19 | + |
| 20 | +@Component({ |
| 21 | + selector: 'CameraShakeScene', |
| 22 | + standalone: true, |
| 23 | + template: ` |
| 24 | + <ngt-mesh (beforeRender)="onBeforeRender($event)"> |
| 25 | + <ngt-box-geometry *args="[2, 2, 2]" /> |
| 26 | + <ngt-mesh-standard-material [wireframe]="true" /> |
| 27 | + </ngt-mesh> |
| 28 | + <ngt-mesh [position]="[0, -6, 0]" [rotation]="[Math.PI / -2, 0, 0]"> |
| 29 | + <ngt-plane-geometry *args="[200, 200, 75, 75]" /> |
| 30 | + <ngt-mesh-basic-material [wireframe]="true" color="red" [side]="DoubleSide" /> |
| 31 | + </ngt-mesh> |
| 32 | + `, |
| 33 | + imports: [NgtArgs], |
| 34 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 35 | +}) |
| 36 | +class Scene { |
| 37 | + readonly Math = Math; |
| 38 | + readonly DoubleSide = THREE.DoubleSide; |
| 39 | + |
| 40 | + onBeforeRender({ object: mesh }: NgtBeforeRenderEvent<THREE.Mesh>) { |
| 41 | + mesh.rotation.x = mesh.rotation.y += 0.01; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +@Component({ |
| 46 | + standalone: true, |
| 47 | + template: ` |
| 48 | + <ngts-orbit-controls [makeDefault]="true" /> |
| 49 | + <ngts-camera-shake |
| 50 | + [maxPitch]="maxPitch" |
| 51 | + [maxRoll]="maxRoll" |
| 52 | + [maxYaw]="maxYaw" |
| 53 | + [pitchFrequency]="pitchFrequency" |
| 54 | + [rollFrequency]="rollFrequency" |
| 55 | + [yawFrequency]="yawFrequency" |
| 56 | + /> |
| 57 | + <CameraShakeScene /> |
| 58 | + `, |
| 59 | + imports: [NgtsCameraShake, Scene, NgtsOrbitControls], |
| 60 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 61 | +}) |
| 62 | +class WithOrbitControlsStory { |
| 63 | + @Input() maxPitch = argsOptions.maxPitch.defaultValue; |
| 64 | + @Input() maxRoll = argsOptions.maxRoll.defaultValue; |
| 65 | + @Input() maxYaw = argsOptions.maxYaw.defaultValue; |
| 66 | + @Input() pitchFrequency = argsOptions.pitchFrequency.defaultValue; |
| 67 | + @Input() rollFrequency = argsOptions.rollFrequency.defaultValue; |
| 68 | + @Input() yawFrequency = argsOptions.yawFrequency.defaultValue; |
| 69 | +} |
| 70 | + |
| 71 | +@Component({ |
| 72 | + standalone: true, |
| 73 | + template: ` |
| 74 | + <ngts-camera-shake |
| 75 | + [maxPitch]="maxPitch" |
| 76 | + [maxRoll]="maxRoll" |
| 77 | + [maxYaw]="maxYaw" |
| 78 | + [pitchFrequency]="pitchFrequency" |
| 79 | + [rollFrequency]="rollFrequency" |
| 80 | + [yawFrequency]="yawFrequency" |
| 81 | + /> |
| 82 | + <CameraShakeScene /> |
| 83 | + `, |
| 84 | + imports: [NgtsCameraShake, Scene], |
| 85 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 86 | +}) |
| 87 | +class DefaultCameraShakeStory { |
| 88 | + @Input() maxPitch = argsOptions.maxPitch.defaultValue; |
| 89 | + @Input() maxRoll = argsOptions.maxRoll.defaultValue; |
| 90 | + @Input() maxYaw = argsOptions.maxYaw.defaultValue; |
| 91 | + @Input() pitchFrequency = argsOptions.pitchFrequency.defaultValue; |
| 92 | + @Input() rollFrequency = argsOptions.rollFrequency.defaultValue; |
| 93 | + @Input() yawFrequency = argsOptions.yawFrequency.defaultValue; |
| 94 | +} |
| 95 | + |
| 96 | +export default { |
| 97 | + title: 'Staging/Camera Shake', |
| 98 | + decorators: [moduleMetadata({ imports: [StorybookSetup] })], |
| 99 | +} as Meta; |
| 100 | + |
| 101 | +export const Default = makeStoryObject(DefaultCameraShakeStory, { |
| 102 | + canvasOptions: { camera: { position: [0, 0, 10] }, controls: false }, |
| 103 | + argsOptions, |
| 104 | +}); |
| 105 | + |
| 106 | +export const WithOrbitControls = makeStoryObject(WithOrbitControlsStory, { |
| 107 | + canvasOptions: { camera: { position: [0, 0, 10] }, controls: false }, |
| 108 | + argsOptions, |
| 109 | +}); |
0 commit comments