From 04db5cd5ea8f2c2095df06e11b5899796f225da6 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Nov 2019 21:11:53 +0100 Subject: [PATCH] closes https://github.com/assimp/assimp/issues/2119: initial version. --- code/glTF/glTFAsset.inl | 3 --- code/glTF/glTFCommon.h | 17 +++++++---------- code/glTF2/glTF2Asset.h | 6 +++++- code/glTF2/glTF2Asset.inl | 23 ++++++++++++++++++----- code/glTF2/glTF2Exporter.h | 1 + 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/code/glTF/glTFAsset.inl b/code/glTF/glTFAsset.inl index f31781a3f..25cf1873c 100644 --- a/code/glTF/glTFAsset.inl +++ b/code/glTF/glTFAsset.inl @@ -1427,9 +1427,6 @@ inline void Asset::ReadExtensionsUsed(Document& doc) } } - #define CHECK_EXT(EXT) \ - if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true; - CHECK_EXT(KHR_binary_glTF); CHECK_EXT(KHR_materials_common); diff --git a/code/glTF/glTFCommon.h b/code/glTF/glTFCommon.h index d9edee75e..b2e28d580 100644 --- a/code/glTF/glTFCommon.h +++ b/code/glTF/glTFCommon.h @@ -188,7 +188,7 @@ namespace glTFCommon { size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out); inline - size_t DecodeBase64(const char* in, uint8_t*& out) { + size_t DecodeBase64(const char* in, uint8_t*& out) { return DecodeBase64(in, strlen(in), out); } @@ -221,25 +221,22 @@ namespace glTFCommon { }; inline - char EncodeCharBase64(uint8_t b) { + char EncodeCharBase64(uint8_t b) { return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[size_t(b)]; } inline - uint8_t DecodeCharBase64(char c) { + uint8_t DecodeCharBase64(char c) { return DATA::tableDecodeBase64[size_t(c)]; // TODO faster with lookup table or ifs? - /*if (c >= 'A' && c <= 'Z') return c - 'A'; - if (c >= 'a' && c <= 'z') return c - 'a' + 26; - if (c >= '0' && c <= '9') return c - '0' + 52; - if (c == '+') return 62; - if (c == '/') return 63; - return 64; // '-' */ } size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out); void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out); - } + } // namespace Util + +#define CHECK_EXT(EXT) \ + if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true; } diff --git a/code/glTF2/glTF2Asset.h b/code/glTF2/glTF2Asset.h index 15c4c44fa..60a393170 100644 --- a/code/glTF2/glTF2Asset.h +++ b/code/glTF2/glTF2Asset.h @@ -685,6 +685,10 @@ namespace glTF2 Ref texture; unsigned int index; unsigned int texCoord = 0; + + float offset[2]; + float rotation; + float scale[2]; }; struct NormalTextureInfo : TextureInfo @@ -1024,7 +1028,7 @@ namespace glTF2 bool KHR_materials_pbrSpecularGlossiness; bool KHR_materials_unlit; bool KHR_lights_punctual; - + bool KHR_texture_transform; } extensionsUsed; AssetMetadata asset; diff --git a/code/glTF2/glTF2Asset.inl b/code/glTF2/glTF2Asset.inl index 6b47b1607..310fcde06 100644 --- a/code/glTF2/glTF2Asset.inl +++ b/code/glTF2/glTF2Asset.inl @@ -800,8 +800,20 @@ inline void Texture::Read(Value& obj, Asset& r) } namespace { - inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out) - { + inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out) { + if (r.extensionsUsed.KHR_texture_transform) { + if (Value *extensions = FindObject(*prop, "extensions")) { + if (Value *pKHR_texture_transform = FindObject(*extensions, "KHR_texture_transform")) { + if (Value *array = FindArray(*pKHR_texture_transform, "offset")) { + out.offset[0] = (*array)[0].GetFloat(); + out.offset[1] = (*array)[1].GetFloat(); + } + ReadMember(*pKHR_texture_transform, "rotation", out.rotation); + ReadMember(*pKHR_texture_transform, "scale", *out.scale); + } + } + } + if (Value* index = FindUInt(*prop, "index")) { out.texture = r.textures.Retrieve(index->GetUint()); } @@ -877,6 +889,9 @@ inline void Material::Read(Value& material, Asset& r) } } + if (r.extensionsUsed.KHR_texture_transform) { + } + unlit = nullptr != FindObject(*extensions, "KHR_materials_unlit"); } } @@ -1463,12 +1478,10 @@ inline void Asset::ReadExtensionsUsed(Document& doc) } } - #define CHECK_EXT(EXT) \ - if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true; - CHECK_EXT(KHR_materials_pbrSpecularGlossiness); CHECK_EXT(KHR_materials_unlit); CHECK_EXT(KHR_lights_punctual); + CHECK_EXT(KHR_texture_transform); #undef CHECK_EXT } diff --git a/code/glTF2/glTF2Exporter.h b/code/glTF2/glTF2Exporter.h index 2dc083709..b527c4bc9 100644 --- a/code/glTF2/glTF2Exporter.h +++ b/code/glTF2/glTF2Exporter.h @@ -74,6 +74,7 @@ namespace glTF2 struct Texture; // Vec/matrix types, as raw float arrays + typedef float (vec2)[2]; typedef float (vec3)[3]; typedef float (vec4)[4]; }