Curve3D

Inherits: Resource < Reference < Object

描述二维空间的贝兹尔曲线。

描述

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

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

属性

float

bake_interval

0.2

bool

up_vector_enabled

true

方法

void

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

void

clear_points ( )

float

get_baked_length ( ) const

PoolVector3Array

get_baked_points ( ) const

PoolRealArray

get_baked_tilts ( ) const

PoolVector3Array

get_baked_up_vectors ( ) const

float

get_closest_offset ( Vector3 to_point ) const

Vector3

get_closest_point ( Vector3 to_point ) const

int

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

Vector3

interpolate ( int idx, float t ) const

Vector3

interpolate_baked ( float offset, bool cubic=false ) const

Vector3

interpolate_baked_up_vector ( float offset, bool apply_tilt=false ) const

Vector3

interpolatef ( float fofs ) const

void

remove_point ( int idx )

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 )

PoolVector3Array

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

属性说明

Default

0.2

Setter

set_bake_interval(value)

Getter

get_bake_interval()

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


  • bool up_vector_enabled

Default

true

Setter

set_up_vector_enabled(value)

Getter

is_up_vector_enabled()

如果true,曲线将烘焙出用于定向的向量。当PathFollow.rotation_mode被设置为PathFollow.ROTATION_ORIENTED时,就会使用这个功能。改变它将强制重新计算缓存。

方法说明

在曲线的 position 上添加一个点,控制点 inout

如果给定了 at_position,这个点会被插入到点号 at_position 之前,并将这个点(以及之后的每一个点)移到被插入点之后。如果at_position没有给定,或者是一个非法值(at_position <0at_position >= [method get_point_count]),该点将被追加在点列表的最后。


  • void clear_points ( )

从曲线中删除所有点。


  • float get_baked_length ( ) const

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


PoolVector3Array 的形式返回缓存的点。


PoolRealArray 的形式返回倾斜的缓存。


PoolVector3Array 的形式返回向上向量的缓存。

如果 up_vector_enabledfalse,缓存将是空的。


返回离 to_point 最近的偏移量。这个偏移量可以用在 interpolate_bakedinterpolate_baked_up_vector 中。

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


返回最接近 to_point 并烘焙好的点(在曲线的局部空间)。

to_point 必须是在这个曲线的局部空间。


  • int get_point_count ( ) const

返回描述曲线的点数。


返回通往顶点 idx 的控制点的位置。返回的位置是相对于顶点 idx的。如果索引超出了范围,函数会向控制台发送一个错误,并返回 (0, 0, 0)


返回从顶点 idx 伸出的控制点的位置。返回的位置是相对于顶点 idx 的。如果索引超出了范围,函数会向控制台发送一个错误,并返回 (0, 0, 0)


返回顶点的位置 idx。如果索引超出边界,函数会向控制台发送一个错误信息,并返回 (0,0,0)


返回 idx 点的倾斜角,单位为弧度。如果指数超出范围,函数将向控制台发送错误信息,并返回 0


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

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


返回曲线中 offset 偏移位置的一个点,其中 offset 以沿曲线的 3D 单位距离测量。

为了做到这一点,它找到 offset 所在的两个缓存点,然后进行内插值。如果 cubic 被设置为true,这个插值是立方的,如果设置为 false,则是线性的。

立体插值倾向于更好地遵循曲线,但线性插值更快(而且通常足够精确)。


  • Vector3 interpolate_baked_up_vector ( float offset, bool apply_tilt=false ) const

返回位于 offset 位置的曲线内的向上向量,其中 offset 是以 3D 单位测量的曲线距离。

为此,它会找到 offset 所在的两个缓存向上向量,然后对其进行插值。如果 apply_tilttrue,内插后的倾斜会被应用到内插的向上向量上。

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


返回顶点 fofs 的位置。它使用 fofs 的整数部分作为 idx 和分数部分作为 t 调用 interpolate


  • void remove_point ( int idx )

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


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


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


  • void set_point_position ( int idx, Vector3 position )

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


  • void set_point_tilt ( int idx, float tilt )

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

倾斜控制着沿路径移动的对象沿观察轴的旋转。在控制 PathFollow 的曲线的情况下,此倾斜是对 PathFollow 计算的自然倾斜的偏移。


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

这个近似值在每个点之间做了直段,然后将这些直段细分,直到得到的形状足够相似。

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

tolerance_degrees 控制一个曲线段的中点与实际曲线的偏差多少度才会被细分。