Update cgltf.
This commit is contained in:
Vendored
+19
-13
@@ -35,8 +35,8 @@
|
||||
* variable.
|
||||
*
|
||||
* `cgltf_result cgltf_load_buffers(const cgltf_options*, cgltf_data*,
|
||||
* const char* base_path)` can be optionally called to open and read buffer
|
||||
* files using the `FILE*` APIs. The specified base_path is the the path to
|
||||
* const char* gltf_path)` can be optionally called to open and read buffer
|
||||
* files using the `FILE*` APIs. The `gltf_path` argument is the path to
|
||||
* the original glTF file, which allows the parser to resolve the path to
|
||||
* buffer files.
|
||||
*
|
||||
@@ -522,7 +522,7 @@ cgltf_result cgltf_parse_file(
|
||||
cgltf_result cgltf_load_buffers(
|
||||
const cgltf_options* options,
|
||||
cgltf_data* data,
|
||||
const char* base_path);
|
||||
const char* gltf_path);
|
||||
|
||||
|
||||
cgltf_result cgltf_load_buffer_base64(const cgltf_options* options, cgltf_size size, const char* base64, void** out_data);
|
||||
@@ -614,11 +614,13 @@ static const uint32_t GlbMagicBinChunk = 0x004E4942;
|
||||
|
||||
static void* cgltf_default_alloc(void* user, cgltf_size size)
|
||||
{
|
||||
(void)user;
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void cgltf_default_free(void* user, void* ptr)
|
||||
{
|
||||
(void)user;
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
@@ -848,18 +850,18 @@ static void cgltf_combine_paths(char* path, const char* base, const char* uri)
|
||||
}
|
||||
}
|
||||
|
||||
static cgltf_result cgltf_load_buffer_file(const cgltf_options* options, cgltf_size size, const char* uri, const char* base_path, void** out_data)
|
||||
static cgltf_result cgltf_load_buffer_file(const cgltf_options* options, cgltf_size size, const char* uri, const char* gltf_path, void** out_data)
|
||||
{
|
||||
void* (*memory_alloc)(void*, cgltf_size) = options->memory_alloc ? options->memory_alloc : &cgltf_default_alloc;
|
||||
void (*memory_free)(void*, void*) = options->memory_free ? options->memory_free : &cgltf_default_free;
|
||||
|
||||
char* path = (char*)memory_alloc(options->memory_user_data, strlen(uri) + strlen(base_path) + 1);
|
||||
char* path = (char*)memory_alloc(options->memory_user_data, strlen(uri) + strlen(gltf_path) + 1);
|
||||
if (!path)
|
||||
{
|
||||
return cgltf_result_out_of_memory;
|
||||
}
|
||||
|
||||
cgltf_combine_paths(path, base_path, uri);
|
||||
cgltf_combine_paths(path, gltf_path, uri);
|
||||
|
||||
FILE* file = fopen(path, "rb");
|
||||
|
||||
@@ -939,7 +941,7 @@ cgltf_result cgltf_load_buffer_base64(const cgltf_options* options, cgltf_size s
|
||||
return cgltf_result_success;
|
||||
}
|
||||
|
||||
cgltf_result cgltf_load_buffers(const cgltf_options* options, cgltf_data* data, const char* base_path)
|
||||
cgltf_result cgltf_load_buffers(const cgltf_options* options, cgltf_data* data, const char* gltf_path)
|
||||
{
|
||||
if (options == NULL)
|
||||
{
|
||||
@@ -990,7 +992,7 @@ cgltf_result cgltf_load_buffers(const cgltf_options* options, cgltf_data* data,
|
||||
}
|
||||
else if (strstr(uri, "://") == NULL)
|
||||
{
|
||||
cgltf_result res = cgltf_load_buffer_file(options, data->buffers[i].size, uri, base_path, &data->buffers[i].data);
|
||||
cgltf_result res = cgltf_load_buffer_file(options, data->buffers[i].size, uri, gltf_path, &data->buffers[i].data);
|
||||
|
||||
if (res != cgltf_result_success)
|
||||
{
|
||||
@@ -1412,7 +1414,7 @@ static cgltf_size cgltf_component_read_index(const void* in, cgltf_component_typ
|
||||
case cgltf_component_type_r_32u:
|
||||
return *((const uint32_t*) in);
|
||||
case cgltf_component_type_r_32f:
|
||||
return *((const float*) in);
|
||||
return (cgltf_size)*((const float*) in);
|
||||
case cgltf_component_type_r_8:
|
||||
return *((const int8_t*) in);
|
||||
case cgltf_component_type_r_8u:
|
||||
@@ -1448,7 +1450,7 @@ static cgltf_float cgltf_component_read_float(const void* in, cgltf_component_ty
|
||||
}
|
||||
}
|
||||
|
||||
return cgltf_component_read_index(in, component_type);
|
||||
return (cgltf_float)cgltf_component_read_index(in, component_type);
|
||||
}
|
||||
|
||||
static cgltf_size cgltf_num_components(cgltf_type type);
|
||||
@@ -1665,6 +1667,7 @@ static int cgltf_parse_json_string(cgltf_options* options, jsmntok_t const* toke
|
||||
|
||||
static 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)
|
||||
{
|
||||
(void)json_chunk;
|
||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_ARRAY);
|
||||
if (*out_array)
|
||||
{
|
||||
@@ -1823,9 +1826,9 @@ static int cgltf_parse_json_primitive(cgltf_options* options, jsmntok_t const* t
|
||||
return i;
|
||||
}
|
||||
|
||||
for (cgltf_size j = 0; j < out_prim->targets_count; ++j)
|
||||
for (cgltf_size k = 0; k < out_prim->targets_count; ++k)
|
||||
{
|
||||
i = cgltf_parse_json_attribute_list(options, tokens, i, json_chunk, &out_prim->targets[j].attributes, &out_prim->targets[j].attributes_count);
|
||||
i = cgltf_parse_json_attribute_list(options, tokens, i, json_chunk, &out_prim->targets[k].attributes, &out_prim->targets[k].attributes_count);
|
||||
if (i < 0)
|
||||
{
|
||||
return i;
|
||||
@@ -2442,6 +2445,7 @@ static int cgltf_parse_json_image(cgltf_options* options, jsmntok_t const* token
|
||||
|
||||
static int cgltf_parse_json_sampler(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_sampler* out_sampler)
|
||||
{
|
||||
(void)options;
|
||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||
|
||||
out_sampler->wrap_s = 10497;
|
||||
@@ -3500,6 +3504,7 @@ static int cgltf_parse_json_scenes(cgltf_options* options, jsmntok_t const* toke
|
||||
|
||||
static int cgltf_parse_json_animation_sampler(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_animation_sampler* out_sampler)
|
||||
{
|
||||
(void)options;
|
||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||
|
||||
int size = tokens[i].size;
|
||||
@@ -3554,6 +3559,7 @@ static int cgltf_parse_json_animation_sampler(cgltf_options* options, jsmntok_t
|
||||
|
||||
static int cgltf_parse_json_animation_channel(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_animation_channel* out_channel)
|
||||
{
|
||||
(void)options;
|
||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||
|
||||
int size = tokens[i].size;
|
||||
@@ -3962,7 +3968,7 @@ static int cgltf_parse_json_root(cgltf_options* options, jsmntok_t const* tokens
|
||||
|
||||
cgltf_result cgltf_parse_json(cgltf_options* options, const uint8_t* json_chunk, cgltf_size size, cgltf_data** out_data)
|
||||
{
|
||||
jsmn_parser parser = { 0 };
|
||||
jsmn_parser parser = { 0, 0, 0 };
|
||||
|
||||
if (options->json_token_count == 0)
|
||||
{
|
||||
|
||||
Vendored
+15
-2
@@ -56,6 +56,9 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
|
||||
#ifdef CGLTF_WRITE_IMPLEMENTATION
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM (1 << 0)
|
||||
#define CGLTF_EXTENSION_FLAG_MATERIALS_UNLIT (1 << 1)
|
||||
@@ -181,8 +184,18 @@ static void cgltf_write_floatprop(cgltf_write_context* context, const char* labe
|
||||
if (val != def)
|
||||
{
|
||||
cgltf_write_indent(context);
|
||||
CGLTF_SPRINTF("\"%s\": %g", label, val);
|
||||
CGLTF_SPRINTF("\"%s\": ", label);
|
||||
CGLTF_SPRINTF("%g", val);
|
||||
context->needs_comma = 1;
|
||||
|
||||
if (context->cursor)
|
||||
{
|
||||
char *decimal_comma = strchr(context->cursor - context->tmp, ',');
|
||||
if (decimal_comma)
|
||||
{
|
||||
*decimal_comma = '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,7 +829,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
|
||||
|
||||
/* cgltf is distributed under MIT license:
|
||||
*
|
||||
* Copyright (c) 2018 Johannes Kuhlmann
|
||||
* Copyright (c) 2019 Philip Rideout
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
Reference in New Issue
Block a user