Browse Source

GLTFLoader: Fix KHR_texture_transform support when rotation is specified (#34033)

Arseny Kapoulkine 1 week ago
parent
commit
490f2a7cbc
1 changed files with 21 additions and 0 deletions
  1. 21 0
      examples/jsm/loaders/GLTFLoader.js

+ 21 - 0
examples/jsm/loaders/GLTFLoader.js

@@ -2072,6 +2072,27 @@ class GLTFTextureTransformExtension {
 
 		}
 
+		if ( transform.rotation !== undefined ) {
+
+			// glTF's KHR_texture_transform order differs from three.js:
+			// glTF defines the UV transform as T * R * S
+			// three.js defines the UV transform as T * S * R
+			//
+			// To fix this, we need to override the matrix with the value computed per glTF spec
+			// We still set the other fields so that you can inspect/export the resulting object.
+
+			const c = Math.cos( texture.rotation );
+			const s = Math.sin( texture.rotation );
+
+			texture.matrix.set(
+				texture.repeat.x * c, texture.repeat.y * s, texture.offset.x,
+				- texture.repeat.x * s, texture.repeat.y * c, texture.offset.y,
+				0, 0, 1
+			);
+			texture.matrixAutoUpdate = false;
+
+		}
+
 		texture.needsUpdate = true;
 
 		return texture;

粤ICP备19079148号