From 16615e6663cb31037557e104a49db6eecfae2161 Mon Sep 17 00:00:00 2001 From: Gary Oberbrunner Date: Fri, 15 Mar 2019 18:04:51 -0400 Subject: [PATCH] GLTFExporter: prefix all geom attributes except official ones According to the spec, all custom vertex attributes must start with _. --- examples/js/exporters/GLTFExporter.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index d233660332..01c2cdca0a 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -1165,6 +1165,30 @@ THREE.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+$/, + ]; + + 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 ) ) { attributes[ attributeName ] = cachedData.attributes.get( attribute ); -- GitLab