Add basic loader for gltf

Added loading of avocado. Something is still wrong though,
becaus I cannot see the seed. But basic functionality is there.
This commit is contained in:
Piotr Krygier
2026-03-19 21:00:39 +01:00
parent 984a56a8e8
commit 99fb36d9fd
14 changed files with 186 additions and 32 deletions
+1 -1
View File
@@ -4382,7 +4382,7 @@ static int cgltf_parse_json_diffuse_transmission(cgltf_options* options, jsmntok
// Defaults
cgltf_fill_float_array(out_diff_transmission->diffuse_transmission_color_factor, 3, 1.0f);
out_diff_transmission->diffuse_transmission_factor = 0.f;
for (int j = 0; j < size; ++j)
{
CGLTF_CHECK_KEY(tokens[i]);
+1 -1
View File
@@ -28,7 +28,7 @@
exit(1); \
}
#define rse_free(ptr) free(ptr);
#define rse_free(ptr) if (ptr != NULL) free(ptr);
#define rse_memcpy(dst, src, size) memcpy(dst, src, size);
#define rse_memset(ptr, value, size) memset(ptr, value, size);
+2 -1
View File
@@ -3,6 +3,7 @@
#include <stddef.h>
#include "commons.h"
#include "cgltf.h"
#define MAX_PATH_LENGTH (4096U)
@@ -22,7 +23,7 @@ rse_err_t file_load_pixels(const char* file_name, unsigned char* buffer, size_t*
rse_err_t file_append_full_path(char* file_path, size_t max_buffer_size);
rse_err_t file_json_parser(const char* file_name);
rse_err_t file_load_gltf(const char* file_name, cgltf_data** data);
#endif /* FILE_UTILS_H */
+2 -4
View File
@@ -247,24 +247,22 @@ rse_err_t file_write(const char* file_name, size_t bytes_count, char* buffer)
return ret;
}
rse_err_t file_load_gltf(const char* file_name)
rse_err_t file_load_gltf(const char* file_name, cgltf_data** data)
{
char real_path[MAX_PATH_LENGTH] = {0};
rse_err_t ret = RSE_ERROR_NO_ERROR;
cgltf_options options = {0};
cgltf_data* data = NULL;
strncpy(real_path, file_name, MAX_PATH_LENGTH);
if ((ret = file_append_full_path(real_path, MAX_PATH_LENGTH)) != RSE_ERROR_NO_ERROR) {
return ret;
}
if (cgltf_parse_file(&options, real_path, &data) != cgltf_result_success) {
if (cgltf_parse_file(&options, real_path, data) != cgltf_result_success) {
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Failed to parse GLTF data");
return RSE_ERROR_INTERNAL_ERROR;
}
cgltf_free(data);
return ret;
}