瀏覽代碼

GLTFExporter: prefix all geom attributes except official ones

According to the spec, all custom vertex attributes must start with _.
Gary Oberbrunner 6 年之前
父節點
當前提交
16615e6663
共有 1 個文件被更改,包括 24 次插入0 次删除
  1. 24 0
      examples/js/exporters/GLTFExporter.js

+ 24 - 0
examples/js/exporters/GLTFExporter.js

@@ -1165,6 +1165,30 @@ THREE.GLTFExporter.prototype = {
 				var attribute = geometry.attributes[ attributeName ];
 				var attribute = geometry.attributes[ attributeName ];
 				attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase();
 				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+$/,
+				];
+
+				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
+				}
+
 				if ( cachedData.attributes.has( attribute ) ) {
 				if ( cachedData.attributes.has( attribute ) ) {
 
 
 					attributes[ attributeName ] = cachedData.attributes.get( attribute );
 					attributes[ attributeName ] = cachedData.attributes.get( attribute );