Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
feat/escaperoom: work in progress [might break]
Browse files Browse the repository at this point in the history
  • Loading branch information
coderofsalvation committed Jul 9, 2024
1 parent 485c3d4 commit 6fc94b6
Show file tree
Hide file tree
Showing 19 changed files with 10,172 additions and 1,666,897 deletions.
114 changes: 60 additions & 54 deletions dist/xrfragment.aframe.all.js

Large diffs are not rendered by default.

112 changes: 59 additions & 53 deletions dist/xrfragment.aframe.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* v0.5.1 generated at Wed Jun 26 11:16:30 AM UTC 2024
* v0.5.1 generated at Tue Jul 9 04:28:50 PM UTC 2024
* https://xrfragment.org
* SPDX-License-Identifier: MPL-2.0
*/
// Generated by Haxe 4.3.3
var $hx_exports = typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this;
(function ($global) { "use strict";
$hx_exports["xrfragment"] = $hx_exports["xrfragment"] || {};
Expand Down Expand Up @@ -158,24 +159,11 @@ Std.string = function(s) {
return js_Boot.__string_rec(s,"");
};
Std.parseInt = function(x) {
if(x != null) {
var _g = 0;
var _g1 = x.length;
while(_g < _g1) {
var i = _g++;
var c = x.charCodeAt(i);
if(c <= 8 || c >= 14 && c != 32 && c != 45) {
var nc = x.charCodeAt(i + 1);
var v = parseInt(x,nc == 120 || nc == 88 ? 16 : 10);
if(isNaN(v)) {
return null;
} else {
return v;
}
}
}
var v = parseInt(x);
if(isNaN(v)) {
return null;
}
return null;
return v;
};
var StringBuf = function() {
this.b = "";
Expand Down Expand Up @@ -471,10 +459,10 @@ haxe_Template.prototype = {
var _g_offset = 0;
var _g_s = data;
while(_g_offset < _g_s.length) {
var _g1_key = _g_offset;
var _g1_value = _g_s.charCodeAt(_g_offset++);
var i = _g1_key;
var c = _g1_value;
var _g_key = _g_offset;
var _g_value = _g_s.charCodeAt(_g_offset++);
var i = _g_key;
var c = _g_value;
if(c != 32) {
l.add({ p : HxOverrides.substr(data,i,null), s : true});
break;
Expand Down Expand Up @@ -1384,6 +1372,8 @@ xrfragment_URI.toAbsolute = function(url,newUrl) {
}
if(newURI.directory != null) {
if(newUrl.charAt(0) != "/" && newUrl.indexOf("://") == -1) {
var stripRelative_r = new RegExp("\\./.*","".split("u").join(""));
directory = directory.replace(stripRelative_r,"");
directory += newURI.directory;
} else {
directory = newURI.directory;
Expand Down Expand Up @@ -1668,6 +1658,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)
Expand Down Expand Up @@ -1845,12 +1836,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) => {
Expand Down Expand Up @@ -2024,14 +2016,15 @@ xrf.hasNoMaterial = (mesh) => {
const hasMaterialName = mesh.material && mesh.material.name.length > 0
return mesh.geometry && !hasMaterialName && !hasTexture
}

xrf.navigator = {
URI:{
scheme: document.location.protocol.replace(/:$/,''),
directory: document.location.pathname,
host: document.location.hostname,
port: document.location.port,
file: 'index.glb'
}
URI: xrf.URI.parse(document.location.href)
// scheme: document.location.protocol.replace(/:$/,''),
// directory: document.location.pathname,
// host: document.location.hostname,
// port: document.location.port,
// file: 'index.glb'
// }
}

xrf.navigator.to = (url,flags,loader,data) => {
Expand All @@ -2041,6 +2034,8 @@ xrf.navigator.to = (url,flags,loader,data) => {
URI.hash = xrf.navigator.reactifyHash(URI.hash) // automatically reflect hash-changes to navigator.to(...)
// decorate with extra state
URI.fileChange = URI.file && URI.URN + URI.file != xrf.navigator.URI.URN + xrf.navigator.URI.file
console.log( URI.URN + URI.file )
console.log( 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
Expand Down Expand Up @@ -2068,8 +2063,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 ){
Expand Down Expand Up @@ -2173,14 +2167,14 @@ xrf.navigator.setupNavigateFallbacks = () => {
xrf.navigator.updateHash = (hash,opts) => {
if( hash.replace(/^#/,'') == document.location.hash.substr(1) || hash.match(/\|/) ) return // skip unnecesary pushState triggers
console.log(`URI: ${document.location.search.substr(1)}#${hash}`)
xrf.navigator.updateHash.active = true // important to prevent recursion
xrf.navigator.updateHash.active = false // important to prevent recursion
document.location.hash = hash
xrf.navigator.updateHash.active = false
xrf.navigator.updateHash.active = true
}

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({}, '', document.location.pathname + `?${xrf.navigator.URI.source.replace(/#.*/,'')}#${hash}` )
xrf.emit('pushState', {file, hash} )
}

Expand Down Expand Up @@ -2243,7 +2237,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!
Expand Down Expand Up @@ -2361,8 +2356,9 @@ xrf.addEventListener('audioInited', function(opts){
*/
// this is called by navigator.js rather than by a URL e.g.

xrf.frag.defaultPredefinedViews = (opts) => {
xrf.frag['#'] = xrf.frag.defaultPredefinedViews = (opts) => {
let {scene,model} = opts;
if( !scene ) return
let defaultFragment;
scene.traverse( (n) => {
if( n.userData && n.userData['#'] ){
Expand Down Expand Up @@ -2715,10 +2711,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()
Expand All @@ -2739,7 +2742,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 ){
Expand All @@ -2762,7 +2765,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 ){
Expand All @@ -2774,12 +2776,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)
})

Expand Down Expand Up @@ -3401,8 +3397,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) )
Expand Down Expand Up @@ -3431,10 +3427,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}}`) ){
Expand Down Expand Up @@ -4178,6 +4175,14 @@ window.AFRAME.registerComponent('xrf', {
if( VRbutton ) VRbutton.addEventListener('click', () => AFRAME.XRF.hashbus.pub( '#VR' ) )
})

// not part of the spec, but convenient to only show AR button when negative VR-tag was defined in default fragment ('#' in rootscene file)
xrf.addEventListener('#', function(e){
if( e.frag['#'].string.match(/-VR/) ){
aScene.removeAttribute('xr-mode-ui')
aScene.setAttribute('xr-mode-ui',"XRMode: ar")
}
})

let repositionUser = (scale) => () => {
// sometimes AFRAME resets the user position to 0,0,0 when entering VR (not sure why)
setTimeout( () => {
Expand All @@ -4190,6 +4195,7 @@ window.AFRAME.registerComponent('xrf', {
aScene.addEventListener('enter-ar', repositionUser(2) )

xrf.addEventListener('navigateLoaded', (opts) => {

setTimeout( () => AFRAME.fade.out(),500)
let isLocal = opts.url.match(/^#/)
if( isLocal ) return
Expand Down
32 changes: 11 additions & 21 deletions dist/xrfragment.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6fc94b6

Please sign in to comment.