Skip to content

Commit 4c61180

Browse files
committed
lod/detailed/statsgl
1 parent 4470a8e commit 4c61180

File tree

20 files changed

+295
-7
lines changed

20 files changed

+295
-7
lines changed

apps/kitchen-sink/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
}
2222
],
2323
"styles": ["apps/kitchen-sink/src/styles.css"],
24-
"scripts": [],
25-
"externalDependencies": ["three/examples/jsm/utils/BufferGeometryUtils", "three/examples/jsm/postprocessing/Pass"]
24+
"scripts": []
2625
},
2726
"configurations": {
2827
"production": {
@@ -38,6 +37,7 @@
3837
"maximumError": "4kb"
3938
}
4039
],
40+
"externalDependencies": ["three/examples/jsm/utils/BufferGeometryUtils", "three/examples/jsm/postprocessing/Pass"],
4141
"outputHashing": "all"
4242
},
4343
"development": {

apps/kitchen-sink/public/bust-1-d.glb

529 KB
Binary file not shown.

apps/kitchen-sink/public/bust-2-d.glb

15.7 KB
Binary file not shown.

apps/kitchen-sink/public/bust-3-d.glb

5.39 KB
Binary file not shown.

apps/kitchen-sink/public/bust-4-d.glb

2.32 KB
Binary file not shown.

apps/kitchen-sink/public/bust-5-d.glb

1.27 KB
Binary file not shown.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, input, Signal } from '@angular/core';
2+
import { NgtEuler, NgtVector3 } from 'angular-three';
3+
import { NgtsOrbitControls } from 'angular-three-soba/controls';
4+
import { injectGLTF } from 'angular-three-soba/loaders';
5+
import { NgtsBakeShadows } from 'angular-three-soba/misc';
6+
import { NgtsDetailed } from 'angular-three-soba/performances';
7+
import { NgtsEnvironment } from 'angular-three-soba/staging';
8+
import { Mesh, MeshStandardMaterial } from 'three';
9+
import { GLTF } from 'three-stdlib';
10+
11+
const positions = [...Array(800)].map(() => ({
12+
position: [40 - Math.random() * 80, 40 - Math.random() * 80, 40 - Math.random() * 80],
13+
rotation: [Math.random() * Math.PI * 2, Math.random() * Math.PI * 2, Math.random() * Math.PI * 2],
14+
})) as Array<{ position: [number, number, number]; rotation: [number, number, number] }>;
15+
16+
interface BustGLTF extends GLTF {
17+
nodes: { Mesh_0001: Mesh };
18+
materials: { default: MeshStandardMaterial };
19+
}
20+
21+
@Component({
22+
selector: 'app-bust',
23+
standalone: true,
24+
template: `
25+
<ngts-detailed [distances]="[0, 15, 25, 35, 100]" [options]="{ position: position(), rotation: rotation() }">
26+
@for (level of gltfs() || []; track $index) {
27+
<ngt-mesh
28+
[receiveShadow]="true"
29+
[castShadow]="true"
30+
[geometry]="level.nodes.Mesh_0001.geometry"
31+
[material]="level.materials.default"
32+
>
33+
<ngt-value [rawValue]="0.25" attach="material.envMapIntensity" />
34+
</ngt-mesh>
35+
}
36+
</ngts-detailed>
37+
`,
38+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
39+
changeDetection: ChangeDetectionStrategy.OnPush,
40+
imports: [NgtsDetailed],
41+
})
42+
export class LODBust {
43+
position = input<NgtVector3>([0, 0, 0]);
44+
rotation = input<NgtEuler>([0, 0, 0]);
45+
46+
gltfs = injectGLTF(() => [
47+
'./bust-1-d.glb',
48+
'./bust-2-d.glb',
49+
'./bust-3-d.glb',
50+
'./bust-4-d.glb',
51+
'./bust-5-d.glb',
52+
]) as Signal<BustGLTF[] | null>;
53+
}
54+
55+
@Component({
56+
standalone: true,
57+
template: `
58+
@for (p of positions; track $index) {
59+
<app-bust [position]="p.position" [rotation]="p.rotation" />
60+
}
61+
<ngts-orbit-controls [options]="{ autoRotate: true, autoRotateSpeed: 0.5, zoomSpeed: 0.075 }" />
62+
<ngt-point-light [intensity]="0.5 * Math.PI" [decay]="0" />
63+
<ngt-spot-light [position]="50" [intensity]="1.5 * Math.PI" [castShadow]="true" [decay]="0" />
64+
<ngts-environment [options]="{ preset: 'city' }" />
65+
<ngts-bake-shadows />
66+
`,
67+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
68+
changeDetection: ChangeDetectionStrategy.OnPush,
69+
imports: [NgtsBakeShadows, NgtsEnvironment, NgtsOrbitControls, LODBust],
70+
})
71+
export class Experience {
72+
protected readonly Math = Math;
73+
protected readonly positions = positions;
74+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { NgtCanvas } from 'angular-three';
3+
import { NgtsLoader } from 'angular-three-soba/loaders';
4+
import { NgtsStats } from 'angular-three-soba/stats';
5+
import { Experience } from './experience';
6+
7+
@Component({
8+
standalone: true,
9+
template: `
10+
<ngt-canvas stats [sceneGraph]="scene" frameloop="demand" [camera]="{ position: [0, 0, 40] }" />
11+
<ngts-loader />
12+
`,
13+
changeDetection: ChangeDetectionStrategy.OnPush,
14+
imports: [NgtCanvas, NgtsLoader, NgtsStats],
15+
})
16+
export default class LOD {
17+
scene = Experience;
18+
}

apps/kitchen-sink/src/app/soba/shaky/shaky.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { NgtCanvas } from 'angular-three';
3+
import { NgtsStats } from 'angular-three-soba/stats';
34
import { Experience } from './experience';
45

56
@Component({
67
standalone: true,
78
template: `
8-
<ngt-canvas [sceneGraph]="scene" [shadows]="true" [camera]="{ position: [0, 160, 160], fov: 20 }" [dpr]="[1, 2]" />
9+
<ngt-canvas
10+
[stats]="{ minimal: true }"
11+
[sceneGraph]="scene"
12+
[shadows]="true"
13+
[camera]="{ position: [0, 160, 160], fov: 20 }"
14+
[dpr]="[1, 2]"
15+
/>
916
`,
10-
imports: [NgtCanvas],
17+
imports: [NgtCanvas, NgtsStats],
1118
changeDetection: ChangeDetectionStrategy.OnPush,
1219
host: { class: 'shaky-soba' },
1320
styles: `

apps/kitchen-sink/src/app/soba/soba.routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const routes: Routes = [
1717
path: 'shaky',
1818
loadComponent: () => import('./shaky/shaky'),
1919
},
20+
{
21+
path: 'lod',
22+
loadComponent: () => import('./lod/lod'),
23+
},
2024
{
2125
path: '',
2226
redirectTo: 'basic',

0 commit comments

Comments
 (0)