work in progress [might break]
This commit is contained in:
parent
34a398da1d
commit
cb7340d209
|
@ -1,6 +1,3 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) 2023 Leon van Kammen/NLNET
|
||||
|
||||
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"] || {};
|
||||
|
@ -253,11 +250,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:75:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:78:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
@ -266,6 +263,7 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) {
|
||||
this.isNumber = new EReg("^[0-9\\.]+$","");
|
||||
this.isClass = new EReg("^[-]?class$","");
|
||||
this.isAddition = new EReg("^\\+","");
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
|
@ -329,6 +327,9 @@ xrfragment_Query.prototype = {
|
|||
if(_gthis.isExclude.match(k)) {
|
||||
oper = "!=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else if(_gthis.isAddition.match(k)) {
|
||||
oper = "+=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else {
|
||||
v = HxOverrides.substr(v,oper.length,null);
|
||||
}
|
||||
|
@ -596,9 +597,80 @@ xrfragment_XRF.isUrlOrPretypedView = new EReg("(^#|://)?\\..*","");
|
|||
xrfragment_XRF.isString = new EReg(".*","");
|
||||
})({});
|
||||
var xrfragment = $hx_exports["xrfragment"];
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) 2023 Leon van Kammen/NLNET
|
||||
|
||||
var xrf = {}
|
||||
|
||||
xrf.init = function(opts){
|
||||
opts = opts || {}
|
||||
xrf.Parser.debug = xrf.debug
|
||||
for ( let i in opts ) xrf[i] = opts[i]
|
||||
xrf.emit('init',opts)
|
||||
return xrf.query
|
||||
}
|
||||
|
||||
xrf.query = function(){
|
||||
// framework implementations can override this function, see src/3rd/js/three/index.sj
|
||||
alert("queries are not implemented (yet) for this particular framework")
|
||||
}
|
||||
|
||||
// map library functions to xrf
|
||||
for ( let i in xrfragment ) xrf[i] = xrfragment[i]
|
||||
/*
|
||||
* (promise-able) EVENTS
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* xrf.addEventListener('foo',(e) => {
|
||||
* // let promise = e.promise()
|
||||
* console.log("navigating to: "+e.detail.destination.url)
|
||||
* // promise.resolve()
|
||||
* // promise.reject("not going to happen")
|
||||
* })
|
||||
*
|
||||
* xrf.emit('foo',123)
|
||||
* xrf.emit('foo',123).then(...).catch(...).finally(...)
|
||||
*/
|
||||
|
||||
xrf.addEventListener = function(eventName, callback) {
|
||||
if( !this._listeners ) this._listeners = []
|
||||
if (!this._listeners[eventName]) {
|
||||
// create a new array for this event name if it doesn't exist yet
|
||||
this._listeners[eventName] = [];
|
||||
}
|
||||
// add the callback to the listeners array for this event name
|
||||
this._listeners[eventName].push(callback);
|
||||
};
|
||||
|
||||
xrf.emit = function(eventName, data){
|
||||
return xrf.emit.promise(eventName,data)
|
||||
}
|
||||
|
||||
xrf.emit.normal = function(eventName, data) {
|
||||
if( !xrf._listeners ) xrf._listeners = []
|
||||
var callbacks = xrf._listeners[eventName]
|
||||
if (callbacks) {
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
callbacks[i](data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xrf.emit.promise = function(e, opts){
|
||||
opts.XRF = xrf // always pass root XRF obj
|
||||
return new Promise( (resolve, reject) => {
|
||||
opts.promise = () => {
|
||||
opts.promise.halted = true
|
||||
return { resolve, reject }
|
||||
}
|
||||
xrf.emit.normal(e, opts)
|
||||
if( !opts.promise.halted ) resolve()
|
||||
})
|
||||
}
|
||||
// wrapper to survive in/outside modules
|
||||
|
||||
xrfragment.InteractiveGroup = function(THREE,renderer,camera){
|
||||
xrf.InteractiveGroup = function(THREE,renderer,camera){
|
||||
|
||||
let {
|
||||
Group,
|
||||
|
@ -732,24 +804,19 @@ xrfragment.InteractiveGroup = function(THREE,renderer,camera){
|
|||
|
||||
return new InteractiveGroup(renderer,camera)
|
||||
}
|
||||
let xrf = xrfragment
|
||||
xrf.frag = {}
|
||||
xrf.model = {}
|
||||
|
||||
xrf.init = function(opts){
|
||||
opts = opts || {}
|
||||
let XRF = function(){
|
||||
alert("queries are not implemented (yet)")
|
||||
}
|
||||
for ( let i in opts ) xrf[i] = opts[i]
|
||||
for ( let i in xrf.XRF ) xrf.XRF[i] // shortcuts to constants (NAVIGATOR e.g.)
|
||||
xrf.Parser.debug = xrf.debug
|
||||
xrf.init = ((init) => function(opts){
|
||||
init(opts)
|
||||
if( opts.loaders ) Object.values(opts.loaders).map( xrf.patchLoader )
|
||||
|
||||
xrf.patchRenderer(opts.renderer)
|
||||
xrf.navigator.init()
|
||||
return xrf
|
||||
}
|
||||
// return xrfragment lib as 'xrf' query functor (like jquery)
|
||||
for ( let i in xrf ) xrf.query[i] = xrf[i]
|
||||
return xrf.query
|
||||
})(xrf.init)
|
||||
|
||||
xrf.patchRenderer = function(renderer){
|
||||
renderer.xr.addEventListener( 'sessionstart', () => xrf.baseReferenceSpace = renderer.xr.getReferenceSpace() );
|
||||
|
@ -765,7 +832,10 @@ xrf.patchLoader = function(loader){
|
|||
loader.prototype.load = ((load) => function(url, onLoad, onProgress, onError){
|
||||
load.call( this,
|
||||
url,
|
||||
(model) => { onLoad(model); xrf.parseModel(model,url) },
|
||||
(model) => {
|
||||
onLoad(model);
|
||||
xrf.parseModel(model,url)
|
||||
},
|
||||
onProgress,
|
||||
onError)
|
||||
})(loader.prototype.load)
|
||||
|
@ -776,9 +846,16 @@ xrf.getFile = (url) => url.split("/").pop().replace(/#.*/,'')
|
|||
xrf.parseModel = function(model,url){
|
||||
let file = xrf.getFile(url)
|
||||
model.file = file
|
||||
model.render = function(){}
|
||||
// eval embedded XR fragments
|
||||
model.scene.traverse( (mesh) => xrf.eval.mesh(mesh,model) )
|
||||
// add animations
|
||||
model.clock = new THREE.Clock();
|
||||
model.mixer = new THREE.AnimationMixer(model.scene)
|
||||
console.dir(model)
|
||||
model.animations.map( (anim) => model.mixer.clipAction( anim ).play() )
|
||||
model.render = function(){
|
||||
model.mixer.update( model.clock.getDelta() )
|
||||
}
|
||||
}
|
||||
|
||||
xrf.getLastModel = () => xrf.model.last
|
||||
|
@ -793,12 +870,10 @@ xrf.eval = function( url, model ){
|
|||
for ( let i in meshes ) {
|
||||
for ( let k in frag ){
|
||||
let mesh = meshes[i]
|
||||
if( !String(k).match(/(pos|rot)/) ) notice = true
|
||||
let opts = {frag, mesh, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
||||
xrf.eval.fragment(k,opts)
|
||||
}
|
||||
}
|
||||
if( notice ) alert("only 'pos' and 'rot' XRF.NAVIGATOR-flagged XR fragments are supported (for now)")
|
||||
}
|
||||
|
||||
xrf.eval.mesh = (mesh,model) => {
|
||||
|
@ -879,7 +954,7 @@ xrf.navigator.to = (url,event) => {
|
|||
xrf.add( model.scene )
|
||||
xrf.model = model
|
||||
xrf.eval( url, model ) // and eval URI XR fragments
|
||||
xrf.navigator.pushState( file, hash )
|
||||
xrf.navigator.pushState( `${dir}${file}`, hash )
|
||||
resolve(model)
|
||||
})
|
||||
})
|
||||
|
@ -897,57 +972,6 @@ 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}` )
|
||||
}
|
||||
/*
|
||||
* (promise-able) EVENTS
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* xrf.addEventListener('foo',(e) => {
|
||||
* // let promise = e.promise()
|
||||
* console.log("navigating to: "+e.detail.destination.url)
|
||||
* // promise.resolve()
|
||||
* // promise.reject("not going to happen")
|
||||
* })
|
||||
*
|
||||
* xrf.emit('foo',123)
|
||||
* xrf.emit('foo',123).then(...).catch(...).finally(...)
|
||||
*/
|
||||
|
||||
xrf.addEventListener = function(eventName, callback) {
|
||||
if( !this._listeners ) this._listeners = []
|
||||
if (!this._listeners[eventName]) {
|
||||
// create a new array for this event name if it doesn't exist yet
|
||||
this._listeners[eventName] = [];
|
||||
}
|
||||
// add the callback to the listeners array for this event name
|
||||
this._listeners[eventName].push(callback);
|
||||
};
|
||||
|
||||
xrf.emit = function(eventName, data){
|
||||
return xrf.emit.promise(eventName,data)
|
||||
}
|
||||
|
||||
xrf.emit.normal = function(eventName, data) {
|
||||
if( !xrf._listeners ) xrf._listeners = []
|
||||
var callbacks = xrf._listeners[eventName]
|
||||
if (callbacks) {
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
callbacks[i](data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xrf.emit.promise = function(e, opts){
|
||||
opts.XRF = xrf // always pass root XRF obj
|
||||
return new Promise( (resolve, reject) => {
|
||||
opts.promise = () => {
|
||||
opts.promise.halted = true
|
||||
return { resolve, reject }
|
||||
}
|
||||
xrf.emit.normal(e, opts)
|
||||
if( !opts.promise.halted ) resolve()
|
||||
})
|
||||
}
|
||||
xrf.frag.env = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
let env = mesh.getObjectByName(v.string)
|
||||
|
@ -1021,13 +1045,6 @@ xrf.frag.href = function(v, opts){
|
|||
scale: new THREE.Vector3(),
|
||||
quat: new THREE.Quaternion()
|
||||
}
|
||||
mesh.getWorldPosition(world.pos)
|
||||
mesh.getWorldScale(world.scale)
|
||||
mesh.getWorldQuaternion(world.quat);
|
||||
mesh.position.copy(world.pos)
|
||||
mesh.scale.copy(world.scale)
|
||||
mesh.setRotationFromQuaternion(world.quat);
|
||||
|
||||
// detect equirectangular image
|
||||
let texture = mesh.material.map
|
||||
if( texture && texture.source.data.height == texture.source.data.width/2 ){
|
||||
|
@ -1076,12 +1093,41 @@ xrf.frag.href = function(v, opts){
|
|||
`,
|
||||
});
|
||||
mesh.material.needsUpdate = true
|
||||
}
|
||||
}else mesh.material = mesh.material.clone()
|
||||
|
||||
let teleport = mesh.userData.XRF.href.exec = (e) => {
|
||||
xrf
|
||||
.emit('href',{click:true,mesh,xrf:v}) // let all listeners agree
|
||||
.then( () => xrf.navigator.to(v.string) ) // ok let's surf to HREF!
|
||||
let click = mesh.userData.XRF.href.exec = (e) => {
|
||||
if( v.string[0] == '#' ){
|
||||
let frag = xrf.URI.parse(v.string)
|
||||
if( frag.q ){ // show/hider
|
||||
let q = frag.q.query
|
||||
scene.traverse( (mesh) => {
|
||||
for ( let i in q ) {
|
||||
if( i == mesh.name && q[i].id != undefined ) mesh.visible = q[i].id
|
||||
if( i == mesh.userData.class && q[i].class != undefined ) mesh.visible = q[i].class
|
||||
}
|
||||
})
|
||||
}else if( !v.string.match(/=/) ){ // projection or Selection of Interest (SoI)
|
||||
let id = v.string.substr(1)
|
||||
scene.traverse( (mesh) => {
|
||||
if( mesh.selection ){
|
||||
mesh.remove(mesh.selection)
|
||||
delete mesh.selection
|
||||
}
|
||||
if( id == mesh.name || id == mesh.userData.class ){
|
||||
console.log("applying selection")
|
||||
mesh.selection = new THREE.BoxHelper(mesh,0xff00ff)
|
||||
mesh.selection.scale.set(2,2,2)
|
||||
mesh.selection.position.copy( mesh.position )
|
||||
scene.add(mesh.selection)
|
||||
}
|
||||
})
|
||||
|
||||
}else{ // teleport
|
||||
xrf
|
||||
.emit('href',{click:true,mesh,xrf:v}) // let all listeners agree
|
||||
.then( () => xrf.navigator.to(v.string) ) // ok let's surf to HREF!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let selected = (state) => () => {
|
||||
|
@ -1097,14 +1143,18 @@ xrf.frag.href = function(v, opts){
|
|||
.then( () => mesh.selected = state )
|
||||
}
|
||||
|
||||
if( !opts.frag.q ){ // query means an action
|
||||
mesh.addEventListener('click', teleport )
|
||||
mesh.addEventListener('mousemove', selected(true) )
|
||||
mesh.addEventListener('nocollide', selected(false) )
|
||||
}
|
||||
mesh.addEventListener('click', click )
|
||||
mesh.addEventListener('mousemove', selected(true) )
|
||||
mesh.addEventListener('nocollide', selected(false) )
|
||||
|
||||
// lazy add mesh (because we're inside a recursive traverse)
|
||||
setTimeout( (mesh) => {
|
||||
mesh.getWorldPosition(world.pos)
|
||||
mesh.getWorldScale(world.scale)
|
||||
mesh.getWorldQuaternion(world.quat);
|
||||
mesh.position.copy(world.pos)
|
||||
mesh.scale.copy(world.scale)
|
||||
mesh.setRotationFromQuaternion(world.quat);
|
||||
xrf.interactive.add(mesh)
|
||||
}, 20, mesh )
|
||||
}
|
||||
|
@ -1170,16 +1220,35 @@ xrf.frag.pos = function(v, opts){
|
|||
xrf.frag.q = function(v, opts){
|
||||
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
||||
console.log(" └ running query ")
|
||||
let qobjs = Object.keys(v.query)
|
||||
|
||||
v.scene = new THREE.Group()
|
||||
for ( let i in v.query ) {
|
||||
let target = v.query[i]
|
||||
|
||||
// remove objects if requested
|
||||
if( target.id != undefined && (target.mesh = scene.getObjectByName(i)) ){
|
||||
target.mesh.visible = target.id
|
||||
target.mesh.parent.remove(target.mesh)
|
||||
console.log(` └ removing mesh: ${i}`)
|
||||
}else console.log(` └ mesh not found: ${i}`)
|
||||
if( !scene.getObjectByName(i) && i != '*' ) return console.log(` └ mesh not found: ${i}`)
|
||||
if( i == '*' ){
|
||||
let cloneScene = scene.clone()
|
||||
cloneScene.children.forEach( (child) => v.scene.getObjectByName(child.name) ? null : v.scene.add(child) )
|
||||
target.mesh = v.scene
|
||||
}else{
|
||||
console.log(` └ query-ing mesh: ${i}`)
|
||||
if( !v.scene.getObjectByName(i) && target.id === true ){
|
||||
v.scene.add( target.mesh = scene.getObjectByName(i).clone() )
|
||||
}
|
||||
}
|
||||
if( target.id != undefined && target.mesh ){
|
||||
target.mesh.position.set(0,0,0)
|
||||
target.mesh.rotation.set(0,0,0)
|
||||
}
|
||||
}
|
||||
// remove negative selectors
|
||||
let remove = []
|
||||
v.scene.traverse( (mesh) => {
|
||||
for ( let i in v.query ) {
|
||||
if( mesh.name == i && v.query[i].id === false ) remove.push(mesh)
|
||||
}
|
||||
})
|
||||
remove.map( (mesh) => mesh.parent.remove( mesh ) )
|
||||
}
|
||||
xrf.frag.rot = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
@ -1195,37 +1264,38 @@ xrf.frag.rot = function(v, opts){
|
|||
|
||||
xrf.frag.src = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
let src = new THREE.Group()
|
||||
|
||||
if( v.string[0] == "#" ){ // local
|
||||
console.log(" └ instancing src")
|
||||
let frag = xrfragment.URI.parse(v.string)
|
||||
// Get an instance of the original model
|
||||
let sceneInstance = new THREE.Group()
|
||||
sceneInstance.isSrc = true
|
||||
|
||||
// prevent infinite recursion #1: skip src-instanced models
|
||||
for ( let i in model.scene.children ) {
|
||||
let child = model.scene.children[i]
|
||||
if( child.isSrc ) continue;
|
||||
sceneInstance.add( model.scene.children[i].clone() )
|
||||
}
|
||||
|
||||
sceneInstance.position.copy( mesh.position )
|
||||
sceneInstance.scale.copy(mesh.scale)
|
||||
sceneInstance.updateMatrixWorld(true) // needed because we're going to move portals to the interactive-group
|
||||
|
||||
// apply embedded XR fragments
|
||||
setTimeout( () => {
|
||||
sceneInstance.traverse( (m) => {
|
||||
if( m.userData && m.userData.src ) return ;//delete m.userData.src // prevent infinite recursion
|
||||
xrf.eval.mesh(m,{scene,recursive:true})
|
||||
})
|
||||
// Add the instance to the scene
|
||||
//model.scene.add(clone);
|
||||
// apply URI XR Fragments inside src-value
|
||||
for( var i in frag ){
|
||||
xrf.eval.fragment(i, Object.assign(opts,{frag, model:{scene:sceneInstance},scene:sceneInstance}))
|
||||
xrf.eval.fragment(i, Object.assign(opts,{frag, model,scene}))
|
||||
}
|
||||
// Add the instance to the scene
|
||||
model.scene.add(sceneInstance);
|
||||
if( frag.q.query ){
|
||||
let srcScene = frag.q.scene
|
||||
if( !srcScene || !srcScene.visible ) return
|
||||
console.log(" └ inserting "+i+" (srcScene)")
|
||||
srcScene.position.set(0,0,0)
|
||||
srcScene.rotation.set(0,0,0)
|
||||
srcScene.traverse( (m) => {
|
||||
if( m.userData && (m.userData.src || m.userData.href) ) return ;//delete m.userData.src // prevent infinite recursion
|
||||
xrf.eval.mesh(m,{scene,recursive:true})
|
||||
})
|
||||
if( srcScene.visible ) src.add( srcScene )
|
||||
}
|
||||
src.position.copy( mesh.position )
|
||||
src.rotation.copy( mesh.rotation )
|
||||
src.scale.copy( mesh.scale )
|
||||
mesh.add(src)
|
||||
console.dir(opts)
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations
|
||||
},10)
|
||||
}
|
||||
}
|
||||
|
@ -1250,7 +1320,7 @@ window.AFRAME.registerComponent('xrf', {
|
|||
|
||||
// enable XR fragments
|
||||
let aScene = document.querySelector('a-scene')
|
||||
let XRF = AFRAME.XRF = xrfragment.init({
|
||||
let XRF = AFRAME.XRF = xrf.init({
|
||||
THREE,
|
||||
camera: aScene.camera,
|
||||
scene: aScene.object3D,
|
||||
|
@ -1266,20 +1336,23 @@ window.AFRAME.registerComponent('xrf', {
|
|||
xrf(v,opts)
|
||||
}
|
||||
|
||||
XRF.pos = camOverride
|
||||
xrf.pos = camOverride
|
||||
|
||||
// in order to set the rotation programmatically
|
||||
// we need to disable look-controls
|
||||
XRF.rot = (xrf,v,opts) => {
|
||||
xrf.rot = (xrf,v,opts) => {
|
||||
let {renderer} = opts;
|
||||
let look = document.querySelector('[look-controls]')
|
||||
if( look ) look.removeAttribute("look-controls")
|
||||
camOverride(xrf,v,opts)
|
||||
// *TODO* make look-controls compatible, because simply
|
||||
// adding the look-controls will revert to the old rotation (cached somehow?)
|
||||
//setTimeout( () => look.setAttribute("look-controls",""), 100 )
|
||||
}
|
||||
|
||||
// convert portal to a-entity so AFRAME
|
||||
// raycaster can find & execute it
|
||||
XRF.href = (xrf,v,opts) => {
|
||||
xrf.href = (xrf,v,opts) => {
|
||||
camOverride(xrf,v,opts)
|
||||
let {mesh,camera} = opts;
|
||||
let el = document.createElement("a-entity")
|
||||
|
@ -1290,7 +1363,7 @@ window.AFRAME.registerComponent('xrf', {
|
|||
}
|
||||
|
||||
// cleanup xrf-get objects when resetting scene
|
||||
XRF.reset = ((reset) => () => {
|
||||
xrf.reset = ((reset) => () => {
|
||||
reset()
|
||||
console.log("aframe reset")
|
||||
let els = [...document.querySelectorAll('[xrf-get]')]
|
||||
|
@ -1428,11 +1501,12 @@ window.AFRAME.registerComponent('xrf-get', {
|
|||
console.error("mesh with name '"+meshname+"' not found in model")
|
||||
return;
|
||||
}
|
||||
// convert to worldcoordinates
|
||||
mesh.getWorldPosition(mesh.position)
|
||||
mesh.getWorldScale(mesh.scale)
|
||||
mesh.getWorldQuaternion(mesh.quaternion)
|
||||
if( !this.data.clone ) mesh.parent.remove(mesh)
|
||||
////mesh.updateMatrixWorld();
|
||||
this.el.object3D.position.setFromMatrixPosition(scene.matrixWorld);
|
||||
this.el.object3D.quaternion.setFromRotationMatrix(scene.matrixWorld);
|
||||
mesh.xrf = true // mark for deletion by xrf
|
||||
mesh.isXRF = true // mark for deletion by xrf
|
||||
this.el.setObject3D('mesh', mesh );
|
||||
if( !this.el.id ) this.el.setAttribute("id",`xrf-${mesh.name}`)
|
||||
|
||||
|
|
|
@ -0,0 +1,599 @@
|
|||
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"] || {};
|
||||
var EReg = function(r,opt) {
|
||||
this.r = new RegExp(r,opt.split("u").join(""));
|
||||
};
|
||||
EReg.__name__ = true;
|
||||
EReg.prototype = {
|
||||
match: function(s) {
|
||||
if(this.r.global) {
|
||||
this.r.lastIndex = 0;
|
||||
}
|
||||
this.r.m = this.r.exec(s);
|
||||
this.r.s = s;
|
||||
return this.r.m != null;
|
||||
}
|
||||
,split: function(s) {
|
||||
var d = "#__delim__#";
|
||||
return s.replace(this.r,d).split(d);
|
||||
}
|
||||
};
|
||||
var HxOverrides = function() { };
|
||||
HxOverrides.__name__ = true;
|
||||
HxOverrides.cca = function(s,index) {
|
||||
var x = s.charCodeAt(index);
|
||||
if(x != x) {
|
||||
return undefined;
|
||||
}
|
||||
return x;
|
||||
};
|
||||
HxOverrides.substr = function(s,pos,len) {
|
||||
if(len == null) {
|
||||
len = s.length;
|
||||
} else if(len < 0) {
|
||||
if(pos == 0) {
|
||||
len = s.length + len;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return s.substr(pos,len);
|
||||
};
|
||||
HxOverrides.now = function() {
|
||||
return Date.now();
|
||||
};
|
||||
Math.__name__ = true;
|
||||
var Reflect = function() { };
|
||||
Reflect.__name__ = true;
|
||||
Reflect.field = function(o,field) {
|
||||
try {
|
||||
return o[field];
|
||||
} catch( _g ) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reflect.fields = function(o) {
|
||||
var a = [];
|
||||
if(o != null) {
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
for( var f in o ) {
|
||||
if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) {
|
||||
a.push(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
Reflect.deleteField = function(o,field) {
|
||||
if(!Object.prototype.hasOwnProperty.call(o,field)) {
|
||||
return false;
|
||||
}
|
||||
delete(o[field]);
|
||||
return true;
|
||||
};
|
||||
var Std = function() { };
|
||||
Std.__name__ = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
var StringTools = function() { };
|
||||
StringTools.__name__ = true;
|
||||
StringTools.isSpace = function(s,pos) {
|
||||
var c = HxOverrides.cca(s,pos);
|
||||
if(!(c > 8 && c < 14)) {
|
||||
return c == 32;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
StringTools.ltrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,r)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,r,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.rtrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,l - r - 1)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,0,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.trim = function(s) {
|
||||
return StringTools.ltrim(StringTools.rtrim(s));
|
||||
};
|
||||
StringTools.replace = function(s,sub,by) {
|
||||
return s.split(sub).join(by);
|
||||
};
|
||||
var haxe_iterators_ArrayIterator = function(array) {
|
||||
this.current = 0;
|
||||
this.array = array;
|
||||
};
|
||||
haxe_iterators_ArrayIterator.__name__ = true;
|
||||
haxe_iterators_ArrayIterator.prototype = {
|
||||
hasNext: function() {
|
||||
return this.current < this.array.length;
|
||||
}
|
||||
,next: function() {
|
||||
return this.array[this.current++];
|
||||
}
|
||||
};
|
||||
var js_Boot = function() { };
|
||||
js_Boot.__name__ = true;
|
||||
js_Boot.__string_rec = function(o,s) {
|
||||
if(o == null) {
|
||||
return "null";
|
||||
}
|
||||
if(s.length >= 5) {
|
||||
return "<...>";
|
||||
}
|
||||
var t = typeof(o);
|
||||
if(t == "function" && (o.__name__ || o.__ename__)) {
|
||||
t = "object";
|
||||
}
|
||||
switch(t) {
|
||||
case "function":
|
||||
return "<function>";
|
||||
case "object":
|
||||
if(((o) instanceof Array)) {
|
||||
var str = "[";
|
||||
s += "\t";
|
||||
var _g = 0;
|
||||
var _g1 = o.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s);
|
||||
}
|
||||
str += "]";
|
||||
return str;
|
||||
}
|
||||
var tostr;
|
||||
try {
|
||||
tostr = o.toString;
|
||||
} catch( _g ) {
|
||||
return "???";
|
||||
}
|
||||
if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") {
|
||||
var s2 = o.toString();
|
||||
if(s2 != "[object Object]") {
|
||||
return s2;
|
||||
}
|
||||
}
|
||||
var str = "{\n";
|
||||
s += "\t";
|
||||
var hasp = o.hasOwnProperty != null;
|
||||
var k = null;
|
||||
for( k in o ) {
|
||||
if(hasp && !o.hasOwnProperty(k)) {
|
||||
continue;
|
||||
}
|
||||
if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") {
|
||||
continue;
|
||||
}
|
||||
if(str.length != 2) {
|
||||
str += ", \n";
|
||||
}
|
||||
str += s + k + " : " + js_Boot.__string_rec(o[k],s);
|
||||
}
|
||||
s = s.substring(1);
|
||||
str += "\n" + s + "}";
|
||||
return str;
|
||||
case "string":
|
||||
return o;
|
||||
default:
|
||||
return String(o);
|
||||
}
|
||||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
Frag_h["class"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["src"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL;
|
||||
Frag_h["pos"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.T_STRING_OBJ | xrfragment_XRF.EMBEDDED | xrfragment_XRF.NAVIGATOR;
|
||||
Frag_h["href"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
Frag_h["q"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["scale"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["rot"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED | xrfragment_XRF.NAVIGATOR;
|
||||
Frag_h["translate"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["visible"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["env"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["t"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["gravity"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["physics"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["fov"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_INT | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["clip"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["fog"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["namespace"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["SPDX"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["unit"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) {
|
||||
this.isNumber = new EReg("^[0-9\\.]+$","");
|
||||
this.isClass = new EReg("^[-]?class$","");
|
||||
this.isAddition = new EReg("^\\+","");
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
this.str = "";
|
||||
if(str != null) {
|
||||
this.parse(str);
|
||||
}
|
||||
};
|
||||
xrfragment_Query.__name__ = true;
|
||||
xrfragment_Query.prototype = {
|
||||
toObject: function() {
|
||||
return this.q;
|
||||
}
|
||||
,expandAliases: function(token) {
|
||||
var classAlias = new EReg("^(-)?\\.","");
|
||||
if(classAlias.match(token)) {
|
||||
return StringTools.replace(token,".","class:");
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
var process = function(str,prefix) {
|
||||
if(prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
str = StringTools.trim(str);
|
||||
var k = str.split(":")[0];
|
||||
var v = str.split(":")[1];
|
||||
var filter = { };
|
||||
if(q[prefix + k]) {
|
||||
filter = q[prefix + k];
|
||||
}
|
||||
filter["rules"] = filter["rules"] != null ? filter["rules"] : [];
|
||||
if(_gthis.isProp.match(str)) {
|
||||
var oper = "";
|
||||
if(str.indexOf("*") != -1) {
|
||||
oper = "*";
|
||||
}
|
||||
if(str.indexOf(">") != -1) {
|
||||
oper = ">";
|
||||
}
|
||||
if(str.indexOf("<") != -1) {
|
||||
oper = "<";
|
||||
}
|
||||
if(str.indexOf(">=") != -1) {
|
||||
oper = ">=";
|
||||
}
|
||||
if(str.indexOf("<=") != -1) {
|
||||
oper = "<=";
|
||||
}
|
||||
if(_gthis.isExclude.match(k)) {
|
||||
oper = "!=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else if(_gthis.isAddition.match(k)) {
|
||||
oper = "+=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else {
|
||||
v = HxOverrides.substr(v,oper.length,null);
|
||||
}
|
||||
if(oper.length == 0) {
|
||||
oper = "=";
|
||||
}
|
||||
if(_gthis.isClass.match(k)) {
|
||||
filter[prefix + k] = oper != "!=";
|
||||
q[v] = filter;
|
||||
} else {
|
||||
var rule = { };
|
||||
if(_gthis.isNumber.match(v)) {
|
||||
rule[oper] = parseFloat(v);
|
||||
} else {
|
||||
rule[oper] = v;
|
||||
}
|
||||
filter["rules"].push(rule);
|
||||
q[k] = filter;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
filter["id"] = _gthis.isExclude.match(str) ? false : true;
|
||||
var key = _gthis.isExclude.match(str) ? HxOverrides.substr(str,1,null) : str;
|
||||
q[key] = filter;
|
||||
}
|
||||
};
|
||||
var _g = 0;
|
||||
var _g1 = token.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
process(this.expandAliases(token[i]));
|
||||
}
|
||||
return this.q = q;
|
||||
}
|
||||
,test: function(obj) {
|
||||
var qualify = false;
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(obj);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var v = Std.string(Reflect.field(obj,k));
|
||||
if(this.testProperty(k,v)) {
|
||||
qualify = true;
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(obj);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var v = Std.string(Reflect.field(obj,k));
|
||||
if(this.testProperty(k,v,true)) {
|
||||
qualify = false;
|
||||
}
|
||||
}
|
||||
return qualify;
|
||||
}
|
||||
,testProperty: function(property,value,exclude) {
|
||||
var conds = 0;
|
||||
var fails = 0;
|
||||
var qualify = 0;
|
||||
var testprop = function(expr) {
|
||||
conds += 1;
|
||||
fails += expr ? 0 : 1;
|
||||
return expr;
|
||||
};
|
||||
if(this.q[value] != null) {
|
||||
var v = this.q[value];
|
||||
if(v[property] != null) {
|
||||
return v[property];
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(this.q);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var filter = Reflect.field(this.q,k);
|
||||
if(filter.rules == null) {
|
||||
continue;
|
||||
}
|
||||
var rules = filter.rules;
|
||||
var _g2 = 0;
|
||||
while(_g2 < rules.length) {
|
||||
var rule = rules[_g2];
|
||||
++_g2;
|
||||
if(exclude) {
|
||||
if(Reflect.field(rule,"!=") != null && testprop((value == null ? "null" : "" + value) == Std.string(Reflect.field(rule,"!="))) && exclude) {
|
||||
++qualify;
|
||||
}
|
||||
} else {
|
||||
if(Reflect.field(rule,"*") != null && testprop(parseFloat(value) != null)) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,">") != null && testprop(parseFloat(value) > parseFloat(Reflect.field(rule,">")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"<") != null && testprop(parseFloat(value) < parseFloat(Reflect.field(rule,"<")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,">=") != null && testprop(parseFloat(value) >= parseFloat(Reflect.field(rule,">=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"<=") != null && testprop(parseFloat(value) <= parseFloat(Reflect.field(rule,"<=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"=") != null && (testprop(value == Reflect.field(rule,"=")) || testprop(parseFloat(value) == parseFloat(Reflect.field(rule,"="))))) {
|
||||
++qualify;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return qualify > 0;
|
||||
}
|
||||
};
|
||||
var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { };
|
||||
xrfragment_URI.__name__ = true;
|
||||
xrfragment_URI.parse = function(url,filter) {
|
||||
var store = { };
|
||||
if(url.indexOf("#") == -1) {
|
||||
return store;
|
||||
}
|
||||
var fragment = url.split("#");
|
||||
var splitArray = fragment[1].split("&");
|
||||
var _g = 0;
|
||||
var _g1 = splitArray.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var splitByEqual = splitArray[i].split("=");
|
||||
var regexPlus = new EReg("\\+","g");
|
||||
var key = splitByEqual[0];
|
||||
var value = "";
|
||||
if(splitByEqual.length > 1) {
|
||||
var s = regexPlus.split(splitByEqual[1]).join(" ");
|
||||
value = decodeURIComponent(s.split("+").join(" "));
|
||||
}
|
||||
var ok = xrfragment_Parser.parse(key,value,store);
|
||||
}
|
||||
if(filter != null && filter != 0) {
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(store);
|
||||
while(_g < _g1.length) {
|
||||
var key = _g1[_g];
|
||||
++_g;
|
||||
var xrf = store[key];
|
||||
if(!xrf.is(filter)) {
|
||||
Reflect.deleteField(store,key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return store;
|
||||
};
|
||||
var xrfragment_XRF = $hx_exports["xrfragment"]["XRF"] = function(_fragment,_flags) {
|
||||
this.fragment = _fragment;
|
||||
this.flags = _flags;
|
||||
};
|
||||
xrfragment_XRF.__name__ = true;
|
||||
xrfragment_XRF.set = function(flag,flags) {
|
||||
return flags | flag;
|
||||
};
|
||||
xrfragment_XRF.unset = function(flag,flags) {
|
||||
return flags & ~flag;
|
||||
};
|
||||
xrfragment_XRF.prototype = {
|
||||
is: function(flag) {
|
||||
return (this.flags & flag) != 0;
|
||||
}
|
||||
,validate: function(value) {
|
||||
this.guessType(this,value);
|
||||
if(value.split("|").length > 1) {
|
||||
this.args = [];
|
||||
var args = value.split("|");
|
||||
var _g = 0;
|
||||
var _g1 = args.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var x = new xrfragment_XRF(this.fragment,this.flags);
|
||||
this.guessType(x,args[i]);
|
||||
this.args.push(x);
|
||||
}
|
||||
}
|
||||
if(this.fragment == "q") {
|
||||
this.query = new xrfragment_Query(value).get();
|
||||
}
|
||||
var ok = true;
|
||||
if(!((this.args) instanceof Array)) {
|
||||
if(this.is(xrfragment_XRF.T_VECTOR3) && !(typeof(this.x) == "number" && typeof(this.y) == "number" && typeof(this.z) == "number")) {
|
||||
ok = false;
|
||||
}
|
||||
if(this.is(xrfragment_XRF.T_VECTOR2) && !(typeof(this.x) == "number" && typeof(this.y) == "number")) {
|
||||
ok = false;
|
||||
}
|
||||
var tmp;
|
||||
if(this.is(xrfragment_XRF.T_INT)) {
|
||||
var v = this.int;
|
||||
tmp = !(typeof(v) == "number" && ((v | 0) === v));
|
||||
} else {
|
||||
tmp = false;
|
||||
}
|
||||
if(tmp) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
,guessType: function(v,str) {
|
||||
v.string = str;
|
||||
if(str.split(",").length > 1) {
|
||||
var xyz = str.split(",");
|
||||
if(xyz.length > 0) {
|
||||
v.x = parseFloat(xyz[0]);
|
||||
}
|
||||
if(xyz.length > 1) {
|
||||
v.y = parseFloat(xyz[1]);
|
||||
}
|
||||
if(xyz.length > 2) {
|
||||
v.z = parseFloat(xyz[2]);
|
||||
}
|
||||
}
|
||||
if(xrfragment_XRF.isColor.match(str)) {
|
||||
v.color = str;
|
||||
}
|
||||
if(xrfragment_XRF.isFloat.match(str)) {
|
||||
v.float = parseFloat(str);
|
||||
}
|
||||
if(xrfragment_XRF.isInt.match(str)) {
|
||||
v.int = Std.parseInt(str);
|
||||
}
|
||||
}
|
||||
};
|
||||
if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) {
|
||||
HxOverrides.now = performance.now.bind(performance);
|
||||
}
|
||||
String.__name__ = true;
|
||||
Array.__name__ = true;
|
||||
js_Boot.__toStr = ({ }).toString;
|
||||
xrfragment_Parser.error = "";
|
||||
xrfragment_Parser.debug = false;
|
||||
xrfragment_XRF.ASSET = 1;
|
||||
xrfragment_XRF.PROP_BIND = 2;
|
||||
xrfragment_XRF.QUERY_OPERATOR = 4;
|
||||
xrfragment_XRF.PROMPT = 8;
|
||||
xrfragment_XRF.ROUNDROBIN = 16;
|
||||
xrfragment_XRF.NAVIGATOR = 32;
|
||||
xrfragment_XRF.EMBEDDED = 64;
|
||||
xrfragment_XRF.PV_OVERRIDE = 128;
|
||||
xrfragment_XRF.PV_EXECUTE = 256;
|
||||
xrfragment_XRF.T_COLOR = 8192;
|
||||
xrfragment_XRF.T_INT = 16384;
|
||||
xrfragment_XRF.T_FLOAT = 32768;
|
||||
xrfragment_XRF.T_VECTOR2 = 65536;
|
||||
xrfragment_XRF.T_VECTOR3 = 131072;
|
||||
xrfragment_XRF.T_URL = 262144;
|
||||
xrfragment_XRF.T_PREDEFINED_VIEW = 524288;
|
||||
xrfragment_XRF.T_STRING = 1048576;
|
||||
xrfragment_XRF.T_STRING_OBJ = 2097152;
|
||||
xrfragment_XRF.T_STRING_OBJ_PROP = 4194304;
|
||||
xrfragment_XRF.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$","");
|
||||
xrfragment_XRF.isInt = new EReg("^[0-9]+$","");
|
||||
xrfragment_XRF.isFloat = new EReg("^[0-9]+\\.[0-9]+$","");
|
||||
xrfragment_XRF.isVector = new EReg("([,]+|\\w)","");
|
||||
xrfragment_XRF.isUrl = new EReg("(://)?\\..*","");
|
||||
xrfragment_XRF.isUrlOrPretypedView = new EReg("(^#|://)?\\..*","");
|
||||
xrfragment_XRF.isString = new EReg(".*","");
|
||||
})({});
|
||||
var xrfragment = $hx_exports["xrfragment"];
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,600 @@
|
|||
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"] || {};
|
||||
var EReg = function(r,opt) {
|
||||
this.r = new RegExp(r,opt.split("u").join(""));
|
||||
};
|
||||
EReg.__name__ = true;
|
||||
EReg.prototype = {
|
||||
match: function(s) {
|
||||
if(this.r.global) {
|
||||
this.r.lastIndex = 0;
|
||||
}
|
||||
this.r.m = this.r.exec(s);
|
||||
this.r.s = s;
|
||||
return this.r.m != null;
|
||||
}
|
||||
,split: function(s) {
|
||||
var d = "#__delim__#";
|
||||
return s.replace(this.r,d).split(d);
|
||||
}
|
||||
};
|
||||
var HxOverrides = function() { };
|
||||
HxOverrides.__name__ = true;
|
||||
HxOverrides.cca = function(s,index) {
|
||||
var x = s.charCodeAt(index);
|
||||
if(x != x) {
|
||||
return undefined;
|
||||
}
|
||||
return x;
|
||||
};
|
||||
HxOverrides.substr = function(s,pos,len) {
|
||||
if(len == null) {
|
||||
len = s.length;
|
||||
} else if(len < 0) {
|
||||
if(pos == 0) {
|
||||
len = s.length + len;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return s.substr(pos,len);
|
||||
};
|
||||
HxOverrides.now = function() {
|
||||
return Date.now();
|
||||
};
|
||||
Math.__name__ = true;
|
||||
var Reflect = function() { };
|
||||
Reflect.__name__ = true;
|
||||
Reflect.field = function(o,field) {
|
||||
try {
|
||||
return o[field];
|
||||
} catch( _g ) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reflect.fields = function(o) {
|
||||
var a = [];
|
||||
if(o != null) {
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
for( var f in o ) {
|
||||
if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) {
|
||||
a.push(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
Reflect.deleteField = function(o,field) {
|
||||
if(!Object.prototype.hasOwnProperty.call(o,field)) {
|
||||
return false;
|
||||
}
|
||||
delete(o[field]);
|
||||
return true;
|
||||
};
|
||||
var Std = function() { };
|
||||
Std.__name__ = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
var StringTools = function() { };
|
||||
StringTools.__name__ = true;
|
||||
StringTools.isSpace = function(s,pos) {
|
||||
var c = HxOverrides.cca(s,pos);
|
||||
if(!(c > 8 && c < 14)) {
|
||||
return c == 32;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
StringTools.ltrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,r)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,r,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.rtrim = function(s) {
|
||||
var l = s.length;
|
||||
var r = 0;
|
||||
while(r < l && StringTools.isSpace(s,l - r - 1)) ++r;
|
||||
if(r > 0) {
|
||||
return HxOverrides.substr(s,0,l - r);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
StringTools.trim = function(s) {
|
||||
return StringTools.ltrim(StringTools.rtrim(s));
|
||||
};
|
||||
StringTools.replace = function(s,sub,by) {
|
||||
return s.split(sub).join(by);
|
||||
};
|
||||
var haxe_iterators_ArrayIterator = function(array) {
|
||||
this.current = 0;
|
||||
this.array = array;
|
||||
};
|
||||
haxe_iterators_ArrayIterator.__name__ = true;
|
||||
haxe_iterators_ArrayIterator.prototype = {
|
||||
hasNext: function() {
|
||||
return this.current < this.array.length;
|
||||
}
|
||||
,next: function() {
|
||||
return this.array[this.current++];
|
||||
}
|
||||
};
|
||||
var js_Boot = function() { };
|
||||
js_Boot.__name__ = true;
|
||||
js_Boot.__string_rec = function(o,s) {
|
||||
if(o == null) {
|
||||
return "null";
|
||||
}
|
||||
if(s.length >= 5) {
|
||||
return "<...>";
|
||||
}
|
||||
var t = typeof(o);
|
||||
if(t == "function" && (o.__name__ || o.__ename__)) {
|
||||
t = "object";
|
||||
}
|
||||
switch(t) {
|
||||
case "function":
|
||||
return "<function>";
|
||||
case "object":
|
||||
if(((o) instanceof Array)) {
|
||||
var str = "[";
|
||||
s += "\t";
|
||||
var _g = 0;
|
||||
var _g1 = o.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s);
|
||||
}
|
||||
str += "]";
|
||||
return str;
|
||||
}
|
||||
var tostr;
|
||||
try {
|
||||
tostr = o.toString;
|
||||
} catch( _g ) {
|
||||
return "???";
|
||||
}
|
||||
if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") {
|
||||
var s2 = o.toString();
|
||||
if(s2 != "[object Object]") {
|
||||
return s2;
|
||||
}
|
||||
}
|
||||
var str = "{\n";
|
||||
s += "\t";
|
||||
var hasp = o.hasOwnProperty != null;
|
||||
var k = null;
|
||||
for( k in o ) {
|
||||
if(hasp && !o.hasOwnProperty(k)) {
|
||||
continue;
|
||||
}
|
||||
if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") {
|
||||
continue;
|
||||
}
|
||||
if(str.length != 2) {
|
||||
str += ", \n";
|
||||
}
|
||||
str += s + k + " : " + js_Boot.__string_rec(o[k],s);
|
||||
}
|
||||
s = s.substring(1);
|
||||
str += "\n" + s + "}";
|
||||
return str;
|
||||
case "string":
|
||||
return o;
|
||||
default:
|
||||
return String(o);
|
||||
}
|
||||
};
|
||||
var xrfragment_Parser = $hx_exports["xrfragment"]["Parser"] = function() { };
|
||||
xrfragment_Parser.__name__ = true;
|
||||
xrfragment_Parser.parse = function(key,value,resultMap) {
|
||||
var Frag_h = Object.create(null);
|
||||
Frag_h["prio"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_INT;
|
||||
Frag_h["#"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
Frag_h["class"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["src"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL;
|
||||
Frag_h["pos"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.T_STRING_OBJ | xrfragment_XRF.EMBEDDED | xrfragment_XRF.NAVIGATOR;
|
||||
Frag_h["href"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.T_PREDEFINED_VIEW;
|
||||
Frag_h["q"] = xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["scale"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["rot"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED | xrfragment_XRF.NAVIGATOR;
|
||||
Frag_h["translate"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["visible"] = xrfragment_XRF.QUERY_OPERATOR | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_INT | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["env"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["t"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.ROUNDROBIN | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["gravity"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["physics"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR3 | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["fov"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_INT | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["clip"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_VECTOR2 | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["fog"] = xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED;
|
||||
Frag_h["namespace"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["SPDX"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["unit"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["description"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_STRING;
|
||||
Frag_h["session"] = xrfragment_XRF.ASSET | xrfragment_XRF.T_URL | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.NAVIGATOR | xrfragment_XRF.EMBEDDED | xrfragment_XRF.PROMPT;
|
||||
if(value.length == 0 && !Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.PV_EXECUTE | xrfragment_XRF.NAVIGATOR);
|
||||
return true;
|
||||
}
|
||||
if(key.split(".").length > 1 && value.split(".").length > 1) {
|
||||
resultMap[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND);
|
||||
return true;
|
||||
}
|
||||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) {
|
||||
this.isNumber = new EReg("^[0-9\\.]+$","");
|
||||
this.isClass = new EReg("^[-]?class$","");
|
||||
this.isAddition = new EReg("^\\+","");
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
this.str = "";
|
||||
if(str != null) {
|
||||
this.parse(str);
|
||||
}
|
||||
};
|
||||
xrfragment_Query.__name__ = true;
|
||||
xrfragment_Query.prototype = {
|
||||
toObject: function() {
|
||||
return this.q;
|
||||
}
|
||||
,expandAliases: function(token) {
|
||||
var classAlias = new EReg("^(-)?\\.","");
|
||||
if(classAlias.match(token)) {
|
||||
return StringTools.replace(token,".","class:");
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
,get: function() {
|
||||
return this.q;
|
||||
}
|
||||
,parse: function(str,recurse) {
|
||||
if(recurse == null) {
|
||||
recurse = false;
|
||||
}
|
||||
var _gthis = this;
|
||||
var token = str.split(" ");
|
||||
var q = { };
|
||||
var process = function(str,prefix) {
|
||||
if(prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
str = StringTools.trim(str);
|
||||
var k = str.split(":")[0];
|
||||
var v = str.split(":")[1];
|
||||
var filter = { };
|
||||
if(q[prefix + k]) {
|
||||
filter = q[prefix + k];
|
||||
}
|
||||
filter["rules"] = filter["rules"] != null ? filter["rules"] : [];
|
||||
if(_gthis.isProp.match(str)) {
|
||||
var oper = "";
|
||||
if(str.indexOf("*") != -1) {
|
||||
oper = "*";
|
||||
}
|
||||
if(str.indexOf(">") != -1) {
|
||||
oper = ">";
|
||||
}
|
||||
if(str.indexOf("<") != -1) {
|
||||
oper = "<";
|
||||
}
|
||||
if(str.indexOf(">=") != -1) {
|
||||
oper = ">=";
|
||||
}
|
||||
if(str.indexOf("<=") != -1) {
|
||||
oper = "<=";
|
||||
}
|
||||
if(_gthis.isExclude.match(k)) {
|
||||
oper = "!=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else if(_gthis.isAddition.match(k)) {
|
||||
oper = "+=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else {
|
||||
v = HxOverrides.substr(v,oper.length,null);
|
||||
}
|
||||
if(oper.length == 0) {
|
||||
oper = "=";
|
||||
}
|
||||
if(_gthis.isClass.match(k)) {
|
||||
filter[prefix + k] = oper != "!=";
|
||||
q[v] = filter;
|
||||
} else {
|
||||
var rule = { };
|
||||
if(_gthis.isNumber.match(v)) {
|
||||
rule[oper] = parseFloat(v);
|
||||
} else {
|
||||
rule[oper] = v;
|
||||
}
|
||||
filter["rules"].push(rule);
|
||||
q[k] = filter;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
filter["id"] = _gthis.isExclude.match(str) ? false : true;
|
||||
var key = _gthis.isExclude.match(str) ? HxOverrides.substr(str,1,null) : str;
|
||||
q[key] = filter;
|
||||
}
|
||||
};
|
||||
var _g = 0;
|
||||
var _g1 = token.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
process(this.expandAliases(token[i]));
|
||||
}
|
||||
return this.q = q;
|
||||
}
|
||||
,test: function(obj) {
|
||||
var qualify = false;
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(obj);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var v = Std.string(Reflect.field(obj,k));
|
||||
if(this.testProperty(k,v)) {
|
||||
qualify = true;
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(obj);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var v = Std.string(Reflect.field(obj,k));
|
||||
if(this.testProperty(k,v,true)) {
|
||||
qualify = false;
|
||||
}
|
||||
}
|
||||
return qualify;
|
||||
}
|
||||
,testProperty: function(property,value,exclude) {
|
||||
var conds = 0;
|
||||
var fails = 0;
|
||||
var qualify = 0;
|
||||
var testprop = function(expr) {
|
||||
conds += 1;
|
||||
fails += expr ? 0 : 1;
|
||||
return expr;
|
||||
};
|
||||
if(this.q[value] != null) {
|
||||
var v = this.q[value];
|
||||
if(v[property] != null) {
|
||||
return v[property];
|
||||
}
|
||||
}
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(this.q);
|
||||
while(_g < _g1.length) {
|
||||
var k = _g1[_g];
|
||||
++_g;
|
||||
var filter = Reflect.field(this.q,k);
|
||||
if(filter.rules == null) {
|
||||
continue;
|
||||
}
|
||||
var rules = filter.rules;
|
||||
var _g2 = 0;
|
||||
while(_g2 < rules.length) {
|
||||
var rule = rules[_g2];
|
||||
++_g2;
|
||||
if(exclude) {
|
||||
if(Reflect.field(rule,"!=") != null && testprop((value == null ? "null" : "" + value) == Std.string(Reflect.field(rule,"!="))) && exclude) {
|
||||
++qualify;
|
||||
}
|
||||
} else {
|
||||
if(Reflect.field(rule,"*") != null && testprop(parseFloat(value) != null)) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,">") != null && testprop(parseFloat(value) > parseFloat(Reflect.field(rule,">")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"<") != null && testprop(parseFloat(value) < parseFloat(Reflect.field(rule,"<")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,">=") != null && testprop(parseFloat(value) >= parseFloat(Reflect.field(rule,">=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"<=") != null && testprop(parseFloat(value) <= parseFloat(Reflect.field(rule,"<=")))) {
|
||||
++qualify;
|
||||
}
|
||||
if(Reflect.field(rule,"=") != null && (testprop(value == Reflect.field(rule,"=")) || testprop(parseFloat(value) == parseFloat(Reflect.field(rule,"="))))) {
|
||||
++qualify;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return qualify > 0;
|
||||
}
|
||||
};
|
||||
var xrfragment_URI = $hx_exports["xrfragment"]["URI"] = function() { };
|
||||
xrfragment_URI.__name__ = true;
|
||||
xrfragment_URI.parse = function(url,filter) {
|
||||
var store = { };
|
||||
if(url.indexOf("#") == -1) {
|
||||
return store;
|
||||
}
|
||||
var fragment = url.split("#");
|
||||
var splitArray = fragment[1].split("&");
|
||||
var _g = 0;
|
||||
var _g1 = splitArray.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var splitByEqual = splitArray[i].split("=");
|
||||
var regexPlus = new EReg("\\+","g");
|
||||
var key = splitByEqual[0];
|
||||
var value = "";
|
||||
if(splitByEqual.length > 1) {
|
||||
var s = regexPlus.split(splitByEqual[1]).join(" ");
|
||||
value = decodeURIComponent(s.split("+").join(" "));
|
||||
}
|
||||
var ok = xrfragment_Parser.parse(key,value,store);
|
||||
}
|
||||
if(filter != null && filter != 0) {
|
||||
var _g = 0;
|
||||
var _g1 = Reflect.fields(store);
|
||||
while(_g < _g1.length) {
|
||||
var key = _g1[_g];
|
||||
++_g;
|
||||
var xrf = store[key];
|
||||
if(!xrf.is(filter)) {
|
||||
Reflect.deleteField(store,key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return store;
|
||||
};
|
||||
var xrfragment_XRF = $hx_exports["xrfragment"]["XRF"] = function(_fragment,_flags) {
|
||||
this.fragment = _fragment;
|
||||
this.flags = _flags;
|
||||
};
|
||||
xrfragment_XRF.__name__ = true;
|
||||
xrfragment_XRF.set = function(flag,flags) {
|
||||
return flags | flag;
|
||||
};
|
||||
xrfragment_XRF.unset = function(flag,flags) {
|
||||
return flags & ~flag;
|
||||
};
|
||||
xrfragment_XRF.prototype = {
|
||||
is: function(flag) {
|
||||
return (this.flags & flag) != 0;
|
||||
}
|
||||
,validate: function(value) {
|
||||
this.guessType(this,value);
|
||||
if(value.split("|").length > 1) {
|
||||
this.args = [];
|
||||
var args = value.split("|");
|
||||
var _g = 0;
|
||||
var _g1 = args.length;
|
||||
while(_g < _g1) {
|
||||
var i = _g++;
|
||||
var x = new xrfragment_XRF(this.fragment,this.flags);
|
||||
this.guessType(x,args[i]);
|
||||
this.args.push(x);
|
||||
}
|
||||
}
|
||||
if(this.fragment == "q") {
|
||||
this.query = new xrfragment_Query(value).get();
|
||||
}
|
||||
var ok = true;
|
||||
if(!((this.args) instanceof Array)) {
|
||||
if(this.is(xrfragment_XRF.T_VECTOR3) && !(typeof(this.x) == "number" && typeof(this.y) == "number" && typeof(this.z) == "number")) {
|
||||
ok = false;
|
||||
}
|
||||
if(this.is(xrfragment_XRF.T_VECTOR2) && !(typeof(this.x) == "number" && typeof(this.y) == "number")) {
|
||||
ok = false;
|
||||
}
|
||||
var tmp;
|
||||
if(this.is(xrfragment_XRF.T_INT)) {
|
||||
var v = this.int;
|
||||
tmp = !(typeof(v) == "number" && ((v | 0) === v));
|
||||
} else {
|
||||
tmp = false;
|
||||
}
|
||||
if(tmp) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
,guessType: function(v,str) {
|
||||
v.string = str;
|
||||
if(str.split(",").length > 1) {
|
||||
var xyz = str.split(",");
|
||||
if(xyz.length > 0) {
|
||||
v.x = parseFloat(xyz[0]);
|
||||
}
|
||||
if(xyz.length > 1) {
|
||||
v.y = parseFloat(xyz[1]);
|
||||
}
|
||||
if(xyz.length > 2) {
|
||||
v.z = parseFloat(xyz[2]);
|
||||
}
|
||||
}
|
||||
if(xrfragment_XRF.isColor.match(str)) {
|
||||
v.color = str;
|
||||
}
|
||||
if(xrfragment_XRF.isFloat.match(str)) {
|
||||
v.float = parseFloat(str);
|
||||
}
|
||||
if(xrfragment_XRF.isInt.match(str)) {
|
||||
v.int = Std.parseInt(str);
|
||||
}
|
||||
}
|
||||
};
|
||||
if(typeof(performance) != "undefined" ? typeof(performance.now) == "function" : false) {
|
||||
HxOverrides.now = performance.now.bind(performance);
|
||||
}
|
||||
String.__name__ = true;
|
||||
Array.__name__ = true;
|
||||
js_Boot.__toStr = ({ }).toString;
|
||||
xrfragment_Parser.error = "";
|
||||
xrfragment_Parser.debug = false;
|
||||
xrfragment_XRF.ASSET = 1;
|
||||
xrfragment_XRF.PROP_BIND = 2;
|
||||
xrfragment_XRF.QUERY_OPERATOR = 4;
|
||||
xrfragment_XRF.PROMPT = 8;
|
||||
xrfragment_XRF.ROUNDROBIN = 16;
|
||||
xrfragment_XRF.NAVIGATOR = 32;
|
||||
xrfragment_XRF.EMBEDDED = 64;
|
||||
xrfragment_XRF.PV_OVERRIDE = 128;
|
||||
xrfragment_XRF.PV_EXECUTE = 256;
|
||||
xrfragment_XRF.T_COLOR = 8192;
|
||||
xrfragment_XRF.T_INT = 16384;
|
||||
xrfragment_XRF.T_FLOAT = 32768;
|
||||
xrfragment_XRF.T_VECTOR2 = 65536;
|
||||
xrfragment_XRF.T_VECTOR3 = 131072;
|
||||
xrfragment_XRF.T_URL = 262144;
|
||||
xrfragment_XRF.T_PREDEFINED_VIEW = 524288;
|
||||
xrfragment_XRF.T_STRING = 1048576;
|
||||
xrfragment_XRF.T_STRING_OBJ = 2097152;
|
||||
xrfragment_XRF.T_STRING_OBJ_PROP = 4194304;
|
||||
xrfragment_XRF.isColor = new EReg("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$","");
|
||||
xrfragment_XRF.isInt = new EReg("^[0-9]+$","");
|
||||
xrfragment_XRF.isFloat = new EReg("^[0-9]+\\.[0-9]+$","");
|
||||
xrfragment_XRF.isVector = new EReg("([,]+|\\w)","");
|
||||
xrfragment_XRF.isUrl = new EReg("(://)?\\..*","");
|
||||
xrfragment_XRF.isUrlOrPretypedView = new EReg("(^#|://)?\\..*","");
|
||||
xrfragment_XRF.isString = new EReg(".*","");
|
||||
})({});
|
||||
var xrfragment = $hx_exports["xrfragment"];
|
||||
export default xrfragment;
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,3 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) 2023 Leon van Kammen/NLNET
|
||||
|
||||
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"] || {};
|
||||
|
@ -253,11 +250,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:75:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:78:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
@ -266,6 +263,7 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) {
|
||||
this.isNumber = new EReg("^[0-9\\.]+$","");
|
||||
this.isClass = new EReg("^[-]?class$","");
|
||||
this.isAddition = new EReg("^\\+","");
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
|
@ -329,6 +327,9 @@ xrfragment_Query.prototype = {
|
|||
if(_gthis.isExclude.match(k)) {
|
||||
oper = "!=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else if(_gthis.isAddition.match(k)) {
|
||||
oper = "+=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else {
|
||||
v = HxOverrides.substr(v,oper.length,null);
|
||||
}
|
||||
|
@ -596,9 +597,80 @@ xrfragment_XRF.isUrlOrPretypedView = new EReg("(^#|://)?\\..*","");
|
|||
xrfragment_XRF.isString = new EReg(".*","");
|
||||
})({});
|
||||
var xrfragment = $hx_exports["xrfragment"];
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) 2023 Leon van Kammen/NLNET
|
||||
|
||||
var xrf = {}
|
||||
|
||||
xrf.init = function(opts){
|
||||
opts = opts || {}
|
||||
xrf.Parser.debug = xrf.debug
|
||||
for ( let i in opts ) xrf[i] = opts[i]
|
||||
xrf.emit('init',opts)
|
||||
return xrf.query
|
||||
}
|
||||
|
||||
xrf.query = function(){
|
||||
// framework implementations can override this function, see src/3rd/js/three/index.sj
|
||||
alert("queries are not implemented (yet) for this particular framework")
|
||||
}
|
||||
|
||||
// map library functions to xrf
|
||||
for ( let i in xrfragment ) xrf[i] = xrfragment[i]
|
||||
/*
|
||||
* (promise-able) EVENTS
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* xrf.addEventListener('foo',(e) => {
|
||||
* // let promise = e.promise()
|
||||
* console.log("navigating to: "+e.detail.destination.url)
|
||||
* // promise.resolve()
|
||||
* // promise.reject("not going to happen")
|
||||
* })
|
||||
*
|
||||
* xrf.emit('foo',123)
|
||||
* xrf.emit('foo',123).then(...).catch(...).finally(...)
|
||||
*/
|
||||
|
||||
xrf.addEventListener = function(eventName, callback) {
|
||||
if( !this._listeners ) this._listeners = []
|
||||
if (!this._listeners[eventName]) {
|
||||
// create a new array for this event name if it doesn't exist yet
|
||||
this._listeners[eventName] = [];
|
||||
}
|
||||
// add the callback to the listeners array for this event name
|
||||
this._listeners[eventName].push(callback);
|
||||
};
|
||||
|
||||
xrf.emit = function(eventName, data){
|
||||
return xrf.emit.promise(eventName,data)
|
||||
}
|
||||
|
||||
xrf.emit.normal = function(eventName, data) {
|
||||
if( !xrf._listeners ) xrf._listeners = []
|
||||
var callbacks = xrf._listeners[eventName]
|
||||
if (callbacks) {
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
callbacks[i](data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xrf.emit.promise = function(e, opts){
|
||||
opts.XRF = xrf // always pass root XRF obj
|
||||
return new Promise( (resolve, reject) => {
|
||||
opts.promise = () => {
|
||||
opts.promise.halted = true
|
||||
return { resolve, reject }
|
||||
}
|
||||
xrf.emit.normal(e, opts)
|
||||
if( !opts.promise.halted ) resolve()
|
||||
})
|
||||
}
|
||||
// wrapper to survive in/outside modules
|
||||
|
||||
xrfragment.InteractiveGroup = function(THREE,renderer,camera){
|
||||
xrf.InteractiveGroup = function(THREE,renderer,camera){
|
||||
|
||||
let {
|
||||
Group,
|
||||
|
@ -732,24 +804,19 @@ xrfragment.InteractiveGroup = function(THREE,renderer,camera){
|
|||
|
||||
return new InteractiveGroup(renderer,camera)
|
||||
}
|
||||
let xrf = xrfragment
|
||||
xrf.frag = {}
|
||||
xrf.model = {}
|
||||
|
||||
xrf.init = function(opts){
|
||||
opts = opts || {}
|
||||
let XRF = function(){
|
||||
alert("queries are not implemented (yet)")
|
||||
}
|
||||
for ( let i in opts ) xrf[i] = opts[i]
|
||||
for ( let i in xrf.XRF ) xrf.XRF[i] // shortcuts to constants (NAVIGATOR e.g.)
|
||||
xrf.Parser.debug = xrf.debug
|
||||
xrf.init = ((init) => function(opts){
|
||||
init(opts)
|
||||
if( opts.loaders ) Object.values(opts.loaders).map( xrf.patchLoader )
|
||||
|
||||
xrf.patchRenderer(opts.renderer)
|
||||
xrf.navigator.init()
|
||||
return xrf
|
||||
}
|
||||
// return xrfragment lib as 'xrf' query functor (like jquery)
|
||||
for ( let i in xrf ) xrf.query[i] = xrf[i]
|
||||
return xrf.query
|
||||
})(xrf.init)
|
||||
|
||||
xrf.patchRenderer = function(renderer){
|
||||
renderer.xr.addEventListener( 'sessionstart', () => xrf.baseReferenceSpace = renderer.xr.getReferenceSpace() );
|
||||
|
@ -765,7 +832,10 @@ xrf.patchLoader = function(loader){
|
|||
loader.prototype.load = ((load) => function(url, onLoad, onProgress, onError){
|
||||
load.call( this,
|
||||
url,
|
||||
(model) => { onLoad(model); xrf.parseModel(model,url) },
|
||||
(model) => {
|
||||
onLoad(model);
|
||||
xrf.parseModel(model,url)
|
||||
},
|
||||
onProgress,
|
||||
onError)
|
||||
})(loader.prototype.load)
|
||||
|
@ -776,9 +846,16 @@ xrf.getFile = (url) => url.split("/").pop().replace(/#.*/,'')
|
|||
xrf.parseModel = function(model,url){
|
||||
let file = xrf.getFile(url)
|
||||
model.file = file
|
||||
model.render = function(){}
|
||||
// eval embedded XR fragments
|
||||
model.scene.traverse( (mesh) => xrf.eval.mesh(mesh,model) )
|
||||
// add animations
|
||||
model.clock = new THREE.Clock();
|
||||
model.mixer = new THREE.AnimationMixer(model.scene)
|
||||
console.dir(model)
|
||||
model.animations.map( (anim) => model.mixer.clipAction( anim ).play() )
|
||||
model.render = function(){
|
||||
model.mixer.update( model.clock.getDelta() )
|
||||
}
|
||||
}
|
||||
|
||||
xrf.getLastModel = () => xrf.model.last
|
||||
|
@ -793,12 +870,10 @@ xrf.eval = function( url, model ){
|
|||
for ( let i in meshes ) {
|
||||
for ( let k in frag ){
|
||||
let mesh = meshes[i]
|
||||
if( !String(k).match(/(pos|rot)/) ) notice = true
|
||||
let opts = {frag, mesh, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
||||
xrf.eval.fragment(k,opts)
|
||||
}
|
||||
}
|
||||
if( notice ) alert("only 'pos' and 'rot' XRF.NAVIGATOR-flagged XR fragments are supported (for now)")
|
||||
}
|
||||
|
||||
xrf.eval.mesh = (mesh,model) => {
|
||||
|
@ -879,7 +954,7 @@ xrf.navigator.to = (url,event) => {
|
|||
xrf.add( model.scene )
|
||||
xrf.model = model
|
||||
xrf.eval( url, model ) // and eval URI XR fragments
|
||||
xrf.navigator.pushState( file, hash )
|
||||
xrf.navigator.pushState( `${dir}${file}`, hash )
|
||||
resolve(model)
|
||||
})
|
||||
})
|
||||
|
@ -897,57 +972,6 @@ 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}` )
|
||||
}
|
||||
/*
|
||||
* (promise-able) EVENTS
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* xrf.addEventListener('foo',(e) => {
|
||||
* // let promise = e.promise()
|
||||
* console.log("navigating to: "+e.detail.destination.url)
|
||||
* // promise.resolve()
|
||||
* // promise.reject("not going to happen")
|
||||
* })
|
||||
*
|
||||
* xrf.emit('foo',123)
|
||||
* xrf.emit('foo',123).then(...).catch(...).finally(...)
|
||||
*/
|
||||
|
||||
xrf.addEventListener = function(eventName, callback) {
|
||||
if( !this._listeners ) this._listeners = []
|
||||
if (!this._listeners[eventName]) {
|
||||
// create a new array for this event name if it doesn't exist yet
|
||||
this._listeners[eventName] = [];
|
||||
}
|
||||
// add the callback to the listeners array for this event name
|
||||
this._listeners[eventName].push(callback);
|
||||
};
|
||||
|
||||
xrf.emit = function(eventName, data){
|
||||
return xrf.emit.promise(eventName,data)
|
||||
}
|
||||
|
||||
xrf.emit.normal = function(eventName, data) {
|
||||
if( !xrf._listeners ) xrf._listeners = []
|
||||
var callbacks = xrf._listeners[eventName]
|
||||
if (callbacks) {
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
callbacks[i](data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xrf.emit.promise = function(e, opts){
|
||||
opts.XRF = xrf // always pass root XRF obj
|
||||
return new Promise( (resolve, reject) => {
|
||||
opts.promise = () => {
|
||||
opts.promise.halted = true
|
||||
return { resolve, reject }
|
||||
}
|
||||
xrf.emit.normal(e, opts)
|
||||
if( !opts.promise.halted ) resolve()
|
||||
})
|
||||
}
|
||||
xrf.frag.env = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
let env = mesh.getObjectByName(v.string)
|
||||
|
@ -1021,13 +1045,6 @@ xrf.frag.href = function(v, opts){
|
|||
scale: new THREE.Vector3(),
|
||||
quat: new THREE.Quaternion()
|
||||
}
|
||||
mesh.getWorldPosition(world.pos)
|
||||
mesh.getWorldScale(world.scale)
|
||||
mesh.getWorldQuaternion(world.quat);
|
||||
mesh.position.copy(world.pos)
|
||||
mesh.scale.copy(world.scale)
|
||||
mesh.setRotationFromQuaternion(world.quat);
|
||||
|
||||
// detect equirectangular image
|
||||
let texture = mesh.material.map
|
||||
if( texture && texture.source.data.height == texture.source.data.width/2 ){
|
||||
|
@ -1076,12 +1093,41 @@ xrf.frag.href = function(v, opts){
|
|||
`,
|
||||
});
|
||||
mesh.material.needsUpdate = true
|
||||
}
|
||||
}else mesh.material = mesh.material.clone()
|
||||
|
||||
let teleport = mesh.userData.XRF.href.exec = (e) => {
|
||||
xrf
|
||||
.emit('href',{click:true,mesh,xrf:v}) // let all listeners agree
|
||||
.then( () => xrf.navigator.to(v.string) ) // ok let's surf to HREF!
|
||||
let click = mesh.userData.XRF.href.exec = (e) => {
|
||||
if( v.string[0] == '#' ){
|
||||
let frag = xrf.URI.parse(v.string)
|
||||
if( frag.q ){ // show/hider
|
||||
let q = frag.q.query
|
||||
scene.traverse( (mesh) => {
|
||||
for ( let i in q ) {
|
||||
if( i == mesh.name && q[i].id != undefined ) mesh.visible = q[i].id
|
||||
if( i == mesh.userData.class && q[i].class != undefined ) mesh.visible = q[i].class
|
||||
}
|
||||
})
|
||||
}else if( !v.string.match(/=/) ){ // projection or Selection of Interest (SoI)
|
||||
let id = v.string.substr(1)
|
||||
scene.traverse( (mesh) => {
|
||||
if( mesh.selection ){
|
||||
mesh.remove(mesh.selection)
|
||||
delete mesh.selection
|
||||
}
|
||||
if( id == mesh.name || id == mesh.userData.class ){
|
||||
console.log("applying selection")
|
||||
mesh.selection = new THREE.BoxHelper(mesh,0xff00ff)
|
||||
mesh.selection.scale.set(2,2,2)
|
||||
mesh.selection.position.copy( mesh.position )
|
||||
scene.add(mesh.selection)
|
||||
}
|
||||
})
|
||||
|
||||
}else{ // teleport
|
||||
xrf
|
||||
.emit('href',{click:true,mesh,xrf:v}) // let all listeners agree
|
||||
.then( () => xrf.navigator.to(v.string) ) // ok let's surf to HREF!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let selected = (state) => () => {
|
||||
|
@ -1097,14 +1143,18 @@ xrf.frag.href = function(v, opts){
|
|||
.then( () => mesh.selected = state )
|
||||
}
|
||||
|
||||
if( !opts.frag.q ){ // query means an action
|
||||
mesh.addEventListener('click', teleport )
|
||||
mesh.addEventListener('mousemove', selected(true) )
|
||||
mesh.addEventListener('nocollide', selected(false) )
|
||||
}
|
||||
mesh.addEventListener('click', click )
|
||||
mesh.addEventListener('mousemove', selected(true) )
|
||||
mesh.addEventListener('nocollide', selected(false) )
|
||||
|
||||
// lazy add mesh (because we're inside a recursive traverse)
|
||||
setTimeout( (mesh) => {
|
||||
mesh.getWorldPosition(world.pos)
|
||||
mesh.getWorldScale(world.scale)
|
||||
mesh.getWorldQuaternion(world.quat);
|
||||
mesh.position.copy(world.pos)
|
||||
mesh.scale.copy(world.scale)
|
||||
mesh.setRotationFromQuaternion(world.quat);
|
||||
xrf.interactive.add(mesh)
|
||||
}, 20, mesh )
|
||||
}
|
||||
|
@ -1170,16 +1220,35 @@ xrf.frag.pos = function(v, opts){
|
|||
xrf.frag.q = function(v, opts){
|
||||
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
||||
console.log(" └ running query ")
|
||||
let qobjs = Object.keys(v.query)
|
||||
|
||||
v.scene = new THREE.Group()
|
||||
for ( let i in v.query ) {
|
||||
let target = v.query[i]
|
||||
|
||||
// remove objects if requested
|
||||
if( target.id != undefined && (target.mesh = scene.getObjectByName(i)) ){
|
||||
target.mesh.visible = target.id
|
||||
target.mesh.parent.remove(target.mesh)
|
||||
console.log(` └ removing mesh: ${i}`)
|
||||
}else console.log(` └ mesh not found: ${i}`)
|
||||
if( !scene.getObjectByName(i) && i != '*' ) return console.log(` └ mesh not found: ${i}`)
|
||||
if( i == '*' ){
|
||||
let cloneScene = scene.clone()
|
||||
cloneScene.children.forEach( (child) => v.scene.getObjectByName(child.name) ? null : v.scene.add(child) )
|
||||
target.mesh = v.scene
|
||||
}else{
|
||||
console.log(` └ query-ing mesh: ${i}`)
|
||||
if( !v.scene.getObjectByName(i) && target.id === true ){
|
||||
v.scene.add( target.mesh = scene.getObjectByName(i).clone() )
|
||||
}
|
||||
}
|
||||
if( target.id != undefined && target.mesh ){
|
||||
target.mesh.position.set(0,0,0)
|
||||
target.mesh.rotation.set(0,0,0)
|
||||
}
|
||||
}
|
||||
// remove negative selectors
|
||||
let remove = []
|
||||
v.scene.traverse( (mesh) => {
|
||||
for ( let i in v.query ) {
|
||||
if( mesh.name == i && v.query[i].id === false ) remove.push(mesh)
|
||||
}
|
||||
})
|
||||
remove.map( (mesh) => mesh.parent.remove( mesh ) )
|
||||
}
|
||||
xrf.frag.rot = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
@ -1195,38 +1264,38 @@ xrf.frag.rot = function(v, opts){
|
|||
|
||||
xrf.frag.src = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
let src = new THREE.Group()
|
||||
|
||||
if( v.string[0] == "#" ){ // local
|
||||
console.log(" └ instancing src")
|
||||
let frag = xrfragment.URI.parse(v.string)
|
||||
// Get an instance of the original model
|
||||
let sceneInstance = new THREE.Group()
|
||||
sceneInstance.isSrc = true
|
||||
|
||||
// prevent infinite recursion #1: skip src-instanced models
|
||||
for ( let i in model.scene.children ) {
|
||||
let child = model.scene.children[i]
|
||||
if( child.isSrc ) continue;
|
||||
sceneInstance.add( model.scene.children[i].clone() )
|
||||
}
|
||||
|
||||
sceneInstance.position.copy( mesh.position )
|
||||
sceneInstance.scale.copy(mesh.scale)
|
||||
sceneInstance.updateMatrixWorld(true) // needed because we're going to move portals to the interactive-group
|
||||
|
||||
// apply embedded XR fragments
|
||||
setTimeout( () => {
|
||||
sceneInstance.traverse( (m) => {
|
||||
if( m.userData && m.userData.src ) return ;//delete m.userData.src // prevent infinite recursion
|
||||
xrf.eval.mesh(m,{scene,recursive:true})
|
||||
})
|
||||
// Add the instance to the scene
|
||||
//model.scene.add(clone);
|
||||
// apply URI XR Fragments inside src-value
|
||||
for( var i in frag ){
|
||||
xrf.eval.fragment(i, Object.assign(opts,{frag, model:{scene:sceneInstance},scene:sceneInstance}))
|
||||
xrf.eval.fragment(i, Object.assign(opts,{frag, model,scene}))
|
||||
}
|
||||
// Add the instance to the scene
|
||||
model.scene.add(sceneInstance);
|
||||
if( frag.q.query ){
|
||||
let srcScene = frag.q.scene
|
||||
if( !srcScene || !srcScene.visible ) return
|
||||
console.log(" └ inserting "+i+" (srcScene)")
|
||||
srcScene.position.set(0,0,0)
|
||||
srcScene.rotation.set(0,0,0)
|
||||
srcScene.traverse( (m) => {
|
||||
if( m.userData && (m.userData.src || m.userData.href) ) return ;//delete m.userData.src // prevent infinite recursion
|
||||
xrf.eval.mesh(m,{scene,recursive:true})
|
||||
})
|
||||
if( srcScene.visible ) src.add( srcScene )
|
||||
}
|
||||
src.position.copy( mesh.position )
|
||||
src.rotation.copy( mesh.rotation )
|
||||
src.scale.copy( mesh.scale )
|
||||
mesh.add(src)
|
||||
console.dir(opts)
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations
|
||||
},10)
|
||||
}
|
||||
}
|
||||
export default xrfragment;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -17,7 +17,7 @@
|
|||
<a class="btn-foot" id="model" target="_blank" href="">⬇️ model</a>
|
||||
<textarea style="display:none"></textarea>
|
||||
|
||||
<script async src="./../../assets/alpine.min.js"></script>
|
||||
<script async src="./../../assets/js/alpine.min.js"></script>
|
||||
<!-- Import maps polyfill -->
|
||||
<!-- Remove this when import maps will be widely supported -->
|
||||
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
|
||||
|
@ -33,7 +33,7 @@
|
|||
<script type="module">
|
||||
import * as THREE from 'three';
|
||||
|
||||
import xrfragment from './../../../dist/xrfragment.three.js';
|
||||
import xrfragment from './../../../dist/xrfragment.three.module.js';
|
||||
|
||||
import { loadFile, setupConsole, setupUrlBar, notify } from './../../assets/js/utils.js';
|
||||
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
|
||||
|
|
24
make
24
make
|
@ -45,25 +45,25 @@ build(){
|
|||
haxe build.hxml
|
||||
ok=$?
|
||||
sed -i 's|.*nonlocal .*||g' dist/xrfragment.py
|
||||
echo build OK
|
||||
build_js
|
||||
}
|
||||
|
||||
build_js(){
|
||||
# add js module
|
||||
cat dist/license.js dist/xrfragment.js > dist/xrfragment.module.js
|
||||
echo "export default xrfragment;" >> dist/xrfragment.module.js
|
||||
cat dist/xrfragment.js > dist/xrfragment.module.js
|
||||
echo "export default xrfragment;" >> dist/xrfragment.module.js
|
||||
# add THREE
|
||||
cat dist/xrfragment.js \
|
||||
src/3rd/js/*.js \
|
||||
src/3rd/js/three/*.js \
|
||||
src/3rd/js/three/xrf/*.js > dist/xrfragment.three.js
|
||||
# add THREE module
|
||||
cat dist/license.js \
|
||||
dist/xrfragment.js \
|
||||
src/3rd/three/*.js \
|
||||
src/3rd/three/xrf/*.js > dist/xrfragment.three.js
|
||||
echo "export default xrfragment;" >> dist/xrfragment.three.js
|
||||
cat dist/xrfragment.three.js > dist/xrfragment.three.module.js
|
||||
echo "export default xrfragment;" >> dist/xrfragment.three.module.js
|
||||
# add AFRAME
|
||||
cat dist/license.js \
|
||||
dist/xrfragment.js \
|
||||
src/3rd/three/*.js \
|
||||
src/3rd/three/xrf/*.js \
|
||||
src/3rd/aframe/*.js > dist/xrfragment.aframe.js
|
||||
cat dist/xrfragment.three.js \
|
||||
src/3rd/js/aframe/*.js > dist/xrfragment.aframe.js
|
||||
ls -la dist | grep js
|
||||
exit $ok
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ window.AFRAME.registerComponent('xrf', {
|
|||
|
||||
// enable XR fragments
|
||||
let aScene = document.querySelector('a-scene')
|
||||
let XRF = AFRAME.XRF = xrfragment.init({
|
||||
let XRF = AFRAME.XRF = xrf.init({
|
||||
THREE,
|
||||
camera: aScene.camera,
|
||||
scene: aScene.object3D,
|
||||
|
@ -35,20 +35,23 @@ window.AFRAME.registerComponent('xrf', {
|
|||
xrf(v,opts)
|
||||
}
|
||||
|
||||
XRF.pos = camOverride
|
||||
xrf.pos = camOverride
|
||||
|
||||
// in order to set the rotation programmatically
|
||||
// we need to disable look-controls
|
||||
XRF.rot = (xrf,v,opts) => {
|
||||
xrf.rot = (xrf,v,opts) => {
|
||||
let {renderer} = opts;
|
||||
let look = document.querySelector('[look-controls]')
|
||||
if( look ) look.removeAttribute("look-controls")
|
||||
camOverride(xrf,v,opts)
|
||||
// *TODO* make look-controls compatible, because simply
|
||||
// adding the look-controls will revert to the old rotation (cached somehow?)
|
||||
//setTimeout( () => look.setAttribute("look-controls",""), 100 )
|
||||
}
|
||||
|
||||
// convert portal to a-entity so AFRAME
|
||||
// raycaster can find & execute it
|
||||
XRF.href = (xrf,v,opts) => {
|
||||
xrf.href = (xrf,v,opts) => {
|
||||
camOverride(xrf,v,opts)
|
||||
let {mesh,camera} = opts;
|
||||
let el = document.createElement("a-entity")
|
||||
|
@ -59,7 +62,7 @@ window.AFRAME.registerComponent('xrf', {
|
|||
}
|
||||
|
||||
// cleanup xrf-get objects when resetting scene
|
||||
XRF.reset = ((reset) => () => {
|
||||
xrf.reset = ((reset) => () => {
|
||||
reset()
|
||||
console.log("aframe reset")
|
||||
let els = [...document.querySelectorAll('[xrf-get]')]
|
|
@ -17,11 +17,12 @@ window.AFRAME.registerComponent('xrf-get', {
|
|||
console.error("mesh with name '"+meshname+"' not found in model")
|
||||
return;
|
||||
}
|
||||
// convert to worldcoordinates
|
||||
mesh.getWorldPosition(mesh.position)
|
||||
mesh.getWorldScale(mesh.scale)
|
||||
mesh.getWorldQuaternion(mesh.quaternion)
|
||||
if( !this.data.clone ) mesh.parent.remove(mesh)
|
||||
////mesh.updateMatrixWorld();
|
||||
this.el.object3D.position.setFromMatrixPosition(scene.matrixWorld);
|
||||
this.el.object3D.quaternion.setFromRotationMatrix(scene.matrixWorld);
|
||||
mesh.xrf = true // mark for deletion by xrf
|
||||
mesh.isXRF = true // mark for deletion by xrf
|
||||
this.el.setObject3D('mesh', mesh );
|
||||
if( !this.el.id ) this.el.setAttribute("id",`xrf-${mesh.name}`)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) 2023 Leon van Kammen/NLNET
|
||||
|
||||
var xrf = {}
|
||||
|
||||
xrf.init = function(opts){
|
||||
opts = opts || {}
|
||||
xrf.Parser.debug = xrf.debug
|
||||
for ( let i in opts ) xrf[i] = opts[i]
|
||||
xrf.emit('init',opts)
|
||||
return xrf.query
|
||||
}
|
||||
|
||||
xrf.query = function(){
|
||||
// framework implementations can override this function, see src/3rd/js/three/index.sj
|
||||
alert("queries are not implemented (yet) for this particular framework")
|
||||
}
|
||||
|
||||
// map library functions to xrf
|
||||
for ( let i in xrfragment ) xrf[i] = xrfragment[i]
|
|
@ -1,6 +1,6 @@
|
|||
// wrapper to survive in/outside modules
|
||||
|
||||
xrfragment.InteractiveGroup = function(THREE,renderer,camera){
|
||||
xrf.InteractiveGroup = function(THREE,renderer,camera){
|
||||
|
||||
let {
|
||||
Group,
|
|
@ -1,21 +1,16 @@
|
|||
let xrf = xrfragment
|
||||
xrf.frag = {}
|
||||
xrf.model = {}
|
||||
|
||||
xrf.init = function(opts){
|
||||
opts = opts || {}
|
||||
let XRF = function(){
|
||||
alert("queries are not implemented (yet)")
|
||||
}
|
||||
for ( let i in opts ) xrf[i] = opts[i]
|
||||
for ( let i in xrf.XRF ) xrf.XRF[i] // shortcuts to constants (NAVIGATOR e.g.)
|
||||
xrf.Parser.debug = xrf.debug
|
||||
xrf.init = ((init) => function(opts){
|
||||
init(opts)
|
||||
if( opts.loaders ) Object.values(opts.loaders).map( xrf.patchLoader )
|
||||
|
||||
xrf.patchRenderer(opts.renderer)
|
||||
xrf.navigator.init()
|
||||
return xrf
|
||||
}
|
||||
// return xrfragment lib as 'xrf' query functor (like jquery)
|
||||
for ( let i in xrf ) xrf.query[i] = xrf[i]
|
||||
return xrf.query
|
||||
})(xrf.init)
|
||||
|
||||
xrf.patchRenderer = function(renderer){
|
||||
renderer.xr.addEventListener( 'sessionstart', () => xrf.baseReferenceSpace = renderer.xr.getReferenceSpace() );
|
||||
|
@ -31,7 +26,10 @@ xrf.patchLoader = function(loader){
|
|||
loader.prototype.load = ((load) => function(url, onLoad, onProgress, onError){
|
||||
load.call( this,
|
||||
url,
|
||||
(model) => { onLoad(model); xrf.parseModel(model,url) },
|
||||
(model) => {
|
||||
onLoad(model);
|
||||
xrf.parseModel(model,url)
|
||||
},
|
||||
onProgress,
|
||||
onError)
|
||||
})(loader.prototype.load)
|
||||
|
@ -42,9 +40,16 @@ xrf.getFile = (url) => url.split("/").pop().replace(/#.*/,'')
|
|||
xrf.parseModel = function(model,url){
|
||||
let file = xrf.getFile(url)
|
||||
model.file = file
|
||||
model.render = function(){}
|
||||
// eval embedded XR fragments
|
||||
model.scene.traverse( (mesh) => xrf.eval.mesh(mesh,model) )
|
||||
// add animations
|
||||
model.clock = new THREE.Clock();
|
||||
model.mixer = new THREE.AnimationMixer(model.scene)
|
||||
console.dir(model)
|
||||
model.animations.map( (anim) => model.mixer.clipAction( anim ).play() )
|
||||
model.render = function(){
|
||||
model.mixer.update( model.clock.getDelta() )
|
||||
}
|
||||
}
|
||||
|
||||
xrf.getLastModel = () => xrf.model.last
|
||||
|
@ -59,12 +64,10 @@ xrf.eval = function( url, model ){
|
|||
for ( let i in meshes ) {
|
||||
for ( let k in frag ){
|
||||
let mesh = meshes[i]
|
||||
if( !String(k).match(/(pos|rot)/) ) notice = true
|
||||
let opts = {frag, mesh, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
||||
xrf.eval.fragment(k,opts)
|
||||
}
|
||||
}
|
||||
if( notice ) alert("only 'pos' and 'rot' XRF.NAVIGATOR-flagged XR fragments are supported (for now)")
|
||||
}
|
||||
|
||||
xrf.eval.mesh = (mesh,model) => {
|
|
@ -24,7 +24,7 @@ xrf.navigator.to = (url,event) => {
|
|||
xrf.add( model.scene )
|
||||
xrf.model = model
|
||||
xrf.eval( url, model ) // and eval URI XR fragments
|
||||
xrf.navigator.pushState( file, hash )
|
||||
xrf.navigator.pushState( `${dir}${file}`, hash )
|
||||
resolve(model)
|
||||
})
|
||||
})
|
|
@ -36,13 +36,6 @@ xrf.frag.href = function(v, opts){
|
|||
scale: new THREE.Vector3(),
|
||||
quat: new THREE.Quaternion()
|
||||
}
|
||||
mesh.getWorldPosition(world.pos)
|
||||
mesh.getWorldScale(world.scale)
|
||||
mesh.getWorldQuaternion(world.quat);
|
||||
mesh.position.copy(world.pos)
|
||||
mesh.scale.copy(world.scale)
|
||||
mesh.setRotationFromQuaternion(world.quat);
|
||||
|
||||
// detect equirectangular image
|
||||
let texture = mesh.material.map
|
||||
if( texture && texture.source.data.height == texture.source.data.width/2 ){
|
||||
|
@ -91,12 +84,41 @@ xrf.frag.href = function(v, opts){
|
|||
`,
|
||||
});
|
||||
mesh.material.needsUpdate = true
|
||||
}
|
||||
}else mesh.material = mesh.material.clone()
|
||||
|
||||
let teleport = mesh.userData.XRF.href.exec = (e) => {
|
||||
xrf
|
||||
.emit('href',{click:true,mesh,xrf:v}) // let all listeners agree
|
||||
.then( () => xrf.navigator.to(v.string) ) // ok let's surf to HREF!
|
||||
let click = mesh.userData.XRF.href.exec = (e) => {
|
||||
if( v.string[0] == '#' ){
|
||||
let frag = xrf.URI.parse(v.string)
|
||||
if( frag.q ){ // show/hider
|
||||
let q = frag.q.query
|
||||
scene.traverse( (mesh) => {
|
||||
for ( let i in q ) {
|
||||
if( i == mesh.name && q[i].id != undefined ) mesh.visible = q[i].id
|
||||
if( i == mesh.userData.class && q[i].class != undefined ) mesh.visible = q[i].class
|
||||
}
|
||||
})
|
||||
}else if( !v.string.match(/=/) ){ // projection or Selection of Interest (SoI)
|
||||
let id = v.string.substr(1)
|
||||
scene.traverse( (mesh) => {
|
||||
if( mesh.selection ){
|
||||
mesh.remove(mesh.selection)
|
||||
delete mesh.selection
|
||||
}
|
||||
if( id == mesh.name || id == mesh.userData.class ){
|
||||
console.log("applying selection")
|
||||
mesh.selection = new THREE.BoxHelper(mesh,0xff00ff)
|
||||
mesh.selection.scale.set(2,2,2)
|
||||
mesh.selection.position.copy( mesh.position )
|
||||
scene.add(mesh.selection)
|
||||
}
|
||||
})
|
||||
|
||||
}else{ // teleport
|
||||
xrf
|
||||
.emit('href',{click:true,mesh,xrf:v}) // let all listeners agree
|
||||
.then( () => xrf.navigator.to(v.string) ) // ok let's surf to HREF!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let selected = (state) => () => {
|
||||
|
@ -112,14 +134,18 @@ xrf.frag.href = function(v, opts){
|
|||
.then( () => mesh.selected = state )
|
||||
}
|
||||
|
||||
if( !opts.frag.q ){ // query means an action
|
||||
mesh.addEventListener('click', teleport )
|
||||
mesh.addEventListener('mousemove', selected(true) )
|
||||
mesh.addEventListener('nocollide', selected(false) )
|
||||
}
|
||||
mesh.addEventListener('click', click )
|
||||
mesh.addEventListener('mousemove', selected(true) )
|
||||
mesh.addEventListener('nocollide', selected(false) )
|
||||
|
||||
// lazy add mesh (because we're inside a recursive traverse)
|
||||
setTimeout( (mesh) => {
|
||||
mesh.getWorldPosition(world.pos)
|
||||
mesh.getWorldScale(world.scale)
|
||||
mesh.getWorldQuaternion(world.quat);
|
||||
mesh.position.copy(world.pos)
|
||||
mesh.scale.copy(world.scale)
|
||||
mesh.setRotationFromQuaternion(world.quat);
|
||||
xrf.interactive.add(mesh)
|
||||
}, 20, mesh )
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
xrf.frag.q = function(v, opts){
|
||||
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
||||
console.log(" └ running query ")
|
||||
let qobjs = Object.keys(v.query)
|
||||
|
||||
v.scene = new THREE.Group()
|
||||
for ( let i in v.query ) {
|
||||
let target = v.query[i]
|
||||
if( !scene.getObjectByName(i) && i != '*' ) return console.log(` └ mesh not found: ${i}`)
|
||||
if( i == '*' ){
|
||||
let cloneScene = scene.clone()
|
||||
cloneScene.children.forEach( (child) => v.scene.getObjectByName(child.name) ? null : v.scene.add(child) )
|
||||
target.mesh = v.scene
|
||||
}else{
|
||||
console.log(` └ query-ing mesh: ${i}`)
|
||||
if( !v.scene.getObjectByName(i) && target.id === true ){
|
||||
v.scene.add( target.mesh = scene.getObjectByName(i).clone() )
|
||||
}
|
||||
}
|
||||
if( target.id != undefined && target.mesh ){
|
||||
target.mesh.position.set(0,0,0)
|
||||
target.mesh.rotation.set(0,0,0)
|
||||
}
|
||||
}
|
||||
// remove negative selectors
|
||||
let remove = []
|
||||
v.scene.traverse( (mesh) => {
|
||||
for ( let i in v.query ) {
|
||||
if( mesh.name == i && v.query[i].id === false ) remove.push(mesh)
|
||||
}
|
||||
})
|
||||
remove.map( (mesh) => mesh.parent.remove( mesh ) )
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// *TODO* use webgl instancing
|
||||
|
||||
xrf.frag.src = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
let src = new THREE.Group()
|
||||
|
||||
if( v.string[0] == "#" ){ // local
|
||||
console.log(" └ instancing src")
|
||||
let frag = xrfragment.URI.parse(v.string)
|
||||
|
||||
// apply embedded XR fragments
|
||||
setTimeout( () => {
|
||||
// Add the instance to the scene
|
||||
//model.scene.add(clone);
|
||||
// apply URI XR Fragments inside src-value
|
||||
for( var i in frag ){
|
||||
xrf.eval.fragment(i, Object.assign(opts,{frag, model,scene}))
|
||||
}
|
||||
if( frag.q.query ){
|
||||
let srcScene = frag.q.scene
|
||||
if( !srcScene || !srcScene.visible ) return
|
||||
console.log(" └ inserting "+i+" (srcScene)")
|
||||
srcScene.position.set(0,0,0)
|
||||
srcScene.rotation.set(0,0,0)
|
||||
srcScene.traverse( (m) => {
|
||||
if( m.userData && (m.userData.src || m.userData.href) ) return ;//delete m.userData.src // prevent infinite recursion
|
||||
xrf.eval.mesh(m,{scene,recursive:true})
|
||||
})
|
||||
if( srcScene.visible ) src.add( srcScene )
|
||||
}
|
||||
src.position.copy( mesh.position )
|
||||
src.rotation.copy( mesh.rotation )
|
||||
src.scale.copy( mesh.scale )
|
||||
mesh.add(src)
|
||||
console.dir(opts)
|
||||
if( !opts.recursive ) mesh.material.visible = false // lets hide the preview object because deleting disables animations
|
||||
},10)
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
xrf.frag.q = function(v, opts){
|
||||
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
|
||||
console.log(" └ running query ")
|
||||
for ( let i in v.query ) {
|
||||
let target = v.query[i]
|
||||
|
||||
// remove objects if requested
|
||||
if( target.id != undefined && (target.mesh = scene.getObjectByName(i)) ){
|
||||
target.mesh.visible = target.id
|
||||
target.mesh.parent.remove(target.mesh)
|
||||
console.log(` └ removing mesh: ${i}`)
|
||||
}else console.log(` └ mesh not found: ${i}`)
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
// *TODO* use webgl instancing
|
||||
|
||||
xrf.frag.src = function(v, opts){
|
||||
let { mesh, model, camera, scene, renderer, THREE} = opts
|
||||
|
||||
if( v.string[0] == "#" ){ // local
|
||||
console.log(" └ instancing src")
|
||||
let frag = xrfragment.URI.parse(v.string)
|
||||
// Get an instance of the original model
|
||||
let sceneInstance = new THREE.Group()
|
||||
sceneInstance.isSrc = true
|
||||
|
||||
// prevent infinite recursion #1: skip src-instanced models
|
||||
for ( let i in model.scene.children ) {
|
||||
let child = model.scene.children[i]
|
||||
if( child.isSrc ) continue;
|
||||
sceneInstance.add( model.scene.children[i].clone() )
|
||||
}
|
||||
|
||||
sceneInstance.position.copy( mesh.position )
|
||||
sceneInstance.scale.copy(mesh.scale)
|
||||
sceneInstance.updateMatrixWorld(true) // needed because we're going to move portals to the interactive-group
|
||||
|
||||
// apply embedded XR fragments
|
||||
setTimeout( () => {
|
||||
sceneInstance.traverse( (m) => {
|
||||
if( m.userData && m.userData.src ) return ;//delete m.userData.src // prevent infinite recursion
|
||||
xrf.eval.mesh(m,{scene,recursive:true})
|
||||
})
|
||||
// apply URI XR Fragments inside src-value
|
||||
for( var i in frag ){
|
||||
xrf.eval.fragment(i, Object.assign(opts,{frag, model:{scene:sceneInstance},scene:sceneInstance}))
|
||||
}
|
||||
// Add the instance to the scene
|
||||
model.scene.add(sceneInstance);
|
||||
},10)
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ class Query {
|
|||
private var q:haxe.DynamicAccess<Dynamic> = {};
|
||||
private var isProp:EReg = ~/^.*:[><=!]?/;
|
||||
private var isExclude:EReg = ~/^-/;
|
||||
private var isAddition:EReg = ~/^\+/;
|
||||
private var isClass:EReg = ~/^[-]?class$/;
|
||||
private var isNumber:EReg = ~/^[0-9\.]+$/;
|
||||
|
||||
|
@ -89,6 +90,9 @@ class Query {
|
|||
if( isExclude.match(k) ){
|
||||
oper = "!=";
|
||||
k = k.substr(1); // convert "-foo" into "foo"
|
||||
}else if( isAddition.match(k) ){
|
||||
oper = "+=";
|
||||
k = k.substr(1); // convert "+foo" into "foo"
|
||||
}else v = v.substr(oper.length); // change ">=foo" into "foo" (strip operator)
|
||||
if( oper.length == 0 ) oper = "=";
|
||||
|
||||
|
|
|
@ -360,11 +360,11 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
if(Object.prototype.hasOwnProperty.call(Frag_h,key)) {
|
||||
var v = new xrfragment_XRF(key,Frag_h[key]);
|
||||
if(!v.validate(value)) {
|
||||
console.log("src/xrfragment/Parser.hx:75:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
console.log("src/xrfragment/Parser.hx:77:","⚠ fragment '" + key + "' has incompatible value (" + value + ")");
|
||||
return false;
|
||||
}
|
||||
if(xrfragment_Parser.debug) {
|
||||
console.log("src/xrfragment/Parser.hx:78:","✔ " + key + ": " + v.string);
|
||||
console.log("src/xrfragment/Parser.hx:80:","✔ " + key + ": " + v.string);
|
||||
}
|
||||
resultMap[key] = v;
|
||||
}
|
||||
|
@ -373,6 +373,7 @@ xrfragment_Parser.parse = function(key,value,resultMap) {
|
|||
var xrfragment_Query = $hx_exports["xrfragment"]["Query"] = function(str) {
|
||||
this.isNumber = new EReg("^[0-9\\.]+$","");
|
||||
this.isClass = new EReg("^[-]?class$","");
|
||||
this.isAddition = new EReg("^\\+","");
|
||||
this.isExclude = new EReg("^-","");
|
||||
this.isProp = new EReg("^.*:[><=!]?","");
|
||||
this.q = { };
|
||||
|
@ -436,6 +437,9 @@ xrfragment_Query.prototype = {
|
|||
if(_gthis.isExclude.match(k)) {
|
||||
oper = "!=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else if(_gthis.isAddition.match(k)) {
|
||||
oper = "+=";
|
||||
k = HxOverrides.substr(k,1,null);
|
||||
} else {
|
||||
v = HxOverrides.substr(v,oper.length,null);
|
||||
}
|
||||
|
|
|
@ -1451,13 +1451,14 @@ class xrfragment_Parser:
|
|||
|
||||
class xrfragment_Query:
|
||||
_hx_class_name = "xrfragment.Query"
|
||||
__slots__ = ("str", "q", "isProp", "isExclude", "isClass", "isNumber")
|
||||
_hx_fields = ["str", "q", "isProp", "isExclude", "isClass", "isNumber"]
|
||||
__slots__ = ("str", "q", "isProp", "isExclude", "isAddition", "isClass", "isNumber")
|
||||
_hx_fields = ["str", "q", "isProp", "isExclude", "isAddition", "isClass", "isNumber"]
|
||||
_hx_methods = ["toObject", "expandAliases", "get", "parse", "test", "testProperty"]
|
||||
|
||||
def __init__(self,_hx_str):
|
||||
self.isNumber = EReg("^[0-9\\.]+$","")
|
||||
self.isClass = EReg("^[-]?class$","")
|
||||
self.isAddition = EReg("^\\+","")
|
||||
self.isExclude = EReg("^-","")
|
||||
self.isProp = EReg("^.*:[><=!]?","")
|
||||
self.q = _hx_AnonObject({})
|
||||
|
@ -1521,7 +1522,13 @@ class xrfragment_Query:
|
|||
oper = "!="
|
||||
k = HxString.substr(k,1,None)
|
||||
else:
|
||||
v = HxString.substr(v,len(oper),None)
|
||||
_this = _gthis.isAddition
|
||||
_this.matchObj = python_lib_Re.search(_this.pattern,k)
|
||||
if (_this.matchObj is not None):
|
||||
oper = "+="
|
||||
k = HxString.substr(k,1,None)
|
||||
else:
|
||||
v = HxString.substr(v,len(oper),None)
|
||||
if (len(oper) == 0):
|
||||
oper = "="
|
||||
_this = _gthis.isClass
|
||||
|
|
Loading…
Reference in New Issue