Closed mgerhardy closed 2 years ago
Hi Martin, and apologies for the late reply. I think you're right - this should be better documented in ogt_vox. I'm re-opening this issue until I can address this documentation.
The pivot for magicavoxel is the halfway through each voxel grid, (ie. each ogt_vox_model), precisely as you have it:
pivot.x = floor(model->size_x / 2);
pivot.y = floor(model->size_y / 2);
pivot.z = floor(model->size_z / 2);
My own use-case is to generate triangle mesh from voxel grid (using ogt_voxel_meshify), and I usually bias the output vertex positions of that meshify step (which are in mesh local space) like so:
for each vertex:
vertex.pos -= pivot;
The net effect is it recenters the output mesh such that the pivot is at coordinate (0,0,0) in mesh local space. Then I simply use the instance transforms within the scene for ordinary rendering.
Thanks for your response. I've only closed this because the linked pull request added a method to perform these steps - which is kind of a documentation, too.
I added some documentation in this commit: https://github.com/jpaver/opengametools/commit/d39bf794b43fd5c13afccb11bea92f7fafe257c3
@mgerhardy -- could you take a look and see if this is helpful? Otherwise, I will close as resolved. Thanks!
Thanks a lot - that should help ;)
Maybe it's obvious for everybody except me, but I thought that sharing my current implementation might help others and is a good opportunity to get some feedback on my solution:
the
zUpMat
is just to bring everything into my own coordinate system (y upwards)If I am doing something stupid here, please let me know. If not it might help others.
Find the full source code at https://github.com/mgerhardy/vengi/blob/master/src/modules/voxelformat/VoxFormat.cpp