From fe11649571b0ddce31f0e16d41bbb9aea13de5e7 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Mon, 5 Dec 2022 00:22:09 -0500 Subject: [PATCH] GLTFExporter: Fix regression in normalized attributes. (#25076) NOTE: Some vertex attributes require KHR_mesh_quantization for normalized values, and this is not supported yet. See: https://github.com/mrdoob/three.js/issues/20474 --- examples/jsm/exporters/GLTFExporter.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/jsm/exporters/GLTFExporter.js b/examples/jsm/exporters/GLTFExporter.js index b6d76de898afc1..eb4222534d7b31 100644 --- a/examples/jsm/exporters/GLTFExporter.js +++ b/examples/jsm/exporters/GLTFExporter.js @@ -269,6 +269,12 @@ function getMinMax( attribute, start, count ) { else if ( a === 2 ) value = attribute.getZ( i ); else if ( a === 3 ) value = attribute.getW( i ); + if ( attribute.normalized === true ) { + + value = MathUtils.normalize( value, attribute.array ); + + } + } output.min[ a ] = Math.min( output.min[ a ], value ); @@ -876,6 +882,12 @@ class GLTFWriter { else if ( a === 2 ) value = attribute.getZ( i ); else if ( a === 3 ) value = attribute.getW( i ); + if ( attribute.normalized === true ) { + + value = MathUtils.normalize( value, attribute.array ); + + } + } if ( componentType === WEBGL_CONSTANTS.FLOAT ) { @@ -1606,12 +1618,14 @@ class GLTFWriter { for ( let j = 0, jl = attribute.count; j < jl; j ++ ) { - relativeAttribute.setXYZ( - j, - attribute.getX( j ) - baseAttribute.getX( j ), - attribute.getY( j ) - baseAttribute.getY( j ), - attribute.getZ( j ) - baseAttribute.getZ( j ) - ); + for ( let a = 0; a < attribute.itemSize; a ++ ) { + + if ( a === 0 ) relativeAttribute.setX( j, attribute.getX( j ) - baseAttribute.getX( j ) ); + if ( a === 1 ) relativeAttribute.setY( j, attribute.getY( j ) - baseAttribute.getY( j ) ); + if ( a === 2 ) relativeAttribute.setZ( j, attribute.getZ( j ) - baseAttribute.getZ( j ) ); + if ( a === 3 ) relativeAttribute.setW( j, attribute.getW( j ) - baseAttribute.getW( j ) ); + + } }