From b01d0e57d9efa7dce94896991596c0d4be2a9947 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Sat, 10 Jun 2023 14:43:07 +0200 Subject: [PATCH] wip: trigger default view --- dist/xrfragment.aframe.js | 7 +++--- dist/xrfragment.js | 2 +- dist/xrfragment.lua | 30 +++++++++++++++----------- dist/xrfragment.module.js | 2 +- dist/xrfragment.py | 9 ++++++-- dist/xrfragment.three.js | 7 +++--- dist/xrfragment.three.module.js | 7 +++--- src/3rd/js/three/navigator.js | 3 ++- src/3rd/js/three/xrf/predefinedView.js | 2 +- src/xrfragment/URI.hx | 2 +- test/generated/test.js | 2 +- test/generated/test.py | 11 +++++++--- 12 files changed, 52 insertions(+), 32 deletions(-) diff --git a/dist/xrfragment.aframe.js b/dist/xrfragment.aframe.js index a37073d..1d2ce49 100644 --- a/dist/xrfragment.aframe.js +++ b/dist/xrfragment.aframe.js @@ -452,7 +452,7 @@ var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; xrfragment_URI.parse = function(url,filter) { var store = { }; - if(url.indexOf("#") == -1) { + if(url == null || url.indexOf("#") == -1) { return store; } var fragment = url.split("#"); @@ -966,7 +966,8 @@ xrf.navigator.to = (url,event) => { model.file = file xrf.add( model.scene ) xrf.model = model - xrf.eval( url, model ) // and eval URI XR fragments + xrf.eval( '#', model ) // execute the default projection '#' (if exist) + xrf.eval( url, model ) // and eval URI XR fragments xrf.navigator.pushState( `${dir}${file}`, hash ) resolve(model) }) @@ -1202,7 +1203,7 @@ const doPredefinedView = (opts) => { const predefinedView = (frag,scene,mesh) => { let id = frag.string - if( mesh.userData[id] ){ + if( mesh.userData[`#${id}`] ){ let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED ) for ( let k in frag ){ let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE } diff --git a/dist/xrfragment.js b/dist/xrfragment.js index 95de028..83c98bc 100644 --- a/dist/xrfragment.js +++ b/dist/xrfragment.js @@ -452,7 +452,7 @@ var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; xrfragment_URI.parse = function(url,filter) { var store = { }; - if(url.indexOf("#") == -1) { + if(url == null || url.indexOf("#") == -1) { return store; } var fragment = url.split("#"); diff --git a/dist/xrfragment.lua b/dist/xrfragment.lua index 9811312..7d35dba 100644 --- a/dist/xrfragment.lua +++ b/dist/xrfragment.lua @@ -2051,20 +2051,26 @@ _hx_exports["xrfragment"]["URI"] = __xrfragment_URI __xrfragment_URI.__name__ = true __xrfragment_URI.parse = function(url,filter) local store = _hx_e(); - local startIndex = nil; - if (startIndex == nil) then - startIndex = 1; + local tmp; + if (url ~= nil) then + local startIndex = nil; + if (startIndex == nil) then + startIndex = 1; + else + startIndex = startIndex + 1; + end; + local r = __lua_lib_luautf8_Utf8.find(url, "#", startIndex, true); + tmp = (function() + local _hx_1 + if ((r ~= nil) and (r > 0)) then + _hx_1 = r - 1; else + _hx_1 = -1; end + return _hx_1 + end )() == -1; else - startIndex = startIndex + 1; + tmp = true; end; - local r = __lua_lib_luautf8_Utf8.find(url, "#", startIndex, true); - if ((function() - local _hx_1 - if ((r ~= nil) and (r > 0)) then - _hx_1 = r - 1; else - _hx_1 = -1; end - return _hx_1 - end )() == -1) then + if (tmp) then do return store end; end; local idx = 1; diff --git a/dist/xrfragment.module.js b/dist/xrfragment.module.js index 4ee6980..0b8a5b4 100644 --- a/dist/xrfragment.module.js +++ b/dist/xrfragment.module.js @@ -452,7 +452,7 @@ var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; xrfragment_URI.parse = function(url,filter) { var store = { }; - if(url.indexOf("#") == -1) { + if(url == null || url.indexOf("#") == -1) { return store; } var fragment = url.split("#"); diff --git a/dist/xrfragment.py b/dist/xrfragment.py index b4a4c6b..b86afdf 100644 --- a/dist/xrfragment.py +++ b/dist/xrfragment.py @@ -1536,8 +1536,13 @@ class xrfragment_URI: @staticmethod def parse(url,_hx_filter): store = _hx_AnonObject({}) - startIndex = None - if (((url.find("#") if ((startIndex is None)) else HxString.indexOfImpl(url,"#",startIndex))) == -1): + tmp = None + if (url is not None): + startIndex = None + tmp = (((url.find("#") if ((startIndex is None)) else HxString.indexOfImpl(url,"#",startIndex))) == -1) + else: + tmp = True + if tmp: return store fragment = url.split("#") _this = (fragment[1] if 1 < len(fragment) else None) diff --git a/dist/xrfragment.three.js b/dist/xrfragment.three.js index ffee5f6..98957da 100644 --- a/dist/xrfragment.three.js +++ b/dist/xrfragment.three.js @@ -452,7 +452,7 @@ var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; xrfragment_URI.parse = function(url,filter) { var store = { }; - if(url.indexOf("#") == -1) { + if(url == null || url.indexOf("#") == -1) { return store; } var fragment = url.split("#"); @@ -966,7 +966,8 @@ xrf.navigator.to = (url,event) => { model.file = file xrf.add( model.scene ) xrf.model = model - xrf.eval( url, model ) // and eval URI XR fragments + xrf.eval( '#', model ) // execute the default projection '#' (if exist) + xrf.eval( url, model ) // and eval URI XR fragments xrf.navigator.pushState( `${dir}${file}`, hash ) resolve(model) }) @@ -1202,7 +1203,7 @@ const doPredefinedView = (opts) => { const predefinedView = (frag,scene,mesh) => { let id = frag.string - if( mesh.userData[id] ){ + if( mesh.userData[`#${id}`] ){ let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED ) for ( let k in frag ){ let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE } diff --git a/dist/xrfragment.three.module.js b/dist/xrfragment.three.module.js index d4943f5..fb9fd75 100644 --- a/dist/xrfragment.three.module.js +++ b/dist/xrfragment.three.module.js @@ -452,7 +452,7 @@ var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; xrfragment_URI.parse = function(url,filter) { var store = { }; - if(url.indexOf("#") == -1) { + if(url == null || url.indexOf("#") == -1) { return store; } var fragment = url.split("#"); @@ -966,7 +966,8 @@ xrf.navigator.to = (url,event) => { model.file = file xrf.add( model.scene ) xrf.model = model - xrf.eval( url, model ) // and eval URI XR fragments + xrf.eval( '#', model ) // execute the default projection '#' (if exist) + xrf.eval( url, model ) // and eval URI XR fragments xrf.navigator.pushState( `${dir}${file}`, hash ) resolve(model) }) @@ -1202,7 +1203,7 @@ const doPredefinedView = (opts) => { const predefinedView = (frag,scene,mesh) => { let id = frag.string - if( mesh.userData[id] ){ + if( mesh.userData[`#${id}`] ){ let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED ) for ( let k in frag ){ let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE } diff --git a/src/3rd/js/three/navigator.js b/src/3rd/js/three/navigator.js index 8ef68b0..a071732 100644 --- a/src/3rd/js/three/navigator.js +++ b/src/3rd/js/three/navigator.js @@ -23,7 +23,8 @@ xrf.navigator.to = (url,event) => { model.file = file xrf.add( model.scene ) xrf.model = model - xrf.eval( url, model ) // and eval URI XR fragments + xrf.eval( '#', model ) // execute the default projection '#' (if exist) + xrf.eval( url, model ) // and eval URI XR fragments xrf.navigator.pushState( `${dir}${file}`, hash ) resolve(model) }) diff --git a/src/3rd/js/three/xrf/predefinedView.js b/src/3rd/js/three/xrf/predefinedView.js index 0e22f4b..8bb144e 100644 --- a/src/3rd/js/three/xrf/predefinedView.js +++ b/src/3rd/js/three/xrf/predefinedView.js @@ -25,7 +25,7 @@ const doPredefinedView = (opts) => { const predefinedView = (frag,scene,mesh) => { let id = frag.string - if( mesh.userData[id] ){ + if( mesh.userData[`#${id}`] ){ let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED ) for ( let k in frag ){ let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE } diff --git a/src/xrfragment/URI.hx b/src/xrfragment/URI.hx index ab55a16..d95bdb1 100644 --- a/src/xrfragment/URI.hx +++ b/src/xrfragment/URI.hx @@ -46,7 +46,7 @@ class URI { @:keep public static function parse(url:String,filter:Int):haxe.DynamicAccess { var store:haxe.DynamicAccess = {}; // 1. store key/values into a associative array or dynamic object - if( url.indexOf("#") == -1 ) return store; + if( url == null || url.indexOf("#") == -1 ) return store; var fragment:Array = url.split("#"); // 1. fragment URI starts with `#` var splitArray:Array = fragment[1].split('&'); // 1. fragments are split by `&` for (i in 0...splitArray.length) { // 1. loop thru each fragment diff --git a/test/generated/test.js b/test/generated/test.js index 38933dc..992b8e0 100644 --- a/test/generated/test.js +++ b/test/generated/test.js @@ -562,7 +562,7 @@ var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { }; xrfragment_URI.__name__ = true; xrfragment_URI.parse = function(url,filter) { var store = { }; - if(url.indexOf("#") == -1) { + if(url == null || url.indexOf("#") == -1) { return store; } var fragment = url.split("#"); diff --git a/test/generated/test.py b/test/generated/test.py index af25ec7..88f26ab 100644 --- a/test/generated/test.py +++ b/test/generated/test.py @@ -1599,8 +1599,8 @@ class xrfragment_Query: fails = 0 qualify = 0 def _hx_local_2(expr): - nonlocal fails nonlocal conds + nonlocal fails conds = (conds + 1) fails = (fails + (0 if expr else 1)) return expr @@ -1650,8 +1650,13 @@ class xrfragment_URI: @staticmethod def parse(url,_hx_filter): store = _hx_AnonObject({}) - startIndex = None - if (((url.find("#") if ((startIndex is None)) else HxString.indexOfImpl(url,"#",startIndex))) == -1): + tmp = None + if (url is not None): + startIndex = None + tmp = (((url.find("#") if ((startIndex is None)) else HxString.indexOfImpl(url,"#",startIndex))) == -1) + else: + tmp = True + if tmp: return store fragment = url.split("#") _this = (fragment[1] if 1 < len(fragment) else None)