@@ -23,6 +23,7 @@ import {
2323 VSMShadowMap ,
2424 WebGLRenderer ,
2525} from "three"
26+ import { processProps } from "../playground/controls/process-props.ts"
2627import type { CanvasProps } from "./create-canvas.tsx"
2728import { frameContext , threeContext } from "./hooks.ts"
2829import { pluginContext } from "./internal-context.ts"
@@ -31,7 +32,6 @@ import { CursorRaycaster, type EventRaycaster } from "./raycasters.tsx"
3132import type { CameraKind , Context , FrameListener , FrameListenerCallback , Plugin } from "./types.ts"
3233import {
3334 binarySearch ,
34- defaultProps ,
3535 getCurrentViewport ,
3636 meta ,
3737 removeElementFromArray ,
@@ -48,7 +48,22 @@ import { useMeasure } from "./utils/use-measure.ts"
4848 * based on the provided properties.
4949 */
5050export function createThree ( canvas : HTMLCanvasElement , props : CanvasProps , plugins : Plugin [ ] ) {
51- const canvasProps = defaultProps ( props , { frameloop : "always" } )
51+ const [ canvasProps , rest ] = processProps ( props , { frameloop : "always" } , [
52+ "children" ,
53+ "frameloop" ,
54+ "class" ,
55+ "defaultCamera" ,
56+ "defaultRaycaster" ,
57+ "fallback" ,
58+ "flat" ,
59+ "frameloop" ,
60+ "gl" ,
61+ "linear" ,
62+ "orthographic" ,
63+ "scene" ,
64+ "shadows" ,
65+ "style" ,
66+ ] )
5267
5368 /**********************************************************************************/
5469 /* */
@@ -237,8 +252,6 @@ export function createThree(canvas: HTMLCanvasElement, props: CanvasProps, plugi
237252 const clock = new Clock ( )
238253 clock . start ( )
239254
240- const pluginMap = new ReactiveMap < Plugin , ReturnType < Plugin > > ( )
241-
242255 const context : Context = {
243256 get bounds ( ) {
244257 return measure . bounds ( )
@@ -249,15 +262,7 @@ export function createThree(canvas: HTMLCanvasElement, props: CanvasProps, plugi
249262 return this . gl . getPixelRatio ( )
250263 } ,
251264 props,
252- registerPlugin ( plugin ) {
253- let result = pluginMap . get ( plugin )
254- if ( result ) {
255- return result
256- }
257- result = plugin ( context )
258- pluginMap . set ( plugin , result )
259- return result
260- } ,
265+ registerPlugin,
261266 render,
262267 requestRender,
263268 get viewport ( ) {
@@ -293,6 +298,28 @@ export function createThree(canvas: HTMLCanvasElement, props: CanvasProps, plugi
293298 ] ,
294299 )
295300
301+ /**********************************************************************************/
302+ /* */
303+ /* Plugins */
304+ /* */
305+ /**********************************************************************************/
306+
307+ const pluginMap = new ReactiveMap < Plugin , ReturnType < Plugin > > ( )
308+
309+ function registerPlugin ( plugin : Plugin ) {
310+ let result = pluginMap . get ( plugin )
311+ if ( result ) {
312+ return result
313+ }
314+ result = plugin ( context )
315+ pluginMap . set ( plugin , result )
316+ return result
317+ }
318+
319+ const pluginMethods = createMemo ( ( ) =>
320+ mergeProps ( ...plugins . map ( init => ( ) => registerPlugin ( init ) ( canvas ) ) ) ,
321+ )
322+
296323 /**********************************************************************************/
297324 /* */
298325 /* Effects */
@@ -310,6 +337,16 @@ export function createThree(canvas: HTMLCanvasElement, props: CanvasProps, plugi
310337 }
311338 } )
312339
340+ // Manage props resolved to plugins
341+ createRenderEffect ( ( ) => {
342+ const _pluginMethods = pluginMethods ( )
343+ for ( const key in canvasProps ) {
344+ if ( key in _pluginMethods ) {
345+ _pluginMethods [ key ] ?.( canvasProps [ key as keyof typeof canvasProps ] )
346+ }
347+ }
348+ } )
349+
313350 // Manage camera
314351 createRenderEffect ( ( ) => {
315352 if ( cameraStack . peek ( ) ) return
0 commit comments