This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Curve2d Class

Warning
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.

This class represents an interface enabling you to create and manage 2D curves. These curves are used, for example, to control behavior of various parameters of particle systems (how they change over time).

Curve2d Class

Members

getHash() const#

Returns the current hash value calculated for the curve. Hash value is used for performance optimization and helps define if the curve really needs to be updated, or nothing has changed in its parameters (repeat mode, key points, and tangents are all the same).

Return value

Current hash value calculated for the curve.

getNumKeys() const#

Returns the current total number of key points in the curve.

Return value

Current total number of key points in the curve.

void setRepeatModeStart ( ) #

Sets a new repeat mode for the beginning of the curve (defines behavior before the first key point), one of the REPEAT_MODE_* values. This mode shall be used for repeating the sequence defined by the key points of the curve (tiling curves).

Arguments

  • start - The repeat mode for the beginning of the curve (defines behavior before the first key point), one of the REPEAT_MODE_* values.

getRepeatModeStart() const#

Returns the current repeat mode for the beginning of the curve (defines behavior before the first key point), one of the REPEAT_MODE_* values. This mode shall be used for repeating the sequence defined by the key points of the curve (tiling curves).

Return value

Current repeat mode for the beginning of the curve (defines behavior before the first key point), one of the REPEAT_MODE_* values.

void setRepeatModeEnd ( ) #

Sets a new repeat mode for the end of the curve (defines behavior after the last key point), one of the REPEAT_MODE_* values. This mode shall be used for repeating the sequence defined by the key points of the curve (tiling curves).

Arguments

  • end - The repeat mode for the end of the curve (defines behavior after the last key point), one of the REPEAT_MODE_* values.

getRepeatModeEnd() const#

Returns the current repeat mode for the end of the curve (defines behavior after the last key point), one of the REPEAT_MODE_* values. This mode shall be used for repeating the sequence defined by the key points of the curve (tiling curves).

Return value

Current repeat mode for the end of the curve (defines behavior after the last key point), one of the REPEAT_MODE_* values.

getEventChanged() const#

The event handler signature is as follows: myhandler()

Usage Example

Source code

Return value

Event reference.

Curve2d ( ) #

Constructor. Creates a new 2d curve instance.

void clear ( ) #

Clears the curve removing all key points and tangents.

void copy ( const Curve2d curve ) #

Copies all the data (all key points and tangents) from the specified source curve.

Arguments

  • const Curve2d curve - Source curve.

int addKey ( const vec2 & point ) #

Adds a new key point with the specified coordinates to the curve. Upon completion on this operation the CHANGED event is triggered.

Arguments

  • const vec2 & point - Coordinates of the new key point to be added.

Return value

Number of the added key point.

int addKey ( const vec2 & point, const vec2 & left_tangent, const vec2 & right_tangent ) #

Adds a new key point with the specified coordinates and tangents to the curve. Upon completion on this operation the CHANGED event is triggered.

Arguments

  • const vec2 & point - Coordinates of the new key point to be added.
  • const vec2 & left_tangent - Coordinates of the left tangent at the key point.
  • const vec2 & right_tangent - Coordinates of the right tangent at the key point.

Return value

Number of the added key point.

void removeKey ( int index ) #

Removes the key point with the specified number from the curve. Upon completion on this operation the CHANGED event is triggered.

Arguments

int moveKey ( int index, const vec2 & point ) #

Moves the key point with the specified number to a new position (preserving the tangents). Upon completion on this operation the CHANGED event is triggered. The index of key point will be updated automatically. This method can be used to implement dragging of keys on the curve. In case of moving multiple keys it is recommended to use the setKeyPoint() method to set new values for keys and then sort them all at once via the sortKeys() method to save performance.

Arguments

  • int index - Key point number, in the range from 0 to the total number of key points in the curve.
  • const vec2 & point - New coordinates of the key point.

Return value

New index of the key.

void sortKeys ( ) #

Sorts all key points ov the curve by time (X axis) in the ascending order. Upon completion on this operation the CHANGED event is triggered.

void setKeyPoint ( int index, const vec2 & point ) #

Sets new coordinates for the specified key point (tangents are unaffected). Upon completion on this operation the CHANGED event is triggered. This method unlike the moveKey() does not update the index of the key point automatically. It can be used to implement dragging of multiple keys to set new values for them along with subsequent sorting all keys at once via the sortKeys() method to save performance.

Arguments

  • int index - Key point number, in the range from 0 to the total number of key points in the curve.
  • const vec2 & point - New coordinates to be set for the specified point.

void setKeyLeftTangent ( int index, const vec2 & point ) #

Sets new coordinates for the left tangent at the specified key point of the curve. Upon completion on this operation the CHANGED event is triggered.

Arguments

  • int index - Key point number, in the range from 0 to the total number of key points in the curve.
  • const vec2 & point - New coordinates of the left tangent at the specified key point to be set.

void setKeyRightTangent ( int index, const vec2 & point ) #

Sets new coordinates for the right tangent at the specified key point of the curve. Upon completion on this operation the CHANGED event is triggered.

Arguments

  • int index - Key point number, in the range from 0 to the total number of key points in the curve.
  • const vec2 & point - New coordinates of the right tangent at the specified key point to be set.

vec2 getKeyPoint ( int index ) #

Returns the coordinates of the key point with the specified number.

Arguments

Return value

Current coordinates of the specified key point.

vec2 getKeyLeftTangent ( int index ) #

Returns the current coordinates for the left tangent at the specified key point of the curve.

Arguments

Return value

Current coordinates of the left tangent at the specified key point.

vec2 getKeyRightTangent ( int index ) #

Returns the current coordinates for the right tangent at the specified key point of the curve.

Arguments

Return value

Current coordinates of the right tangent at the specified key point.

int saveState ( Stream stream ) #

Saves data of the curve to a binary stream.

Example using saveState() and restoreState() methods:

Source code (UnigineScript)
// initialize a node and set its state
Curve2d curve = new Curve2d();
curve.addKey(vec2(1, 0));
curve.addKey(vec2(2, 1));
curve.addKey(vec2(4, 3));

// save state
Blob blob_state = new Blob();
curve.saveState(blob_state);

// change state
curve.removeKey(1);

// restore state
blob_state.seekSet(0); // returning the carriage to the start of the blob
curve.restoreState(blob_state);

Arguments

  • Stream stream - Stream to which the curve data will be saved.

Return value

1 if the curve data is saved successfully; otherwise, 0.

int restoreState ( Stream stream ) #

Restores curve data from a binary stream.

Example using saveState() and restoreState() methods:

Source code (UnigineScript)
// initialize a node and set its state
Curve2d curve = new Curve2d();
curve.addKey(vec2(1, 0));
curve.addKey(vec2(2, 1));
curve.addKey(vec2(4, 3));

// save state
Blob blob_state = new Blob();
curve.saveState(blob_state);

// change state
curve.removeKey(1);

// restore state
blob_state.seekSet(0); // returning the carriage to the start of the blob
curve.restoreState(blob_state);

Arguments

  • Stream stream - Stream in which the saved curve parameter data is stored.

Return value

1 if the curve data is restored successfully; otherwise, 0.

int save ( Xml xml ) #

Saves data of the curve to the specified instance of the Xml class.

Arguments

  • Xml xml - Xml class instance to which the curve data will be saved.

Return value

1 if the curve data is successfully saved to the specified Xml class instance; otherwise, 0.

int load ( Xml xml ) #

Loads curve data from the specified instance of the Xml class.

Arguments

  • Xml xml - Xml class instance in which the curve data is stored.

Return value

1 if the curve data is successfully loaded from the specified Xml class instance; otherwise, 0.

float evaluate ( float time ) #

Returns the evaluated value of the curve at the specified point in time.

Arguments

  • float time - The time within the curve you want to evaluate (horizontal axis in the curve graph).

Return value

The value of the curve, at the specified point in time.
Last update: 2024-03-04
Build: ()