bugfix ('es: set' event/metadata-key conflict) +global animation loop via default fragment fi fix + relative URL fix

This commit is contained in:
Leon van Kammen 2024-07-09 08:42:40 +00:00
parent aba739c317
commit 485c3d4cfd
6 changed files with 24 additions and 21 deletions

View File

@ -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)

View File

@ -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) => {

View File

@ -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} )
}

View File

@ -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}}`) ){

View File

@ -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!

View File

@ -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)
})