Closed mgerhardy closed 2 years ago
I'm almost sure that the problem is in the way I calculate the pivot.
commit 103ae55b5f32f8ea5bae86aa573508fd7058c731 (HEAD -> master)
Author: Martin Gerhardy <martin.gerhardy@gmail.com>
Date: Wed Feb 2 19:16:03 2022 +0100
VOXELFORMAT: pivot issue with magicavoxel vox files #110
diff --git a/src/modules/voxelformat/VoxFormat.cpp b/src/modules/voxelformat/VoxFormat.cpp
index e3a204ca3..84bc0758d 100644
--- a/src/modules/voxelformat/VoxFormat.cpp
+++ b/src/modules/voxelformat/VoxFormat.cpp
@@ -97,7 +97,7 @@ bool VoxFormat::addInstance(const ogt_vox_scene *scene, uint32_t ogt_instanceIdx
const uint8_t *ogtVoxels = ogtModel->voxel_data;
const uint8_t *ogtVoxel = ogtVoxels;
const glm::ivec3 maxs(ogtModel->size_x - 1, ogtModel->size_y - 1, ogtModel->size_z - 1);
- const glm::vec4 pivot((float)maxs.x / 2.0f + 0.5f, (float)maxs.y / 2.0f + 0.5f, (float)maxs.z / 2.0f + 0.5f, 0.0f);
+ const glm::vec4 pivot(glm::floor((float)maxs.x / 2.0f) + 0.5f, glm::floor((float)maxs.y / 2.0f) + 0.5f, glm::floor((float)maxs.z / 2.0f) + 0.5f, 0.0f);
const glm::ivec3& transformedMins = transform(ogtMat, glm::ivec3(0), pivot);
const glm::ivec3& transformedMaxs = transform(ogtMat, maxs, pivot);
const glm::ivec3& zUpMins = transform(zUpMat, transformedMins, glm::ivec4(0));
but this fix broke some other models (like the lion)
c5f3487d1a74e7684ef3de857b7e2c03cf183bc6 fixes a sorting issue
It looks like the problem is with the group order of the vox file. See the following screenshots.
Notice the voxel poking through the hat
Using the original order of the groups fixes the "problem" in magicavoxel - but not in our voxel importer.