Skip to content

Commit 7372b25

Browse files
committed
clear cached for gainmap env
1 parent 05ccb4b commit 7372b25

File tree

10 files changed

+39
-20
lines changed

10 files changed

+39
-20
lines changed

libs/core/src/lib/loader.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,12 @@ _injectLoader.destroy = () => {
166166
cached.clear();
167167
};
168168

169+
_injectLoader.clear = (urls: string | string[]) => {
170+
const urlToClear = Array.isArray(urls) ? urls : [urls];
171+
urlToClear.forEach((url) => {
172+
cached.delete(url);
173+
});
174+
};
175+
169176
export type NgtInjectedLoader = typeof _injectLoader;
170177
export const injectLoader: NgtInjectedLoader = _injectLoader;
-56.2 KB
Loading
-64.5 KB
Loading
-67.6 KB
Loading
-55.8 KB
Loading
-58.3 KB
Loading
-62.1 KB
Loading
Loading

libs/soba/src/staging/environment.stories.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ import { makeDecorators, makeStoryObject, number, select } from '../setup-canvas
2626
})
2727
class Torus {}
2828

29-
@Component({
30-
standalone: true,
31-
template: `
32-
<ngts-environment [options]="options()" />
33-
<environment-torus />
34-
<ngts-orbit-controls [options]="{ autoRotate: true }" />
35-
`,
36-
imports: [Torus, NgtsEnvironment, NgtsOrbitControls],
37-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
38-
changeDetection: ChangeDetectionStrategy.OnPush,
39-
})
40-
class FilesEnvironmentStory {
41-
options = input({} as NgtsEnvironmentOptions);
42-
}
43-
4429
@Component({
4530
standalone: true,
4631
template: `
@@ -72,13 +57,23 @@ export const Default = makeStoryObject(DefaultEnvironmentStory, {
7257
},
7358
});
7459

75-
export const Files = makeStoryObject(FilesEnvironmentStory, {
60+
export const Files = makeStoryObject(DefaultEnvironmentStory, {
7661
canvasOptions: { controls: false, camera: { position: [0, 0, 10] } },
7762
argsOptions: {
7863
options: {
7964
background: true,
8065
files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
81-
path: 'https://drei.pmnd.rs/cube/',
66+
path: './cube/',
67+
},
68+
},
69+
});
70+
71+
export const GainMap = makeStoryObject(DefaultEnvironmentStory, {
72+
canvasOptions: { controls: false, camera: { position: [0, 0, 10] } },
73+
argsOptions: {
74+
options: {
75+
files: ['./gainmap/potsdamer_platz_1k.jpg'],
76+
background: true,
8277
},
8378
},
8479
});

libs/soba/staging/src/lib/environment.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export function injectEnvironment(
143143
return { files, preset, encoding, path, extensions };
144144
});
145145

146+
const files = pick(adjustedOptions, 'files');
147+
146148
const resultOptions = computed(() => {
147149
const { files } = adjustedOptions();
148150
const multiFile = Array.isArray(files);
@@ -194,6 +196,21 @@ export function injectEnvironment(
194196

195197
const texture = signal<Texture | CubeTexture | null>(null);
196198
afterNextRender(() => {
199+
autoEffect(() => {
200+
const [{ extension, multiFile }, _files] = [untracked(resultOptions), files()];
201+
202+
if (extension !== 'webp' && extension !== 'jpg' && extension !== 'jpeg') return;
203+
204+
gl().domElement.addEventListener(
205+
'webglcontextlost',
206+
() => {
207+
// @ts-expect-error - files is correctly passed
208+
injectLoader.clear(multiFile ? [_files] : _files);
209+
},
210+
{ once: true },
211+
);
212+
});
213+
197214
const result = injectLoader(
198215
loader,
199216
// @ts-expect-error
@@ -216,7 +233,7 @@ export function injectEnvironment(
216233
},
217234
},
218235
);
219-
//
236+
220237
autoEffect(() => {
221238
const loaderResult = result();
222239
if (!loaderResult) return;
@@ -235,8 +252,8 @@ export function injectEnvironment(
235252
textureResult.mapping = isCubeMap ? CubeReflectionMapping : EquirectangularReflectionMapping;
236253

237254
if ('colorSpace' in textureResult)
238-
(textureResult as any).colorSpace = encoding ?? isCubeMap ? 'srgb' : 'srgb-linear';
239-
else (textureResult as any).encoding = encoding ?? isCubeMap ? sRGBEncoding : LinearEncoding;
255+
(textureResult as any).colorSpace = encoding ?? (isCubeMap ? 'srgb' : 'srgb-linear');
256+
else (textureResult as any).encoding = encoding ?? (isCubeMap ? sRGBEncoding : LinearEncoding);
240257

241258
texture.set(textureResult);
242259
});

0 commit comments

Comments
 (0)