Bläddra i källkod

GLTFLoader: Fix handling of normalized animation outputs

Per GLTF spec, rotation and weight animation outputs can use normalized
BYTE/SHORT/etc. accessors. However, the animation tracks don't support
normalized values, which results in erroneous playback.

This change manually renormalizes the array elements before handing them
to the animation system to fix this.

Fixes #16658.
Arseny Kapoulkine 6 år sedan
förälder
incheckning
a90520c009
1 ändrade filer med 20 tillägg och 1 borttagningar
  1. 20 1
      examples/js/loaders/GLTFLoader.js

+ 20 - 1
examples/js/loaders/GLTFLoader.js

@@ -2869,12 +2869,31 @@ THREE.GLTFLoader = ( function () {
 
 
 				}
 				}
 
 
+				var outputArray = outputAccessor.array;
+
+				if ( outputAccessor.normalized ) {
+
+					var bits = outputAccessor.array.BYTES_PER_ELEMENT * 8;
+					var scale = 1 / ((1 << (bits - 1)) - 1);
+
+					var scaled = new Float32Array( outputArray.length );
+
+					for ( var j = 0, jl = outputArray.length; j < jl; j ++ ) {
+
+						scaled[j] = outputArray[j] * scale;
+
+					}
+
+					outputArray = scaled;
+
+				}
+
 				for ( var j = 0, jl = targetNames.length; j < jl; j ++ ) {
 				for ( var j = 0, jl = targetNames.length; j < jl; j ++ ) {
 
 
 					var track = new TypedKeyframeTrack(
 					var track = new TypedKeyframeTrack(
 						targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
 						targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
 						inputAccessor.array,
 						inputAccessor.array,
-						outputAccessor.array,
+						outputArray,
 						interpolation
 						interpolation
 					);
 					);