|
| 1 | +import { NgIf } from '@angular/common'; |
| 2 | +import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core'; |
| 3 | +import { Meta } from '@storybook/angular'; |
| 4 | +import { NgtArgs } from 'angular-three'; |
| 5 | +import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras'; |
| 6 | +import { NgtsOrbitControls } from 'angular-three-soba/controls'; |
| 7 | +import { ENVIRONMENT_PRESETS, NgtsContactShadows, NgtsEnvironment } from 'angular-three-soba/staging'; |
| 8 | +import { makeDecorators, makeStoryObject, number, select } from '../setup-canvas'; |
| 9 | + |
| 10 | +const presets = Object.keys(ENVIRONMENT_PRESETS); |
| 11 | + |
| 12 | +const preset = select('park', { options: presets }); |
| 13 | +const height = number(15, { range: true, min: 0, max: 50, step: 0.1 }); |
| 14 | +const radius = number(60, { range: true, min: 0, max: 200, step: 1 }); |
| 15 | +const blur = number(0, { range: true, min: 0, max: 1, step: 0.01 }); |
| 16 | +const defaultPreset = select(presets[0], { options: presets }); |
| 17 | + |
| 18 | +@Component({ |
| 19 | + standalone: true, |
| 20 | + template: ` |
| 21 | + <ngts-environment [ground]="{ height, radius }" [preset]="preset" /> |
| 22 | + <ngt-mesh [position]="[0, 5, 0]"> |
| 23 | + <ngt-box-geometry *args="[10, 10, 10]" /> |
| 24 | + <ngt-mesh-standard-material [metalness]="1" [roughness]="0" /> |
| 25 | + </ngt-mesh> |
| 26 | + <ngts-contact-shadows |
| 27 | + [resolution]="1024" |
| 28 | + [position]="[0, 0, 0]" |
| 29 | + [scale]="100" |
| 30 | + [blur]="2" |
| 31 | + [opacity]="1" |
| 32 | + [far]="10" |
| 33 | + /> |
| 34 | + <ngts-orbit-controls [autoRotate]="true" /> |
| 35 | + <ngts-perspective-camera [position]="[40, 40, 40]" [makeDefault]="true" /> |
| 36 | + `, |
| 37 | + imports: [NgtsEnvironment, NgtsOrbitControls, NgtsPerspectiveCamera, NgtsContactShadows, NgtArgs], |
| 38 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 39 | +}) |
| 40 | +class GroundEnvironmentStory { |
| 41 | + @Input() preset = preset.defaultValue; |
| 42 | + @Input() height = height.defaultValue; |
| 43 | + @Input() radius = radius.defaultValue; |
| 44 | +} |
| 45 | + |
| 46 | +@Component({ |
| 47 | + standalone: true, |
| 48 | + template: ` |
| 49 | + <ngts-environment |
| 50 | + [background]="background" |
| 51 | + [path]="'soba/cube/'" |
| 52 | + [files]="['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']" |
| 53 | + /> |
| 54 | + <ngt-mesh> |
| 55 | + <ngt-torus-knot-geometry *args="[1, 0.5, 128, 32]" /> |
| 56 | + <ngt-mesh-standard-material [metalness]="1" [roughness]="0" /> |
| 57 | + </ngt-mesh> |
| 58 | + <ngts-orbit-controls [autoRotate]="true" /> |
| 59 | + `, |
| 60 | + imports: [NgtsEnvironment, NgtsOrbitControls, NgtArgs], |
| 61 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 62 | +}) |
| 63 | +class FilesEnvironmentStory { |
| 64 | + @Input() background = true; |
| 65 | +} |
| 66 | + |
| 67 | +@Component({ |
| 68 | + standalone: true, |
| 69 | + template: ` |
| 70 | + <ngts-environment [background]="background" [preset]="preset" [blur]="blur" /> |
| 71 | + <ngt-mesh> |
| 72 | + <ngt-torus-knot-geometry *args="[1, 0.5, 128, 32]" /> |
| 73 | + <ngt-mesh-standard-material [metalness]="1" [roughness]="0" /> |
| 74 | + </ngt-mesh> |
| 75 | + <ngts-orbit-controls [autoRotate]="true" /> |
| 76 | + `, |
| 77 | + imports: [NgtsEnvironment, NgtsOrbitControls, NgtArgs, NgIf], |
| 78 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 79 | +}) |
| 80 | +class DefaultEnvironmentStory { |
| 81 | + @Input() background = true; |
| 82 | + @Input() preset = defaultPreset.defaultValue; |
| 83 | + @Input() blur = blur.defaultValue; |
| 84 | +} |
| 85 | + |
| 86 | +export default { |
| 87 | + title: 'Staging/Environment', |
| 88 | + decorators: makeDecorators(), |
| 89 | +} as Meta; |
| 90 | + |
| 91 | +export const Default = makeStoryObject(DefaultEnvironmentStory, { |
| 92 | + canvasOptions: { controls: false, camera: { position: [0, 0, 10] } }, |
| 93 | + argsOptions: { background: true, blur, preset: defaultPreset }, |
| 94 | +}); |
| 95 | + |
| 96 | +export const Files = makeStoryObject(FilesEnvironmentStory, { |
| 97 | + canvasOptions: { controls: false, camera: { position: [0, 0, 10] } }, |
| 98 | + argsOptions: { background: true }, |
| 99 | +}); |
| 100 | + |
| 101 | +export const Ground = makeStoryObject(GroundEnvironmentStory, { |
| 102 | + canvasOptions: { controls: false, camera: { position: [0, 0, 10] } }, |
| 103 | + argsOptions: { preset, height, radius }, |
| 104 | +}); |
0 commit comments