Skip to content

Commit d7b342e

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
docs: migrate lod
1 parent 8e66e23 commit d7b342e

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

apps/sandbox/src/app/pages/keen/scene.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ngtp-effect-composer>
1515
<ngtp-bloom [intensity]="5" />
16-
<ngtp-dot-screen [scale]="3" />
16+
<!-- <ngtp-dot-screen [scale]="3" /> -->
1717
</ngtp-effect-composer>
1818

1919
<ngts-orbit-controls />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<ngt-canvas [sceneGraph]="scene" frameloop="demand" [camera]="{position: [0, 0, 40]}" />
2+
<ngts-stats [right]="true" />
3+
<ngts-loader />
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<ngts-detailed [distances]="[0, 15, 25, 35, 100]" [position]="position" [rotation]="rotation">
2+
<ngt-mesh
3+
*ngFor="let level of levels()"
4+
[receiveShadow]="true"
5+
[castShadow]="true"
6+
[geometry]="level.nodes.Mesh_0001.geometry"
7+
[material]="level.materials.default"
8+
>
9+
<ngt-value [rawValue]="0.25" attach="material.envMapIntensity" />
10+
</ngt-mesh>
11+
</ngts-detailed>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<lod-bust *ngFor="let p of positions" [position]="p.position" [rotation]="p.rotation" />
2+
<ngts-orbit-controls [zoomSpeed]="0.075" />
3+
<ngt-point-light [position]="0" [intensity]="0.5" />
4+
<ngt-spot-light [position]="50" [intensity]="2.5" [castShadow]="true" />
5+
<ngts-environment preset="city" />
6+
<ngts-bake-shadows />

0 commit comments

Comments
 (0)