Class Curve3D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
This class describes a Bézier curve in 3D space. It is mainly used to give a shape to a Path3D, but can be manually sampled for other purposes.
It keeps a cache of precalculated points along the curve, to speed up further calculations.
public class Curve3D : Resource, IDisposable
- Inheritance
-
Curve3D
- Implements
- Inherited Members
Constructors
Curve3D()
public Curve3D()
Properties
BakeInterval
The distance in meters between two adjacent cached points. Changing it forces the cache to be recomputed the next time the GetBakedPoints() or GetBakedLength() function is called. The smaller the distance, the more points in the cache and the more memory it will consume, so use with care.
public float BakeInterval { get; set; }
Property Value
PointCount
The number of points describing the curve.
public int PointCount { get; set; }
Property Value
UpVectorEnabled
If true
, the curve will bake up vectors used for orientation. This is used when RotationMode is set to Oriented. Changing it forces the cache to be recomputed.
public bool UpVectorEnabled { get; set; }
Property Value
_Data
public Dictionary _Data { get; set; }
Property Value
Methods
AddPoint(Vector3, Vector3?, Vector3?, int)
Adds a point with the specified position
relative to the curve's own position, with control points in
and out
. Appends the new point at the end of the point list.
If index
is given, the new point is inserted before the existing point identified by index index
. Every existing point starting from index
is shifted further down the list of points. The index must be greater than or equal to 0
and must not exceed the number of existing points in the line. See PointCount.
public void AddPoint(Vector3 position, Vector3? @in = null, Vector3? @out = null, int index = -1)
Parameters
position
Vector3in
Vector3?If the parameter is null, then the default value is
new Vector3(0, 0, 0)
.out
Vector3?If the parameter is null, then the default value is
new Vector3(0, 0, 0)
.index
int
ClearPoints()
Removes all points from the curve.
public void ClearPoints()
GetBakedLength()
Returns the total length of the curve, based on the cached points. Given enough density (see BakeInterval), it should be approximate enough.
public float GetBakedLength()
Returns
GetBakedPoints()
Returns the cache of points as a Vector3[].
public Vector3[] GetBakedPoints()
Returns
- Vector3[]
GetBakedTilts()
Returns the cache of tilts as a float[].
public float[] GetBakedTilts()
Returns
- float[]
GetBakedUpVectors()
Returns the cache of up vectors as a Vector3[].
If UpVectorEnabled is false
, the cache will be empty.
public Vector3[] GetBakedUpVectors()
Returns
- Vector3[]
GetClosestOffset(Vector3)
Returns the closest offset to toPoint
. This offset is meant to be used in SampleBaked(float, bool) or SampleBakedUpVector(float, bool).
toPoint
must be in this curve's local space.
public float GetClosestOffset(Vector3 toPoint)
Parameters
toPoint
Vector3
Returns
GetClosestPoint(Vector3)
Returns the closest point on baked segments (in curve's local space) to toPoint
.
toPoint
must be in this curve's local space.
public Vector3 GetClosestPoint(Vector3 toPoint)
Parameters
toPoint
Vector3
Returns
GetPointIn(int)
Returns the position of the control point leading to the vertex idx
. The returned position is relative to the vertex idx
. If the index is out of bounds, the function sends an error to the console, and returns (0, 0, 0)
.
public Vector3 GetPointIn(int idx)
Parameters
idx
int
Returns
GetPointOut(int)
Returns the position of the control point leading out of the vertex idx
. The returned position is relative to the vertex idx
. If the index is out of bounds, the function sends an error to the console, and returns (0, 0, 0)
.
public Vector3 GetPointOut(int idx)
Parameters
idx
int
Returns
GetPointPosition(int)
Returns the position of the vertex idx
. If the index is out of bounds, the function sends an error to the console, and returns (0, 0, 0)
.
public Vector3 GetPointPosition(int idx)
Parameters
idx
int
Returns
GetPointTilt(int)
Returns the tilt angle in radians for the point idx
. If the index is out of bounds, the function sends an error to the console, and returns 0
.
public float GetPointTilt(int idx)
Parameters
idx
int
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
RemovePoint(int)
Deletes the point idx
from the curve. Sends an error to the console if idx
is out of bounds.
public void RemovePoint(int idx)
Parameters
idx
int
Sample(int, float)
Returns the position between the vertex idx
and the vertex idx + 1
, where t
controls if the point is the first vertex (t = 0.0
), the last vertex (t = 1.0
), or in between. Values of t
outside the range (0.0 >= t <=1
) give strange, but predictable results.
If idx
is out of bounds it is truncated to the first or last vertex, and t
is ignored. If the curve has no points, the function sends an error to the console, and returns (0, 0, 0)
.
public Vector3 Sample(int idx, float t)
Parameters
Returns
SampleBaked(float, bool)
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).
public Vector3 SampleBaked(float offset = 0, bool cubic = false)
Parameters
Returns
SampleBakedUpVector(float, bool)
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 applyTilt
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)
.
public Vector3 SampleBakedUpVector(float offset, bool applyTilt = false)
Parameters
Returns
SampleBakedWithRotation(float, bool, bool)
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 SampleBaked(float, bool).
public Transform3D SampleBakedWithRotation(float offset = 0, bool cubic = false, bool applyTilt = false)
Parameters
Returns
Samplef(float)
Returns the position at the vertex fofs
. It calls Sample(int, float) using the integer part of fofs
as idx
, and its fractional part as t
.
public Vector3 Samplef(float fofs)
Parameters
fofs
float
Returns
SetPointIn(int, Vector3)
Sets the position of the control point leading to the vertex idx
. If the index is out of bounds, the function sends an error to the console. The position is relative to the vertex.
public void SetPointIn(int idx, Vector3 position)
Parameters
SetPointOut(int, Vector3)
Sets the position of the control point leading out of the vertex idx
. If the index is out of bounds, the function sends an error to the console. The position is relative to the vertex.
public void SetPointOut(int idx, Vector3 position)
Parameters
SetPointPosition(int, Vector3)
Sets the position for the vertex idx
. If the index is out of bounds, the function sends an error to the console.
public void SetPointPosition(int idx, Vector3 position)
Parameters
SetPointTilt(int, float)
Sets the tilt angle in radians for the point idx
. If the index is out of bounds, the function sends an error to the console.
The tilt controls the rotation along the look-at axis an object traveling the path would have. In the case of a curve controlling a PathFollow3D, this tilt is an offset over the natural tilt the PathFollow3D calculates.
public void SetPointTilt(int idx, float tilt)
Parameters
Tessellate(int, float)
Returns a list of points along the curve, with a curvature controlled point density. That is, the curvier parts will have more points than the straighter parts.
This approximation makes straight segments between each point, then subdivides those segments until the resulting shape is similar enough.
maxStages
controls how many subdivisions a curve segment may face before it is considered approximate enough. Each subdivision splits the segment in half, so the default 5 stages may mean up to 32 subdivisions per curve segment. Increase with care!
toleranceDegrees
controls how many degrees the midpoint of a segment may deviate from the real curve, before the segment has to be subdivided.
public Vector3[] Tessellate(int maxStages = 5, float toleranceDegrees = 4)
Parameters
Returns
- Vector3[]
TessellateEvenLength(int, float)
Returns a list of points along the curve, with almost uniform density. maxStages
controls how many subdivisions a curve segment may face before it is considered approximate enough. Each subdivision splits the segment in half, so the default 5 stages may mean up to 32 subdivisions per curve segment. Increase with care!
toleranceLength
controls the maximal distance between two neighboring points, before the segment has to be subdivided.
public Vector3[] TessellateEvenLength(int maxStages = 5, float toleranceLength = 0.2)
Parameters
Returns
- Vector3[]