|
| 1 | +import { RouteMeta } from '@analogjs/router'; |
| 2 | +import { NgFor } from '@angular/common'; |
| 3 | +import { Component, computed, CUSTOM_ELEMENTS_SCHEMA, Input, Signal } from '@angular/core'; |
| 4 | +import { NgtArgs, NgtCanvas } from 'angular-three'; |
| 5 | +import { NgtsOrbitControls } from 'angular-three-soba/controls'; |
| 6 | +import { injectNgtsGLTFLoader, NgtsLoader } from 'angular-three-soba/loaders'; |
| 7 | +import { NgtsBakeShadows } from 'angular-three-soba/misc'; |
| 8 | +import { NgtsDetailed, NgtsStats } from 'angular-three-soba/performance'; |
| 9 | +import { NgtsEnvironment } from 'angular-three-soba/staging'; |
| 10 | +import { GLTF } from 'three-stdlib'; |
| 11 | + |
| 12 | +export const routeMeta: RouteMeta = { |
| 13 | + title: 'Level of Details', |
| 14 | +}; |
| 15 | + |
| 16 | +const positions = [...Array(800)].map(() => ({ |
| 17 | + position: [40 - Math.random() * 80, 40 - Math.random() * 80, 40 - Math.random() * 80], |
| 18 | + rotation: [Math.random() * Math.PI * 2, Math.random() * Math.PI * 2, Math.random() * Math.PI * 2], |
| 19 | +})) as Array<{ position: [number, number, number]; rotation: [number, number, number] }>; |
| 20 | + |
| 21 | +interface BustGLTF extends GLTF { |
| 22 | + nodes: { Mesh_0001: THREE.Mesh }; |
| 23 | + materials: { default: THREE.MeshStandardMaterial }; |
| 24 | +} |
| 25 | + |
| 26 | +@Component({ |
| 27 | + selector: 'lod-bust', |
| 28 | + standalone: true, |
| 29 | + templateUrl: 'lod-bust.html', |
| 30 | + imports: [NgtsDetailed, NgFor, NgtArgs], |
| 31 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 32 | +}) |
| 33 | +class LodBust { |
| 34 | + @Input() position: [number, number, number] = [0, 0, 0]; |
| 35 | + @Input() rotation: [number, number, number] = [0, 0, 0]; |
| 36 | + |
| 37 | + readonly #gltfs = injectNgtsGLTFLoader(() => [ |
| 38 | + 'bust-1-d.glb', |
| 39 | + 'bust-2-d.glb', |
| 40 | + 'bust-3-d.glb', |
| 41 | + 'bust-4-d.glb', |
| 42 | + 'bust-5-d.glb', |
| 43 | + ]) as Signal<BustGLTF[]>; |
| 44 | + readonly levels = computed(() => this.#gltfs() || []); |
| 45 | +} |
| 46 | + |
| 47 | +@Component({ |
| 48 | + standalone: true, |
| 49 | + templateUrl: 'scene.html', |
| 50 | + imports: [LodBust, NgFor, NgtsOrbitControls, NgtsEnvironment, NgtsBakeShadows], |
| 51 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 52 | +}) |
| 53 | +class SceneGraph { |
| 54 | + readonly positions = positions; |
| 55 | +} |
| 56 | + |
| 57 | +@Component({ |
| 58 | + standalone: true, |
| 59 | + templateUrl: 'index.html', |
| 60 | + imports: [NgtCanvas, NgtsStats, NgtsLoader], |
| 61 | +}) |
| 62 | +export default class LevelOfDetails { |
| 63 | + readonly scene = SceneGraph; |
| 64 | +} |
0 commit comments