polyscope
polyscope copied to clipboard
Set custom texture
Hi, first of all, thank you for making such a great interface! It is really useful and easy to tweak.
In my work, I often need to visualize textured meshes using parametrization. The textures provided are not enough, unfortunately. The best solution would be is to use an image as texture. Example of a texture.
I am willing to code it myself, however, I am not sure where to start. How can it be done? What files/functions should I look into?
Thank you!
Hi! Thanks for reaching out.
As your say, texture mapping is not something Polyscope supports right now. It's on the roadmap, but I haven't gotten around to it yet.
This is probably not an easy change to make. In general, the internals of Polyscope are not very well documented for anyone other than me to edit :)
However, if you wanted to get it a shot, some basic steps would be:
- Create a new
SurfaceQuantity
, such as aSurfaceTextureMapQuantity
, similar to https://github.com/nmwsharp/polyscope/blob/master/include/polyscope/surface_color_quantity.h (etc) - Make this quantity take a set of texture coordinates per-vertex or per-corner as input, using the adaptors, and ALSO take an image (in some format; Polyscope does not have a standard API for users passing in images yet).
- Load the texture and UV data in to the render engine. There is already
render::Engine::generateTextureBuffer()
which loads the image from a data pointer. - Create a shader which renders by indexing the image texture; hopefully you can sort through this by copying the existing shaders
Thanks Nicholas! I did implement that here. My implementation does not entirely follow your guidelines, unfortunately. (implemented shortly after posting the question)
Feel free to copy-paste code from it as needed of course. Otherwise, I will re-arrange the code following your points and make a pull request. It will take me a while.
Hey @nmwsharp @luca-morreale any update regarding official custom texture support? Badly needed here :D
FYI, texture support has been recently merged. Both color and scalar textures are supported, and they pull their UV coordinates from a separate ParameterizationQuantity.
It's not yet documented on the docs website yet. I'm trying to get those docs written up ASAP for this and some other changes to cut a new version, hopefully in the next week or two 🤞.
In the meantime:
Adder functions: https://github.com/nmwsharp/polyscope/blob/master/include/polyscope/surface_mesh.h#L127-L144 Example usage: https://github.com/nmwsharp/polyscope/blob/master/test/src/surface_mesh_test.cpp#L166-L182
That's amazing, thank you!