我在获取自定义 aframe 组件中 aframe 文本组件的高度/宽度时遇到问题。文本出现在我的场景中,我能够 console.log '几何' 和 '材质' 属性。然而,geometry.layout 属性未定义,尽管我可以在 console.log 中看到它! “布局”属性包含高度和宽度,这就是我所需要的。我怎样才能得到它们? 感谢您的帮助。
const label = document.createElement('a-text');
label.setAttribute('id', 'label');
label.setAttribute('position', '0 0 0');
label.setAttribute('value', 'Label test');
label.setAttribute('color', 'black');
label.addEventListener('object3dset', () => {
const { material, geometry } = label.object3D.children[0];
// Property geometry.layout is 'undefined' !!!
console.log('LAYOUT', geometry.layout);
console.log('LAYOUT_HEIGHT', geometry.layout.height);
console.log('LAYOUT_WIDTH', geometry.layout.width);
material.alphaTest = 0.5;
material.transparent = true;
material.depthTest = false;
material.depthWrite = false;
});
您可以尝试打开检查器并询问组件的属性以查看高度/宽度的设置位置。打开检查器的快捷方式是 CTRL+ALT+I(在 Mac 上为 CTRL+OPTION+I)。 有关检查器的更多信息,请访问:https://github.com/aframevr/aframe/blob/master/docs/introduction/visual-inspector-and-dev-tools.md