Skip to content

[rmodels] Some faces of the gltf model are not rendered ? #3165

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

Closed
nicklhy opened this issue Jul 11, 2023 · 6 comments
Closed

[rmodels] Some faces of the gltf model are not rendered ? #3165

nicklhy opened this issue Jul 11, 2023 · 6 comments
Labels
external This issue depends on external lib

Comments

@nicklhy
Copy link

nicklhy commented Jul 11, 2023

Issue description

I tried to load and render a gltf mesh model like below

Model model = LoadModel("/path/to/my/model.glb");

while (!WindowShouldClose()) {
    UpdateCamera(&camera, CAMERA_THIRD_PERSON);

    BeginDrawing();

    ClearBackground(RAYWHITE);

    BeginMode3D(camera);

    DrawModel(model, position, 1.0f, WHITE);  // Draw animated model
    DrawGrid(10, 1.0f);

    EndMode3D();

    EndDrawing();
}

The rendering result is like below.
model_render

The model opened in blender is like below.
blender_image

It looks like some faces of the mesh model are not rendered at all. And the color of other faces also looks quite different.

Environment

OS:Ubuntu 20.04

@nicklhy
Copy link
Author

nicklhy commented Jul 11, 2023

raylib 4.5
INFO: GL: OpenGL device information:
INFO: > Vendor: Intel
INFO: > Renderer: Mesa Intel(R) UHD Graphics (TGL GT1)
INFO: > Version: 4.6 (Core Profile) Mesa 21.2.6
INFO: > GLSL: 4.60

@raysan5
Copy link
Owner

raysan5 commented Jul 11, 2023

I think it could be related to the way the gltf is created. raylib uses cgltf library to load models.

@nicklhy
Copy link
Author

nicklhy commented Jul 12, 2023

I set the log level to debug and got this warning:

WARNING: MODEL: [asset/models/aircraft_carrier.glb] Indices data converted from u32 to u16, possible loss of data
WARNING: MODEL: [asset/models/aircraft_carrier.glb] Indices data converted from u32 to u16, possible loss of data
WARNING: MODEL: [asset/models/aircraft_carrier.glb] Indices data converted from u32 to u16, possible loss of data
WARNING: MODEL: [asset/models/aircraft_carrier.glb] Indices data converted from u32 to u16, possible loss of data

I also noticed that there is a restriction warning in rmodels.c:LoadGLTF,

- Vertex attibute types and formats supported:
    > Vertices (position): vec3: float
    > Normals: vec3: float
    > Texcoords: vec2: float
    > Colors: vec4: u8, u16, f32 (normalized)
    > Indices: u16, u32 (truncated to u16)

Does it mean raylib is only able to load mesh models with vertex number less than 65535 (max val of uint16_t) ?

@VVill-ga
Copy link

I just ran into this last week and you're on the right track. I'll try to explain it to the extent that I understand it.

GLTF is an indexed model format, meaning it lists out all the vertex coordinates in the mesh, and then uses sets of 3 indexes (like vertex 0 2 3, 2 3 5, etc) to make each triangle. For large models like yours, it is more efficient with space, but it takes more processing power for the GPU to compute and has that pesky vertex count limit which I believe comes from the functionality of the cgltf library that @raysan5 mentioned.

To solve this, you can use a non-indexed model format like .obj, which instead lists the position of each vertex in each triangle for every triangle. This makes the file format larger, but it is easier for the GPU to run through and draw the model. And it won't have the same indexing limit that the GLTF loader has.

@raysan5 raysan5 added the external This issue depends on external lib label Jul 13, 2023
@nicklhy
Copy link
Author

nicklhy commented Jul 14, 2023

Great thanks for your detailed reply ! That helps a lot for me to understand the current design.
I just tried the obj format, but it seems the vertex/face number could still be a problem.

test_model_loading: /path/to/xxx-project/build/_deps/raylib-src/src/external/tinyobj_loader_c.h:1105: parseLine: Assertion `3 * num_f < TINYOBJ_MAX_FACES_PER_F_LINE' failed.

I guess it is necessary to compress my model (vertex/edge/face numbers) in blender before use it in raylib.

@raysan5
Copy link
Owner

raysan5 commented Aug 6, 2023

This issue seems to be external to raylib, maybe related to cgltf.h library or how the model is exported from the 3d creation software. Please note that glTF format is a complex format with many export options and also several versions, not all possibilities are supported.

@raysan5 raysan5 closed this as completed Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This issue depends on external lib
Projects
None yet
Development

No branches or pull requests

3 participants