Skip to content

Commit ca5484b

Browse files
committed
lots of mesh materials
1 parent fc5a81e commit ca5484b

File tree

32 files changed

+3214
-9
lines changed

32 files changed

+3214
-9
lines changed

Diff for: libs/core/src/lib/directives/key.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export class NgtKey {
1919
private lastKey = '';
2020
private viewRef?: EmbeddedViewRef<unknown>;
2121

22-
@Input() set key(key: string) {
23-
if (this.lastKey !== key) {
22+
@Input() set key(key: string | number | object) {
23+
const normalizedKey = key.toString();
24+
if (this.lastKey !== normalizedKey) {
2425
this.createView();
25-
this.lastKey = key;
26+
this.lastKey = normalizedKey;
2627
}
2728
}
2829

Diff for: libs/soba/abstractions/src/edges/edges.ts

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { NgIf, NgTemplateOutlet } from '@angular/common';
2+
import { CUSTOM_ELEMENTS_SCHEMA, Component, ContentChild, Directive, Input, TemplateRef, effect } from '@angular/core';
3+
import { extend, injectNgtRef, signalStore, type NgtAnyRecord, type NgtLineSegments } from 'angular-three';
4+
import * as THREE from 'three';
5+
import { LineBasicMaterial, LineSegments } from 'three';
6+
7+
export type NgtsEdgesState = {
8+
threshold: number;
9+
color: THREE.ColorRepresentation;
10+
geometry: THREE.BufferGeometry;
11+
userData: NgtAnyRecord;
12+
};
13+
14+
declare global {
15+
interface HTMLElementTagNameMap {
16+
/**
17+
* @extends ngt-line-segments
18+
*/
19+
'ngts-edges': NgtsEdgesState & NgtLineSegments;
20+
}
21+
}
22+
23+
extend({ LineSegments, LineBasicMaterial });
24+
25+
@Directive({ selector: 'ng-template[ngtsEdgesContent]', standalone: true })
26+
export class NgtsEdgesContent {}
27+
28+
@Component({
29+
selector: 'ngts-edges',
30+
standalone: true,
31+
template: `
32+
<ngt-line-segments [ref]="edgesRef" [raycast]="nullRaycast" ngtCompound>
33+
<ng-container *ngIf="content; else defaultMaterial" [ngTemplateOutlet]="content" />
34+
<ng-template #defaultMaterial>
35+
<ngt-line-basic-material [color]="color()" />
36+
</ng-template>
37+
</ngt-line-segments>
38+
`,
39+
imports: [NgIf, NgTemplateOutlet],
40+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
41+
})
42+
export class NgtsEdges {
43+
nullRaycast = () => null;
44+
45+
@ContentChild(NgtsEdgesContent, { read: TemplateRef }) content?: TemplateRef<unknown>;
46+
47+
private inputs = signalStore<NgtsEdgesState>({ threshold: 15, color: 'black' });
48+
49+
@Input() edgesRef = injectNgtRef<LineSegments>();
50+
51+
@Input({ alias: 'threshold' }) set _threshold(threshold: number) {
52+
this.inputs.set({ threshold });
53+
}
54+
55+
@Input({ alias: 'color' }) set _color(color: THREE.ColorRepresentation) {
56+
this.inputs.set({ color });
57+
}
58+
59+
@Input({ alias: 'geometry' }) set _geometry(geometry: THREE.BufferGeometry) {
60+
this.inputs.set({ geometry });
61+
}
62+
63+
@Input({ alias: 'userData' }) set _userData(userData: NgtAnyRecord) {
64+
this.inputs.set({ userData });
65+
}
66+
67+
private geometry = this.inputs.select('geometry');
68+
private threshold = this.inputs.select('threshold');
69+
70+
color = this.inputs.select('color');
71+
72+
constructor() {
73+
effect(() => {
74+
const edges = this.edgesRef.nativeElement;
75+
if (!edges) return;
76+
const parent = this.edgesRef.nativeElement.parent as THREE.Mesh;
77+
if (parent) {
78+
const [geometry, threshold] = [this.geometry() || parent.geometry, this.threshold()];
79+
if (geometry !== edges.userData['currentGeom'] || threshold !== edges.userData['currentThreshold']) {
80+
edges.userData['currentGeom'] = geometry;
81+
edges.userData['currentThreshold'] = threshold;
82+
edges.geometry = new THREE.EdgesGeometry(geometry, threshold);
83+
}
84+
}
85+
});
86+
}
87+
}

Diff for: libs/soba/abstractions/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './billboard/billboard';
22
export * from './detailed/detailed';
3+
export * from './edges/edges';
34
export * from './grid/grid';
45
export * from './text-3d/text-3d';
56
export * from './text/text';

Diff for: libs/soba/cameras/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './camera/camera-content';
12
export * from './cube-camera/cube-camera';
23
export * from './orthographic-camera/orthographic-camera';
34
export * from './perspective-camera/perspective-camera';

Diff for: libs/soba/materials/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
export * from './mesh-distort-material/mesh-distort-material';
2+
export * from './mesh-reflector-material/mesh-reflector-material';
3+
export * from './mesh-refraction-material/mesh-refraction-material';
4+
export * from './mesh-transmission-material/mesh-transmission-material';
5+
export * from './mesh-wobble-material/mesh-wobble-material';
16
export * from './point-material/point-material';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2+
import { injectBeforeRender, injectNgtRef, NgtArgs, signalStore, type NgtMeshPhysicalMaterial } from 'angular-three';
3+
import { injectNgtsMeshDistortMaterial, MeshDistortMaterial } from 'angular-three-soba/shaders';
4+
5+
export type NgtsMeshDistortMaterialState = {
6+
time: number;
7+
distort: number;
8+
radius: number;
9+
speed: number;
10+
};
11+
12+
declare global {
13+
interface HTMLElementTagNameMap {
14+
/**
15+
* @extends ngt-mesh-physical-material
16+
*/
17+
'ngts-mesh-distort-material': NgtsMeshDistortMaterialState & NgtMeshPhysicalMaterial;
18+
}
19+
}
20+
21+
@Component({
22+
selector: 'ngts-mesh-distort-material',
23+
standalone: true,
24+
template: `
25+
<ngt-primitive
26+
*args="[material]"
27+
[ref]="materialRef"
28+
[time]="time()"
29+
[distort]="distort()"
30+
[radius]="radius()"
31+
ngtCompound
32+
attach="material"
33+
/>
34+
`,
35+
imports: [NgtArgs],
36+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
37+
})
38+
export class NgtsMeshDistortMaterial {
39+
private inputs = signalStore<NgtsMeshDistortMaterialState>({
40+
speed: 1,
41+
time: 0,
42+
distort: 0.4,
43+
radius: 1,
44+
});
45+
46+
@Input() materialRef = injectNgtRef<InstanceType<MeshDistortMaterial>>();
47+
48+
@Input({ alias: 'time' }) set _time(time: number) {
49+
this.inputs.set({ time });
50+
}
51+
52+
@Input({ alias: 'distort' }) set _distort(distort: number) {
53+
this.inputs.set({ distort });
54+
}
55+
56+
@Input({ alias: 'radius' }) set _radius(radius: number) {
57+
this.inputs.set({ radius });
58+
}
59+
60+
@Input({ alias: 'speed' }) set _speed(speed: number) {
61+
this.inputs.set({ speed });
62+
}
63+
64+
private MeshDistortMaterial = injectNgtsMeshDistortMaterial();
65+
material = new this.MeshDistortMaterial();
66+
67+
time = this.inputs.select('time');
68+
distort = this.inputs.select('distort');
69+
radius = this.inputs.select('radius');
70+
71+
constructor() {
72+
injectBeforeRender(({ clock }) => {
73+
this.material.time = clock.getElapsedTime() * this.inputs.get('speed');
74+
});
75+
}
76+
}

0 commit comments

Comments
 (0)