Make the Magicavoxel parser load voxels lazily #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In my engine, I use gvox as follows. I identify chunks of the world (256³ regions) to be loaded, and forward them to background threads. These background threads instantiate a gvox context and adapters, and then do a parser-driven blit for that chunk.
The Magicavoxel adapter, upon instantiation, reads and loads the entire Magicavoxel file into memory as flat arrays. This is very wasteful and leads to computer lag for my use case (the system allocator is heavily burdened), since a bunch of extra models are loaded that fall outside of the 256³ region about which I care.
To fix this, this PR adds lazy loading of Magicavoxel model chunks. The voxels for a model from a Magicavoxel file are not decompressed until that model is read for the first time. This improves performance and eliminates lag spikes for me.