瀏覽代碼

Editor: Ensure clips are optimized before exporting to glTF. (#27529)

Michael Herzog 1 年之前
父節點
當前提交
222ab9a09e
共有 1 個文件被更改,包括 18 次插入2 次删除
  1. 18 2
      editor/js/Menubar.File.js

+ 18 - 2
editor/js/Menubar.File.js

@@ -225,6 +225,14 @@ function MenubarFile( editor ) {
 		const scene = editor.scene;
 		const scene = editor.scene;
 		const animations = getAnimations( scene );
 		const animations = getAnimations( scene );
 
 
+		const optimizedAnimations = [];
+
+		for ( const animation of animations ) {
+
+			optimizedAnimations.push( animation.clone().optimize() );
+
+		}
+
 		const { GLTFExporter } = await import( 'three/addons/exporters/GLTFExporter.js' );
 		const { GLTFExporter } = await import( 'three/addons/exporters/GLTFExporter.js' );
 
 
 		const exporter = new GLTFExporter();
 		const exporter = new GLTFExporter();
@@ -233,7 +241,7 @@ function MenubarFile( editor ) {
 
 
 			saveArrayBuffer( result, 'scene.glb' );
 			saveArrayBuffer( result, 'scene.glb' );
 
 
-		}, undefined, { binary: true, animations: animations } );
+		}, undefined, { binary: true, animations: optimizedAnimations } );
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
@@ -248,6 +256,14 @@ function MenubarFile( editor ) {
 		const scene = editor.scene;
 		const scene = editor.scene;
 		const animations = getAnimations( scene );
 		const animations = getAnimations( scene );
 
 
+		const optimizedAnimations = [];
+
+		for ( const animation of animations ) {
+
+			optimizedAnimations.push( animation.clone().optimize() );
+
+		}
+
 		const { GLTFExporter } = await import( 'three/addons/exporters/GLTFExporter.js' );
 		const { GLTFExporter } = await import( 'three/addons/exporters/GLTFExporter.js' );
 
 
 		const exporter = new GLTFExporter();
 		const exporter = new GLTFExporter();
@@ -256,7 +272,7 @@ function MenubarFile( editor ) {
 
 
 			saveString( JSON.stringify( result, null, 2 ), 'scene.gltf' );
 			saveString( JSON.stringify( result, null, 2 ), 'scene.gltf' );
 
 
-		}, undefined, { animations: animations } );
+		}, undefined, { animations: optimizedAnimations } );
 
 
 
 
 	} );
 	} );