Skip to content

Commit d745649

Browse files
committed
[FIX] Show all animations even when they have duplicate names
1 parent f3b4eda commit d745649

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/viewer.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,24 @@ class Viewer {
18101810

18111811
// rebuild the animation state graph
18121812
private rebuildAnimTracks() {
1813+
// Build unique display names for animations (handle duplicate names)
1814+
const nameCounts = new Map<string, number>();
1815+
this.animTracks.forEach((t: any) => {
1816+
nameCounts.set(t.name, (nameCounts.get(t.name) ?? 0) + 1);
1817+
});
1818+
1819+
// If there are duplicates, append index to make names unique
1820+
const nameIndices = new Map<string, number>();
1821+
const uniqueDisplayNames: string[] = this.animTracks.map((t: any) => {
1822+
const name = t.name;
1823+
if (nameCounts.get(name) > 1) {
1824+
const index = nameIndices.get(name) ?? 0;
1825+
nameIndices.set(name, index + 1);
1826+
return `${name} (${index + 1})`;
1827+
}
1828+
return name;
1829+
});
1830+
18131831
this.entities.forEach((entity) => {
18141832
// create the anim component if there isn't one already
18151833
if (!entity.anim) {
@@ -1834,7 +1852,8 @@ class Viewer {
18341852
]);
18351853
const path = `track_${i}`;
18361854
entity.anim.assignAnimation(path, t);
1837-
this.animationMap[t.name] = path;
1855+
// Use unique display name as key to avoid overwriting animations with the same name
1856+
this.animationMap[uniqueDisplayNames[i]] = path;
18381857
});
18391858
// if the user has selected to play all tracks in succession, then transition to the next track after a set amount of loops
18401859
entity.anim.on('transition', (e) => {

0 commit comments

Comments
 (0)