我有一组圆形几何元素,它们位于二十面体元素的顶点上。我想使用jQuery在每个单独的circle元素上执行click事件。那么如何在这些元素上实现jQuery click事件..
建议我做一些很好的参考..
答案 0 :(得分:1)
使用光线投射方法。基本机制是这样的: (三个版本70和javascript vanila)
1)设置目标
var targets = [],
// When defining your 3d objects, use the push method
// to select the meshes you want to intersect.
// targets.push(objectMesh);
2)设置raycaster
var raycaster = new THREE.Raycaster(),
mouse = new THREE.Vector2(),
intersects;
3)相交目标
searchTarget(event){
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
intersects = raycaster.intersectObjects(targets);
if (intersects.length > 0){
// Use the intersected objects:
// intersects[0] represents the foremost object that was hovered
}
}
4)设置监听器
renderer.domElement.addEventListener('mousemove', searchTarget, false);
你也可以使用jQuery:$( "#canvas" ).mousemove( searchTarget );