30#ifndef CGLTF_WRITE_H_INCLUDED__
31#define CGLTF_WRITE_H_INCLUDED__
58#if defined(__INTELLISENSE__) || defined(__JETBRAINS_IDE__)
60#define CGLTF_WRITE_IMPLEMENTATION
63#ifdef CGLTF_WRITE_IMPLEMENTATION
72#define CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM (1 << 0)
73#define CGLTF_EXTENSION_FLAG_MATERIALS_UNLIT (1 << 1)
74#define CGLTF_EXTENSION_FLAG_SPECULAR_GLOSSINESS (1 << 2)
75#define CGLTF_EXTENSION_FLAG_LIGHTS_PUNCTUAL (1 << 3)
76#define CGLTF_EXTENSION_FLAG_DRACO_MESH_COMPRESSION (1 << 4)
77#define CGLTF_EXTENSION_FLAG_MATERIALS_CLEARCOAT (1 << 5)
78#define CGLTF_EXTENSION_FLAG_MATERIALS_IOR (1 << 6)
79#define CGLTF_EXTENSION_FLAG_MATERIALS_SPECULAR (1 << 7)
80#define CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION (1 << 8)
81#define CGLTF_EXTENSION_FLAG_MATERIALS_SHEEN (1 << 9)
82#define CGLTF_EXTENSION_FLAG_MATERIALS_VARIANTS (1 << 10)
83#define CGLTF_EXTENSION_FLAG_MATERIALS_VOLUME (1 << 11)
84#define CGLTF_EXTENSION_FLAG_TEXTURE_BASISU (1 << 12)
85#define CGLTF_EXTENSION_FLAG_MATERIALS_EMISSIVE_STRENGTH (1 << 13)
86#define CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING (1 << 14)
87#define CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE (1 << 15)
88#define CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY (1 << 16)
89#define CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION (1 << 17)
90#define CGLTF_EXTENSION_FLAG_TEXTURE_WEBP (1 << 18)
91#define CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION (1 << 19)
92#define CGLTF_EXTENSION_FLAG_MATERIALS_SUBSURFACE (1 << 20)
93#define CGLTF_EXTENSION_FLAG_CAMERA_LENS (1 << 21)
106 uint32_t extension_flags;
107 uint32_t required_extension_flags;
108} cgltf_write_context;
110#define CGLTF_MIN(a, b) (a < b ? a : b)
112#ifdef FLT_DECIMAL_DIG
114 #define CGLTF_DECIMAL_DIG (FLT_DECIMAL_DIG)
116 #define CGLTF_DECIMAL_DIG 9
119#define CGLTF_SPRINTF(...) { \
120 assert(context->cursor || (!context->cursor && context->remaining == 0)); \
121 context->tmp = snprintf ( context->cursor, context->remaining, __VA_ARGS__ ); \
122 context->chars_written += context->tmp; \
123 if (context->cursor) { \
124 context->cursor += context->tmp; \
125 context->remaining -= context->tmp; \
128#define CGLTF_SNPRINTF(length, ...) { \
129 assert(context->cursor || (!context->cursor && context->remaining == 0)); \
130 context->tmp = snprintf ( context->cursor, CGLTF_MIN(length + 1, context->remaining), __VA_ARGS__ ); \
131 context->chars_written += length; \
132 if (context->cursor) { \
133 context->cursor += length; \
134 context->remaining -= length; \
137#define CGLTF_WRITE_IDXPROP(label, val, start) if (val) { \
138 cgltf_write_indent(context); \
139 CGLTF_SPRINTF("\"%s\": %d", label, (int) (val - start)); \
140 context->needs_comma = 1; }
142#define CGLTF_WRITE_IDXARRPROP(label, dim, vals, start) if (vals) { \
143 cgltf_write_indent(context); \
144 CGLTF_SPRINTF("\"%s\": [", label); \
145 for (int i = 0; i < (int)(dim); ++i) { \
146 int idx = (int) (vals[i] - start); \
147 if (i != 0) CGLTF_SPRINTF(","); \
148 CGLTF_SPRINTF(" %d", idx); \
150 CGLTF_SPRINTF(" ]"); \
151 context->needs_comma = 1; }
153#define CGLTF_WRITE_TEXTURE_INFO(label, info) if (info.texture) { \
154 cgltf_write_line(context, "\"" label "\": {"); \
155 CGLTF_WRITE_IDXPROP("index", info.texture, context->data->textures); \
156 cgltf_write_intprop(context, "texCoord", info.texcoord, 0); \
157 if (info.has_transform) { \
158 context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
159 cgltf_write_texture_transform(context, &info.transform); \
161 cgltf_write_line(context, "}"); }
163#define CGLTF_WRITE_NORMAL_TEXTURE_INFO(label, info) if (info.texture) { \
164 cgltf_write_line(context, "\"" label "\": {"); \
165 CGLTF_WRITE_IDXPROP("index", info.texture, context->data->textures); \
166 cgltf_write_intprop(context, "texCoord", info.texcoord, 0); \
167 cgltf_write_floatprop(context, "scale", info.scale, 1.0f); \
168 if (info.has_transform) { \
169 context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
170 cgltf_write_texture_transform(context, &info.transform); \
172 cgltf_write_line(context, "}"); }
174#define CGLTF_WRITE_OCCLUSION_TEXTURE_INFO(label, info) if (info.texture) { \
175 cgltf_write_line(context, "\"" label "\": {"); \
176 CGLTF_WRITE_IDXPROP("index", info.texture, context->data->textures); \
177 cgltf_write_intprop(context, "texCoord", info.texcoord, 0); \
178 cgltf_write_floatprop(context, "strength", info.scale, 1.0f); \
179 if (info.has_transform) { \
180 context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
181 cgltf_write_texture_transform(context, &info.transform); \
183 cgltf_write_line(context, "}"); }
186#define GlbHeaderSize 12
187#define GlbChunkHeaderSize 8
188static const uint32_t GlbVersion = 2;
189static const uint32_t GlbMagic = 0x46546C67;
190static const uint32_t GlbMagicJsonChunk = 0x4E4F534A;
191static const uint32_t GlbMagicBinChunk = 0x004E4942;
195static void cgltf_write_indent(cgltf_write_context* context)
197 if (context->needs_comma)
199 CGLTF_SPRINTF(
",\n");
200 context->needs_comma = 0;
206 for (
int i = 0; i < context->depth; ++i)
208 CGLTF_SPRINTF(
"%s", context->indent);
212static void cgltf_write_line(cgltf_write_context* context,
const char* line)
214 if (line[0] ==
']' || line[0] ==
'}')
217 context->needs_comma = 0;
219 cgltf_write_indent(context);
220 CGLTF_SPRINTF(
"%s", line);
222 if (line[0] ==
']' || line[0] ==
'}')
224 context->needs_comma = 1;
226 if (line[last] ==
'[' || line[last] ==
'{')
229 context->needs_comma = 0;
233static void cgltf_write_strprop(cgltf_write_context* context,
const char* label,
const char* val)
237 cgltf_write_indent(context);
238 CGLTF_SPRINTF(
"\"%s\": \"%s\"", label, val);
239 context->needs_comma = 1;
243static void cgltf_write_extras(cgltf_write_context* context,
const cgltf_extras* extras)
247 cgltf_write_indent(context);
248 CGLTF_SPRINTF(
"\"extras\": %s", extras->
data);
249 context->needs_comma = 1;
254 if (length > 0 && context->data->json)
256 char* json_string = ((
char*) context->data->json) + extras->
start_offset;
257 cgltf_write_indent(context);
258 CGLTF_SPRINTF(
"%s",
"\"extras\": ");
260 context->needs_comma = 1;
265static void cgltf_write_stritem(cgltf_write_context* context,
const char* item)
267 cgltf_write_indent(context);
268 CGLTF_SPRINTF(
"\"%s\"", item);
269 context->needs_comma = 1;
272static void cgltf_write_intprop(cgltf_write_context* context,
const char* label,
int val,
int def)
276 cgltf_write_indent(context);
277 CGLTF_SPRINTF(
"\"%s\": %d", label, val);
278 context->needs_comma = 1;
282static void cgltf_write_sizeprop(cgltf_write_context* context,
const char* label,
cgltf_size val,
cgltf_size def)
286 cgltf_write_indent(context);
287 CGLTF_SPRINTF(
"\"%s\": %zu", label, val);
288 context->needs_comma = 1;
292static void cgltf_write_floatprop(cgltf_write_context* context,
const char* label,
float val,
float def)
296 cgltf_write_indent(context);
297 CGLTF_SPRINTF(
"\"%s\": ", label);
298 CGLTF_SPRINTF(
"%.*g", CGLTF_DECIMAL_DIG, val);
299 context->needs_comma = 1;
303 char *decimal_comma = strchr(context->cursor - context->tmp,
',');
306 *decimal_comma =
'.';
312static void cgltf_write_boolprop_optional(cgltf_write_context* context,
const char* label,
bool val,
bool def)
316 cgltf_write_indent(context);
317 CGLTF_SPRINTF(
"\"%s\": %s", label, val ?
"true" :
"false");
318 context->needs_comma = 1;
322static void cgltf_write_floatarrayprop(cgltf_write_context* context,
const char* label,
const cgltf_float* vals,
cgltf_size dim)
324 cgltf_write_indent(context);
325 CGLTF_SPRINTF(
"\"%s\": [", label);
330 CGLTF_SPRINTF(
", %.*g", CGLTF_DECIMAL_DIG, vals[i]);
334 CGLTF_SPRINTF(
"%.*g", CGLTF_DECIMAL_DIG, vals[i]);
338 context->needs_comma = 1;
341static bool cgltf_check_floatarray(
const float* vals,
int dim,
float val) {
344 if (vals[dim] != val)
387 default:
return NULL;
391static const char* cgltf_str_from_type(
cgltf_type type)
402 default:
return NULL;
427 default:
return NULL;
438 default:
return NULL;
442static void cgltf_write_texture_transform(cgltf_write_context* context,
const cgltf_texture_transform* transform)
444 cgltf_write_line(context,
"\"extensions\": {");
445 cgltf_write_line(context,
"\"KHR_texture_transform\": {");
446 if (cgltf_check_floatarray(transform->
offset, 2, 0.0f))
448 cgltf_write_floatarrayprop(context,
"offset", transform->
offset, 2);
450 cgltf_write_floatprop(context,
"rotation", transform->
rotation, 0.0f);
451 if (cgltf_check_floatarray(transform->
scale, 2, 1.0f))
453 cgltf_write_floatarrayprop(context,
"scale", transform->
scale, 2);
457 cgltf_write_intprop(context,
"texCoord", transform->
texcoord, -1);
459 cgltf_write_line(context,
"}");
460 cgltf_write_line(context,
"}");
463static void cgltf_write_asset(cgltf_write_context* context,
const cgltf_asset* asset)
465 cgltf_write_line(context,
"\"asset\": {");
466 cgltf_write_strprop(context,
"copyright", asset->
copyright);
467 cgltf_write_strprop(context,
"generator", asset->
generator);
468 cgltf_write_strprop(context,
"version", asset->
version);
469 cgltf_write_strprop(context,
"min_version", asset->
min_version);
470 cgltf_write_extras(context, &asset->
extras);
471 cgltf_write_line(context,
"}");
474static void cgltf_write_primitive(cgltf_write_context* context,
const cgltf_primitive* prim)
476 cgltf_write_intprop(context,
"mode", cgltf_int_from_primitive_type(prim->
type), 4);
477 CGLTF_WRITE_IDXPROP(
"indices", prim->
indices, context->data->accessors);
478 CGLTF_WRITE_IDXPROP(
"material", prim->
material, context->data->materials);
479 cgltf_write_line(context,
"\"attributes\": {");
483 CGLTF_WRITE_IDXPROP(attr->
name, attr->
data, context->data->accessors);
485 cgltf_write_line(context,
"}");
489 cgltf_write_line(context,
"\"targets\": [");
492 cgltf_write_line(context,
"{");
496 CGLTF_WRITE_IDXPROP(attr->
name, attr->
data, context->data->accessors);
498 cgltf_write_line(context,
"}");
500 cgltf_write_line(context,
"]");
502 cgltf_write_extras(context, &prim->
extras);
506 cgltf_write_line(context,
"\"extensions\": {");
510 context->extension_flags |= CGLTF_EXTENSION_FLAG_DRACO_MESH_COMPRESSION;
513 context->required_extension_flags |= CGLTF_EXTENSION_FLAG_DRACO_MESH_COMPRESSION;
516 cgltf_write_line(context,
"\"KHR_draco_mesh_compression\": {");
518 cgltf_write_line(context,
"\"attributes\": {");
522 CGLTF_WRITE_IDXPROP(attr->
name, attr->
data, context->data->accessors);
524 cgltf_write_line(context,
"}");
525 cgltf_write_line(context,
"}");
530 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_VARIANTS;
531 cgltf_write_line(context,
"\"KHR_materials_variants\": {");
532 cgltf_write_line(context,
"\"mappings\": [");
536 cgltf_write_line(context,
"{");
537 CGLTF_WRITE_IDXPROP(
"material", map->
material, context->data->materials);
539 cgltf_write_indent(context);
540 CGLTF_SPRINTF(
"\"variants\": [%d]", (
int)map->
variant);
541 context->needs_comma = 1;
543 cgltf_write_extras(context, &map->
extras);
544 cgltf_write_line(context,
"}");
546 cgltf_write_line(context,
"]");
547 cgltf_write_line(context,
"}");
550 cgltf_write_line(context,
"}");
554static void cgltf_write_mesh(cgltf_write_context* context,
const cgltf_mesh* mesh)
556 cgltf_write_line(context,
"{");
557 cgltf_write_strprop(context,
"name", mesh->
name);
559 cgltf_write_line(context,
"\"primitives\": [");
562 cgltf_write_line(context,
"{");
563 cgltf_write_primitive(context, mesh->
primitives + i);
564 cgltf_write_line(context,
"}");
566 cgltf_write_line(context,
"]");
573 cgltf_write_extras(context, &mesh->
extras);
574 cgltf_write_line(context,
"}");
577static void cgltf_write_buffer_view(cgltf_write_context* context,
const cgltf_buffer_view* view)
579 cgltf_write_line(context,
"{");
580 cgltf_write_strprop(context,
"name", view->
name);
581 CGLTF_WRITE_IDXPROP(
"buffer", view->
buffer, context->
data->buffers);
582 cgltf_write_sizeprop(context,
"byteLength", view->
size, (
cgltf_size)-1);
583 cgltf_write_sizeprop(context,
"byteOffset", view->
offset, 0);
584 cgltf_write_sizeprop(context,
"byteStride", view->
stride, 0);
586 cgltf_write_extras(context, &view->
extras);
587 cgltf_write_line(context,
"}");
591static void cgltf_write_buffer(cgltf_write_context* context,
const cgltf_buffer* buffer)
593 cgltf_write_line(context,
"{");
594 cgltf_write_strprop(context,
"name", buffer->
name);
595 cgltf_write_strprop(context,
"uri", buffer->
uri);
596 cgltf_write_sizeprop(context,
"byteLength", buffer->
size, (
cgltf_size)-1);
597 cgltf_write_extras(context, &buffer->
extras);
598 cgltf_write_line(context,
"}");
601static void cgltf_write_material(cgltf_write_context* context,
const cgltf_material* material)
603 cgltf_write_line(context,
"{");
604 cgltf_write_strprop(context,
"name", material->
name);
607 cgltf_write_floatprop(context,
"alphaCutoff", material->
alpha_cutoff, 0.5f);
609 cgltf_write_boolprop_optional(context,
"doubleSided", (
bool)material->
double_sided,
false);
614 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_UNLIT;
619 context->extension_flags |= CGLTF_EXTENSION_FLAG_SPECULAR_GLOSSINESS;
624 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_CLEARCOAT;
629 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION;
634 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_VOLUME;
639 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_IOR;
644 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_SPECULAR;
649 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_SHEEN;
654 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_EMISSIVE_STRENGTH;
659 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE;
664 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION;
669 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_SUBSURFACE;
674 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY;
679 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION;
685 cgltf_write_line(context,
"\"pbrMetallicRoughness\": {");
688 cgltf_write_floatprop(context,
"metallicFactor", params->
metallic_factor, 1.0f);
689 cgltf_write_floatprop(context,
"roughnessFactor", params->
roughness_factor, 1.0f);
692 cgltf_write_floatarrayprop(context,
"baseColorFactor", params->
base_color_factor, 4);
694 cgltf_write_line(context,
"}");
699 cgltf_write_line(context,
"\"extensions\": {");
703 cgltf_write_line(context,
"\"KHR_materials_clearcoat\": {");
707 cgltf_write_floatprop(context,
"clearcoatFactor", params->
clearcoat_factor, 0.0f);
709 cgltf_write_line(context,
"}");
714 cgltf_write_line(context,
"\"KHR_materials_ior\": {");
715 cgltf_write_floatprop(context,
"ior", params->
ior, 1.5f);
716 cgltf_write_line(context,
"}");
721 cgltf_write_line(context,
"\"KHR_materials_specular\": {");
724 cgltf_write_floatprop(context,
"specularFactor", params->
specular_factor, 1.0f);
729 cgltf_write_line(context,
"}");
734 cgltf_write_line(context,
"\"KHR_materials_transmission\": {");
737 cgltf_write_line(context,
"}");
742 cgltf_write_line(context,
"\"KHR_materials_volume\": {");
744 cgltf_write_floatprop(context,
"thicknessFactor", params->
thickness_factor, 0.0f);
747 cgltf_write_floatarrayprop(context,
"attenuationColor", params->
attenuation_color, 3);
753 cgltf_write_line(context,
"}");
758 cgltf_write_line(context,
"\"KHR_materials_sheen\": {");
763 cgltf_write_floatarrayprop(context,
"sheenColorFactor", params->
sheen_color_factor, 3);
766 cgltf_write_line(context,
"}");
771 cgltf_write_line(context,
"\"KHR_materials_pbrSpecularGlossiness\": {");
776 cgltf_write_floatarrayprop(context,
"diffuseFactor", params->
diffuse_factor, 4);
780 cgltf_write_floatarrayprop(context,
"specularFactor", params->
specular_factor, 3);
782 cgltf_write_floatprop(context,
"glossinessFactor", params->
glossiness_factor, 1.0f);
783 cgltf_write_line(context,
"}");
787 cgltf_write_line(context,
"\"KHR_materials_unlit\": {}");
791 cgltf_write_line(context,
"\"KHR_materials_emissive_strength\": {");
793 cgltf_write_floatprop(context,
"emissiveStrength", params->
emissive_strength, 1.f);
794 cgltf_write_line(context,
"}");
798 cgltf_write_line(context,
"\"KHR_materials_iridescence\": {");
802 cgltf_write_floatprop(context,
"iridescenceIor", params->
iridescence_ior, 1.3f);
806 cgltf_write_line(context,
"}");
811 cgltf_write_line(context,
"\"KHR_materials_diffuse_transmission\": {");
819 cgltf_write_line(context,
"}");
824 cgltf_write_line(context,
"\"EXT_materials_subsurface\": {");
826 cgltf_write_floatprop(context,
"subsurfaceWeight", params->
subsurface_weight, 0.f);
829 cgltf_write_floatarrayprop(context,
"subsurfaceRadius", params->
subsurface_radius, 3);
831 cgltf_write_floatprop(context,
"subsurfaceScale", params->
subsurface_scale, 0.05f);
832 cgltf_write_line(context,
"}");
836 cgltf_write_line(context,
"\"KHR_materials_anisotropy\": {");
841 cgltf_write_line(context,
"}");
845 cgltf_write_line(context,
"\"KHR_materials_dispersion\": {");
847 cgltf_write_floatprop(context,
"dispersion", params->
dispersion, 0.f);
848 cgltf_write_line(context,
"}");
850 cgltf_write_line(context,
"}");
853 CGLTF_WRITE_NORMAL_TEXTURE_INFO(
"normalTexture", material->
normal_texture);
854 CGLTF_WRITE_OCCLUSION_TEXTURE_INFO(
"occlusionTexture", material->
occlusion_texture);
858 cgltf_write_floatarrayprop(context,
"emissiveFactor", material->
emissive_factor, 3);
860 cgltf_write_strprop(context,
"alphaMode", cgltf_str_from_alpha_mode(material->
alpha_mode));
861 cgltf_write_extras(context, &material->
extras);
862 cgltf_write_line(context,
"}");
865static void cgltf_write_image(cgltf_write_context* context,
const cgltf_image* image)
867 cgltf_write_line(context,
"{");
868 cgltf_write_strprop(context,
"name", image->
name);
869 cgltf_write_strprop(context,
"uri", image->
uri);
870 CGLTF_WRITE_IDXPROP(
"bufferView", image->
buffer_view, context->
data->buffer_views);
871 cgltf_write_strprop(context,
"mimeType", image->
mime_type);
872 cgltf_write_extras(context, &image->
extras);
873 cgltf_write_line(context,
"}");
876static void cgltf_write_texture(cgltf_write_context* context,
const cgltf_texture* texture)
878 cgltf_write_line(context,
"{");
879 cgltf_write_strprop(context,
"name", texture->
name);
880 CGLTF_WRITE_IDXPROP(
"source", texture->
image, context->data->images);
881 CGLTF_WRITE_IDXPROP(
"sampler", texture->
sampler, context->data->samplers);
885 cgltf_write_line(context,
"\"extensions\": {");
888 context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_BASISU;
889 cgltf_write_line(context,
"\"KHR_texture_basisu\": {");
890 CGLTF_WRITE_IDXPROP(
"source", texture->
basisu_image, context->data->images);
891 cgltf_write_line(context,
"}");
895 context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_WEBP;
896 cgltf_write_line(context,
"\"EXT_texture_webp\": {");
897 CGLTF_WRITE_IDXPROP(
"source", texture->
webp_image, context->data->images);
898 cgltf_write_line(context,
"}");
900 cgltf_write_line(context,
"}");
902 cgltf_write_extras(context, &texture->
extras);
903 cgltf_write_line(context,
"}");
906static void cgltf_write_skin(cgltf_write_context* context,
const cgltf_skin* skin)
908 cgltf_write_line(context,
"{");
909 CGLTF_WRITE_IDXPROP(
"skeleton", skin->
skeleton, context->data->nodes);
911 CGLTF_WRITE_IDXARRPROP(
"joints", skin->
joints_count, skin->
joints, context->data->nodes);
912 cgltf_write_strprop(context,
"name", skin->
name);
913 cgltf_write_extras(context, &skin->
extras);
914 cgltf_write_line(context,
"}");
922 return "translation";
937 switch (interpolation_type)
944 return "CUBICSPLINE";
953 cgltf_write_strprop(context, label, cgltf_write_str_path_type(path_type));
956static void cgltf_write_interpolation_type(cgltf_write_context* context,
const char *label,
cgltf_interpolation_type interpolation_type)
958 cgltf_write_strprop(context, label, cgltf_write_str_interpolation_type(interpolation_type));
961static void cgltf_write_animation_sampler(cgltf_write_context* context,
const cgltf_animation_sampler* animation_sampler)
963 cgltf_write_line(context,
"{");
964 cgltf_write_interpolation_type(context,
"interpolation", animation_sampler->
interpolation);
965 CGLTF_WRITE_IDXPROP(
"input", animation_sampler->
input, context->data->accessors);
966 CGLTF_WRITE_IDXPROP(
"output", animation_sampler->
output, context->data->accessors);
967 cgltf_write_extras(context, &animation_sampler->
extras);
968 cgltf_write_line(context,
"}");
973 cgltf_write_line(context,
"{");
974 CGLTF_WRITE_IDXPROP(
"sampler", animation_channel->
sampler, animation->
samplers);
975 cgltf_write_line(context,
"\"target\": {");
976 CGLTF_WRITE_IDXPROP(
"node", animation_channel->
target_node, context->data->nodes);
977 cgltf_write_path_type(context,
"path", animation_channel->
target_path);
978 cgltf_write_line(context,
"}");
979 cgltf_write_extras(context, &animation_channel->
extras);
980 cgltf_write_line(context,
"}");
983static void cgltf_write_animation(cgltf_write_context* context,
const cgltf_animation* animation)
985 cgltf_write_line(context,
"{");
986 cgltf_write_strprop(context,
"name", animation->
name);
990 cgltf_write_line(context,
"\"samplers\": [");
993 cgltf_write_animation_sampler(context, animation->
samplers + i);
995 cgltf_write_line(context,
"]");
999 cgltf_write_line(context,
"\"channels\": [");
1002 cgltf_write_animation_channel(context, animation, animation->
channels + i);
1004 cgltf_write_line(context,
"]");
1006 cgltf_write_extras(context, &animation->
extras);
1007 cgltf_write_line(context,
"}");
1010static void cgltf_write_sampler(cgltf_write_context* context,
const cgltf_sampler* sampler)
1012 cgltf_write_line(context,
"{");
1013 cgltf_write_strprop(context,
"name", sampler->
name);
1014 cgltf_write_intprop(context,
"magFilter", sampler->
mag_filter, 0);
1015 cgltf_write_intprop(context,
"minFilter", sampler->
min_filter, 0);
1016 cgltf_write_intprop(context,
"wrapS", sampler->
wrap_s, 10497);
1017 cgltf_write_intprop(context,
"wrapT", sampler->
wrap_t, 10497);
1018 cgltf_write_extras(context, &sampler->
extras);
1019 cgltf_write_line(context,
"}");
1022static void cgltf_write_node(cgltf_write_context* context,
const cgltf_node* node)
1024 cgltf_write_line(context,
"{");
1026 CGLTF_WRITE_IDXPROP(
"mesh", node->
mesh, context->data->meshes);
1027 cgltf_write_strprop(context,
"name", node->
name);
1030 cgltf_write_floatarrayprop(context,
"matrix", node->
matrix, 16);
1034 cgltf_write_floatarrayprop(context,
"translation", node->
translation, 3);
1038 cgltf_write_floatarrayprop(context,
"rotation", node->
rotation, 4);
1042 cgltf_write_floatarrayprop(context,
"scale", node->
scale, 3);
1046 CGLTF_WRITE_IDXPROP(
"skin", node->
skin, context->data->skins);
1051 cgltf_write_line(context,
"\"extensions\": {");
1055 context->extension_flags |= CGLTF_EXTENSION_FLAG_LIGHTS_PUNCTUAL;
1056 cgltf_write_line(context,
"\"KHR_lights_punctual\": {");
1057 CGLTF_WRITE_IDXPROP(
"light", node->
light, context->data->lights);
1058 cgltf_write_line(context,
"}");
1063 context->extension_flags |= CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING;
1064 context->required_extension_flags |= CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING;
1066 cgltf_write_line(context,
"\"EXT_mesh_gpu_instancing\": {");
1068 cgltf_write_line(context,
"\"attributes\": {");
1073 CGLTF_WRITE_IDXPROP(attr->
name, attr->
data, context->data->accessors);
1076 cgltf_write_line(context,
"}");
1078 cgltf_write_line(context,
"}");
1082 cgltf_write_line(context,
"}");
1091 CGLTF_WRITE_IDXPROP(
"camera", node->
camera, context->
data->cameras);
1094 cgltf_write_extras(context, &node->
extras);
1095 cgltf_write_line(context,
"}");
1098static void cgltf_write_scene(cgltf_write_context* context,
const cgltf_scene* scene)
1100 cgltf_write_line(context,
"{");
1101 cgltf_write_strprop(context,
"name", scene->
name);
1102 CGLTF_WRITE_IDXARRPROP(
"nodes", scene->
nodes_count, scene->
nodes, context->data->nodes);
1103 cgltf_write_extras(context, &scene->
extras);
1104 cgltf_write_line(context,
"}");
1107static void cgltf_write_accessor(cgltf_write_context* context,
const cgltf_accessor* accessor)
1109 cgltf_write_line(context,
"{");
1110 cgltf_write_strprop(context,
"name", accessor->
name);
1111 CGLTF_WRITE_IDXPROP(
"bufferView", accessor->
buffer_view, context->
data->buffer_views);
1112 cgltf_write_intprop(context,
"componentType", cgltf_int_from_component_type(accessor->
component_type), 0);
1113 cgltf_write_strprop(context,
"type", cgltf_str_from_type(accessor->
type));
1115 cgltf_write_boolprop_optional(context,
"normalized", (
bool)accessor->
normalized,
false);
1116 cgltf_write_sizeprop(context,
"byteOffset", (
int)accessor->
offset, 0);
1117 cgltf_write_intprop(context,
"count", (
int)accessor->
count, -1);
1120 cgltf_write_floatarrayprop(context,
"min", accessor->
min, dim);
1124 cgltf_write_floatarrayprop(context,
"max", accessor->
max, dim);
1128 cgltf_write_line(context,
"\"sparse\": {");
1129 cgltf_write_intprop(context,
"count", (
int)accessor->
sparse.
count, 0);
1130 cgltf_write_line(context,
"\"indices\": {");
1134 cgltf_write_line(context,
"}");
1135 cgltf_write_line(context,
"\"values\": {");
1138 cgltf_write_line(context,
"}");
1139 cgltf_write_line(context,
"}");
1141 cgltf_write_extras(context, &accessor->
extras);
1142 cgltf_write_line(context,
"}");
1145static void cgltf_write_camera(cgltf_write_context* context,
const cgltf_camera* camera)
1147 cgltf_write_line(context,
"{");
1148 cgltf_write_strprop(context,
"type", cgltf_str_from_camera_type(camera->
type));
1151 cgltf_write_strprop(context,
"name", camera->
name);
1156 cgltf_write_line(context,
"\"orthographic\": {");
1162 cgltf_write_line(context,
"}");
1166 cgltf_write_line(context,
"\"perspective\": {");
1180 cgltf_write_line(context,
"}");
1184 context->extension_flags |= CGLTF_EXTENSION_FLAG_CAMERA_LENS;
1185 cgltf_write_line(context,
"\"extensions\": {");
1186 cgltf_write_line(context,
"\"EXT_camera_lens\": {");
1187 cgltf_write_floatprop(context,
"sensorSize", camera->
lens.
sensor_size, -1.0f);
1188 cgltf_write_floatprop(context,
"fStop", camera->
lens.
fstop, -1.0f);
1193 cgltf_write_line(context,
"}");
1194 cgltf_write_line(context,
"}");
1196 cgltf_write_extras(context, &camera->
extras);
1197 cgltf_write_line(context,
"}");
1200static void cgltf_write_light(cgltf_write_context* context,
const cgltf_light* light)
1202 context->extension_flags |= CGLTF_EXTENSION_FLAG_LIGHTS_PUNCTUAL;
1204 cgltf_write_line(context,
"{");
1205 cgltf_write_strprop(context,
"type", cgltf_str_from_light_type(light->
type));
1208 cgltf_write_strprop(context,
"name", light->
name);
1210 if (cgltf_check_floatarray(light->
color, 3, 1.0f))
1212 cgltf_write_floatarrayprop(context,
"color", light->
color, 3);
1214 cgltf_write_floatprop(context,
"intensity", light->
intensity, 1.0f);
1215 cgltf_write_floatprop(context,
"range", light->
range, 0.0f);
1219 cgltf_write_line(context,
"\"spot\": {");
1221 cgltf_write_floatprop(context,
"outerConeAngle", light->
spot_outer_cone_angle, 3.14159265358979323846f/4.0f);
1222 cgltf_write_line(context,
"}");
1224 cgltf_write_extras( context, &light->
extras );
1225 cgltf_write_line(context,
"}");
1230 context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_VARIANTS;
1232 cgltf_write_line(context,
"{");
1233 cgltf_write_strprop(context,
"name", variant->
name);
1234 cgltf_write_extras(context, &variant->
extras);
1235 cgltf_write_line(context,
"}");
1238static void cgltf_write_glb(FILE* file,
const void* json_buf,
const cgltf_size json_size,
const void* bin_buf,
const cgltf_size bin_size)
1240 char header[GlbHeaderSize];
1241 char chunk_header[GlbChunkHeaderSize];
1242 char json_pad[3] = { 0x20, 0x20, 0x20 };
1243 char bin_pad[3] = { 0, 0, 0 };
1245 cgltf_size json_padsize = (json_size % 4 != 0) ? 4 - json_size % 4 : 0;
1246 cgltf_size bin_padsize = (bin_size % 4 != 0) ? 4 - bin_size % 4 : 0;
1247 cgltf_size total_size = GlbHeaderSize + GlbChunkHeaderSize + json_size + json_padsize;
1248 if (bin_buf != NULL && bin_size > 0) {
1249 total_size += GlbChunkHeaderSize + bin_size + bin_padsize;
1253 memcpy(header, &GlbMagic, 4);
1254 memcpy(header + 4, &GlbVersion, 4);
1255 memcpy(header + 8, &total_size, 4);
1256 fwrite(header, 1, GlbHeaderSize, file);
1259 uint32_t json_chunk_size = (uint32_t)(json_size + json_padsize);
1260 memcpy(chunk_header, &json_chunk_size, 4);
1261 memcpy(chunk_header + 4, &GlbMagicJsonChunk, 4);
1262 fwrite(chunk_header, 1, GlbChunkHeaderSize, file);
1264 fwrite(json_buf, 1, json_size, file);
1265 fwrite(json_pad, 1, json_padsize, file);
1267 if (bin_buf != NULL && bin_size > 0) {
1269 uint32_t bin_chunk_size = (uint32_t)(bin_size + bin_padsize);
1270 memcpy(chunk_header, &bin_chunk_size, 4);
1271 memcpy(chunk_header + 4, &GlbMagicBinChunk, 4);
1272 fwrite(chunk_header, 1, GlbChunkHeaderSize, file);
1274 fwrite(bin_buf, 1, bin_size, file);
1275 fwrite(bin_pad, 1, bin_padsize, file);
1282 char* buffer = (
char*) malloc(expected);
1284 if (expected != actual) {
1285 fprintf(stderr,
"Error: expected %zu bytes but wrote %zu bytes.\n", expected, actual);
1287 FILE* file = fopen(path,
"wb");
1294 cgltf_write_glb(file, buffer, actual - 1, data->
bin, data->
bin_size);
1297 fwrite(buffer, actual - 1, 1, file);
1304static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extension_flags)
1306 if (extension_flags & CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM) {
1307 cgltf_write_stritem(context,
"KHR_texture_transform");
1309 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_UNLIT) {
1310 cgltf_write_stritem(context,
"KHR_materials_unlit");
1312 if (extension_flags & CGLTF_EXTENSION_FLAG_SPECULAR_GLOSSINESS) {
1313 cgltf_write_stritem(context,
"KHR_materials_pbrSpecularGlossiness");
1315 if (extension_flags & CGLTF_EXTENSION_FLAG_LIGHTS_PUNCTUAL) {
1316 cgltf_write_stritem(context,
"KHR_lights_punctual");
1318 if (extension_flags & CGLTF_EXTENSION_FLAG_DRACO_MESH_COMPRESSION) {
1319 cgltf_write_stritem(context,
"KHR_draco_mesh_compression");
1321 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_CLEARCOAT) {
1322 cgltf_write_stritem(context,
"KHR_materials_clearcoat");
1324 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_IOR) {
1325 cgltf_write_stritem(context,
"KHR_materials_ior");
1327 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_SPECULAR) {
1328 cgltf_write_stritem(context,
"KHR_materials_specular");
1330 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_TRANSMISSION) {
1331 cgltf_write_stritem(context,
"KHR_materials_transmission");
1333 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_SHEEN) {
1334 cgltf_write_stritem(context,
"KHR_materials_sheen");
1336 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_VARIANTS) {
1337 cgltf_write_stritem(context,
"KHR_materials_variants");
1339 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_VOLUME) {
1340 cgltf_write_stritem(context,
"KHR_materials_volume");
1342 if (extension_flags & CGLTF_EXTENSION_FLAG_TEXTURE_BASISU) {
1343 cgltf_write_stritem(context,
"KHR_texture_basisu");
1345 if (extension_flags & CGLTF_EXTENSION_FLAG_TEXTURE_WEBP) {
1346 cgltf_write_stritem(context,
"EXT_texture_webp");
1348 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_EMISSIVE_STRENGTH) {
1349 cgltf_write_stritem(context,
"KHR_materials_emissive_strength");
1351 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE) {
1352 cgltf_write_stritem(context,
"KHR_materials_iridescence");
1354 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION) {
1355 cgltf_write_stritem(context,
"KHR_materials_diffuse_transmission");
1357 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_SUBSURFACE) {
1358 cgltf_write_stritem(context,
"EXT_materials_subsurface");
1360 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY) {
1361 cgltf_write_stritem(context,
"KHR_materials_anisotropy");
1363 if (extension_flags & CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING) {
1364 cgltf_write_stritem(context,
"EXT_mesh_gpu_instancing");
1366 if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION) {
1367 cgltf_write_stritem(context,
"KHR_materials_dispersion");
1369 if (extension_flags & CGLTF_EXTENSION_FLAG_CAMERA_LENS) {
1370 cgltf_write_stritem(context,
"EXT_camera_lens");
1377 cgltf_write_context ctx;
1378 ctx.buffer = buffer;
1379 ctx.buffer_size = size;
1380 ctx.remaining = size;
1381 ctx.cursor = buffer;
1382 ctx.chars_written = 0;
1386 ctx.needs_comma = 0;
1387 ctx.extension_flags = 0;
1388 ctx.required_extension_flags = 0;
1390 cgltf_write_context* context = &ctx;
1396 cgltf_write_line(context,
"\"accessors\": [");
1399 cgltf_write_accessor(context, data->
accessors + i);
1401 cgltf_write_line(context,
"]");
1404 cgltf_write_asset(context, &data->
asset);
1408 cgltf_write_line(context,
"\"bufferViews\": [");
1411 cgltf_write_buffer_view(context, data->
buffer_views + i);
1413 cgltf_write_line(context,
"]");
1418 cgltf_write_line(context,
"\"buffers\": [");
1421 cgltf_write_buffer(context, data->
buffers + i);
1423 cgltf_write_line(context,
"]");
1428 cgltf_write_line(context,
"\"images\": [");
1431 cgltf_write_image(context, data->
images + i);
1433 cgltf_write_line(context,
"]");
1438 cgltf_write_line(context,
"\"meshes\": [");
1441 cgltf_write_mesh(context, data->
meshes + i);
1443 cgltf_write_line(context,
"]");
1448 cgltf_write_line(context,
"\"materials\": [");
1451 cgltf_write_material(context, data->
materials + i);
1453 cgltf_write_line(context,
"]");
1458 cgltf_write_line(context,
"\"nodes\": [");
1461 cgltf_write_node(context, data->
nodes + i);
1463 cgltf_write_line(context,
"]");
1468 cgltf_write_line(context,
"\"samplers\": [");
1471 cgltf_write_sampler(context, data->
samplers + i);
1473 cgltf_write_line(context,
"]");
1476 CGLTF_WRITE_IDXPROP(
"scene", data->
scene, data->
scenes);
1480 cgltf_write_line(context,
"\"scenes\": [");
1483 cgltf_write_scene(context, data->
scenes + i);
1485 cgltf_write_line(context,
"]");
1490 cgltf_write_line(context,
"\"textures\": [");
1493 cgltf_write_texture(context, data->
textures + i);
1495 cgltf_write_line(context,
"]");
1500 cgltf_write_line(context,
"\"skins\": [");
1503 cgltf_write_skin(context, data->
skins + i);
1505 cgltf_write_line(context,
"]");
1510 cgltf_write_line(context,
"\"animations\": [");
1513 cgltf_write_animation(context, data->
animations + i);
1515 cgltf_write_line(context,
"]");
1520 cgltf_write_line(context,
"\"cameras\": [");
1523 cgltf_write_camera(context, data->
cameras + i);
1525 cgltf_write_line(context,
"]");
1530 cgltf_write_line(context,
"\"extensions\": {");
1534 cgltf_write_line(context,
"\"KHR_lights_punctual\": {");
1535 cgltf_write_line(context,
"\"lights\": [");
1538 cgltf_write_light(context, data->
lights + i);
1540 cgltf_write_line(context,
"]");
1541 cgltf_write_line(context,
"}");
1546 cgltf_write_line(context,
"\"KHR_materials_variants\": {");
1547 cgltf_write_line(context,
"\"variants\": [");
1550 cgltf_write_variant(context, data->
variants + i);
1552 cgltf_write_line(context,
"]");
1553 cgltf_write_line(context,
"}");
1556 cgltf_write_line(context,
"}");
1559 if (context->extension_flags != 0)
1561 cgltf_write_line(context,
"\"extensionsUsed\": [");
1562 cgltf_write_extensions(context, context->extension_flags);
1563 cgltf_write_line(context,
"]");
1566 if (context->required_extension_flags != 0)
1568 cgltf_write_line(context,
"\"extensionsRequired\": [");
1569 cgltf_write_extensions(context, context->required_extension_flags);
1570 cgltf_write_line(context,
"]");
1573 cgltf_write_extras(context, &data->
extras);
1575 CGLTF_SPRINTF(
"\n}\n");
1579 return 1 + ctx.chars_written;
size_t cgltf_size
Definition cgltf.h:104
cgltf_animation_path_type
Definition cgltf.h:224
@ cgltf_animation_path_type_weights
Definition cgltf.h:229
@ cgltf_animation_path_type_translation
Definition cgltf.h:226
@ cgltf_animation_path_type_scale
Definition cgltf.h:228
@ cgltf_animation_path_type_rotation
Definition cgltf.h:227
cgltf_primitive_type
Definition cgltf.h:204
@ cgltf_primitive_type_line_strip
Definition cgltf.h:209
@ cgltf_primitive_type_lines
Definition cgltf.h:207
@ cgltf_primitive_type_triangles
Definition cgltf.h:210
@ cgltf_primitive_type_line_loop
Definition cgltf.h:208
@ cgltf_primitive_type_triangle_fan
Definition cgltf.h:212
@ cgltf_primitive_type_points
Definition cgltf.h:206
@ cgltf_primitive_type_triangle_strip
Definition cgltf.h:211
cgltf_interpolation_type
Definition cgltf.h:233
@ cgltf_interpolation_type_cubic_spline
Definition cgltf.h:236
@ cgltf_interpolation_type_linear
Definition cgltf.h:234
@ cgltf_interpolation_type_step
Definition cgltf.h:235
cgltf_light_type
Definition cgltf.h:247
@ cgltf_light_type_spot
Definition cgltf.h:251
@ cgltf_light_type_point
Definition cgltf.h:250
@ cgltf_light_type_directional
Definition cgltf.h:249
float cgltf_float
Definition cgltf.h:106
cgltf_type
Definition cgltf.h:191
@ cgltf_type_vec4
Definition cgltf.h:196
@ cgltf_type_mat2
Definition cgltf.h:197
@ cgltf_type_vec2
Definition cgltf.h:194
@ cgltf_type_vec3
Definition cgltf.h:195
@ cgltf_type_scalar
Definition cgltf.h:193
@ cgltf_type_mat3
Definition cgltf.h:198
@ cgltf_type_mat4
Definition cgltf.h:199
cgltf_component_type
Definition cgltf.h:179
@ cgltf_component_type_r_32f
Definition cgltf.h:186
@ cgltf_component_type_r_8
Definition cgltf.h:181
@ cgltf_component_type_r_8u
Definition cgltf.h:182
@ cgltf_component_type_r_32u
Definition cgltf.h:185
@ cgltf_component_type_r_16u
Definition cgltf.h:184
@ cgltf_component_type_r_16
Definition cgltf.h:183
cgltf_result
Definition cgltf.h:120
@ cgltf_result_success
Definition cgltf.h:121
@ cgltf_result_file_not_found
Definition cgltf.h:127
@ cgltf_file_type_glb
Definition cgltf.h:115
cgltf_camera_type
Definition cgltf.h:240
@ cgltf_camera_type_orthographic
Definition cgltf.h:243
@ cgltf_camera_type_perspective
Definition cgltf.h:242
cgltf_alpha_mode
Definition cgltf.h:217
@ cgltf_alpha_mode_mask
Definition cgltf.h:219
@ cgltf_alpha_mode_blend
Definition cgltf.h:220
cgltf_size cgltf_write(const cgltf_options *options, char *buffer, cgltf_size size, const cgltf_data *data)
cgltf_result cgltf_write_file(const cgltf_options *options, const char *path, const cgltf_data *data)
cgltf_buffer_view * indices_buffer_view
Definition cgltf.h:380
cgltf_component_type indices_component_type
Definition cgltf.h:382
cgltf_size values_byte_offset
Definition cgltf.h:384
cgltf_buffer_view * values_buffer_view
Definition cgltf.h:383
cgltf_size indices_byte_offset
Definition cgltf.h:381
cgltf_size count
Definition cgltf.h:379
char * name
Definition cgltf.h:389
cgltf_bool normalized
Definition cgltf.h:391
cgltf_extras extras
Definition cgltf.h:403
cgltf_bool is_sparse
Definition cgltf.h:401
cgltf_float max[16]
Definition cgltf.h:400
cgltf_size count
Definition cgltf.h:394
cgltf_type type
Definition cgltf.h:392
cgltf_float min[16]
Definition cgltf.h:398
cgltf_size offset
Definition cgltf.h:393
cgltf_bool has_min
Definition cgltf.h:397
cgltf_buffer_view * buffer_view
Definition cgltf.h:396
cgltf_bool has_max
Definition cgltf.h:399
cgltf_component_type component_type
Definition cgltf.h:390
cgltf_accessor_sparse sparse
Definition cgltf.h:402
cgltf_node * target_node
Definition cgltf.h:862
cgltf_extras extras
Definition cgltf.h:864
cgltf_animation_path_type target_path
Definition cgltf.h:863
cgltf_animation_sampler * sampler
Definition cgltf.h:861
cgltf_extras extras
Definition cgltf.h:855
cgltf_accessor * input
Definition cgltf.h:852
cgltf_accessor * output
Definition cgltf.h:853
cgltf_interpolation_type interpolation
Definition cgltf.h:854
cgltf_animation_sampler * samplers
Definition cgltf.h:871
cgltf_animation_channel * channels
Definition cgltf.h:873
cgltf_size channels_count
Definition cgltf.h:874
cgltf_size samplers_count
Definition cgltf.h:872
char * name
Definition cgltf.h:870
cgltf_extras extras
Definition cgltf.h:875
cgltf_texture_view anisotropy_texture
Definition cgltf.h:587
cgltf_float anisotropy_strength
Definition cgltf.h:585
cgltf_float anisotropy_rotation
Definition cgltf.h:586
cgltf_extras extras
Definition cgltf.h:891
char * version
Definition cgltf.h:889
char * min_version
Definition cgltf.h:890
char * copyright
Definition cgltf.h:887
char * generator
Definition cgltf.h:888
char * name
Definition cgltf.h:410
cgltf_accessor * data
Definition cgltf.h:413
cgltf_extras extras
Definition cgltf.h:372
cgltf_size size
Definition cgltf.h:366
cgltf_buffer * buffer
Definition cgltf.h:364
char * name
Definition cgltf.h:363
cgltf_size stride
Definition cgltf.h:367
cgltf_size offset
Definition cgltf.h:365
void * data
Definition cgltf.h:369
char * uri
Definition cgltf.h:326
char * name
Definition cgltf.h:324
cgltf_extras extras
Definition cgltf.h:329
cgltf_size size
Definition cgltf.h:325
void * data
Definition cgltf.h:327
cgltf_float sensor_size
Definition cgltf.h:741
cgltf_uint aperture_blades
Definition cgltf.h:744
cgltf_float aperture_ratio
Definition cgltf.h:746
cgltf_float aperture_rotation
Definition cgltf.h:745
cgltf_float fstop
Definition cgltf.h:742
cgltf_float focus_distance
Definition cgltf.h:743
cgltf_float znear
Definition cgltf.h:736
cgltf_float xmag
Definition cgltf.h:733
cgltf_float ymag
Definition cgltf.h:734
cgltf_float zfar
Definition cgltf.h:735
cgltf_extras extras
Definition cgltf.h:737
cgltf_float yfov
Definition cgltf.h:725
cgltf_bool has_zfar
Definition cgltf.h:726
cgltf_bool has_aspect_ratio
Definition cgltf.h:723
cgltf_float zfar
Definition cgltf.h:727
cgltf_float aspect_ratio
Definition cgltf.h:724
cgltf_float znear
Definition cgltf.h:728
cgltf_extras extras
Definition cgltf.h:729
union cgltf_camera::@0 data
cgltf_extras extras
Definition cgltf.h:758
char * name
Definition cgltf.h:750
cgltf_bool has_lens
Definition cgltf.h:756
cgltf_camera_type type
Definition cgltf.h:751
cgltf_camera_orthographic orthographic
Definition cgltf.h:754
cgltf_camera_perspective perspective
Definition cgltf.h:753
cgltf_camera_lens lens
Definition cgltf.h:757
cgltf_float clearcoat_roughness_factor
Definition cgltf.h:514
cgltf_texture_view clearcoat_roughness_texture
Definition cgltf.h:510
cgltf_texture_view clearcoat_normal_texture
Definition cgltf.h:511
cgltf_float clearcoat_factor
Definition cgltf.h:513
cgltf_texture_view clearcoat_texture
Definition cgltf.h:509
cgltf_size bin_size
Definition cgltf.h:973
cgltf_size variants_count
Definition cgltf.h:954
cgltf_scene * scenes
Definition cgltf.h:945
const void * bin
Definition cgltf.h:972
cgltf_size buffer_views_count
Definition cgltf.h:913
cgltf_asset asset
Definition cgltf.h:901
cgltf_mesh * meshes
Definition cgltf.h:903
cgltf_light * lights
Definition cgltf.h:933
cgltf_size buffers_count
Definition cgltf.h:916
cgltf_buffer_view * buffer_views
Definition cgltf.h:912
cgltf_size cameras_count
Definition cgltf.h:931
cgltf_skin * skins
Definition cgltf.h:927
cgltf_scene * scene
Definition cgltf.h:948
cgltf_size images_count
Definition cgltf.h:919
cgltf_material * materials
Definition cgltf.h:906
cgltf_sampler * samplers
Definition cgltf.h:924
cgltf_size skins_count
Definition cgltf.h:928
cgltf_size textures_count
Definition cgltf.h:922
cgltf_animation * animations
Definition cgltf.h:950
cgltf_node * nodes
Definition cgltf.h:942
cgltf_accessor * accessors
Definition cgltf.h:909
cgltf_camera * cameras
Definition cgltf.h:930
cgltf_size samplers_count
Definition cgltf.h:925
cgltf_size animations_count
Definition cgltf.h:951
cgltf_image * images
Definition cgltf.h:918
cgltf_size nodes_count
Definition cgltf.h:943
cgltf_texture * textures
Definition cgltf.h:921
cgltf_size accessors_count
Definition cgltf.h:910
cgltf_size scenes_count
Definition cgltf.h:946
cgltf_size meshes_count
Definition cgltf.h:904
cgltf_buffer * buffers
Definition cgltf.h:915
cgltf_extras extras
Definition cgltf.h:956
cgltf_size lights_count
Definition cgltf.h:934
cgltf_material_variant * variants
Definition cgltf.h:953
cgltf_size materials_count
Definition cgltf.h:907
cgltf_float diffuse_transmission_color_factor[3]
Definition cgltf.h:571
cgltf_float diffuse_transmission_factor
Definition cgltf.h:570
cgltf_texture_view diffuse_transmission_texture
Definition cgltf.h:569
cgltf_texture_view diffuse_transmission_color_texture
Definition cgltf.h:572
cgltf_float dispersion
Definition cgltf.h:592
cgltf_attribute * attributes
Definition cgltf.h:670
cgltf_size attributes_count
Definition cgltf.h:671
cgltf_buffer_view * buffer_view
Definition cgltf.h:669
cgltf_float emissive_strength
Definition cgltf.h:554
char * uri
Definition cgltf.h:419
char * mime_type
Definition cgltf.h:421
cgltf_extras extras
Definition cgltf.h:422
char * name
Definition cgltf.h:418
cgltf_buffer_view * buffer_view
Definition cgltf.h:420
cgltf_float ior
Definition cgltf.h:525
cgltf_float iridescence_thickness_max
Definition cgltf.h:563
cgltf_float iridescence_ior
Definition cgltf.h:561
cgltf_texture_view iridescence_thickness_texture
Definition cgltf.h:564
cgltf_float iridescence_thickness_min
Definition cgltf.h:562
cgltf_texture_view iridescence_texture
Definition cgltf.h:560
cgltf_float iridescence_factor
Definition cgltf.h:559
cgltf_extras extras
Definition cgltf.h:771
cgltf_float range
Definition cgltf.h:768
cgltf_float color[3]
Definition cgltf.h:765
cgltf_light_type type
Definition cgltf.h:767
cgltf_float intensity
Definition cgltf.h:766
cgltf_float spot_outer_cone_angle
Definition cgltf.h:770
char * name
Definition cgltf.h:764
cgltf_float spot_inner_cone_angle
Definition cgltf.h:769
cgltf_extras extras
Definition cgltf.h:660
cgltf_size variant
Definition cgltf.h:658
cgltf_material * material
Definition cgltf.h:659
cgltf_extras extras
Definition cgltf.h:883
char * name
Definition cgltf.h:882
cgltf_bool double_sided
Definition cgltf.h:649
cgltf_pbr_specular_glossiness pbr_specular_glossiness
Definition cgltf.h:629
char * name
Definition cgltf.h:612
cgltf_pbr_metallic_roughness pbr_metallic_roughness
Definition cgltf.h:628
cgltf_dispersion dispersion
Definition cgltf.h:641
cgltf_iridescence iridescence
Definition cgltf.h:637
cgltf_bool has_subsurface
Definition cgltf.h:624
cgltf_extras extras
Definition cgltf.h:651
cgltf_bool has_anisotropy
Definition cgltf.h:625
cgltf_sheen sheen
Definition cgltf.h:633
cgltf_bool has_sheen
Definition cgltf.h:620
cgltf_bool unlit
Definition cgltf.h:650
cgltf_bool has_diffuse_transmission
Definition cgltf.h:623
cgltf_specular specular
Definition cgltf.h:632
cgltf_float emissive_factor[3]
Definition cgltf.h:646
cgltf_emissive_strength emissive_strength
Definition cgltf.h:636
cgltf_bool has_ior
Definition cgltf.h:618
cgltf_anisotropy anisotropy
Definition cgltf.h:640
cgltf_bool has_transmission
Definition cgltf.h:616
cgltf_bool has_pbr_metallic_roughness
Definition cgltf.h:613
cgltf_bool has_iridescence
Definition cgltf.h:622
cgltf_volume volume
Definition cgltf.h:635
cgltf_bool has_volume
Definition cgltf.h:617
cgltf_texture_view emissive_texture
Definition cgltf.h:645
cgltf_bool has_emissive_strength
Definition cgltf.h:621
cgltf_diffuse_transmission diffuse_transmission
Definition cgltf.h:638
cgltf_texture_view occlusion_texture
Definition cgltf.h:644
cgltf_transmission transmission
Definition cgltf.h:634
cgltf_bool has_clearcoat
Definition cgltf.h:615
cgltf_ior ior
Definition cgltf.h:631
cgltf_alpha_mode alpha_mode
Definition cgltf.h:647
cgltf_subsurface subsurface
Definition cgltf.h:639
cgltf_clearcoat clearcoat
Definition cgltf.h:630
cgltf_bool has_pbr_specular_glossiness
Definition cgltf.h:614
cgltf_texture_view normal_texture
Definition cgltf.h:643
cgltf_float alpha_cutoff
Definition cgltf.h:648
cgltf_bool has_specular
Definition cgltf.h:619
cgltf_bool has_dispersion
Definition cgltf.h:626
cgltf_size attributes_count
Definition cgltf.h:676
cgltf_attribute * attributes
Definition cgltf.h:675
cgltf_primitive * primitives
Definition cgltf.h:698
cgltf_size primitives_count
Definition cgltf.h:699
cgltf_extras extras
Definition cgltf.h:704
cgltf_size weights_count
Definition cgltf.h:701
char * name
Definition cgltf.h:697
cgltf_float * weights
Definition cgltf.h:700
cgltf_size attributes_count
Definition cgltf.h:665
cgltf_attribute * attributes
Definition cgltf.h:664
cgltf_mesh_gpu_instancing mesh_gpu_instancing
Definition cgltf.h:835
cgltf_skin * skin
Definition cgltf.h:817
cgltf_extras extras
Definition cgltf.h:833
cgltf_size children_count
Definition cgltf.h:816
char * name
Definition cgltf.h:813
cgltf_size weights_count
Definition cgltf.h:824
cgltf_light * light
Definition cgltf.h:820
cgltf_float rotation[4]
Definition cgltf.h:830
cgltf_bool has_translation
Definition cgltf.h:825
cgltf_mesh * mesh
Definition cgltf.h:818
cgltf_node ** children
Definition cgltf.h:815
cgltf_bool has_rotation
Definition cgltf.h:826
cgltf_float matrix[16]
Definition cgltf.h:832
cgltf_bool has_matrix
Definition cgltf.h:828
cgltf_bool has_scale
Definition cgltf.h:827
cgltf_float scale[3]
Definition cgltf.h:831
cgltf_float * weights
Definition cgltf.h:823
cgltf_bool has_mesh_gpu_instancing
Definition cgltf.h:834
cgltf_camera * camera
Definition cgltf.h:819
cgltf_float translation[3]
Definition cgltf.h:829
cgltf_file_type type
Definition cgltf.h:150
cgltf_texture_view diffuse_texture
Definition cgltf.h:499
cgltf_float specular_factor[3]
Definition cgltf.h:503
cgltf_float diffuse_factor[4]
Definition cgltf.h:502
cgltf_float glossiness_factor
Definition cgltf.h:504
cgltf_texture_view specular_glossiness_texture
Definition cgltf.h:500
cgltf_draco_mesh_compression draco_mesh_compression
Definition cgltf.h:689
cgltf_size attributes_count
Definition cgltf.h:684
cgltf_size targets_count
Definition cgltf.h:686
cgltf_accessor * indices
Definition cgltf.h:681
cgltf_morph_target * targets
Definition cgltf.h:685
cgltf_bool has_draco_mesh_compression
Definition cgltf.h:688
cgltf_size mappings_count
Definition cgltf.h:691
cgltf_extras extras
Definition cgltf.h:687
cgltf_material_mapping * mappings
Definition cgltf.h:690
cgltf_attribute * attributes
Definition cgltf.h:683
cgltf_primitive_type type
Definition cgltf.h:680
cgltf_material * material
Definition cgltf.h:682
cgltf_extras extras
Definition cgltf.h:450
cgltf_wrap_mode wrap_t
Definition cgltf.h:449
cgltf_filter_type mag_filter
Definition cgltf.h:446
cgltf_wrap_mode wrap_s
Definition cgltf.h:448
char * name
Definition cgltf.h:445
cgltf_filter_type min_filter
Definition cgltf.h:447
char * name
Definition cgltf.h:841
cgltf_node ** nodes
Definition cgltf.h:842
cgltf_extras extras
Definition cgltf.h:846
cgltf_size nodes_count
Definition cgltf.h:843
cgltf_texture_view sheen_color_texture
Definition cgltf.h:546
cgltf_float sheen_color_factor[3]
Definition cgltf.h:547
cgltf_float sheen_roughness_factor
Definition cgltf.h:549
cgltf_texture_view sheen_roughness_texture
Definition cgltf.h:548
cgltf_extras extras
Definition cgltf.h:717
cgltf_node * skeleton
Definition cgltf.h:715
cgltf_node ** joints
Definition cgltf.h:713
cgltf_accessor * inverse_bind_matrices
Definition cgltf.h:716
cgltf_size joints_count
Definition cgltf.h:714
char * name
Definition cgltf.h:712
cgltf_float specular_factor
Definition cgltf.h:533
cgltf_float specular_color_factor[3]
Definition cgltf.h:532
cgltf_texture_view specular_color_texture
Definition cgltf.h:531
cgltf_texture_view specular_texture
Definition cgltf.h:530
cgltf_float subsurface_radius[3]
Definition cgltf.h:579
cgltf_float subsurface_scale
Definition cgltf.h:580
char * subsurface_method
Definition cgltf.h:577
cgltf_float subsurface_weight
Definition cgltf.h:578
cgltf_bool has_texcoord
Definition cgltf.h:474
cgltf_float rotation
Definition cgltf.h:472
cgltf_float scale[2]
Definition cgltf.h:473
cgltf_float offset[2]
Definition cgltf.h:471
cgltf_int texcoord
Definition cgltf.h:475
cgltf_bool has_basisu
Definition cgltf.h:460
cgltf_image * basisu_image
Definition cgltf.h:461
cgltf_sampler * sampler
Definition cgltf.h:459
char * name
Definition cgltf.h:457
cgltf_image * image
Definition cgltf.h:458
cgltf_bool has_webp
Definition cgltf.h:462
cgltf_extras extras
Definition cgltf.h:464
cgltf_image * webp_image
Definition cgltf.h:463
cgltf_float transmission_factor
Definition cgltf.h:520
cgltf_texture_view transmission_texture
Definition cgltf.h:519
cgltf_float attenuation_distance
Definition cgltf.h:541
cgltf_float thickness_factor
Definition cgltf.h:539
cgltf_texture_view thickness_texture
Definition cgltf.h:538
cgltf_float attenuation_color[3]
Definition cgltf.h:540