@threlte/core
Advanced tools
Comparing version 7.2.1 to 7.3.0
@@ -20,3 +20,3 @@ export { default as Canvas } from './Canvas.svelte'; | ||
export { type AsyncWritable, asyncWritable } from './lib/asyncWritable'; | ||
export type { ThrelteContext } from './lib/contexts'; | ||
export { type ThrelteContext, createThrelteContext } from './lib/contexts'; | ||
export type { Size } from './types'; | ||
@@ -23,0 +23,0 @@ export { createObjectStore } from './lib/createObjectStore'; |
@@ -27,2 +27,4 @@ // canvas component | ||
export { asyncWritable } from './lib/asyncWritable'; | ||
// contexts | ||
export { createThrelteContext } from './lib/contexts'; | ||
// utils | ||
@@ -29,0 +31,0 @@ export { createObjectStore } from './lib/createObjectStore'; |
/// <reference types="svelte" /> | ||
import { type Readable, type Writable } from 'svelte/store'; | ||
import { Scene, type Camera, type ColorSpace, type ShadowMapType, type ToneMapping, type WebGLRenderer } from 'three'; | ||
import type { Scheduler, Stage, Task } from '../frame-scheduling'; | ||
import { Scheduler, type Stage, type Task } from '../frame-scheduling'; | ||
import type { DisposableThreeObject, Size } from '../types'; | ||
@@ -107,8 +107,5 @@ import { type CurrentWritable } from './storeUtils'; | ||
/** | ||
* ### `createContexts` | ||
* | ||
* This function creates the context objects `ThrelteContext` and | ||
* `ThrelteInternalContext` for a Threlte application. | ||
* This function creates the necessary context objects for a Threlte application. | ||
*/ | ||
export declare const createContexts: (options: { | ||
export declare const createThrelteContext: (options: { | ||
colorSpace: ColorSpace; | ||
@@ -124,7 +121,2 @@ toneMapping: ToneMapping; | ||
useLegacyLights: boolean; | ||
}) => { | ||
ctx: ThrelteContext; | ||
internalCtx: ThrelteInternalContext; | ||
getCtx: () => ThrelteContext; | ||
getInternalCtx: () => ThrelteInternalContext; | ||
}; | ||
}) => ThrelteContext; |
import { setContext, tick } from 'svelte'; | ||
import { derived } from 'svelte/store'; | ||
import { Scene } from 'three'; | ||
import { getDefaultCamera } from './defaultCamera'; | ||
import { Scheduler } from '../frame-scheduling'; | ||
import { getDefaultCamera, setDefaultCameraAspectOnSizeChange } from './defaultCamera'; | ||
import { currentWritable } from './storeUtils'; | ||
import { injectLegacyFrameCompatibilityContext } from '../hooks/legacy/utils'; | ||
/** | ||
* ### `createContexts` | ||
* | ||
* This function creates the context objects `ThrelteContext` and | ||
* `ThrelteInternalContext` for a Threlte application. | ||
* This function creates the necessary context objects for a Threlte application. | ||
*/ | ||
export const createContexts = (options) => { | ||
export const createThrelteContext = (options) => { | ||
const internalCtx = { | ||
@@ -78,2 +77,21 @@ frameInvalidated: true, | ||
}; | ||
// TODO: Remove in Threlte 7 | ||
const { useRenderOrders } = injectLegacyFrameCompatibilityContext(); | ||
const scheduler = new Scheduler(); | ||
const mainStage = scheduler.createStage(Symbol('threlte-main-stage')); | ||
const renderStage = scheduler.createStage(Symbol('threlte-render-stage'), { | ||
after: mainStage, | ||
callback(_, runTasks) { | ||
if (ctx.shouldRender()) | ||
runTasks(); | ||
} | ||
}); | ||
const autoRenderTask = renderStage.createTask(Symbol('threlte-auto-render-task'), (_) => { | ||
// we're in here when autoRender is true In Threlte 7 we still have to | ||
// check for the existence of `useRender` instances | ||
if (useRenderOrders.length > 0) | ||
return; | ||
// if there are no useRender instances, we can render the scene | ||
ctx.renderer.render(ctx.scene, ctx.camera.current); | ||
}); | ||
const ctx = { | ||
@@ -100,6 +118,6 @@ size: derived([options.userSize, options.parentSize], ([uSize, pSize]) => { | ||
autoRender: currentWritable(options.autoRender), | ||
scheduler: undefined, | ||
mainStage: undefined, | ||
renderStage: undefined, | ||
autoRenderTask: undefined, | ||
scheduler, | ||
mainStage, | ||
renderStage, | ||
autoRenderTask, | ||
shouldRender: () => { | ||
@@ -113,2 +131,3 @@ const shouldRender = ctx.renderMode.current === 'always' || | ||
}; | ||
setDefaultCameraAspectOnSizeChange(ctx); | ||
const userCtx = currentWritable({}); | ||
@@ -118,10 +137,3 @@ setContext('threlte', ctx); | ||
setContext('threlte-user-context', userCtx); | ||
const getCtx = () => ctx; | ||
const getInternalCtx = () => internalCtx; | ||
return { | ||
ctx, | ||
internalCtx, | ||
getCtx, | ||
getInternalCtx | ||
}; | ||
return ctx; | ||
}; |
{ | ||
"name": "@threlte/core", | ||
"version": "7.2.1", | ||
"version": "7.3.0", | ||
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
6449
297869