import * as OGL from 'ogl' ; import { suspend } from 'suspend-react' ; import { useOGL } from '../hooks' ; import { buildGraph } from '../shared/utils' ; /**
 * Loads assets suspensefully.
 */ export const useLoader = ( loader , input , extensions ? ) => { const { gl } = useOGL ( ) ; const keys = Array . isArray ( input ) ? input : [ input ] ; return suspend ( async ( loader , ... urls ) => { extensions ?. ( loader ) ; const result = await Promise . all ( urls . map ( async ( url ) => { if ( loader === OGL . TextureLoader ) return loader . load ( gl , { url } ) ; const data = await loader . load ( gl , url ) ; if ( data . scene ) { const scene = data . scene ?. length ? data . scene [ 0 ] : data . scene ; const graph = buildGraph ( scene ) ; Object . assign ( data , { scene , ... graph } ) ; } return data ; } ) ) ; return Array . isArray ( input ) ? result : result [ 0 ] ; } , [ loader , ... keys ] ) ; } ;