Skip to content

[model] what is the mesh vertex size #2165

Description

@Abdelilah-Majid

Please, before submitting a new issue verify and check:

  • [ x ] I tested it on latest raylib version from master branch
  • [ x ] I checked there is no similar issue already reported
  • [ x ] My code has no errors or misuse of raylib

Issue description

hi! i am building a game engine with c and raylib and i want to use this library for optimizing meshes : https://github.com/zeux/meshoptimizer

so i am using obj models and they are not indexed and this library need an indexed mesh, and also i need an indexed mesh to implement LOD

this library has some functions for indexing a mesh:

size_t index_count = face_count * 3; std::vector<unsigned int> remap(index_count); // allocate temporary memory for the remap table

size_t vertex_count = meshopt_generateVertexRemap(&remap[0], NULL, index_count, &unindexed_vertices[0], index_count, sizeof(Vertex));


meshopt_remapIndexBuffer(indices, NULL, index_count, &remap[0]);
 meshopt_remapVertexBuffer(vertices, &unindexed_vertices[0], index_count, sizeof(Vertex), &remap[0]);

so i put this code into my game engine and i set the vertex size to sizeof(float) and i got some weird effects with my mesh, so i submite an issue in this lib repo and the guy there said that the vertex size should not be 4bytes its 12 or even more;

so i have started expirementing with the vertex size i put 12 and a lot other values and i have started searching in the rlgl.h but it never give me the correct value;

can any one give me the correct size of a mesh vertex;

thanks

Environment

pc, fedora 34, opengl 2.1, an old inte integrated graphics ship

Issue Screenshot

Screenshot from 2021-11-21 23-33-13
Screenshot from 2021-11-21 23-33-29
Screenshot from 2021-11-22 15-39-28
Screenshot from 2021-11-22 15-39-39

Code Example

 for (int i = 0; i < g_model.model.meshCount; i++) {
    unsigned int vertex_size = sizeof(float)*3+1; //12+2*9-1 ;
    size_t index_count = g_model.model.meshes[i].triangleCount * 3;

    unsigned int *indices = malloc(sizeof(unsigned int) * index_count);
    g_model.model.meshes[i].indices = (unsigned short *)malloc(sizeof(unsigned short) * index_count);

    unsigned int *remap = malloc(sizeof(unsigned int) * index_count); // allocate temporary memory for the remap table
    size_t vertex_count = meshopt_generateVertexRemap(remap, NULL, index_count, g_model.model.meshes[i].vertices, index_count, vertex_size);

    float *vertices = malloc(vertex_size * vertex_count);

    meshopt_remapIndexBuffer(indices, NULL, index_count, remap);

    meshopt_remapVertexBuffer(vertices, g_model.model.meshes[i].vertices, index_count, vertex_size, remap);

    for (unsigned short j = 0; j < index_count; j++) {
      g_model.model.meshes[i].indices[j] = (unsigned short)indices[j];
      printf("indices_%d: %d\n", j, indices[j]);
    }

    g_model.model.meshes[i].vertices = vertices;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions