vengi-voxel / vengi

free and open source voxel art tools - editor, thumbnailer and format converter
http://vengi-voxel.github.io/vengi/
Other
1.08k stars 90 forks source link

VOXELFORMAT: pivot issue with magicavoxel vox files #110

Closed mgerhardy closed 2 years ago

mgerhardy commented 2 years ago

It looks like the problem is with the group order of the vox file. See the following screenshots.

group-order-3

Notice the voxel poking through the hat

group-order-2

Using the original order of the groups fixes the "problem" in magicavoxel - but not in our voxel importer.

group-order

mgerhardy commented 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));

Bildschirmfoto von 2022-02-02 19-56-36

but this fix broke some other models (like the lion)

Bildschirmfoto von 2022-02-02 19-58-23

mgerhardy commented 2 years ago

c5f3487d1a74e7684ef3de857b7e2c03cf183bc6 fixes a sorting issue