@@ -30,6 +30,7 @@ import {
3030 HavokPlugin ,
3131 PickingInfo ,
3232 SceneLoaderFlags ,
33+ EngineView ,
3334} from "babylonjs" ;
3435
3536import { Button } from "../../ui/shadcn/ui/button" ;
@@ -166,6 +167,7 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
166167
167168 private _workingCanvas : HTMLCanvasElement | null = null ;
168169 private _mainCanvas : HTMLCanvasElement | null = null ;
170+ private _mainView : EngineView | null = null ;
169171
170172 private _previewCamera : Camera | null = null ;
171173
@@ -325,18 +327,36 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
325327 fixedDimensions,
326328 } ) ;
327329
330+ if ( ! this . engine || ! this . _mainView || ! this . _mainCanvas ) {
331+ return ;
332+ }
333+
334+ this . _mainView ! . customResize = undefined ;
335+
328336 switch ( fixedDimensions ) {
329337 case "720p" :
330- this . engine ?. setSize ( 1280 , 720 ) ;
338+ this . _mainCanvas ! . width = 1280 ;
339+ this . _mainCanvas ! . height = 720 ;
340+
341+ this . _mainView ! . customResize = ( ) => {
342+ this . engine . setSize ( 1280 , 720 ) ;
343+ } ;
331344 break ;
332345 case "1080p" :
333- this . engine ?. setSize ( 1920 , 1080 ) ;
346+ this . _mainCanvas ! . width = 1920 ;
347+ this . _mainCanvas ! . height = 1080 ;
348+
349+ this . _mainView ! . customResize = ( ) => {
350+ this . engine . setSize ( 1920 , 1080 ) ;
351+ } ;
334352 break ;
335353 case "4k" :
336- this . engine ?. setSize ( 3840 , 2160 ) ;
337- break ;
338- default :
339- this . engine ?. resize ( ) ;
354+ this . _mainCanvas ! . width = 3840 ;
355+ this . _mainCanvas ! . height = 2160 ;
356+
357+ this . _mainView ! . customResize = ( ) => {
358+ this . engine . setSize ( 3840 , 2160 ) ;
359+ } ;
340360 break ;
341361 }
342362 }
@@ -492,7 +512,7 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
492512 this . gizmo = new EditorPreviewGizmo ( this . scene ) ;
493513
494514 this . engine . hideLoadingUI ( ) ;
495- this . engine . registerView ( this . _mainCanvas ) ;
515+ this . _mainView = this . engine . registerView ( this . _mainCanvas ) ;
496516
497517 this . engine . runRenderLoop ( ( ) => {
498518 if ( this . _renderScene && ! this . play . state . playing ) {
0 commit comments