Skip to content

Commit

Permalink
fix: recreate CanvasTexture in rerenderTextElement (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
fand authored Jun 8, 2024
1 parent 8ea3cff commit 38608a8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/react-vfx/src/vfx-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,20 @@ export default class VFXPlayer {
try {
e.element.style.setProperty("opacity", "1"); // TODO: Restore original opacity

const texture: THREE.CanvasTexture = e.uniforms["src"].value;
const canvas = texture.image;
const oldTexture: THREE.CanvasTexture = e.uniforms["src"].value;
const canvas = oldTexture.image;

const texture = new THREE.CanvasTexture(canvas);

await dom2canvas(e.element, canvas);
if (canvas.width === 0 || canvas.width === 0) {
throw "omg";
}

e.element.style.setProperty("opacity", "0");
e.uniforms["src"].value = texture;
oldTexture.dispose();

texture.needsUpdate = true;
e.element.style.setProperty("opacity", "0");
} catch (e) {
console.error(e);
}
Expand Down

0 comments on commit 38608a8

Please sign in to comment.