From 485c3d4cfde0e1e87257e15d280edbb96d638dac Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 9 Jul 2024 08:42:40 +0000 Subject: [PATCH] bugfix ('es: set' event/metadata-key conflict) +global animation loop via default fragment fi fix + relative URL fix --- src/3rd/js/pubsub.js | 1 + src/3rd/js/three/hashbus.js | 13 +++++++------ src/3rd/js/three/navigator.js | 5 ++--- src/3rd/js/three/xrf/dynamic/URIvars.js | 7 ++++--- src/3rd/js/three/xrf/href.js | 3 ++- src/3rd/js/three/xrf/t.js | 16 ++++++++-------- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/3rd/js/pubsub.js b/src/3rd/js/pubsub.js index 9a2ba13..8c74ef8 100644 --- a/src/3rd/js/pubsub.js +++ b/src/3rd/js/pubsub.js @@ -39,6 +39,7 @@ xrf.emit = function(eventName, data){ console.groupCollapsed(label) console.info(data) console.groupEnd(label) + if( eventName == 'reset' ) debugger if( xrf.debug > 2 ) debugger } return xrf.emit.promise(eventName,data) diff --git a/src/3rd/js/three/hashbus.js b/src/3rd/js/three/hashbus.js index e83b1ae..b750358 100644 --- a/src/3rd/js/three/hashbus.js +++ b/src/3rd/js/three/hashbus.js @@ -39,12 +39,13 @@ pub.fragment = (k, opts ) => { // evaluate one fragment if( !opts.skipXRWG && isPVorMediaFrag ) pub.XRWG(k,opts) // call native function (xrf/env.js e.g.), or pass it to user decorator - xrf.emit(k,opts) - .then( () => { - let func = xrf.frag[k] || function(){} - if( typeof xrf[k] == 'function' ) xrf[k]( func, frag, opts) - else func( frag, opts) - }) + if( xrf.frag[k] ){ + xrf.emit(k,opts) + .then( () => { + let func = xrf.frag[k] || function(){} + func( frag, opts) + }) + } } pub.XRWG = (word,opts) => { diff --git a/src/3rd/js/three/navigator.js b/src/3rd/js/three/navigator.js index fdf8157..a3f4679 100644 --- a/src/3rd/js/three/navigator.js +++ b/src/3rd/js/three/navigator.js @@ -42,8 +42,7 @@ xrf.navigator.to = (url,flags,loader,data) => { loader = loader || new Loader().setPath( URI.URN ) } - - if( URI.duplicatePos || (!URI.fragment && !URI.file && !URI.fileExt) ){ + if( URI.duplicatePos || (!Object.values(URI.XRF).length && !URI.file && !URI.fileExt) ){ return resolve(xrf.model) // nothing we can do here } if( xrf.model && !URI.fileChange && URI.hashChange && !URI.hasPos ){ @@ -154,7 +153,7 @@ xrf.navigator.updateHash = (hash,opts) => { xrf.navigator.pushState = (file,hash) => { if( file == document.location.search.substr(1) ) return // page is in its default state - window.history.pushState({},`${file}#${hash}`, document.location.pathname + `?${file}#${hash}` ) + window.history.pushState({},`${file}#${hash}`, document.location.pathname + `?${xrf.navigator.URI.source}#${hash}` ) xrf.emit('pushState', {file, hash} ) } diff --git a/src/3rd/js/three/xrf/dynamic/URIvars.js b/src/3rd/js/three/xrf/dynamic/URIvars.js index bbae122..db5635f 100644 --- a/src/3rd/js/three/xrf/dynamic/URIvars.js +++ b/src/3rd/js/three/xrf/dynamic/URIvars.js @@ -26,8 +26,8 @@ xrf.addEventListener('parseModel', (opts) => { if( n.userData ){ for( let i in n.userData ){ - if( i[0] == '#' || i.match(/^(href|tag)$/) ) continue // ignore XR Fragment aliases - if( i == 'src' ){ + //if( i[0] == '#' || i.match(/^(href|tag)$/) ) continue // ignore XR Fragment aliases + if( i.match(/^(src|href|tag)/) ){ // lets declare empty variables found in src-values ('https://foo.com/video.mp4#{somevar}') e.g. if( n.userData[i].match(variables) ){ let vars = [].concat( n.userData[i].match(variables) ) @@ -56,10 +56,11 @@ xrf.addEventListener('dynamicKeyValue', (opts) => { if( !xrf.URI.vars[ v.string ] ) return console.error(`'${v.string}' metadata-key not found in scene`) //if( xrf.URI.vars[ id ] && !match.length ) return console.error(`'${id}' object/tag/metadata-key not found in scene`) - if( xrf.debug ) console.log(`URI.vars[${id}]='${v.string}'`) + if( xrf.debug ) console.log(`URI.vars[${id}] => '${v.string}'`) if( xrf.URI.vars[id] ){ xrf.URI.vars[ id ] = xrf.URI.vars[ v.string ] // update var + if( xrf.debug ) console.log(`URI.vars[${id}] => '${xrf.URI.vars[ v.string ]()}'`) xrf.scene.traverse( (n) => { // re-expand src-values which use the updated URI Template var if( n.userData && n.userData.src && n.userData.srcTemplate && n.userData.srcTemplate.match(`{${id}}`) ){ diff --git a/src/3rd/js/three/xrf/href.js b/src/3rd/js/three/xrf/href.js index c596f5d..669c95c 100644 --- a/src/3rd/js/three/xrf/href.js +++ b/src/3rd/js/three/xrf/href.js @@ -38,7 +38,8 @@ xrf.frag.href = function(v, opts){ if( !mesh.material || !mesh.material.visible ) return // ignore invisible nodes // update our values to the latest value (might be edited) - xrf.Parser.parse( "href", mesh.userData.href, frag ) + let URI = xrf.URI.template( mesh.userData.href, xrf.URI.vars.__object ) + xrf.Parser.parse( "href", URI, frag ) const v = frag.href // bubble up! diff --git a/src/3rd/js/three/xrf/t.js b/src/3rd/js/three/xrf/t.js index 792cc4e..1a8bd91 100644 --- a/src/3rd/js/three/xrf/t.js +++ b/src/3rd/js/three/xrf/t.js @@ -40,10 +40,17 @@ xrf.frag.t.default = { xrf.addEventListener('parseModel', (opts) => { let {model} = opts let mixer = model.mixer = new xrf.THREE.AnimationMixer(model.scene) + mixer.model = model mixer.loop = {timeStart:0,timeStop:0,speed:1.0} mixer.i = xrf.mixers.length mixer.actions = [] + + // calculate total duration/frame based on longest animation + mixer.duration = 0 + if( model.animations.length ){ + model.animations.map( (a) => mixer.duration = ( a.duration > mixer.duration ) ? a.duration : mixer.duration ) + } model.animations.map( (anim) => { anim.optimize() @@ -64,7 +71,7 @@ xrf.addEventListener('parseModel', (opts) => { mixer.updateLoop = (t) => { if( t ){ mixer.loop.timeStart = t.x != undefined ? t.x : mixer.loop.timeStart - mixer.loop.timeStop = t.y != undefined ? t.y : mixer.duration + mixer.loop.timeStop = t.y != undefined ? t.y : mixer.loop.timeStop } mixer.actions.map( (action) => { if( mixer.loop.timeStart != undefined ){ @@ -87,7 +94,6 @@ xrf.addEventListener('parseModel', (opts) => { mixer.update = function(time){ mixer.time = Math.abs(mixer.time) if( time == 0 ) return update.call(this,time) - // loop jump if( mixer.loop.timeStop > 0 && mixer.time > mixer.loop.timeStop ){ if( mixer.loop.enabled ){ @@ -99,12 +105,6 @@ xrf.addEventListener('parseModel', (opts) => { mixer.update.patched = true } - // calculate total duration/frame based on longest animation - mixer.duration = 0 - if( model.animations.length ){ - model.animations.map( (a) => mixer.duration = ( a.duration > mixer.duration ) ? a.duration : mixer.duration ) - } - xrf.mixers.push(mixer) })