Scripting API

Home Scripting API Index Class Overview

com.nolimitscoaster

Class Tools


public class Tools
extends Object

Contains tool functions

Method Summary

static void convertToLinearFromSRGB(nlvm.math3d.Vector3f col, float intensity)
  Converts color from sRGB to linear color space.
static void convertToLinearFromSRGB(nlvm.math3d.Vector4f col, float intensity)
  Converts color from sRGB to linear color space.
static double cubicRamp(double x)
  Cubic ramp function
static double lerp(double t, double a, double b)
  Computes the linear interpolation between two values a and b
static float lerp(float t, float a, float b)
  Computes the linear interpolation between two values a and b
static byte[] loadBinaryFile(String path)
  Loads a binary file
static byte[] loadBinaryFileFromResource(ResourcePath resourcePath)
  Loads a binary file
static byte[] loadBinaryFileFromResourceId(String resourceId)
  Loads a binary file
static String loadTextFile(String path)
  Loads a text file in UTF8 encoding
static String loadTextFileFromResource(ResourcePath resourcePath)
  Loads a text file in UTF8 encoding
static String loadTextFileFromResourceId(String resourceId)
  Loads a text file in UTF8 encoding
static void matrixToPitchHeadBankPos(nlvm.math3d.Matrix4x4f mIn, nlvm.math3d.Vector3f pitchHeadBankOut, nlvm.math3d.Vector3f posOut)
  Computes a set of angles and a translation vector based on an input transformation matrix.
static void matrixToPitchHeadBankPosScale(nlvm.math3d.Matrix4x4f mIn, nlvm.math3d.Vector3f pitchHeadBankOut, nlvm.math3d.Vector3f posOut, nlvm.math3d.Vector3f scaleOut)
  Computes a set of angles and a translation vector and a scale vector based on an input transformation matrix.
static float perlinNoise(float x, float y, float z)
  Perlin noise function (3D)
static double quinticRamp(double x)
  Quintic ramp function
static double switchRampC1(double T, double S, double ta, double t)
  A special fade function with 3 phases (acceleration, constant speed, deceleration).
static double switchRampC2(double T, double S, double ta, double t)
  A special fade function with 3 phases (acceleration, linear speed, deceleration).


Method Detail


convertToLinearFromSRGB

public static void convertToLinearFromSRGB(nlvm.math3d.Vector3f col, float intensity)

Converts color from sRGB to linear color space.

The RGB color in col.x,y,z is converted from sRGB gamma color space to linear color space and is afterwards multiplied with an intensity factor. The input values are assumed to be in the range 0...1 as converted from 0..255 values divided by 255.0f. Values outside of 0...1 will be clamped to 0...1 before the conversion to linear space. The result of the conversion is stored in col.x,y,z.

Parameters:

col - In and out parameter with color information stored in x,y,z (0...1). Must not be null.
intensity - Intensity factor which will be implicitly multiplied to the result of the conversion. Set to 1.0f for a standard conversion.

Since:
    2.6.2.0


convertToLinearFromSRGB

public static void convertToLinearFromSRGB(nlvm.math3d.Vector4f col, float intensity)

Converts color from sRGB to linear color space.

The RGB color in col.x,y,z is converted from sRGB gamma color space to linear color space and is afterwards multiplied with an intensity factor. The input values are assumed to be in the range 0...1 as converted from 0..255 values divided by 255.0f. Values outside of 0...1 will be clamped to 0...1 before the conversion to linear space. The result of the conversion is stored in col.x,y,z. The w component which typically stores alpha channel is ignored and left untouched.

Parameters:

col - In and out parameter with color information stored in x,y,z (0...1). Must not be null. w is not modified.
intensity - Intensity factor which will be implicitly multiplied to the result of the conversion. Set to 1.0f for a standard conversion.

Since:
    2.6.2.0


cubicRamp

public static double cubicRamp(double x)

Cubic ramp function

A smoothstep function that will compute 3*x^2 - 2*x^3

Parameters:

x - input value (will be clamped to the range 0..1)

Returns:
    output value (0..1)


lerp

public static double lerp(double t, double a, double b)

Computes the linear interpolation between two values a and b

Pseudo code: this = (1-t) * a + t * b.

Parameters:

t - interpolation time, typically between 0...1
a - first value
b - second value

Since:
    2.6.3.3


lerp

public static float lerp(float t, float a, float b)

Computes the linear interpolation between two values a and b

Pseudo code: this = (1-t) * a + t * b.

Parameters:

t - interpolation time, typically between 0...1
a - first value
b - second value

Since:
    2.6.3.3


loadBinaryFile

public static byte[] loadBinaryFile(String path)

Loads a binary file

Parameters:

path - path to file (relative to the classpath)

Returns:
    content of file as byte array, will return null if file could not be found or loaded

Since:
    2.2.4.0


loadBinaryFileFromResource

public static byte[] loadBinaryFileFromResource(ResourcePath resourcePath)

Loads a binary file

Parameters:

resourcePath - The resource path can be obtained from Script.getResourcePathForId

Returns:
    content of file as byte array, will return null if the resource path is null or file could not be found or loaded

Since:
    2.2.4.0


loadBinaryFileFromResourceId

public static byte[] loadBinaryFileFromResourceId(String resourceId)

Loads a binary file

Parameters:

resourceId - The resource id as specified in the script description (nl2script) file

Returns:
    content of file as byte array, will return null if the resourceId is unknown or file could not be found or loaded

Since:
    2.2.4.0

Note: Deprecated  since 2.5.7.0 use loadBinaryFileFromResource instead


loadTextFile

public static String loadTextFile(String path)

Loads a text file in UTF8 encoding

Parameters:

path - path to file (relative to the classpath)

Returns:
    content of file as text, will return null if file could not be found or loaded

Since:
    2.2.4.0


loadTextFileFromResource

public static String loadTextFileFromResource(ResourcePath resourcePath)

Loads a text file in UTF8 encoding

Parameters:

resourcePath - A resource path that can be obtained from Script.getResourcePathForId

Returns:
    content of file as text, will return null if the resource path is null or file could not be found or loaded

Since:
    2.5.7.0


loadTextFileFromResourceId

public static String loadTextFileFromResourceId(String resourceId)

Loads a text file in UTF8 encoding

Parameters:

resourceId - The resource id as specified in the script description (nl2script) file

Returns:
    content of file as text, will return null if the resourceId is unknown or file could not be found or loaded

Since:
    2.2.4.0

Note: Deprecated  since 2.5.7.0 use loadTextFileFromResource instead


matrixToPitchHeadBankPos

public static void matrixToPitchHeadBankPos(nlvm.math3d.Matrix4x4f mIn, nlvm.math3d.Vector3f pitchHeadBankOut, nlvm.math3d.Vector3f posOut)

Computes a set of angles and a translation vector based on an input transformation matrix.

This is a helper method to convert between a transformation matrix returned by Train.getCarMatrix() and Train.getBogeyMatrix() and angles that are expected in SceneObject.setRotation().

Parameters:

mIn - Input matrix, must not be null
pitchHeadBankOut - Result vector with pitch, head, bank angles (radians), can be null if the angles are not requested.
posOut - Result vector with translation, can be null if the translation is not requested.

matrixToPitchHeadBankPosScale

public static void matrixToPitchHeadBankPosScale(nlvm.math3d.Matrix4x4f mIn, nlvm.math3d.Vector3f pitchHeadBankOut, nlvm.math3d.Vector3f posOut, nlvm.math3d.Vector3f scaleOut)

Computes a set of angles and a translation vector and a scale vector based on an input transformation matrix.

This is a helper method to convert between a transformation matrix returned by Train.getCarMatrix() and Train.getBogeyMatrix() and angles that are expected in SceneObject.setRotation().

Parameters:

mIn - Input matrix, must not be null
pitchHeadBankOut - Result vector with pitch, head, bank angles (radians), can be null if the angles are not requested.
posOut - Result vector with translation, can be null if the translation is not requested.
scaleOut - Result vector with scale, can be null if the scale is not requested.

perlinNoise

public static float perlinNoise(float x, float y, float z)

Perlin noise function (3D)

Perlin noise is a type of gradient noise by Ken Perlin.

Parameters:

x - 1st input parameter
y - 2nd input parameter
z - 3rd input parameter

Returns:
    gradient noise (-1 to +1) based on input parameters

Since:
    2.5.2.0


quinticRamp

public static double quinticRamp(double x)

Quintic ramp function

A smoothstep function that will compute 6*x^5 - 15*x^4 + 10*x^3

Parameters:

x - input value (will be clamped to the range 0..1)

Returns:
    output value (0..1)


switchRampC1

public static double switchRampC1(double T, double S, double ta, double t)

A special fade function with 3 phases (acceleration, constant speed, deceleration).

The fade function is C1 smooth (continuous speed) Within the acceleration and deceleration phase, the acceleration is constant. In the constant speed phase, the acceleration is zero.

Parameters:

T - Total time (must be > 0)
S - Total value (value at time=T)
ta - Time of acceleration and deceleration phases (must be > 0 and <= T/2)
t - Time (should be 0...T)

Returns:
    Value at time=t (will be between 0...S)


switchRampC2

public static double switchRampC2(double T, double S, double ta, double t)

A special fade function with 3 phases (acceleration, linear speed, deceleration).

The fade function is C2 smooth (continuous acceleration) Within the acceleration and deceleration phase, the acceleration represents a triangular wave. In the constant speed phase, the acceleration is zero.

Parameters:

T - Total time (must be > 0)
S - Total value (value at time=T)
ta - Time of acceleration and deceleration phases (must be > 0 and <= T/2)
t - Time (should be 0...T)

Returns:
    Value at time=t (will be between 0...S)