Skip to content

Commit 320e432

Browse files
authored
Editor: Improve animation panel. (#33110)
1 parent 051fbfd commit 320e432

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

editor/js/Animation.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { UIPanel, UIText, UIButton } from './libs/ui.js';
1+
import { UIPanel, UIText, UIButton, UINumber } from './libs/ui.js';
22

33
import { AnimationPathHelper } from 'three/addons/helpers/AnimationPathHelper.js';
44

55
function Animation( editor ) {
66

77
const signals = editor.signals;
8+
const strings = editor.strings;
9+
const mixer = editor.mixer;
810

911
const container = new UIPanel();
1012
container.setId( 'animation' );
@@ -33,9 +35,9 @@ function Animation( editor ) {
3335
container.add( controlsPanel );
3436

3537
// SVG icons
36-
const playIcon = `<svg width="12" height="12" viewBox="0 0 12 12"><path d="M3 1.5v9l7-4.5z" fill="currentColor"/></svg>`;
37-
const pauseIcon = `<svg width="12" height="12" viewBox="0 0 12 12"><path d="M2 1h3v10H2zM7 1h3v10H7z" fill="currentColor"/></svg>`;
38-
const stopIcon = `<svg width="12" height="12" viewBox="0 0 12 12"><rect x="2" y="2" width="8" height="8" fill="currentColor"/></svg>`;
38+
const playIcon = '<svg width="12" height="12" viewBox="0 0 12 12"><path d="M3 1.5v9l7-4.5z" fill="currentColor"/></svg>';
39+
const pauseIcon = '<svg width="12" height="12" viewBox="0 0 12 12"><path d="M2 1h3v10H2zM7 1h3v10H7z" fill="currentColor"/></svg>';
40+
const stopIcon = '<svg width="12" height="12" viewBox="0 0 12 12"><rect x="2" y="2" width="8" height="8" fill="currentColor"/></svg>';
3941

4042
const playButton = new UIButton();
4143
playButton.dom.innerHTML = playIcon;
@@ -130,6 +132,17 @@ function Animation( editor ) {
130132
const durationText = new UIText( '0.00' ).setWidth( '36px' );
131133
timeDisplay.appendChild( durationText.dom );
132134

135+
// Time Scale
136+
const mixerTimeScaleNumber = new UINumber( 1 ).setWidth( '60px' ).setRange( - 10, 10 );
137+
mixerTimeScaleNumber.onChange( function () {
138+
139+
mixer.timeScale = mixerTimeScaleNumber.getValue();
140+
141+
} );
142+
143+
controlsPanel.add( new UIText( strings.getKey( 'sidebar/animations/timescale' ) ).setClass( 'Label' ) );
144+
controlsPanel.add( mixerTimeScaleNumber );
145+
133146
// Timeline area with track rows
134147
const timelineArea = document.createElement( 'div' );
135148
timelineArea.style.flex = '1';
@@ -440,6 +453,7 @@ function Animation( editor ) {
440453
trackTimeline.appendChild( keyframe );
441454

442455
}
456+
443457
trackRow.appendChild( trackTimeline );
444458

445459
// Hover on position tracks to show path helper
@@ -485,13 +499,27 @@ function Animation( editor ) {
485499

486500
}
487501

488-
// Select clip without playing
489-
currentClip = clip;
490-
currentRoot = root;
491-
currentAction = editor.mixer.clipAction( clip, root );
502+
if ( currentClip === clip ) {
492503

493-
// Update duration display
494-
durationText.setValue( clip.duration.toFixed( 2 ) );
504+
// Unselect clip
505+
currentAction = null;
506+
currentClip = null;
507+
currentRoot = null;
508+
509+
timeText.setValue( '0.00' );
510+
durationText.setValue( '0.00' );
511+
512+
} else {
513+
514+
// Select clip without playing
515+
currentClip = clip;
516+
currentRoot = root;
517+
currentAction = editor.mixer.clipAction( clip, root );
518+
519+
// Update duration display
520+
durationText.setValue( clip.duration.toFixed( 2 ) );
521+
522+
}
495523

496524
}
497525

editor/js/commands/SetSceneCommand.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SetSceneCommand extends Command {
2424
this.cmdArray.push( new SetUuidCommand( this.editor, this.editor.scene, scene.uuid ) );
2525
this.cmdArray.push( new SetValueCommand( this.editor, this.editor.scene, 'name', scene.name ) );
2626
this.cmdArray.push( new SetValueCommand( this.editor, this.editor.scene, 'userData', JSON.parse( JSON.stringify( scene.userData ) ) ) );
27+
this.cmdArray.push( new SetValueCommand( this.editor, this.editor.scene, 'animations', scene.animations ) );
2728

2829
while ( scene.children.length > 0 ) {
2930

0 commit comments

Comments
 (0)