@@ -64,16 +64,32 @@ class DOMException {
64
64
}
65
65
}
66
66
67
- if ( Platform . OS == "windows" ) {
68
- const originalEnterXRAsync : ( ...args : any [ ] ) => Promise < any > = WebXRExperienceHelper . prototype . enterXRAsync ;
69
- WebXRExperienceHelper . prototype . enterXRAsync = async function ( ...args : any [ ] ) : Promise < any > {
67
+ if ( Platform . OS === "android" || Platform . OS === "ios" ) {
68
+ const originalEnterXRAsync : ( ...args : any [ ] ) => Promise < WebXRSessionManager > = WebXRExperienceHelper . prototype . enterXRAsync ;
69
+ WebXRExperienceHelper . prototype . enterXRAsync = async function ( ...args : any [ ] ) : Promise < WebXRSessionManager > {
70
+ // TODO: https://github.com/BabylonJS/BabylonNative/issues/649
71
+ // Android/iOS require manually clearing the default frame buffer to prevent garbage from being rendered for a few frames during the XR transition
72
+ const sessionManager = await originalEnterXRAsync . apply ( this , args ) ;
73
+ const scene = sessionManager . scene ;
74
+ const beforeRenderObserver = scene . onBeforeRenderObservable . add ( ( ) => {
75
+ scene . getEngine ( ) . unBindFramebuffer ( undefined ! ) ;
76
+ scene . getEngine ( ) . clear ( scene . clearColor , true , false ) ;
77
+ } ) ;
78
+ sessionManager . onXRSessionEnded . add ( ( ) => {
79
+ scene . onBeforeRenderObservable . remove ( beforeRenderObserver ) ;
80
+ } ) ;
81
+ return sessionManager ;
82
+ } ;
83
+ } else if ( Platform . OS === "windows" ) {
84
+ const originalEnterXRAsync : ( ...args : any [ ] ) => Promise < WebXRSessionManager > = WebXRExperienceHelper . prototype . enterXRAsync ;
85
+ WebXRExperienceHelper . prototype . enterXRAsync = async function ( ...args : any [ ] ) : Promise < WebXRSessionManager > {
70
86
// TODO: https://github.com/BabylonJS/BabylonNative/issues/577
71
87
// Windows HMDs require different rendering behaviors than default xr rendering for mobile devices
72
88
const sessionManager = await originalEnterXRAsync . apply ( this , args ) ;
73
89
sessionManager . scene . clearColor = Color3 . Black ( ) . toColor4 ( ) ;
74
90
sessionManager . scene . autoClear = true ;
75
91
return sessionManager ;
76
- }
92
+ } ;
77
93
}
78
94
79
95
// Babylon Native includes a native atob polyfill, but it relies JSI to deal with the strings, and JSI has a bug where it assumes strings are null terminated, and a base 64 string can contain one of these.
0 commit comments