瀏覽代碼

Merge pull request #13366 from takahirox/GLTFExporterTargetNames

GLTFExpporter: Support morph targetNames
Mr.doob 7 年之前
父節點
當前提交
7ff2ee0074
共有 1 個文件被更改,包括 21 次插入0 次删除
  1. 21 0
      examples/js/exporters/GLTFExporter.js

+ 21 - 0
examples/js/exporters/GLTFExporter.js

@@ -811,6 +811,19 @@ THREE.GLTFExporter.prototype = {
 			if ( mesh.morphTargetInfluences !== undefined && mesh.morphTargetInfluences.length > 0 ) {
 
 				var weights = [];
+				var targetNames = [];
+				var reverseDictionary = {};
+
+				if ( mesh.morphTargetDictionary !== undefined ) {
+
+					for ( var key in mesh.morphTargetDictionary ) {
+
+						reverseDictionary[ mesh.morphTargetDictionary[ key ] ] = key;
+
+					}
+
+				}
+
 				gltfMesh.primitives[ 0 ].targets = [];
 
 				for ( var i = 0; i < mesh.morphTargetInfluences.length; ++ i ) {
@@ -828,11 +841,19 @@ THREE.GLTFExporter.prototype = {
 					gltfMesh.primitives[ 0 ].targets.push( target );
 
 					weights.push( mesh.morphTargetInfluences[ i ] );
+					if ( mesh.morphTargetDictionary !== undefined ) targetNames.push( reverseDictionary[ i ] );
 
 				}
 
 				gltfMesh.weights = weights;
 
+				if ( targetNames.length > 0 ) {
+
+					gltfMesh.extras = {};
+					gltfMesh.extras.targetNames = targetNames;
+
+				}
+
 			}
 
 			outputJSON.meshes.push( gltfMesh );