Keyframes Layers trueSKY Actor

Select your engine:

Scripting

Alongside the Sequencer tool, trueSKY can be driven and configured via Unity scripting. Similarly to using the sequencer, the settings and properties in trueSKY for Unity are split between Keyframe properties (temporal values for clouds and sky), Layer properites (values for clouds and sky that persist throughout a sequence) and the properties of the trueSKY object itself (configuration settings).

trueSKY Object

To modify trueSKY object via scripting, a reference to the active object in the scene must first be obtained (there should only be one). This can be done upon initialisation; the code to do so is as follows:

simul.trueSKY trueSky=simul.trueSKY.GetTrueSky();

All editor properties of the trueSKY object are publicly accessible, so once a reference to the trueSKY object has been obtained, they can also be accessed and modified via scripting. For example, to disable depth blending:

private simul.trueSKY tS;  

void Start () 
{
tS = simul.trueSKY.GetTrueSky (); 
tS.DepthBlending = false;
}

Layers

Layer properties are those accessible in the sequencer by clicking on the layer name on the left of the timeline. These affect the entire sequence and the values will remain until the user changes them manually. This differs in nature from keyframe properties, which are active only between specified times and will be automatically modified via interpolation (for example if two adjacent keyframes have cloudiness set to 0.4 and 0.6 respectively, trueSKY will interpolate these values for times in between, increasing gradually from 0.4 to 0.6). The functions needed to Get and Set layer properties are as follows:

Sky:

Clouds:

For trueSKY 4.1a

2D Clouds:

  • Get2DCloudFloat (string name): Gets the 2D cloud layer float specified by the name string.
  • Get2DCloudInt (string name): Gets the 2D cloud layer int specified by the name string.
  • Set2DCloudFloat (string name, float value): Sets the 2D cloud layer float specified by the name string to the given float value.
  • Set2DCloudInt (string name, int value): Sets the 2D cloud layer int specified by the name string to the given float value.

Example: To increment the Ozone layer strength by 0.1,

private trueSKY tS;

void Start () 
{
tS = trueSKY.GetTrueSky (); 
tS.SetSkyFloat("OzoneStrength", tS.GetSkyFloat("OzoneStrength") + 0.1f);  
}

For information about the layer properties you can change and the name strings needed to do so, see the Cloud and Sky pages.

Keyframes

Keyframes in trueSKY can be accessed, counted, modified, created and deleted via scripting. To delete a keyframe or change its properties, the Unique Identifier (Uid) will need to be known. These can be retrieved either by index (the keyframes in the sequencer, which are zero-indexed) or by retrieving the current/interpolated keyframe (not viewable in the sequencer, as they are interpolated). Uids are unique and persistent for the session, but not across saves or restarts, so they should not be stored. Note: For any functions with a layer parameter, the layer indexes are as follows: 0 for the sky, 1 for 3D Clouds and 2 for 2D Clouds (if in 4.1a).

Sky:

3D Clouds:

For trueSKY 4.1a

2D Clouds:

  • GetCloud2DKeyframeByIndex (int index): Get the 2D cloud keyframe with specified index.
  • GetInterpolatedCloudKeyframe (int layer = 2): Retrieve the interpolated (current) 2D cloud keyframe.
  • Insert2DCloudKeyframe (float t): Insert a 2D cloud keyframe at specified time t.
  • GetNumCloud2DKeyframes (): Returns the total number of 2D cloud keyframes.

Once you know the Uid of a keyframe, you can then get the values of its properties, set said values or delete the keyframe. Whether you’re accessing/modifying sky, 3D cloud or 2D cloud keyframes, these tasks are accomplished via the following functions:

Example: In the script KeyframeTesting.cs in the Simul directory, is a function that sets all the cloud keyframes to have a “cloudiness” of 0.8 when the game is run:

int numk = trueSky.GetNumCloudKeyframes();

for(int i = 0; i < numk; i++)
{
uint uid = trueSky.GetCloudKeyframeByIndex(i);
trueSky.SetKeyframeValue(uid, "cloudiness", 0.8);
}

Example: Getting the current cloudiness of the interpolated keyframe

private trueSKY tS;   

void Start () 
{
tS = trueSKY.GetTrueSky();
uint uid = tS.GetInterpolatedCloudKeyframe (1);
tS.GetKeyframeValue (uid, "cloudiness"); 
}

Other Functions

Queries

TrueSKY for Unity also provides some built in functions to carry out queries at given positions. It is possible to carry out cloud queries at a given position, and cloud line queries across two positions. These will return a VolumeQueryResult and a LineQueryResult respectively. Additionally there are more simplified functions for when you want just one value, for example, the amount of rain at a given position. Where applicable, id parameters should be given any unique integer (calling another query with the same id will overwrite the former). The functions are as follows:

The contents of the structs are as follows:

VolumeQueryResult:

LineQueryResult:

Storms

The centre of a storm can be set via the SetStormCentre (float x, float y) function. This is equivalent to setting the storm centre via the map window in the sequencer (hence only two axes).

Unity <-> trueSKY Coordinate Conversions

As Unity and trueSKY treat coordinates differently (which axis is considered “up”), these functions are provided to convert between them when needed: