Hi everyone. I am trying to duplicate a house that has been lightmaped in a scene multiple times and have it in a batch group too so it doesn’t cost any performance. I think the best way is to extract the lightmap that engine bakes so I can put it in the lightmap slot. now is there a way to extract and save the lightmap that engine bakes as a PNG ?
No there isn’t a way to do that as an API. But you may be able to write a system that exports the render targets.
@mvaligursky will know more on this.
There isn’t a way to save lightmaps at the moment. The idea here is that the lightmapper is very fast and you can generate lightmaps at the start instead of loading them, which can often take longer (especially on slower connections).
If you want to download lightmaps, there are other higher quality external baking tools you could look into.
Note that lightmapper is not compatible with batching at this stage, and so should not be used together.
But Iagree with @Leonidas - you could in theory walk over mesh instances that are baked, use GetParameter on it to access the lightmap Texture, and save it off … but it would not be straightforward I’m afraid as it’s not officially tested / supported path.
Thank you for your in depth reply.
the thing is I actually really like the lightmap right now PlayCanvas generated. and I don’t think it would be easy or even possible to recreate that in any other software. I think it would be worth it to be able to be able to save the map from playcanvas engine and use it in lightmap slot. now would you please help me do it or give me some guidance to how to do it?
Inspect this file: https://github.com/playcanvas/engine/blob/dev/src/scene/mesh-instance.js
the setRealtimeLightmap is a function called when the lightmap texture is generated and assigned to the mesh instance. See how it calls get parameter on it to access the texture.
const old = this.getParameter(name);
You could call the same getParameter to get access to the texture and save it.
How to do saving easily to a file (for example tga) I’m not entirely sure, I think other people can advice on this - we probably have some take screenshot tutorials that do it. Note that the texture needs to be saved with alpha channel as well.