Skip to content

Commit

Permalink
GLTFExporter: Fix regression in normalized attributes. (#25076)
Browse files Browse the repository at this point in the history
NOTE: Some vertex attributes require KHR_mesh_quantization
for normalized values, and this is not supported yet. See:
#20474
  • Loading branch information
donmccurdy authored Dec 5, 2022
1 parent b6b5bb4 commit fe11649
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) );

}

}

Expand Down

0 comments on commit fe11649

Please sign in to comment.