Author Topic: TerrainGenerator importing async data (eg. UnityWebRequest)  (Read 61 times)

RunningPixel

  • Newbie
  • *
  • Posts: 6
    • View Profile
Hi team!
I would like to import chunk of data on request for chunk generation from async data sources (web, firebase, rest api ...)
peeking into code and documentation the right place to do this should be PaintChunk (VoxelChunk chunk) into a TerrainGenerator, but this is not an async method or a corountine so it will not wait for data being loaded.

Have you any suggestion on how to achieve this?

I was wondering if using hasContent, returning it to false until the data is loaded will trigger a chunk reload or once is called it is gone and will be not called PaintChunk again.

Cheers!

[EDIT]
Just made a quick test to see if PaintChunk returning false on a chunk triggers another try later and it does not.

« Last Edit: April 24, 2021, 02:50:57 PM by RunningPixel »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6981
    • View Profile
Re: TerrainGenerator importing async data (eg. UnityWebRequest)
« Reply #1 on: April 27, 2021, 09:31:00 AM »
Hi,

In this case you will need to overwrite the contents of the chunk once you get the data from the network.

1) Use the OnChunkBeforeCreate event to initiate the download.
2) In the PaintChunk you could just return so the chunk contents are empty.
3) When your download is read, you could use SetChunkRawData (or fill the chunk.voxels[] array directly) and call ChunkRedraw method to refresh the chunk contents.

Regards

RunningPixel

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: TerrainGenerator importing async data (eg. UnityWebRequest)
« Reply #2 on: April 27, 2021, 05:53:19 PM »
Oh, cool, nice approach. Thank you.
In case there some water into the data loaded I have to make something special in order to let it work properly?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6981
    • View Profile
Re: TerrainGenerator importing async data (eg. UnityWebRequest)
« Reply #3 on: April 28, 2021, 08:25:28 AM »
Water is just an attribute of each voxel. It's stored in the flags field, as you can see in the SetWaterLevel method. If you're using the "ChunkRawData" methods, those fields are read/set as well, so it should just work.