@@ -9,6 +9,7 @@ import RuntimeMetrics from './RuntimeMetrics.js';
99import FrameClock from './FrameClock.js' ;
1010import FixedTicker from './FixedTicker.js' ;
1111import EventBus from '../events/EventBus.js' ;
12+ import { Camera3D } from '../camera/index.js' ;
1213import { backgroundImage , fullscreenBezel , FullscreenService , resolvePreferredFullscreenTarget } from '../runtime/index.js' ;
1314import { AudioService } from '../audio/index.js' ;
1415import { Logger } from '../logging/index.js' ;
@@ -30,6 +31,7 @@ export default class Engine {
3031 fullscreenBezelLayer = null ,
3132 audio = null ,
3233 logger = null ,
34+ camera3D = null ,
3335 } = { } ) {
3436 if ( ! canvas ) {
3537 throw new Error ( 'Engine requires a canvas.' ) ;
@@ -68,6 +70,7 @@ export default class Engine {
6870 } ) ;
6971 this . audio = audio || new AudioService ( ) ;
7072 this . logger = logger || new Logger ( { channel : 'engine' } ) ;
73+ this . camera3D = camera3D || new Camera3D ( ) ;
7174 this . settings = new SettingsSystem ( {
7275 namespace : 'toolboxaid:engine-settings' ,
7376 defaults : {
@@ -97,12 +100,42 @@ export default class Engine {
97100 }
98101
99102 this . scene = scene ;
103+ this . attachScene3DCamera ( this . scene ) ;
100104
101105 if ( this . scene && typeof this . scene . enter === 'function' ) {
102106 this . scene . enter ( this ) ;
103107 }
104108 }
105109
110+ attachScene3DCamera ( scene ) {
111+ if ( ! scene || ! this . camera3D ) {
112+ return ;
113+ }
114+
115+ if ( typeof scene . setCamera3D === 'function' ) {
116+ try {
117+ scene . setCamera3D ( this . camera3D , this ) ;
118+ } catch ( error ) {
119+ this . logger ?. warn ?. ( 'Engine scene setCamera3D hook failed.' , {
120+ error : error ?. message || String ( error ) ,
121+ } ) ;
122+ }
123+ return ;
124+ }
125+
126+ if ( scene . camera3D !== undefined && scene . camera3D !== null ) {
127+ return ;
128+ }
129+
130+ try {
131+ scene . camera3D = this . camera3D ;
132+ } catch ( error ) {
133+ this . logger ?. warn ?. ( 'Engine scene camera3D assignment failed.' , {
134+ error : error ?. message || String ( error ) ,
135+ } ) ;
136+ }
137+ }
138+
106139 start ( ) {
107140 if ( this . input && typeof this . input . attach === 'function' ) {
108141 this . input . attach ( ) ;
0 commit comments