Skip to content

Commit 462132d

Browse files
committed
docs: add starbucks example
1 parent 6fb9294 commit 462132d

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed
Loading
Binary file not shown.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const routes: Routes = [
5757
path: 'simple-sound-analyser',
5858
loadComponent: () => import('./simple-sound-analyser/simple-sound-analyser'),
5959
},
60+
{
61+
path: 'starbucks',
62+
loadComponent: () => import('./starbucks/starbucks'),
63+
},
6064
{
6165
path: '',
6266
redirectTo: 'stars',
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
CUSTOM_ELEMENTS_SCHEMA,
5+
effect,
6+
Signal,
7+
signal,
8+
viewChild,
9+
} from '@angular/core';
10+
import { NgtArgs, NgtEuler, NgtVector3 } from 'angular-three';
11+
import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';
12+
import { NgtsOrbitControls, NgtsPivotControls, OnDragParameters } from 'angular-three-soba/controls';
13+
import { injectGLTF, injectTexture } from 'angular-three-soba/loaders';
14+
import { NgtsDecal } from 'angular-three-soba/misc';
15+
import { NgtsAccumulativeShadows, NgtsRandomizedLights } from 'angular-three-soba/staging';
16+
import { Euler, Mesh, MeshStandardMaterial, Quaternion, Vector3 } from 'three';
17+
import { GLTF } from 'three-stdlib';
18+
19+
type CupGLTF = GLTF & {
20+
nodes: { coffee_cup_top_16oz: Mesh };
21+
materials: { ['13 - Default']: MeshStandardMaterial };
22+
};
23+
@Component({
24+
selector: 'app-cup',
25+
standalone: true,
26+
template: `
27+
@if (gltf(); as gltf) {
28+
<ngt-mesh
29+
[castShadow]="true"
30+
[geometry]="gltf.nodes.coffee_cup_top_16oz.geometry"
31+
[material]="gltf.materials['13 - Default']"
32+
[dispose]="null"
33+
[position]="[0, -1, 0]"
34+
[scale]="2"
35+
>
36+
<ngt-value [rawValue]="1" attach="material.aoMapIntensity" />
37+
<ngt-group [position]="[0, 0.75, 0.5]">
38+
<ngts-pivot-controls
39+
[options]="{ activeAxes: [true, true, false], scale: 0.55 }"
40+
(dragged)="onDrag($event)"
41+
/>
42+
</ngt-group>
43+
<ngts-decal
44+
[options]="{
45+
map: logoTexture(),
46+
position: position(),
47+
rotation: rotation(),
48+
scale: scale(),
49+
depthTest: true,
50+
}"
51+
/>
52+
</ngt-mesh>
53+
}
54+
`,
55+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
56+
changeDetection: ChangeDetectionStrategy.OnPush,
57+
imports: [NgtsPivotControls, NgtsDecal],
58+
})
59+
export class Cup {
60+
protected position = signal<NgtVector3>([0, 0.75, 0.3]);
61+
protected rotation = signal<NgtEuler>([0, 0, 0]);
62+
protected scale = signal<NgtVector3>([0.6, 0.6, 0.6]);
63+
64+
protected gltf = injectGLTF(() => './coffee-transformed.glb') as Signal<CupGLTF | null>;
65+
protected logoTexture = injectTexture(() => './1200px-Starbucks_Logo_ab_2011.svg.png');
66+
67+
decal = viewChild(NgtsDecal);
68+
69+
constructor() {
70+
effect(() => {
71+
console.log(this.decal()?.meshRef().nativeElement);
72+
});
73+
}
74+
75+
onDrag({ l }: OnDragParameters) {
76+
const position = new Vector3();
77+
const scale = new Vector3();
78+
const quaternion = new Quaternion();
79+
l.decompose(position, quaternion, scale);
80+
const rotation = new Euler().setFromQuaternion(quaternion);
81+
this.position.set([position.x, position.y + 0.75, position.z + 0.3]);
82+
this.rotation.set([rotation.x, rotation.y, rotation.z]);
83+
this.scale.set([0.6 * scale.x, 0.6 * scale.y, 0.6 * scale.z]);
84+
}
85+
}
86+
87+
@Component({
88+
standalone: true,
89+
template: `
90+
<ngts-orthographic-camera [options]="{ makeDefault: true, position: [0, 10, 100], zoom: 140 }" />
91+
92+
<ngt-color attach="background" *args="['#027946']" />
93+
94+
<ngt-ambient-light [intensity]="0.5 * Math.PI" />
95+
<ngt-directional-light [intensity]="0.5 * Math.PI" [position]="[10, 10, 10]" />
96+
97+
<app-cup />
98+
99+
<ngts-accumulative-shadows
100+
[options]="{ temporal: true, frames: 100, alphaTest: 0.85, opacity: 1, scale: 25, position: [0, -1, 0] }"
101+
>
102+
<ngts-randomized-lights
103+
[options]="{ amount: 8, radius: 10, ambient: 0.7, position: [10, 10, -5], bias: 0.01, size: 10 }"
104+
/>
105+
</ngts-accumulative-shadows>
106+
107+
<ngts-orbit-controls [options]="{ makeDefault: true }" />
108+
`,
109+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
110+
changeDetection: ChangeDetectionStrategy.OnPush,
111+
imports: [NgtsOrthographicCamera, NgtArgs, Cup, NgtsAccumulativeShadows, NgtsRandomizedLights, NgtsOrbitControls],
112+
host: { class: 'starbucks-soba-experience' },
113+
})
114+
export class Experience {
115+
protected readonly Math = Math;
116+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { NgtCanvas } from 'angular-three';
3+
import { Experience } from './experience';
4+
5+
@Component({
6+
standalone: true,
7+
template: `
8+
<ngt-canvas [sceneGraph]="scene" [shadows]="true" />
9+
`,
10+
changeDetection: ChangeDetectionStrategy.OnPush,
11+
imports: [NgtCanvas],
12+
host: { class: 'starbucks-soba' },
13+
})
14+
export default class Starbucks {
15+
protected scene = Experience;
16+
}

0 commit comments

Comments
 (0)