2023-06-08 17:45:21 +02:00
|
|
|
const doPredefinedView = (opts) => {
|
|
|
|
|
let {frag,scene} = opts
|
|
|
|
|
|
2023-06-09 17:40:52 +02:00
|
|
|
const selectionOfInterest = (frag,scene,mesh) => {
|
|
|
|
|
let id = frag.string
|
2023-06-08 17:45:21 +02:00
|
|
|
// Selection of Interest if predefined_view matches object name
|
|
|
|
|
if( mesh.selection ){
|
|
|
|
|
scene.remove(mesh.selection)
|
|
|
|
|
delete mesh.selection
|
|
|
|
|
}
|
|
|
|
|
if( id == mesh.name || id.substr(1) == mesh.userData.class ){
|
2023-06-09 17:40:52 +02:00
|
|
|
xrf.emit('selection',{...opts,frag})
|
2023-06-08 17:45:21 +02:00
|
|
|
.then( () => {
|
|
|
|
|
const margin = 1.2
|
|
|
|
|
mesh.scale.multiplyScalar( margin )
|
|
|
|
|
mesh.selection = new xrf.THREE.BoxHelper(mesh,0xff00ff)
|
|
|
|
|
mesh.scale.divideScalar( margin )
|
|
|
|
|
mesh.selection.material.dispose()
|
|
|
|
|
mesh.selection.material = xrf.navigator.material.selection
|
|
|
|
|
mesh.selection.isXRF = true
|
|
|
|
|
scene.add(mesh.selection)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 16:40:08 +02:00
|
|
|
const predefinedView = (frag,scene,mesh) => {
|
|
|
|
|
let id = frag.string
|
2023-06-10 14:43:07 +02:00
|
|
|
if( mesh.userData[`#${id}`] ){
|
2023-06-08 17:45:21 +02:00
|
|
|
let frag = xrf.URI.parse( mesh.userData[id], xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED )
|
|
|
|
|
for ( let k in frag ){
|
|
|
|
|
let opts = {frag, model, camera: xrf.camera, scene: xrf.scene, renderer: xrf.renderer, THREE: xrf.THREE }
|
2023-06-09 17:40:52 +02:00
|
|
|
xrf.emit('predefinedView',{...opts,frag})
|
2023-06-08 17:45:21 +02:00
|
|
|
.then( () => xrf.eval.fragment(k,opts) )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( let i in frag ) {
|
|
|
|
|
let v = frag[i]
|
|
|
|
|
if( v.is( xrf.XRF.PV_EXECUTE ) ){
|
2023-06-09 16:40:08 +02:00
|
|
|
if( v.args ) v = v.args[ xrf.roundrobin(v,xrf.model) ]
|
2023-06-08 17:45:21 +02:00
|
|
|
// wait for nested instances to arrive at the scene
|
|
|
|
|
setTimeout( () => {
|
|
|
|
|
if( !scene ) return
|
|
|
|
|
scene.traverse( (mesh) => {
|
2023-06-09 17:40:52 +02:00
|
|
|
selectionOfInterest( v, scene, mesh )
|
2023-06-09 16:40:08 +02:00
|
|
|
predefinedView( v , scene, mesh )
|
2023-06-08 17:45:21 +02:00
|
|
|
})
|
|
|
|
|
},100)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when predefined view occurs in url changes
|
|
|
|
|
xrf.addEventListener('eval', doPredefinedView )
|
|
|
|
|
|
|
|
|
|
// clicking href url with predefined view
|
|
|
|
|
xrf.addEventListener('href', (opts) => {
|
|
|
|
|
if( !opts.click || opts.xrf.string[0] != '#' ) return
|
|
|
|
|
let frag = xrf.URI.parse( opts.xrf.string, xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.EMBEDDED )
|
|
|
|
|
doPredefinedView({frag,scene:xrf.scene})
|
|
|
|
|
})
|
2023-06-09 17:40:52 +02:00
|
|
|
|
|
|
|
|
//let updateUrl = (opts) => {
|
|
|
|
|
// console.dir(opts)
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//xrf.addEventListener('predefinedView', updateUrl )
|
|
|
|
|
//xrf.addEventListener('selection', updateUrl )
|