From 7f8ffca589b3ca9ca79173b6e147055b611c4a68 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Wed, 17 Apr 2024 15:20:21 +0000 Subject: [PATCH] minor bugfixes due to new release --- src/3rd/js/plugin/frontend/$chat.js | 5 +-- src/3rd/js/plugin/frontend/$connections.js | 4 ++- src/3rd/js/plugin/frontend/frontend.js | 3 +- src/3rd/js/three/index.js | 1 + src/3rd/js/three/navigator.js | 39 ++++++++++++---------- src/3rd/js/three/xrf/#.js | 9 +++-- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/3rd/js/plugin/frontend/$chat.js b/src/3rd/js/plugin/frontend/$chat.js index 5e7c884..d8529f5 100644 --- a/src/3rd/js/plugin/frontend/$chat.js +++ b/src/3rd/js/plugin/frontend/$chat.js @@ -105,7 +105,7 @@ chatComponent = { br.classList.add.apply(br.classList, opts.class) div.classList.add.apply(div.classList, opts.class.concat(["envelope"])) } - if( msg.className.match(/(info|guide|ui)/) || !opts.from ){ + if( !msg.className.match(/(info|guide|ui)/) && !opts.from ){ let frag = xrf.URI.parse(document.location.hash).XRF opts.from = 'you' if( frag.pos ) opts.pos = frag.pos.string @@ -284,7 +284,8 @@ chatComponent.css = ` cursor:grabbing; border: 1px solid #0002; } - #messages .msg *{ + #messages .msg *, + #messages .user *{ pointer-events:all; -webkit-user-select:text; -moz-user-select:-moz-text; diff --git a/src/3rd/js/plugin/frontend/$connections.js b/src/3rd/js/plugin/frontend/$connections.js index 13c5f2c..e7b6b62 100644 --- a/src/3rd/js/plugin/frontend/$connections.js +++ b/src/3rd/js/plugin/frontend/$connections.js @@ -249,7 +249,9 @@ connectionsComponent = { set(data,k,v){ data[k] = v switch( k ){ - case "visible": el.style.display = v ? '' : 'none'; break; + case "visible": el.style.display = v ? '' : 'none'; + if( !v && el.parentNode && el.parentNode.parentNode ) el.parentNode.parentNode.remove() + break; case "webcam": $webcam.innerHTML = ``; break; case "chatnetwork": $chatnetwork.innerHTML = ``; break; case "scene": $scene.innerHTML = ``; break; diff --git a/src/3rd/js/plugin/frontend/frontend.js b/src/3rd/js/plugin/frontend/frontend.js index b40df29..05746f7 100644 --- a/src/3rd/js/plugin/frontend/frontend.js +++ b/src/3rd/js/plugin/frontend/frontend.js @@ -95,7 +95,8 @@ window.frontend = (opts) => new Proxy({ : "use WASD-keys and mouse-drag to move around" window.notify(instructions,{timeout:false}) xrf.addEventListener('navigate', (opts) => { - window.notify('teleporting to '+opts.url+"

use back/forward browserbutton to undo") + let pos = opts.url.replace( document.location.href.replace(/#.*/,''), '') + window.notify('teleporting to '+pos+"

use back/forward browserbutton to undo") }) // close dialogs when url changes },2000 ) diff --git a/src/3rd/js/three/index.js b/src/3rd/js/three/index.js index 344a920..70675e4 100644 --- a/src/3rd/js/three/index.js +++ b/src/3rd/js/three/index.js @@ -41,6 +41,7 @@ xrf.parseModel = function(model,url){ let file = xrf.getFile(url) model.file = file model.isXRF = true + model.scene.isXRFRoot = true model.scene.traverse( (n) => n.isXRF = true ) // mark for deletion during reset() xrf.emit('parseModel',{model,url,file}) diff --git a/src/3rd/js/three/navigator.js b/src/3rd/js/three/navigator.js index c5175bf..fd049df 100644 --- a/src/3rd/js/three/navigator.js +++ b/src/3rd/js/three/navigator.js @@ -13,10 +13,12 @@ xrf.navigator.to = (url,flags,loader,data) => { let URI = xrfragment.URI.toAbsolute( xrf.navigator.URI, url ) URI.hash = xrf.navigator.reactifyHash(URI.hash) - let fileChange = URI.URN + URI.file != xrf.navigator.URI.URN + xrf.navigator.URI.file - let external = URI.URN != document.location.origin + document.location.pathname - let hasPos = URI.hash.pos - let hashChange = String(xrf.navigator.URI.fragment||"") != String(URI.fragment||"") + // decorate with extra state + URI.fileChange = URI.file && URI.URN + URI.file != xrf.navigator.URI.URN + xrf.navigator.URI.file + URI.external = URI.file && URI.URN != document.location.origin + document.location.pathname + URI.hasPos = URI.hash.pos ? true : false + URI.duplicatePos = URI.source == xrf.navigator.URI.source && URI.hasPos + URI.hashChange = String(xrf.navigator.URI.fragment||"") != String(URI.fragment||"") let hashbus = xrf.hashbus xrf.navigator.URI = URI let {directory,file,fragment,fileExt} = URI; @@ -40,22 +42,25 @@ xrf.navigator.to = (url,flags,loader,data) => { loader = loader || new Loader().setPath( URI.URN ) } - if( !URI.fragment && !URI.file && !URI.fileExt ) return resolve(xrf.model) // nothing we can do here - if( xrf.model && !fileChange && hashChange && !hasPos ){ + if( URI.duplicatePos || (!URI.fragment && !URI.file && !URI.fileExt) ){ + return resolve(xrf.model) // nothing we can do here + } + + if( xrf.model && !URI.fileChange && URI.hashChange && !URI.hasPos ){ evalFragment() - return resolve(xrf.model) // positional navigation + return resolve(xrf.model) // eval non-positional fragments (no loader needed) } xrf .emit('navigateLoading', {url,loader,data}) .then( () => { - if( (!fileChange || !file) && hashChange && hasPos ){ // we're already loaded + if( (!URI.fileChange || !file) && URI.hashChange && URI.hasPos ){ // we're already loaded evalFragment() xrf.emit('navigateLoaded',{url}) return resolve(xrf.model) } - + // clear xrf objects from scene if( xrf.model && xrf.model.scene ) xrf.model.scene.visible = false xrf.reset() @@ -67,11 +72,6 @@ xrf.navigator.to = (url,flags,loader,data) => { const onLoad = (model) => { model.file = URI.file - // only change url when loading *another* file - if( xrf.model ){ - xrf.navigator.pushState( external ? URI.URN + URI.file : URI.file, fragment ) - } - //if( xrf.model ) xrf.navigator.pushState( `${ document.location.pathname != URI.directory ? URI.directory: ''}${URI.file}`, fragment ) xrf.model = model if( !model.isXRF ) xrf.parseModel(model,url.replace(directory,"")) // this marks the model as an XRF model @@ -86,12 +86,17 @@ xrf.navigator.to = (url,flags,loader,data) => { model.scene.traverse( (mesh) => xrf.parseModel.metadataInMesh(mesh,model) ) } // spec: 1. execute the default predefined view '#' (if exist) (https://xrfragment.org/#predefined_view) - xrf.frag.defaultPredefinedViews({model,scene:model.scene}) + const defaultFragment = xrf.frag.defaultPredefinedViews({model,scene:model.scene}) // spec: predefined view(s) & objects-of-interest-in-XRWG from URI (https://xrfragment.org/#predefined_view) let frag = xrf.hashbus.pub( url, model) // and eval URI XR fragments - + xrf.add( model.scene ) - if( fragment ) xrf.navigator.updateHash(fragment) + + // only change url when loading *another* file + fragment = fragment || defaultFragment || '' + xrf.navigator.pushState( URI.external ? URI.URN + URI.file : URI.file, fragment.replace(/^#/,'') ) + //if( fragment ) xrf.navigator.updateHash(fragment) + xrf.emit('navigateLoaded',{url,model}) resolve(model) } diff --git a/src/3rd/js/three/xrf/#.js b/src/3rd/js/three/xrf/#.js index c172dfe..8a0ea73 100644 --- a/src/3rd/js/three/xrf/#.js +++ b/src/3rd/js/three/xrf/#.js @@ -2,11 +2,14 @@ xrf.frag.defaultPredefinedViews = (opts) => { let {scene,model} = opts; + let defaultFragment; scene.traverse( (n) => { if( n.userData && n.userData['#'] ){ - if( !n.parent && !document.location.hash ){ - xrf.navigator.to( n.userData['#'] ) - }else xrf.hashbus.pub( n.userData['#'], n ) // evaluate default XR fragments without affecting URL + if( n.isXRFRoot ){ + defaultFragment = n.userData['#'] + } + xrf.hashbus.pub( n.userData['#'], n ) // evaluate default XR fragments without affecting URL } }) + return defaultFragment }