Bladeren bron

Update GLTF exporter and BufferGeometryUtils to support relative morphs

The code in GLTF exporter is probably suboptimal - it's not clear that
we need to clone the attribute if it's already relative.
Arseny Kapoulkine 5 jaren geleden
bovenliggende
commit
4e3cb37e32

+ 12 - 8
examples/js/exporters/GLTFExporter.js

@@ -1339,14 +1339,18 @@ THREE.GLTFExporter.prototype = {
 						// Clones attribute not to override
 						var relativeAttribute = attribute.clone();
 
-						for ( var 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 )
-							);
+						if ( !geometry.morphTargetsRelative ) {
+
+							for ( var 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 )
+									);
+
+							}
 
 						}
 

+ 4 - 0
examples/js/utils/BufferGeometryUtils.js

@@ -199,6 +199,8 @@ THREE.BufferGeometryUtils = {
 		var attributes = {};
 		var morphAttributes = {};
 
+		var morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
+
 		var mergedGeometry = new THREE.BufferGeometry();
 
 		var offset = 0;
@@ -225,6 +227,8 @@ THREE.BufferGeometryUtils = {
 
 			// gather morph attributes, exit early if they're different
 
+			if ( morphTargetsRelative !== geometry.morphTargetsRelative ) return null;
+
 			for ( var name in geometry.morphAttributes ) {
 
 				if ( ! morphAttributesUsed.has( name ) ) return null;

+ 12 - 8
examples/jsm/exporters/GLTFExporter.js

@@ -1363,14 +1363,18 @@ GLTFExporter.prototype = {
 						// Clones attribute not to override
 						var relativeAttribute = attribute.clone();
 
-						for ( var 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 )
-							);
+						if ( !geometry.morphTargetsRelative ) {
+
+							for ( var 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 )
+									);
+
+							}
 
 						}
 

+ 4 - 0
examples/jsm/utils/BufferGeometryUtils.js

@@ -208,6 +208,8 @@ var BufferGeometryUtils = {
 		var attributes = {};
 		var morphAttributes = {};
 
+		var morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
+
 		var mergedGeometry = new BufferGeometry();
 
 		var offset = 0;
@@ -234,6 +236,8 @@ var BufferGeometryUtils = {
 
 			// gather morph attributes, exit early if they're different
 
+			if ( morphTargetsRelative !== geometry.morphTargetsRelative ) return null;
+
 			for ( var name in geometry.morphAttributes ) {
 
 				if ( ! morphAttributesUsed.has( name ) ) return null;