xrfragment/test/aframe/filter.js

95 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

2023-11-17 16:34:11 +01:00
// test the XR Fragments parser-filters with THREEjs scns
2023-11-16 14:50:57 +01:00
THREE = AFRAME.THREE
createScene = (noadd) => {
let obj = {a:{},b:{},c:{},d:{},extembed:{}}
2023-11-16 14:50:57 +01:00
for ( let i in obj ){
obj[i] = new THREE.Object3D()
obj[i].name = i
2023-11-17 16:34:11 +01:00
obj[i].material = {visible:true, clone: () => ({visible:true}) }
2023-11-16 14:50:57 +01:00
}
let {a,b,c,d,extembed} = obj
let scene = xrf.scene = new THREE.Scene()
2023-11-16 14:50:57 +01:00
if( !noadd ){
a.add(b)
b.add(c)
scene.add(a)
extembed.add(d)
scene.add(extembed)
2023-11-16 14:50:57 +01:00
}
b.userData.score = 2
2023-11-23 12:30:18 +01:00
a.userData.tag = "VR"
b.userData.tag = "foo hide"
c.userData.tag = "flop flap VR"
2023-11-17 16:34:11 +01:00
a.userData.price = 1
b.userData.price = 5
c.userData.price = 10
b.isSRC = "local"
d.userData.tag = "VR"
extembed.isSRC = true
extembed.isSRCExternal = true
return {a,b,c,d,extembed,scene}
2023-11-16 14:50:57 +01:00
}
filterScene = (URI,opts) => {
opts = opts || {}
2024-04-16 15:19:08 +02:00
frag = xrf.URI.parse(URI).XRF
var {a,b,c,d,extembed,scene} = createScene()
xrf.filter.scene({...opts,scene,frag})
2023-11-17 16:34:11 +01:00
scene.visible = (objname, expected, checkMaterial) => {
let o = scene.getObjectByName(objname)
if( !o ) return false === expected
let is = checkMaterial ? o.material.visible : o.visible
if( is !== expected ) console.dir(o)
return is === expected
}
2023-11-16 14:50:57 +01:00
return scene
}
2023-11-17 16:34:11 +01:00
scn = filterScene("#b")
test = () => scn.visible("a",true,true) && scn.visible("b",true) && scn.visible("c",true)
2023-11-17 16:34:11 +01:00
console.assert( test(), {scn,reason:`objectname: #b `})
scn = filterScene("#-b")
test = () => scn.visible("a",true,true) && scn.visible("b",false,true) && scn.visible("c",true) && scn.visible("c",true,true)
console.assert( test(), {scn,reason:`objectname: #-b`})
2023-11-17 16:34:11 +01:00
scn = filterScene("#-b*")
test = () => scn.visible("a",true,true) && scn.visible("b",false,true) && scn.visible("c",false,true)
console.assert( test(), {scn,reason:`objectname: #b*`})
2023-11-17 16:34:11 +01:00
scn = filterScene("#b",{reparent:true})
test = () => scn.visible("a",false) && scn.visible("b",true) && scn.visible("c",true)
console.assert( test(), {scn,reason:`objectname: #b (reparent scene)`})
scn = filterScene("#-b&b*")
2023-11-18 20:50:22 +01:00
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("c",true)
2023-11-17 16:34:11 +01:00
console.assert( test(), {scn,reason:`objectname: #-b&b `})
scn = filterScene("#-a&score*")
test = () => scn.visible("a",false,true) && scn.visible("b",true,true) && scn.visible("c",true,true)
2023-11-17 16:34:11 +01:00
console.assert( test(), {scn,reason:`propertyfilter: #score `})
scn = filterScene("#-a&score*=2")
test = () => scn.visible("a",false,true) && scn.visible("b",true) && scn.visible("c",true)
2023-11-18 20:50:22 +01:00
console.assert( test(), {scn,reason:`propertyfilter: #score=2`})
2023-11-17 16:34:11 +01:00
scn = filterScene("#-price*&price=>5")
test = () => scn.visible("a",false,true) && scn.visible("b",true,true) && scn.visible("c",true,true)
console.assert( test(), {scn,reason:`tagfilter: #-price&price=>5"`})
2023-11-17 16:34:11 +01:00
scn = filterScene("#-hide*")
test = () => scn.visible("a",true,true) && scn.visible("b",false,true) && scn.visible("c",false,true)
console.assert( test(), {scn,reason:`tagfilter: #-hide*"`})
2023-11-17 16:34:11 +01:00
scn = filterScene("#-VR")
test = () => scn.visible("a",false,true) && scn.visible("b",true,true) && scn.visible("c",false,true) && scn.visible("extembed",true,true) && scn.visible("d",true,true)
console.assert( test(), {scn,reason:`tagfilter: #-VR"`})
2023-11-17 16:34:11 +01:00
scn = filterScene("#-VR*")
test = () => scn.visible("a",false,true) && scn.visible("b",false,true) && scn.visible("c",false,true) && scn.visible("extembed",true,true) && scn.visible("d",true,true)
console.assert( test(), {scn,reason:`tagfilter: #-VR*"`})
2023-11-23 12:30:18 +01:00