From 2db8a4a9e68c874f78ede4dc0469458f8a0c3be4 Mon Sep 17 00:00:00 2001 From: Temdog007 Date: Sun, 3 Feb 2019 03:42:12 -0700 Subject: [PATCH] Fixed coding style --- editor/js/Editor.js | 6 +- editor/js/Loader.js | 14 ++--- editor/js/Sidebar.Animation.js | 100 ++++++++++++++++++--------------- 3 files changed, 67 insertions(+), 53 deletions(-) diff --git a/editor/js/Editor.js b/editor/js/Editor.js index 702eb4bb02..7eea8dfb6e 100644 --- a/editor/js/Editor.js +++ b/editor/js/Editor.js @@ -240,8 +240,10 @@ Editor.prototype = { }, - addAnimation: function(result) { - this.animations[result.scene.uuid] = result.animations; + addAnimation: function ( result ) { + + this.animations[ result.scene.uuid ] = result.animations; + }, // diff --git a/editor/js/Loader.js b/editor/js/Loader.js index 3c70205a4f..d792bbf849 100644 --- a/editor/js/Loader.js +++ b/editor/js/Loader.js @@ -34,7 +34,7 @@ var Loader = function ( editor ) { for ( var i = 0; i < files.length; i ++ ) { - scope.loadFile( files[ i ], manager ) ; + scope.loadFile( files[ i ], manager ); } @@ -150,7 +150,7 @@ var Loader = function ( editor ) { stream.offset = 0; var loader = new THREE.CTMLoader(); - loader.createModel( new CTM.File( stream ), function( geometry ) { + loader.createModel( new CTM.File( stream ), function ( geometry ) { geometry.sourceType = "ctm"; geometry.sourceFile = file.name; @@ -216,7 +216,7 @@ var Loader = function ( editor ) { loader.parse( contents, '', function ( result ) { result.scene.name = filename; - editor.addAnimation(result); + editor.addAnimation( result ); editor.execute( new AddObjectCommand( result.scene ) ); } ); @@ -247,7 +247,7 @@ var Loader = function ( editor ) { loader.parse( contents, '', function ( result ) { result.scene.name = filename; - editor.addAnimation(result); + editor.addAnimation( result ); editor.execute( new AddObjectCommand( result.scene ) ); } ); @@ -452,7 +452,7 @@ var Loader = function ( editor ) { var group = new THREE.Group(); group.scale.multiplyScalar( 0.1 ); - group.scale.y *= -1; + group.scale.y *= - 1; for ( var i = 0; i < paths.length; i ++ ) { @@ -680,7 +680,7 @@ var Loader = function ( editor ) { var loader = new THREE.GLTFLoader(); loader.parse( file.asArrayBuffer(), '', function ( result ) { - editor.addAnimation(result); + editor.addAnimation( result ); editor.execute( new AddObjectCommand( result.scene ) ); } ); @@ -692,7 +692,7 @@ var Loader = function ( editor ) { var loader = new THREE.GLTFLoader( manager ); loader.parse( file.asText(), '', function ( result ) { - editor.addAnimation(result); + editor.addAnimation( result ); editor.execute( new AddObjectCommand( result.scene ) ); } ); diff --git a/editor/js/Sidebar.Animation.js b/editor/js/Sidebar.Animation.js index 2bd0c02b1f..78ad54abbe 100644 --- a/editor/js/Sidebar.Animation.js +++ b/editor/js/Sidebar.Animation.js @@ -9,61 +9,71 @@ Sidebar.Animation = function ( editor ) { var renderer = null; signals.rendererChanged.add( function ( newRenderer ) { + renderer = newRenderer; - }); - signals.objectSelected.add(function(object) - { + } ); + + signals.objectSelected.add( function ( object ) { + var uuid = object !== null ? object.uuid : ''; - var animations = editor.animations[uuid]; - if(animations !== undefined) - { - container.setDisplay(''); + var animations = editor.animations[ uuid ]; + if ( animations !== undefined ) { + + container.setDisplay( '' ); - mixer = new THREE.AnimationMixer(object); + mixer = new THREE.AnimationMixer( object ); var options = {}; - for(var animation of animations) - { - options[animation.name] = animation.name; + for ( var animation of animations ) { + + options[ animation.name ] = animation.name; + + var action = mixer.clipAction( animation ); + actions[ animation.name ] = action; - var action = mixer.clipAction(animation); - actions[animation.name] = action; } - animationsSelect.setOptions(options); - } - else - { - container.setDisplay('none'); + animationsSelect.setOptions( options ); + + } else { + + container.setDisplay( 'none' ); + } - }); + + } ); var mixer, currentAnimation, actions = {}; var clock = new THREE.Clock(); - function updateAnimation() - { - if(mixer !== undefined && renderer !== null) - { + function updateAnimation() { + + if ( mixer !== undefined && renderer !== null ) { + var dt = clock.getDelta(); - mixer.update(dt); - if(currentAnimation !== undefined && currentAnimation.isRunning()) - { - requestAnimationFrame(updateAnimation); - renderer.render(editor.scene, editor.camera); - } - else - { + mixer.update( dt ); + if ( currentAnimation !== undefined && currentAnimation.isRunning() ) { + + requestAnimationFrame( updateAnimation ); + renderer.render( editor.scene, editor.camera ); + + } else { + currentAnimation = undefined; + } + } + } - function stopAnimations() - { - if(mixer !== undefined) - { + function stopAnimations() { + + if ( mixer !== undefined ) { + mixer.stopAllAction(); + } + } var container = new UI.Panel(); @@ -71,21 +81,23 @@ Sidebar.Animation = function ( editor ) { container.add( new UI.Text( 'Animation' ).setTextTransform( 'uppercase' ) ); - var div = new UI.Div().setMarginLeft('90px'); - container.add(div); + var div = new UI.Div().setMarginLeft( '90px' ); + container.add( div ); + + div.add( new UI.Button( "Stop" ).setFontSize( '12px' ).onClick( stopAnimations ), new UI.Break() ); - div.add(new UI.Button("Stop").setFontSize('12px').onClick(stopAnimations), new UI.Break()); + var animationsSelect = new UI.Select().setFontSize( '12px' ).setMarginTop( '10px' ).onChange( function () { + + currentAnimation = actions[ animationsSelect.getValue() ]; + if ( currentAnimation !== undefined ) { - var animationsSelect = new UI.Select().setFontSize('12px').setMarginTop('10px').onChange(function() - { - currentAnimation = actions[animationsSelect.getValue()]; - if(currentAnimation !== undefined) - { stopAnimations(); currentAnimation.play(); updateAnimation(); + } - }); + + } ); div.add( animationsSelect ); return container; -- GitLab