Skip to content

Commit 2c43c6f

Browse files
committed
docs(examples): update starbucks routes
1 parent aef9617 commit 2c43c6f

File tree

3 files changed

+120
-10
lines changed

3 files changed

+120
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ const routes: Routes = [
133133
},
134134
},
135135
},
136-
// {
137-
// path: 'starbucks',
138-
// loadComponent: () => import('./starbucks/starbucks'),
139-
// data: {
140-
// credits: {
141-
// title: 'Decal and Pivot Controls',
142-
// link: 'https://codesandbox.io/p/sandbox/om2ff8',
143-
// },
144-
// },
145-
// },
136+
{
137+
path: 'starbucks',
138+
loadComponent: () => import('./starbucks/starbucks'),
139+
data: {
140+
credits: {
141+
title: 'Decal and Pivot Controls',
142+
link: 'https://codesandbox.io/p/sandbox/om2ff8',
143+
},
144+
},
145+
},
146146
{
147147
path: 'bruno-simons-20k',
148148
loadComponent: () => import('./bruno-simons-20k/bruno-simons-20k'),
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, signal } from '@angular/core';
2+
import { NgtArgs, NgtEuler, NgtVector3 } from 'angular-three';
3+
import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';
4+
import { NgtsOrbitControls } from 'angular-three-soba/controls';
5+
import { NgtsPivotControls, OnDragParameters } from 'angular-three-soba/gizmos';
6+
import { injectGLTF, injectTexture } from 'angular-three-soba/loaders';
7+
import { NgtsDecal } from 'angular-three-soba/misc';
8+
import { NgtsAccumulativeShadows, NgtsRandomizedLights } from 'angular-three-soba/staging';
9+
import { Euler, Mesh, MeshStandardMaterial, Quaternion, Vector3 } from 'three';
10+
import { GLTF } from 'three-stdlib';
11+
12+
type CupGLTF = GLTF & {
13+
nodes: { coffee_cup_top_16oz: Mesh };
14+
materials: { ['13 - Default']: MeshStandardMaterial };
15+
};
16+
@Component({
17+
selector: 'app-cup',
18+
template: `
19+
@if (gltf(); as gltf) {
20+
<ngt-mesh
21+
castShadow
22+
[geometry]="gltf.nodes.coffee_cup_top_16oz.geometry"
23+
[material]="gltf.materials['13 - Default']"
24+
[dispose]="null"
25+
[position]="[0, -1, 0]"
26+
[scale]="2"
27+
>
28+
<ngt-value [rawValue]="1" attach="material.aoMapIntensity" />
29+
<ngt-group [position]="[0, 0.75, 0.5]">
30+
<ngts-pivot-controls
31+
[options]="{ activeAxes: [true, true, false], scale: 0.55 }"
32+
(dragged)="onDrag($event)"
33+
/>
34+
</ngt-group>
35+
<ngts-decal
36+
[options]="{ map: texture(), position: position(), rotation: rotation(), scale: scale(), depthTest: true }"
37+
/>
38+
</ngt-mesh>
39+
}
40+
`,
41+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
42+
changeDetection: ChangeDetectionStrategy.OnPush,
43+
imports: [NgtsPivotControls, NgtsDecal],
44+
})
45+
export class Cup {
46+
protected position = signal<NgtVector3>([0, 0.75, 0.3]);
47+
protected rotation = signal<NgtEuler>([0, 0, 0]);
48+
protected scale = signal<NgtVector3>([0.6, 0.6, 0.6]);
49+
50+
protected gltf = injectGLTF<CupGLTF>(() => './coffee-transformed.glb');
51+
protected texture = injectTexture(() => './1200px-Starbucks_Logo_ab_2011.svg.png');
52+
53+
private p = new Vector3();
54+
private s = new Vector3();
55+
private q = new Quaternion();
56+
57+
onDrag({ l }: OnDragParameters) {
58+
l.decompose(this.p, this.q, this.s);
59+
const rotation = new Euler().setFromQuaternion(this.q);
60+
this.position.set([this.p.x, this.p.y + 0.75, this.p.z + 0.3]);
61+
this.rotation.set([rotation.x, rotation.y, rotation.z]);
62+
this.scale.set([0.6 * this.s.x, 0.6 * this.s.y, 0.6 * this.s.z]);
63+
}
64+
}
65+
66+
@Component({
67+
selector: 'app-scene-graph',
68+
template: `
69+
<ngts-orthographic-camera [options]="{ makeDefault: true, position: [0, 10, 100], zoom: 140 }" />
70+
71+
<ngt-color attach="background" *args="['#027946']" />
72+
73+
<ngt-ambient-light [intensity]="0.5 * Math.PI" />
74+
<ngt-directional-light [intensity]="0.5 * Math.PI" [position]="[10, 10, 10]" />
75+
76+
<app-cup />
77+
78+
<ngts-accumulative-shadows
79+
[options]="{ temporal: true, frames: 100, alphaTest: 0.85, opacity: 1, scale: 25, position: [0, -1, 0] }"
80+
>
81+
<ngts-randomized-lights
82+
[options]="{ amount: 8, radius: 10, ambient: 0.7, position: [10, 10, -5], bias: 0.01, size: 10 }"
83+
/>
84+
</ngts-accumulative-shadows>
85+
86+
<ngts-orbit-controls [options]="{ makeDefault: true }" />
87+
`,
88+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
89+
changeDetection: ChangeDetectionStrategy.OnPush,
90+
imports: [NgtsOrthographicCamera, NgtArgs, Cup, NgtsAccumulativeShadows, NgtsRandomizedLights, NgtsOrbitControls],
91+
host: { class: 'starbucks-soba-experience' },
92+
})
93+
export class SceneGraph {
94+
protected readonly Math = Math;
95+
}
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>
8+
<app-scene-graph *canvasContent />
9+
</ngt-canvas>
10+
`,
11+
changeDetection: ChangeDetectionStrategy.OnPush,
12+
imports: [NgtCanvas, SceneGraph, NgtCanvasContent],
13+
host: { class: 'starbucks-soba' },
14+
})
15+
export default class Starbucks {}

0 commit comments

Comments
 (0)