Skip to content

Commit d0b8cb5

Browse files
committed
detailed
1 parent 02f292d commit d0b8cb5

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input, effect } from '@angular/core';
2+
import { NgtBeforeRenderEvent, extend, injectNgtRef, signalStore, type NgtLOD } from 'angular-three';
3+
import { LOD } from 'three';
4+
5+
extend({ LOD });
6+
7+
export type NgtsDetailedState = {
8+
hysteresis: number;
9+
distances: number[];
10+
};
11+
12+
declare global {
13+
interface HTMLElementTagNameMap {
14+
/**
15+
* @extends ngt-lOD
16+
*/
17+
'ngts-detailed': NgtsDetailedState & NgtLOD;
18+
}
19+
}
20+
21+
@Component({
22+
selector: 'ngts-detailed',
23+
standalone: true,
24+
template: `
25+
<ngt-lOD ngtCompound [ref]="lodRef" (beforeRender)="onBeforeRender($event)">
26+
<ng-content />
27+
</ngt-lOD>
28+
`,
29+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
30+
})
31+
export class NgtsDetailed {
32+
private inputs = signalStore<NgtsDetailedState>({ hysteresis: 0 });
33+
34+
@Input() lodRef = injectNgtRef<LOD>();
35+
36+
@Input({ required: true, alias: 'distances' }) set _distances(distances: number[]) {
37+
this.inputs.set({ distances });
38+
}
39+
40+
@Input({ alias: 'hysteresis' }) set _hysteresis(hysteresis: number) {
41+
this.inputs.set({ hysteresis });
42+
}
43+
44+
constructor() {
45+
this.updateChildren();
46+
}
47+
48+
onBeforeRender({ object, state }: NgtBeforeRenderEvent<LOD>) {
49+
object.update(state.camera);
50+
}
51+
52+
private updateChildren() {
53+
const lodChildren = this.lodRef.children();
54+
const _distances = this.inputs.select('distances');
55+
const _hysteresis = this.inputs.select('hysteresis');
56+
57+
effect(() => {
58+
const lod = this.lodRef.nativeElement;
59+
if (!lod) return;
60+
const [distances, hysteresis, children] = [_distances(), _hysteresis(), lodChildren()];
61+
lod.levels.length = 0;
62+
children.forEach((child, index) => {
63+
lod.addLevel(child, distances[index], hysteresis);
64+
});
65+
});
66+
}
67+
}

libs/soba/abstractions/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './billboard/billboard';
2+
export * from './detailed/detailed';
23
export * from './grid/grid';
34
export * from './text-3d/text-3d';
45
export * from './text/text';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2+
import { Meta, StoryFn } from '@storybook/angular';
3+
import { NgtArgs } from 'angular-three';
4+
import { NgtsDetailed } from 'angular-three-soba/abstractions';
5+
import { NgtsOrbitControls } from 'angular-three-soba/controls';
6+
import { makeDecorators, makeStoryFunction } from '../setup-canvas';
7+
8+
@Component({
9+
standalone: true,
10+
template: `
11+
<ngts-detailed [distances]="[0, 50, 150]">
12+
<ngt-mesh>
13+
<ngt-icosahedron-geometry *args="[10, 3]" />
14+
<ngt-mesh-basic-material color="hotpink" [wireframe]="true" />
15+
</ngt-mesh>
16+
17+
<ngt-mesh>
18+
<ngt-icosahedron-geometry *args="[10, 2]" />
19+
<ngt-mesh-basic-material color="lightgreen" [wireframe]="true" />
20+
</ngt-mesh>
21+
22+
<ngt-mesh>
23+
<ngt-icosahedron-geometry *args="[10, 1]" />
24+
<ngt-mesh-basic-material color="lightblue" [wireframe]="true" />
25+
</ngt-mesh>
26+
</ngts-detailed>
27+
<ngts-orbit-controls [enablePan]="false" [enableRotate]="false" [zoomSpeed]="0.5" />
28+
`,
29+
imports: [NgtsDetailed, NgtsOrbitControls, NgtArgs],
30+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
31+
})
32+
class DefaultDetailedStory {}
33+
34+
export default {
35+
title: 'Abstractions/Detailed',
36+
decorators: makeDecorators(),
37+
} as Meta;
38+
39+
export const Default: StoryFn = makeStoryFunction(DefaultDetailedStory, {
40+
controls: false,
41+
camera: { position: [0, 0, 100] },
42+
});

tools/scripts/generate-soba-json.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const entryPoints = {
4343
'stars',
4444
'accumulative-shadows',
4545
'accumulative-shadows/randomized-lights',
46+
'stage',
4647
],
4748
};
4849

0 commit comments

Comments
 (0)