【发布时间】:2020-09-11 07:47:31
【问题描述】:
我将 aframe 和 AR.js 用于增强现实项目。我正在尝试将鼠标事件附加到 3D 对象。根据 ar.js 文档,您必须为此使用光标。
我要做的是,将鼠标设为光标,然后使用aframe-mouse-cursor-component 将鼠标事件附加到它上面,如图所示here。
它在一定程度上起作用。我可以使用鼠标在屏幕上拖动 3D 资产,但鼠标事件都不起作用。
这是 HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@1c2407b26c61958baa93967b5412487cd94b290b/dist/aframe-master.min.js"></script>
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
<script src="js/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/aframe-mouse-cursor-component@0.5.3/dist/aframe-mouse-cursor-component.min.js"></script>
<body style='margin : 0px; overflow: hidden;'>
<a-scene embedded arjs='sourceType: webcam' cursor="rayOrigin: mouse">
<a-assets>
<!--Used <a-asset-item> here -->
</a-assets>
<a-marker type='pattern' url='markers/mainmarker.patt'>
<a-entity right gltf-model="#arrow" scale="1.5 1.5 1.5" ></a-entity>
<!-- other <a-entity> entities -->
</a-marker>
<a-entity camera look-controls mouse-cursor>
<!-- <a-entity cursor="fuse: true; fuseTimeout: 500"
position="0 0 -1"
geometry="primitive: ring; radiusInner: 0.049; radiusOuter: 0.05"
material="color: red; shader: flat">
</a-entity> I have tried the code with and without this part -->
</a-entity>
</a-scene>
</body>
</html>
这是 JS:
AFRAME.registerComponent('right', {
init: function () {
this.el.addEventListener('mousedown', function (evt) {
console.log("THIS GOT CLICKED");
//other stuff to do
});
}
});
我尝试了很多事件 - mousedown、mouseup、click 等。但都没有工作。
如何将这些事件绑定到鼠标?
【问题讨论】:
标签: javascript dom-events aframe