|
| 1 | +import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, input, type Signal } from '@angular/core'; |
| 2 | +import { NgtArgs } from 'angular-three'; |
| 3 | +import { NgtsGrid } from 'angular-three-soba/abstractions'; |
| 4 | +import { NgtsOrbitControls } from 'angular-three-soba/controls'; |
| 5 | +import { injectGLTF } from 'angular-three-soba/loaders'; |
| 6 | +import { NgtsAccumulativeShadows, NgtsCenter, NgtsEnvironment, NgtsRandomizedLights } from 'angular-three-soba/staging'; |
| 7 | +import { Mesh } from 'three'; |
| 8 | +import type { GLTF } from 'three-stdlib'; |
| 9 | + |
| 10 | +type SuzanneGLTF = GLTF & { |
| 11 | + nodes: { Suzanne: Mesh }; |
| 12 | + materials: {}; |
| 13 | +}; |
| 14 | + |
| 15 | +@Component({ |
| 16 | + selector: 'grid-suzi', |
| 17 | + standalone: true, |
| 18 | + template: ` |
| 19 | + @if (gltf(); as gltf) { |
| 20 | + <ngt-mesh |
| 21 | + [geometry]="gltf.nodes.Suzanne.geometry" |
| 22 | + [castShadow]="true" |
| 23 | + [receiveShadow]="true" |
| 24 | + [rotation]="rotation()" |
| 25 | + [scale]="scale()" |
| 26 | + > |
| 27 | + <ngt-mesh-standard-material color="#9d4b4b" /> |
| 28 | + </ngt-mesh> |
| 29 | + } |
| 30 | + `, |
| 31 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 32 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 33 | +}) |
| 34 | +export class Suzi { |
| 35 | + gltf = injectGLTF( |
| 36 | + () => 'https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/suzanne-high-poly/model.gltf', |
| 37 | + ) as Signal<SuzanneGLTF | null>; |
| 38 | + |
| 39 | + rotation = input([0, 0, 0]); |
| 40 | + scale = input(1); |
| 41 | +} |
| 42 | + |
| 43 | +@Component({ |
| 44 | + selector: 'grid-shadows', |
| 45 | + standalone: true, |
| 46 | + template: ` |
| 47 | + <ngts-accumulative-shadows |
| 48 | + [options]="{ temporal: true, frames: 100, color: '#9d4b4b', colorBlend: 0.5, alphaTest: 0.75, scale: 20 }" |
| 49 | + > |
| 50 | + <ngts-randomized-lights [options]="{ amount: 8, radius: 4, position: [5, 5, -10] }" /> |
| 51 | + </ngts-accumulative-shadows> |
| 52 | + `, |
| 53 | + imports: [NgtsAccumulativeShadows, NgtsRandomizedLights], |
| 54 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 55 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 56 | +}) |
| 57 | +export class Shadows {} |
| 58 | + |
| 59 | +@Component({ |
| 60 | + standalone: true, |
| 61 | + template: ` |
| 62 | + <ngt-group [position]="[0, -0.5, 0]"> |
| 63 | + <ngts-center [options]="{ top: true }"> |
| 64 | + <grid-suzi [rotation]="[-0.63, 0, 0]" [scale]="2" /> |
| 65 | + </ngts-center> |
| 66 | +
|
| 67 | + <ngts-center [options]="{ top: true, position: [-2, 0, 2] }"> |
| 68 | + <ngt-mesh [castShadow]="true"> |
| 69 | + <ngt-sphere-geometry *args="[0.5, 64, 64]" /> |
| 70 | + <ngt-mesh-standard-material color="#9d4b4b" /> |
| 71 | + </ngt-mesh> |
| 72 | + </ngts-center> |
| 73 | +
|
| 74 | + <ngts-center [options]="{ top: true, position: [2.5, 0, 1] }"> |
| 75 | + <ngt-mesh [castShadow]="true" [rotation]="[0, Math.PI / 4, 0]"> |
| 76 | + <ngt-box-geometry *args="[0.7, 0.7, 0.7]" /> |
| 77 | + <ngt-mesh-standard-material color="#9d4b4b" /> |
| 78 | + </ngt-mesh> |
| 79 | + </ngts-center> |
| 80 | +
|
| 81 | + <grid-shadows /> |
| 82 | +
|
| 83 | + <ngts-grid |
| 84 | + [options]="{ |
| 85 | + planeArgs: [10.5, 10.5], |
| 86 | + position: [0, -0.01, 0], |
| 87 | + cellSize: 0.6, |
| 88 | + cellThickness: 1, |
| 89 | + cellColor: '#6f6f6f', |
| 90 | + sectionSize: 3.3, |
| 91 | + sectionThickness: 1.5, |
| 92 | + sectionColor: '#9d4b4b', |
| 93 | + fadeDistance: 25, |
| 94 | + fadeStrength: 1, |
| 95 | + followCamera: false, |
| 96 | + infiniteGrid: true, |
| 97 | + }" |
| 98 | + /> |
| 99 | + </ngt-group> |
| 100 | + <ngts-orbit-controls [options]="{ makeDefault: true }" /> |
| 101 | + <ngts-environment [options]="{ preset: 'city' }" /> |
| 102 | + `, |
| 103 | + imports: [Suzi, Shadows, NgtsOrbitControls, NgtsEnvironment, NgtsCenter, NgtArgs, NgtsGrid], |
| 104 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 105 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 106 | +}) |
| 107 | +export default class GridScene { |
| 108 | + Math = Math; |
| 109 | +} |
| 110 | + |
| 111 | +// export const Default = makeStoryFunction(DefaultGridStory, { |
| 112 | +// camera: { position: [10, 12, 12], fov: 25 }, |
| 113 | +// lights: false, |
| 114 | +// controls: false, |
| 115 | +// background: '#303035', |
| 116 | +// }); |
0 commit comments