Saving Baked Lightmaps

Hi folks,

I’m working on a project that involves a large environment with lots of assets surrounding it. Due to that, I’m both baking lightmaps instead of using realtime, but also decided to “chunk” my map into smaller areas that get loaded in or offloaded as you get close to them. The catch is that since these chunks are not there from the start, they don’t get light baking information and load up unlit.

Anyone knows how to
A: trigger a new lightmap bake (ideally bake again on all objects with tag X)
or
B: save light bake information and add that to models so that they look properly lit when loaded in w/o having to light bake mid-run time and risk chugging.
or
C: any other ideas yall may have!

Thanks in advance!

Hi @HugoH2p !

I think I’ve had a similar problem as you in the past. Take a look here at the API reference for the lightmapper part of the Playcanvas application:

https://developer.playcanvas.com/en/api/pc.Lightmapper.html

You’ll see that the lightmapper accepts an array argument of entities that need to be rebaked, or provide nothing if you want to rebake the whole scene. Since doing the whole scene was too expensive for my use, I collected the entities I needed and than passed them to the lightmapper. It would look something like this in your script:

this.app.lightmapper.bake([<YOUR-ENTITIES-HERE>]);

If you couple that with a GraphNode Tag search you should be able to achieve what you’re looking for. That might look something like this:

var entities = this.app.root.findByTag('YOUR-TAG-HERE');

this.app.lightmapper.bake(entities);

I hope this is helpful.

3 Likes

You may also want to consider baking your lightmaps in the 3D modelling package instead so you don’t have to do it at runtime : Lightmapping | Learn PlayCanvas