MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / gltf_parse_extras

Function gltf_parse_extras

StereoKitC/libraries/cgltf.cpp:25–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace sk {
24
25void gltf_parse_extras(model_t model, model_node_id node, const char *extras_json, size_t extras_size) {
26 jsmn_parser parser;
27 jsmn_init(&parser);
28
29 int32_t token_ct = jsmn_parse(&parser, extras_json, extras_size, nullptr, 0);
30 if (token_ct <= 0) return;
31
32 jsmntok_t* tokens = sk_malloc_t(jsmntok_t, token_ct);
33 jsmn_init(&parser);
34 token_ct = jsmn_parse(&parser, extras_json, extras_size, tokens, token_ct);
35
36 if (token_ct < 1 || tokens[0].type != JSMN_OBJECT) {
37 return;
38 }
39
40 for (int32_t i = 1; i < token_ct; i+=1) {
41 if (tokens[i].type == JSMN_STRING) {
42 if (tokens[i].size == 1) {
43 stref_t key = { extras_json + tokens[i ].start, (uint32_t)(tokens[i ].end-tokens[i ].start) };
44 stref_t val = { extras_json + tokens[i+1].start, (uint32_t)(tokens[i+1].end-tokens[i+1].start) };
45 char* key_str = stref_copy(key);
46 char* val_str = stref_copy(val);
47 model_node_info_set(model, node, key_str, val_str);
48 sk_free(key_str);
49 sk_free(val_str);
50 } else {
51 stref_t key = { extras_json + tokens[i].start, (uint32_t)(tokens[i].end - tokens[i].start) };
52 char* key_str = stref_copy(key);
53 model_node_info_set(model, node, key_str, "true");
54 sk_free(key_str);
55 }
56 } else if (tokens[i].type == JSMN_OBJECT) {
57 log_warn("SK node extras does not support object types");
58 } else if (tokens[i].type == JSMN_ARRAY) {
59 log_warn("SK node extras does not support array types");
60 }
61 i += tokens[i].size;
62 }
63 sk_free(tokens);
64}
65
66}

Callers 1

gltf_add_nodeFunction · 0.85

Calls 5

jsmn_initFunction · 0.85
jsmn_parseFunction · 0.85
stref_copyFunction · 0.85
model_node_info_setFunction · 0.85
log_warnFunction · 0.85

Tested by

no test coverage detected