Struct Assets

Source
pub struct Assets;
Expand description

If you want to manage loading assets, this is the class for you! https://stereokit.net/Pages/StereoKit/Assets.html

§Examples

use stereokit_rust::{maths::Matrix, system::{Assets, AssetType, Asset, Pivot},
                     sprite::Sprite};

let my_sprite = Sprite::from_file("textures/open_gltf.jpeg", None, None)
                  .expect("open_gltf.jpeg should be able to create sprite");

for asset in Assets::all().filter(|s| !s.to_string().contains(" default/")) {
    if let Asset::Sprite(sprite) = asset {
        if !sprite.get_id().starts_with("sk/ui/") {
            assert_eq!(sprite, my_sprite);
        }
    }
}

for asset in Assets::all_of_type(AssetType::Sprite) {
    if let Asset::Sprite(sprite) = asset {
        if !sprite.get_id().starts_with("sk/ui/") {
            assert_eq!(sprite, my_sprite);
        }
    } else {
        panic!("asset should be a sprite");
    }
}

filename_scr = "screenshots/assets.jpeg"; fov_scr= 55.0;
test_screenshot!( // !!!! Get a proper main loop !!!!
    my_sprite.draw(token, Matrix::Y_180, Pivot::Center, None);
);
screenshot

Implementations§

Source§

impl Assets

Source

pub const MODEL_FORMATS: [&'static str; 5]

A list of supported model format extensions. This pairs pretty well with Platform::file_picker when attempting to load a Model! https://stereokit.net/Pages/StereoKit/Assets/ModelFormats.html

Source

pub const TEXTURE_FORMATS: [&'static str; 11]

A list of supported texture format extensions. This pairs pretty well with Platform::file_picker when attempting to load a Tex! https://stereokit.net/Pages/StereoKit/Assets/TextureFormats.html

Source

pub const SOUND_FORMATS: [&'static str; 2]

supported sound format by asset Sound https://stereokit.net/Pages/StereoKit/Sound.html

Source

pub fn all() -> AssetIter

This is an iterator upon all assets loaded by StereoKit at the current moment. https://stereokit.net/Pages/StereoKit/Assets/All.html

see also AssetIter Asset

§Examples
use stereokit_rust::{maths::Matrix,  system::{Assets, AssetType, Asset},
                     sprite::Sprite};

let my_sprite = Sprite::from_file("textures/open_gltf.jpeg", None, None)
                  .expect("open_gltf.jpeg should be able to create sprite");

let all = Assets::all();

let mut sprite_count = 0    ; let mut texture_count = 0;
let mut model_count = 0     ; let mut sound_count = 0;
let mut material_count = 0  ; let mut shader_count = 0;
let mut font_count = 0      ; let mut other_count = 0;
let mut mesh_count = 0      ; let mut render_list_count = 0;
for asset in all {
    match asset {
        Asset::Sprite(sprite) => sprite_count += 1,
        Asset::Model(model) => model_count +=1,
        Asset::Sound(sound) => sound_count +=1,
        Asset::Tex(texture) => texture_count +=1,
        Asset::Material(material) => material_count +=1,
        Asset::Font(font) => font_count +=1,
        Asset::Mesh(mesh) => mesh_count +=1,
        Asset::Shader(shader) => shader_count +=1,
        Asset::RenderList(render_list) => render_list_count +=1,
    _  => other_count +=1,  

    }
}
assert_eq!(sprite_count,    13 + 1 );
assert_eq!(texture_count,   23 + 1 );
assert_eq!(model_count,     2);
assert_eq!(sound_count,     5);
assert_eq!(material_count,  37 + 1 );
assert_eq!(shader_count,    15);
assert_eq!(font_count,      1);
assert_eq!(mesh_count,  26);
assert_eq!(render_list_count, 1);
assert_eq!(other_count, 0);
Source

pub fn all_of_type(asset_type: AssetType) -> AssetIter

This is an iterator upon all assets matching the specified type. https://stereokit.net/Pages/StereoKit/Assets/Type.html

  • asset_type - Any IAsset type

see also AssetIter Asset IAsset

§Examples
use stereokit_rust::{system::{Assets, AssetType, Asset},
                     sprite::Sprite};

let my_sprite = Sprite::from_file("textures/open_gltf.jpeg", None, None)
                  .expect("open_gltf.jpeg should be able to create sprite");

let all = Assets::all_of_type(AssetType::Sprite);

let mut sprite_count = 0;
for asset in all {
    match asset {
        Asset::Sprite(sprite) => sprite_count += 1,
        _ => panic!("asset should be a sprite"),
    }
}
assert_eq!(sprite_count, 13 + 1);
Source

pub fn current_task() -> i32

This is the index of the current asset loading task. Note that to load one asset, multiple tasks are generated. https://stereokit.net/Pages/StereoKit/Assets/CurrentTask.html

see also assets_current_task Assets::total_tasks

§Examples
use stereokit_rust::{system::Assets, sprite::Sprite};
let my_sprite = Sprite::from_file("textures/open_gltf.jpeg", None, None)
                  .expect("open_gltf.jpeg should be able to create sprite");

let current_task = Assets::current_task();
assert_eq!(Assets::total_tasks(), 1);
number_of_steps = 200;
assert_eq!(current_task, 0);
Source

pub fn current_task_priority() -> i32

StereoKit processes tasks in order of priority. This returns the priority of the current task, and can be used to wait until all tasks within a certain priority range have been completed. https://stereokit.net/Pages/StereoKit/Assets/CurrentTaskPriority.html

see also assets_current_task_priority

§Examples
use stereokit_rust::{system::Assets, sprite::Sprite};

let my_sprite = Sprite::from_file("textures/open_gltf.jpeg", None, None)
                  .expect("open_gltf.jpeg should be able to create sprite");

let current_task_priority  = Assets::current_task_priority();
assert_eq!(current_task_priority, 10);
Source

pub fn total_tasks() -> i32

This is the total number of tasks that have been added to the loading system, including all completed and pending tasks. Note that to load one asset, multiple tasks are generated. https://stereokit.net/Pages/StereoKit/Assets/TotalTasks.html

see also assets_total_tasks

§Examples
use stereokit_rust::{system::Assets, sprite::Sprite};

let my_sprite1 = Sprite::from_file("textures/open_gltf.jpeg", None, None)
                  .expect("open_gltf.jpeg should be able to create sprite");

let my_sprite2 = Sprite::from_file("textures/log_viewer.jpeg", None, None)
                  .expect("log_viewer.jpeg should be able to create sprite");

test_steps!( // !!!! Get a proper main loop !!!!
    let total_tasks  = Assets::total_tasks();
    assert_eq!(total_tasks, 2);
);
Source

pub fn block_for_priority(priority: i32)

This will block the execution of the application until all asset tasks below the priority value have completed loading. To block until all assets are loaded, pass in i32::MAX for the priority. https://stereokit.net/Pages/StereoKit/Assets/BlockForPriority.html

see also assets_block_for_priority

§Examples
use stereokit_rust::{maths::{Vec3, Matrix},  system::{Assets, AssetState}, tex::Tex,
                     material::Material, mesh::Mesh, model::Model, util::named_colors};

// The model is loaded asynchronously, so we need to wait for it to be loaded before we can screenshot it.
let model = Model::from_file("cuve.glb", None)
                .expect("mobiles.gltf should be a valid model");
let transform = Matrix::t_r_s([0.15, -0.75, -1.0], [0.0, 110.0, 0.0], [0.4, 0.4, 0.4]);

Assets::block_for_priority(i32::MAX);

filename_scr = "screenshots/assets_block_for_priority.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    model.draw(token, transform, Some(named_colors::MISTY_ROSE.into()), None);
);
screenshot

Auto Trait Implementations§

§

impl Freeze for Assets

§

impl RefUnwindSafe for Assets

§

impl Send for Assets

§

impl Sync for Assets

§

impl Unpin for Assets

§

impl UnwindSafe for Assets

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more