update cgltf from 1.13 to 1.14

This commit is contained in:
shashank
2024-12-29 19:58:55 +05:30
parent ad99d20d29
commit 77511da195
3 changed files with 549 additions and 242 deletions

View File

@@ -105,6 +105,7 @@ type :: enum c.int {
}
primitive_type :: enum c.int {
invalid,
points,
lines,
line_loop,
@@ -222,15 +223,6 @@ accessor_sparse :: struct {
indices_component_type: component_type,
values_buffer_view: ^buffer_view,
values_byte_offset: uint,
extras: extras_t,
indices_extras: extras_t,
values_extras: extras_t,
extensions_count: uint,
extensions: [^]extension `fmt:"v,extensions_count"`,
indices_extensions_count: uint,
indices_extensions: [^]extension `fmt:"v,indices_extensions_count"`,
values_extensions_count: uint,
values_extensions: [^]extension `fmt:"v,values_extensions_count"`,
}
accessor :: struct {
@@ -306,9 +298,6 @@ texture_view :: struct {
scale: f32, /* equivalent to strength for occlusion_texture */
has_transform: b32,
transform: texture_transform,
extras: extras_t,
extensions_count: uint,
extensions: [^]extension `fmt:"v,extensions_count"`,
}
pbr_metallic_roughness :: struct {
@@ -381,6 +370,16 @@ iridescence :: struct {
iridescence_thickness_texture: texture_view,
}
anisotropy :: struct {
anisotropy_strength: f32,
anisotropy_rotation: f32,
anisotropy_texture: texture_view,
}
dispersion :: struct {
dispersion: f32,
}
material :: struct {
name: cstring,
has_pbr_metallic_roughness: b32,
@@ -393,6 +392,8 @@ material :: struct {
has_sheen: b32,
has_emissive_strength: b32,
has_iridescence: b32,
has_anisotropy: b32,
has_dispersion: b32,
pbr_metallic_roughness: pbr_metallic_roughness,
pbr_specular_glossiness: pbr_specular_glossiness,
clearcoat: clearcoat,
@@ -403,6 +404,8 @@ material :: struct {
volume: volume,
emissive_strength: emissive_strength,
iridescence: iridescence,
anisotropy: anisotropy,
dispersion: dispersion,
normal_texture: texture_view,
occlusion_texture: texture_view,
emissive_texture: texture_view,
@@ -432,7 +435,6 @@ draco_mesh_compression :: struct {
}
mesh_gpu_instancing :: struct {
buffer_view: ^buffer_view,
attributes: []attribute,
}
@@ -683,6 +685,9 @@ foreign lib {
node_transform_local :: proc(node: ^node, out_matrix: [^]f32) ---
node_transform_world :: proc(node: ^node, out_matrix: [^]f32) ---
@(require_results)
buffer_view_data :: proc(view: ^/*const*/buffer_view) -> [^]byte ---
@(require_results)
accessor_read_float :: proc(accessor: ^/*const*/accessor, index: uint, out: [^]f32, element_size: uint) -> b32 ---
@(require_results)
@@ -693,13 +698,53 @@ foreign lib {
@(require_results)
num_components :: proc(type: type) -> uint ---
@(require_results)
component_size :: proc(component_type: component_type) -> uint ---
@(require_results)
calc_size :: proc(type: type, component_type: component_type) -> uint ---
@(require_results)
accessor_unpack_floats :: proc(accessor: ^/*const*/accessor, out: [^]f32, float_count: uint) -> uint ---
@(require_results)
accessor_unpack_indices :: proc(accessor: ^/*const*/accessor , out: rawptr, out_component_size: uint, index_count: uint) -> uint ---
/* this function is deprecated and will be removed in the future; use cgltf_extras::data instead */
@(require_results)
copy_extras_json :: proc(data: ^data, extras: ^extras_t, dest: [^]byte, dest_size: ^uint) -> result ---
@(require_results)
mesh_index :: proc(data: ^/*const*/data, object: ^/*const*/mesh) -> uint ---
@(require_results)
material_index :: proc(data: ^/*const*/data, object: ^/*const*/material) -> uint ---
@(require_results)
accessor_index :: proc(data: ^/*const*/data, object: ^/*const*/accessor) -> uint ---
@(require_results)
buffer_view_index :: proc(data: ^/*const*/data, object: ^/*const*/buffer_view) -> uint ---
@(require_results)
buffer_index :: proc(data: ^/*const*/data, object: ^/*const*/buffer) -> uint ---
@(require_results)
image_index :: proc(data: ^/*const*/data, object: ^/*const*/image) -> uint ---
@(require_results)
texture_index :: proc(data: ^/*const*/data, object: ^/*const*/texture) -> uint ---
@(require_results)
sampler_index :: proc(data: ^/*const*/data, object: ^/*const*/sampler) -> uint ---
@(require_results)
skin_index :: proc(data: ^/*const*/data, object: ^/*const*/skin) -> uint ---
@(require_results)
camera_index :: proc(data: ^/*const*/data, object: ^/*const*/camera) -> uint ---
@(require_results)
light_index :: proc(data: ^/*const*/data, object: ^/*const*/light) -> uint ---
@(require_results)
node_index :: proc(data: ^/*const*/data, object: ^/*const*/node) -> uint ---
@(require_results)
scene_index :: proc(data: ^/*const*/data, object: ^/*const*/scene) -> uint ---
@(require_results)
animation_index :: proc(data: ^/*const*/data, object: ^/*const*/animation) -> uint ---
@(require_results)
animation_sampler_index :: proc(animation: ^/*const*/animation, object: ^/*const*/animation_sampler) -> uint ---
@(require_results)
animation_channel_index :: proc(animation: ^/*const*/animation, object: ^/*const*/animation_channel) -> uint ---
@(require_results)
write_file :: proc(#by_ptr options: options, path: cstring, data: ^data) -> result ---
@(require_results)

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/**
* cgltf_write - a single-file glTF 2.0 writer written in C99.
*
* Version: 1.13
* Version: 1.14
*
* Website: https://github.com/jkuhlmann/cgltf
*
@@ -85,6 +85,8 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
#define CGLTF_EXTENSION_FLAG_MATERIALS_EMISSIVE_STRENGTH (1 << 13)
#define CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING (1 << 14)
#define CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE (1 << 15)
#define CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY (1 << 16)
#define CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION (1 << 17)
typedef struct {
char* buffer;
@@ -152,7 +154,6 @@ typedef struct {
context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
cgltf_write_texture_transform(context, &info.transform); \
} \
cgltf_write_extras(context, &info.extras); \
cgltf_write_line(context, "}"); }
#define CGLTF_WRITE_NORMAL_TEXTURE_INFO(label, info) if (info.texture) { \
@@ -164,7 +165,6 @@ typedef struct {
context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
cgltf_write_texture_transform(context, &info.transform); \
} \
cgltf_write_extras(context, &info.extras); \
cgltf_write_line(context, "}"); }
#define CGLTF_WRITE_OCCLUSION_TEXTURE_INFO(label, info) if (info.texture) { \
@@ -176,12 +176,11 @@ typedef struct {
context->extension_flags |= CGLTF_EXTENSION_FLAG_TEXTURE_TRANSFORM; \
cgltf_write_texture_transform(context, &info.transform); \
} \
cgltf_write_extras(context, &info.extras); \
cgltf_write_line(context, "}"); }
#ifndef CGLTF_CONSTS
static const cgltf_size GlbHeaderSize = 12;
static const cgltf_size GlbChunkHeaderSize = 8;
#define GlbHeaderSize 12
#define GlbChunkHeaderSize 8
static const uint32_t GlbVersion = 2;
static const uint32_t GlbMagic = 0x46546C67;
static const uint32_t GlbMagicJsonChunk = 0x4E4F534A;
@@ -360,6 +359,21 @@ static int cgltf_int_from_component_type(cgltf_component_type ctype)
}
}
static int cgltf_int_from_primitive_type(cgltf_primitive_type ctype)
{
switch (ctype)
{
case cgltf_primitive_type_points: return 0;
case cgltf_primitive_type_lines: return 1;
case cgltf_primitive_type_line_loop: return 2;
case cgltf_primitive_type_line_strip: return 3;
case cgltf_primitive_type_triangles: return 4;
case cgltf_primitive_type_triangle_strip: return 5;
case cgltf_primitive_type_triangle_fan: return 6;
default: return -1;
}
}
static const char* cgltf_str_from_alpha_mode(cgltf_alpha_mode alpha_mode)
{
switch (alpha_mode)
@@ -455,7 +469,7 @@ static void cgltf_write_asset(cgltf_write_context* context, const cgltf_asset* a
static void cgltf_write_primitive(cgltf_write_context* context, const cgltf_primitive* prim)
{
cgltf_write_intprop(context, "mode", (int) prim->type, 4);
cgltf_write_intprop(context, "mode", cgltf_int_from_primitive_type(prim->type), 4);
CGLTF_WRITE_IDXPROP("indices", prim->indices, context->data->accessors);
CGLTF_WRITE_IDXPROP("material", prim->material, context->data->materials);
cgltf_write_line(context, "\"attributes\": {");
@@ -641,6 +655,16 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE;
}
if (material->has_anisotropy)
{
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY;
}
if (material->has_dispersion)
{
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION;
}
if (material->has_pbr_metallic_roughness)
{
const cgltf_pbr_metallic_roughness* params = &material->pbr_metallic_roughness;
@@ -656,7 +680,7 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
cgltf_write_line(context, "}");
}
if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_ior || material->has_specular || material->has_transmission || material->has_sheen || material->has_volume || material->has_emissive_strength || material->has_iridescence)
if (material->unlit || material->has_pbr_specular_glossiness || material->has_clearcoat || material->has_ior || material->has_specular || material->has_transmission || material->has_sheen || material->has_volume || material->has_emissive_strength || material->has_iridescence || material->has_anisotropy || material->has_dispersion)
{
cgltf_write_line(context, "\"extensions\": {");
if (material->has_clearcoat)
@@ -767,6 +791,22 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
CGLTF_WRITE_TEXTURE_INFO("iridescenceThicknessTexture", params->iridescence_thickness_texture);
cgltf_write_line(context, "}");
}
if (material->has_anisotropy)
{
cgltf_write_line(context, "\"KHR_materials_anisotropy\": {");
const cgltf_anisotropy* params = &material->anisotropy;
cgltf_write_floatprop(context, "anisotropyFactor", params->anisotropy_strength, 0.f);
cgltf_write_floatprop(context, "anisotropyRotation", params->anisotropy_rotation, 0.f);
CGLTF_WRITE_TEXTURE_INFO("anisotropyTexture", params->anisotropy_texture);
cgltf_write_line(context, "}");
}
if (material->has_dispersion)
{
cgltf_write_line(context, "\"KHR_materials_dispersion\": {");
const cgltf_dispersion* params = &material->dispersion;
cgltf_write_floatprop(context, "dispersion", params->dispersion, 0.f);
cgltf_write_line(context, "}");
}
cgltf_write_line(context, "}");
}
@@ -977,7 +1017,6 @@ static void cgltf_write_node(cgltf_write_context* context, const cgltf_node* nod
cgltf_write_line(context, "\"EXT_mesh_gpu_instancing\": {");
{
CGLTF_WRITE_IDXPROP("bufferView", node->mesh_gpu_instancing.buffer_view, context->data->buffer_views);
cgltf_write_line(context, "\"attributes\": {");
{
for (cgltf_size i = 0; i < node->mesh_gpu_instancing.attributes_count; ++i)
@@ -1044,14 +1083,11 @@ static void cgltf_write_accessor(cgltf_write_context* context, const cgltf_acces
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_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, "}");
cgltf_write_extras(context, &accessor->sparse.extras);
cgltf_write_line(context, "}");
}
cgltf_write_extras(context, &accessor->extras);
@@ -1123,6 +1159,7 @@ static void cgltf_write_light(cgltf_write_context* context, const cgltf_light* l
cgltf_write_floatprop(context, "outerConeAngle", light->spot_outer_cone_angle, 3.14159265358979323846f/4.0f);
cgltf_write_line(context, "}");
}
cgltf_write_extras( context, &light->extras );
cgltf_write_line(context, "}");
}
@@ -1249,9 +1286,15 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_IRIDESCENCE) {
cgltf_write_stritem(context, "KHR_materials_iridescence");
}
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_ANISOTROPY) {
cgltf_write_stritem(context, "KHR_materials_anisotropy");
}
if (extension_flags & CGLTF_EXTENSION_FLAG_MESH_GPU_INSTANCING) {
cgltf_write_stritem(context, "EXT_mesh_gpu_instancing");
}
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION) {
cgltf_write_stritem(context, "KHR_materials_dispersion");
}
}
cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size size, const cgltf_data* data)