Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions cgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,16 @@ typedef struct cgltf_draco_mesh_compression {
cgltf_size attributes_count;
} cgltf_draco_mesh_compression;

typedef struct cgltf_gaussian_splatting {
char* kernel;
char* color_space;
char* sorting_method;
char* projection;
cgltf_extras extras;
cgltf_size extensions_count;
cgltf_extension* extensions;
} cgltf_gaussian_splatting;

typedef struct cgltf_mesh_gpu_instancing {
cgltf_attribute* attributes;
cgltf_size attributes_count;
Expand All @@ -616,6 +626,8 @@ typedef struct cgltf_primitive {
cgltf_draco_mesh_compression draco_mesh_compression;
cgltf_material_mapping* mappings;
cgltf_size mappings_count;
cgltf_bool has_gaussian_splatting;
cgltf_gaussian_splatting gaussian_splatting;
cgltf_size extensions_count;
cgltf_extension* extensions;
} cgltf_primitive;
Expand Down Expand Up @@ -3139,6 +3151,55 @@ static int cgltf_parse_json_draco_mesh_compression(cgltf_options* options, jsmnt
return i;
}

static int cgltf_parse_json_gaussian_splatting(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_gaussian_splatting* out_gaussian_splatting)
{
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, "kernel") == 0)
{
i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_gaussian_splatting->kernel);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "colorSpace") == 0)
{
i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_gaussian_splatting->color_space);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "sortingMethod") == 0)
{
i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_gaussian_splatting->sorting_method);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "projection") == 0)
{
i = cgltf_parse_json_string(options, tokens, i + 1, json_chunk, &out_gaussian_splatting->projection);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "extras") == 0)
{
i = cgltf_parse_json_extras(options, tokens, i + 1, json_chunk, &out_gaussian_splatting->extras);
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "extensions") == 0)
{
i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_gaussian_splatting->extensions_count, &out_gaussian_splatting->extensions);
}
else
{
i = cgltf_skip_json(tokens, i+1);
}

if (i < 0)
{
return i;
}
}

return i;
}

static int cgltf_parse_json_mesh_gpu_instancing(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_mesh_gpu_instancing* out_mesh_gpu_instancing)
{
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
Expand Down Expand Up @@ -3410,6 +3471,11 @@ static int cgltf_parse_json_primitive(cgltf_options* options, jsmntok_t const* t
out_prim->has_draco_mesh_compression = 1;
i = cgltf_parse_json_draco_mesh_compression(options, tokens, i + 1, json_chunk, &out_prim->draco_mesh_compression);
}
else if (cgltf_json_strcmp(tokens+i, json_chunk, "KHR_gaussian_splatting") == 0)
{
out_prim->has_gaussian_splatting = 1;
i = cgltf_parse_json_gaussian_splatting(options, tokens, i + 1, json_chunk, &out_prim->gaussian_splatting);
}
else if (cgltf_json_strcmp(tokens+i, json_chunk, "KHR_materials_variants") == 0)
{
i = cgltf_parse_json_material_mappings(options, tokens, i + 1, json_chunk, out_prim);
Expand Down
18 changes: 17 additions & 1 deletion cgltf_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size si
#define CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION (1 << 17)
#define CGLTF_EXTENSION_FLAG_TEXTURE_WEBP (1 << 18)
#define CGLTF_EXTENSION_FLAG_MATERIALS_DIFFUSE_TRANSMISSION (1 << 19)
#define CGLTF_EXTENSION_FLAG_GAUSSIAN_SPLATTING (1 << 20)

typedef struct {
char* buffer;
Expand Down Expand Up @@ -499,7 +500,7 @@ static void cgltf_write_primitive(cgltf_write_context* context, const cgltf_prim
}
cgltf_write_extras(context, &prim->extras);

if (prim->has_draco_mesh_compression || prim->mappings_count > 0)
if (prim->has_draco_mesh_compression || prim->has_gaussian_splatting || prim->mappings_count > 0)
{
cgltf_write_line(context, "\"extensions\": {");

Expand All @@ -523,6 +524,18 @@ static void cgltf_write_primitive(cgltf_write_context* context, const cgltf_prim
cgltf_write_line(context, "}");
}

if (prim->has_gaussian_splatting)
{
context->extension_flags |= CGLTF_EXTENSION_FLAG_GAUSSIAN_SPLATTING;
cgltf_write_line(context, "\"KHR_gaussian_splatting\": {");
cgltf_write_strprop(context, "kernel", prim->gaussian_splatting.kernel);
cgltf_write_strprop(context, "colorSpace", prim->gaussian_splatting.color_space);
cgltf_write_strprop(context, "sortingMethod", prim->gaussian_splatting.sorting_method);
cgltf_write_strprop(context, "projection", prim->gaussian_splatting.projection);
cgltf_write_extras(context, &prim->gaussian_splatting.extras);
cgltf_write_line(context, "}");
}

if (prim->mappings_count > 0)
{
context->extension_flags |= CGLTF_EXTENSION_FLAG_MATERIALS_VARIANTS;
Expand Down Expand Up @@ -1329,6 +1342,9 @@ static void cgltf_write_extensions(cgltf_write_context* context, uint32_t extens
if (extension_flags & CGLTF_EXTENSION_FLAG_MATERIALS_DISPERSION) {
cgltf_write_stritem(context, "KHR_materials_dispersion");
}
if (extension_flags & CGLTF_EXTENSION_FLAG_GAUSSIAN_SPLATTING) {
cgltf_write_stritem(context, "KHR_gaussian_splatting");
}
}

cgltf_size cgltf_write(const cgltf_options* options, char* buffer, cgltf_size size, const cgltf_data* data)
Expand Down