jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.42k stars 135 forks source link

GLTF primitive type not written correctly? #243

Closed mhuckvale closed 6 months ago

mhuckvale commented 7 months ago

In cgltf_write the GLTF primitive type is written by converting the internal enumeration with a cast to int:

  static void cgltf_write_primitive(cgltf_write_context* context, const cgltf_primitive* prim)
  {
     cgltf_write_intprop(context, "mode", (int) prim->type, 4);

However the internal enumeration uses a different coding than the GLTF standard, which causes the type written to be one larger than the correct value. So if a file is read, written, read back and written again, the primitive type increases by one each time. A quick fix is to subtract 1 from the internal code, but better would be to have a function to map the enumeration back to a GLTF code.

Thanks for the library.

Mark Huckvale

jkuhlmann commented 6 months ago

This should be fixed by the referenced commit.