Skip to content

Commit 707b44a

Browse files
authored
Merge pull request #12967 from takahirox/GLTFExporterMorph
GLTFExporter Fix Morph
2 parents 7ff2ee0 + 28f5d74 commit 707b44a

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

examples/js/exporters/GLTFExporter.js

+40-2
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,49 @@ THREE.GLTFExporter.prototype = {
830830

831831
var target = {};
832832

833+
var warned = false;
834+
833835
for ( var attributeName in geometry.morphAttributes ) {
834836

837+
// glTF 2.0 morph supports only POSITION/NORMAL/TANGENT.
838+
// Three.js doesn't support TANGENT yet.
839+
840+
if ( attributeName !== 'position' && attributeName !== 'normal' ) {
841+
842+
if ( ! warned ) {
843+
844+
console.warn( 'GLTFExporter: Only POSITION and NORMAL morph are supported.' );
845+
warned = true;
846+
847+
}
848+
849+
continue;
850+
851+
}
852+
835853
var attribute = geometry.morphAttributes[ attributeName ][ i ];
836-
attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase();
837-
target[ attributeName ] = processAccessor( attribute, geometry );
854+
855+
// Three.js morph attribute has absolute values while the one of glTF has relative values.
856+
//
857+
// glTF 2.0 Specification:
858+
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#morph-targets
859+
860+
var baseAttribute = geometry.attributes[ attributeName ];
861+
// Clones attribute not to override
862+
var relativeAttribute = attribute.clone();
863+
864+
for ( var j = 0, jl = attribute.count; j < jl; j ++ ) {
865+
866+
relativeAttribute.setXYZ(
867+
j,
868+
attribute.getX( j ) - baseAttribute.getX( j ),
869+
attribute.getY( j ) - baseAttribute.getY( j ),
870+
attribute.getZ( j ) - baseAttribute.getZ( j )
871+
);
872+
873+
}
874+
875+
target[ attributeName.toUpperCase() ] = processAccessor( relativeAttribute, geometry );
838876

839877
}
840878

0 commit comments

Comments
 (0)