Update cgltf.h
This commit is contained in:
parent
1b14c082ed
commit
aca9ab0ebb
1 changed files with 168 additions and 62 deletions
164
src/external/cgltf.h
vendored
164
src/external/cgltf.h
vendored
|
@ -63,6 +63,11 @@
|
||||||
* By passing null for the output pointer, users can find out how many floats are required in the
|
* By passing null for the output pointer, users can find out how many floats are required in the
|
||||||
* output buffer.
|
* output buffer.
|
||||||
*
|
*
|
||||||
|
* `cgltf_accessor_unpack_indices` reads in the index data from an accessor. Assumes that
|
||||||
|
* `cgltf_load_buffers` has already been called. By passing null for the output pointer, users can
|
||||||
|
* find out how many indices are required in the output buffer. Returns 0 if the accessor is
|
||||||
|
* sparse or if the output component size is less than the accessor's component size.
|
||||||
|
*
|
||||||
* `cgltf_num_components` is a tiny utility that tells you the dimensionality of
|
* `cgltf_num_components` is a tiny utility that tells you the dimensionality of
|
||||||
* a certain accessor type. This can be used before `cgltf_accessor_unpack_floats` to help allocate
|
* a certain accessor type. This can be used before `cgltf_accessor_unpack_floats` to help allocate
|
||||||
* the necessary amount of memory. `cgltf_component_size` and `cgltf_calc_size` exist for
|
* the necessary amount of memory. `cgltf_component_size` and `cgltf_calc_size` exist for
|
||||||
|
@ -197,6 +202,7 @@ typedef enum cgltf_type
|
||||||
|
|
||||||
typedef enum cgltf_primitive_type
|
typedef enum cgltf_primitive_type
|
||||||
{
|
{
|
||||||
|
cgltf_primitive_type_invalid,
|
||||||
cgltf_primitive_type_points,
|
cgltf_primitive_type_points,
|
||||||
cgltf_primitive_type_lines,
|
cgltf_primitive_type_lines,
|
||||||
cgltf_primitive_type_line_loop,
|
cgltf_primitive_type_line_loop,
|
||||||
|
@ -499,6 +505,11 @@ typedef struct cgltf_anisotropy
|
||||||
cgltf_texture_view anisotropy_texture;
|
cgltf_texture_view anisotropy_texture;
|
||||||
} cgltf_anisotropy;
|
} cgltf_anisotropy;
|
||||||
|
|
||||||
|
typedef struct cgltf_dispersion
|
||||||
|
{
|
||||||
|
cgltf_float dispersion;
|
||||||
|
} cgltf_dispersion;
|
||||||
|
|
||||||
typedef struct cgltf_material
|
typedef struct cgltf_material
|
||||||
{
|
{
|
||||||
char* name;
|
char* name;
|
||||||
|
@ -513,6 +524,7 @@ typedef struct cgltf_material
|
||||||
cgltf_bool has_emissive_strength;
|
cgltf_bool has_emissive_strength;
|
||||||
cgltf_bool has_iridescence;
|
cgltf_bool has_iridescence;
|
||||||
cgltf_bool has_anisotropy;
|
cgltf_bool has_anisotropy;
|
||||||
|
cgltf_bool has_dispersion;
|
||||||
cgltf_pbr_metallic_roughness pbr_metallic_roughness;
|
cgltf_pbr_metallic_roughness pbr_metallic_roughness;
|
||||||
cgltf_pbr_specular_glossiness pbr_specular_glossiness;
|
cgltf_pbr_specular_glossiness pbr_specular_glossiness;
|
||||||
cgltf_clearcoat clearcoat;
|
cgltf_clearcoat clearcoat;
|
||||||
|
@ -524,6 +536,7 @@ typedef struct cgltf_material
|
||||||
cgltf_emissive_strength emissive_strength;
|
cgltf_emissive_strength emissive_strength;
|
||||||
cgltf_iridescence iridescence;
|
cgltf_iridescence iridescence;
|
||||||
cgltf_anisotropy anisotropy;
|
cgltf_anisotropy anisotropy;
|
||||||
|
cgltf_dispersion dispersion;
|
||||||
cgltf_texture_view normal_texture;
|
cgltf_texture_view normal_texture;
|
||||||
cgltf_texture_view occlusion_texture;
|
cgltf_texture_view occlusion_texture;
|
||||||
cgltf_texture_view emissive_texture;
|
cgltf_texture_view emissive_texture;
|
||||||
|
@ -838,7 +851,7 @@ cgltf_size cgltf_component_size(cgltf_component_type component_type);
|
||||||
cgltf_size cgltf_calc_size(cgltf_type type, cgltf_component_type component_type);
|
cgltf_size cgltf_calc_size(cgltf_type type, cgltf_component_type component_type);
|
||||||
|
|
||||||
cgltf_size cgltf_accessor_unpack_floats(const cgltf_accessor* accessor, cgltf_float* out, cgltf_size float_count);
|
cgltf_size cgltf_accessor_unpack_floats(const cgltf_accessor* accessor, cgltf_float* out, cgltf_size float_count);
|
||||||
cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, cgltf_uint* out, cgltf_size index_count);
|
cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, void* out, cgltf_size out_component_size, cgltf_size index_count);
|
||||||
|
|
||||||
/* this function is deprecated and will be removed in the future; use cgltf_extras::data instead */
|
/* this function is deprecated and will be removed in the future; use cgltf_extras::data instead */
|
||||||
cgltf_result cgltf_copy_extras_json(const cgltf_data* data, const cgltf_extras* extras, char* dest, cgltf_size* dest_size);
|
cgltf_result cgltf_copy_extras_json(const cgltf_data* data, const cgltf_extras* extras, char* dest, cgltf_size* dest_size);
|
||||||
|
@ -938,8 +951,8 @@ static int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, jsmntok_t
|
||||||
|
|
||||||
|
|
||||||
#ifndef CGLTF_CONSTS
|
#ifndef CGLTF_CONSTS
|
||||||
static const cgltf_size GlbHeaderSize = 12;
|
#define GlbHeaderSize 12
|
||||||
static const cgltf_size GlbChunkHeaderSize = 8;
|
#define GlbChunkHeaderSize 8
|
||||||
static const uint32_t GlbVersion = 2;
|
static const uint32_t GlbVersion = 2;
|
||||||
static const uint32_t GlbMagic = 0x46546C67;
|
static const uint32_t GlbMagic = 0x46546C67;
|
||||||
static const uint32_t GlbMagicJsonChunk = 0x4E4F534A;
|
static const uint32_t GlbMagicJsonChunk = 0x4E4F534A;
|
||||||
|
@ -1141,7 +1154,7 @@ cgltf_result cgltf_parse(const cgltf_options* options, const void* data, cgltf_s
|
||||||
// JSON chunk: length
|
// JSON chunk: length
|
||||||
uint32_t json_length;
|
uint32_t json_length;
|
||||||
memcpy(&json_length, json_chunk, 4);
|
memcpy(&json_length, json_chunk, 4);
|
||||||
if (GlbHeaderSize + GlbChunkHeaderSize + json_length > size)
|
if (json_length > size - GlbHeaderSize - GlbChunkHeaderSize)
|
||||||
{
|
{
|
||||||
return cgltf_result_data_too_short;
|
return cgltf_result_data_too_short;
|
||||||
}
|
}
|
||||||
|
@ -1158,7 +1171,7 @@ cgltf_result cgltf_parse(const cgltf_options* options, const void* data, cgltf_s
|
||||||
const void* bin = NULL;
|
const void* bin = NULL;
|
||||||
cgltf_size bin_size = 0;
|
cgltf_size bin_size = 0;
|
||||||
|
|
||||||
if (GlbHeaderSize + GlbChunkHeaderSize + json_length + GlbChunkHeaderSize <= size)
|
if (GlbChunkHeaderSize <= size - GlbHeaderSize - GlbChunkHeaderSize - json_length)
|
||||||
{
|
{
|
||||||
// We can read another chunk
|
// We can read another chunk
|
||||||
const uint8_t* bin_chunk = json_chunk + json_length;
|
const uint8_t* bin_chunk = json_chunk + json_length;
|
||||||
|
@ -1166,7 +1179,7 @@ cgltf_result cgltf_parse(const cgltf_options* options, const void* data, cgltf_s
|
||||||
// Bin chunk: length
|
// Bin chunk: length
|
||||||
uint32_t bin_length;
|
uint32_t bin_length;
|
||||||
memcpy(&bin_length, bin_chunk, 4);
|
memcpy(&bin_length, bin_chunk, 4);
|
||||||
if (GlbHeaderSize + GlbChunkHeaderSize + json_length + GlbChunkHeaderSize + bin_length > size)
|
if (bin_length > size - GlbHeaderSize - GlbChunkHeaderSize - json_length - GlbChunkHeaderSize)
|
||||||
{
|
{
|
||||||
return cgltf_result_data_too_short;
|
return cgltf_result_data_too_short;
|
||||||
}
|
}
|
||||||
|
@ -1552,6 +1565,9 @@ cgltf_result cgltf_validate(cgltf_data* data)
|
||||||
{
|
{
|
||||||
cgltf_accessor* accessor = &data->accessors[i];
|
cgltf_accessor* accessor = &data->accessors[i];
|
||||||
|
|
||||||
|
CGLTF_ASSERT_IF(data->accessors[i].component_type == cgltf_component_type_invalid, cgltf_result_invalid_gltf);
|
||||||
|
CGLTF_ASSERT_IF(data->accessors[i].type == cgltf_type_invalid, cgltf_result_invalid_gltf);
|
||||||
|
|
||||||
cgltf_size element_size = cgltf_calc_size(accessor->type, accessor->component_type);
|
cgltf_size element_size = cgltf_calc_size(accessor->type, accessor->component_type);
|
||||||
|
|
||||||
if (accessor->buffer_view)
|
if (accessor->buffer_view)
|
||||||
|
@ -1565,7 +1581,7 @@ cgltf_result cgltf_validate(cgltf_data* data)
|
||||||
{
|
{
|
||||||
cgltf_accessor_sparse* sparse = &accessor->sparse;
|
cgltf_accessor_sparse* sparse = &accessor->sparse;
|
||||||
|
|
||||||
cgltf_size indices_component_size = cgltf_calc_size(cgltf_type_scalar, sparse->indices_component_type);
|
cgltf_size indices_component_size = cgltf_component_size(sparse->indices_component_type);
|
||||||
cgltf_size indices_req_size = sparse->indices_byte_offset + indices_component_size * sparse->count;
|
cgltf_size indices_req_size = sparse->indices_byte_offset + indices_component_size * sparse->count;
|
||||||
cgltf_size values_req_size = sparse->values_byte_offset + element_size * sparse->count;
|
cgltf_size values_req_size = sparse->values_byte_offset + element_size * sparse->count;
|
||||||
|
|
||||||
|
@ -1631,12 +1647,15 @@ cgltf_result cgltf_validate(cgltf_data* data)
|
||||||
|
|
||||||
for (cgltf_size j = 0; j < data->meshes[i].primitives_count; ++j)
|
for (cgltf_size j = 0; j < data->meshes[i].primitives_count; ++j)
|
||||||
{
|
{
|
||||||
|
CGLTF_ASSERT_IF(data->meshes[i].primitives[j].type == cgltf_primitive_type_invalid, cgltf_result_invalid_gltf);
|
||||||
CGLTF_ASSERT_IF(data->meshes[i].primitives[j].targets_count != data->meshes[i].primitives[0].targets_count, cgltf_result_invalid_gltf);
|
CGLTF_ASSERT_IF(data->meshes[i].primitives[j].targets_count != data->meshes[i].primitives[0].targets_count, cgltf_result_invalid_gltf);
|
||||||
|
|
||||||
if (data->meshes[i].primitives[j].attributes_count)
|
CGLTF_ASSERT_IF(data->meshes[i].primitives[j].attributes_count == 0, cgltf_result_invalid_gltf);
|
||||||
{
|
|
||||||
cgltf_accessor* first = data->meshes[i].primitives[j].attributes[0].data;
|
cgltf_accessor* first = data->meshes[i].primitives[j].attributes[0].data;
|
||||||
|
|
||||||
|
CGLTF_ASSERT_IF(first->count == 0, cgltf_result_invalid_gltf);
|
||||||
|
|
||||||
for (cgltf_size k = 0; k < data->meshes[i].primitives[j].attributes_count; ++k)
|
for (cgltf_size k = 0; k < data->meshes[i].primitives[j].attributes_count; ++k)
|
||||||
{
|
{
|
||||||
CGLTF_ASSERT_IF(data->meshes[i].primitives[j].attributes[k].data->count != first->count, cgltf_result_invalid_gltf);
|
CGLTF_ASSERT_IF(data->meshes[i].primitives[j].attributes[k].data->count != first->count, cgltf_result_invalid_gltf);
|
||||||
|
@ -1657,6 +1676,9 @@ cgltf_result cgltf_validate(cgltf_data* data)
|
||||||
indices->component_type != cgltf_component_type_r_16u &&
|
indices->component_type != cgltf_component_type_r_16u &&
|
||||||
indices->component_type != cgltf_component_type_r_32u, cgltf_result_invalid_gltf);
|
indices->component_type != cgltf_component_type_r_32u, cgltf_result_invalid_gltf);
|
||||||
|
|
||||||
|
CGLTF_ASSERT_IF(indices && indices->type != cgltf_type_scalar, cgltf_result_invalid_gltf);
|
||||||
|
CGLTF_ASSERT_IF(indices && indices->stride != cgltf_component_size(indices->component_type), cgltf_result_invalid_gltf);
|
||||||
|
|
||||||
if (indices && indices->buffer_view && indices->buffer_view->buffer->data)
|
if (indices && indices->buffer_view && indices->buffer_view->buffer->data)
|
||||||
{
|
{
|
||||||
cgltf_size index_bound = cgltf_calc_index_bound(indices->buffer_view, indices->offset, indices->component_type, indices->count);
|
cgltf_size index_bound = cgltf_calc_index_bound(indices->buffer_view, indices->offset, indices->component_type, indices->count);
|
||||||
|
@ -1670,7 +1692,6 @@ cgltf_result cgltf_validate(cgltf_data* data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (cgltf_size i = 0; i < data->nodes_count; ++i)
|
for (cgltf_size i = 0; i < data->nodes_count; ++i)
|
||||||
{
|
{
|
||||||
|
@ -1724,10 +1745,15 @@ cgltf_result cgltf_validate(cgltf_data* data)
|
||||||
|
|
||||||
cgltf_size values = channel->sampler->interpolation == cgltf_interpolation_type_cubic_spline ? 3 : 1;
|
cgltf_size values = channel->sampler->interpolation == cgltf_interpolation_type_cubic_spline ? 3 : 1;
|
||||||
|
|
||||||
CGLTF_ASSERT_IF(channel->sampler->input->count * components * values != channel->sampler->output->count, cgltf_result_data_too_short);
|
CGLTF_ASSERT_IF(channel->sampler->input->count * components * values != channel->sampler->output->count, cgltf_result_invalid_gltf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (cgltf_size i = 0; i < data->variants_count; ++i)
|
||||||
|
{
|
||||||
|
CGLTF_ASSERT_IF(!data->variants[i].name, cgltf_result_invalid_gltf);
|
||||||
|
}
|
||||||
|
|
||||||
return cgltf_result_success;
|
return cgltf_result_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2550,7 +2576,7 @@ cgltf_size cgltf_animation_channel_index(const cgltf_animation* animation, const
|
||||||
return (cgltf_size)(object - animation->channels);
|
return (cgltf_size)(object - animation->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, cgltf_uint* out, cgltf_size index_count)
|
cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, void* out, cgltf_size out_component_size, cgltf_size index_count)
|
||||||
{
|
{
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
{
|
{
|
||||||
|
@ -2558,6 +2584,7 @@ cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, cgltf_u
|
||||||
}
|
}
|
||||||
|
|
||||||
index_count = accessor->count < index_count ? accessor->count : index_count;
|
index_count = accessor->count < index_count ? accessor->count : index_count;
|
||||||
|
cgltf_size index_component_size = cgltf_component_size(accessor->component_type);
|
||||||
|
|
||||||
if (accessor->is_sparse)
|
if (accessor->is_sparse)
|
||||||
{
|
{
|
||||||
|
@ -2567,6 +2594,10 @@ cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, cgltf_u
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (index_component_size > out_component_size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
const uint8_t* element = cgltf_buffer_view_data(accessor->buffer_view);
|
const uint8_t* element = cgltf_buffer_view_data(accessor->buffer_view);
|
||||||
if (element == NULL)
|
if (element == NULL)
|
||||||
{
|
{
|
||||||
|
@ -2574,18 +2605,29 @@ cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, cgltf_u
|
||||||
}
|
}
|
||||||
element += accessor->offset;
|
element += accessor->offset;
|
||||||
|
|
||||||
if (accessor->component_type == cgltf_component_type_r_32u && accessor->stride == sizeof(cgltf_uint))
|
if (index_component_size == out_component_size && accessor->stride == out_component_size)
|
||||||
{
|
{
|
||||||
memcpy(out, element, index_count * sizeof(cgltf_uint));
|
memcpy(out, element, index_count * index_component_size);
|
||||||
|
return index_count;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
cgltf_uint* dest = out;
|
|
||||||
|
|
||||||
for (cgltf_size index = 0; index < index_count; index++, dest++, element += accessor->stride)
|
// The component size of the output array is larger than the component size of the index data, so index data will be padded.
|
||||||
|
switch (out_component_size)
|
||||||
{
|
{
|
||||||
*dest = (cgltf_uint)cgltf_component_read_index(element, accessor->component_type);
|
case 2:
|
||||||
|
for (cgltf_size index = 0; index < index_count; index++, element += accessor->stride)
|
||||||
|
{
|
||||||
|
((uint16_t*)out)[index] = (uint16_t)cgltf_component_read_index(element, accessor->component_type);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
for (cgltf_size index = 0; index < index_count; index++, element += accessor->stride)
|
||||||
|
{
|
||||||
|
((uint32_t*)out)[index] = (uint32_t)cgltf_component_read_index(element, accessor->component_type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return index_count;
|
return index_count;
|
||||||
|
@ -2596,7 +2638,7 @@ cgltf_size cgltf_accessor_unpack_indices(const cgltf_accessor* accessor, cgltf_u
|
||||||
#define CGLTF_ERROR_LEGACY -3
|
#define CGLTF_ERROR_LEGACY -3
|
||||||
|
|
||||||
#define CGLTF_CHECK_TOKTYPE(tok_, type_) if ((tok_).type != (type_)) { return CGLTF_ERROR_JSON; }
|
#define CGLTF_CHECK_TOKTYPE(tok_, type_) if ((tok_).type != (type_)) { return CGLTF_ERROR_JSON; }
|
||||||
#define CGLTF_CHECK_TOKTYPE_RETTYPE(tok_, type_, ret_) if ((tok_).type != (type_)) { return (ret_)CGLTF_ERROR_JSON; }
|
#define CGLTF_CHECK_TOKTYPE_RET(tok_, type_, ret_) if ((tok_).type != (type_)) { return ret_; }
|
||||||
#define CGLTF_CHECK_KEY(tok_) if ((tok_).type != JSMN_STRING || (tok_).size == 0) { return CGLTF_ERROR_JSON; } /* checking size for 0 verifies that a value follows the key */
|
#define CGLTF_CHECK_KEY(tok_) if ((tok_).type != JSMN_STRING || (tok_).size == 0) { return CGLTF_ERROR_JSON; } /* checking size for 0 verifies that a value follows the key */
|
||||||
|
|
||||||
#define CGLTF_PTRINDEX(type, idx) (type*)((cgltf_size)idx + 1)
|
#define CGLTF_PTRINDEX(type, idx) (type*)((cgltf_size)idx + 1)
|
||||||
|
@ -2623,12 +2665,13 @@ static int cgltf_json_to_int(jsmntok_t const* tok, const uint8_t* json_chunk)
|
||||||
|
|
||||||
static cgltf_size cgltf_json_to_size(jsmntok_t const* tok, const uint8_t* json_chunk)
|
static cgltf_size cgltf_json_to_size(jsmntok_t const* tok, const uint8_t* json_chunk)
|
||||||
{
|
{
|
||||||
CGLTF_CHECK_TOKTYPE_RETTYPE(*tok, JSMN_PRIMITIVE, cgltf_size);
|
CGLTF_CHECK_TOKTYPE_RET(*tok, JSMN_PRIMITIVE, 0);
|
||||||
char tmp[128];
|
char tmp[128];
|
||||||
int size = (size_t)(tok->end - tok->start) < sizeof(tmp) ? (int)(tok->end - tok->start) : (int)(sizeof(tmp) - 1);
|
int size = (size_t)(tok->end - tok->start) < sizeof(tmp) ? (int)(tok->end - tok->start) : (int)(sizeof(tmp) - 1);
|
||||||
strncpy(tmp, (const char*)json_chunk + tok->start, size);
|
strncpy(tmp, (const char*)json_chunk + tok->start, size);
|
||||||
tmp[size] = 0;
|
tmp[size] = 0;
|
||||||
return (cgltf_size)CGLTF_ATOLL(tmp);
|
long long res = CGLTF_ATOLL(tmp);
|
||||||
|
return res < 0 ? 0 : (cgltf_size)res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cgltf_float cgltf_json_to_float(jsmntok_t const* tok, const uint8_t* json_chunk)
|
static cgltf_float cgltf_json_to_float(jsmntok_t const* tok, const uint8_t* json_chunk)
|
||||||
|
@ -2810,6 +2853,11 @@ static void cgltf_parse_attribute_type(const char* name, cgltf_attribute_type* o
|
||||||
if (us && *out_type != cgltf_attribute_type_invalid)
|
if (us && *out_type != cgltf_attribute_type_invalid)
|
||||||
{
|
{
|
||||||
*out_index = CGLTF_ATOI(us + 1);
|
*out_index = CGLTF_ATOI(us + 1);
|
||||||
|
if (*out_index < 0)
|
||||||
|
{
|
||||||
|
*out_type = cgltf_attribute_type_invalid;
|
||||||
|
*out_index = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3142,6 +3190,31 @@ static int cgltf_parse_json_material_mappings(cgltf_options* options, jsmntok_t
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cgltf_primitive_type cgltf_json_to_primitive_type(jsmntok_t const* tok, const uint8_t* json_chunk)
|
||||||
|
{
|
||||||
|
int type = cgltf_json_to_int(tok, json_chunk);
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return cgltf_primitive_type_points;
|
||||||
|
case 1:
|
||||||
|
return cgltf_primitive_type_lines;
|
||||||
|
case 2:
|
||||||
|
return cgltf_primitive_type_line_loop;
|
||||||
|
case 3:
|
||||||
|
return cgltf_primitive_type_line_strip;
|
||||||
|
case 4:
|
||||||
|
return cgltf_primitive_type_triangles;
|
||||||
|
case 5:
|
||||||
|
return cgltf_primitive_type_triangle_strip;
|
||||||
|
case 6:
|
||||||
|
return cgltf_primitive_type_triangle_fan;
|
||||||
|
default:
|
||||||
|
return cgltf_primitive_type_invalid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int cgltf_parse_json_primitive(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_primitive* out_prim)
|
static int cgltf_parse_json_primitive(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_primitive* out_prim)
|
||||||
{
|
{
|
||||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||||
|
@ -3158,9 +3231,7 @@ static int cgltf_parse_json_primitive(cgltf_options* options, jsmntok_t const* t
|
||||||
if (cgltf_json_strcmp(tokens+i, json_chunk, "mode") == 0)
|
if (cgltf_json_strcmp(tokens+i, json_chunk, "mode") == 0)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
out_prim->type
|
out_prim->type = cgltf_json_to_primitive_type(tokens+i, json_chunk);
|
||||||
= (cgltf_primitive_type)
|
|
||||||
cgltf_json_to_int(tokens+i, json_chunk);
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "indices") == 0)
|
else if (cgltf_json_strcmp(tokens+i, json_chunk, "indices") == 0)
|
||||||
|
@ -3410,7 +3481,7 @@ static int cgltf_parse_json_accessor_sparse(jsmntok_t const* tokens, int i, cons
|
||||||
if (cgltf_json_strcmp(tokens+i, json_chunk, "count") == 0)
|
if (cgltf_json_strcmp(tokens+i, json_chunk, "count") == 0)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
out_sparse->count = cgltf_json_to_int(tokens + i, json_chunk);
|
out_sparse->count = cgltf_json_to_size(tokens + i, json_chunk);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "indices") == 0)
|
else if (cgltf_json_strcmp(tokens+i, json_chunk, "indices") == 0)
|
||||||
|
@ -3546,8 +3617,7 @@ static int cgltf_parse_json_accessor(cgltf_options* options, jsmntok_t const* to
|
||||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "count") == 0)
|
else if (cgltf_json_strcmp(tokens+i, json_chunk, "count") == 0)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
out_accessor->count =
|
out_accessor->count = cgltf_json_to_size(tokens+i, json_chunk);
|
||||||
cgltf_json_to_int(tokens+i, json_chunk);
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "type") == 0)
|
else if (cgltf_json_strcmp(tokens+i, json_chunk, "type") == 0)
|
||||||
|
@ -4234,6 +4304,37 @@ static int cgltf_parse_json_anisotropy(cgltf_options* options, jsmntok_t const*
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cgltf_parse_json_dispersion(jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_dispersion* out_dispersion)
|
||||||
|
{
|
||||||
|
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||||
|
int size = tokens[i].size;
|
||||||
|
++i;
|
||||||
|
|
||||||
|
|
||||||
|
for (int j = 0; j < size; ++j)
|
||||||
|
{
|
||||||
|
CGLTF_CHECK_KEY(tokens[i]);
|
||||||
|
|
||||||
|
if (cgltf_json_strcmp(tokens + i, json_chunk, "dispersion") == 0)
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
out_dispersion->dispersion = cgltf_json_to_float(tokens + i, json_chunk);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i = cgltf_skip_json(tokens, i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < 0)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
static int cgltf_parse_json_image(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_image* out_image)
|
static int cgltf_parse_json_image(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_image* out_image)
|
||||||
{
|
{
|
||||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||||
|
@ -4627,6 +4728,11 @@ static int cgltf_parse_json_material(cgltf_options* options, jsmntok_t const* to
|
||||||
out_material->has_anisotropy = 1;
|
out_material->has_anisotropy = 1;
|
||||||
i = cgltf_parse_json_anisotropy(options, tokens, i + 1, json_chunk, &out_material->anisotropy);
|
i = cgltf_parse_json_anisotropy(options, tokens, i + 1, json_chunk, &out_material->anisotropy);
|
||||||
}
|
}
|
||||||
|
else if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_materials_dispersion") == 0)
|
||||||
|
{
|
||||||
|
out_material->has_dispersion = 1;
|
||||||
|
i = cgltf_parse_json_dispersion(tokens, i + 1, json_chunk, &out_material->dispersion);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_material->extensions[out_material->extensions_count++]));
|
i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_material->extensions[out_material->extensions_count++]));
|
||||||
|
@ -4786,7 +4892,7 @@ static int cgltf_parse_json_meshopt_compression(cgltf_options* options, jsmntok_
|
||||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "count") == 0)
|
else if (cgltf_json_strcmp(tokens+i, json_chunk, "count") == 0)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
out_meshopt_compression->count = cgltf_json_to_int(tokens+i, json_chunk);
|
out_meshopt_compression->count = cgltf_json_to_size(tokens+i, json_chunk);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "mode") == 0)
|
else if (cgltf_json_strcmp(tokens+i, json_chunk, "mode") == 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue