Table of Contents

Class Utils

Namespace
LibGFX.Core
Assembly
LibGFX.dll

Utility class for various helper functions

public class Utils
Inheritance
Utils
Inherited Members

Methods

ApplyScale(Matrix4x4, Vector3)

Applies a scale to the given transform matrix for the phyiscs. You should not use this method outside of compound shapes. On single shapes, the scale is applied directly to the shape. This funtion is used to apply the correct non uniform scale to the transform matrix.

public static Matrix4x4 ApplyScale(Matrix4x4 transform, Vector3 scale)

Parameters

transform Matrix4x4
scale Vector3

Returns

Matrix4x4

ByteBGRAToBitmap(byte[], int, int)

Creates a new Bitmap from a byte array containing pixel data in BGRA format with 32 bits per pixel.

public static Bitmap ByteBGRAToBitmap(byte[] pixels, int width, int height)

Parameters

pixels byte[]

An array of bytes representing the pixel data in BGRA order. The array length must be at least width × height × 4.

width int

The width, in pixels, of the resulting bitmap. Must be greater than 0.

height int

The height, in pixels, of the resulting bitmap. Must be greater than 0.

Returns

Bitmap

A Bitmap object containing the image represented by the specified BGRA pixel data.

Remarks

The resulting bitmap is vertically flipped to match the coordinate origin used by OpenGL, where the origin is at the bottom-left corner. The input pixel data must be in row-major order, with each pixel represented by four bytes (blue, green, red, alpha).

CalculatePitch(Vector3, Vector3)

Calculates the pitch angle from point1 to point2.

public static float CalculatePitch(Vector3 point1, Vector3 point2)

Parameters

point1 Vector3

The starting point.

point2 Vector3

The target point.

Returns

float

The pitch angle in degrees.

CalculateYaw(Vector3, Vector3)

public static float CalculateYaw(Vector3 point1, Vector3 point2)

Parameters

point1 Vector3
point2 Vector3

Returns

float

CreateDefaultAssetManager()

Creates a new instance of the default asset manager configured with loaders for common asset types.

public static AssetManager CreateDefaultAssetManager()

Returns

AssetManager

An AssetManager instance pre-registered with loaders for textures, audio clips, materials, cubemaps, sprite materials, skinned mesh models, and static mesh models.

Remarks

Use this method to obtain an asset manager that is ready to load standard asset types without additional configuration. Custom loaders can be registered with the returned manager if needed.

CreateEmptyNormalMap(int, int)

Creates an empty normal map with the given width and height.

public static Bitmap CreateEmptyNormalMap(int width, int height)

Parameters

width int
height int

Returns

Bitmap

CreateImageData(int, int, Vector4i)

Creates image data (byte array) filled with the given color in RGBA format.

public static byte[] CreateImageData(int width, int height, Vector4i color)

Parameters

width int
height int
color Vector4i

Returns

byte[]

DeserializeAABB(JObject)

public static AABB DeserializeAABB(JObject value)

Parameters

value JObject

Returns

AABB

DeserializeGameElement(JObject, SerializationContext)

public static GameElement DeserializeGameElement(JObject obj, SerializationContext serializationContext)

Parameters

obj JObject
serializationContext SerializationContext

Returns

GameElement

DeserializeMatrix4(JObject)

public static Matrix4 DeserializeMatrix4(JObject reader)

Parameters

reader JObject

Returns

Matrix4

DeserializeQuat(JObject)

public static Quaternion DeserializeQuat(JObject value)

Parameters

value JObject

Returns

Quaternion

DeserializeVec2(JObject)

public static Vector2 DeserializeVec2(JObject value)

Parameters

value JObject

Returns

Vector2

DeserializeVec2i(JObject)

public static Vector2i DeserializeVec2i(JObject value)

Parameters

value JObject

Returns

Vector2i

DeserializeVec3(JObject)

public static Vector3 DeserializeVec3(JObject value)

Parameters

value JObject

Returns

Vector3

DeserializeVec3i(JObject)

public static Vector3i DeserializeVec3i(JObject value)

Parameters

value JObject

Returns

Vector3i

DeserializeVec4(JObject)

public static Vector4 DeserializeVec4(JObject value)

Parameters

value JObject

Returns

Vector4

DeserializeVec4i(JObject)

public static Vector4i DeserializeVec4i(JObject value)

Parameters

value JObject

Returns

Vector4i

DeserializeVertex(JObject)

Deserializes a vertex from the specified JSON object.

public static Vertex DeserializeVertex(JObject value)

Parameters

value JObject

A Newtonsoft.Json.Linq.JObject containing the serialized vertex data. Must not be null and must include the required fields.

Returns

Vertex

A Vertex instance populated with data from the JSON object.

Remarks

The JSON object is expected to contain the fields "TexCoord", "Normal", "Tangent", "BoneIDs", and "BoneWeights" as nested objects. Missing or incorrectly typed fields may result in exceptions.

FindNodeByNameRecursive(SceneNodeData, string, out SceneNodeData)

Recursively searches the scene graph starting from the specified node for a node with the given name.

public static bool FindNodeByNameRecursive(SceneNodeData currentNode, string name, out SceneNodeData foundNode)

Parameters

currentNode SceneNodeData

The node from which to begin the search. This node and its descendants will be examined.

name string

The name of the node to search for. The comparison is case-sensitive.

foundNode SceneNodeData

When this method returns, contains the first node with the specified name if found; otherwise, a default value.

Returns

bool

true if a node with the specified name is found; otherwise, false.

Remarks

The search is performed in a depth-first manner. Only the first matching node encountered will be returned in foundNode.

GetBestDepthStencilFormat(bool, bool)

Selects the most appropriate depth and/or stencil renderbuffer storage format based on the specified requirements.

public static RenderFlags.GFXRenderbufferStorage GetBestDepthStencilFormat(bool depth, bool stencil)

Parameters

depth bool

true to request a format that supports depth buffering; otherwise, false.

stencil bool

true to request a format that supports stencil buffering; otherwise, false.

Returns

RenderFlags.GFXRenderbufferStorage

A GFXRenderbufferStorage value representing the best matching format for the requested depth and stencil support.

Exceptions

ArgumentException

Thrown if both depth and stencil are false, as at least one must be requested.

GetBtTransform(GameElement, Vector3)

Gets the bullet transform matrix for the given element.

public static Matrix4x4 GetBtTransform(GameElement element, Vector3 offsetLocation = default)

Parameters

element GameElement
offsetLocation Vector3

Returns

Matrix4x4

GetBtTransform(Vector3, Quaternion, Vector3)

Gets the bullet transform matrix for the given location and rotation.

public static Matrix4x4 GetBtTransform(Vector3 location, Quaternion rotation, Vector3 offsetLocation = default)

Parameters

location Vector3
rotation Quaternion
offsetLocation Vector3

Returns

Matrix4x4

GetCurrentTimeMillis()

Gets the current time in milliseconds since the Unix epoch.

public static long GetCurrentTimeMillis()

Returns

long

GetUVTransformFromTilemap(int, int, int, int, int, int)

public static Vector4 GetUVTransformFromTilemap(int width, int height, int cellWidth, int cellHeight, int tileX, int tileY)

Parameters

width int
height int
cellWidth int
cellHeight int
tileX int
tileY int

Returns

Vector4

LoadTextureIfExists(JObject, string, string)

public static Texture LoadTextureIfExists(JObject jsonObject, string propertyName, string basePath)

Parameters

jsonObject JObject
propertyName string
basePath string

Returns

Texture

LocalToWorldPositon(Transform, Vector3)

Converts a local position to a world position using the given transform.

public static Vector3 LocalToWorldPositon(Transform transform, Vector3 localPosition)

Parameters

transform Transform
localPosition Vector3

Returns

Vector3

LookAt(Vector3, Vector3)

public static Quaternion LookAt(Vector3 campos, Vector3 targetpos)

Parameters

campos Vector3
targetpos Vector3

Returns

Quaternion

ParseFloat(string)

public static float ParseFloat(string value)

Parameters

value string

Returns

float

ReadFloat(JsonReader)

public static float ReadFloat(JsonReader reader)

Parameters

reader JsonReader

Returns

float

SerializeAABB(AABB, JsonWriter)

public static void SerializeAABB(AABB aabb, JsonWriter writer)

Parameters

aabb AABB
writer JsonWriter

SerializeMatrix4(Matrix4, JsonWriter)

public static void SerializeMatrix4(Matrix4 mat, JsonWriter writer)

Parameters

mat Matrix4
writer JsonWriter

SerializeQuat(Quaternion, JsonWriter)

public static void SerializeQuat(Quaternion quat, JsonWriter writer)

Parameters

quat Quaternion
writer JsonWriter

SerializeVec2(Vector2, JsonWriter)

public static void SerializeVec2(Vector2 vec, JsonWriter writer)

Parameters

vec Vector2
writer JsonWriter

SerializeVec2i(Vector2i, JsonWriter)

public static void SerializeVec2i(Vector2i vec, JsonWriter writer)

Parameters

vec Vector2i
writer JsonWriter

SerializeVec3(Vector3, JsonWriter)

public static void SerializeVec3(Vector3 vec, JsonWriter writer)

Parameters

vec Vector3
writer JsonWriter

SerializeVec3i(Vector3i, JsonWriter)

public static void SerializeVec3i(Vector3i vec, JsonWriter writer)

Parameters

vec Vector3i
writer JsonWriter

SerializeVec4(Vector4, JsonWriter)

public static void SerializeVec4(Vector4 vec, JsonWriter writer)

Parameters

vec Vector4
writer JsonWriter

SerializeVec4i(Vector4i, JsonWriter)

public static void SerializeVec4i(Vector4i vec, JsonWriter writer)

Parameters

vec Vector4i
writer JsonWriter

SerializeVertex(Vertex, JsonWriter)

Serializes the specified vertex to JSON using the provided writer.

public static void SerializeVertex(Vertex vertex, JsonWriter writer)

Parameters

vertex Vertex

The vertex to serialize. Must not be null.

writer JsonWriter

The JsonWriter instance used to write the serialized JSON output. Must not be null.

ToRadians(Vector3)

Converts a Vector3 to radians.

public static Vector3 ToRadians(Vector3 input)

Parameters

input Vector3

Returns

Vector3

WorldToLocalPosition(Transform, Vector3)

Converts a world position to a local position using the given transform.

public static Vector3 WorldToLocalPosition(Transform transform, Vector3 worldPosition)

Parameters

transform Transform
worldPosition Vector3

Returns

Vector3