import { EventState , Observer } from '@babylonjs/core/Misc/observable.js' ; import { Scene } from '@babylonjs/core/scene.js' ; import { Nullable } from '@babylonjs/core/types.js' ; import { useContext , useEffect } from 'react' ; import { SceneContext } from './scene' ; export type OnFrameRenderFn = ( eventData : Scene , eventState : EventState ) => void ; param callback param mask param insertFirst param callOnce export const useBeforeRender = ( callback , mask ? , insertFirst ? , callOnce ? ) : void => { const { scene } = useContext ( SceneContext ) ; useEffect ( ( ) => { if ( scene === null ) { return ; } const unregisterOnFirstCall = callOnce === true ; const sceneObserver = scene . onBeforeRenderObservable . add ( callback , mask , insertFirst , undefined , unregisterOnFirstCall ) ; if ( unregisterOnFirstCall !== true ) { return ( ) => { scene . onBeforeRenderObservable . remove ( sceneObserver ) ; } ; } } ) ; } ; param callback param mask param insertFirst param callOnce export const useAfterRender = ( callback , mask ? , insertFirst ? , callOnce ? ) : void => { const { scene } = useContext ( SceneContext ) ; useEffect ( ( ) => { if ( scene === null ) { return ; } const unregisterOnFirstCall = callOnce === true ; const sceneObserver = scene . onAfterRenderObservable . add ( callback , mask , insertFirst , undefined , unregisterOnFirstCall ) ; if ( unregisterOnFirstCall !== true ) { return ( ) => { scene . onAfterRenderObservable . remove ( sceneObserver ) ; } ; } } ) ; } ;