Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[models] Importer for MagicaVoxel .vox files does not handle multiple chunks in one .vox file #4806

Open
jhcdjhcd opened this issue Mar 2, 2025 · 0 comments

Comments

@jhcdjhcd
Copy link

jhcdjhcd commented Mar 2, 2025

Issue description

The .vox file format (https://paulbourke.net/dataformats/vox/) specifies that you can have multiple chunks in one file. Each is introduced by a SIZE section. In https://github.com/raysan5/raylib/blob/master/src/external/vox_loader.h you can see in Vox_LoadFromMemory where the SIZE sections are handled there is always a call to Vox_AllocArray where m_arrayChunks is always resized based on the values for that SIZE section. What this means in practice is that each SIZE section ends up resetting the loaded chunks in our VoxArray3D, so whichever chunk data happens to come last in the file is the only data that gets loaded.

There is an example file at https://static.biomes.aw/wood_container.vox that illustrates the problem. In MagicaVoxel you can see it's a model of a wooden chest consisting of two sub-parts. When it's loaded in a raylib app the top is missing - see screenshots.

Environment

Windows 11 x64 10.0.26100 Build 26100, NVIDIA GeForce RTX 3090, OpenGL v4.6

Issue Screenshot

Full model in MagicaVoxel:
Image
Model with bottom part disabled in Magic Voxel:
Image
Model as it's loaded in raylib app:
Image

Code Example

#include "raylib.h"

int main(void) {

    InitWindow(1280, 720, "Vox Test");
    SetTargetFPS(60);

    Camera3D camera = {
        .position = (Vector3){ 10.0f, 14.0f, 10.0f },
        .target = (Vector3){ 0.0f, 0.0f, 0.0f },
        .up = (Vector3){ 0.0f, 1.0f, 0.0f },
        .fovy = 50.0f,
        .projection = CAMERA_PERSPECTIVE
    };

    Model model = LoadModel("./vox_examples/wood_container.vox");
    Vector3 modelPosition = { 0.0f, 0.0f, 0.0f };

    while (!WindowShouldClose()) {

        UpdateCamera(&camera, CAMERA_ORBITAL);

        BeginDrawing();
        ClearBackground(RAYWHITE);

        BeginMode3D(camera);
        DrawModel(model, modelPosition, 1.0f, WHITE);
        DrawGrid(10, 1.0f);
        EndMode3D();

        DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY);

        EndDrawing();
    }

    UnloadModel(model);
    CloseWindow();

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant