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?
Most likely the texture hasnāt been uploaded to the GPU before being used by a model. Can you try calling upload to your texture before accessing it?
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: