onclick - OnClick 在 AFrame-AR.js 场景中的模型
问题描述
我正在使用 Aframe 和 ARJS 处理增强现实场景。当检测到标记时,我目前正在渲染 obj 模型。我的要求是能够在渲染时单击单个模型并对其进行操作。由于某种原因,onclick 似乎不适用于框架模型实体,但它适用于其他原始实体,如 box 。这是我的方法 -
AFRAME.registerComponent('cursor-listener', {
init: function () {
this.el.addEventListener('click', function (evt) {
console.log('I was clicked at: ', evt.detail.intersection.point);
});
}
});
</script>
</head>
<body>
<a-scene embedded arjs='trackingMethod: best; debugUIEnabled: false;' foo>
<a-assets>
<a-asset-item id="crate-obj" src="model.obj"></a-asset-item>
<a-asset-item id="crate-mtl" src="model.mtl"></a-asset-item>
<img id="texture" src="brick.jpg">
</a-assets>
<a-marker preset='hiro'>
<a-entity ><a-obj-model class="collidable" cursor-listener id="animated-marker" src="#crate-obj" position="0 -1.6 0" mtl="#crate-mtl" rotation="-90 0 0" scale="0.004 0.004 0.004" material="" obj-model=""></a-obj-model></a-entity>
//onclick doesn't work
<a-entity material=" src: url(box.png) " class="collidable" cursor-
listener position="0 -1 0"></a-entity> //onclick works here
</a-marker>
<a-camera-static/>
</a-scene>
</body>
</html>
有什么我可能会忽略的吗?或者有没有其他方法可以达到这个要求。谢谢。
解决方案
您需要使用该cursor
组件,因为该click
事件基于 3D 中的光线跟踪。
<a-marker preset='hiro' cursor='rayOrigin: mouse'></a-marker>
推荐阅读
- python - 具有所有自变量作为分类的随机森林回归器
- javascript - 在 React js 中无法使用 beforeunload 函数
- bash - 如果条件不是,则无法以红色打印
- microsoft-teams - 在 Microsoft Teams 中为每个成员创建数字日记
- python - 如何使用 python/scipy 对曲线族进行曲线拟合
- python - 为列表 b 的每个元素检查列表 a 中最接近的最大元素 对此代码的任何优化建议以获取巨大列表
- python - 使用 Python 发送公司电子邮件:TimeoutError
- c++ - 从虚拟析构函数错误 C++ 调用虚拟函数
- xml - 使用 Xpath 跳过指定单词后的空单元格
- expect - 期望脚本接受负数但不接受正数