检测与精灵相交的光线 [英] Detecting rays intersecting a sprite

查看:29
本文介绍了检测与精灵相交的光线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单击鼠标时,我会投射一条射线以查看单击与哪些对象相交.我有一堆可以使用的 Mesh 对象.但是,当我将 Sprite 添加到对象列表时,从未检测到该 Sprite.

On mouse clicks, I project a ray to see which objects are intersected by the click. I have a bunch of Mesh objects that this works with. When I add a Sprite to the list of objects however, the Sprite is never detected.

1) 应该检测精灵吗?有什么东西使它们无法检测到吗?我需要做些什么才能使它们看起来坚固"?2)如果无法检测到精灵,那么使它们可点击的最佳方法是什么?在它们周围添加隐形圆柱体?

1) Should Sprites be detected? Is there something that makes them not detectable? Is there something that I need to do to make them appear 'solid'? 2) If Sprites cannot be detected, what's the best approach to making them clickable? Add invisible cylinders around them?

这是一些适用于 Mesh 的部分代码.

Here's some partial code that works with Mesh.

var containerPosition = $container.position();
var vector = new THREE.Vector3(((event.clientX - containerPosition.left) / scene.WIDTH) * 2 - 1, - ((event.clientY - containerPosition.top) / scene.HEIGHT) * 2 + 1, 0.5);
new THREE.Projector().unprojectVector(vector, scene.camera);
var ray = new THREE.Ray(scene.camera.position, vector.subSelf(scene.camera.position).normalize());
var intersects = ray.intersectObjects(scene.solidObjects);
if (intersects.length > 0) {

推荐答案

似乎 Raycaster 类中的 intersectObject 方法仅配置为查找与 THREE.Particle 和 THREE.Mesh 的碰撞.查看当前的源代码:

It seems as though the intersectObject method in the Raycaster class is only configured to look for collisions with THREE.Particle and THREE.Mesh. See the current source code at:

https://github.com/mrdoob/三.js/blob/master/src/core/Raycaster.js

这篇关于检测与精灵相交的光线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆