Skip to content

Commit 100ef3c

Browse files
committed
update animations
1 parent 52cf031 commit 100ef3c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

libs/soba/misc/src/animations/animations.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DestroyRef, Injector, computed, effect, inject, runInInjectionContext } from '@angular/core';
1+
import { Injector, computed, effect, runInInjectionContext } from '@angular/core';
22
import { assertInjectionContext, injectBeforeRender, injectNgtRef, type NgtRef } from 'angular-three';
33
import * as THREE from 'three';
44

@@ -30,24 +30,11 @@ export function injectNgtsAnimations(
3030
const clips = [] as THREE.AnimationClip[];
3131
const names = [] as string[];
3232

33-
inject(DestroyRef).onDestroy(() => {
34-
// clear cached
35-
cached = {};
36-
// uncache actions
37-
Object.values(actions).forEach((action) => {
38-
mixer.uncacheAction(action as unknown as THREE.AnimationClip, object!);
39-
});
40-
// stop all actions
41-
mixer.stopAllAction();
42-
43-
object = null;
44-
});
45-
4633
injectBeforeRender(({ delta }) => mixer.update(delta));
4734

4835
const ready = computed(() => !!actualRef.nativeElement && !!animationsFactory().length);
4936

50-
effect(() => {
37+
effect((onCleanup) => {
5138
const actual = actualRef.nativeElement;
5239
if (!actual) return;
5340
object = actual;
@@ -70,6 +57,19 @@ export function injectNgtsAnimations(
7057
actions[clip.name].play();
7158
}
7259
}
60+
61+
onCleanup(() => {
62+
// clear cached
63+
cached = {};
64+
// stop all actions
65+
mixer.stopAllAction();
66+
// uncache actions
67+
Object.values(actions).forEach((action) => {
68+
mixer.uncacheAction(action as unknown as THREE.AnimationClip, object!);
69+
});
70+
71+
object = null;
72+
});
7373
});
7474

7575
return { ref: actualRef, actions, mixer, names, clips, ready };

libs/soba/src/staging/backdrop.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default {
5454
};
5555

5656
const canvasOptions = makeCanvasOptions({
57-
camera: { position: [-1, 2, 4], fov: 35 },
57+
camera: { position: [-1, 2, 5], fov: 35 },
5858
controls: false,
5959
compoundPrefixes: ['backdrop-robot'],
6060
useLegacyLights: true,

0 commit comments

Comments
 (0)