I'm making an A-Frame project in which I have to set a 3D object to an entity during runtime based on user input. Is there a way to use selector types to set it?
Example:
AFRAME.registerComponent('model',{
schema:{
ext: {type: 'string', default:'gltf'},
scene:{type: 'selector'},
material:{type: 'selector'},
scale:{type: 'string', default: '1 1 1'}
},
init: function (){
var el = this.el;
var data = this.data;
if(data.ext == 'obj')
{
el.setAttribute('obj-model','obj',data.scene);
el.setAttribute('obj-model','mtl',data.material);
}
else
el.setAttribute('gltf-model',data.scene);
el.setAttribute('scale',data.scale);
console.log(this.el.toString() + ': Model component registered successfully!');
}
});
By setting it using the element ID it doesn't work, but if I input the ID manually in the HTML document it works perfectly.
The gltf-model and the obj-model components don't take DOM elements but URLs or selectors. Pass the selector right into the model
AFRAME.registerComponent('model',{
schema:{
ext: {type: 'string', default:'gltf'},
scene:{type: 'string' },
material:{type: 'string'},
scale:{type: 'string', default: '1 1 1'}
}