Skip to content

Commit 9a39450

Browse files
authored
Inspector v2: Add scene explorer command for playing/pausing animation groups (#17005)
This change adds a play/pause command for animation groups. There is already a button in the property grid, but this makes it easy to see at a glance in scene explorer which animation groups are playing and quickly toggle there state. <img width="477" height="168" alt="image" src="https://github.com/user-attachments/assets/8d679a4b-86ec-4df9-a5b0-0e7b4df0ab48" />
1 parent 7093248 commit 9a39450

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/dev/inspector-v2/src/services/panes/scene/animationGroupExplorerService.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ServiceDefinition } from "../../../modularity/serviceDefinition";
22
import type { ISceneContext } from "../../sceneContext";
33
import type { ISceneExplorerService } from "./sceneExplorerService";
44

5-
import { FilmstripRegular, StackRegular } from "@fluentui/react-icons";
5+
import { FilmstripRegular, PauseFilled, PlayFilled, StackRegular } from "@fluentui/react-icons";
66

77
import { AnimationGroup, TargetedAnimation } from "core/Animations/animationGroup";
88
import { Observable } from "core/Misc";
@@ -54,9 +54,45 @@ export const AnimationGroupExplorerServiceDefinition: ServiceDefinition<[], [ISc
5454
getEntityRemovedObservables: () => [scene.onAnimationGroupRemovedObservable],
5555
});
5656

57+
const animationPlayPauseCommandRegistration = sceneExplorerService.addCommand({
58+
predicate: (entity: unknown) => entity instanceof AnimationGroup,
59+
getCommand: (animationGroup) => {
60+
const onChangeObservable = new Observable<void>();
61+
const playObserver = animationGroup.onAnimationGroupPlayObservable.add(() => onChangeObservable.notifyObservers());
62+
const pauseObserver = animationGroup.onAnimationGroupPauseObservable.add(() => onChangeObservable.notifyObservers());
63+
const endObserver = animationGroup.onAnimationGroupEndObservable.add(() => onChangeObservable.notifyObservers());
64+
65+
return {
66+
type: "toggle",
67+
get displayName() {
68+
return `${animationGroup.isPlaying ? "Pause" : "Play"} Animation`;
69+
},
70+
icon: () => (animationGroup.isPlaying ? <PauseFilled /> : <PlayFilled />),
71+
get isEnabled() {
72+
return animationGroup.isPlaying;
73+
},
74+
set isEnabled(enabled: boolean) {
75+
if (enabled) {
76+
animationGroup.play(true);
77+
} else {
78+
animationGroup.pause();
79+
}
80+
},
81+
onChange: onChangeObservable,
82+
dispose: () => {
83+
playObserver.remove();
84+
pauseObserver.remove();
85+
endObserver.remove();
86+
onChangeObservable.clear();
87+
},
88+
};
89+
},
90+
});
91+
5792
return {
5893
dispose: () => {
5994
sectionRegistration.dispose();
95+
animationPlayPauseCommandRegistration.dispose();
6096
},
6197
};
6298
},

packages/dev/inspector-v2/test/app/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Additionally, here are some PGs that are helpful for testing specific features:
33
// Frame graphs: http://localhost:1338/?inspectorv2#9YU4C5#23
44
// Sprites: https://localhost:1338/?inspectorv2#YCY2IL#4
5+
// Animation groups: http://localhost:1338/?inspectorv2#FMAYKS
56

67
import HavokPhysics from "@babylonjs/havok";
78
import type { Nullable } from "core/types";

0 commit comments

Comments
 (0)