Skip to content

Commit 7c6eab4

Browse files
committed
docs(examples): add baking soft shadows demo
1 parent cebdc38 commit 7c6eab4

File tree

6 files changed

+262
-1
lines changed

6 files changed

+262
-1
lines changed

apps/examples/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"scripts": [],
2525
"loader": {
2626
".blob": "file",
27-
".glb": "file"
27+
".glb": "file",
28+
".gltf": "file"
2829
}
2930
},
3031
"configurations": {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { NgtCanvas, NgtCanvasContent } from 'angular-three/dom';
3+
import { SceneGraph } from './scene';
4+
5+
@Component({
6+
template: `
7+
<ngt-canvas shadows [camera]="{ position: [4, 2.5, 8], fov: 35 }">
8+
<app-scene-graph *canvasContent />
9+
</ngt-canvas>
10+
`,
11+
changeDetection: ChangeDetectionStrategy.OnPush,
12+
imports: [NgtCanvas, NgtCanvasContent, SceneGraph],
13+
host: { class: 'baking-soft-shadows' },
14+
})
15+
export default class BakingSoftShadows {}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { ChangeDetectionStrategy, Component, computed, CUSTOM_ELEMENTS_SCHEMA, input } from '@angular/core';
2+
import { is, NgtArgs, NgtThreeElements } from 'angular-three';
3+
import { NgtsOrbitControls } from 'angular-three-soba/controls';
4+
import { injectGLTF } from 'angular-three-soba/loaders';
5+
import { NgtsAccumulativeShadows, NgtsCenter, NgtsEnvironment, NgtsRandomizedLights } from 'angular-three-soba/staging';
6+
import * as THREE from 'three';
7+
import { FlakesTexture, GLTF } from 'three-stdlib';
8+
import suziGLTF from './suzi.gltf';
9+
10+
interface SuziGLTF extends GLTF {
11+
materials: {
12+
default: THREE.MeshStandardMaterial;
13+
};
14+
}
15+
16+
@Component({
17+
selector: 'app-suzi',
18+
template: `
19+
<ngt-primitive *args="[scene()]" [parameters]="options()" />
20+
`,
21+
imports: [NgtArgs],
22+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
23+
changeDetection: ChangeDetectionStrategy.OnPush,
24+
})
25+
export class Suzi {
26+
options = input<Partial<NgtThreeElements['ngt-group']>>({});
27+
protected gltf = injectGLTF<SuziGLTF>(() => suziGLTF);
28+
29+
protected scene = computed(() => {
30+
const gltf = this.gltf();
31+
if (!gltf) return null;
32+
33+
const { scene, materials } = gltf;
34+
35+
scene.traverse((obj) => {
36+
if (is.three<THREE.Mesh>(obj, 'isMesh')) {
37+
obj.receiveShadow = obj.castShadow = true;
38+
}
39+
});
40+
41+
materials.default.color.set('orange');
42+
materials.default.roughness = 0;
43+
materials.default.normalMap = new THREE.CanvasTexture(
44+
// @ts-expect-error - three-stdlib type
45+
new FlakesTexture(),
46+
THREE.UVMapping,
47+
THREE.RepeatWrapping,
48+
THREE.RepeatWrapping,
49+
);
50+
materials.default.normalMap.repeat.set(40, 40);
51+
materials.default.normalScale.set(0.1, 0.1);
52+
53+
return scene;
54+
});
55+
}
56+
57+
@Component({
58+
selector: 'app-scene-graph',
59+
template: `
60+
<ngt-color *args="['goldenrod']" attach="background" />
61+
62+
<ngt-group [position]="[0, -0.5, 0]">
63+
<ngts-center [options]="{ top: true }">
64+
<app-suzi [options]="{ rotation: [-0.63, 0, 0], scale: 2 }" />
65+
</ngts-center>
66+
67+
<ngts-center [options]="{ top: true, position: [-2, 0, 1] }">
68+
<ngt-mesh castShadow>
69+
<ngt-sphere-geometry *args="[0.25, 64, 64]" />
70+
<ngt-mesh-standard-material color="lightblue" />
71+
</ngt-mesh>
72+
</ngts-center>
73+
74+
<ngts-center [options]="{ top: true, position: [2.5, 0, 1] }">
75+
<ngt-mesh castShadow [rotation]="[0, Math.PI / 4, 0]">
76+
<ngt-box-geometry *args="[0.5, 0.5, 0.5]" />
77+
<ngt-mesh-standard-material color="indianred" />
78+
</ngt-mesh>
79+
</ngts-center>
80+
81+
<ngts-accumulative-shadows
82+
[options]="{
83+
temporal: true,
84+
frames: 100,
85+
color: 'orange',
86+
colorBlend: 2,
87+
toneMapped: true,
88+
alphaTest: 0.75,
89+
opacity: 2,
90+
scale: 12,
91+
}"
92+
>
93+
<ngts-randomized-lights
94+
[options]="{ intensity: Math.PI, amount: 8, radius: 4, ambient: 0.5, position: [5, 5, -10], bias: 0.001 }"
95+
/>
96+
</ngts-accumulative-shadows>
97+
</ngt-group>
98+
99+
<ngts-orbit-controls [options]="{ minPolarAngle: 0, maxPolarAngle: Math.PI / 2 }" />
100+
<ngts-environment [options]="{ preset: 'city' }" />
101+
`,
102+
103+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
104+
changeDetection: ChangeDetectionStrategy.OnPush,
105+
imports: [
106+
NgtsEnvironment,
107+
NgtsOrbitControls,
108+
NgtsAccumulativeShadows,
109+
NgtsRandomizedLights,
110+
NgtsCenter,
111+
NgtArgs,
112+
Suzi,
113+
],
114+
})
115+
export class SceneGraph {
116+
protected readonly Math = Math;
117+
}

apps/examples/src/app/soba/baking-soft-shadows/suzi.gltf

Lines changed: 113 additions & 0 deletions
Large diffs are not rendered by default.

apps/examples/src/app/soba/soba.routes.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ const routes: Routes = [
206206
},
207207
},
208208
},
209+
{
210+
path: 'baking-soft-shadows',
211+
loadComponent: () => import('./baking-soft-shadows/baking-soft-shadows'),
212+
data: {
213+
credits: {
214+
title: 'Baking Soft Shadows',
215+
link: 'https://pmndrs.github.io/examples/demos/baking-soft-shadows',
216+
},
217+
},
218+
},
209219
{
210220
path: '',
211221
redirectTo: 'stars',

apps/examples/src/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ declare module '*.glb' {
77
const url: string;
88
export default url;
99
}
10+
11+
declare module '*.gltf' {
12+
const url: string;
13+
export default url;
14+
}

0 commit comments

Comments
 (0)