()
| 165 | |
| 166 | useEffect(() => { |
| 167 | const loadOverlayTextures = async () => { |
| 168 | if (!rendererRef.current) return; |
| 169 | |
| 170 | const overlayEffect = effects.find(e => e.type === 'overlay' && e.enabled); |
| 171 | if (!overlayEffect) { |
| 172 | if (lastOverlayParamsRef.current !== null) { |
| 173 | rendererRef.current.setOverlayTexture(null); |
| 174 | lastOverlayParamsRef.current = null; |
| 175 | } |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | const { texture, customTextureUrl } = overlayEffect.params; |
| 180 | const paramsKey = `${texture}:${customTextureUrl || ''}`; |
| 181 | |
| 182 | if (lastOverlayParamsRef.current === paramsKey) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | if (texture === OVERLAY_TEXTURES.CUSTOM && customTextureUrl) { |
| 187 | try { |
| 188 | const result = await loadImageFromURL(customTextureUrl); |
| 189 | if (cancelled) return; |
| 190 | rendererRef.current.setOverlayTexture(result.image); |
| 191 | lastOverlayParamsRef.current = paramsKey; |
| 192 | renderPreview(); |
| 193 | } catch { |
| 194 | console.warn('Failed to load custom overlay texture'); |
| 195 | } |
| 196 | } else if (texture !== OVERLAY_TEXTURES.CUSTOM) { |
| 197 | const textureImg = await generateProceduralTexture(texture); |
| 198 | if (cancelled) return; |
| 199 | rendererRef.current.setOverlayTexture(textureImg); |
| 200 | lastOverlayParamsRef.current = paramsKey; |
| 201 | renderPreview(); |
| 202 | } |
| 203 | }; |
| 204 | |
| 205 | let cancelled = false; |
| 206 | loadOverlayTextures(); |
no test coverage detected