From 04f81538b7d458569d280dc1e10e517494df9fa4 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 29 Mar 2026 21:37:01 +0200 Subject: [PATCH] ADDED: Some sample code to export gltf/glb meshes -WIP- --- src/rmodels.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/rmodels.c b/src/rmodels.c index 6c1e0482e..3fff05eaa 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -10,6 +10,7 @@ * #define SUPPORT_FILEFORMAT_MTL * #define SUPPORT_FILEFORMAT_IQM * #define SUPPORT_FILEFORMAT_GLTF +* #define SUPPORT_FILEFORMAT_GLTF_WRITE * #define SUPPORT_FILEFORMAT_VOX * #define SUPPORT_FILEFORMAT_M3D * Selected desired fileformats to be supported for model data loading @@ -71,6 +72,11 @@ #define CGLTF_IMPLEMENTATION #include "external/cgltf.h" // glTF file format loading #endif +#if SUPPORT_FILEFORMAT_GLTF_WRITE + // NOTE: No need for custom allocators, memory buffer provided + #define CGLTF_WRITE_IMPLEMENTATION + #include "external/cgltf_write.h" // glTF file format writing +#endif #if SUPPORT_FILEFORMAT_VOX #define VOX_MALLOC RL_MALLOC @@ -2017,6 +2023,19 @@ bool ExportMesh(Mesh mesh, const char *fileName) RL_FREE(txtData); } + else if (IsFileExtension(fileName, ".gltf")) // Or .glb + { + // TODO: Implement gltf/glb support + /* + cgltf_size expected = cgltf_write(options, NULL, 0, data); + char *buffer = (char *)RL_CALLOC(expected, 0); + cgltf_size actual = cgltf_write(options, buffer, expected, data); + + // NOTE: cgltf_write() includes a NULL terminator that should be ommited in case of a .glb + if (options->type == cgltf_file_type_glb) cgltf_write_glb(file, buffer, actual - 1, data->bin, data->bin_size); + else SaveFileText(fileName, buffer); // Write a plain JSON file + */ + } else if (IsFileExtension(fileName, ".raw")) { // TODO: Support additional file formats to export mesh vertex data