Resources module

This module contains functions for requesting various resources and retrieving their content. Resources can be requested by their path, GUID (for meshes), or ID (for textures). See Fonts Assets Import to learn how to import font assets into your project. To use this module, include the following line in your project file:

require engine.resource_core // or require engine.core

Structures

MeshGeometry

Represents a mesh geometry.

Fields:
  • vertices : array<float3> - The array of vertices positions in the mesh

  • normals : array<float3> - The array of vertices normals in the mesh, if empty, the normals will be computed automatically

  • uv : array<float2> - The array of vertices uv in the mesh

  • triangles : array<uint3> - The array of triangles defining the triangles in the mesh

Handled types

MeshId

A mesh resource handle.

MaterialId

A material resource handle.

TextureId

A texture resource handle.

SoundId

A sound resource handle.

ModelId

A model resource handle.

AnimationId

An animation resource handle.

SkeletonId

A skeleton resource handle.

AnimationMaskId

A mesh animation mask resource handle.

TextId

A text resource handle.

FontId

A font resource handle.

PrefabId

A prefab resource handle.

CollisionId

A mesh collision resource handle.

Functions

get_resource_name(resId: MeshId|MaterialId|TextureId|SoundId|ModelId|AnimationId|SkeletonId|TextId|FontId|PrefabId|CollisionId): string

Get the name of the resource. Returns an empty string if the resource is not found or is not loaded.

Arguments:
Returns:
  • string - The name of the resource

get_text_asset(res_id: TextId; block: block<(string#):void>): bool

Get a text asset by its id

Arguments:
  • res_id : TextId - the id of the text asset

  • block : block<(string#):void> implicit - the block to call for the text asset, it receives the content of the text asset as a string

Returns:
  • bool - true if the text asset was found, false otherwise

get_animation_duration(res_id: AnimationId; block: block<(float):void>): bool

Gets the duration of an AnimationId resource.

Arguments:
  • res_id : AnimationId - the id of the animation resource

  • block : block<(float):void> implicit - the block to call for the found duration of an animation

Returns:
  • bool - true if the animation asset was found, false otherwise

create_animation_mask(reference_model: string implicit; mask_name: string implicit; default_mask_weight: float; mask_weight: float; mask_roots: array<string>): AnimationMaskId
Arguments:
  • reference_model : string implicit - path to the model with reference skeleton

  • mask_name : string implicit - name of the mask, used only in debug purposes

  • default_mask_weight : float - default weight of the mask. This value assigned to all bones in the mask during initialization

  • mask_weight : float - weight of the mask for nodes that contain in the mask.

  • mask_roots : array<string> implicit - array of root bones for the mask. All nodes that are children of the root bones will be included in the mask and have mask_weight weight

Returns:
MeshId(): MeshId
Returns:
  • MeshId - an empty MeshId object

valid(id: MeshId): bool
Arguments:
Returns:
  • bool - whether the MeshId is valid

MaterialId(): MaterialId
Returns:
valid(id: MaterialId): bool
Arguments:
Returns:
  • bool - whether the MaterialId is valid

TextureId(): TextureId
Returns:
valid(id: TextureId): bool
Arguments:
Returns:
  • bool - whether the TextureId is valid

SoundId(): SoundId
Returns:
  • SoundId - an empty SoundId object

valid(id: SoundId): bool
Arguments:
Returns:
  • bool - whether the SoundId is valid

ModelId(): ModelId
Returns:
  • ModelId - an empty ModelId object

valid(id: ModelId): bool
Arguments:
Returns:
  • bool - whether the ModelId is valid

AnimationId(): AnimationId
Returns:
valid(id: AnimationId): bool
Arguments:
Returns:
  • bool - whether the AnimationId is valid

SkeletonId(): SkeletonId
Returns:
valid(id: SkeletonId): bool
Arguments:
Returns:
  • bool - whether the SkeletonId is valid

AnimationMaskId(): AnimationMaskId
Returns:
valid(id: AnimationMaskId): bool
Arguments:
Returns:
  • bool - whether the AnimationMaskId is valid

TextId(): TextId
Returns:
  • TextId - an empty TextId object

valid(id: TextId): bool
Arguments:
Returns:
  • bool - whether the TextId is valid

FontId(): FontId
Returns:
  • FontId - an empty FontId object

valid(id: FontId): bool
Arguments:
Returns:
  • bool - whether the FontId is valid

PrefabId(): PrefabId
Returns:
valid(id: PrefabId): bool
Arguments:
Returns:
  • bool - whether the PrefabId is valid

CollisionId(): CollisionId
Returns:
valid(id: CollisionId): bool
Arguments:
Returns:
  • bool - whether the CollisionId is valid

generate_mesh(generator_path: string): MeshId

Generates a mesh using the provided generator

Arguments:
  • generator_path : string

generate_mesh(generator_path: string; properties: GenericStorage): MeshId

Generates a mesh using the provided generator

Arguments:
request_mesh_from_model(prefab_asset_path: string; mesh_name: string): MeshId

Requests a mesh from a prefab with given name and returns the corresponding resource ID.

Arguments:
  • prefab_asset_path : string - the path to the prefab asset

  • mesh_name : string - the name of the mesh in the prefab

Returns:
  • MeshId - the resource ID of the mesh

Usage example:

let meshId = request_mesh_from_model("prefab.fbx", "Cube 0")
update_mesh(meshId: MeshId; mesh: MeshGeometry): bool

Updates the mesh with the provided vertices and triangles If mesh.normals if empty the smooth-normals will be computed automatically. No need to compute them manually If mesh.uv is empty the uv will set to (0, 0)

Arguments:
create_mesh(mesh: MeshGeometry): MeshId

Creates a mesh from the provided vertices and triangles If mesh.normals if empty the smooth-normals will be computed automatically. No need to compute them manually If mesh.uv is empty the uv will set to (0, 0)

Arguments:
request_collision_from_model(prefab_asset_path: string; mesh_name: string): CollisionId

Requests a mesh from a prefab with given name and returns the corresponding resource ID.

Arguments:
  • prefab_asset_path : string - the path to the prefab asset

  • mesh_name : string - the name of the mesh in the prefab

Returns:

Usage example:

let meshId = request_collision_from_model("prefab.fbx", "Cube 0")
create_mesh_collision_sync(triangles: array<uint3>; vertices: array<float3>; build_convex_hull: bool = false): CollisionId

Creates a mesh collision from the provided vertices and triangles This function is synchronous and will block until the collision is created

Arguments:
  • triangles : array<uint3>

  • vertices : array<float3>

  • build_convex_hull : bool

create_mesh_collision_async(triangles: array<uint3>; vertices: array<float3>; build_convex_hull: bool = false): CollisionId

Creates a mesh collision from the provided vertices and triangles This function is asynchronous and will create the collision in the background

Arguments:
  • triangles : array<uint3>

  • vertices : array<float3>

  • build_convex_hull : bool

create_mesh_collision(triangles: array<uint3>; vertices: array<float3>; build_convex_hull: bool = false): CollisionId

Creates a mesh collision from the provided vertices and triangles Alias for create_mesh_collision_sync

Arguments:
  • triangles : array<uint3>

  • vertices : array<float3>

  • build_convex_hull : bool

update_mesh_collision_sync(collisionId: CollisionId; triangles: array<uint3>; vertices: array<float3>; build_convex_hull: bool = false): bool

Update mesh collision from the provided vertices and triangles This function is synchronous and will block until the collision is updated

Arguments:
  • collisionId : CollisionId

  • triangles : array<uint3>

  • vertices : array<float3>

  • build_convex_hull : bool

update_mesh_collision_async(collisionId: CollisionId; triangles: array<uint3>; vertices: array<float3>; build_convex_hull: bool = false): bool

Update mesh collision from the provided vertices and triangles This function is asynchronous and will update the collision in the background

Arguments:
  • collisionId : CollisionId

  • triangles : array<uint3>

  • vertices : array<float3>

  • build_convex_hull : bool

update_mesh_collision(collisionId: CollisionId; triangles: array<uint3>; vertices: array<float3>; build_convex_hull: bool = false): bool

Update mesh collision from the provided vertices and triangles Alias for update_mesh_collision_sync

Arguments:
  • collisionId : CollisionId

  • triangles : array<uint3>

  • vertices : array<float3>

  • build_convex_hull : bool

create_mesh_collision(mesh: MeshGeometry; build_convex_hull: bool = false): CollisionId

Creates a mesh collision from the provided MeshGeometry Alias for create_mesh_collision_sync

Arguments:
update_mesh_collision(collisionId: CollisionId; mesh: MeshGeometry; build_convex_hull: bool = false): bool

Update mesh collision from the provided MeshGeometry Alias for update_mesh_collision_sync

Arguments:
create_heightmap_collision_sync(heigth_map: array<float>; width: uint; height: uint; cell_size: float): CollisionId

Creates a collider from the provided heightmap heigth_map should be a width * height array of floats filled by rows width and height are the dimensions of the heightmap, and should be powers of 2 and equal to each other cell_size is the size of a single cell in the heightmap This function is synchronous and will block until the collision is created

Arguments:
  • heigth_map : array<float>

  • width : uint

  • height : uint

  • cell_size : float

request_animation(path_to_asset: string; name_in_asset: string): AnimationId

Requests an animation asset by the path to it and the name within the asset, and returns the corresponding resource ID.

Arguments:
  • path_to_asset : string - the path to the animation asset

  • name_in_asset : string - the name of the animation within the asset

Returns:

Usage example:

let animationId = request_animation("animation.fbx", "walk")
get_model_animations(modelId: ModelId): array<tuple<animationId:AnimationId;name:string>>

Returns the list of animations for the specified model.

Arguments:
request_sound(path: string): SoundId

Request sound resource located in the ‘path’ multiple request calls with same path and other properties will return same SoundId will create runtime asset which will dissapear in end of session

Arguments:
  • path : string

request_font(path: string): FontId

Requests a font resource by the path to it and returns the corresponding resource ID.

Arguments:
  • path : string - the path to the font file

Returns:
  • FontId - the resource ID of the font resource

Usage example:

let fontId = request_font("Calibri.ttf")
request_text(path: string): TextId

Requests a text file resource by the path to it and returns the corresponding resource ID. This call is synchronous and will block the script until the text file is loaded.

Arguments:
  • path : string - the path to the text file

Returns:
  • TextId - the resource ID of the text file resource

Usage example:

let textId = request_text("text.txt")
let exists = get_text_asset(resId) $(content : string#) {
     print(content)
}