chrisdill / raylib-cs

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming
http://www.raylib.com/
zlib License
795 stars 69 forks source link

Problem with loading model from string (vox format) #168

Closed ghost closed 1 year ago

ghost commented 1 year ago

hello ! i started to writing game with raylib cs but when i started loading model (vox format) , i watched just a white cube in the middle of scene and in the console i seen this: photo

code:

using Raylib_cs; using System.Numerics;

namespace Other { static class Programm { public static void Main() { Raylib.InitWindow(1000, 800, "hello world !");

        Model model = Raylib.LoadModel("assets\\sword.vox");
        Camera3D camera = new Camera3D(
            new Vector3(0f, 2f, 10f),
            new Vector3(0f, 2f, 0f),
            new Vector3(0f, 1f, 0f),
            60f,
            CameraProjection.CAMERA_PERSPECTIVE
        );

        while (!Raylib.WindowShouldClose()) {
            Raylib.BeginDrawing();
            Raylib.BeginMode3D(camera);
            Raylib.DrawModel(model, new Vector3(0f, 1f, 0f), 1f, Color.WHITE);
            Raylib.EndMode3D();
            Raylib.EndDrawing();
        }
    }
}

}

p.s. i downloaded a library with Nuget and i use vs code

chrisdill commented 1 year ago

Where is the assets folder in your project? Are you able to load other resources from it or is the issue only with vox models?

nickyMcDonald commented 1 year ago

In your case it looks like the file loaded successfully but the VOX data did not. That looks like a formatting issue. I couldn’t reproduce this bug:

using Raylib_cs;
using System.Numerics;

Raylib.InitWindow(3000, 1800, "Hello World!");
Raylib.SetTargetFPS(60);

Model model = Raylib.LoadModel("Chicken.vox");
Camera3D camera = new(
    new Vector3(0f, 2f, 10f),
    new Vector3(5f, 0f, 0f),
    Vector3.UnitY,
    90f,
    CameraProjection.CAMERA_PERSPECTIVE);

while (!Raylib.WindowShouldClose())
{
    Raylib.BeginDrawing();
    Raylib.BeginMode3D(camera);
    Raylib.DrawModel(model, default, 1f, Color.WHITE);
    Raylib.EndMode3D();
    Raylib.EndDrawing();
}
Raylib.UnloadModel(model);

INFO: FILEIO: [Chicken.vox] File loaded successfully INFO: MODEL: [Chicken.vox] VOX data loaded successfully : 5512 vertices/1 meshes INFO: VAO: [ID 2] Mesh uploaded successfully to VRAM (GPU) screenshot000 Chicken.zip

ghost commented 1 year ago

sory that i too late The VOX data really doesn't load, although the model itself loads without problems But i noticed that this is not only a problem of CS version, i tried it with C++ and doesn't work too However with C (and mcvs) it's work succesful

image

C++ version: image

C# work tree example

nickyMcDonald commented 1 year ago

@SerikTamerlan, if you open Bob.vox in notepad are the first 5 characters “VOX -” or “VOX È” or neither? If it’s “VOX È” I would suggest trying to export Bob differently, so it shows as “VOX -”. I have never used MagicaVoxel, however I’m certain the fifth character is the version number. Its 150 ‘-‘ or 200 ‘È’. If you could play around with the settings so it exports as “VOX -” it should work. As a last resort you can try to write a ‘-‘ where the ‘È’ was to force down the version.

@ChrisDill, If I’m correct with my assumptions this pr Addition of support for vox files in version 200. by Bigfoot71 · Pull Request #3097 · raysan5/raylib (github.com) back in June should “fix” this problem. It would explain why Sarik got his models to work in C, however I’m still confused as to why it wouldn’t work in C++.

ghost commented 1 year ago

Hi ! Well when i open file with notepad, i seen just "VOX" and other characters, not "VOX -" , perhaps it's problem with encoding, however it's doesn't work. Also i made new vox model and export it with "VOX" format, but doen't work too

Now i'm thinking that i weired somthing wrong, so it doen't work

nickyMcDonald commented 1 year ago

Your vox file in order to load properly needs to pass the two checks shown in the link:

https://github.com/raysan5/raylib/pull/3097/files#diff-875e5e2d236b1008fda9390194783194918d063c839e6b8a417a859a017e2f69L542-L561

nickyMcDonald commented 1 year ago

To be clear it returns an invalid format error if the first four bytes aren't the string "VOX " <- including the space. It will also return a file version error if the next 4 bytes are not (uint)150.

So if your file does not start with "VOX -000" including all the spaces (the last 3 are null characters '\0'). You will continue to run into this issue.

Hope this helps :/