pxlUtils

pxlUtils

new pxlUtils(assetRootopt, mobileopt)

Description:
  • Utility class providing various helper functions for pxlNav.

Source:
Properties:
Name Type Description
curMS number

Read-Only; Current time in milliseconds since the last frame update.

Parameters:
Name Type Attributes Default Description
assetRoot string <optional>
"images/assets/"

Root path for assets.

mobile boolean <optional>

Whether running on a mobile device.

Methods

(static) Utils#applyTransformList(curObj, transList)

Description:
  • Apply a transformation list to an object (position, rotation, scale).

Source:
Parameters:
Name Type Description
curObj Object

The object to transform.

transList Object

Transformation list with keys "r", "t", "s", and optional "rOrder".

(static) Utils#arrayToStr(arr, precisionopt) → {Array.<string>}

Description:
  • Round each element of an array to a fixed precision and return as array of strings.

Source:
Parameters:
Name Type Attributes Default Description
arr Array.<number>

Array of numbers.

precision number <optional>
2

Number of decimal places.

Returns:

Array of rounded strings.

Type
Array.<string>

(static) Utils#checkInt(val) → {boolean}

Description:
  • Check if a value is an integer.

Source:
Parameters:
Name Type Description
val number

The value to check.

Returns:

True if integer, false otherwise.

Type
boolean

(static) Utils#cleanBasic(messageString) → {string}

Description:
  • Basic clean of a string, allowing some symbols.

Source:
Parameters:
Name Type Description
messageString string

String to clean.

Returns:

Cleaned string.

Type
string

(static) Utils#cleanStrict(messageString) → {string}

Description:
  • Strictly clean a string from HTML and non-alphanumeric characters.

Source:
Parameters:
Name Type Description
messageString string

String to clean.

Returns:

Cleaned string.

Type
string

(static) Utils#cleanString(messageString) → {string}

Description:
  • Remove HTML from a string.

Source:
Parameters:
Name Type Description
messageString string

String to clean.

Returns:

Cleaned string.

Type
string

(static) Utils#colorToLinear(color) → {Object}

Description:
  • Convert a color or Vector3 to linear color space.

Source:
Parameters:
Name Type Description
color Object

Color or Vector3 object.

Returns:

Converted color.

Type
Object

(static) Utils#colorTosRGB(color) → {Object}

Description:
  • Convert a color or Vector3 to sRGB color space.

Source:
Parameters:
Name Type Description
color Object

Color or Vector3 object.

Returns:

Converted color.

Type
Object

(static) Utils#componentToHex(c) → {string}

Description:
  • Convert a color component to hexadecimal string.

Source:
Parameters:
Name Type Description
c number

Color component (0-255).

Returns:

Hexadecimal string.

Type
string

(static) Utils#convertColor(color, spaceopt) → {Object}

Description:
  • Convert a color between color spaces.

Source:
Parameters:
Name Type Attributes Default Description
color Object

Color object.

space number <optional>
this.pxlEnums.COLOR_SHIFT.KEEP

Target color space.

Returns:

Converted color.

Type
Object

(static) Utils#copyRoomUrl() → {boolean|string}

Description:
  • Copy the current room URL to the clipboard.

Source:
Returns:

Status of the copy operation.

Type
boolean | string

(static) Utils#degToRad(deg) → {number}

Description:
  • Convert degrees to radians.

Source:
Parameters:
Name Type Description
deg number

Degrees.

Returns:

Radians.

Type
number

(static) Utils#dupeArray(val, count) → {Array}

Description:
  • Duplicate an array a specified number of times.

Source:
Example
// Duplicate an array
import { pxlNav } from 'pxlNav.js';
const pxlParticleBase = pxlNav.pxlEffects.pxlParticles.pxlParticle

build(){
 pxlParticleBase.dupeArray( [0.0,0.75], 4 );
 // Output: [0.0,0.75], [0.0,0.75], [0.0,0.75], [0.0,0.75]
}
Parameters:
Name Type Description
val Array

The array to duplicate.

count number

Number of times to duplicate.

Returns:

Duplicated array.

Type
Array

(static) Utils#flattenArrayToStr(arr, precisionopt, delimiteropt) → {string}

Description:
  • Flatten an array to a joined string with specified precision and delimiter.

Source:
Parameters:
Name Type Attributes Default Description
arr Array.<number>

Array of numbers.

precision number <optional>
2

Number of decimal places.

delimiter string <optional>
","

Delimiter for joining.

Returns:

Joined string.

Type
string

(static) Utils#gammaCorrectColor(color, gammaInopt, gammaOutopt) → {Object}

Description:
  • Apply gamma correction to a color or Vector3.

Source:
Parameters:
Name Type Attributes Default Description
color Object

Color or Vector3 object.

gammaIn number | string <optional>
"2.2"

Input gamma.

gammaOut number | string <optional>
"1.8"

Output gamma.

Returns:

Gamma-corrected color.

Type
Object

(static) Utils#gammaCorrection(channel, gammaInopt, gammaOutopt) → {number}

Description:
  • Apply gamma correction to a single channel.

Source:
Parameters:
Name Type Attributes Default Description
channel number

Channel value.

gammaIn number | string <optional>
"2.2"

Input gamma.

gammaOut number | string <optional>
"1.8"

Output gamma.

Returns:

Gamma-corrected channel.

Type
number

(static) Utils#getCanvasTexture(canvas) → {Object}

Description:
  • Create a CanvasTexture and MeshBasicMaterial from a canvas.

Source:
Parameters:
Name Type Description
canvas HTMLCanvasElement

Canvas element.

Returns:

Texture and material.

Type
Object

(static) Utils#getDateTime() → {Array.<string>}

Description:
  • Get the current date and time as an array.

Source:
Returns:

[date, time] in "YYYY-MM-DD" and "HH:MM:SS" format.

Type
Array.<string>

(static) Utils#getRandom(list, seedopt) → {*}

Description:
  • Get a random element from a list.

Source:
Parameters:
Name Type Attributes Default Description
list Array

List of elements.

seed number <optional>
1.14

Optional seed.

Returns:

Random element.

Type
*

(static) Utils#getVideoTexture(videoObject) → {VideoTexture}

Description:
  • Create a VideoTexture from a video element.

Source:
Parameters:
Name Type Description
videoObject HTMLVideoElement

Video element.

Returns:

Video texture.

Type
VideoTexture

(static) Utils#hexToRgb(hex) → {Array.<number>}

Description:
  • Convert a hex color string to RGB array.

Source:
Parameters:
Name Type Description
hex string

Hex color string.

Returns:

[r, g, b] array.

Type
Array.<number>

(static) Utils#loadTexture(imgPath, channelsopt, modsopt) → {Texture}

Description:
  • Load a texture from an image path.

Source:
Parameters:
Name Type Attributes Default Description
imgPath string

Image path.

channels number | null <optional>
null

Channel format index.

mods Object <optional>
{}

Texture modifications.

Returns:

Loaded texture.

Type
Texture

(static) Utils#randomFloat(min, max) → {number}

Description:
  • Generate a random float between min and max.

Source:
Parameters:
Name Type Description
min number

Minimum value.

max number

Maximum value.

Returns:

Random float.

Type
number

(static) Utils#randomizeArray(inputArr) → {Array}

Description:
  • Randomize the order of elements in an array.

Source:
Parameters:
Name Type Description
inputArr Array

Input array.

Returns:

Randomized array.

Type
Array

(static) Utils#rgbToHex(r, g, b) → {string}

Description:
  • Convert RGB values to a hexadecimal color string.

Source:
Parameters:
Name Type Description
r number

Red (0-255).

g number

Green (0-255).

b number

Blue (0-255).

Returns:

Hex color string.

Type
string

(static) Utils#screenToNDC(x, y, width, height) → {Vector2}

Description:
  • Convert screen coordinates to normalized device coordinates (NDC).

Source:
Parameters:
Name Type Description
x number

X coordinate.

y number

Y coordinate.

width number

Screen width.

height number

Screen height.

Returns:

NDC coordinates.

Type
Vector2

(static) Utils#stringToRgb(string, boostopt, zoFitopt) → {Array.<number>}

Description:
  • Generate an RGB color from a string.

Source:
Parameters:
Name Type Attributes Default Description
string string

Input string.

boost number | null <optional>
null

Optional boost factor.

zoFit boolean <optional>
false

If true, normalize to [0,1].

Returns:

RGB array.

Type
Array.<number>

(static) Utils#toHundreths(val) → {number}

Description:
  • Round a number to the nearest hundredths (2 decimal places).

Source:
Parameters:
Name Type Description
val number

Value to round.

Returns:

Rounded value.

Type
number

(static) Utils#toLinear(val) → {number}

Description:
  • Convert an sRGB value to linear.

Source:
Parameters:
Name Type Description
val number

sRGB value.

Returns:

Linear value.

Type
number

(static) Utils#toNearestStr(val, precisionopt) → {string}

Description:
  • Round a value to a fixed precision and return as string.

Source:
Parameters:
Name Type Attributes Default Description
val number

Value to round.

precision number <optional>
2

Number of decimal places.

Returns:

Rounded value as string.

Type
string

(static) Utils#toTenths(val) → {number}

Description:
  • Round a number to the nearest tenths (1 decimal place).

Source:
Parameters:
Name Type Description
val number

Value to round.

Returns:

Rounded value.

Type
number

(static) Utils#tosRGB(val) → {number}

Description:
  • Convert a linear value to sRGB.

Source:
Parameters:
Name Type Description
val number

Linear value.

Returns:

sRGB value.

Type
number

(static) Utils#updateUrl(url, stateopt, titleopt)

Description:
  • Update the browser URL using history API.

Source:
Parameters:
Name Type Attributes Default Description
url string

The new URL.

state Object <optional>
{}

State object for history.

title string <optional>
""

Title for the history entry.