Browse Source

GLTFExporter: Clean up.

linbingquan 4 years ago
parent
commit
b3508e49b6
2 changed files with 31 additions and 4 deletions
  1. 15 1
      examples/js/exporters/GLTFExporter.js
  2. 16 3
      examples/jsm/exporters/GLTFExporter.js

+ 15 - 1
examples/js/exporters/GLTFExporter.js

@@ -31,6 +31,8 @@ var WEBGL_CONSTANTS = {
 	REPEAT: 10497
 };
 
+var identityArray = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ];
+
 var THREE_TO_WEBGL = {};
 
 THREE_TO_WEBGL[ THREE.NearestFilter ] = WEBGL_CONSTANTS.NEAREST;
@@ -152,6 +154,18 @@ THREE.GLTFExporter.prototype = {
 
 		}
 
+		/**
+		 * Is identity matrix
+		 *
+		 * @param {THREE.Matrix4} matrix
+		 * @returns {Boolean} Returns true, if parameter is identity matrix
+		 */
+		function isIdentityMatrix( matrix ) {
+
+			return equalArray( matrix.elements, identityArray );
+
+		}
+
 		/**
 		 * Converts a string to an ArrayBuffer.
 		 * @param  {string} text
@@ -1777,7 +1791,7 @@ THREE.GLTFExporter.prototype = {
 
 				}
 
-				if ( ! equalArray( object.matrix.elements, new THREE.Matrix4().toArray() ) ) {
+				if ( ! isIdentityMatrix( object.matrix ) ) {
 
 					gltfNode.matrix = object.matrix.elements;
 

+ 16 - 3
examples/jsm/exporters/GLTFExporter.js

@@ -17,8 +17,7 @@ import {
 	RGBAFormat,
 	RepeatWrapping,
 	Scene,
-	Vector3,
-	Matrix4
+	Vector3
 } from "../../../build/three.module.js";
 
 //------------------------------------------------------------------------------
@@ -52,6 +51,8 @@ var WEBGL_CONSTANTS = {
 	REPEAT: 10497
 };
 
+var identityArray = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ];
+
 var THREE_TO_WEBGL = {};
 
 THREE_TO_WEBGL[ NearestFilter ] = WEBGL_CONSTANTS.NEAREST;
@@ -173,6 +174,18 @@ GLTFExporter.prototype = {
 
 		}
 
+		/**
+		 * Is identity matrix
+		 *
+		 * @param {THREE.Matrix4} matrix
+		 * @returns {Boolean} Returns true, if parameter is identity matrix
+		 */
+		function isIdentityMatrix( matrix ) {
+
+			return equalArray( matrix.elements, identityArray );
+
+		}
+
 		/**
 		 * Converts a string to an ArrayBuffer.
 		 * @param  {string} text
@@ -1798,7 +1811,7 @@ GLTFExporter.prototype = {
 
 				}
 
-				if ( ! equalArray( object.matrix.elements, new Matrix4().toArray() ) ) {
+				if ( ! isIdentityMatrix( object.matrix ) ) {
 
 					gltfNode.matrix = object.matrix.elements;