2021-07-31 15:10:08 +02:00
|
|
|
import React, {useLayoutEffect} from 'react'
|
|
|
|
import {useThree} from '@react-three/fiber'
|
|
|
|
import type {ISheet} from '@theatre/core'
|
|
|
|
import {bindToCanvas} from './store'
|
|
|
|
|
|
|
|
const Wrapper: React.FC<{
|
|
|
|
getSheet: () => ISheet
|
|
|
|
}> = (props) => {
|
|
|
|
const {scene, gl} = useThree((s) => ({scene: s.scene, gl: s.gl}))
|
|
|
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
const sheet = props.getSheet()
|
|
|
|
if (!sheet || sheet.type !== 'Theatre_Sheet_PublicAPI') {
|
|
|
|
throw new Error(
|
|
|
|
`getSheet() in <Wrapper getSheet={getSheet}> has returned an invalid value`,
|
|
|
|
)
|
|
|
|
}
|
2021-08-08 22:25:48 +02:00
|
|
|
bindToCanvas({sheet, gl, scene})
|
2021-07-31 15:10:08 +02:00
|
|
|
}, [scene, gl])
|
|
|
|
|
|
|
|
return <>{props.children}</>
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Wrapper
|