gltfpack: Add basic support for EXT_texture_webp

Similarly to KHR_texture_basisu appearing in the input, we now preserve
webp images along with the extension if they are present in the input
file.
This commit is contained in:
Arseny Kapoulkine
2024-06-22 09:29:49 -07:00
parent 1fd12b1172
commit e137a8b252
4 changed files with 18 additions and 4 deletions
+3
View File
@@ -454,6 +454,7 @@ static void process(cgltf_data* data, const char* input_path, const char* output
bool ext_instancing = false;
bool ext_texture_transform = false;
bool ext_texture_basisu = false;
bool ext_texture_webp = false;
size_t accr_offset = 0;
size_t node_offset = 0;
@@ -512,6 +513,7 @@ static void process(cgltf_data* data, const char* input_path, const char* output
assert(textures[i].remap == int(texture_offset));
texture_offset++;
ext_texture_basisu = ext_texture_basisu || texture.has_basisu;
ext_texture_webp = ext_texture_webp || texture.has_webp;
}
for (size_t i = 0; i < data->materials_count; ++i)
@@ -838,6 +840,7 @@ static void process(cgltf_data* data, const char* input_path, const char* output
{"KHR_materials_variants", data->variants_count > 0, false},
{"KHR_lights_punctual", data->lights_count > 0, false},
{"KHR_texture_basisu", (!json_textures.empty() && settings.texture_ktx2) || ext_texture_basisu, true},
{"EXT_texture_webp", ext_texture_webp, true},
{"EXT_mesh_gpu_instancing", ext_instancing, true},
};
+1
View File
@@ -8,6 +8,7 @@ static const char* kMimeTypes[][2] = {
{"image/jpeg", ".jpeg"},
{"image/png", ".png"},
{"image/ktx2", ".ktx2"},
{"image/webp", ".webp"},
};
static const char* inferMimeType(const char* path)
+6 -3
View File
@@ -11,10 +11,10 @@ static bool areTexturesEqual(const cgltf_texture& lhs, const cgltf_texture& rhs)
if (lhs.sampler != rhs.sampler)
return false;
if (lhs.has_basisu != rhs.has_basisu)
if (lhs.basisu_image != rhs.basisu_image)
return false;
if (lhs.basisu_image != rhs.basisu_image)
if (lhs.webp_image != rhs.webp_image)
return false;
return true;
@@ -446,9 +446,12 @@ static const cgltf_image* getTextureImage(const cgltf_texture* texture)
if (texture && texture->image)
return texture->image;
if (texture && texture->has_basisu && texture->basisu_image)
if (texture && texture->basisu_image)
return texture->basisu_image;
if (texture && texture->webp_image)
return texture->webp_image;
return NULL;
}
+8 -1
View File
@@ -975,13 +975,20 @@ void writeTexture(std::string& json, const cgltf_texture& texture, const ImageIn
}
}
if (texture.has_basisu && texture.basisu_image)
if (texture.basisu_image)
{
comma(json);
append(json, "\"extensions\":{\"KHR_texture_basisu\":{\"source\":");
append(json, size_t(texture.basisu_image - data->images));
append(json, "}}");
}
else if (texture.webp_image)
{
comma(json);
append(json, "\"extensions\":{\"EXT_texture_webp\":{\"source\":");
append(json, size_t(texture.webp_image - data->images));
append(json, "}}");
}
}
void writeMeshAttributes(std::string& json, std::vector<BufferView>& views, std::string& json_accessors, size_t& accr_offset, const Mesh& mesh, int target, const QuantizationPosition& qp, const QuantizationTexture& qt, const Settings& settings)