Up to date

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

Curve3D

继承: Resource < RefCounted < Object

描述 3D 空间的贝兹尔曲线。

描述

该类描述了 3D 空间中的贝塞尔曲线。它主要用于给 Path3D 提供一个形状,但也可以手动采样以用于其他目的。

它保留沿曲线预先计算的点的缓存,以加速进一步的计算。

属性

float

bake_interval

0.2

int

point_count

0

bool

up_vector_enabled

true

方法

void

add_point ( Vector3 position, Vector3 in=Vector3(0, 0, 0), Vector3 out=Vector3(0, 0, 0), int index=-1 )

void

clear_points ( )

float

get_baked_length ( ) const

PackedVector3Array

get_baked_points ( ) const

PackedFloat32Array

get_baked_tilts ( ) const

PackedVector3Array

get_baked_up_vectors ( ) const

float

get_closest_offset ( Vector3 to_point ) const

Vector3

get_closest_point ( Vector3 to_point ) const

Vector3

get_point_in ( int idx ) const

Vector3

get_point_out ( int idx ) const

Vector3

get_point_position ( int idx ) const

float

get_point_tilt ( int idx ) const

void

remove_point ( int idx )

Vector3

sample ( int idx, float t ) const

Vector3

sample_baked ( float offset=0.0, bool cubic=false ) const

Vector3

sample_baked_up_vector ( float offset, bool apply_tilt=false ) const

Transform3D

sample_baked_with_rotation ( float offset=0.0, bool cubic=false, bool apply_tilt=false ) const

Vector3

samplef ( float fofs ) const

void

set_point_in ( int idx, Vector3 position )

void

set_point_out ( int idx, Vector3 position )

void

set_point_position ( int idx, Vector3 position )

void

set_point_tilt ( int idx, float tilt )

PackedVector3Array

tessellate ( int max_stages=5, float tolerance_degrees=4 ) const

PackedVector3Array

tessellate_even_length ( int max_stages=5, float tolerance_length=0.2 ) const


属性说明

float bake_interval = 0.2

  • void set_bake_interval ( float value )

  • float get_bake_interval ( )

相邻两个缓存点之间的距离,单位为米。改变它将迫使缓存在下次调用 get_baked_pointsget_baked_length 函数时重新计算。距离越小,缓存中的点越多,占用的内存也越多,所以使用时要注意。


int point_count = 0

  • void set_point_count ( int value )

  • int get_point_count ( )

描述该曲线的点的数量。


bool up_vector_enabled = true

  • void set_up_vector_enabled ( bool value )

  • bool is_up_vector_enabled ( )

如果为 true,则曲线将烘焙用于定向的向量。当 PathFollow3D.rotation_mode 被设置为 PathFollow3D.ROTATION_ORIENTED 时使用。更改它会强制缓存被重新计算。


方法说明

void add_point ( Vector3 position, Vector3 in=Vector3(0, 0, 0), Vector3 out=Vector3(0, 0, 0), int index=-1 )

添加一个具有相对于曲线自身位置的指定 position,且带有控制点 inout 的点。在点列表的末尾追加该新点。

如果给定了 index,则将新点插入到由索引 index 标识的已有点之前。从 index 开始的每个已有点,都会在点列表中进一步向下移动。索引必须大于或等于 0,并且不得超过线段中已有点的数量。参见 point_count


void clear_points ( )

从曲线中移除所有点。


float get_baked_length ( ) const

根据缓存的点,返回曲线的总长度。给予足够的密度(见 bake_interval),它应该是足够近似的。


PackedVector3Array get_baked_points ( ) const

返回缓存的点,类型为 PackedVector3Array


PackedFloat32Array get_baked_tilts ( ) const

将倾斜缓存返回为一个 PackedFloat32Array


PackedVector3Array get_baked_up_vectors ( ) const

将向上向量的缓存返回为一个 PackedVector3Array

如果 up_vector_enabledfalse,则缓存将为空。


float get_closest_offset ( Vector3 to_point ) const

返回最接近 to_point 的偏移量。该偏移量被用于 sample_bakedsample_baked_up_vector

to_point 必须在该曲线的局部空间中。


Vector3 get_closest_point ( Vector3 to_point ) const

返回已烘焙的线段上最接近 to_point 的点(在曲线的局部空间中)。

to_point 必须在该曲线的局部空间中。


Vector3 get_point_in ( int idx ) const

返回指向顶点 idx 的控制点的位置。返回的位置是相对于顶点 idx 的。如果索引越界,则该函数将向控制台发送一个错误,并返回 (0, 0, 0)


Vector3 get_point_out ( int idx ) const

返回离向顶点 idx 的控制点的位置。返回的位置是相对于顶点 idx 的。如果索引越界,则该函数将向控制台发送一个错误,并返回 (0, 0, 0)


Vector3 get_point_position ( int idx ) const

返回顶点 idx 的位置。如果索引越界,则该函数将向控制台发送一个错误,并返回 (0, 0, 0)


float get_point_tilt ( int idx ) const

返回点 idx 的倾斜弧度角。如果索引越界,则该函数将向控制台发送一个错误,并返回 0


void remove_point ( int idx )

从曲线上删除点 idx。如果 idx 越界,则会向控制台发送错误信息。


Vector3 sample ( int idx, float t ) const

返回顶点 idx 和顶点 idx + 1 之间的位置,其中 t 控制该点是否为第一个顶点(t = 0.0)、最后一个顶点(t = 1.0)、或介于两者之间。超出范围(0.0 >= t <=1)的 t 的值会给出奇怪但可预测的结果。

如果 idx 越界,它将被截断到第一个或最后一个顶点,而 t 将被忽略。如果曲线没有点,则该函数将向控制台发送一个错误,并返回 (0, 0, 0)


Vector3 sample_baked ( float offset=0.0, bool cubic=false ) const

返回曲线内位于 offset 位置的一个点,其中 offset 为沿曲线的 3D 单位测量距离。为此,它会找到 offset 位于其间的两个缓存点,然后对值进行插值。如果 cubic 被设置为 true,则该插值是立方插值;如果被设置为 false,则该插值是线性插值。

立方插值往往能更好地跟随曲线,但线性插值速度更快(而且通常足够精确)。


Vector3 sample_baked_up_vector ( float offset, bool apply_tilt=false ) const

返回曲线内位于 offset 位置的向上向量,其中 offset 为沿曲线的 3D 单位测量距离。为此,它会找到 offset 位于其间的两个缓存向上向量,然后对值进行插值。如果 apply_tilttrue,则对插值后的向上向量应用插值后的倾斜。

如果曲线没有向上向量,则该函数将向控制台发送一个错误,并返回 (0, 1, 0)


Transform3D sample_baked_with_rotation ( float offset=0.0, bool cubic=false, bool apply_tilt=false ) const

返回一个 Transform3D,其中 origin 作为点位置,basis.x 作为横向向量,basis.y 作为向上向量,basis.z 作为前向向量。当曲线长度为 0 时,将没有合理的方法来计算旋转,所有向量都会与全局空间轴对齐。另请参见 sample_baked


Vector3 samplef ( float fofs ) const

返回顶点 fofs 的位置。该函数使用 fofs 的整数部分作为 idx,其小数部分作为 t,调用 sample


void set_point_in ( int idx, Vector3 position )

设置通往顶点 idx 的控制点位置。如果索引超出范围,函数会向控制台发送错误信息。位置相对于顶点。


void set_point_out ( int idx, Vector3 position )

设置从顶点 idx 引出的控制点位置。如果索引超出范围,函数会向控制台发送错误信息。位置相对于顶点。


void set_point_position ( int idx, Vector3 position )

设置顶点 idx 的位置。如果索引超出范围,函数会向控制台发送错误信息。


void set_point_tilt ( int idx, float tilt )

以弧度为单位,设置点 idx 的倾斜角度。如果索引超出范围,则该函数将向控制台发送一个错误。

倾斜控制对象沿着路径行进时,沿着观察轴的旋转。在曲线控制 PathFollow3D 的情况下,该倾斜是 PathFollow3D 计算的自然倾斜的偏移。


PackedVector3Array tessellate ( int max_stages=5, float tolerance_degrees=4 ) const

返回沿曲线的点的列表,点的密度由曲率控制。也就是说,弯曲的部分比直的部分有更多的点。

这种近似会在每个点之间制作直段,然后将这些直段细分,直到得到的形状足够相似。

max_stages 控制曲线段在被认为足够近似之前可能会面临多少次细分。每次细分会将曲线段分成两半,因此默认的 5 个阶段可能意味着每个曲线段最多得到 32 个细分。请谨慎增加!

tolerance_degrees 控制曲线段在其中点偏离真实曲线的多少度会被细分。


PackedVector3Array tessellate_even_length ( int max_stages=5, float tolerance_length=0.2 ) const

返回沿曲线的点列表,具有几乎均匀的密度。max_stages 控制曲线段在被认为足够近似之前可能面临多少次细分。每次细分将段分成两半,因此默认的 5 个阶段可能意味着每个曲线段最多 32 个细分。请谨慎增加!

tolerance_length 控制在必须细分线段之前两个相邻点之间的最大距离。