xrfragment/src/3rd/js/aframe/xrf-get.js

37 lines
957 B
JavaScript
Raw Normal View History

2023-05-22 18:58:05 +02:00
window.AFRAME.registerComponent('xrf-get', {
schema: {
name: {type: 'string'},
clone: {type: 'boolean', default:false}
},
init: function () {
var el = this.el;
var meshname = this.data.name || this.data;
this.el.addEventListener('update', (evt) => {
let scene = AFRAME.XRF.scene
let mesh = scene.getObjectByName(meshname);
if (!mesh){
console.error("mesh with name '"+meshname+"' not found in model")
return;
}
2023-06-07 17:42:21 +02:00
// convert to worldcoordinates
mesh.getWorldPosition(mesh.position)
mesh.getWorldScale(mesh.scale)
mesh.getWorldQuaternion(mesh.quaternion)
2023-05-22 18:58:05 +02:00
if( !this.data.clone ) mesh.parent.remove(mesh)
2023-06-07 17:42:21 +02:00
mesh.isXRF = true // mark for deletion by xrf
2023-05-22 18:58:05 +02:00
this.el.setObject3D('mesh', mesh );
if( !this.el.id ) this.el.setAttribute("id",`xrf-${mesh.name}`)
})
if( this.el.className == "ray" ) this.el.emit("update")
}
});