Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
TriangleMesh
继承: RefCounted < Object
用于高效、无物理交互查询的三角形几何体。
描述
在三角形几何体周围创建一个包围体积层次(Bounding Volume Hierarchy,BVH)树结构。
三角形 BVH 树可以用于高效的交互查询,无需涉及物理引擎。
例如,在编辑器工具中可以用来根据鼠标光标位置选择具有复杂形状的对象。
性能:为复杂几何体创建 BVH 树是一个缓慢的过程,最好在后台线程中进行。
方法
create_from_faces(faces: PackedVector3Array) |
|
get_faces() const |
|
intersect_ray(begin: Vector3, dir: Vector3) const |
|
intersect_segment(begin: Vector3, end: Vector3) const |
方法说明
bool create_from_faces(faces: PackedVector3Array) 🔗
根据面数组创建 BVH 树。输入的 faces 数组中的每三个顶点代表一个三角形(面)。
如果树成功构建则返回 true,否则返回 false。
PackedVector3Array get_faces() const 🔗
返回几何体中所有面的副本。数组中每三个顶点代表一个三角形(面)。
Dictionary intersect_ray(begin: Vector3, dir: Vector3) const 🔗
检测与射线的交点,射线从 begin 开始,朝向 dir,无限延伸。
如果与某个三角形存在交点,则返回一个 Dictionary,其中包含以下字段:
position:相交三角形上的位置。
normal:相交三角形的法线。
face_index:相交三角形的索引。
如果不存在交点则返回空 Dictionary。
另见 intersect_segment(),与此方法类似,但使用的是线段,长度有限。
Dictionary intersect_segment(begin: Vector3, end: Vector3) const 🔗
检测与线段的交点,线段从 begin 开始,到 end 结束。
如果与某个三角形存在交点,则返回一个 Dictionary,其中包含以下字段:
position:相交三角形上的位置。
normal:相交三角形的法线。
face_index:相交三角形的索引。
如果不存在交点则返回空 Dictionary。
另见 intersect_ray(),与此方法类似,但使用的是射线,长度无限。