Skip to content

Commit d2bf885

Browse files
committed
fix: clean up selections from rx-state
1 parent ac400c9 commit d2bf885

File tree

11 files changed

+128
-129
lines changed

11 files changed

+128
-129
lines changed

libs/angular-three-soba/abstractions/src/lib/gizmo-helper/gizmo-helper.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
Output,
1313
TemplateRef,
1414
} from '@angular/core';
15-
import { selectSlice } from '@rx-angular/state';
1615
import { extend, injectNgtRef, NgtPortal, NgtPortalContent, NgtRxStore, NgtStore } from 'angular-three';
1716
import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';
1817
import { combineLatest, map } from 'rxjs';
@@ -191,7 +190,13 @@ export class NgtsGizmoHelper extends NgtRxStore implements OnInit {
191190
private setGizmoPosition() {
192191
this.connect(
193192
'gizmoPosition',
194-
combineLatest([this.store.select('size'), this.select(selectSlice(['alignment', 'margin']))]).pipe(
193+
combineLatest([
194+
this.store.select('size'),
195+
combineLatest({
196+
alignment: this.select('alignment'),
197+
margin: this.select('margin'),
198+
}),
199+
]).pipe(
195200
map(([size, { alignment, margin }]) => {
196201
const [marginX, marginY] = margin;
197202
const x = alignment.endsWith('-center')

libs/angular-three-soba/abstractions/src/lib/text-3d/text-3d.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
44
import { Mesh } from 'three';
55
import { FontLoader, TextGeometry } from 'three-stdlib';
66

7-
declare type Glyph = {
8-
_cachedOutline: string[];
9-
ha: number;
10-
o: string;
11-
};
7+
declare type Glyph = { _cachedOutline: string[]; ha: number; o: string };
128

139
declare type FontData = {
14-
boundingBox: {
15-
yMax: number;
16-
yMin: number;
17-
};
10+
boundingBox: { yMax: number; yMin: number };
1811
familyName: string;
19-
glyphs: {
20-
[k: string]: Glyph;
21-
};
12+
glyphs: { [k: string]: Glyph };
2213
resolution: number;
2314
underlineThickness: number;
2415
};

libs/angular-three-soba/materials/src/lib/mesh-transmission-material/mesh-transmission-material.ts

-4
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,4 @@ export class NgtsMeshTranmissionMaterial extends NgtRxStore {
203203
}
204204
});
205205
}
206-
207-
ngOnInit() {
208-
console.log(this.materialRef);
209-
}
210206
}

libs/angular-three-soba/performance/src/lib/detailed/detailed.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input, OnInit } from '@angular/core';
2-
import { extend, injectNgtRef, NgtRxStore } from 'angular-three';
2+
import { extend, injectNgtRef, NgtBeforeRenderEvent, NgtRxStore } from 'angular-three';
33
import { combineLatest } from 'rxjs';
44
import { LOD } from 'three';
55

@@ -9,7 +9,7 @@ extend({ LOD });
99
selector: 'ngts-detailed[distances]',
1010
standalone: true,
1111
template: `
12-
<ngt-lOD [ref]="lodRef" ngtCompound (beforeRender)="$any($event).object.update($any($event).state.camera)">
12+
<ngt-lOD [ref]="lodRef" ngtCompound (beforeRender)="onLODBeforeRender($any($event))">
1313
<ng-content />
1414
</ngt-lOD>
1515
`,
@@ -26,6 +26,10 @@ export class NgtsDetailed extends NgtRxStore implements OnInit {
2626
this.updateLodChildren();
2727
}
2828

29+
onLODBeforeRender({ object, state }: NgtBeforeRenderEvent<THREE.LOD>) {
30+
object.update(state.camera);
31+
}
32+
2933
private updateLodChildren() {
3034
this.hold(combineLatest([this.lodRef.children$(), this.select('distances')]), ([children, distances]) => {
3135
this.lodRef.nativeElement.levels.length = 0;

libs/angular-three-soba/shaders/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export * from './lib/mesh-refraction-material/mesh-refraction-material';
99
export * from './lib/mesh-transmission-material/mesh-transmission-material';
1010
export * from './lib/mesh-wobble-material/mesh-wobble-material';
1111
export * from './lib/shader-material/shader-material';
12+
export * from './lib/soft-shadow-material/soft-shadow-material';
1213
export * from './lib/spot-light-material/spot-light-material';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as THREE from 'three';
2+
import { shaderMaterial } from '../shader-material/shader-material';
3+
4+
export const SoftShadowMaterial = shaderMaterial(
5+
{
6+
color: new THREE.Color(),
7+
blend: 2.0,
8+
alphaTest: 0.75,
9+
opacity: 0,
10+
map: null,
11+
},
12+
// language=GLSL
13+
`
14+
varying vec2 vUv;
15+
void main() {
16+
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);
17+
vUv = uv;
18+
}
19+
`,
20+
// language=GLSL
21+
`
22+
varying vec2 vUv;
23+
uniform sampler2D map;
24+
uniform vec3 color;
25+
uniform float blend;
26+
uniform float opacity;
27+
uniform float alphaTest;
28+
void main() {
29+
vec4 sampledDiffuseColor = texture2D(map, vUv);
30+
gl_FragColor = vec4(color * sampledDiffuseColor.r * blend, max(0.0, (1.0 - (sampledDiffuseColor.r + sampledDiffuseColor.g + sampledDiffuseColor.b) / alphaTest)) * opacity);
31+
#include <tonemapping_fragment>
32+
#include <encodings_fragment>
33+
}
34+
`
35+
);
36+
37+
export type SoftShadowMaterialInputs = {
38+
map: THREE.Texture;
39+
color?: THREE.ColorRepresentation;
40+
alphaTest?: number;
41+
blend?: number;
42+
};

libs/angular-three-soba/src/shaders/mesh-refraction-material.stories.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ extend({ Mesh, Color, AmbientLight, SpotLight, PointLight, SphereGeometry, MeshS
2727
<ng-template [ngtsCameraContent]="true" let-texture="fbo">
2828
<ngts-caustics
2929
color="white"
30-
[backfaces]="true"
30+
[backside]="true"
3131
[position]="[0, -0.5, 0]"
3232
[lightSource]="[5, 5, -10]"
3333
[worldRadius]="1"
3434
[ior]="1.8"
35-
[backfaceIor]="1.1"
35+
[backsideIOR]="1.1"
3636
[intensity]="0.1"
3737
>
3838
<ngt-mesh

libs/angular-three-soba/staging/src/lib/accumulative-shadows/accumulative-shadows.ts

+3-43
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,11 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Directive, inject, InjectionToken, Input } from '@angular/core';
22
import { extend, getLocalState, injectNgtRef, NgtRxStore, NgtStore } from 'angular-three';
3-
import { shaderMaterial } from 'angular-three-soba/shaders';
3+
import { SoftShadowMaterial, SoftShadowMaterialInputs } from 'angular-three-soba/shaders';
44
import { combineLatest, Subject } from 'rxjs';
55
import * as THREE from 'three';
66
import { Group, Mesh, PlaneGeometry } from 'three';
77
import { ProgressiveLightMap } from './progressive-light-map';
88

9-
const SoftShadowMaterial = shaderMaterial(
10-
{
11-
color: new THREE.Color(),
12-
blend: 2.0,
13-
alphaTest: 0.75,
14-
opacity: 0,
15-
map: null,
16-
},
17-
// language=GLSL
18-
`
19-
varying vec2 vUv;
20-
void main() {
21-
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);
22-
vUv = uv;
23-
}
24-
`,
25-
// language=GLSL
26-
`
27-
varying vec2 vUv;
28-
uniform sampler2D map;
29-
uniform vec3 color;
30-
uniform float blend;
31-
uniform float opacity;
32-
uniform float alphaTest;
33-
void main() {
34-
vec4 sampledDiffuseColor = texture2D(map, vUv);
35-
gl_FragColor = vec4(color * sampledDiffuseColor.r * blend, max(0.0, (1.0 - (sampledDiffuseColor.r + sampledDiffuseColor.g + sampledDiffuseColor.b) / alphaTest)) * opacity);
36-
#include <tonemapping_fragment>
37-
#include <encodings_fragment>
38-
}
39-
`
40-
);
41-
42-
type SoftShadowMaterialInputs = {
43-
map: THREE.Texture;
44-
color?: THREE.ColorRepresentation;
45-
alphaTest?: number;
46-
blend?: number;
47-
};
48-
499
extend({ SoftShadowMaterial, Group, Mesh, PlaneGeometry });
5010

5111
export type NgtsAccumulativeShadowsLightApi = { update: () => void };
@@ -166,7 +126,7 @@ function accumulativeShadowsApiFactory(accumulativeShadows: NgtsAccumulativeShad
166126
return api;
167127
}
168128

169-
@Directive({ selector: 'ngts-accumulative-shadows-consumer', standalone: true })
129+
@Directive({ selector: '[ngtsAccumulativeShadowsConsumer]', standalone: true })
170130
export class AccumulativeShadowsConsumer {
171131
constructor() {
172132
inject(NGTS_ACCUMULATIVE_SHADOWS_API);
@@ -180,7 +140,7 @@ export class AccumulativeShadowsConsumer {
180140
<ngt-group ngtCompound>
181141
<ngt-group [ref]="accumulativeShadowsRef" [traverse]="nullTraverse">
182142
<ng-content />
183-
<ngts-accumulative-shadows-consumer />
143+
<ng-container ngtsAccumulativeShadowsConsumer />
184144
</ngt-group>
185145
<ngt-mesh [ref]="meshRef" [receiveShadow]="true" [scale]="get('scale')" [rotation]="[-Math.PI / 2, 0, 0]">
186146
<ngt-plane-geometry />

libs/angular-three-soba/staging/src/lib/accumulative-shadows/randomized-lights.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function randomizedLightsApiFactory(randomizedLights: NgtsRandomizedLights) {
6060
return api;
6161
}
6262

63-
@Directive({ selector: 'ngts-randomized-lights-consumer', standalone: true })
63+
@Directive({ selector: '[ngtsRandomizedLightsConsumer]', standalone: true })
6464
export class RandomizedLightsConsumer {
6565
constructor() {
6666
inject(NGTS_RANDOMIZED_LIGHTS_API);
@@ -81,7 +81,7 @@ export class RandomizedLightsConsumer {
8181
<ngt-vector2 *args="[get('mapSize'), get('mapSize')]" attach="shadow.mapSize" />
8282
<ngt-orthographic-camera *args="get('cameraArgs')" attach="shadow.camera" />
8383
</ngt-directional-light>
84-
<ngts-randomized-lights-consumer />
84+
<ng-container ngtsRandomizedLightsConsumer />
8585
</ngt-group>
8686
`,
8787
imports: [RandomizedLightsConsumer, NgtArgs, NgtRepeat],

libs/angular-three-soba/staging/src/lib/caustics/caustics.ts

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NgIf } from '@angular/common';
2-
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, inject, Input, OnInit } from '@angular/core';
2+
import { Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, inject, Input, OnInit } from '@angular/core';
33
import { extend, injectNgtRef, NgtRxStore, NgtStore } from 'angular-three';
44
import { NgtsEdges } from 'angular-three-soba/abstractions';
55
import { injectNgtsFBO } from 'angular-three-soba/misc';
@@ -189,7 +189,6 @@ export class NgtsCaustics extends NgtRxStore implements OnInit {
189189
);
190190

191191
private readonly store = inject(NgtStore);
192-
private readonly cdr = inject(ChangeDetectorRef);
193192

194193
override initialize(): void {
195194
this.set({
@@ -232,43 +231,41 @@ export class NgtsCaustics extends NgtRxStore implements OnInit {
232231
this.effect(
233232
combineLatest([
234233
this.sceneRef.$,
235-
this.sceneRef.children$('both'),
234+
this.sceneRef.children$(),
236235
this.causticsRef.$,
237236
this.cameraRef.$,
238-
this.planeRef.$,
239-
this.planeRef.children$('both'),
240237
this.normalTargetFbo.$,
241238
this.normalTargetBFbo.$,
242239
this.causticsTargetFbo.$,
243240
this.causticsTargetBFbo.$,
241+
this.planeRef.$,
242+
this.planeRef.children$('both'),
244243
]),
245244
([
246245
scene,
247246
children,
248247
caustics,
249248
camera,
250-
plane,
251-
,
252249
normalTarget,
253250
normalTargetB,
254251
causticsTarget,
255252
causticsTargetB,
253+
plane,
256254
]) => {
257-
const v = new THREE.Vector3();
258-
const lpF = new THREE.Frustum();
259-
const lpM = new THREE.Matrix4();
260-
const lpP = new THREE.Plane();
261-
262-
const lightDir = new THREE.Vector3();
263-
const lightDirInv = new THREE.Vector3();
264-
const bounds = new THREE.Box3();
265-
const focusPos = new THREE.Vector3();
266-
267-
let count = 0;
268-
269255
caustics.updateWorldMatrix(false, true);
270256

271257
if (children.length > 1) {
258+
const v = new THREE.Vector3();
259+
const lpF = new THREE.Frustum();
260+
const lpM = new THREE.Matrix4();
261+
const lpP = new THREE.Plane();
262+
263+
const lightDir = new THREE.Vector3();
264+
const lightDirInv = new THREE.Vector3();
265+
const bounds = new THREE.Box3();
266+
const focusPos = new THREE.Vector3();
267+
268+
let count = 0;
272269
return this.store.get('internal').subscribe(({ gl }) => {
273270
const {
274271
frames,
@@ -399,10 +396,10 @@ export class NgtsCaustics extends NgtRxStore implements OnInit {
399396

400397
// Render front face caustics
401398
causticsMaterial.ior = ior;
402-
// @ts-ignore
403-
plane.material.lightProjMatrix = camera.projectionMatrix;
404-
// @ts-ignore
405-
plane.material.lightViewMatrix = camera.matrixWorldInverse;
399+
(plane.material as CausticsProjectionMaterialType).lightProjMatrix =
400+
camera.projectionMatrix;
401+
(plane.material as CausticsProjectionMaterialType).lightViewMatrix =
402+
camera.matrixWorldInverse;
406403
causticsMaterial.normalTexture = normalTarget.texture;
407404
causticsMaterial.depthTexture = normalTarget.depthTexture;
408405
gl.setRenderTarget(causticsTarget);

0 commit comments

Comments
 (0)