1 | Sidebar.Animation = function ( editor ) {
|
---|
2 |
|
---|
3 | var signals = editor.signals;
|
---|
4 |
|
---|
5 | var options = {};
|
---|
6 | var possibleAnimations = {};
|
---|
7 |
|
---|
8 | var container = new UI.Panel();
|
---|
9 | container.setDisplay( 'none' );
|
---|
10 |
|
---|
11 | container.add( new UI.Text( 'Animation' ) );
|
---|
12 | container.add( new UI.Break(), new UI.Break() );
|
---|
13 |
|
---|
14 | var AnimationsRow = new UI.Panel();
|
---|
15 | var Animations = new UI.Select().setOptions( options ).setWidth( '130px' ).setColor( '#444' ).setFontSize( '12px' );
|
---|
16 | AnimationsRow.add( new UI.Text( 'animations' ).setWidth( '90px' ) );
|
---|
17 | AnimationsRow.add( Animations );
|
---|
18 | container.add( AnimationsRow );
|
---|
19 | container.add( new UI.Break() );
|
---|
20 |
|
---|
21 | var PlayRow = new UI.Panel();
|
---|
22 | var playButton = new UI.Button().setLabel("Play").onClick(play);
|
---|
23 | PlayRow.add( playButton );
|
---|
24 | container.add( PlayRow );
|
---|
25 | container.add( new UI.Break() );
|
---|
26 |
|
---|
27 | function play() {
|
---|
28 |
|
---|
29 | var value = Animations.getValue();
|
---|
30 |
|
---|
31 | if ( possibleAnimations[ value ] ) {
|
---|
32 |
|
---|
33 | var anims = possibleAnimations[value]
|
---|
34 |
|
---|
35 | for ( var i = 0; i < anims.length; i ++ ) {
|
---|
36 |
|
---|
37 | anims[ i ].play();
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | signals.playAnimations.dispatch( anims );
|
---|
42 |
|
---|
43 | };
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | signals.objectAdded.add( function ( object ) {
|
---|
48 |
|
---|
49 | if ( object instanceof THREE.Mesh ) {
|
---|
50 |
|
---|
51 | if ( object.geometry && object.geometry.animation ) {
|
---|
52 |
|
---|
53 | var name = object.geometry.animation.name;
|
---|
54 | options[name] = name
|
---|
55 |
|
---|
56 | Animations.setOptions( options );
|
---|
57 |
|
---|
58 | THREE.AnimationHandler.add( object.geometry.animation );
|
---|
59 |
|
---|
60 | var animation = new THREE.Animation( object, name, THREE.AnimationHandler.CATMULLROM );
|
---|
61 |
|
---|
62 | if ( possibleAnimations[ name ] ){
|
---|
63 |
|
---|
64 | possibleAnimations[ name ].push( animation );
|
---|
65 |
|
---|
66 | } else {
|
---|
67 |
|
---|
68 | possibleAnimations[ name ] = [ animation ];
|
---|
69 |
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | }
|
---|
75 |
|
---|
76 | } );
|
---|
77 |
|
---|
78 | signals.objectSelected.add( function ( object ) {
|
---|
79 |
|
---|
80 | if ( object && object.geometry && object.geometry.animation ) {
|
---|
81 |
|
---|
82 | container.setDisplay( 'block' );
|
---|
83 |
|
---|
84 | } else {
|
---|
85 |
|
---|
86 | container.setDisplay( 'none' );
|
---|
87 |
|
---|
88 | }
|
---|
89 |
|
---|
90 | } );
|
---|
91 |
|
---|
92 | return container;
|
---|
93 |
|
---|
94 | }
|
---|