瀏覽代碼

add missing setup of texture transform in aiMaterial.

Kim Kulling 6 年之前
父節點
當前提交
17946e26ef
共有 2 個文件被更改,包括 18 次插入2 次删除
  1. 10 2
      code/glTF2/glTF2Asset.inl
  2. 8 0
      code/glTF2/glTF2Importer.cpp

+ 10 - 2
code/glTF2/glTF2Asset.inl

@@ -802,14 +802,22 @@ inline void Texture::Read(Value& obj, Asset& r)
 namespace {
     inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out) {
 	    if (r.extensionsUsed.KHR_texture_transform) {
-			if (Value *extensions = FindObject(*prop, "extensions")) {
+			out.scale[0] = 1;
+			out.scale[1] = 1;
+			out.offset[0] = 0;
+			out.offset[1] = 0;
+			out.rotation = 0;
+            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 *array = FindArray(*pKHR_texture_transform, "scale")) {
+						out.scale[0] = (*array)[0].GetFloat();
+						out.scale[1] = (*array)[1].GetFloat();
+					}
 				}
 			}
         }

+ 8 - 0
code/glTF2/glTF2Importer.cpp

@@ -206,6 +206,14 @@ inline void SetMaterialTextureProperty(std::vector<int>& embeddedTexIdxs, Asset&
             uri.length = 1 + ASSIMP_itoa10(uri.data + 1, MAXLEN - 1, texIdx);
         }
 
+        aiUVTransform transform;
+		transform.mTranslation.x = prop.offset[0];
+		transform.mTranslation.y = prop.offset[0];
+		transform.mRotation = prop.rotation;
+		transform.mScaling.x = prop.scale[0];
+		transform.mScaling.y = prop.scale[1];
+		mat->AddProperty(&transform, 1, _AI_MATKEY_UVTRANSFORM_BASE, texType, texSlot);
+
         mat->AddProperty(&uri, AI_MATKEY_TEXTURE(texType, texSlot));
         mat->AddProperty(&prop.texCoord, 1, _AI_MATKEY_GLTF_TEXTURE_TEXCOORD_BASE, texType, texSlot);