I have material which was loaded as an pc.Asset. This material has diffuseMap (which was loaded with the material) and I want to access pixels of this texture. I do it as follows:
mat.diffuseMap.lock({mode: pc.TEXTURELOCK_READ});
But instead of an array with pixels I get ImageBitmap object with properties { width: 512, height: 512 }
There is also support for this added in the engine recently. I think it’s merged, though I’m not aware of a public example on how to use it. @slimbuck@mvaligursky any idea?
The async texture download is just an internal implementation we’re testing, it’s not ready for release. The API will most likely change as well as we’ll implement WebGPU version.
Hi @Leonidas, thank for the reply. Your methid readPixelsFromTexture() works but I still have a problem with it.
I have a material with a diffuseMap texture. I load this material as an Asset and I don’t use this material on any MeshInstance.
I want to create a new texture based on the original texture from the material an then I want to use this new texture for another material.
The problem is that I can’t get pixels from the original texture if I don’t use the original material on a MeshInstance. If I try to use you readPixelsFromTexture() before using the original material, all pixels are zero.
Is there a way how to initialize the texture without applying the material to a MeshInstance?
initBodyMaterial() use the baseMat.diffuseMap texture for filling dynamic texture. It works if I use the baseMat on some visible MeshInstance but not without it pc.Texture.upload() didn’t help.
One way to extract data from any texture (including compressed formats) is to render it to another texture. I’m just adding code to handle this to usdz exporter, but this is the core of this: