有没有办法通过在模式中使用选择器在运行时在 A-Frame 中设置 'gltf-model' 或 'obj-model'?

Is there a way to set a 'gltf-model' or 'obj-model' in A-Frame during runtime by using a selector in the schema?

我正在制作一个 A-Frame 项目,我必须在运行时根据用户输入将 3D 对象设置为实体。有没有办法使用选择器类型来设置它?

示例:

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!');
   }
});

通过使用元素 ID 设置它不起作用,但如果我在 HTML 文档中手动输入 ID,它就可以正常工作。

gltf-model and the obj-model 组件不采用 DOM 元素,而是采用 URL 或选择器。将选择器直接传递到模型中

AFRAME.registerComponent('model',{
 schema:{
  ext: {type: 'string', default:'gltf'},
  scene:{type: 'string' },
  material:{type: 'string'},
  scale:{type: 'string', default: '1 1 1'}
}

Corrected glitch