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
}