Skip to content

Commit 18b02de

Browse files
committed
docs(soba): adjust grid and instances stories
1 parent dc83f8b commit 18b02de

File tree

2 files changed

+63
-22
lines changed

2 files changed

+63
-22
lines changed

libs/soba/src/abstractions/grid.stories.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, input, Signal } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
CUSTOM_ELEMENTS_SCHEMA,
5+
effect,
6+
input,
7+
output,
8+
signal,
9+
Signal,
10+
} from '@angular/core';
211
import { Meta } from '@storybook/angular';
312
import { NgtAnyRecord, NgtArgs } from 'angular-three';
413
import { NgtsGrid } from 'angular-three-soba/abstractions';
@@ -40,6 +49,14 @@ class Suzi {
4049

4150
rotation = input([0, 0, 0]);
4251
scale = input(1);
52+
loaded = output<void>();
53+
54+
constructor() {
55+
effect(() => {
56+
const gltf = this.gltf();
57+
if (gltf) this.loaded.emit();
58+
});
59+
}
4360
}
4461

4562
@Component({
@@ -63,22 +80,24 @@ class Shadows {}
6380
template: `
6481
<ngt-group [position]="[0, -0.5, 0]">
6582
<ngts-center [options]="{ top: true }">
66-
<grid-suzi [rotation]="[-0.63, 0, 0]" [scale]="2" />
83+
<grid-suzi [rotation]="[-0.63, 0, 0]" [scale]="2" (loaded)="loaded.set(true)" />
6784
</ngts-center>
6885
69-
<ngts-center [options]="{ top: true, position: [-2, 0, 2] }">
70-
<ngt-mesh [castShadow]="true">
71-
<ngt-sphere-geometry *args="[0.5, 64, 64]" />
72-
<ngt-mesh-standard-material color="#9d4b4b" />
73-
</ngt-mesh>
74-
</ngts-center>
86+
@if (loaded()) {
87+
<ngts-center [options]="{ top: true, position: [-2, 0, 2] }">
88+
<ngt-mesh [castShadow]="true">
89+
<ngt-sphere-geometry *args="[0.5, 64, 64]" />
90+
<ngt-mesh-standard-material color="#9d4b4b" />
91+
</ngt-mesh>
92+
</ngts-center>
7593
76-
<ngts-center [options]="{ top: true, position: [2.5, 0, 1] }">
77-
<ngt-mesh [castShadow]="true" [rotation]="[0, Math.PI / 4, 0]">
78-
<ngt-box-geometry *args="[0.7, 0.7, 0.7]" />
79-
<ngt-mesh-standard-material color="#9d4b4b" />
80-
</ngt-mesh>
81-
</ngts-center>
94+
<ngts-center [options]="{ top: true, position: [2.5, 0, 1] }">
95+
<ngt-mesh [castShadow]="true" [rotation]="[0, Math.PI / 4, 0]">
96+
<ngt-box-geometry *args="[0.7, 0.7, 0.7]" />
97+
<ngt-mesh-standard-material color="#9d4b4b" />
98+
</ngt-mesh>
99+
</ngts-center>
100+
}
82101
83102
<grid-shadows />
84103
@@ -108,6 +127,7 @@ class Shadows {}
108127
})
109128
class DefaultGridStory {
110129
Math = Math;
130+
loaded = signal(false);
111131
}
112132

113133
export default {

libs/soba/src/performances/instances.stories.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, input, Signal, viewChild } from '@angular/core';
22
import { Meta } from '@storybook/angular';
3-
import { injectBeforeRender, NgtObjectEvents, omit, pick } from 'angular-three';
3+
import { injectBeforeRender, injectObjectEvents, omit, pick } from 'angular-three';
44
import { NgtsOrbitControls } from 'angular-three-soba/controls';
55
import { injectGLTF } from 'angular-three-soba/loaders';
66
import { NgtsInstance, NgtsInstances } from 'angular-three-soba/performances';
@@ -30,17 +30,12 @@ type Data = (typeof data)[number];
3030
standalone: true,
3131
template: `
3232
<ngt-group [parameters]="parameters()">
33-
<ngts-instance
34-
#instance
35-
[ngtObjectEvents]="instance.positionMeshRef()"
36-
(pointerover)="$event.stopPropagation(); this.hovered = true"
37-
(pointerout)="this.hovered = false"
38-
/>
33+
<ngts-instance />
3934
</ngt-group>
4035
`,
4136
schemas: [CUSTOM_ELEMENTS_SCHEMA],
4237
changeDetection: ChangeDetectionStrategy.OnPush,
43-
imports: [NgtsInstance, NgtObjectEvents],
38+
imports: [NgtsInstance],
4439
})
4540
class Shoe {
4641
data = input.required<Data>();
@@ -58,6 +53,32 @@ class Shoe {
5853
constructor() {
5954
const color = new Color();
6055

56+
/**
57+
* We can also use ngtObjectEvents and Event Bindings
58+
* However, using Event Bindings on the template triggers CD everytime the event fires
59+
* which is not ideal for this case
60+
*
61+
* @example
62+
*
63+
* ```html
64+
* <ngts-instance
65+
* #instance
66+
* [ngtObjectEvents]="instance.positionMeshRef()"
67+
* (pointerover)="$event.stopPropagation(); this.hovered = true"
68+
* (pointerout)="this.hovered = false"
69+
* />
70+
* ```
71+
*/
72+
injectObjectEvents(() => this.instance().positionMeshRef(), {
73+
pointerover: (event) => {
74+
event.stopPropagation();
75+
this.hovered = true;
76+
},
77+
pointerout: () => {
78+
this.hovered = false;
79+
},
80+
});
81+
6182
injectBeforeRender(({ clock }) => {
6283
const instance = this.instance().positionMeshRef().nativeElement;
6384
const t = clock.getElapsedTime() + this.random() * 10000;

0 commit comments

Comments
 (0)