92#ifndef CGLTF_H_INCLUDED__
93#define CGLTF_H_INCLUDED__
131 void (*
free) (
void* user,
void* ptr);
778 const char* gltf_path);
815#if defined(__INTELLISENSE__) || defined(__JETBRAINS_IDE__)
817#define CGLTF_IMPLEMENTATION
820#ifdef CGLTF_IMPLEMENTATION
828#if !defined(CGLTF_MALLOC) || !defined(CGLTF_FREE) || !defined(CGLTF_ATOI) || !defined(CGLTF_ATOF) || !defined(CGLTF_ATOLL)
833#define JSMN_PARENT_LINKS
852 JSMN_ERROR_NOMEM = -1,
854 JSMN_ERROR_INVAL = -2,
863#ifdef JSMN_PARENT_LINKS
869 unsigned int toknext;
872static void jsmn_init(jsmn_parser *parser);
873static int jsmn_parse(jsmn_parser *parser,
const char *js,
size_t len, jsmntok_t *tokens,
size_t num_tokens);
880static const cgltf_size GlbChunkHeaderSize = 8;
881static const uint32_t GlbVersion = 2;
882static const uint32_t GlbMagic = 0x46546C67;
883static const uint32_t GlbMagicJsonChunk = 0x4E4F534A;
884static const uint32_t GlbMagicBinChunk = 0x004E4942;
887#define CGLTF_MALLOC(size) malloc(size)
890#define CGLTF_FREE(ptr) free(ptr)
893#define CGLTF_ATOI(str) atoi(str)
896#define CGLTF_ATOF(str) atof(str)
899#define CGLTF_ATOLL(str) atoll(str)
901#ifndef CGLTF_VALIDATE_ENABLE_ASSERTS
902#define CGLTF_VALIDATE_ENABLE_ASSERTS 0
905static void* cgltf_default_alloc(
void* user,
cgltf_size size)
911static void cgltf_default_free(
void* user,
void* ptr)
919 if (
SIZE_MAX / element_size < count)
928 memset(result, 0, element_size * count);
935 void* (*memory_alloc)(
void*,
cgltf_size) = memory_options->
alloc ? memory_options->
alloc : &cgltf_default_alloc;
936 void (*memory_free)(
void*,
void*) = memory_options->
free ? memory_options->
free : &cgltf_default_free;
938 FILE* file = fopen(path,
"rb");
948 fseek(file, 0, SEEK_END);
952 __int64 length = ftell(file);
954 __int64 length = _ftelli64(file);
957 long length = ftell(file);
966 fseek(file, 0, SEEK_SET);
970 char* file_data = (
char*)memory_alloc(memory_options->
user_data, file_size);
977 cgltf_size read_size = fread(file_data, 1, file_size, file);
981 if (read_size != file_size)
983 memory_free(memory_options->
user_data, file_data);
1002 void (*memfree)(
void*,
void*) = memory_options->
free ? memory_options->
free : &cgltf_default_free;
1003 memfree(memory_options->
user_data, data);
1010 if (size < GlbHeaderSize)
1015 if (options ==
NULL)
1023 fixed_options.
memory.
alloc = &cgltf_default_alloc;
1027 fixed_options.
memory.
free = &cgltf_default_free;
1032 memcpy(&tmp, data, 4);
1033 if (tmp != GlbMagic)
1047 cgltf_result json_result = cgltf_parse_json(&fixed_options, (
const uint8_t*)data, size, out_data);
1060 memcpy(&tmp, ptr + 4, 4);
1062 if (version != GlbVersion)
1068 memcpy(&tmp, ptr + 8, 4);
1074 const uint8_t* json_chunk = ptr + GlbHeaderSize;
1076 if (GlbHeaderSize + GlbChunkHeaderSize > size)
1083 memcpy(&json_length, json_chunk, 4);
1084 if (GlbHeaderSize + GlbChunkHeaderSize + json_length > size)
1090 memcpy(&tmp, json_chunk + 4, 4);
1091 if (tmp != GlbMagicJsonChunk)
1096 json_chunk += GlbChunkHeaderSize;
1098 const void* bin = 0;
1101 if (GlbHeaderSize + GlbChunkHeaderSize + json_length + GlbChunkHeaderSize <= size)
1104 const uint8_t* bin_chunk = json_chunk + json_length;
1108 memcpy(&bin_length, bin_chunk, 4);
1109 if (GlbHeaderSize + GlbChunkHeaderSize + json_length + GlbChunkHeaderSize + bin_length > size)
1115 memcpy(&tmp, bin_chunk + 4, 4);
1116 if (tmp != GlbMagicBinChunk)
1121 bin_chunk += GlbChunkHeaderSize;
1124 bin_size = bin_length;
1127 cgltf_result json_result = cgltf_parse_json(&fixed_options, json_chunk, json_length, out_data);
1134 (*out_data)->bin = bin;
1135 (*out_data)->bin_size = bin_size;
1142 if (options ==
NULL)
1150 void* file_data =
NULL;
1158 result =
cgltf_parse(options, file_data, file_size, out_data);
1162 file_release(&options->
memory, &options->
file, file_data);
1166 (*out_data)->file_data = file_data;
1171static void cgltf_combine_paths(
char* path,
const char* base,
const char* uri)
1173 const char* s0 = strrchr(base,
'/');
1174 const char* s1 = strrchr(base,
'\\');
1175 const char* slash = s0 ? (s1 && s1 > s0 ? s1 : s0) : s1;
1179 size_t prefix = slash - base + 1;
1181 strncpy(path, base, prefix);
1182 strcpy(path + prefix, uri);
1193 void (*memory_free)(
void*,
void*) = options->
memory.
free ? options->
memory.
free : &cgltf_default_free;
1196 char* path = (
char*)memory_alloc(options->
memory.
user_data, strlen(uri) + strlen(gltf_path) + 1);
1202 cgltf_combine_paths(path, gltf_path, uri);
1207 void* file_data =
NULL;
1220 void (*memory_free)(
void*,
void*) = options->
memory.
free ? options->
memory.
free : &cgltf_default_free;
1222 unsigned char* data = (
unsigned char*)memory_alloc(options->
memory.
user_data, size);
1228 unsigned int buffer = 0;
1229 unsigned int buffer_bits = 0;
1233 while (buffer_bits < 8)
1235 char ch = *base64++;
1238 (unsigned)(ch -
'A') < 26 ? (ch -
'A') :
1239 (
unsigned)(ch -
'a') < 26 ? (ch -
'a') + 26 :
1240 (unsigned)(ch -
'0') < 10 ? (ch -
'0') + 52 :
1251 buffer = (buffer << 6) | index;
1255 data[i] = (
unsigned char)(buffer >> (buffer_bits - 8));
1264static int cgltf_unhex(
char ch)
1267 (
unsigned)(ch -
'0') < 10 ? (ch -
'0') :
1268 (unsigned)(ch -
'A') < 6 ? (ch -
'A') + 10 :
1269 (
unsigned)(ch -
'a') < 6 ? (ch -
'a') + 10 :
1275 char*
read = strchr(
string,
'\\');
1280 char* write = string;
1281 char* last = string;
1287 strncpy(write, last, written);
1294 case '\"': *write++ =
'\"';
break;
1295 case '/': *write++ =
'/';
break;
1296 case '\\': *write++ =
'\\';
break;
1297 case 'b': *write++ =
'\b';
break;
1298 case 'f': *write++ =
'\f';
break;
1299 case 'r': *write++ =
'\r';
break;
1300 case 'n': *write++ =
'\n';
break;
1301 case 't': *write++ =
'\t';
break;
1308 character = (character << 4) + cgltf_unhex(*
read++);
1311 if (character <= 0x7F)
1313 *write++ = character & 0xFF;
1315 else if (character <= 0x7FF)
1317 *write++ = 0xC0 | ((character >> 6) & 0xFF);
1318 *write++ = 0x80 | (character & 0x3F);
1322 *write++ = 0xE0 | ((character >> 12) & 0xFF);
1323 *write++ = 0x80 | ((character >> 6) & 0x3F);
1324 *write++ = 0x80 | (character & 0x3F);
1336 strcpy(write, last);
1348 int ch1 = cgltf_unhex(i[1]);
1352 int ch2 = cgltf_unhex(i[2]);
1356 *write++ = (char)(ch1 * 16 + ch2);
1371 if (options ==
NULL)
1401 if (strncmp(uri,
"data:", 5) == 0)
1403 const char* comma = strchr(uri,
',');
1405 if (comma && comma - uri >= 7 && strncmp(comma - 7,
";base64", 7) == 0)
1420 else if (strstr(uri,
"://") ==
NULL && gltf_path)
1443 char* data = (
char*)buffer_view->
buffer->
data + offset + buffer_view->
offset;
1446 switch (component_type)
1449 for (
size_t i = 0; i < count; ++i)
1452 bound = bound > v ? bound : v;
1457 for (
size_t i = 0; i < count; ++i)
1460 bound = bound > v ? bound : v;
1465 for (
size_t i = 0; i < count; ++i)
1468 bound = bound > v ? bound : v;
1479#if CGLTF_VALIDATE_ENABLE_ASSERTS
1480#define CGLTF_ASSERT_IF(cond, result) assert(!(cond)); if (cond) return result;
1482#define CGLTF_ASSERT_IF(cond, result) if (cond) return result;
1591 CGLTF_ASSERT_IF(indices &&
1658 components =
channel->target_node->mesh->primitives[0].targets_count;
1678 *dest_size = json_size + 1;
1684 if (*dest_size + 1 < json_size)
1687 dest[*dest_size - 1] = 0;
1692 dest[json_size] = 0;
1700 for (
cgltf_size i = 0; i < extensions_count; ++i)
1996 memcpy(lm, node->
matrix,
sizeof(
float) * 16);
2009 float sx = node->
scale[0];
2010 float sy = node->
scale[1];
2011 float sz = node->
scale[2];
2013 lm[0] = (1 - 2 * qy*qy - 2 * qz*qz) * sx;
2014 lm[1] = (2 * qx*qy + 2 * qz*qw) * sx;
2015 lm[2] = (2 * qx*qz - 2 * qy*qw) * sx;
2018 lm[4] = (2 * qx*qy - 2 * qz*qw) * sy;
2019 lm[5] = (1 - 2 * qx*qx - 2 * qz*qz) * sy;
2020 lm[6] = (2 * qy*qz + 2 * qx*qw) * sy;
2023 lm[8] = (2 * qx*qz + 2 * qy*qw) * sz;
2024 lm[9] = (2 * qy*qz - 2 * qx*qw) * sz;
2025 lm[10] = (1 - 2 * qx*qx - 2 * qy*qy) * sz;
2047 for (
int i = 0; i < 4; ++i)
2049 float l0 = lm[i * 4 + 0];
2050 float l1 = lm[i * 4 + 1];
2051 float l2 = lm[i * 4 + 2];
2053 float r0 = l0 * pm[0] + l1 * pm[4] + l2 * pm[8];
2054 float r1 = l0 * pm[1] + l1 * pm[5] + l2 * pm[9];
2055 float r2 = l0 * pm[2] + l1 * pm[6] + l2 * pm[10];
2072 switch (component_type)
2075 return *((
const int16_t*) in);
2083 return *((
const int8_t*) in);
2085 return *((
const uint8_t*) in);
2095 return *((
const float*) in);
2100 switch (component_type)
2116 return (
cgltf_float)cgltf_component_read_index(in, component_type);
2125 if (element_size < num_components) {
2131 cgltf_size component_size = cgltf_component_size(component_type);
2135 out[0] = cgltf_component_read_float(element, component_type, normalized);
2136 out[1] = cgltf_component_read_float(element + 1, component_type, normalized);
2137 out[2] = cgltf_component_read_float(element + 4, component_type, normalized);
2138 out[3] = cgltf_component_read_float(element + 5, component_type, normalized);
2144 out[0] = cgltf_component_read_float(element, component_type, normalized);
2145 out[1] = cgltf_component_read_float(element + 1, component_type, normalized);
2146 out[2] = cgltf_component_read_float(element + 2, component_type, normalized);
2147 out[3] = cgltf_component_read_float(element + 4, component_type, normalized);
2148 out[4] = cgltf_component_read_float(element + 5, component_type, normalized);
2149 out[5] = cgltf_component_read_float(element + 6, component_type, normalized);
2150 out[6] = cgltf_component_read_float(element + 8, component_type, normalized);
2151 out[7] = cgltf_component_read_float(element + 9, component_type, normalized);
2152 out[8] = cgltf_component_read_float(element + 10, component_type, normalized);
2158 out[0] = cgltf_component_read_float(element, component_type, normalized);
2159 out[1] = cgltf_component_read_float(element + 2, component_type, normalized);
2160 out[2] = cgltf_component_read_float(element + 4, component_type, normalized);
2161 out[3] = cgltf_component_read_float(element + 8, component_type, normalized);
2162 out[4] = cgltf_component_read_float(element + 10, component_type, normalized);
2163 out[5] = cgltf_component_read_float(element + 12, component_type, normalized);
2164 out[6] = cgltf_component_read_float(element + 16, component_type, normalized);
2165 out[7] = cgltf_component_read_float(element + 18, component_type, normalized);
2166 out[8] = cgltf_component_read_float(element + 20, component_type, normalized);
2170 for (
cgltf_size i = 0; i < num_components; ++i)
2172 out[i] = cgltf_component_read_float(element + component_size * i, component_type, normalized);
2198 memset(out, 0, element_size *
sizeof(
cgltf_float));
2202 if (element ==
NULL)
2206 element += accessor->
offset + accessor->
stride * index;
2216 return available_floats;
2219 float_count = available_floats < float_count ? available_floats : float_count;
2220 cgltf_size element_count = float_count / floats_per_element;
2226 for (
cgltf_size index = 0; index < element_count; index++, dest += floats_per_element)
2242 if (index_data ==
NULL || reader_head ==
NULL)
2251 for (
cgltf_size reader_index = 0; reader_index < sparse->
count; reader_index++, index_data += index_stride)
2254 float* writer_head = out + writer_index * floats_per_element;
2261 reader_head += dense.
stride;
2265 return element_count * floats_per_element;
2270 switch (component_type)
2273 return *((
const int8_t*) in);
2276 return *((
const uint8_t*) in);
2279 return *((
const int16_t*) in);
2296 if (element_size < num_components)
2307 cgltf_size component_size = cgltf_component_size(component_type);
2309 for (
cgltf_size i = 0; i < num_components; ++i)
2311 out[i] = cgltf_component_read_uint(element + component_size * i, component_type);
2324 memset(out, 0, element_size *
sizeof(
cgltf_uint ));
2328 if (element ==
NULL)
2332 element += accessor->
offset + accessor->
stride * index;
2333 return cgltf_element_read_uint(element, accessor->
type, accessor->
component_type, out, element_size);
2347 if (element ==
NULL)
2351 element += accessor->
offset + accessor->
stride * index;
2352 return cgltf_component_read_index(element, accessor->
component_type);
2355#define CGLTF_ERROR_JSON -1
2356#define CGLTF_ERROR_NOMEM -2
2357#define CGLTF_ERROR_LEGACY -3
2359#define CGLTF_CHECK_TOKTYPE(tok_, type_) if ((tok_).type != (type_)) { return CGLTF_ERROR_JSON; }
2360#define CGLTF_CHECK_TOKTYPE_RETTYPE(tok_, type_, ret_) if ((tok_).type != (type_)) { return (ret_)CGLTF_ERROR_JSON; }
2361#define CGLTF_CHECK_KEY(tok_) if ((tok_).type != JSMN_STRING || (tok_).size == 0) { return CGLTF_ERROR_JSON; }
2363#define CGLTF_PTRINDEX(type, idx) (type*)((cgltf_size)idx + 1)
2364#define CGLTF_PTRFIXUP(var, data, size) if (var) { if ((cgltf_size)var > size) { return CGLTF_ERROR_JSON; } var = &data[(cgltf_size)var-1]; }
2365#define CGLTF_PTRFIXUP_REQ(var, data, size) if (!var || (cgltf_size)var > size) { return CGLTF_ERROR_JSON; } var = &data[(cgltf_size)var-1];
2367static int cgltf_json_strcmp(jsmntok_t
const* tok,
const uint8_t* json_chunk,
const char* str)
2369 CGLTF_CHECK_TOKTYPE(*tok, JSMN_STRING);
2370 size_t const str_len = strlen(str);
2371 size_t const name_length = tok->end - tok->start;
2372 return (str_len == name_length) ? strncmp((
const char*)json_chunk + tok->start, str, str_len) : 128;
2375static int cgltf_json_to_int(jsmntok_t
const* tok,
const uint8_t* json_chunk)
2377 CGLTF_CHECK_TOKTYPE(*tok, JSMN_PRIMITIVE);
2379 int size = (
cgltf_size)(tok->end - tok->start) <
sizeof(tmp) ? tok->end - tok->start : (
int)(
sizeof(tmp) - 1);
2380 strncpy(tmp, (
const char*)json_chunk + tok->start, size);
2382 return CGLTF_ATOI(tmp);
2385static cgltf_size cgltf_json_to_size(jsmntok_t
const* tok,
const uint8_t* json_chunk)
2387 CGLTF_CHECK_TOKTYPE_RETTYPE(*tok, JSMN_PRIMITIVE,
cgltf_size);
2389 int size = (
cgltf_size)(tok->end - tok->start) <
sizeof(tmp) ? tok->end - tok->start : (
int)(
sizeof(tmp) - 1);
2390 strncpy(tmp, (
const char*)json_chunk + tok->start, size);
2395static cgltf_float cgltf_json_to_float(jsmntok_t
const* tok,
const uint8_t* json_chunk)
2397 CGLTF_CHECK_TOKTYPE(*tok, JSMN_PRIMITIVE);
2399 int size = (
cgltf_size)(tok->end - tok->start) <
sizeof(tmp) ? tok->end - tok->start : (
int)(
sizeof(tmp) - 1);
2400 strncpy(tmp, (
const char*)json_chunk + tok->start, size);
2405static cgltf_bool cgltf_json_to_bool(jsmntok_t
const* tok,
const uint8_t* json_chunk)
2407 int size = tok->end - tok->start;
2408 return size == 4 && memcmp(json_chunk + tok->start,
"true", 4) == 0;
2411static int cgltf_skip_json(jsmntok_t
const* tokens,
int i)
2417 switch (tokens[i].type)
2420 end += tokens[i].size * 2;
2424 end += tokens[i].size;
2427 case JSMN_PRIMITIVE:
2441static void cgltf_fill_float_array(
float* out_array,
int size,
float value)
2443 for (
int j = 0; j < size; ++j)
2445 out_array[j] = value;
2449static int cgltf_parse_json_float_array(jsmntok_t
const* tokens,
int i,
const uint8_t* json_chunk,
float* out_array,
int size)
2451 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_ARRAY);
2452 if (tokens[i].size != size)
2454 return CGLTF_ERROR_JSON;
2457 for (
int j = 0; j < size; ++j)
2459 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_PRIMITIVE);
2460 out_array[j] = cgltf_json_to_float(tokens + i, json_chunk);
2466static int cgltf_parse_json_string(
cgltf_options* options, jsmntok_t
const* tokens,
int i,
const uint8_t* json_chunk,
char** out_string)
2468 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_STRING);
2471 return CGLTF_ERROR_JSON;
2473 int size = tokens[i].end - tokens[i].start;
2477 return CGLTF_ERROR_NOMEM;
2479 strncpy(result, (
const char*)json_chunk + tokens[i].start, size);
2481 *out_string = result;
2485static int cgltf_parse_json_array(
cgltf_options* options, jsmntok_t
const* tokens,
int i,
const uint8_t* json_chunk,
size_t element_size,
void** out_array,
cgltf_size* out_size)
2488 if (tokens[i].type != JSMN_ARRAY)
2490 return tokens[i].type == JSMN_OBJECT ? CGLTF_ERROR_LEGACY : CGLTF_ERROR_JSON;
2494 return CGLTF_ERROR_JSON;
2496 int size = tokens[i].size;
2497 void* result = cgltf_calloc(options, element_size, size);
2500 return CGLTF_ERROR_NOMEM;
2502 *out_array = result;
2507static int cgltf_parse_json_string_array(
cgltf_options* options, jsmntok_t
const* tokens,
int i,
const uint8_t* json_chunk,
char*** out_array,
cgltf_size* out_size)
2509 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_ARRAY);
2510 i = cgltf_parse_json_array(options, tokens, i, json_chunk,
sizeof(
char*), (
void**)out_array, out_size);
2518 i = cgltf_parse_json_string(options, tokens, i, json_chunk, j + (*out_array));
2527static void cgltf_parse_attribute_type(
const char* name,
cgltf_attribute_type* out_type,
int* out_index)
2529 const char* us = strchr(name,
'_');
2530 size_t len = us ? (size_t)(us - name) : strlen(name);
2532 if (len == 8 && strncmp(name,
"POSITION", 8) == 0)
2536 else if (len == 6 && strncmp(name,
"NORMAL", 6) == 0)
2540 else if (len == 7 && strncmp(name,
"TANGENT", 7) == 0)
2544 else if (len == 8 && strncmp(name,
"TEXCOORD", 8) == 0)
2548 else if (len == 5 && strncmp(name,
"COLOR", 5) == 0)
2552 else if (len == 6 && strncmp(name,
"JOINTS", 6) == 0)
2556 else if (len == 7 && strncmp(name,
"WEIGHTS", 7) == 0)
2567 *out_index = CGLTF_ATOI(us + 1);
2573 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2575 if (*out_attributes)
2577 return CGLTF_ERROR_JSON;
2580 *out_attributes_count = tokens[i].size;
2584 if (!*out_attributes)
2586 return CGLTF_ERROR_NOMEM;
2589 for (
cgltf_size j = 0; j < *out_attributes_count; ++j)
2591 CGLTF_CHECK_KEY(tokens[i]);
2593 i = cgltf_parse_json_string(options, tokens, i, json_chunk, &(*out_attributes)[j].name);
2596 return CGLTF_ERROR_JSON;
2599 cgltf_parse_attribute_type((*out_attributes)[j].name, &(*out_attributes)[j].type, &(*out_attributes)[j].index);
2601 (*out_attributes)[j].data = CGLTF_PTRINDEX(
cgltf_accessor, cgltf_json_to_int(tokens + i, json_chunk));
2608static int cgltf_parse_json_extras(jsmntok_t
const* tokens,
int i,
const uint8_t* json_chunk,
cgltf_extras* out_extras)
2613 i = cgltf_skip_json(tokens, i);
2619 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_STRING);
2620 CGLTF_CHECK_TOKTYPE(tokens[i+1], JSMN_OBJECT);
2621 if (out_extension->
name)
2623 return CGLTF_ERROR_JSON;
2626 cgltf_size name_length = tokens[i].end - tokens[i].start;
2628 if (!out_extension->
name)
2630 return CGLTF_ERROR_NOMEM;
2632 strncpy(out_extension->
name, (
const char*)json_chunk + tokens[i].start, name_length);
2633 out_extension->
name[name_length] = 0;
2636 size_t start = tokens[i].start;
2637 size_t size = tokens[i].end - start;
2639 if (!out_extension->
data)
2641 return CGLTF_ERROR_NOMEM;
2643 strncpy(out_extension->
data, (
const char*)json_chunk + start, size);
2644 out_extension->
data[size] =
'\0';
2646 i = cgltf_skip_json(tokens, i);
2655 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2658 return CGLTF_ERROR_JSON;
2661 int extensions_size = tokens[i].size;
2662 *out_extensions_count = 0;
2665 if (!*out_extensions)
2667 return CGLTF_ERROR_NOMEM;
2672 for (
int j = 0; j < extensions_size; ++j)
2674 CGLTF_CHECK_KEY(tokens[i]);
2676 cgltf_size extension_index = (*out_extensions_count)++;
2678 i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, extension);
2690 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2692 int size = tokens[i].size;
2695 for (
int j = 0; j < size; ++j)
2697 CGLTF_CHECK_KEY(tokens[i]);
2699 if (cgltf_json_strcmp(tokens + i, json_chunk,
"attributes") == 0)
2701 i = cgltf_parse_json_attribute_list(options, tokens, i + 1, json_chunk, &out_draco_mesh_compression->
attributes, &out_draco_mesh_compression->
attributes_count);
2703 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"bufferView") == 0)
2722 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_ARRAY);
2724 int size = tokens[i].size;
2727 for (
int j = 0; j < size; ++j)
2729 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2731 int obj_size = tokens[i].size;
2735 int variants_tok = -1;
2738 for (
int k = 0; k < obj_size; ++k)
2740 CGLTF_CHECK_KEY(tokens[i]);
2742 if (cgltf_json_strcmp(tokens + i, json_chunk,
"material") == 0)
2745 material = cgltf_json_to_int(tokens + i, json_chunk);
2748 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"variants") == 0)
2751 CGLTF_CHECK_TOKTYPE(tokens[variants_tok], JSMN_ARRAY);
2753 i = cgltf_skip_json(tokens, i+1);
2755 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
2757 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &extras);
2761 i = cgltf_skip_json(tokens, i+1);
2770 if (material < 0 || variants_tok < 0)
2772 return CGLTF_ERROR_JSON;
2777 for (
int k = 0; k < tokens[variants_tok].size; ++k)
2779 int variant = cgltf_json_to_int(&tokens[variants_tok + 1 + k], json_chunk);
2784 out_mappings[*offset].
variant = variant;
2785 out_mappings[*offset].
extras = extras;
2792 (*offset) += tokens[variants_tok].size;
2801 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2803 int size = tokens[i].size;
2806 for (
int j = 0; j < size; ++j)
2808 CGLTF_CHECK_KEY(tokens[i]);
2810 if (cgltf_json_strcmp(tokens + i, json_chunk,
"mappings") == 0)
2814 return CGLTF_ERROR_JSON;
2818 int k = cgltf_parse_json_material_mapping_data(options, tokens, i + 1, json_chunk,
NULL, &mappings_offset);
2827 mappings_offset = 0;
2828 i = cgltf_parse_json_material_mapping_data(options, tokens, i + 1, json_chunk, out_prim->
mappings, &mappings_offset);
2832 i = cgltf_skip_json(tokens, i+1);
2846 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2850 int size = tokens[i].size;
2853 for (
int j = 0; j < size; ++j)
2855 CGLTF_CHECK_KEY(tokens[i]);
2857 if (cgltf_json_strcmp(tokens+i, json_chunk,
"mode") == 0)
2862 cgltf_json_to_int(tokens+i, json_chunk);
2865 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"indices") == 0)
2871 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"material") == 0)
2877 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"attributes") == 0)
2881 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"targets") == 0)
2898 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
2900 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_prim->
extras);
2902 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
2906 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2909 return CGLTF_ERROR_JSON;
2912 int extensions_size = tokens[i].size;
2918 return CGLTF_ERROR_NOMEM;
2922 for (
int k = 0; k < extensions_size; ++k)
2924 CGLTF_CHECK_KEY(tokens[i]);
2926 if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_draco_mesh_compression") == 0)
2929 i = cgltf_parse_json_draco_mesh_compression(options, tokens, i + 1, json_chunk, &out_prim->
draco_mesh_compression);
2931 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_variants") == 0)
2933 i = cgltf_parse_json_material_mappings(options, tokens, i + 1, json_chunk, out_prim);
2937 i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_prim->
extensions[out_prim->
extensions_count++]));
2948 i = cgltf_skip_json(tokens, i+1);
2962 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
2964 int size = tokens[i].size;
2967 for (
int j = 0; j < size; ++j)
2969 CGLTF_CHECK_KEY(tokens[i]);
2971 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
2973 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_mesh->
name);
2975 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"primitives") == 0)
2985 i = cgltf_parse_json_primitive(options, tokens, i, json_chunk, &out_mesh->
primitives[prim_index]);
2992 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"weights") == 0)
3000 i = cgltf_parse_json_float_array(tokens, i - 1, json_chunk, out_mesh->
weights, (
int)out_mesh->
weights_count);
3002 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3009 if (tokens[i].type == JSMN_OBJECT)
3011 int extras_size = tokens[i].size;
3014 for (
int k = 0; k < extras_size; ++k)
3016 CGLTF_CHECK_KEY(tokens[i]);
3018 if (cgltf_json_strcmp(tokens+i, json_chunk,
"targetNames") == 0 && tokens[i+1].type == JSMN_ARRAY)
3024 i = cgltf_skip_json(tokens, i+1);
3035 i = cgltf_skip_json(tokens, i);
3038 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3040 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_mesh->
extensions_count, &out_mesh->
extensions);
3044 i = cgltf_skip_json(tokens, i+1);
3066 i = cgltf_parse_json_mesh(options, tokens, i, json_chunk, &out_data->
meshes[j]);
3077 int type = cgltf_json_to_int(tok, json_chunk);
3100 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3102 int size = tokens[i].size;
3105 for (
int j = 0; j < size; ++j)
3107 CGLTF_CHECK_KEY(tokens[i]);
3109 if (cgltf_json_strcmp(tokens+i, json_chunk,
"count") == 0)
3112 out_sparse->
count = cgltf_json_to_int(tokens + i, json_chunk);
3115 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"indices") == 0)
3118 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3120 int indices_size = tokens[i].size;
3123 for (
int k = 0; k < indices_size; ++k)
3125 CGLTF_CHECK_KEY(tokens[i]);
3127 if (cgltf_json_strcmp(tokens+i, json_chunk,
"bufferView") == 0)
3133 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteOffset") == 0)
3139 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"componentType") == 0)
3145 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3147 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_sparse->
indices_extras);
3149 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3155 i = cgltf_skip_json(tokens, i+1);
3164 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"values") == 0)
3167 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3169 int values_size = tokens[i].size;
3172 for (
int k = 0; k < values_size; ++k)
3174 CGLTF_CHECK_KEY(tokens[i]);
3176 if (cgltf_json_strcmp(tokens+i, json_chunk,
"bufferView") == 0)
3182 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteOffset") == 0)
3188 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3190 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_sparse->
values_extras);
3192 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3198 i = cgltf_skip_json(tokens, i+1);
3207 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3209 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_sparse->
extras);
3211 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3213 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_sparse->
extensions_count, &out_sparse->
extensions);
3217 i = cgltf_skip_json(tokens, i+1);
3231 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3233 int size = tokens[i].size;
3236 for (
int j = 0; j < size; ++j)
3238 CGLTF_CHECK_KEY(tokens[i]);
3240 if (cgltf_json_strcmp(tokens + i, json_chunk,
"name") == 0)
3242 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_accessor->
name);
3244 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"bufferView") == 0)
3250 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteOffset") == 0)
3254 cgltf_json_to_size(tokens+i, json_chunk);
3257 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"componentType") == 0)
3260 out_accessor->
component_type = cgltf_json_to_component_type(tokens + i, json_chunk);
3263 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"normalized") == 0)
3266 out_accessor->
normalized = cgltf_json_to_bool(tokens+i, json_chunk);
3269 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"count") == 0)
3272 out_accessor->
count =
3273 cgltf_json_to_int(tokens+i, json_chunk);
3276 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"type") == 0)
3279 if (cgltf_json_strcmp(tokens+i, json_chunk,
"SCALAR") == 0)
3283 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"VEC2") == 0)
3287 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"VEC3") == 0)
3291 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"VEC4") == 0)
3295 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"MAT2") == 0)
3299 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"MAT3") == 0)
3303 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"MAT4") == 0)
3309 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"min") == 0)
3314 int min_size = tokens[i].size > 16 ? 16 : tokens[i].size;
3315 i = cgltf_parse_json_float_array(tokens, i, json_chunk, out_accessor->
min, min_size);
3317 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"max") == 0)
3322 int max_size = tokens[i].size > 16 ? 16 : tokens[i].size;
3323 i = cgltf_parse_json_float_array(tokens, i, json_chunk, out_accessor->
max, max_size);
3325 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"sparse") == 0)
3328 i = cgltf_parse_json_accessor_sparse(options, tokens, i + 1, json_chunk, &out_accessor->
sparse);
3330 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3332 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_accessor->
extras);
3334 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3336 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_accessor->
extensions_count, &out_accessor->
extensions);
3340 i = cgltf_skip_json(tokens, i+1);
3352static int cgltf_parse_json_texture_transform(jsmntok_t
const* tokens,
int i,
const uint8_t* json_chunk,
cgltf_texture_transform* out_texture_transform)
3354 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3356 int size = tokens[i].size;
3359 for (
int j = 0; j < size; ++j)
3361 CGLTF_CHECK_KEY(tokens[i]);
3363 if (cgltf_json_strcmp(tokens + i, json_chunk,
"offset") == 0)
3365 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_texture_transform->
offset, 2);
3367 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"rotation") == 0)
3370 out_texture_transform->
rotation = cgltf_json_to_float(tokens + i, json_chunk);
3373 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"scale") == 0)
3375 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_texture_transform->
scale, 2);
3377 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"texCoord") == 0)
3381 out_texture_transform->
texcoord = cgltf_json_to_int(tokens + i, json_chunk);
3386 i = cgltf_skip_json(tokens, i + 1);
3400 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3402 out_texture_view->
scale = 1.0f;
3403 cgltf_fill_float_array(out_texture_view->
transform.
scale, 2, 1.0f);
3405 int size = tokens[i].size;
3408 for (
int j = 0; j < size; ++j)
3410 CGLTF_CHECK_KEY(tokens[i]);
3412 if (cgltf_json_strcmp(tokens + i, json_chunk,
"index") == 0)
3415 out_texture_view->
texture = CGLTF_PTRINDEX(
cgltf_texture, cgltf_json_to_int(tokens + i, json_chunk));
3418 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"texCoord") == 0)
3421 out_texture_view->
texcoord = cgltf_json_to_int(tokens + i, json_chunk);
3424 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"scale") == 0)
3427 out_texture_view->
scale = cgltf_json_to_float(tokens + i, json_chunk);
3430 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"strength") == 0)
3433 out_texture_view->
scale = cgltf_json_to_float(tokens + i, json_chunk);
3436 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3438 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_texture_view->
extras);
3440 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3444 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3447 return CGLTF_ERROR_JSON;
3450 int extensions_size = tokens[i].size;
3456 return CGLTF_ERROR_NOMEM;
3461 for (
int k = 0; k < extensions_size; ++k)
3463 CGLTF_CHECK_KEY(tokens[i]);
3465 if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_texture_transform") == 0)
3468 i = cgltf_parse_json_texture_transform(tokens, i + 1, json_chunk, &out_texture_view->
transform);
3472 i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_texture_view->
extensions[out_texture_view->
extensions_count++]));
3483 i = cgltf_skip_json(tokens, i + 1);
3497 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3499 int size = tokens[i].size;
3502 for (
int j = 0; j < size; ++j)
3504 CGLTF_CHECK_KEY(tokens[i]);
3506 if (cgltf_json_strcmp(tokens+i, json_chunk,
"metallicFactor") == 0)
3510 cgltf_json_to_float(tokens + i, json_chunk);
3513 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"roughnessFactor") == 0)
3517 cgltf_json_to_float(tokens+i, json_chunk);
3520 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"baseColorFactor") == 0)
3522 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_pbr->
base_color_factor, 4);
3524 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"baseColorTexture") == 0)
3526 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk,
3529 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"metallicRoughnessTexture") == 0)
3531 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk,
3534 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3536 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_pbr->
extras);
3540 i = cgltf_skip_json(tokens, i+1);
3554 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3555 int size = tokens[i].size;
3558 for (
int j = 0; j < size; ++j)
3560 CGLTF_CHECK_KEY(tokens[i]);
3562 if (cgltf_json_strcmp(tokens+i, json_chunk,
"diffuseFactor") == 0)
3564 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_pbr->
diffuse_factor, 4);
3566 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"specularFactor") == 0)
3568 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_pbr->
specular_factor, 3);
3570 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"glossinessFactor") == 0)
3576 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"diffuseTexture") == 0)
3578 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_pbr->
diffuse_texture);
3580 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"specularGlossinessTexture") == 0)
3586 i = cgltf_skip_json(tokens, i+1);
3600 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3601 int size = tokens[i].size;
3604 for (
int j = 0; j < size; ++j)
3606 CGLTF_CHECK_KEY(tokens[i]);
3608 if (cgltf_json_strcmp(tokens+i, json_chunk,
"clearcoatFactor") == 0)
3611 out_clearcoat->
clearcoat_factor = cgltf_json_to_float(tokens + i, json_chunk);
3614 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"clearcoatRoughnessFactor") == 0)
3620 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"clearcoatTexture") == 0)
3622 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_clearcoat->
clearcoat_texture);
3624 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"clearcoatRoughnessTexture") == 0)
3628 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"clearcoatNormalTexture") == 0)
3634 i = cgltf_skip_json(tokens, i+1);
3646static int cgltf_parse_json_ior(jsmntok_t
const* tokens,
int i,
const uint8_t* json_chunk,
cgltf_ior* out_ior)
3648 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3649 int size = tokens[i].size;
3653 out_ior->
ior = 1.5f;
3655 for (
int j = 0; j < size; ++j)
3657 CGLTF_CHECK_KEY(tokens[i]);
3659 if (cgltf_json_strcmp(tokens+i, json_chunk,
"ior") == 0)
3662 out_ior->
ior = cgltf_json_to_float(tokens + i, json_chunk);
3667 i = cgltf_skip_json(tokens, i+1);
3681 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3682 int size = tokens[i].size;
3689 for (
int j = 0; j < size; ++j)
3691 CGLTF_CHECK_KEY(tokens[i]);
3693 if (cgltf_json_strcmp(tokens+i, json_chunk,
"specularFactor") == 0)
3696 out_specular->
specular_factor = cgltf_json_to_float(tokens + i, json_chunk);
3699 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"specularColorFactor") == 0)
3701 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_specular->
specular_color_factor, 3);
3703 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"specularTexture") == 0)
3705 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_specular->
specular_texture);
3707 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"specularColorTexture") == 0)
3709 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_specular->
specular_color_texture);
3713 i = cgltf_skip_json(tokens, i+1);
3727 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3728 int size = tokens[i].size;
3731 for (
int j = 0; j < size; ++j)
3733 CGLTF_CHECK_KEY(tokens[i]);
3735 if (cgltf_json_strcmp(tokens+i, json_chunk,
"transmissionFactor") == 0)
3741 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"transmissionTexture") == 0)
3743 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_transmission->
transmission_texture);
3747 i = cgltf_skip_json(tokens, i+1);
3761 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3762 int size = tokens[i].size;
3765 for (
int j = 0; j < size; ++j)
3767 CGLTF_CHECK_KEY(tokens[i]);
3769 if (cgltf_json_strcmp(tokens + i, json_chunk,
"thicknessFactor") == 0)
3772 out_volume->
thickness_factor = cgltf_json_to_float(tokens + i, json_chunk);
3775 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"thicknessTexture") == 0)
3777 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_volume->
thickness_texture);
3779 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"attenuationColor") == 0)
3781 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_volume->
attenuation_color, 3);
3783 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"attenuationDistance") == 0)
3791 i = cgltf_skip_json(tokens, i + 1);
3805 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3806 int size = tokens[i].size;
3809 for (
int j = 0; j < size; ++j)
3811 CGLTF_CHECK_KEY(tokens[i]);
3813 if (cgltf_json_strcmp(tokens+i, json_chunk,
"sheenColorFactor") == 0)
3815 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_sheen->
sheen_color_factor, 3);
3817 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"sheenColorTexture") == 0)
3819 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_sheen->
sheen_color_texture);
3821 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"sheenRoughnessFactor") == 0)
3827 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"sheenRoughnessTexture") == 0)
3833 i = cgltf_skip_json(tokens, i+1);
3847 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3849 int size = tokens[i].size;
3852 for (
int j = 0; j < size; ++j)
3854 CGLTF_CHECK_KEY(tokens[i]);
3856 if (cgltf_json_strcmp(tokens + i, json_chunk,
"uri") == 0)
3858 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_image->
uri);
3860 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"bufferView") == 0)
3866 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"mimeType") == 0)
3868 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_image->
mime_type);
3870 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"name") == 0)
3872 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_image->
name);
3874 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3876 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_image->
extras);
3878 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3880 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_image->
extensions_count, &out_image->
extensions);
3884 i = cgltf_skip_json(tokens, i + 1);
3899 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3901 out_sampler->
wrap_s = 10497;
3902 out_sampler->
wrap_t = 10497;
3904 int size = tokens[i].size;
3907 for (
int j = 0; j < size; ++j)
3909 CGLTF_CHECK_KEY(tokens[i]);
3911 if (cgltf_json_strcmp(tokens + i, json_chunk,
"name") == 0)
3913 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_sampler->
name);
3915 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"magFilter") == 0)
3919 = cgltf_json_to_int(tokens + i, json_chunk);
3922 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"minFilter") == 0)
3926 = cgltf_json_to_int(tokens + i, json_chunk);
3929 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"wrapS") == 0)
3933 = cgltf_json_to_int(tokens + i, json_chunk);
3936 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"wrapT") == 0)
3940 = cgltf_json_to_int(tokens + i, json_chunk);
3943 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3945 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_sampler->
extras);
3947 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
3949 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_sampler->
extensions_count, &out_sampler->
extensions);
3953 i = cgltf_skip_json(tokens, i + 1);
3967 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
3969 int size = tokens[i].size;
3972 for (
int j = 0; j < size; ++j)
3974 CGLTF_CHECK_KEY(tokens[i]);
3976 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
3978 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_texture->
name);
3980 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"sampler") == 0)
3983 out_texture->
sampler = CGLTF_PTRINDEX(
cgltf_sampler, cgltf_json_to_int(tokens + i, json_chunk));
3986 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"source") == 0)
3989 out_texture->
image = CGLTF_PTRINDEX(
cgltf_image, cgltf_json_to_int(tokens + i, json_chunk));
3992 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
3994 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_texture->
extras);
3996 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
4000 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4003 return CGLTF_ERROR_JSON;
4006 int extensions_size = tokens[i].size;
4013 return CGLTF_ERROR_NOMEM;
4016 for (
int k = 0; k < extensions_size; ++k)
4018 CGLTF_CHECK_KEY(tokens[i]);
4020 if (cgltf_json_strcmp(tokens + i, json_chunk,
"KHR_texture_basisu") == 0)
4024 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4025 int num_properties = tokens[i].size;
4028 for (
int t = 0; t < num_properties; ++t)
4030 CGLTF_CHECK_KEY(tokens[i]);
4032 if (cgltf_json_strcmp(tokens + i, json_chunk,
"source") == 0)
4040 i = cgltf_skip_json(tokens, i + 1);
4046 i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_texture->
extensions[out_texture->
extensions_count++]));
4057 i = cgltf_skip_json(tokens, i + 1);
4071 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4086 int size = tokens[i].size;
4089 for (
int j = 0; j < size; ++j)
4091 CGLTF_CHECK_KEY(tokens[i]);
4093 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
4095 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_material->
name);
4097 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"pbrMetallicRoughness") == 0)
4100 i = cgltf_parse_json_pbr_metallic_roughness(options, tokens, i + 1, json_chunk, &out_material->
pbr_metallic_roughness);
4102 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"emissiveFactor") == 0)
4104 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_material->
emissive_factor, 3);
4106 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"normalTexture") == 0)
4108 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk,
4111 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"occlusionTexture") == 0)
4113 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk,
4116 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"emissiveTexture") == 0)
4118 i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk,
4121 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"alphaMode") == 0)
4124 if (cgltf_json_strcmp(tokens + i, json_chunk,
"OPAQUE") == 0)
4128 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"MASK") == 0)
4132 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"BLEND") == 0)
4138 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"alphaCutoff") == 0)
4141 out_material->
alpha_cutoff = cgltf_json_to_float(tokens + i, json_chunk);
4144 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"doubleSided") == 0)
4148 cgltf_json_to_bool(tokens + i, json_chunk);
4151 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4153 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_material->
extras);
4155 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
4159 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4162 return CGLTF_ERROR_JSON;
4165 int extensions_size = tokens[i].size;
4172 return CGLTF_ERROR_NOMEM;
4175 for (
int k = 0; k < extensions_size; ++k)
4177 CGLTF_CHECK_KEY(tokens[i]);
4179 if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_pbrSpecularGlossiness") == 0)
4182 i = cgltf_parse_json_pbr_specular_glossiness(options, tokens, i + 1, json_chunk, &out_material->
pbr_specular_glossiness);
4184 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_unlit") == 0)
4186 out_material->
unlit = 1;
4187 i = cgltf_skip_json(tokens, i+1);
4189 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_clearcoat") == 0)
4192 i = cgltf_parse_json_clearcoat(options, tokens, i + 1, json_chunk, &out_material->
clearcoat);
4194 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_ior") == 0)
4197 i = cgltf_parse_json_ior(tokens, i + 1, json_chunk, &out_material->
ior);
4199 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_specular") == 0)
4202 i = cgltf_parse_json_specular(options, tokens, i + 1, json_chunk, &out_material->
specular);
4204 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_transmission") == 0)
4207 i = cgltf_parse_json_transmission(options, tokens, i + 1, json_chunk, &out_material->
transmission);
4209 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"KHR_materials_volume") == 0)
4212 i = cgltf_parse_json_volume(options, tokens, i + 1, json_chunk, &out_material->
volume);
4214 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_sheen") == 0)
4217 i = cgltf_parse_json_sheen(options, tokens, i + 1, json_chunk, &out_material->
sheen);
4221 i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_material->
extensions[out_material->
extensions_count++]));
4232 i = cgltf_skip_json(tokens, i+1);
4254 i = cgltf_parse_json_accessor(options, tokens, i, json_chunk, &out_data->
accessors[j]);
4273 i = cgltf_parse_json_material(options, tokens, i, json_chunk, &out_data->
materials[j]);
4292 i = cgltf_parse_json_image(options, tokens, i, json_chunk, &out_data->
images[j]);
4311 i = cgltf_parse_json_texture(options, tokens, i, json_chunk, &out_data->
textures[j]);
4330 i = cgltf_parse_json_sampler(options, tokens, i, json_chunk, &out_data->
samplers[j]);
4342 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4344 int size = tokens[i].size;
4347 for (
int j = 0; j < size; ++j)
4349 CGLTF_CHECK_KEY(tokens[i]);
4351 if (cgltf_json_strcmp(tokens+i, json_chunk,
"buffer") == 0)
4354 out_meshopt_compression->
buffer = CGLTF_PTRINDEX(
cgltf_buffer, cgltf_json_to_int(tokens + i, json_chunk));
4357 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteOffset") == 0)
4360 out_meshopt_compression->
offset = cgltf_json_to_size(tokens+i, json_chunk);
4363 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteLength") == 0)
4366 out_meshopt_compression->
size = cgltf_json_to_size(tokens+i, json_chunk);
4369 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteStride") == 0)
4372 out_meshopt_compression->
stride = cgltf_json_to_size(tokens+i, json_chunk);
4375 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"count") == 0)
4378 out_meshopt_compression->
count = cgltf_json_to_int(tokens+i, json_chunk);
4381 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"mode") == 0)
4384 if (cgltf_json_strcmp(tokens+i, json_chunk,
"ATTRIBUTES") == 0)
4388 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"TRIANGLES") == 0)
4392 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"INDICES") == 0)
4398 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"filter") == 0)
4401 if (cgltf_json_strcmp(tokens+i, json_chunk,
"NONE") == 0)
4405 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"OCTAHEDRAL") == 0)
4409 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"QUATERNION") == 0)
4413 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"EXPONENTIAL") == 0)
4421 i = cgltf_skip_json(tokens, i+1);
4435 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4437 int size = tokens[i].size;
4440 for (
int j = 0; j < size; ++j)
4442 CGLTF_CHECK_KEY(tokens[i]);
4444 if (cgltf_json_strcmp(tokens + i, json_chunk,
"name") == 0)
4446 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_buffer_view->
name);
4448 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"buffer") == 0)
4451 out_buffer_view->
buffer = CGLTF_PTRINDEX(
cgltf_buffer, cgltf_json_to_int(tokens + i, json_chunk));
4454 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteOffset") == 0)
4457 out_buffer_view->
offset =
4458 cgltf_json_to_size(tokens+i, json_chunk);
4461 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteLength") == 0)
4464 out_buffer_view->
size =
4465 cgltf_json_to_size(tokens+i, json_chunk);
4468 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteStride") == 0)
4471 out_buffer_view->
stride =
4472 cgltf_json_to_size(tokens+i, json_chunk);
4475 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"target") == 0)
4478 int type = cgltf_json_to_int(tokens+i, json_chunk);
4494 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4496 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_buffer_view->
extras);
4498 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
4502 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4505 return CGLTF_ERROR_JSON;
4508 int extensions_size = tokens[i].size;
4514 return CGLTF_ERROR_NOMEM;
4518 for (
int k = 0; k < extensions_size; ++k)
4520 CGLTF_CHECK_KEY(tokens[i]);
4522 if (cgltf_json_strcmp(tokens+i, json_chunk,
"EXT_meshopt_compression") == 0)
4525 i = cgltf_parse_json_meshopt_compression(options, tokens, i + 1, json_chunk, &out_buffer_view->
meshopt_compression);
4529 i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_buffer_view->
extensions[out_buffer_view->
extensions_count++]));
4540 i = cgltf_skip_json(tokens, i+1);
4562 i = cgltf_parse_json_buffer_view(options, tokens, i, json_chunk, &out_data->
buffer_views[j]);
4573 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4575 int size = tokens[i].size;
4578 for (
int j = 0; j < size; ++j)
4580 CGLTF_CHECK_KEY(tokens[i]);
4582 if (cgltf_json_strcmp(tokens + i, json_chunk,
"name") == 0)
4584 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_buffer->
name);
4586 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"byteLength") == 0)
4590 cgltf_json_to_size(tokens+i, json_chunk);
4593 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"uri") == 0)
4595 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_buffer->
uri);
4597 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4599 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_buffer->
extras);
4601 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
4603 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_buffer->
extensions_count, &out_buffer->
extensions);
4607 i = cgltf_skip_json(tokens, i+1);
4629 i = cgltf_parse_json_buffer(options, tokens, i, json_chunk, &out_data->
buffers[j]);
4640 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4642 int size = tokens[i].size;
4645 for (
int j = 0; j < size; ++j)
4647 CGLTF_CHECK_KEY(tokens[i]);
4649 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
4651 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_skin->
name);
4653 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"joints") == 0)
4655 i = cgltf_parse_json_array(options, tokens, i + 1, json_chunk,
sizeof(
cgltf_node*), (
void**)&out_skin->
joints, &out_skin->
joints_count);
4663 out_skin->
joints[k] = CGLTF_PTRINDEX(
cgltf_node, cgltf_json_to_int(tokens + i, json_chunk));
4667 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"skeleton") == 0)
4670 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_PRIMITIVE);
4671 out_skin->
skeleton = CGLTF_PTRINDEX(
cgltf_node, cgltf_json_to_int(tokens + i, json_chunk));
4674 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"inverseBindMatrices") == 0)
4677 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_PRIMITIVE);
4681 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4683 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_skin->
extras);
4685 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
4687 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_skin->
extensions_count, &out_skin->
extensions);
4691 i = cgltf_skip_json(tokens, i+1);
4705 i = cgltf_parse_json_array(options, tokens, i, json_chunk,
sizeof(
cgltf_skin), (
void**)&out_data->
skins, &out_data->
skins_count);
4713 i = cgltf_parse_json_skin(options, tokens, i, json_chunk, &out_data->
skins[j]);
4724 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4726 int size = tokens[i].size;
4729 for (
int j = 0; j < size; ++j)
4731 CGLTF_CHECK_KEY(tokens[i]);
4733 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
4735 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_camera->
name);
4737 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"type") == 0)
4740 if (cgltf_json_strcmp(tokens + i, json_chunk,
"perspective") == 0)
4744 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"orthographic") == 0)
4750 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"perspective") == 0)
4754 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4756 int data_size = tokens[i].size;
4761 for (
int k = 0; k < data_size; ++k)
4763 CGLTF_CHECK_KEY(tokens[i]);
4765 if (cgltf_json_strcmp(tokens+i, json_chunk,
"aspectRatio") == 0)
4772 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"yfov") == 0)
4778 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"zfar") == 0)
4785 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"znear") == 0)
4791 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4797 i = cgltf_skip_json(tokens, i+1);
4806 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"orthographic") == 0)
4810 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4812 int data_size = tokens[i].size;
4817 for (
int k = 0; k < data_size; ++k)
4819 CGLTF_CHECK_KEY(tokens[i]);
4821 if (cgltf_json_strcmp(tokens+i, json_chunk,
"xmag") == 0)
4827 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"ymag") == 0)
4833 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"zfar") == 0)
4839 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"znear") == 0)
4845 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4851 i = cgltf_skip_json(tokens, i+1);
4860 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4862 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_camera->
extras);
4864 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
4866 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_camera->
extensions_count, &out_camera->
extensions);
4870 i = cgltf_skip_json(tokens, i+1);
4892 i = cgltf_parse_json_camera(options, tokens, i, json_chunk, &out_data->
cameras[j]);
4903 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4905 out_light->
color[0] = 1.f;
4906 out_light->
color[1] = 1.f;
4907 out_light->
color[2] = 1.f;
4913 int size = tokens[i].size;
4916 for (
int j = 0; j < size; ++j)
4918 CGLTF_CHECK_KEY(tokens[i]);
4920 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
4922 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_light->
name);
4924 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"color") == 0)
4926 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_light->
color, 3);
4928 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"intensity") == 0)
4931 out_light->
intensity = cgltf_json_to_float(tokens + i, json_chunk);
4934 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"type") == 0)
4937 if (cgltf_json_strcmp(tokens + i, json_chunk,
"directional") == 0)
4941 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"point") == 0)
4945 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"spot") == 0)
4951 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"range") == 0)
4954 out_light->
range = cgltf_json_to_float(tokens + i, json_chunk);
4957 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"spot") == 0)
4961 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
4963 int data_size = tokens[i].size;
4966 for (
int k = 0; k < data_size; ++k)
4968 CGLTF_CHECK_KEY(tokens[i]);
4970 if (cgltf_json_strcmp(tokens+i, json_chunk,
"innerConeAngle") == 0)
4976 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"outerConeAngle") == 0)
4984 i = cgltf_skip_json(tokens, i+1);
4993 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
4995 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_light->
extras);
4999 i = cgltf_skip_json(tokens, i+1);
5021 i = cgltf_parse_json_light(options, tokens, i, json_chunk, &out_data->
lights[j]);
5032 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5035 out_node->
scale[0] = 1.0f;
5036 out_node->
scale[1] = 1.0f;
5037 out_node->
scale[2] = 1.0f;
5038 out_node->
matrix[0] = 1.0f;
5039 out_node->
matrix[5] = 1.0f;
5040 out_node->
matrix[10] = 1.0f;
5041 out_node->
matrix[15] = 1.0f;
5043 int size = tokens[i].size;
5046 for (
int j = 0; j < size; ++j)
5048 CGLTF_CHECK_KEY(tokens[i]);
5050 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
5052 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_node->
name);
5054 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"children") == 0)
5064 out_node->
children[k] = CGLTF_PTRINDEX(
cgltf_node, cgltf_json_to_int(tokens + i, json_chunk));
5068 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"mesh") == 0)
5071 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_PRIMITIVE);
5072 out_node->
mesh = CGLTF_PTRINDEX(
cgltf_mesh, cgltf_json_to_int(tokens + i, json_chunk));
5075 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"skin") == 0)
5078 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_PRIMITIVE);
5079 out_node->
skin = CGLTF_PTRINDEX(
cgltf_skin, cgltf_json_to_int(tokens + i, json_chunk));
5082 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"camera") == 0)
5085 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_PRIMITIVE);
5086 out_node->
camera = CGLTF_PTRINDEX(
cgltf_camera, cgltf_json_to_int(tokens + i, json_chunk));
5089 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"translation") == 0)
5092 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_node->
translation, 3);
5094 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"rotation") == 0)
5097 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_node->
rotation, 4);
5099 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"scale") == 0)
5102 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_node->
scale, 3);
5104 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"matrix") == 0)
5107 i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_node->
matrix, 16);
5109 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"weights") == 0)
5117 i = cgltf_parse_json_float_array(tokens, i - 1, json_chunk, out_node->
weights, (
int)out_node->
weights_count);
5119 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
5121 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_node->
extras);
5123 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
5127 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5130 return CGLTF_ERROR_JSON;
5133 int extensions_size = tokens[i].size;
5139 return CGLTF_ERROR_NOMEM;
5144 for (
int k = 0; k < extensions_size; ++k)
5146 CGLTF_CHECK_KEY(tokens[i]);
5148 if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_lights_punctual") == 0)
5152 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5154 int data_size = tokens[i].size;
5157 for (
int m = 0; m < data_size; ++m)
5159 CGLTF_CHECK_KEY(tokens[i]);
5161 if (cgltf_json_strcmp(tokens + i, json_chunk,
"light") == 0)
5164 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_PRIMITIVE);
5165 out_node->
light = CGLTF_PTRINDEX(
cgltf_light, cgltf_json_to_int(tokens + i, json_chunk));
5170 i = cgltf_skip_json(tokens, i + 1);
5181 i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_node->
extensions[out_node->
extensions_count++]));
5192 i = cgltf_skip_json(tokens, i+1);
5206 i = cgltf_parse_json_array(options, tokens, i, json_chunk,
sizeof(
cgltf_node), (
void**)&out_data->
nodes, &out_data->
nodes_count);
5214 i = cgltf_parse_json_node(options, tokens, i, json_chunk, &out_data->
nodes[j]);
5225 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5227 int size = tokens[i].size;
5230 for (
int j = 0; j < size; ++j)
5232 CGLTF_CHECK_KEY(tokens[i]);
5234 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
5236 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_scene->
name);
5238 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"nodes") == 0)
5240 i = cgltf_parse_json_array(options, tokens, i + 1, json_chunk,
sizeof(
cgltf_node*), (
void**)&out_scene->
nodes, &out_scene->
nodes_count);
5248 out_scene->
nodes[k] = CGLTF_PTRINDEX(
cgltf_node, cgltf_json_to_int(tokens + i, json_chunk));
5252 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
5254 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_scene->
extras);
5256 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
5258 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_scene->
extensions_count, &out_scene->
extensions);
5262 i = cgltf_skip_json(tokens, i+1);
5284 i = cgltf_parse_json_scene(options, tokens, i, json_chunk, &out_data->
scenes[j]);
5296 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5298 int size = tokens[i].size;
5301 for (
int j = 0; j < size; ++j)
5303 CGLTF_CHECK_KEY(tokens[i]);
5305 if (cgltf_json_strcmp(tokens+i, json_chunk,
"input") == 0)
5308 out_sampler->
input = CGLTF_PTRINDEX(
cgltf_accessor, cgltf_json_to_int(tokens + i, json_chunk));
5311 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"output") == 0)
5314 out_sampler->
output = CGLTF_PTRINDEX(
cgltf_accessor, cgltf_json_to_int(tokens + i, json_chunk));
5317 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"interpolation") == 0)
5320 if (cgltf_json_strcmp(tokens + i, json_chunk,
"LINEAR") == 0)
5324 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"STEP") == 0)
5328 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"CUBICSPLINE") == 0)
5334 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
5336 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_sampler->
extras);
5338 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
5340 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_sampler->
extensions_count, &out_sampler->
extensions);
5344 i = cgltf_skip_json(tokens, i+1);
5359 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5361 int size = tokens[i].size;
5364 for (
int j = 0; j < size; ++j)
5366 CGLTF_CHECK_KEY(tokens[i]);
5368 if (cgltf_json_strcmp(tokens+i, json_chunk,
"sampler") == 0)
5374 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"target") == 0)
5378 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5380 int target_size = tokens[i].size;
5383 for (
int k = 0; k < target_size; ++k)
5385 CGLTF_CHECK_KEY(tokens[i]);
5387 if (cgltf_json_strcmp(tokens+i, json_chunk,
"node") == 0)
5393 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"path") == 0)
5396 if (cgltf_json_strcmp(tokens+i, json_chunk,
"translation") == 0)
5400 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"rotation") == 0)
5404 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"scale") == 0)
5408 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"weights") == 0)
5414 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
5416 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_channel->
extras);
5418 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
5420 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_channel->
extensions_count, &out_channel->
extensions);
5424 i = cgltf_skip_json(tokens, i+1);
5435 i = cgltf_skip_json(tokens, i+1);
5449 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5451 int size = tokens[i].size;
5454 for (
int j = 0; j < size; ++j)
5456 CGLTF_CHECK_KEY(tokens[i]);
5458 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
5460 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_animation->
name);
5462 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"samplers") == 0)
5472 i = cgltf_parse_json_animation_sampler(options, tokens, i, json_chunk, &out_animation->
samplers[k]);
5479 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"channels") == 0)
5489 i = cgltf_parse_json_animation_channel(options, tokens, i, json_chunk, &out_animation->
channels[k]);
5496 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
5498 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_animation->
extras);
5500 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
5502 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_animation->
extensions_count, &out_animation->
extensions);
5506 i = cgltf_skip_json(tokens, i+1);
5528 i = cgltf_parse_json_animation(options, tokens, i, json_chunk, &out_data->
animations[j]);
5539 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5541 int size = tokens[i].size;
5544 for (
int j = 0; j < size; ++j)
5546 CGLTF_CHECK_KEY(tokens[i]);
5548 if (cgltf_json_strcmp(tokens+i, json_chunk,
"name") == 0)
5550 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_variant->
name);
5552 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
5554 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_variant->
extras);
5558 i = cgltf_skip_json(tokens, i+1);
5580 i = cgltf_parse_json_variant(options, tokens, i, json_chunk, &out_data->
variants[j]);
5591 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5593 int size = tokens[i].size;
5596 for (
int j = 0; j < size; ++j)
5598 CGLTF_CHECK_KEY(tokens[i]);
5600 if (cgltf_json_strcmp(tokens+i, json_chunk,
"copyright") == 0)
5602 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_asset->
copyright);
5604 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"generator") == 0)
5606 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_asset->
generator);
5608 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"version") == 0)
5610 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_asset->
version);
5612 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"minVersion") == 0)
5614 i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_asset->
min_version);
5616 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extras") == 0)
5618 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_asset->
extras);
5620 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
5622 i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_asset->
extensions_count, &out_asset->
extensions);
5626 i = cgltf_skip_json(tokens, i+1);
5637 return CGLTF_ERROR_LEGACY;
5666 switch (component_type)
5685 cgltf_size component_size = cgltf_component_size(component_type);
5688 return 8 * component_size;
5690 else if (type ==
cgltf_type_mat3 && (component_size == 1 || component_size == 2))
5692 return 12 * component_size;
5697static int cgltf_fixup_pointers(
cgltf_data* out_data);
5701 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5703 int size = tokens[i].size;
5706 for (
int j = 0; j < size; ++j)
5708 CGLTF_CHECK_KEY(tokens[i]);
5710 if (cgltf_json_strcmp(tokens + i, json_chunk,
"asset") == 0)
5712 i = cgltf_parse_json_asset(options, tokens, i + 1, json_chunk, &out_data->
asset);
5714 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"meshes") == 0)
5716 i = cgltf_parse_json_meshes(options, tokens, i + 1, json_chunk, out_data);
5718 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"accessors") == 0)
5720 i = cgltf_parse_json_accessors(options, tokens, i + 1, json_chunk, out_data);
5722 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"bufferViews") == 0)
5724 i = cgltf_parse_json_buffer_views(options, tokens, i + 1, json_chunk, out_data);
5726 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"buffers") == 0)
5728 i = cgltf_parse_json_buffers(options, tokens, i + 1, json_chunk, out_data);
5730 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"materials") == 0)
5732 i = cgltf_parse_json_materials(options, tokens, i + 1, json_chunk, out_data);
5734 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"images") == 0)
5736 i = cgltf_parse_json_images(options, tokens, i + 1, json_chunk, out_data);
5738 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"textures") == 0)
5740 i = cgltf_parse_json_textures(options, tokens, i + 1, json_chunk, out_data);
5742 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"samplers") == 0)
5744 i = cgltf_parse_json_samplers(options, tokens, i + 1, json_chunk, out_data);
5746 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"skins") == 0)
5748 i = cgltf_parse_json_skins(options, tokens, i + 1, json_chunk, out_data);
5750 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"cameras") == 0)
5752 i = cgltf_parse_json_cameras(options, tokens, i + 1, json_chunk, out_data);
5754 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"nodes") == 0)
5756 i = cgltf_parse_json_nodes(options, tokens, i + 1, json_chunk, out_data);
5758 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"scenes") == 0)
5760 i = cgltf_parse_json_scenes(options, tokens, i + 1, json_chunk, out_data);
5762 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"scene") == 0)
5765 out_data->
scene = CGLTF_PTRINDEX(
cgltf_scene, cgltf_json_to_int(tokens + i, json_chunk));
5768 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"animations") == 0)
5770 i = cgltf_parse_json_animations(options, tokens, i + 1, json_chunk, out_data);
5772 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"extras") == 0)
5774 i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_data->
extras);
5776 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensions") == 0)
5780 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5783 return CGLTF_ERROR_JSON;
5786 int extensions_size = tokens[i].size;
5792 return CGLTF_ERROR_NOMEM;
5797 for (
int k = 0; k < extensions_size; ++k)
5799 CGLTF_CHECK_KEY(tokens[i]);
5801 if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_lights_punctual") == 0)
5805 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5807 int data_size = tokens[i].size;
5810 for (
int m = 0; m < data_size; ++m)
5812 CGLTF_CHECK_KEY(tokens[i]);
5814 if (cgltf_json_strcmp(tokens + i, json_chunk,
"lights") == 0)
5816 i = cgltf_parse_json_lights(options, tokens, i + 1, json_chunk, out_data);
5820 i = cgltf_skip_json(tokens, i + 1);
5829 else if (cgltf_json_strcmp(tokens+i, json_chunk,
"KHR_materials_variants") == 0)
5833 CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
5835 int data_size = tokens[i].size;
5838 for (
int m = 0; m < data_size; ++m)
5840 CGLTF_CHECK_KEY(tokens[i]);
5842 if (cgltf_json_strcmp(tokens + i, json_chunk,
"variants") == 0)
5844 i = cgltf_parse_json_variants(options, tokens, i + 1, json_chunk, out_data);
5848 i = cgltf_skip_json(tokens, i + 1);
5868 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensionsUsed") == 0)
5872 else if (cgltf_json_strcmp(tokens + i, json_chunk,
"extensionsRequired") == 0)
5878 i = cgltf_skip_json(tokens, i + 1);
5892 jsmn_parser parser = { 0, 0, 0 };
5896 int token_count = jsmn_parse(&parser, (
const char*)json_chunk, size,
NULL, 0);
5898 if (token_count <= 0)
5915 int token_count = jsmn_parse(&parser, (
const char*)json_chunk, size, tokens, options->
json_token_count);
5917 if (token_count <= 0)
5925 tokens[token_count].type = JSMN_UNDEFINED;
5939 int i = cgltf_parse_json_root(options, tokens, 0, json_chunk, data);
5955 if (cgltf_fixup_pointers(data) < 0)
5961 data->
json = (
const char*)json_chunk;
5969static int cgltf_fixup_pointers(
cgltf_data* data)
6096 return CGLTF_ERROR_JSON;
6116 return CGLTF_ERROR_JSON;
6170static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
6171 jsmntok_t *tokens,
size_t num_tokens) {
6173 if (parser->toknext >= num_tokens) {
6176 tok = &tokens[parser->toknext++];
6177 tok->start = tok->end = -1;
6179#ifdef JSMN_PARENT_LINKS
6188static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type,
6189 int start,
int end) {
6191 token->start = start;
6199static int jsmn_parse_primitive(jsmn_parser *parser,
const char *js,
6200 size_t len, jsmntok_t *tokens,
size_t num_tokens) {
6204 start = parser->pos;
6206 for (; parser->pos < len && js[parser->pos] !=
'\0'; parser->pos++) {
6207 switch (js[parser->pos]) {
6212 case '\t' :
case '\r' :
case '\n' :
case ' ' :
6213 case ',' :
case ']' :
case '}' :
6216 if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
6217 parser->pos = start;
6218 return JSMN_ERROR_INVAL;
6223 parser->pos = start;
6224 return JSMN_ERROR_PART;
6228 if (tokens ==
NULL) {
6232 token = jsmn_alloc_token(parser, tokens, num_tokens);
6233 if (token ==
NULL) {
6234 parser->pos = start;
6235 return JSMN_ERROR_NOMEM;
6237 jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
6238#ifdef JSMN_PARENT_LINKS
6239 token->parent = parser->toksuper;
6248static int jsmn_parse_string(jsmn_parser *parser,
const char *js,
6249 size_t len, jsmntok_t *tokens,
size_t num_tokens) {
6252 int start = parser->pos;
6257 for (; parser->pos < len && js[parser->pos] !=
'\0'; parser->pos++) {
6258 char c = js[parser->pos];
6262 if (tokens ==
NULL) {
6265 token = jsmn_alloc_token(parser, tokens, num_tokens);
6266 if (token ==
NULL) {
6267 parser->pos = start;
6268 return JSMN_ERROR_NOMEM;
6270 jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
6271#ifdef JSMN_PARENT_LINKS
6272 token->parent = parser->toksuper;
6278 if (c ==
'\\' && parser->pos + 1 < len) {
6281 switch (js[parser->pos]) {
6283 case '\"':
case '/' :
case '\\' :
case 'b' :
6284 case 'f' :
case 'r' :
case 'n' :
case 't' :
6289 for(i = 0; i < 4 && parser->pos < len && js[parser->pos] !=
'\0'; i++) {
6291 if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) ||
6292 (js[parser->pos] >= 65 && js[parser->pos] <= 70) ||
6293 (js[parser->pos] >= 97 && js[parser->pos] <= 102))) {
6294 parser->pos = start;
6295 return JSMN_ERROR_INVAL;
6303 parser->pos = start;
6304 return JSMN_ERROR_INVAL;
6308 parser->pos = start;
6309 return JSMN_ERROR_PART;
6315static int jsmn_parse(jsmn_parser *parser,
const char *js,
size_t len,
6316 jsmntok_t *tokens,
size_t num_tokens) {
6320 int count = parser->toknext;
6322 for (; parser->pos < len && js[parser->pos] !=
'\0'; parser->pos++) {
6326 c = js[parser->pos];
6330 if (tokens ==
NULL) {
6333 token = jsmn_alloc_token(parser, tokens, num_tokens);
6335 return JSMN_ERROR_NOMEM;
6336 if (parser->toksuper != -1) {
6337 tokens[parser->toksuper].size++;
6338#ifdef JSMN_PARENT_LINKS
6339 token->parent = parser->toksuper;
6342 token->type = (c ==
'{' ? JSMN_OBJECT : JSMN_ARRAY);
6343 token->start = parser->pos;
6344 parser->toksuper = parser->toknext - 1;
6349 type = (c ==
'}' ? JSMN_OBJECT : JSMN_ARRAY);
6350#ifdef JSMN_PARENT_LINKS
6351 if (parser->toknext < 1) {
6352 return JSMN_ERROR_INVAL;
6354 token = &tokens[parser->toknext - 1];
6356 if (token->start != -1 && token->end == -1) {
6357 if (token->type != type) {
6358 return JSMN_ERROR_INVAL;
6360 token->end = parser->pos + 1;
6361 parser->toksuper = token->parent;
6364 if (token->parent == -1) {
6365 if(token->type != type || parser->toksuper == -1) {
6366 return JSMN_ERROR_INVAL;
6370 token = &tokens[token->parent];
6373 for (i = parser->toknext - 1; i >= 0; i--) {
6375 if (token->start != -1 && token->end == -1) {
6376 if (token->type != type) {
6377 return JSMN_ERROR_INVAL;
6379 parser->toksuper = -1;
6380 token->end = parser->pos + 1;
6385 if (i == -1)
return JSMN_ERROR_INVAL;
6386 for (; i >= 0; i--) {
6388 if (token->start != -1 && token->end == -1) {
6389 parser->toksuper = i;
6396 r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
6397 if (r < 0)
return r;
6399 if (parser->toksuper != -1 && tokens !=
NULL)
6400 tokens[parser->toksuper].size++;
6402 case '\t' :
case '\r' :
case '\n' :
case ' ':
6405 parser->toksuper = parser->toknext - 1;
6408 if (tokens !=
NULL && parser->toksuper != -1 &&
6409 tokens[parser->toksuper].type != JSMN_ARRAY &&
6410 tokens[parser->toksuper].type != JSMN_OBJECT) {
6411#ifdef JSMN_PARENT_LINKS
6412 parser->toksuper = tokens[parser->toksuper].parent;
6414 for (i = parser->toknext - 1; i >= 0; i--) {
6415 if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
6416 if (tokens[i].start != -1 && tokens[i].end == -1) {
6417 parser->toksuper = i;
6427 case '-':
case '0':
case '1' :
case '2':
case '3' :
case '4':
6428 case '5':
case '6':
case '7' :
case '8':
case '9':
6429 case 't':
case 'f':
case 'n' :
6431 if (tokens !=
NULL && parser->toksuper != -1) {
6432 jsmntok_t *t = &tokens[parser->toksuper];
6433 if (t->type == JSMN_OBJECT ||
6434 (t->type == JSMN_STRING && t->size != 0)) {
6435 return JSMN_ERROR_INVAL;
6442 r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
6443 if (r < 0)
return r;
6445 if (parser->toksuper != -1 && tokens !=
NULL)
6446 tokens[parser->toksuper].size++;
6452 return JSMN_ERROR_INVAL;
6457 if (tokens !=
NULL) {
6458 for (i = parser->toknext - 1; i >= 0; i--) {
6460 if (tokens[i].start != -1 && tokens[i].end == -1) {
6461 return JSMN_ERROR_PART;
6473static void jsmn_init(jsmn_parser *parser) {
6475 parser->toknext = 0;
6476 parser->toksuper = -1;
size_t cgltf_size
cgltf - a single-file glTF 2.0 parser written in C99.
void cgltf_node_transform_local(const cgltf_node *node, cgltf_float *out_matrix)
cgltf_result cgltf_parse_file(const cgltf_options *options, const char *path, cgltf_data **out_data)
cgltf_bool cgltf_accessor_read_float(const cgltf_accessor *accessor, cgltf_size index, cgltf_float *out, cgltf_size element_size)
cgltf_animation_path_type
@ cgltf_animation_path_type_weights
@ cgltf_animation_path_type_invalid
@ cgltf_animation_path_type_translation
@ cgltf_animation_path_type_scale
@ cgltf_animation_path_type_rotation
cgltf_result cgltf_validate(cgltf_data *data)
cgltf_meshopt_compression_mode
@ cgltf_meshopt_compression_mode_attributes
@ cgltf_meshopt_compression_mode_invalid
@ cgltf_meshopt_compression_mode_triangles
@ cgltf_meshopt_compression_mode_indices
void cgltf_node_transform_world(const cgltf_node *node, cgltf_float *out_matrix)
@ cgltf_primitive_type_line_strip
@ cgltf_primitive_type_lines
@ cgltf_primitive_type_triangles
@ cgltf_primitive_type_line_loop
@ cgltf_primitive_type_triangle_fan
@ cgltf_primitive_type_points
@ cgltf_primitive_type_triangle_strip
cgltf_bool cgltf_accessor_read_uint(const cgltf_accessor *accessor, cgltf_size index, cgltf_uint *out, cgltf_size element_size)
cgltf_result cgltf_parse(const cgltf_options *options, const void *data, cgltf_size size, cgltf_data **out_data)
void cgltf_decode_uri(char *uri)
cgltf_result cgltf_copy_extras_json(const cgltf_data *data, const cgltf_extras *extras, char *dest, cgltf_size *dest_size)
void cgltf_free(cgltf_data *data)
@ cgltf_interpolation_type_cubic_spline
@ cgltf_interpolation_type_linear
@ cgltf_interpolation_type_step
@ cgltf_light_type_invalid
@ cgltf_light_type_directional
@ cgltf_attribute_type_color
@ cgltf_attribute_type_joints
@ cgltf_attribute_type_invalid
@ cgltf_attribute_type_texcoord
@ cgltf_attribute_type_weights
@ cgltf_attribute_type_position
@ cgltf_attribute_type_tangent
@ cgltf_attribute_type_normal
cgltf_result cgltf_load_buffer_base64(const cgltf_options *options, cgltf_size size, const char *base64, void **out_data)
cgltf_size cgltf_accessor_read_index(const cgltf_accessor *accessor, cgltf_size index)
cgltf_size cgltf_num_components(cgltf_type type)
cgltf_result cgltf_load_buffers(const cgltf_options *options, cgltf_data *data, const char *gltf_path)
void cgltf_decode_string(char *string)
@ cgltf_component_type_r_32f
@ cgltf_component_type_r_8
@ cgltf_component_type_r_8u
@ cgltf_component_type_r_32u
@ cgltf_component_type_r_16u
@ cgltf_component_type_invalid
@ cgltf_component_type_r_16
cgltf_size cgltf_accessor_unpack_floats(const cgltf_accessor *accessor, cgltf_float *out, cgltf_size float_count)
@ cgltf_data_free_method_memory_free
@ cgltf_data_free_method_none
@ cgltf_data_free_method_file_release
cgltf_meshopt_compression_filter
@ cgltf_meshopt_compression_filter_none
@ cgltf_meshopt_compression_filter_quaternion
@ cgltf_meshopt_compression_filter_octahedral
@ cgltf_meshopt_compression_filter_exponential
@ cgltf_result_invalid_gltf
@ cgltf_result_legacy_gltf
@ cgltf_result_data_too_short
@ cgltf_result_unknown_format
@ cgltf_result_file_not_found
@ cgltf_result_out_of_memory
@ cgltf_result_invalid_options
@ cgltf_result_invalid_json
@ cgltf_file_type_invalid
@ cgltf_camera_type_orthographic
@ cgltf_camera_type_invalid
@ cgltf_camera_type_perspective
@ cgltf_alpha_mode_opaque
@ cgltf_buffer_view_type_invalid
@ cgltf_buffer_view_type_vertices
@ cgltf_buffer_view_type_indices
cgltf_size extensions_count
cgltf_extension * indices_extensions
cgltf_extension * values_extensions
cgltf_buffer_view * indices_buffer_view
cgltf_size values_extensions_count
cgltf_size indices_extensions_count
cgltf_component_type indices_component_type
cgltf_size values_byte_offset
cgltf_extras values_extras
cgltf_extension * extensions
cgltf_buffer_view * values_buffer_view
cgltf_size indices_byte_offset
cgltf_extras indices_extras
cgltf_size extensions_count
cgltf_buffer_view * buffer_view
cgltf_component_type component_type
cgltf_accessor_sparse sparse
cgltf_extension * extensions
cgltf_animation_path_type target_path
cgltf_animation_sampler * sampler
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_extension * extensions
cgltf_interpolation_type interpolation
cgltf_size extensions_count
cgltf_animation_sampler * samplers
cgltf_animation_channel * channels
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_size channels_count
cgltf_size samplers_count
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_attribute_type type
cgltf_extension * extensions
cgltf_meshopt_compression meshopt_compression
cgltf_buffer_view_type type
cgltf_bool has_meshopt_compression
cgltf_size extensions_count
cgltf_data_free_method data_free_method
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_bool has_aspect_ratio
union cgltf_camera::@0 data
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_camera_orthographic orthographic
cgltf_camera_perspective perspective
cgltf_float clearcoat_roughness_factor
cgltf_texture_view clearcoat_roughness_texture
cgltf_texture_view clearcoat_normal_texture
cgltf_float clearcoat_factor
cgltf_texture_view clearcoat_texture
cgltf_size variants_count
cgltf_extension * data_extensions
cgltf_size buffer_views_count
cgltf_memory_options memory
cgltf_size extensions_required_count
cgltf_buffer_view * buffer_views
cgltf_size extensions_used_count
cgltf_material * materials
cgltf_size textures_count
cgltf_animation * animations
cgltf_file_type file_type
cgltf_accessor * accessors
char ** extensions_required
cgltf_size samplers_count
cgltf_size animations_count
cgltf_size accessors_count
cgltf_size data_extensions_count
cgltf_material_variant * variants
cgltf_size materials_count
cgltf_attribute * attributes
cgltf_size attributes_count
cgltf_buffer_view * buffer_view
cgltf_result(* read)(const struct cgltf_memory_options *memory_options, const struct cgltf_file_options *file_options, const char *path, cgltf_size *size, void **data)
void(* release)(const struct cgltf_memory_options *memory_options, const struct cgltf_file_options *file_options, void *data)
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_buffer_view * buffer_view
cgltf_float spot_outer_cone_angle
cgltf_float spot_inner_cone_angle
cgltf_material * material
cgltf_pbr_specular_glossiness pbr_specular_glossiness
cgltf_pbr_metallic_roughness pbr_metallic_roughness
cgltf_size extensions_count
cgltf_float emissive_factor[3]
cgltf_bool has_transmission
cgltf_extension * extensions
cgltf_bool has_pbr_metallic_roughness
cgltf_texture_view emissive_texture
cgltf_texture_view occlusion_texture
cgltf_transmission transmission
cgltf_alpha_mode alpha_mode
cgltf_clearcoat clearcoat
cgltf_bool has_pbr_specular_glossiness
cgltf_texture_view normal_texture
void *(* alloc)(void *user, cgltf_size size)
void(* free)(void *user, void *ptr)
cgltf_primitive * primitives
cgltf_size primitives_count
cgltf_extension * extensions
cgltf_size target_names_count
cgltf_size extensions_count
cgltf_meshopt_compression_filter filter
cgltf_meshopt_compression_mode mode
cgltf_size attributes_count
cgltf_attribute * attributes
cgltf_size children_count
cgltf_bool has_translation
cgltf_size extensions_count
cgltf_extension * extensions
cgltf_float translation[3]
cgltf_memory_options memory
cgltf_size json_token_count
cgltf_texture_view diffuse_texture
cgltf_float specular_factor[3]
cgltf_float diffuse_factor[4]
cgltf_float glossiness_factor
cgltf_texture_view specular_glossiness_texture
cgltf_draco_mesh_compression draco_mesh_compression
cgltf_size extensions_count
cgltf_size attributes_count
cgltf_extension * extensions
cgltf_morph_target * targets
cgltf_bool has_draco_mesh_compression
cgltf_size mappings_count
cgltf_material_mapping * mappings
cgltf_attribute * attributes
cgltf_primitive_type type
cgltf_material * material
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_size extensions_count
cgltf_extension * extensions
cgltf_texture_view sheen_color_texture
cgltf_float sheen_color_factor[3]
cgltf_float sheen_roughness_factor
cgltf_texture_view sheen_roughness_texture
cgltf_extension * extensions
cgltf_accessor * inverse_bind_matrices
cgltf_size extensions_count
cgltf_float specular_factor
cgltf_float specular_color_factor[3]
cgltf_texture_view specular_color_texture
cgltf_texture_view specular_texture
cgltf_extension * extensions
cgltf_texture_transform transform
cgltf_size extensions_count
cgltf_image * basisu_image
cgltf_extension * extensions
cgltf_size extensions_count
cgltf_float transmission_factor
cgltf_texture_view transmission_texture
cgltf_float attenuation_distance
cgltf_float thickness_factor
cgltf_texture_view thickness_texture
cgltf_float attenuation_color[3]