浏览代码

GLTFExporter: Address review comments: simplify code, fix style

Also include jsm version (auto-converted)
Gary Oberbrunner 6 年之前
父节点
当前提交
5a41bcd61d
共有 2 个文件被更改,包括 16 次插入20 次删除
  1. 6 20
      examples/js/exporters/GLTFExporter.js
  2. 10 0
      examples/jsm/exporters/GLTFExporter.js

+ 6 - 20
examples/js/exporters/GLTFExporter.js

@@ -1167,26 +1167,12 @@ THREE.GLTFExporter.prototype = {
 
 				// Prefix all geometry attributes except the ones specifically
 				// listed in the spec; non-spec attributes are considered custom.
-				var validVertexAttributes = [
-					/^POSITION$/,
-					/^NORMAL$/,
-					/^TANGENT$/,
-					/^TEXCOORD_\d+$/,
-					/^COLOR_\d+$/,
-					/^JOINTS_\d+$/,
-					/^WEIGHTS_\d+$/,
-				];
-
-				var isValidAttribute = false;
-				for (var i = 0; i < validVertexAttributes.length; i++) {
-					if (validVertexAttributes[i].test(attributeName)) {
-						isValidAttribute = true;
-						break;
-					}
-				}
-				if (!isValidAttribute) {
-					console.log(`Prefixing ${attributeName}`)
-					attributeName = '_' + attributeName
+				var validVertexAttributes =
+						/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
+				if ( ! validVertexAttributes.test( attributeName ) ) {
+
+					attributeName = '_' + attributeName;
+
 				}
 
 				if ( cachedData.attributes.has( attribute ) ) {

+ 10 - 0
examples/jsm/exporters/GLTFExporter.js

@@ -1188,6 +1188,16 @@ GLTFExporter.prototype = {
 				var attribute = geometry.attributes[ attributeName ];
 				attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase();
 
+				// Prefix all geometry attributes except the ones specifically
+				// listed in the spec; non-spec attributes are considered custom.
+				var validVertexAttributes =
+						/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
+				if ( ! validVertexAttributes.test( attributeName ) ) {
+
+					attributeName = '_' + attributeName;
+
+				}
+
 				if ( cachedData.attributes.has( attribute ) ) {
 
 					attributes[ attributeName ] = cachedData.attributes.get( attribute );