jpaver / opengametools

A set of open c++ game development tools that are lightweight, easy-to-integrate and free to use. Currently hosting a magicavoxel .vox full scene loader.
MIT License
373 stars 35 forks source link

ogt: add ogt_stream_from_paletted_voxels_simple api #7

Closed jpaver closed 3 years ago

jpaver commented 3 years ago

Added new function ogt_stream_from_paletted_voxels_simple which is a simple variant of ogt_mesh_from_paletted_voxels_simple that does not return an ogt_mesh, but rather calls into a user-provided function.

The use case for this is to

  1. provide a way for caller to modify geometry for each x/y/z voxel that generates geometry by using the x/y/z information to lookup additional non-voxel-field data.
  2. not have to allocate ogt_mesh_vertex data for the entire voxel field, which can be useful if direclty converting to a custom vertex format without basically doubling the memory footprint.

Internally, ogt_mesh_from_paletted_voxels_simple simply uses ogt_stream_from_paletted_voxels_simple to build up the ogt_mesh now.

jpaver commented 3 years ago

FYI @mrpossoms

The intention behind ogt_voxel_meshify_context was really just to be an allocator context - and in my engine I provide a per-thread devmode allocator for cooking on many threads at once. I know it wasn't very well documented/named for that, but that was the intention. It wasn't supposed to be a catch-all to prevent api overspecification.

I also wanted it to be clear of anything that is not applicable to all APIs that take the context because I wanted to avoid confusion from other users eg. If they set the emit_ctx member of the context but then later switch their call to the _greedy or _polygon generators, they might get stuck on figuring out why their callback is not getting called.

In addition, I wanted to:

Specifically, this PR:

Let me know if that works for you and I can get it in.

mrpossoms commented 3 years ago

@jpaver Yep this definitely looks like it would take care of my use case! My apologies for effectively forcing you to write the feature I needed 😆

jpaver commented 3 years ago

@jpaver Yep this definitely looks like it would take care of my use case! My apologies for effectively forcing you to write the feature I needed 😆

Haha no worries, glad you're getting some use out of it ;)