How to put like mesh vertex or mesh normal into a texture?

I want to use a texture to represent mesh data(normal index vertex uv…)

Hi @11145

I haven’t done that myself, but I think you can loop through the mesh arrays (position, indices, uv coords) and set the texture’s pixels for each using setSource():

Make sure the texture type selected has sufficient precision.

1 Like

thx,but this function only use DOM object.

Yes, sorry, I meant this:

You can create a canvas, set the pixels and then extract the image from the canvas to create a PlayCanvas texture.

This example here copies some vertex like data (wind direction, similar to normals) to textures and uses it as a shader parameter: PlayCanvas Examples

And this one gets positions from the mesh and modifies it on the CPU: PlayCanvas Examples

So I guess you need a combination of these two? Get positions / normals from the mesh, write them to a texture, and then use them in a custom shader.

There are more examples in the engine source code directly I can point you to if needed, bit more advanced - they use higher precision texture formats to store the data (16 or 32 bit per channel), or use encoding / decoding to store larger precision data in multiple 8bit channels.

2 Likes

(@mvaligursky I’ve edited your message the links you posted where pointing to localhost:5000)

1 Like

(great idea, thanks!) :slight_smile:

1 Like