|
Nebula
|
#include <terrainsession.h>
One terrain being edited: the Terrain component of an entity in a scene, the terrain file it names and the maps that file points to.
The maps are kept on the CPU, one texel per meter of the world: the heightmap, normalized from the terrain's lowest to its highest point, a mask per biome and a mask per plant. A brush changes them there, and the texels it touched are uploaded to the textures the renderer draws the terrain with. That is what makes a stroke undoable, a ray can find the ground without reading the GPU back, and saving writes images from what is already in memory.
The renderer's terrain belongs to the sim world. When the component is set up again, by an undo or a scene switch, the session builds the terrain again from what it holds, so the edits stay on screen. The structure of the terrain, its size, biomes and plants, is applied the same way.
Saving writes the maps as images to the source folder, imports them as textures next to the terrain file, writes the terrain file and batches them all. The component names the terrain file; one that names none gets the file the session saves to.