Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: fix type of clearcoatNormalTexture, add missing mime type image/webp #75

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
6 changes: 5 additions & 1 deletion include/fastgltf/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ namespace fastgltf {
DDS = 4,
GltfBuffer = 5,
OctetStream = 6,
WEBP = 7,
};

FASTGLTF_EXPORT enum class AnimationInterpolation : std::uint8_t {
Expand Down Expand Up @@ -458,6 +459,7 @@ namespace fastgltf {
constexpr std::string_view mimeTypeDds = "image/vnd-ms.dds";
constexpr std::string_view mimeTypeGltfBuffer = "application/gltf-buffer";
constexpr std::string_view mimeTypeOctetStream = "application/octet-stream";
constexpr std::string_view mimeTypeWebp = "image/webp";

constexpr std::string_view getMimeTypeString(MimeType mimeType) noexcept {
switch (mimeType) {
Expand All @@ -473,6 +475,8 @@ namespace fastgltf {
return mimeTypeGltfBuffer;
case MimeType::OctetStream:
return mimeTypeOctetStream;
case MimeType::WEBP:
return mimeTypeWebp;
default:
return "";
}
Expand Down Expand Up @@ -1925,7 +1929,7 @@ namespace fastgltf {
Optional<TextureInfo> clearcoatTexture;
num clearcoatRoughnessFactor = 0.0f;
Optional<TextureInfo> clearcoatRoughnessTexture;
Optional<TextureInfo> clearcoatNormalTexture;
Optional<NormalTextureInfo> clearcoatNormalTexture;
};

FASTGLTF_EXPORT struct MaterialSheen {
Expand Down
9 changes: 6 additions & 3 deletions src/fastgltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ fg::MimeType fg::Parser::getMimeTypeFromString(std::string_view mime) {
case force_consteval<crc32c(mimeTypeOctetStream)>: {
return MimeType::OctetStream;
}
case force_consteval<crc32c(mimeTypeWebp)>: {
return MimeType::WEBP;
}
default: {
return MimeType::None;
}
Expand Down Expand Up @@ -2634,9 +2637,9 @@ fg::Error fg::Parser::parseMaterialExtensions(simdjson::dom::object &object, fas
return error;
}

TextureInfo clearcoatNormalTexture;
NormalTextureInfo clearcoatNormalTexture;
if (auto error = parseTextureInfo(clearcoatObject, "clearcoatNormalTexture",
&clearcoatNormalTexture, config.extensions); error ==
&clearcoatNormalTexture, config.extensions, TextureInfoType::NormalTexture); error ==
Error::None) {
clearcoat->clearcoatNormalTexture = std::move(clearcoatNormalTexture);
} else if (error != Error::MissingField) {
Expand Down Expand Up @@ -4735,7 +4738,7 @@ void fg::Exporter::writeMaterials(const Asset& asset, std::string& json) {
if (it->clearcoat->clearcoatNormalTexture.has_value()) {
if (json.back() != '{') json += ',';
json += "\"clearcoatNormalTexture\":";
writeTextureInfo(json, &it->clearcoat->clearcoatNormalTexture.value());
writeTextureInfo(json, &it->clearcoat->clearcoatNormalTexture.value(), TextureInfoType::NormalTexture);
}
json += '}';
}
Expand Down
Loading