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.

Geometry3D

繼承: Object

提供常見 3D 幾何運算的方法。

說明

為建立幾何形狀,計算形狀之間的交集,以及處理 3D 中的各種其他幾何操作提供了一組輔助函式。

方法

Array[Plane]

build_box_planes(extents: Vector3)

Array[Plane]

build_capsule_planes(radius: float, height: float, sides: int, lats: int, axis: Axis = 2)

Array[Plane]

build_cylinder_planes(radius: float, height: float, sides: int, axis: Axis = 2)

PackedVector3Array

clip_polygon(points: PackedVector3Array, plane: Plane)

PackedVector3Array

compute_convex_mesh_points(planes: Array[Plane])

Vector3

get_closest_point_to_segment(point: Vector3, s1: Vector3, s2: Vector3)

Vector3

get_closest_point_to_segment_uncapped(point: Vector3, s1: Vector3, s2: Vector3)

PackedVector3Array

get_closest_points_between_segments(p1: Vector3, p2: Vector3, q1: Vector3, q2: Vector3)

Vector3

get_triangle_barycentric_coords(point: Vector3, a: Vector3, b: Vector3, c: Vector3)

Variant

ray_intersects_triangle(from: Vector3, dir: Vector3, a: Vector3, b: Vector3, c: Vector3)

PackedVector3Array

segment_intersects_convex(from: Vector3, to: Vector3, planes: Array[Plane])

PackedVector3Array

segment_intersects_cylinder(from: Vector3, to: Vector3, height: float, radius: float)

PackedVector3Array

segment_intersects_sphere(from: Vector3, to: Vector3, sphere_position: Vector3, sphere_radius: float)

Variant

segment_intersects_triangle(from: Vector3, to: Vector3, a: Vector3, b: Vector3, c: Vector3)

PackedInt32Array

tetrahedralize_delaunay(points: PackedVector3Array)


方法說明

Array[Plane] build_box_planes(extents: Vector3) 🔗

返回一個包含 6 個 Plane 的陣列,這些 Plane 描述以原點為中心的盒子的邊。盒子大小由 extents 定義,它代表盒子的一個(正)角(即實際大小的一半)。


Array[Plane] build_capsule_planes(radius: float, height: float, sides: int, lats: int, axis: Axis = 2) 🔗

返回一個 Plane 的陣列,這些 Plane 緊密圍繞著以原點為中心的多面膠囊,該膠囊半徑為 radius、高度為 height。參數 sides 定義了將為膠囊的側面部分生成多少個平面,而 lats 給出了膠囊底部和頂部的緯向步數。參數 axis 描述了膠囊的方向軸(0 代表 X,1 代表 Y,2 代表 Z)。


Array[Plane] build_cylinder_planes(radius: float, height: float, sides: int, axis: Axis = 2) 🔗

返回一組 Plane,這些 Plane 緊密圍繞著以原點為中心的多面圓柱體,該圓柱體半徑為 radius、高度為 height 。參數 sides 定義了將為圓柱體的圓形部分生成多少個平面。參數 axis 描述了圓柱體的方向軸(0 代表 X,1 代表 Y,2 代表 Z)。


PackedVector3Array clip_polygon(points: PackedVector3Array, plane: Plane) 🔗

points 中的點所定義的多邊形,裁剪該 plane 並返回該裁剪後的多邊形的點。


PackedVector3Array compute_convex_mesh_points(planes: Array[Plane]) 🔗

計算並傳回所有由 planes 陣列定義的凸形狀的頂點。


Vector3 get_closest_point_to_segment(point: Vector3, s1: Vector3, s2: Vector3) 🔗

返回 3D 線段 (s1, s2) 上與 point 最近的 3D 點。返回的點始終在指定的線段內部。


Vector3 get_closest_point_to_segment_uncapped(point: Vector3, s1: Vector3, s2: Vector3) 🔗

返回直線上與 point 最近的 3D 點,該直線由 (s1, s2) 定義。返回的點可能在線段 (s1, s2) 上,也可能不在,即位於線段的延長線上。


PackedVector3Array get_closest_points_between_segments(p1: Vector3, p2: Vector3, q1: Vector3, q2: Vector3) 🔗

給定兩個 3D 線段 (p1, p2) 和 (q1, q2),找出這兩個線段見距離最近的兩個點。返回 PackedVector3Array,包含 (p1, q1) 和 (p2, q2) 上的點。


Vector3 get_triangle_barycentric_coords(point: Vector3, a: Vector3, b: Vector3, c: Vector3) 🔗

傳回一個 Vector3,其中包含基於 3D 位置(point)與三角形不同頂點(abc).這對於在三角形中不同頂點的資料之間進行插值非常有用。一個範例用例是使用它在網格上平滑旋轉,而不是僅依賴面法線。

這裡是重心座標的更詳細解釋。


Variant ray_intersects_triangle(from: Vector3, dir: Vector3, a: Vector3, b: Vector3, c: Vector3) 🔗

測試起始於 from、方向為 dir 的 3D 射線是否與 abc 構成的三角形相交。如果相交則返回交點 Vector3。如果不相交則返回 null


PackedVector3Array segment_intersects_convex(from: Vector3, to: Vector3, planes: Array[Plane]) 🔗

給定一個通過陣列 planes 中的 Plane 定義的凸面體,測試線段(fromto)是否與該面體相交。如果找到交點,則返回一個 PackedVector3Array,其中包含交點和凸面體的法線。否則,返回一個空陣列。


PackedVector3Array segment_intersects_cylinder(from: Vector3, to: Vector3, height: float, radius: float) 🔗

檢查線段(fromto)是否與以原點為中心且高度為 height、半徑為 radius 的圓柱相交。如果不相交,則返回一個空的 PackedVector3Array。如果相交,則返回的陣列包含交點和圓柱體在交點處的法線。


PackedVector3Array segment_intersects_sphere(from: Vector3, to: Vector3, sphere_position: Vector3, sphere_radius: float) 🔗

檢查線段(fromto)是否與球心位於 sphere_position 且半徑為 sphere_radius 的球體相交。如果不相交,則返回一個空的 PackedVector3Array。如果相交,則返回一個 PackedVector3Array,其中包含交點和球體在交點處的法線。


Variant segment_intersects_triangle(from: Vector3, to: Vector3, a: Vector3, b: Vector3, c: Vector3) 🔗

測試線段(fromto)是否與三角形 abc 相交。如果相交,則將交點作為 Vector3 返回。如果不相交,則返回 null


PackedInt32Array tetrahedralize_delaunay(points: PackedVector3Array) 🔗

Tetrahedralizes the volume specified by a discrete set of points in 3D space, ensuring that no point lies within the circumsphere of any resulting tetrahedron. The method returns a PackedInt32Array where each tetrahedron consists of four consecutive point indices into the points array (resulting in an array with n * 4 elements, where n is the number of tetrahedra found). If the tetrahedralization is unsuccessful, an empty PackedInt32Array is returned.