// luma.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import { luma } from '@luma.gl/core'; import { AnimationLoop } from "./animation-loop.js"; /** Instantiates and runs the render loop */ export function makeAnimationLoop(AnimationLoopTemplateCtor, props) { let renderLoop = null; const device = props?.device || luma.createDevice(); // Create an animation loop; const animationLoop = new AnimationLoop({ ...props, device, async onInitialize(animationProps) { // @ts-expect-error abstract to prevent instantiation renderLoop = new AnimationLoopTemplateCtor(animationProps); // Any async loading can be handled here return await renderLoop?.onInitialize(animationProps); }, onRender: (animationProps) => renderLoop?.onRender(animationProps), onFinalize: (animationProps) => renderLoop?.onFinalize(animationProps) }); // @ts-expect-error Hack: adds info for the website to find animationLoop.getInfo = () => { // @ts-ignore // eslint-disable-next-line no-invalid-this return this.AnimationLoopTemplateCtor.info; }; // Start the loop automatically // animationLoop.start(); return animationLoop; }