将精灵与 Raycaster 相交 [英] Intersect Sprites with Raycaster

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

问题描述

我想用three.js实现一个3D交互式地球,不知道有没有办法用Raycaster在Sprites原语上相交?

I want to realize a 3D interactive globe with three.js and I wonder if there is a way to intersect over Sprites primitive with the Raycaster?

推荐答案

如果您在

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

看起来 intersectObject 函数只检查作为 THREE.Particle 或 THREE.Mesh 实例的对象,而不是 THREE.Sprite.可能这是因为精灵可以设置为使用屏幕坐标,因此在这种情况下投射到 3d 场景中的光线没有意义,或者如果放置在场景中,因为精灵图像总是面向相机,它不会不像标准的 3d 网格.

it would appear that the intersectObject function only checks objects that are instances of THREE.Particle or THREE.Mesh, not THREE.Sprite. Possibly this is because sprites could be set to use screen coordinates, and so a ray that projects into your 3d scene wouldn't make sense in this situation, or if placed in the scene as the sprite image always faces the camera, it doesn't act like your standard 3d mesh.

也许您可以将一个 PlaneGeometry 或一个非常薄的 CubeGeometry 附加到您的 sprite 的位置,将其旋转设置为相机的旋转,以便它始终像 sprite 一样与相机的视图平面平行,然后改为检查与网格的交点?

Perhaps you could attach a PlaneGeometry or a very thin CubeGeometry to the position of your sprite, set its rotation to the rotation of the camera so that it is always parallel to the view plane of the camera like the sprite is, and then check for intersections with the mesh instead?

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

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