aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-02-18 18:46:17 +0100
committerRay <raysan5@gmail.com>2019-02-18 18:46:17 +0100
commitd62652c5b29b322c8c9fa2ab7c7912fe366cd4bc (patch)
tree4a908dfa9c6ee10b5ed4b71fed7b4a3e2b339422 /src
parent5d0ea7f11063c302e338e03370f2a7d6ce6f6748 (diff)
downloadraylib-d62652c5b29b322c8c9fa2ab7c7912fe366cd4bc.tar.gz
raylib-d62652c5b29b322c8c9fa2ab7c7912fe366cd4bc.zip
Update cgltf library
Added some comments to loader function...
Diffstat (limited to 'src')
-rw-r--r--src/external/cgltf.h51
-rw-r--r--src/models.c24
2 files changed, 62 insertions, 13 deletions
diff --git a/src/external/cgltf.h b/src/external/cgltf.h
index 81e1ac7f..4302e77b 100644
--- a/src/external/cgltf.h
+++ b/src/external/cgltf.h
@@ -1,6 +1,49 @@
/**
* cgltf - a single-file glTF 2.0 parser written in C99.
+ *
+ * Version: 1.0
+ *
+ * Website: https://github.com/jkuhlmann/cgltf
+ *
* Distributed under the MIT License, see notice at the end of this file.
+ *
+ * Building:
+ * Include this file where you need the struct and function
+ * declarations. Have exactly one source file where you define
+ * `CGLTF_IMPLEMENTATION` before including this file to get the
+ * function definitions.
+ *
+ * Reference:
+ * `cgltf_result cgltf_parse(const cgltf_options*, const void*,
+ * cgltf_size, cgltf_data**)` parses both glTF and GLB data. If
+ * this function returns `cgltf_result_success`, you have to call
+ * `cgltf_free()` on the created `cgltf_data*` variable.
+ * Note that contents of external files for buffers and images are not
+ * automatically loaded. You'll need to read these files yourself using
+ * URIs in the `cgltf_data` structure.
+ *
+ * `cgltf_options` is the struct passed to `cgltf_parse()` to control
+ * parts of the parsing process. You can use it to force the file type
+ * and provide memory allocation callbacks. Should be zero-initialized
+ * to trigger default behavior.
+ *
+ * `cgltf_data` is the struct allocated and filled by `cgltf_parse()`.
+ * It generally mirrors the glTF format as described by the spec (see
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0).
+ *
+ * `void cgltf_free(cgltf_data*)` frees the allocated `cgltf_data`
+ * variable.
+ *
+ * `cgltf_result cgltf_load_buffers(const cgltf_options*, cgltf_data*,
+ * const char*)` can be optionally called to open and read buffer
+ * files using the `FILE*` APIs.
+ *
+ * `cgltf_result cgltf_parse_file(const cgltf_options* options, const
+ * char* path, cgltf_data** out_data)` can be used to open the given
+ * file using `FILE*` APIs and parse the data using `cgltf_parse()`.
+ *
+ * `cgltf_result cgltf_validate(cgltf_data*)` can be used to do additional
+ * checks to make sure the parsed glTF data is valid.
*/
#ifndef CGLTF_H_INCLUDED__
#define CGLTF_H_INCLUDED__
@@ -462,6 +505,10 @@ void cgltf_free(cgltf_data* data);
void cgltf_node_transform_local(const cgltf_node* node, cgltf_float* out_matrix);
void cgltf_node_transform_world(const cgltf_node* node, cgltf_float* out_matrix);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* #ifndef CGLTF_H_INCLUDED__ */
/*
@@ -4266,10 +4313,6 @@ static void jsmn_init(jsmn_parser *parser) {
#endif /* #ifdef CGLTF_IMPLEMENTATION */
-#ifdef __cplusplus
-}
-#endif
-
/* cgltf is distributed under MIT license:
*
* Copyright (c) 2018 Johannes Kuhlmann
diff --git a/src/models.c b/src/models.c
index 5feec0f6..eace0f66 100644
--- a/src/models.c
+++ b/src/models.c
@@ -2748,17 +2748,17 @@ static Mesh LoadIQM(const char *fileName)
#endif
#if defined(SUPPORT_FILEFORMAT_GLTF)
-// Load GLTF mesh data
+// Load glTF mesh data
static Mesh LoadGLTF(const char *fileName)
{
Mesh mesh = { 0 };
- // GLTF file loading
+ // glTF file loading
FILE *gltfFile = fopen(fileName, "rb");
if (gltfFile == NULL)
{
- TraceLog(LOG_WARNING, "[%s] GLTF file could not be opened", fileName);
+ TraceLog(LOG_WARNING, "[%s] glTF file could not be opened", fileName);
return mesh;
}
@@ -2771,22 +2771,28 @@ static Mesh LoadGLTF(const char *fileName)
fclose(gltfFile);
- // GLTF data loading
+ // glTF data loading
cgltf_options options = {0};
cgltf_data data;
cgltf_result result = cgltf_parse(&options, buffer, size, &data);
-
+
+ free(buffer);
+
if (result == cgltf_result_success)
{
printf("Type: %u\n", data.file_type);
printf("Version: %d\n", data.version);
printf("Meshes: %lu\n", data.meshes_count);
+
+ // TODO: Process glTF data and map to mesh
+
+ // NOTE: data.buffers[] and data.images[] should be loaded
+ // using buffers[n].uri and images[n].uri... or use cgltf_load_buffers(&options, data, fileName);
+
+ cgltf_free(&data);
}
- else TraceLog(LOG_WARNING, "[%s] GLTF data could not be loaded", fileName);
+ else TraceLog(LOG_WARNING, "[%s] glTF data could not be loaded", fileName);
- free(buffer);
- cgltf_free(&data);
-
return mesh;
}
#endif