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.

Curve3D

繼承: Resource < RefCounted < Object

描述 3D 空間的貝茲爾曲線。

說明

該類描述了 3D 空間中的貝茲曲線。它主要用於給 Path3D 提供一個形狀,但也可以手動取樣以用於其他目的。

它保留沿曲線預先計算的點的快取,以加速進一步的計算。

屬性

float

bake_interval

0.2

bool

closed

false

int

point_count

0

Vector3

point_{index}/in

Vector3(0, 0, 0)

Vector3

point_{index}/out

Vector3(0, 0, 0)

Vector3

point_{index}/position

Vector3(0, 0, 0)

float

point_{index}/tilt

0.0

bool

up_vector_enabled

true

方法

void

add_point(position: Vector3, in: Vector3 = Vector3(0, 0, 0), out: Vector3 = Vector3(0, 0, 0), index: int = -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(to_point: Vector3) const

Vector3

get_closest_point(to_point: Vector3) const

Vector3

get_point_in(idx: int) const

Vector3

get_point_out(idx: int) const

Vector3

get_point_position(idx: int) const

float

get_point_tilt(idx: int) const

void

remove_point(idx: int)

Vector3

sample(idx: int, t: float) const

Vector3

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

Vector3

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

Transform3D

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

Vector3

samplef(fofs: float) const

void

set_point_in(idx: int, position: Vector3)

void

set_point_out(idx: int, position: Vector3)

void

set_point_position(idx: int, position: Vector3)

void

set_point_tilt(idx: int, tilt: float)

PackedVector3Array

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

PackedVector3Array

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


屬性說明

float bake_interval = 0.2 🔗

  • void set_bake_interval(value: float)

  • float get_bake_interval()

相鄰兩個快取點之間的距離,單位為米。改變它將迫使快取在下次呼叫 get_baked_points()get_baked_length() 函式時重新計算。距離越小,快取中的點越多,佔用的記憶體也越多,所以使用時要注意。


bool closed = false 🔗

  • void set_closed(value: bool)

  • bool is_closed()

If true, and the curve has more than 2 control points, the last point and the first one will be connected in a loop.


int point_count = 0 🔗

  • void set_point_count(value: int)

  • int get_point_count()

描述該曲線的點的數量。


Vector3 point_{index}/in = Vector3(0, 0, 0) 🔗

The position of the control point leading to the vertex at index.

Note: index is a value in the 0 .. point_count - 1 range.


Vector3 point_{index}/out = Vector3(0, 0, 0) 🔗

The position of the control point leading out of the vertex at index.

Note: index is a value in the 0 .. point_count - 1 range.


Vector3 point_{index}/position = Vector3(0, 0, 0) 🔗

The position of for the vertex at index.

Note: index is a value in the 0 .. point_count - 1 range.


float point_{index}/tilt = 0.0 🔗

The tilt angle in radians for the point at index.

Note: index is a value in the 0 .. point_count - 1 range.


bool up_vector_enabled = true 🔗

  • void set_up_vector_enabled(value: bool)

  • bool is_up_vector_enabled()

如果為 true,則曲線將烘焙用於定向的向量。當 PathFollow3D.rotation_mode 被設定為 PathFollow3D.ROTATION_ORIENTED 時使用。更改它會強制快取被重新計算。


方法說明

void add_point(position: Vector3, in: Vector3 = Vector3(0, 0, 0), out: Vector3 = Vector3(0, 0, 0), index: int = -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(to_point: Vector3) const 🔗

返回最接近 to_point 的偏移量。該偏移量被用於 sample_baked()sample_baked_up_vector()

to_point 必須在該曲線的局部空間中。


Vector3 get_closest_point(to_point: Vector3) const 🔗

返回已烘焙的線段上最接近 to_point 的點(在曲線的局部空間中)。

to_point 必須在該曲線的局部空間中。


Vector3 get_point_in(idx: int) const 🔗

返回指向頂點 idx 的控制點的位置。返回的位置是相對於頂點 idx 的。如果索引越界,則該函式將向控制台發送一個錯誤,並返回 (0, 0, 0)


Vector3 get_point_out(idx: int) const 🔗

返回離向頂點 idx 的控制點的位置。返回的位置是相對於頂點 idx 的。如果索引越界,則該函式將向控制台發送一個錯誤,並返回 (0, 0, 0)


Vector3 get_point_position(idx: int) const 🔗

返回頂點 idx 的位置。如果索引越界,則該函式將向控制台發送一個錯誤,並返回 (0, 0, 0)


float get_point_tilt(idx: int) const 🔗

返回點 idx 的傾斜弧度角。如果索引越界,則該函式將向控制台發送一個錯誤,並返回 0


void remove_point(idx: int) 🔗

從曲線上刪除點 idx。如果 idx 越界,則會向控制台發送錯誤資訊。


Vector3 sample(idx: int, t: float) const 🔗

返回頂點 idx 和頂點 idx + 1 之間的位置,其中 t 控制該點是否為第一個頂點(t = 0.0)、最後一個頂點(t = 1.0)、或介於兩者之間。超出範圍(0.0 >= t <=1)的 t 的值會給出奇怪但可預測的結果。

如果 idx 越界,它將被截斷到第一個或最後一個頂點,而 t 將被忽略。如果曲線沒有點,則該函式將向控制台發送一個錯誤,並返回 (0, 0, 0)


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

Returns a point within the curve at position offset, where offset is measured as a distance in 3D units along the curve. To do that, it finds the two cached points where the offset lies between, then interpolates the values. This interpolation is cubic if cubic is set to true, or linear if set to false.

Cubic interpolation tends to follow the curves better, but linear is faster (and often, precise enough).


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

Returns an up vector within the curve at position offset, where offset is measured as a distance in 3D units along the curve. To do that, it finds the two cached up vectors where the offset lies between, then interpolates the values. If apply_tilt is true, an interpolated tilt is applied to the interpolated up vector.

If the curve has no up vectors, the function sends an error to the console, and returns (0, 1, 0).


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

Returns a Transform3D with origin as point position, basis.x as sideway vector, basis.y as up vector, basis.z as forward vector. When the curve length is 0, there is no reasonable way to calculate the rotation, all vectors aligned with global space axes. See also sample_baked().


Vector3 samplef(fofs: float) const 🔗

返回頂點 fofs 的位置。該函式使用 fofs 的整數部分作為 idx,其小數部分作為 t,呼叫 sample()


void set_point_in(idx: int, position: Vector3) 🔗

設定通往頂點 idx 的控制點位置。如果索引超出範圍,函式會向控制台發送錯誤信息。位置相對於頂點。


void set_point_out(idx: int, position: Vector3) 🔗

設定從頂點 idx 引出的控制點位置。如果索引超出範圍,函式會向控制台發送錯誤資訊。位置相對於頂點。


void set_point_position(idx: int, position: Vector3) 🔗

設定頂點 idx 的位置。如果索引超出範圍,函式會向控制台發送錯誤資訊。


void set_point_tilt(idx: int, tilt: float) 🔗

以弧度為單位,設定點 idx 的傾斜角度。如果索引超出範圍,則該函式將向控制台發送一個錯誤。

傾斜控制物件沿著路徑行進時,沿著觀察軸的旋轉。在曲線控制 PathFollow3D 的情況下,該傾斜是 PathFollow3D 計算的自然傾斜的偏移。


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

返回沿曲線的點的列表,點的密度由曲率控制。也就是說,彎曲的部分比直的部分有更多的點。

這種近似會在每個點之間製作直段,然後將這些直段細分,直到得到的形狀足夠相似。

max_stages 控制曲線段在被認為足夠近似之前可能會面臨多少次細分。每次細分會將曲線段分成兩半,因此預設的 5 個階段可能意味著每個曲線段最多得到 32 個細分。請謹慎增加!

tolerance_degrees 控制曲線段在其中點偏離真實曲線的多少度會被細分。


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

返回沿曲線的點列表,具有幾乎均勻的密度。max_stages 控制曲線段在被認為足夠近似之前可能面臨多少次細分。每次細分將段分成兩半,因此預設的 5 個階段可能意味著每個曲線段最多 32 個細分。請謹慎增加!

tolerance_length 控制在必須細分線段之前兩個相鄰點之間的最大距離。