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()

如果為 true 且曲線的控制點數量大於 2,則結尾的點和開頭的點會連接成環。


int point_count = 0 🔗

  • void set_point_count(value: int)

  • int get_point_count()

描述該曲線的點的數量。


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

通向 index 處頂點的那個控制點的位置。

注意: index 的取值範圍是 0 到 point_count - 1。


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

從 index 處頂點引出的那個控制點的位置。

注意: index 的取值範圍是 0 到 point_count - 1。


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

位於 index 處的那個頂點的位置。

注意: index 的取值範圍是 0 到 point_count - 1。


float point_{index}/tilt = 0.0 🔗

“位於 index 處那個點的傾斜角度(以弧度為單位)。

注意: index 的取值範圍是 0 到 point_count - 1。


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,且帶有控制點 in 和 out 的點。在點列表的末尾追加該新點。

如果給定了 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_enabled 為 false,則快取將為空。


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 🔗

回傳曲線內位於 offset 位置的一個點,其中 offset 為沿曲線的 3D 單位測量距離。為此,它會找到 offset 位於其間的兩個快取點,然後對值進行插值。如果 cubic 被設定為 true,則該插值是立方插值;如果被設定為 false,則該插值是線性插值。

立方插值往往能更好地跟隨曲線,但線性插值速度更快(而且通常足夠精確)。


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

回傳曲線內位於 offset 位置的向上向量,其中 offset 為沿曲線的 3D 單位測量距離。為此,它會找到 offset 位於其間的兩個快取向上向量,然後對值進行插值。如果 apply_tilt 為 true,則對插值後的向上向量應用插值後的傾斜。

如果曲線沒有向上向量,則該函式將向控制台發送一個錯誤,並回傳 (0, 1, 0)。


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

回傳一個 Transform3D,其中 origin 作為點位置,basis.x 作為橫向向量,basis.y 作為向上向量,basis.z 作為前向向量。當曲線長度為 0 時,將沒有合理的方法來計算旋轉,所有向量都會與全域空間軸對齊。另請參見 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 控制在必須細分線段之前兩個相鄰點之間的最大距離。