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);
);

Implementations§
Source§impl Assets
impl Assets
Sourcepub const MODEL_FORMATS: [&'static str; 5]
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
Sourcepub const TEXTURE_FORMATS: [&'static str; 11]
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
Sourcepub const SOUND_FORMATS: [&'static str; 2]
pub const SOUND_FORMATS: [&'static str; 2]
supported sound format by asset Sound https://stereokit.net/Pages/StereoKit/Sound.html
Sourcepub fn all() -> AssetIter ⓘ
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
§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);
Sourcepub fn all_of_type(asset_type: AssetType) -> AssetIter ⓘ
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
- AnyIAsset
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);
Sourcepub fn current_task() -> i32
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);
Sourcepub fn current_task_priority() -> i32
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);
Sourcepub fn total_tasks() -> i32
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);
);
Sourcepub fn block_for_priority(priority: i32)
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);
);

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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.