.. _stdlib_resource_core: ================ 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 :ref:`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 ++++++++++ .. _struct-mesh_structures-MeshGeometry: .. das:attribute:: MeshGeometry Represents a mesh geometry. :Fields: * **vertices** : array - The array of vertices positions in the mesh * **normals** : array - The array of vertices normals in the mesh, if empty, the normals will be computed automatically * **uv** : array - The array of vertices uv in the mesh * **triangles** : array - The array of triangles defining the triangles in the mesh +++++++++++++ Handled types +++++++++++++ .. _handle-public_resources-MeshId: .. das:attribute:: MeshId A mesh resource handle. .. _handle-public_resources-MaterialId: .. das:attribute:: MaterialId A material resource handle. .. _handle-public_resources-TextureId: .. das:attribute:: TextureId A texture resource handle. .. _handle-public_resources-SoundId: .. das:attribute:: SoundId A sound resource handle. .. _handle-public_resources-ModelId: .. das:attribute:: ModelId A model resource handle. .. _handle-public_resources-AnimationId: .. das:attribute:: AnimationId An animation resource handle. .. _handle-public_resources-SkeletonId: .. das:attribute:: SkeletonId A skeleton resource handle. .. _handle-public_resources-AnimationMaskId: .. das:attribute:: AnimationMaskId A mesh animation mask resource handle. .. _handle-public_resources-TextId: .. das:attribute:: TextId A text resource handle. .. _handle-public_resources-FontId: .. das:attribute:: FontId A font resource handle. .. _handle-public_resources-PrefabId: .. das:attribute:: PrefabId A prefab resource handle. .. _handle-public_resources-CollisionId: .. das:attribute:: CollisionId A mesh collision resource handle. +++++++++ Functions +++++++++ * :ref:`get_resource_name (resId: MeshId|MaterialId|TextureId|SoundId|ModelId|AnimationId|SkeletonId|TextId|FontId|PrefabId|CollisionId) : string ` * :ref:`get_text_asset (res_id: TextId; block: block\<(string#):void\>) : bool ` * :ref:`get_animation_duration (res_id: AnimationId; block: block\<(float):void\>) : bool ` * :ref:`create_animation_mask (reference_model: string implicit; mask_name: string implicit; default_mask_weight: float; mask_weight: float; mask_roots: array\) : AnimationMaskId ` * :ref:`MeshId () : MeshId ` * :ref:`valid (id: MeshId) : bool ` * :ref:`MaterialId () : MaterialId ` * :ref:`valid (id: MaterialId) : bool ` * :ref:`TextureId () : TextureId ` * :ref:`valid (id: TextureId) : bool ` * :ref:`SoundId () : SoundId ` * :ref:`valid (id: SoundId) : bool ` * :ref:`ModelId () : ModelId ` * :ref:`valid (id: ModelId) : bool ` * :ref:`AnimationId () : AnimationId ` * :ref:`valid (id: AnimationId) : bool ` * :ref:`SkeletonId () : SkeletonId ` * :ref:`valid (id: SkeletonId) : bool ` * :ref:`AnimationMaskId () : AnimationMaskId ` * :ref:`valid (id: AnimationMaskId) : bool ` * :ref:`TextId () : TextId ` * :ref:`valid (id: TextId) : bool ` * :ref:`FontId () : FontId ` * :ref:`valid (id: FontId) : bool ` * :ref:`PrefabId () : PrefabId ` * :ref:`valid (id: PrefabId) : bool ` * :ref:`CollisionId () : CollisionId ` * :ref:`valid (id: CollisionId) : bool ` * :ref:`generate_mesh (generator_path: string) : MeshId ` * :ref:`generate_mesh (generator_path: string; var properties: GenericStorage) : MeshId ` * :ref:`request_mesh_from_model (prefab_asset_path: string; mesh_name: string) : MeshId ` * :ref:`update_mesh (meshId: MeshId; mesh: MeshGeometry) : bool ` * :ref:`create_mesh (mesh: MeshGeometry) : MeshId ` * :ref:`request_collision_from_model (prefab_asset_path: string; mesh_name: string) : CollisionId ` * :ref:`create_mesh_collision_sync (triangles: array\; vertices: array\; build_convex_hull: bool = false) : CollisionId ` * :ref:`create_mesh_collision_async (triangles: array\; vertices: array\; build_convex_hull: bool = false) : CollisionId ` * :ref:`create_mesh_collision (triangles: array\; vertices: array\; build_convex_hull: bool = false) : CollisionId ` * :ref:`update_mesh_collision_sync (collisionId: CollisionId; triangles: array\; vertices: array\; build_convex_hull: bool = false) : bool ` * :ref:`update_mesh_collision_async (collisionId: CollisionId; triangles: array\; vertices: array\; build_convex_hull: bool = false) : bool ` * :ref:`update_mesh_collision (collisionId: CollisionId; triangles: array\; vertices: array\; build_convex_hull: bool = false) : bool ` * :ref:`create_mesh_collision (mesh: MeshGeometry; build_convex_hull: bool = false) : CollisionId ` * :ref:`update_mesh_collision (collisionId: CollisionId; mesh: MeshGeometry; build_convex_hull: bool = false) : bool ` * :ref:`create_heightmap_collision_sync (heigth_map: array\; width: uint; height: uint; cell_size: float) : CollisionId ` * :ref:`request_animation (path_to_asset: string; name_in_asset: string) : AnimationId ` * :ref:`get_model_animations (modelId: ModelId) : array\\> ` * :ref:`request_sound (path: string) : SoundId ` * :ref:`request_font (path: string) : FontId ` * :ref:`request_text (path: string) : TextId ` .. _function-resource_core_get_resource_name_MeshIdMaterialIdTextureIdSoundIdModelIdAnimationIdSkeletonIdTextIdFontIdPrefabIdCollisionId: .. das:function:: 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: * **resId** : option< :ref:`MeshId ` | :ref:`MaterialId ` | :ref:`TextureId ` | :ref:`SoundId ` | :ref:`ModelId ` | :ref:`AnimationId ` | :ref:`SkeletonId ` | :ref:`TextId ` | :ref:`FontId ` | :ref:`PrefabId ` | :ref:`CollisionId ` > - The resource id :Returns: * string - The name of the resource .. _function-public_resources_get_text_asset_TextId_block_ls_string_hh__c_void_gr_: .. das:function:: get_text_asset(res_id: TextId; block: block<(string#):void>) : bool Get a text asset by its id :Arguments: * **res_id** : :ref:`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 .. _function-public_resources_get_animation_duration_AnimationId_block_ls_float_c_void_gr_: .. das:function:: get_animation_duration(res_id: AnimationId; block: block<(float):void>) : bool Gets the duration of an `AnimationId` resource. :Arguments: * **res_id** : :ref:`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 .. _function-public_resources_create_animation_mask_string_implicit_string_implicit_float_float_array_ls_string_gr_: .. das:function:: create_animation_mask(reference_model: string implicit; mask_name: string implicit; default_mask_weight: float; mask_weight: float; mask_roots: array) : 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 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: * :ref:`AnimationMaskId ` - the AnimationMaskId object .. _function-public_resources_MeshId: .. das:function:: MeshId() : MeshId :Returns: * :ref:`MeshId ` - an empty `MeshId` object .. _function-public_resources_valid_MeshId: .. das:function:: valid(id: MeshId) : bool :Arguments: * **id** : :ref:`MeshId ` :Returns: * bool - whether the `MeshId` is valid .. _function-public_resources_MaterialId: .. das:function:: MaterialId() : MaterialId :Returns: * :ref:`MaterialId ` - an empty `MaterialId` object .. _function-public_resources_valid_MaterialId: .. das:function:: valid(id: MaterialId) : bool :Arguments: * **id** : :ref:`MaterialId ` :Returns: * bool - whether the `MaterialId` is valid .. _function-public_resources_TextureId: .. das:function:: TextureId() : TextureId :Returns: * :ref:`TextureId ` - an empty `TextureId` object .. _function-public_resources_valid_TextureId: .. das:function:: valid(id: TextureId) : bool :Arguments: * **id** : :ref:`TextureId ` :Returns: * bool - whether the `TextureId` is valid .. _function-public_resources_SoundId: .. das:function:: SoundId() : SoundId :Returns: * :ref:`SoundId ` - an empty `SoundId` object .. _function-public_resources_valid_SoundId: .. das:function:: valid(id: SoundId) : bool :Arguments: * **id** : :ref:`SoundId ` :Returns: * bool - whether the `SoundId` is valid .. _function-public_resources_ModelId: .. das:function:: ModelId() : ModelId :Returns: * :ref:`ModelId ` - an empty `ModelId` object .. _function-public_resources_valid_ModelId: .. das:function:: valid(id: ModelId) : bool :Arguments: * **id** : :ref:`ModelId ` :Returns: * bool - whether the `ModelId` is valid .. _function-public_resources_AnimationId: .. das:function:: AnimationId() : AnimationId :Returns: * :ref:`AnimationId ` - an empty `AnimationId` object .. _function-public_resources_valid_AnimationId: .. das:function:: valid(id: AnimationId) : bool :Arguments: * **id** : :ref:`AnimationId ` :Returns: * bool - whether the `AnimationId` is valid .. _function-public_resources_SkeletonId: .. das:function:: SkeletonId() : SkeletonId :Returns: * :ref:`SkeletonId ` - an empty `SkeletonId` object .. _function-public_resources_valid_SkeletonId: .. das:function:: valid(id: SkeletonId) : bool :Arguments: * **id** : :ref:`SkeletonId ` :Returns: * bool - whether the `SkeletonId` is valid .. _function-public_resources_AnimationMaskId: .. das:function:: AnimationMaskId() : AnimationMaskId :Returns: * :ref:`AnimationMaskId ` - an empty `AnimationMaskId` object .. _function-public_resources_valid_AnimationMaskId: .. das:function:: valid(id: AnimationMaskId) : bool :Arguments: * **id** : :ref:`AnimationMaskId ` :Returns: * bool - whether the `AnimationMaskId` is valid .. _function-public_resources_TextId: .. das:function:: TextId() : TextId :Returns: * :ref:`TextId ` - an empty `TextId` object .. _function-public_resources_valid_TextId: .. das:function:: valid(id: TextId) : bool :Arguments: * **id** : :ref:`TextId ` :Returns: * bool - whether the `TextId` is valid .. _function-public_resources_FontId: .. das:function:: FontId() : FontId :Returns: * :ref:`FontId ` - an empty `FontId` object .. _function-public_resources_valid_FontId: .. das:function:: valid(id: FontId) : bool :Arguments: * **id** : :ref:`FontId ` :Returns: * bool - whether the `FontId` is valid .. _function-public_resources_PrefabId: .. das:function:: PrefabId() : PrefabId :Returns: * :ref:`PrefabId ` - an empty `PrefabId` object .. _function-public_resources_valid_PrefabId: .. das:function:: valid(id: PrefabId) : bool :Arguments: * **id** : :ref:`PrefabId ` :Returns: * bool - whether the `PrefabId` is valid .. _function-public_resources_CollisionId: .. das:function:: CollisionId() : CollisionId :Returns: * :ref:`CollisionId ` - an empty `CollisionId` object .. _function-public_resources_valid_CollisionId: .. das:function:: valid(id: CollisionId) : bool :Arguments: * **id** : :ref:`CollisionId ` :Returns: * bool - whether the `CollisionId` is valid .. _function-mesh_resource_generate_mesh_string: .. das:function:: generate_mesh(generator_path: string) : MeshId Generates a mesh using the provided generator :Arguments: * **generator_path** : string .. _function-mesh_resource_generate_mesh_string_GenericStorage: .. das:function:: generate_mesh(generator_path: string; properties: GenericStorage) : MeshId Generates a mesh using the provided generator :Arguments: * **generator_path** : string * **properties** : :ref:`GenericStorage ` .. _function-mesh_resource_request_mesh_from_model_string_string: .. das:function:: 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: * :ref:`MeshId ` - the resource ID of the mesh Usage example:: let meshId = request_mesh_from_model("prefab.fbx", "Cube 0") .. _function-mesh_resource_update_mesh_MeshId_MeshGeometry: .. das:function:: 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** : :ref:`MeshId ` * **mesh** : :ref:`MeshGeometry ` .. _function-mesh_resource_create_mesh_MeshGeometry: .. das:function:: 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** : :ref:`MeshGeometry ` .. _function-collision_resource_request_collision_from_model_string_string: .. das:function:: 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: * :ref:`CollisionId ` - the resource ID of the mesh Usage example:: let meshId = request_collision_from_model("prefab.fbx", "Cube 0") .. _function-collision_resource_create_mesh_collision_sync_array_ls_uint3_gr__array_ls_float3_gr__bool: .. das:function:: create_mesh_collision_sync(triangles: array; vertices: array; 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 * **vertices** : array * **build_convex_hull** : bool .. _function-collision_resource_create_mesh_collision_async_array_ls_uint3_gr__array_ls_float3_gr__bool: .. das:function:: create_mesh_collision_async(triangles: array; vertices: array; 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 * **vertices** : array * **build_convex_hull** : bool .. _function-collision_resource_create_mesh_collision_array_ls_uint3_gr__array_ls_float3_gr__bool: .. das:function:: create_mesh_collision(triangles: array; vertices: array; 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 * **vertices** : array * **build_convex_hull** : bool .. _function-collision_resource_update_mesh_collision_sync_CollisionId_array_ls_uint3_gr__array_ls_float3_gr__bool: .. das:function:: update_mesh_collision_sync(collisionId: CollisionId; triangles: array; vertices: array; 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** : :ref:`CollisionId ` * **triangles** : array * **vertices** : array * **build_convex_hull** : bool .. _function-collision_resource_update_mesh_collision_async_CollisionId_array_ls_uint3_gr__array_ls_float3_gr__bool: .. das:function:: update_mesh_collision_async(collisionId: CollisionId; triangles: array; vertices: array; 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** : :ref:`CollisionId ` * **triangles** : array * **vertices** : array * **build_convex_hull** : bool .. _function-collision_resource_update_mesh_collision_CollisionId_array_ls_uint3_gr__array_ls_float3_gr__bool: .. das:function:: update_mesh_collision(collisionId: CollisionId; triangles: array; vertices: array; build_convex_hull: bool = false) : bool Update mesh collision from the provided vertices and triangles Alias for update_mesh_collision_sync :Arguments: * **collisionId** : :ref:`CollisionId ` * **triangles** : array * **vertices** : array * **build_convex_hull** : bool .. _function-collision_resource_create_mesh_collision_MeshGeometry_bool: .. das:function:: 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** : :ref:`MeshGeometry ` * **build_convex_hull** : bool .. _function-collision_resource_update_mesh_collision_CollisionId_MeshGeometry_bool: .. das:function:: 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** : :ref:`CollisionId ` * **mesh** : :ref:`MeshGeometry ` * **build_convex_hull** : bool .. _function-collision_resource_create_heightmap_collision_sync_array_ls_float_gr__uint_uint_float: .. das:function:: create_heightmap_collision_sync(heigth_map: array; 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 * **width** : uint * **height** : uint * **cell_size** : float .. _function-animation_resource_request_animation_string_string: .. das:function:: 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: * :ref:`AnimationId ` - the resource ID of the animation asset Usage example:: let animationId = request_animation("animation.fbx", "walk") .. _function-animation_resource_get_model_animations_ModelId: .. das:function:: get_model_animations(modelId: ModelId) : array> Returns the list of animations for the specified model. :Arguments: * **modelId** : :ref:`ModelId ` .. _function-audio_resource_request_sound_string: .. das:function:: 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 .. _function-font_resource_request_font_string: .. das:function:: 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: * :ref:`FontId ` - the resource ID of the font resource Usage example:: let fontId = request_font("Calibri.ttf") .. _function-text_resource_request_text_string: .. das:function:: 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: * :ref:`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) }