2
0
Mr.doob 3 жил өмнө
parent
commit
e1499fb641

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

@@ -1555,6 +1555,22 @@
 		return result;
 
 	};
+
+	const _q = new THREE.Quaternion();
+
+	class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
+
+		interpolate_( i1, t0, t, t1 ) {
+
+			const result = super.interpolate_( i1, t0, t, t1 );
+
+			_q.fromArray( result ).normalize().toArray( result );
+
+			return result;
+
+		}
+
+	}
 	/*********************************/
 
 	/********** INTERNALS ************/
@@ -3271,7 +3287,8 @@
 								// A CUBICSPLINE keyframe in glTF has three output values for each input value,
 								// representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
 								// must be divided by three to get the interpolant's sampleSize argument.
-								return new GLTFCubicSplineInterpolant( this.times, this.values, this.getValueSize() / 3, result );
+								const interpolantType = this instanceof THREE.QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
+								return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
 
 							}; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
 

+ 2 - 3
examples/js/loaders/TGALoader.js

@@ -179,11 +179,10 @@
 
 					for ( x = x_start; x !== x_end; x += x_step, i += 2 ) {
 
-						color = image[ i + 0 ] + ( image[ i + 1 ] << 8 ); // Inversed ?
-
+						color = image[ i + 0 ] + ( image[ i + 1 ] << 8 );
 						imageData[ ( x + width * y ) * 4 + 0 ] = ( color & 0x7C00 ) >> 7;
 						imageData[ ( x + width * y ) * 4 + 1 ] = ( color & 0x03E0 ) >> 2;
-						imageData[ ( x + width * y ) * 4 + 2 ] = ( color & 0x001F ) >> 3;
+						imageData[ ( x + width * y ) * 4 + 2 ] = ( color & 0x001F ) << 3;
 						imageData[ ( x + width * y ) * 4 + 3 ] = color & 0x8000 ? 0 : 255;
 
 					}

+ 9 - 2
examples/js/renderers/CSS3DRenderer.js

@@ -4,6 +4,12 @@
  * Based on http://www.emagix.net/academic/mscs-project/item/camera-sync-with-css3-and-webgl-threejs
  */
 
+	const _position = new THREE.Vector3();
+
+	const _quaternion = new THREE.Quaternion();
+
+	const _scale = new THREE.Vector3();
+
 	class CSS3DObject extends THREE.Object3D {
 
 		constructor( element ) {
@@ -186,10 +192,11 @@
 						_matrix.transpose();
 
 						if ( object.rotation2D !== 0 ) _matrix.multiply( _matrix2.makeRotationZ( object.rotation2D ) );
+						object.matrixWorld.decompose( _position, _quaternion, _scale );
 
-						_matrix.copyPosition( object.matrixWorld );
+						_matrix.setPosition( _position );
 
-						_matrix.scale( object.scale );
+						_matrix.scale( _scale );
 
 						_matrix.elements[ 3 ] = 0;
 						_matrix.elements[ 7 ] = 0;