Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Geometry3D

继承: Object

提供常见 3D 几何运算的方法。

描述

为创建几何形状,计算形状之间的交集,以及处理 3D 中的各种其他几何操作提供了一组辅助函数。

方法

Plane[]

build_box_planes ( Vector3 extents )

Plane[]

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

Plane[]

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

PackedVector3Array

clip_polygon ( PackedVector3Array points, Plane plane )

PackedVector3Array

compute_convex_mesh_points ( Plane[] planes )

Vector3

get_closest_point_to_segment ( Vector3 point, Vector3 s1, Vector3 s2 )

Vector3

get_closest_point_to_segment_uncapped ( Vector3 point, Vector3 s1, Vector3 s2 )

PackedVector3Array

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

Vector3

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

Variant

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

PackedVector3Array

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

PackedVector3Array

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

PackedVector3Array

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

Variant

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


方法说明

Plane[] build_box_planes ( Vector3 extents )

返回一个包含 6 个 Plane 的数组,这些 Plane 描述以原点为中心的盒子的边。盒子大小由 extents 定义,它代表盒子的一个(正)角(即实际大小的一半)。


Plane[] build_capsule_planes ( float radius, float height, int sides, int lats, Vector3.Axis axis=2 )

返回一个 Plane 的数组,这些 Plane 紧密围绕着以原点为中心的多面胶囊,该胶囊半径为 radius、高度为 height。参数 sides 定义了将为胶囊的侧面部分生成多少个平面,而 lats 给出了胶囊底部和顶部的纬向步数。参数 axis 描述了胶囊的方向轴(0 代表 X,1 代表 Y,2 代表 Z)。


Plane[] build_cylinder_planes ( float radius, float height, int sides, Vector3.Axis axis=2 )

返回一组 Plane,这些 Plane 紧密围绕着以原点为中心的多面圆柱体,该圆柱体半径为 radius、高度为 height 。参数 sides 定义了将为圆柱体的圆形部分生成多少个平面。参数 axis 描述了圆柱体的方向轴(0 代表 X,1 代表 Y,2 代表 Z)。


PackedVector3Array clip_polygon ( PackedVector3Array points, Plane plane )

points 中的点所定义的多边形,裁剪该 plane 并返回该裁剪后的多边形的点。


PackedVector3Array compute_convex_mesh_points ( Plane[] planes )

计算并返回由一组 planes 定义的凸形状的所有顶点。


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

返回 3D 线段 (s1, s2) 上与 point 最近的 3D 点。返回的点始终在指定的线段内部。


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

返回直线上与 point 最近的 3D 点,该直线由 (s1, s2) 定义。返回的点可能在线段 (s1, s2) 上,也可能不在,即位于线段的延长线上。


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

给定两个 3D 线段 (p1, p2) 和 (q1, q2),找出这两个线段见距离最近的两个点。返回 PackedVector3Array,包含 (p1, q1) 和 (p2, q2) 上的点。


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

返回一个 Vector3,其中包含基于 3D 位置(point)与三角形不同顶点(abc)的接近程度的权重。这对于在三角形中不同顶点的数据之间进行插值非常有用。一个示例用例是使用它在网格上平滑旋转,而不是仅仅依赖于面法线。

这里是重心坐标的更详细解释。


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

测试起始于 from、方向为 dir 的 3D 射线是否与 abc 构成的三角形相交。如果相交则返回交点 Vector3。如果不相交则返回 null


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

给定一个通过数组 planes 中的 Plane 定义的凸面体,测试线段(fromto)是否与该面体相交。如果找到交点,则返回一个 PackedVector3Array,其中包含交点和凸面体的法线。否则,返回一个空数组。


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

检查线段(fromto)是否与以原点为中心且高度为 height、半径为 radius 的圆柱相交。如果不相交,则返回一个空的 PackedVector3Array。如果相交,则返回的数组包含交点和圆柱体在交点处的法线。


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

检查线段(fromto)是否与球心位于 sphere_position 且半径为 sphere_radius 的球体相交。如果不相交,则返回一个空的 PackedVector3Array。如果相交,则返回一个 PackedVector3Array,其中包含交点和球体在交点处的法线。


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

测试线段(fromto)是否与三角形 abc 相交。如果相交,则将交点作为 Vector3 返回。如果不相交,则返回 null