guillaumechereau / goxel

Goxel: Free and Open Source 3D Voxel Editor
GNU General Public License v3.0
2.84k stars 226 forks source link

Imported models are automatically clipped #359

Closed madd-games closed 8 months ago

madd-games commented 8 months ago

I've been experimenting with adding a custom file format for import/export to allow integration with a game I'm working on. The format is very simple and simply saves the grid of voxel colors as an array, alongside the size in all dimensions.

My import_func() therefore sets the image->box to the size loaded from the file. The problem is that this is called from goxel_import_file() in goxel.c which, after calling import_func(), does this:

    if (image_was_empty) {
        image_auto_resize(goxel.image);
    }

This essentially clips the bounds to bounding box of the voxels themselves, removing any empty space on the edges. When I associate my file type with goxel, the image is indeed empty before the import, and so empty space on the edges of the image is clipped. This is undesirable, because as a user I want all data from the model to be preserved, including its size, even if there is empty space.

I'm not sure if I understand the rationale for this code, so I might be missing something, but for my use case, it was enough to remove this code and the problem goes away. Let me know if there is more rationale to this and therefore a different solution is needed. I am happy to make a pull request to fix this once I understand fully.

Thank you

guillaumechereau commented 8 months ago

Right, I'll check it out. Not sure why I added this exactly.

guillaumechereau commented 8 months ago

OK I checked a bit. If I am not mistaken the behavior should be that if the import format did set its layer size, then the image should be resized to it. So normally if your import function sets the layer box size it should be conserved.

Did you write your file import as a js plugin, or as a C file?

madd-games commented 8 months ago

I wrote it as a C file, directly modifying Goxel code.

I see now that the problem was that I was setting the image box but not the layer box. After this change, this code is no longer causing problems.

GrandyB commented 6 months ago

Similar case here where it was auto resizing on first import in a way that wasn't ideal for a specific import being added.

Setting the layer box works. however it has the side effect of the layer becoming "bounded", which I'd prefer it didn't do... but having it bounded is better than the size being smaller than I intend the image to be... would be great if some other method was tried.