@react-three/drei 9.80.1 → 9.80.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("three"),t=require("@react-three/fiber");function n(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var c=n(e);exports.useAnimations=function(e,n){const u=c.useRef(),[o]=c.useState((()=>n?n instanceof r.Object3D?{current:n}:n:u)),[a]=c.useState((()=>new r.AnimationMixer(void 0)));c.useLayoutEffect((()=>{o.current=n&&(n instanceof r.Object3D?n:n.current),a._root=o.current}),[n]);const i=c.useRef({}),s=c.useMemo((()=>{const r={};return e.forEach((e=>Object.defineProperty(r,e.name,{enumerable:!0,get(){if(o.current)return i.current[e.name]||(i.current[e.name]=a.clipAction(e,o.current))},configurable:!0}))),{ref:o,clips:e,actions:r,names:e.map((e=>e.name)),mixer:a}}),[e]);return t.useFrame(((e,r)=>a.update(r))),c.useEffect((()=>{const e=o.current;return()=>{i.current={},a.stopAllAction(),Object.values(s.actions).forEach((r=>{e&&a.uncacheAction(r,e)}))}}),[e]),s};
|
package/core/useAnimations.js
CHANGED
|
@@ -9,9 +9,12 @@ function useAnimations(clips, root) {
|
|
|
9
9
|
} : root : ref); // eslint-disable-next-line prettier/prettier
|
|
10
10
|
|
|
11
11
|
const [mixer] = React.useState(() => new AnimationMixer(undefined));
|
|
12
|
-
React.useLayoutEffect(() =>
|
|
12
|
+
React.useLayoutEffect(() => {
|
|
13
|
+
actualRef.current = root && (root instanceof Object3D ? root : root.current);
|
|
14
|
+
mixer._root = actualRef.current;
|
|
15
|
+
}, [root]);
|
|
13
16
|
const lazyActions = React.useRef({});
|
|
14
|
-
const
|
|
17
|
+
const api = React.useMemo(() => {
|
|
15
18
|
const actions = {};
|
|
16
19
|
clips.forEach(clip => Object.defineProperty(actions, clip.name, {
|
|
17
20
|
enumerable: true,
|
|
@@ -31,13 +34,14 @@ function useAnimations(clips, root) {
|
|
|
31
34
|
names: clips.map(c => c.name),
|
|
32
35
|
mixer
|
|
33
36
|
};
|
|
34
|
-
});
|
|
37
|
+
}, [clips]);
|
|
35
38
|
useFrame((state, delta) => mixer.update(delta));
|
|
36
39
|
React.useEffect(() => {
|
|
37
40
|
const currentRoot = actualRef.current;
|
|
38
41
|
return () => {
|
|
39
42
|
// Clean up only when clips change, wipe out lazy actions and uncache clips
|
|
40
43
|
lazyActions.current = {};
|
|
44
|
+
mixer.stopAllAction();
|
|
41
45
|
Object.values(api.actions).forEach(action => {
|
|
42
46
|
if (currentRoot) {
|
|
43
47
|
mixer.uncacheAction(action, currentRoot);
|
|
@@ -45,11 +49,6 @@ function useAnimations(clips, root) {
|
|
|
45
49
|
});
|
|
46
50
|
};
|
|
47
51
|
}, [clips]);
|
|
48
|
-
React.useEffect(() => {
|
|
49
|
-
return () => {
|
|
50
|
-
mixer.stopAllAction();
|
|
51
|
-
};
|
|
52
|
-
}, [mixer]);
|
|
53
52
|
return api;
|
|
54
53
|
}
|
|
55
54
|
|