@@ -6,6 +6,7 @@ import { SceneContext, EngineContextType } from './hooks';
66import { RootContainer } from '@types' ;
77import Reactylon from '../reconciler' ;
88import { type ContextBridge , useContextBridge } from 'its-fine' ;
9+ import { type CameraProps } from '@props' ;
910
1011type SceneProps = React . PropsWithChildren < {
1112 /**
@@ -58,15 +59,15 @@ export const Scene: React.FC<SceneProps> = ({ children, sceneOptions, onSceneRea
5859 scene . enablePhysics (
5960 physicsOptions ?. gravity || new Vector3 ( 0 , - 9.8 , 0 ) ,
6061 physicsOptions ?. plugin ||
61- new HavokPlugin (
62- true ,
63- await HavokPhysics ( {
64- // TODO: serve .wasm file from your own server
65- locateFile : file => {
66- return `https://preview.babylonjs.com/havok/${ file } ` ;
67- } ,
68- } ) ,
69- ) ,
62+ new HavokPlugin (
63+ true ,
64+ await HavokPhysics ( {
65+ // TODO: serve .wasm file from your own server
66+ locateFile : file => {
67+ return `https://preview.babylonjs.com/havok/${ file } ` ;
68+ } ,
69+ } ) ,
70+ ) ,
7071 ) ;
7172 }
7273 let xrExperience = null ;
@@ -104,8 +105,20 @@ export const Scene: React.FC<SceneProps> = ({ children, sceneOptions, onSceneRea
104105 }
105106 } ;
106107 } else {
107- //TODO: implement logic for multiple canvases but single scene (for each camera -> engine.registerView(canvas, camera))
108- //need linking camera and canvas (what about creating a new prop called "canvas" for camera elements?)
108+ scene . onNewCameraAddedObservable . add ( ( camera ) => {
109+ const augmentedCamera = camera as Camera & CameraProps ;
110+ const canvas = augmentedCamera . canvas ! ;
111+ engine . registerView ( canvas , camera ) ;
112+
113+ canvas . onclick = ( ) => {
114+ if ( scene . activeCamera !== camera ) {
115+ scene . activeCamera ?. detachControl ( ) ;
116+ engine . inputElement = canvas ;
117+ scene . activeCamera = camera ;
118+ camera . attachControl ( ) ;
119+ }
120+ }
121+ } )
109122 }
110123 }
111124
0 commit comments