Unigine.TextureRamp Class
Interface for handling ramp textures. This class lets the user store 2d curves in a form of a texture (convert vectors to raster data).
Ramp textures can be used for color variation in the particles_base material of Particle Systems or in other custom materials.
You can set up to 4 channels for the ramp texture.
TextureRamp Class
Properties
Texture Texture#
The new texture and updates hashes for curves, if required. Returns a pointer to the texture or null if the texture was not created.
int NumChannels#
The number of channels for the texture.
int Resolution#
The width resolution for the texture.
int Flags#
The texture flags.
bool IsDefaultAll#
The value indicating if the values of all curve channels are the default ones which were previously set via DefaultCurve.
Event EventChanged#
The event triggered on changing the ramp texture. You can subscribe to events via
Connect()
and unsubscribe via
Disconnect(). You can also use
EventConnection
and
EventConnections
classes for convenience (see examples below).
The event handler signature is as follows: myhandler( )
For more details see the Event Handling article.
Usage Example
// implement the Changed event handler
void changed_event_handler()
{
Log.Message("\Handling Changed event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections changed_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventChanged.Connect(changed_event_connections, changed_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventChanged.Connect(changed_event_connections, () => {
Log.Message("Handling Changed event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
changed_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Changed event with a handler function
publisher.EventChanged.Connect(changed_event_handler);
// remove subscription to the Changed event later by the handler function
publisher.EventChanged.Disconnect(changed_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection changed_event_connection;
// subscribe to the Changed event with a lambda handler function and keeping the connection
changed_event_connection = publisher.EventChanged.Connect(() => {
Log.Message("Handling Changed event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
changed_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
changed_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
changed_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Changed events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventChanged.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventChanged.Enabled = true;
Members
TextureRamp ( int num_channels, int resolution, int flags ) #
Sets resolution, number of channels and texture flags for this TextureRamp instance. The pointer to the ramp texture is set to null and curves are marked for an update.Arguments
- int num_channels - Number of texture channels.
- int resolution - Width resolution of the ramp texture.
- int flags - Texture flags.
TextureRamp ( TextureRamp texture_ramp ) #
Ramp texture constructor. Creates a new ramp texture by copying a given source ramp texture.Arguments
- TextureRamp texture_ramp - Pointer to a new ramp texture.
TextureRamp ( ) #
void ReleaseTexture ( ) #
Deletes the texture and its pointer.void Copy ( TextureRamp src_texture_ramp ) #
Copies the data of a source ramp texture to the texture.Arguments
- TextureRamp src_texture_ramp - Source ramp texture.
TextureRamp Clone ( ) #
Duplicates the ramp texture and returns a pointer to the copy.Curve2d GetCurve ( int channel ) #
Returns a pointer to the Curve2d for the specified channel.Arguments
- int channel - Required channel.
Return value
Pointer to a Curve2d object.void SetDefaultCurve ( Curve2d default_curve ) #
Resets a curve to a default one.Arguments
- Curve2d default_curve - A curve to be used as the default one.
void SetDefaultCurve ( int channel, Curve2d default_curve ) #
Resets a curve for the given channel to a default one.Arguments
- int channel - R, G, B, or A channel set by the corresponding value from 0 to 3.
- Curve2d default_curve - A curve to be used as the default one.
bool IsDefault ( int channel ) #
Returns a value indicating if the value of the given curve channel is the default one which was previously set via setDefaultCurve.Arguments
- int channel - R, G, B, or A channel set by the corresponding value from 0 to 3.
Return value
true if the curve value is the default one set via setDefaultCurve, otherwise false.void Save ( Xml xml ) #
Saves the ramp texture data to the given Xml node.Arguments
- Xml xml - Target Xml node.
void Save ( Json json ) #
Saves the ramp texture data to the given Json class instance.Arguments
- Json json - Target son class instance.
void Load ( Xml xml ) #
Loads the ramp texture data from the given Xml node.Arguments
- Xml xml - Source Xml node containing ramp texture data.
void Load ( Json json ) #
Loads the ramp texture data from the given Json class instance.Arguments
- Json json - Source Json class instance containing ramp texture data.
void SaveState ( Stream stream ) #
Saves the state of the ramp texture into a binary stream.Example using SaveState() and RestoreState() methods:
// initialize a node and set its state
//...//
// save state
Blob blob_state = new Blob();
ramp.SaveState(blob_state);
// change the node state
//...//
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
ramp.RestoreState(blob_state);
Arguments
- Stream stream - The stream to save the ramp texture state data.
void RestoreState ( Stream stream ) #
Restores the state of the ramp texture from the binary stream.Example using SaveState() and RestoreState() methods:
// initialize a node and set its state
//...//
// save state
Blob blob_state = new Blob();
ramp.SaveState(blob_state);
// change the node state
//...//
// restore state
blob_state.SeekSet(0); // returning the carriage to the start of the blob
ramp.RestoreState(blob_state);
Arguments
- Stream stream - The stream that stores the ramp texture state data.
Last update:
2024-12-13
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)