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¶
- FontId¶
A font resource handle.
- AnimationId¶
An animation resource handle.
- SkeletonId¶
A skeleton resource handle.
- TextId¶
A text resource handle.
- SoundId¶
A sound resource handle.
- PrefabId¶
A prefab resource handle.
- TextureId¶
A texture resource handle.
- ModelId¶
A model resource handle.
- MeshId¶
A mesh resource handle.
- CollisionId¶
A mesh collision resource handle.
- MaterialId¶
A material resource handle.
- AnimationMaskId¶
A mesh animation mask resource handle.
- ShaderId¶
A shader resource handle.
Functions¶
create_mesh_collision (mesh: MeshGeometry; build_convex_hull: bool = false) : CollisionId
generate_mesh (generator_path: string; var properties: GenericStorage) : MeshId
get_animation_duration (res_id: AnimationId; block: block<(float):void>) : bool
get_model_animations (modelId: ModelId) : array<tuple<animationId:AnimationId;name:string>>
get_text_asset (res_id: TextId; block: block<(string#):void>) : bool
request_animation (path_to_asset: string; name_in_asset: string) : AnimationId
request_collision_from_model (prefab_asset_path: string; mesh_name: string) : CollisionId
request_mesh_from_model (prefab_asset_path: string; mesh_name: string) : MeshId
- AnimationId(): AnimationId
- Returns:
AnimationId - an empty AnimationId object
- AnimationMaskId(): AnimationMaskId
- Returns:
AnimationMaskId - an empty AnimationMaskId object
- CollisionId(): CollisionId
- Returns:
CollisionId - an empty CollisionId object
- FontId(): FontId
- Returns:
FontId - an empty FontId object
- MaterialId(): MaterialId
- Returns:
MaterialId - an empty MaterialId object
- MeshId(): MeshId
- Returns:
MeshId - an empty MeshId object
- ModelId(): ModelId
- Returns:
ModelId - an empty ModelId object
- PrefabId(): PrefabId
- Returns:
PrefabId - an empty PrefabId object
- ShaderId(): ShaderId
- Returns:
ShaderId - an empty ShaderId object
- SkeletonId(): SkeletonId
- Returns:
SkeletonId - an empty SkeletonId object
- SoundId(): SoundId
- Returns:
SoundId - an empty SoundId object
- TextId(): TextId
- Returns:
TextId - an empty TextId object
- TextureId(): TextureId
- Returns:
TextureId - an empty TextureId object
- create_animation_mask(reference_model: string; mask_name: string; 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_weightweight
- Returns:
AnimationMaskId - the AnimationMaskId object
- create_heightmap_collision_sync(height_map: array<float>; width: uint; height: uint; cell_size: float): CollisionId¶
Creates a collider from the provided heightmap height_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:
height_map : array<float>
width : uint
height : uint
cell_size : float
- 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:
mesh : MeshGeometry
- 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:
mesh : MeshGeometry
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
- 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_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
- 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:
generator_path : string
properties : GenericStorage
- 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
- get_model_animations(modelId: ModelId): array<tuple<animationId:AnimationId;name:string>>¶
Returns the list of animations for the specified model.
- Arguments:
modelId : ModelId
- get_resource_name(resId: MeshId|MaterialId|TextureId|SoundId|ModelId|AnimationId|SkeletonId|TextId|FontId|PrefabId|CollisionId|ShaderId|AnimationMaskId): string¶
Get the name of the resource. Returns an empty string if the resource is not found or is not loaded.
- Arguments:
resId : option< MeshId| MaterialId| TextureId| SoundId| ModelId| AnimationId| SkeletonId| TextId| FontId| PrefabId| CollisionId| ShaderId| AnimationMaskId> - The resource id
- 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
- is_resource_alive(resId: MeshId|MaterialId|TextureId|SoundId|ModelId|AnimationId|SkeletonId|TextId|FontId|PrefabId|CollisionId|ShaderId|AnimationMaskId): bool¶
Check if the resource is alive. It could be destroyed after asset removing or because of work of resource garbage collector (in normal case resource should be alive).
- Arguments:
resId : option< MeshId| MaterialId| TextureId| SoundId| ModelId| AnimationId| SkeletonId| TextId| FontId| PrefabId| CollisionId| ShaderId| AnimationMaskId> - The resource id
- Returns:
bool - True if the resource is alive, false otherwise
- 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:
AnimationId - the resource ID of the animation asset
Usage example:
let animationId = request_animation("animation.fbx", "walk")
- 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:
CollisionId - the resource ID of the mesh
Usage example:
let meshId = request_collision_from_model("prefab.fbx", "Cube 0")
- 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_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")
- request_shader(path: string): ShaderId¶
Request shader resource located in the ‘path’ Shader could be created in shader graph editor multiple request calls with same path and other properties will return same ShaderId will create runtime asset which will dissapear in end of session
- Arguments:
path : string
- 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_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)
}
- 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:
meshId : MeshId
mesh : MeshGeometry
- 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:
collisionId : CollisionId
mesh : MeshGeometry
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
- 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_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
- valid(resId: MeshId|MaterialId|TextureId|SoundId|ModelId|AnimationId|SkeletonId|TextId|FontId|PrefabId|CollisionId|ShaderId|AnimationMaskId): bool¶
Check if the resource id is valid (not null). It does not mean that the resource is alive. It’s equal to resId != {Resource}Id() or !!resId
- Arguments:
resId : option< MeshId| MaterialId| TextureId| SoundId| ModelId| AnimationId| SkeletonId| TextId| FontId| PrefabId| CollisionId| ShaderId| AnimationMaskId> - The resource id
- Returns:
bool - True if the resource id is valid, false otherwise