123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { UIPanel, UIBreak, UISelect, UIButton, UIText, UINumber, UIRow } from './libs/ui.js';
- function SidebarAnimation( editor ) {
- var strings = editor.strings;
- var signals = editor.signals;
- var mixer = editor.mixer;
- var actions = {};
- signals.objectSelected.add( function ( object ) {
- if ( object !== null && object.animations.length > 0 ) {
- var animations = object.animations;
- container.setDisplay( '' );
- var options = {};
- var firstAnimation;
- for ( var animation of animations ) {
- if ( firstAnimation === undefined ) firstAnimation = animation.name;
- actions[ animation.name ] = mixer.clipAction( animation, object );
- options[ animation.name ] = animation.name;
- }
- animationsSelect.setOptions( options );
- animationsSelect.setValue( firstAnimation );
- mixerTimeScaleNumber.setValue( mixer.timeScale );
- } else {
- container.setDisplay( 'none' );
- }
- } );
- signals.objectRemoved.add( function ( object ) {
- if ( object !== null && object.animations.length > 0 ) {
- mixer.uncacheRoot( object );
- }
- } );
- function playAction() {
- actions[ animationsSelect.getValue() ].play();
- }
- function stopAction() {
- actions[ animationsSelect.getValue() ].stop();
- signals.animationStopped.dispatch();
- }
- function changeTimeScale() {
- mixer.timeScale = mixerTimeScaleNumber.getValue();
- }
- var container = new UIPanel();
- container.setDisplay( 'none' );
- container.add( new UIText( strings.getKey( 'sidebar/animations' ) ).setTextTransform( 'uppercase' ) );
- container.add( new UIBreak() );
- container.add( new UIBreak() );
- //
- var animationsRow = new UIRow();
- var animationsSelect = new UISelect().setFontSize( '12px' );
- animationsRow.add( animationsSelect );
- animationsRow.add( new UIButton( strings.getKey( 'sidebar/animations/play' ) ).setMarginLeft( '4px' ).onClick( playAction ) );
- animationsRow.add( new UIButton( strings.getKey( 'sidebar/animations/stop' ) ).setMarginLeft( '4px' ).onClick( stopAction ) );
- container.add( animationsRow );
- //
- var mixerTimeScaleRow = new UIRow();
- var mixerTimeScaleNumber = new UINumber( 0.5 ).setWidth( '60px' ).setRange( - 10, 10 ).onChange( changeTimeScale );
- mixerTimeScaleRow.add( new UIText( strings.getKey( 'sidebar/animations/timescale' ) ).setWidth( '90px' ) );
- mixerTimeScaleRow.add( mixerTimeScaleNumber );
- container.add( mixerTimeScaleRow );
- return container;
- }
- export { SidebarAnimation };
|