Skip to content

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

Open
@jhcdjhcd

Description

@jhcdjhcd

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    externalThis issue depends on external lib

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions