diff options
Diffstat (limited to '3rdparty/bgfx/3rdparty/cgltf/cgltf_write.h')
-rw-r--r-- | 3rdparty/bgfx/3rdparty/cgltf/cgltf_write.h | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/3rdparty/bgfx/3rdparty/cgltf/cgltf_write.h b/3rdparty/bgfx/3rdparty/cgltf/cgltf_write.h index 50a9d8064af..8b96eb2b664 100644 --- a/3rdparty/bgfx/3rdparty/cgltf/cgltf_write.h +++ b/3rdparty/bgfx/3rdparty/cgltf/cgltf_write.h @@ -1,7 +1,7 @@ /** * cgltf_write - a single-file glTF 2.0 writer written in C99. * - * Version: 1.10 + * Version: 1.11 * * Website: https://github.com/jkuhlmann/cgltf * @@ -64,6 +64,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si #ifdef CGLTF_WRITE_IMPLEMENTATION +#include <assert.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> @@ -109,6 +110,7 @@ typedef struct { #endif #define CGLTF_SPRINTF(...) { \ + assert(context->cursor || (!context->cursor && context->remaining == 0)); \ context->tmp = snprintf ( context->cursor, context->remaining, __VA_ARGS__ ); \ context->chars_written += context->tmp; \ if (context->cursor) { \ @@ -117,6 +119,7 @@ typedef struct { } } #define CGLTF_SNPRINTF(length, ...) { \ + assert(context->cursor || (!context->cursor && context->remaining == 0)); \ context->tmp = snprintf ( context->cursor, CGLTF_MIN(length + 1, context->remaining), __VA_ARGS__ ); \ context->chars_written += length; \ if (context->cursor) { \ @@ -230,6 +233,16 @@ static void cgltf_write_intprop(cgltf_write_context* context, const char* label, } } +static void cgltf_write_sizeprop(cgltf_write_context* context, const char* label, cgltf_size val, cgltf_size def) +{ + if (val != def) + { + cgltf_write_indent(context); + CGLTF_SPRINTF("\"%s\": %zu", label, val); + context->needs_comma = 1; + } +} + static void cgltf_write_floatprop(cgltf_write_context* context, const char* label, float val, float def) { if (val != def) @@ -378,7 +391,10 @@ static void cgltf_write_texture_transform(cgltf_write_context* context, const cg { cgltf_write_floatarrayprop(context, "scale", transform->scale, 2); } - cgltf_write_intprop(context, "texCoord", transform->texcoord, 0); + if (transform->has_texcoord) + { + cgltf_write_intprop(context, "texCoord", transform->texcoord, -1); + } cgltf_write_line(context, "}"); cgltf_write_line(context, "}"); } @@ -501,9 +517,9 @@ static void cgltf_write_buffer_view(cgltf_write_context* context, const cgltf_bu cgltf_write_line(context, "{"); cgltf_write_strprop(context, "name", view->name); CGLTF_WRITE_IDXPROP("buffer", view->buffer, context->data->buffers); - cgltf_write_intprop(context, "byteLength", (int)view->size, -1); - cgltf_write_intprop(context, "byteOffset", (int)view->offset, 0); - cgltf_write_intprop(context, "byteStride", (int)view->stride, 0); + cgltf_write_sizeprop(context, "byteLength", view->size, (cgltf_size)-1); + cgltf_write_sizeprop(context, "byteOffset", view->offset, 0); + cgltf_write_sizeprop(context, "byteStride", view->stride, 0); // NOTE: We skip writing "target" because the spec says its usage can be inferred. cgltf_write_extras(context, &view->extras); cgltf_write_line(context, "}"); @@ -515,7 +531,7 @@ static void cgltf_write_buffer(cgltf_write_context* context, const cgltf_buffer* cgltf_write_line(context, "{"); cgltf_write_strprop(context, "name", buffer->name); cgltf_write_strprop(context, "uri", buffer->uri); - cgltf_write_intprop(context, "byteLength", (int)buffer->size, -1); + cgltf_write_sizeprop(context, "byteLength", buffer->size, (cgltf_size)-1); cgltf_write_extras(context, &buffer->extras); cgltf_write_line(context, "}"); } @@ -524,7 +540,10 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater { cgltf_write_line(context, "{"); cgltf_write_strprop(context, "name", material->name); - cgltf_write_floatprop(context, "alphaCutoff", material->alpha_cutoff, 0.5f); + if (material->alpha_mode == cgltf_alpha_mode_mask) + { + cgltf_write_floatprop(context, "alphaCutoff", material->alpha_cutoff, 0.5f); + } cgltf_write_boolprop_optional(context, "doubleSided", material->double_sided, false); // cgltf_write_boolprop_optional(context, "unlit", material->unlit, false); @@ -663,7 +682,7 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater CGLTF_WRITE_TEXTURE_INFO("specularGlossinessTexture", params->specular_glossiness_texture); if (cgltf_check_floatarray(params->diffuse_factor, 4, 1.0f)) { - cgltf_write_floatarrayprop(context, "dffuseFactor", params->diffuse_factor, 4); + cgltf_write_floatarrayprop(context, "diffuseFactor", params->diffuse_factor, 4); } if (cgltf_check_floatarray(params->specular_factor, 3, 1.0f)) { @@ -907,7 +926,7 @@ static void cgltf_write_accessor(cgltf_write_context* context, const cgltf_acces cgltf_write_strprop(context, "type", cgltf_str_from_type(accessor->type)); cgltf_size dim = cgltf_dim_from_type(accessor->type); cgltf_write_boolprop_optional(context, "normalized", accessor->normalized, false); - cgltf_write_intprop(context, "byteOffset", (int)accessor->offset, 0); + cgltf_write_sizeprop(context, "byteOffset", (int)accessor->offset, 0); cgltf_write_intprop(context, "count", (int)accessor->count, -1); if (accessor->has_min) { @@ -922,13 +941,13 @@ static void cgltf_write_accessor(cgltf_write_context* context, const cgltf_acces cgltf_write_line(context, "\"sparse\": {"); cgltf_write_intprop(context, "count", (int)accessor->sparse.count, 0); cgltf_write_line(context, "\"indices\": {"); - cgltf_write_intprop(context, "byteOffset", (int)accessor->sparse.indices_byte_offset, 0); + cgltf_write_sizeprop(context, "byteOffset", (int)accessor->sparse.indices_byte_offset, 0); CGLTF_WRITE_IDXPROP("bufferView", accessor->sparse.indices_buffer_view, context->data->buffer_views); cgltf_write_intprop(context, "componentType", cgltf_int_from_component_type(accessor->sparse.indices_component_type), 0); cgltf_write_extras(context, &accessor->sparse.indices_extras); cgltf_write_line(context, "}"); cgltf_write_line(context, "\"values\": {"); - cgltf_write_intprop(context, "byteOffset", (int)accessor->sparse.values_byte_offset, 0); + cgltf_write_sizeprop(context, "byteOffset", (int)accessor->sparse.values_byte_offset, 0); CGLTF_WRITE_IDXPROP("bufferView", accessor->sparse.values_buffer_view, context->data->buffer_views); cgltf_write_extras(context, &accessor->sparse.values_extras); cgltf_write_line(context, "}"); @@ -1292,7 +1311,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si /* cgltf is distributed under MIT license: * - * Copyright (c) 2019 Philip Rideout + * Copyright (c) 2019-2021 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 |