expand_content

A processor is a component that runs after the terrain and all masks have been generated, adding extra steps to the data. These steps are kept separate from the main workflow to maintain modularity and compatibility. You can find examples in Chunk Data Processors.

Processors can:

  • Generate additional data based on existing masks or graph-generated data.
  • Provide alternative methods for creating a mesh.
  • Ensure compatibility with other assets by acting as a bridge.
  • Perform other specialized tasks as needed. 

The general workflow for creating your own processor goes like this:

  • Decide what it processes. For example, if it processes Chunk Data, implement the abstract class ChunkProcessor<T> (e.g., ChunkProcessor<ChunkData>). This ensures the component follows the correct lifecycle with existing components and provides the necessary methods for custom processing.
  • Decide what it outputs. For example, if the result is a Mesh, implement the interface IGenerate<T> (e.g., IGenerate<MeshResult>).
  • Handle data persistence (if working with ChunkData). Right after receiving the data, the processor should add itself to the processor list using AddProcessor(). This prevents the data from being disposed of while other processors are still using it.
protected override void OnProcessDone(ChunkData chunk){
    chunk.worldFinalData.AddProcessor(this);
    ChunksToProcess.Add(chunk);
    if(chunk.InstantGeneration)
        UpdateRequests(true);
}

Once processing is complete and the original data is no longer needed, the component should be removed so the data can be disposed of and returned to the pool.

  • Work with the data:
    • Cache the data and store it in a list to allow asynchronous processing.
    • Process it immediately and apply any necessary changes.
    • Discard it and return it to the pool if no modifications are needed.