|
@@ -24570,7 +24570,7 @@ window.Modernizr = function(n, e, t) {
|
|
|
n.prototype.boluoVrInit = function() {
|
|
|
|
|
|
console.log("boluoVrInit")
|
|
|
-
|
|
|
+ webxr.init(this.renderer)
|
|
|
this.isHuawei5X = m.detectHUAWEI5X(),
|
|
|
this.oldRenderer = this.renderer,
|
|
|
this.newRenderer = new this.vrRenderer(this.renderer,this,this.camera);
|
|
@@ -24582,7 +24582,8 @@ window.Modernizr = function(n, e, t) {
|
|
|
return window._vrEnabled
|
|
|
},
|
|
|
set: function(b) {
|
|
|
- b = !!b,
|
|
|
+ if(webxr.xrType)return webxr.enterVR()
|
|
|
+ b = !!b
|
|
|
b ? (a.renderer = a.newRenderer,
|
|
|
window.vrMarkers.forEach(function(a) {
|
|
|
a.visible = !0
|
|
@@ -25018,7 +25019,160 @@ window.Modernizr = function(n, e, t) {
|
|
|
return b.crossOrigin = "anonymous",
|
|
|
b.load(a)
|
|
|
}
|
|
|
- ,
|
|
|
+
|
|
|
+
|
|
|
+ let webxr = {
|
|
|
+ init(renderer) {
|
|
|
+ this.renderer = renderer
|
|
|
+ renderer.xr.enabled = true
|
|
|
+
|
|
|
+ if ('xr' in navigator && 'isSessionSupported' in navigator.xr) {
|
|
|
+ //pico firefox
|
|
|
+
|
|
|
+ var mode = 'immersive-vr'
|
|
|
+ navigator.xr
|
|
|
+ .isSessionSupported(mode)
|
|
|
+ .then(supported => {
|
|
|
+ if (!supported) {
|
|
|
+ this.xrNotFound('isSessionSupported not supported')
|
|
|
+ } else {
|
|
|
+ this.xrType = 'xr' //showEnterXR();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(this.xrNotFound.bind(this, 'isSessionSupported error'))
|
|
|
+ } else if ('getVRDisplays' in navigator) {
|
|
|
+ //pico 的vr browser是这个
|
|
|
+ console.log('getVRDisplays')
|
|
|
+ let setDevice = device => {
|
|
|
+ this.xrType = 'vr'
|
|
|
+ this.device = device
|
|
|
+ this.renderer.xr.setDevice(device) //新版是renderer.vr
|
|
|
+ }
|
|
|
+
|
|
|
+ window.addEventListener(
|
|
|
+ 'vrdisplayconnect',
|
|
|
+ function (event) {
|
|
|
+ setDevice(event.display)
|
|
|
+ },
|
|
|
+ false
|
|
|
+ )
|
|
|
+
|
|
|
+ window.addEventListener(
|
|
|
+ 'vrdisplaydisconnect',
|
|
|
+ function (/*event*/) {
|
|
|
+ console.log('vrdisplaydisconnect')
|
|
|
+ },
|
|
|
+ false
|
|
|
+ )
|
|
|
+
|
|
|
+ window.addEventListener(
|
|
|
+ 'vrdisplaypresentchange',
|
|
|
+ function (event) {
|
|
|
+ console.log('vrdisplaypresentchange', event.display.isPresenting ? 'EXIT VR' : 'ENTER VR')
|
|
|
+ //button.textContent = event.display.isPresenting ? 'EXIT VR' : 'ENTER VR';
|
|
|
+ },
|
|
|
+ false
|
|
|
+ )
|
|
|
+
|
|
|
+ window.addEventListener(
|
|
|
+ 'vrdisplayactivate',
|
|
|
+ function (event) {
|
|
|
+ event.display.requestPresent([{ source: this.renderer.domElement }])
|
|
|
+ },
|
|
|
+ false
|
|
|
+ )
|
|
|
+
|
|
|
+ navigator
|
|
|
+ .getVRDisplays()
|
|
|
+ .then(function (displays) {
|
|
|
+ if (displays.length > 0) {
|
|
|
+ setDevice(displays[0])
|
|
|
+ } else {
|
|
|
+ this.xrNotFound('no displays')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(this.xrNotFound.bind(this, 'getVRDisplays error'))
|
|
|
+ } else {
|
|
|
+ this.xrNotFound('xr not supported')
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ enterVR() {
|
|
|
+ if (!this.xrType) return //不支持
|
|
|
+ console.log('enterVR', this.xrType)
|
|
|
+
|
|
|
+ if (this.xrType == 'vr') {
|
|
|
+ this.device.isPresenting ? this.device.exitPresent() : this.device.requestPresent([{ source: renderer.domElement }])
|
|
|
+ } else if (this.xrType == 'xr') {
|
|
|
+ if (this.currentSession == void 0) {
|
|
|
+ console.log('this.currentSession == void 0 ')
|
|
|
+
|
|
|
+ function getXRSessionInit(mode, options) {
|
|
|
+ var space = (options || {}).referenceSpaceType || 'local-floor'
|
|
|
+ var sessionInit = (options && options.sessionInit) || {}
|
|
|
+
|
|
|
+ // Nothing to do for default features.
|
|
|
+ if (space == 'viewer') return sessionInit
|
|
|
+ if (space == 'local' && mode.startsWith('immersive')) return sessionInit
|
|
|
+
|
|
|
+ // If the user already specified the space as an optional or required feature, don't do anything.
|
|
|
+ if (sessionInit.optionalFeatures && sessionInit.optionalFeatures.includes(space)) return sessionInit
|
|
|
+ if (sessionInit.requiredFeatures && sessionInit.requiredFeatures.includes(space)) return sessionInit
|
|
|
+
|
|
|
+ // The user didn't request the reference space type as a feature. Add it to a shallow copy
|
|
|
+ // of the user-supplied sessionInit requiredFeatures (if any) to ensure it's valid to
|
|
|
+ // request it later.
|
|
|
+ var newInit = Object.assign({}, sessionInit)
|
|
|
+ newInit.requiredFeatures = [space]
|
|
|
+ if (sessionInit.requiredFeatures) {
|
|
|
+ newInit.requiredFeatures = newInit.requiredFeatures.concat(sessionInit.requiredFeatures)
|
|
|
+ }
|
|
|
+ return newInit
|
|
|
+ }
|
|
|
+ let onSessionEnded = (/*event*/) => {
|
|
|
+ console.log('onSessionEnded')
|
|
|
+ this.currentSession.removeEventListener('end', onSessionEnded)
|
|
|
+ setTimeout(()=>{
|
|
|
+ this.renderer.xr.setSession(null)
|
|
|
+ this.currentSession = null
|
|
|
+ },1)//延迟原因:先使THREE里的onSessionEnded执行
|
|
|
+
|
|
|
+ }
|
|
|
+ let onSessionStarted = session => {
|
|
|
+ console.log('onSessionStarted')
|
|
|
+ /* var attributes = this.renderer.getContextAttributes();
|
|
|
+ console.log('xrCompatible', attributes.xrCompatible) */
|
|
|
+ session.addEventListener('end', onSessionEnded)
|
|
|
+ this.renderer.xr.setSession(session)
|
|
|
+ this.currentSession = session
|
|
|
+
|
|
|
+ }
|
|
|
+ var mode = 'immersive-vr'
|
|
|
+ var sessionInit = getXRSessionInit(mode)
|
|
|
+ navigator.xr.requestSession(mode, sessionInit).then(onSessionStarted)
|
|
|
+
|
|
|
+ } else {
|
|
|
+ console.log('this.currentSession.end()', this.currentSession)
|
|
|
+ this.currentSession.end()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /* leaveVR(){
|
|
|
+ if(this.xrType == 'xr'){
|
|
|
+ this.currentSession && this.currentSession.end()
|
|
|
+ }else if(this.xrType == 'vr'){
|
|
|
+
|
|
|
+ }
|
|
|
+ }, */
|
|
|
+ xrNotFound(text) {
|
|
|
+ console.log('xrNotFound:', text)
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/***********************************************************************************************************************************************************************************/
|
|
|
n.prototype.updateScreenSize = function() {//xzw 改 为了截屏 要改canvas大小 以及缩放时不模糊
|
|
|
var W,H;//当截屏时有setTimeout 期间不能恢复大小,所以要用W,H记录正常大小
|