mise
1
I want to do this:
drawImage(dynamicTexture: DynamicTexture, texture: Texture) {
const ctx = dynamicTexture.getContext();
ctx.drawImage(texture.???, 0, 0);
dynamicTexture.update();
}
drawImage takes a https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource
how can I do this without loading the image url again?
You cannot unfortunately
the Canvas2D needs CPU data and not GPU data. You can download again it will be almost free thanks to the browser cache
JohnK
3
2 Likes
mise
4
awesome, that looks like exactly what I needed.
mise
5
For anyone looking, this is how you can use drawImage as well:
const pixeldata = texture.readPixels() as any;
const arr = new Uint8ClampedArray(pixeldata);
const imageData = new ImageData(arr, texture.getSize().width, texture.getSize().height);
createImageBitmap(imageData).then(bitmap => {
const ctx = dynamicTexture.getContext();
ctx.drawImage(image, x, y, w, h);
dynamicTexture.update();
});