Hi, I’m trying to use worker to render scene. I want to render some dynamic font use CanvasTexture. But I find when use TransferControlToOffscreen, if I change the text, the render loop will stop, but new OffscreenCanvas do not.
//if use new OffscreenCanvas, render loop will work fine.
//if not, canvas2 is transferd from main thread, when change the text, render loop will stop sometimes
//canvas2=new OffscreenCanvas(200,200);
canvas2.height = 200;
canvas2.width = 200;
let context = canvas2.getContext('2d');
context.font = "40px Helvetica";
context.fillStyle = 'red';
context.fillText("123", canvas2.width / 2, canvas2.height / 2);
this.sprite = new THREE.Sprite(new THREE.SpriteMaterial({map: new THREE.CanvasTexture(canvas2)}));
this.sprite.scale.set(50, 50, 50);
this.scene.add(this.sprite);
Change like this:
export function click() {
let tempCanvas = sprite.material.map.image;
let tempContext = tempCanvas.getContext("2d");
tempContext.clearRect(0, 0, 200, 200);
tempContext.fillText(String(Math.random().toFixed(2)), 100, 100);
sprite.material.map.needsUpdate = true;
}
Could anyone tell the difference between them? Thanks in advance.