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.

Curve2D

Inherits: Resource < RefCounted < Object

描述 2D 空间的贝塞尔曲线。

Description

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

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

Properties

float

bake_interval

5.0

int

point_count

0

Methods

void

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

void

clear_points ( )

float

get_baked_length ( ) const

PackedVector2Array

get_baked_points ( ) const

float

get_closest_offset ( Vector2 to_point ) const

Vector2

get_closest_point ( Vector2 to_point ) const

Vector2

get_point_in ( int idx ) const

Vector2

get_point_out ( int idx ) const

Vector2

get_point_position ( int idx ) const

void

remove_point ( int idx )

Vector2

sample ( int idx, float t ) const

Vector2

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

Transform2D

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

Vector2

samplef ( float fofs ) const

void

set_point_in ( int idx, Vector2 position )

void

set_point_out ( int idx, Vector2 position )

void

set_point_position ( int idx, Vector2 position )

PackedVector2Array

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

PackedVector2Array

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


Property Descriptions

float bake_interval = 5.0

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

描述该曲线的点的数量。


Method Descriptions

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

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

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


void clear_points ( )

从曲线中移除所有点。


float get_baked_length ( ) const

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


PackedVector2Array get_baked_points ( ) const

返回缓存的点,形式为 PackedVector2Array


float get_closest_offset ( Vector2 to_point ) const

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

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


Vector2 get_closest_point ( Vector2 to_point ) const

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