【问题标题】:On click event in AR mode A-frameAR 模式 A 帧中的点击事件
【发布时间】:2021-03-06 14:30:49
【问题描述】:

我对 AR 很陌生,所以这个问题的答案可能很简单。我编写了一个简单的组件,一旦单击它就会改变框的颜色。该组件在 VR 模式下工作,但在 AR 模式下,当我点击手机屏幕时,它根本不工作。

AFRAME.registerComponent('change-color', {
        schema: {
            color: {
                type: 'string',
                default: 'blue'
            }
        },

        init: function () {
            var data = this.data;
            var el = this.el;

            el.addEventListener('click', function () {
                this.setAttribute('color', data.color);
            })
        }
    });

<a-box id="box" position="0 1.6 3" scale="0.50 0.50 0.50" color="red" change-color></a-box>

【问题讨论】:

    标签: augmented-reality aframe webxr


    【解决方案1】:

    我会调查鼠标(和触摸)光标的使用。

    这里是文档的链接:https://aframe.io/docs/1.0.0/components/cursor.html#properties_rayorigin


    这是一个简单的故障项目,它利用了这个: https://glitch.com/~aframe-grid-select

    注意 index.html 的第 53 行:

    <a-entity raycaster="objects: .collidable" cursor="rayOrigin: mouse" intersection-spawn="event: click; mixin: voxel" ></a-entity>
    

    这是另一个使用相同方法的项目: https://glitch.com/~aframe-building-ui

    注意 index.html 的第 101 行:

    <a-entity id="mouseCursor" cursor="rayOrigin: mouse" raycaster="objects: [raycastable]"></a-entity>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-16
    • 2011-05-01
    • 2018-04-12
    • 2021-08-23
    • 1970-01-01
    • 2014-08-24
    • 2018-04-06
    • 1970-01-01
    相关资源
    最近更新 更多