Actually actually fix dice initial load

This commit is contained in:
Mitchell McCaffrey 2020-05-28 13:56:00 +10:00
parent df57f09080
commit 25d0491374

View File

@ -34,6 +34,19 @@ function DiceTrayOverlay({ isOpen }) {
DiceLoadingContext DiceLoadingContext
); );
// Force render when loading assets
useEffect(() => {
if (isLoading) {
forceSceneRenderRef.current = true;
}
return () => {
if (isLoading) {
forceSceneRenderRef.current = false;
}
};
}, [isLoading]);
// Force render when changing dice tray size
useEffect(() => { useEffect(() => {
const diceTray = diceTrayRef.current; const diceTray = diceTrayRef.current;
let resizeTimout; let resizeTimout;
@ -53,22 +66,11 @@ function DiceTrayOverlay({ isOpen }) {
}, [diceTraySize]); }, [diceTraySize]);
useEffect(() => { useEffect(() => {
let openTimeout;
if (isOpen) { if (isOpen) {
sceneVisibleRef.current = true; sceneVisibleRef.current = true;
// Force scene rendering on open for 1s to ensure dice tray is rendered
forceSceneRenderRef.current = true;
openTimeout = setTimeout(() => {
forceSceneRenderRef.current = false;
}, 1000);
} else { } else {
sceneVisibleRef.current = false; sceneVisibleRef.current = false;
} }
return () => {
if (openTimeout) {
clearTimeout(openTimeout);
}
};
}, [isOpen]); }, [isOpen]);
const handleSceneMount = useCallback(async ({ scene, engine }) => { const handleSceneMount = useCallback(async ({ scene, engine }) => {
@ -102,13 +104,6 @@ function DiceTrayOverlay({ isOpen }) {
let diceTray = new DiceTray("single", scene, shadowGenerator); let diceTray = new DiceTray("single", scene, shadowGenerator);
await diceTray.load(); await diceTray.load();
diceTrayRef.current = diceTray; diceTrayRef.current = diceTray;
// Force rerender on initialize
forceSceneRenderRef.current = true;
setTimeout(() => {
forceSceneRenderRef.current = false;
}, 1000);
assetLoadFinish(); assetLoadFinish();
} }