UNPKG

@threlte/core

Version:

A 3D framework for the web, built on top of Svelte and Three.js

15 lines (14 loc) 479 B
import { getContext, setContext } from 'svelte'; import { Scene } from 'three'; export const createSceneContext = (scene) => { const context = { scene: scene || new Scene() }; setContext('threlte-scene-context', context); return context; }; export const useScene = () => { const context = getContext('threlte-scene-context'); if (!context) { throw new Error('useScene can only be used in a child component to <Canvas>.'); } return context; };