|
| 1 | +import { Component, computed, CUSTOM_ELEMENTS_SCHEMA, effect, Signal } from '@angular/core'; |
| 2 | +import { Meta } from '@storybook/angular'; |
| 3 | +import { applyProps, NgtArgs } from 'angular-three'; |
| 4 | +import { NgtsOrbitControls } from 'angular-three-soba/controls'; |
| 5 | +import { injectNgtsGLTFLoader, NgtsGLTF } from 'angular-three-soba/loaders'; |
| 6 | +import { NgtsAccumulativeShadows, NgtsEnvironment, NgtsRandomizedLights } from 'angular-three-soba/staging'; |
| 7 | +import * as THREE from 'three'; |
| 8 | +import { FlakesTexture } from 'three/examples/jsm/textures/FlakesTexture'; |
| 9 | +import { makeDecorators, makeStoryFunction } from '../setup-canvas'; |
| 10 | + |
| 11 | +injectNgtsGLTFLoader.preload( |
| 12 | + () => 'https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/suzanne-high-poly/model.gltf', |
| 13 | +); |
| 14 | + |
| 15 | +type SuziGLTF = NgtsGLTF<{ materials: { default: THREE.MeshStandardMaterial } }>; |
| 16 | + |
| 17 | +@Component({ |
| 18 | + selector: 'accumulative-shadows-suzi', |
| 19 | + standalone: true, |
| 20 | + template: ` <ngt-primitive ngtCompound *args="[model()]" /> `, |
| 21 | + imports: [NgtArgs], |
| 22 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 23 | +}) |
| 24 | +class Suzi { |
| 25 | + private suziGLTF = injectNgtsGLTFLoader( |
| 26 | + () => 'https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/suzanne-high-poly/model.gltf', |
| 27 | + ) as Signal<SuziGLTF>; |
| 28 | + model = computed(() => { |
| 29 | + const suzi = this.suziGLTF(); |
| 30 | + if (!suzi) return null; |
| 31 | + return suzi.scene; |
| 32 | + }); |
| 33 | + |
| 34 | + constructor() { |
| 35 | + effect(() => { |
| 36 | + const suzi = this.suziGLTF(); |
| 37 | + if (!suzi) return; |
| 38 | + const { scene, materials } = suzi; |
| 39 | + scene.traverse((obj: any) => obj.isMesh && (obj.receiveShadow = obj.castShadow = true)); |
| 40 | + applyProps(materials.default, { |
| 41 | + color: 'orange', |
| 42 | + roughness: 0, |
| 43 | + normalMap: new THREE.CanvasTexture( |
| 44 | + new FlakesTexture(), |
| 45 | + THREE.UVMapping, |
| 46 | + THREE.RepeatWrapping, |
| 47 | + THREE.RepeatWrapping, |
| 48 | + ), |
| 49 | + normalScale: [0.05, 0.05], |
| 50 | + }); |
| 51 | + applyProps(materials.default.normalMap, { |
| 52 | + flipY: false, |
| 53 | + repeat: [40, 40], |
| 54 | + }); |
| 55 | + }); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +@Component({ |
| 60 | + standalone: true, |
| 61 | + template: ` |
| 62 | + <ngt-color *args="['goldenrod']" attach="background" /> |
| 63 | +
|
| 64 | + <accumulative-shadows-suzi [rotation]="[-0.63, 0, 0]" [scale]="2" [position]="[0, -1.175, 0]" /> |
| 65 | + <ngts-accumulative-shadows |
| 66 | + color="goldenrod" |
| 67 | + [temporal]="true" |
| 68 | + [frames]="100" |
| 69 | + [alphaTest]="0.65" |
| 70 | + [opacity]="2" |
| 71 | + [scale]="14" |
| 72 | + [position]="[0, -0.5, 0]" |
| 73 | + > |
| 74 | + <ngts-randomized-lights [amount]="8" [radius]="4" [ambient]="0.5" [bias]="0.001" [position]="[5, 5, -10]" /> |
| 75 | + </ngts-accumulative-shadows> |
| 76 | + <ngts-orbit-controls [autoRotate]="true" /> |
| 77 | + <ngts-environment preset="city" /> |
| 78 | + `, |
| 79 | + imports: [NgtsAccumulativeShadows, NgtsRandomizedLights, NgtsOrbitControls, NgtsEnvironment, NgtArgs, Suzi], |
| 80 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 81 | +}) |
| 82 | +class DefaultAccumulativeShadowsStory {} |
| 83 | + |
| 84 | +export default { |
| 85 | + title: 'Staging/Accumulative Shadows', |
| 86 | + decorators: makeDecorators(), |
| 87 | +} as Meta; |
| 88 | + |
| 89 | +export const Default = makeStoryFunction(DefaultAccumulativeShadowsStory, { |
| 90 | + compoundPrefixes: ['accumulative-shadows-suzi'], |
| 91 | + // NOTE: only works with this |
| 92 | + useLegacyLights: true, |
| 93 | +}); |
0 commit comments