Browse Source

Allow animation speed to be set

Temdog007 6 years ago
parent
commit
8481b49632
3 changed files with 25 additions and 15 deletions
  1. 2 2
      editor/js/Editor.js
  2. 14 10
      editor/js/Loader.js
  3. 9 3
      editor/js/Sidebar.Animation.js

+ 2 - 2
editor/js/Editor.js

@@ -240,9 +240,9 @@ Editor.prototype = {
 
 	},
 
-	addAnimation: function ( result ) {
+	addAnimation: function ( object, animations ) {
 
-		this.animations[ result.scene.uuid ] = result.animations;
+		this.animations[ object.uuid ] = animations;
 
 	},
 

+ 14 - 10
editor/js/Loader.js

@@ -215,9 +215,10 @@ var Loader = function ( editor ) {
 					loader.setDRACOLoader( new THREE.DRACOLoader() );
 					loader.parse( contents, '', function ( result ) {
 
-						result.scene.name = filename;
-						editor.addAnimation( result );
-						editor.execute( new AddObjectCommand( result.scene ) );
+						var scene = result.scene;
+						scene.name = filename;
+						editor.addAnimation( scene, result.animations );
+						editor.execute( new AddObjectCommand( scene ) );
 
 					} );
 
@@ -246,9 +247,10 @@ var Loader = function ( editor ) {
 
 					loader.parse( contents, '', function ( result ) {
 
-						result.scene.name = filename;
-						editor.addAnimation( result );
-						editor.execute( new AddObjectCommand( result.scene ) );
+						var scene = result.scene;
+						scene.name = filename;
+						editor.addAnimation( scene, result.animations );
+						editor.execute( new AddObjectCommand( scene ) );
 
 					} );
 
@@ -680,8 +682,9 @@ var Loader = function ( editor ) {
 					var loader = new THREE.GLTFLoader();
 					loader.parse( file.asArrayBuffer(), '', function ( result ) {
 
-						editor.addAnimation( result );
-						editor.execute( new AddObjectCommand( result.scene ) );
+						var scene = result.scene;
+						editor.addAnimation( scene, result.animations );
+						editor.execute( new AddObjectCommand( scene ) );
 
 					} );
 
@@ -692,8 +695,9 @@ var Loader = function ( editor ) {
 					var loader = new THREE.GLTFLoader( manager );
 					loader.parse( file.asText(), '', function ( result ) {
 
-						editor.addAnimation( result );
-						editor.execute( new AddObjectCommand( result.scene ) );
+						var scene = result.scene;
+						editor.addAnimation( scene, result.animations );
+						editor.execute( new AddObjectCommand( scene ) );
 
 					} );
 

+ 9 - 3
editor/js/Sidebar.Animation.js

@@ -50,7 +50,7 @@ Sidebar.Animation = function ( editor ) {
 		if ( mixer !== undefined && renderer !== null ) {
 
 			var dt = clock.getDelta();
-			mixer.update( dt );
+			mixer.update( dt * speed.getValue() );
 			if ( currentAnimation !== undefined && currentAnimation.isRunning() ) {
 
 				requestAnimationFrame( updateAnimation );
@@ -101,8 +101,14 @@ Sidebar.Animation = function ( editor ) {
 
 	div.add( new UI.Button( "Stop" ).setFontSize( '12px' ).onClick( stopAnimations ), new UI.Break() );
 
-	var animationsSelect = new UI.Select().setFontSize( '12px' ).setMarginTop( '10px' );
-	div.add( animationsSelect );
+	var animationsSelect = new UI.Select().setFontSize( '12px' ).setMarginTop( '10px' ).setMarginBottom( '10px' );
+	div.add( animationsSelect, new UI.Break() );
+
+	var row = new UI.Row();
+	div.add( row );
+
+	var speed = new UI.Number( 1 ).setRange( 0.25, 2 ).setStep( 0.5 ).setMarginLeft( '10px' );
+	row.add( new UI.Text( "Speed" ), speed );
 
 	return container;