phrasing tweaks

This commit is contained in:
Carter Anderson 2020-05-17 10:29:42 -07:00
parent 870f715df3
commit e093a3243b
4 changed files with 15 additions and 12 deletions

View File

@ -112,8 +112,8 @@ name = "plugin"
path = "examples/app/plugin.rs" path = "examples/app/plugin.rs"
[[example]] [[example]]
name = "hot_asset_reload" name = "hot_asset_reloading"
path = "examples/asset/hot_asset_reload.rs" path = "examples/asset/hot_asset_reloading.rs"
[[example]] [[example]]
name = "asset_loading" name = "asset_loading"

View File

@ -206,6 +206,7 @@ impl AssetServer {
} }
} }
// TODO: add type checking here. people shouldn't be able to request a Handle<Texture> for a Mesh asset
pub fn load<T, P: AsRef<Path>>(&self, path: P) -> Result<Handle<T>, AssetServerError> { pub fn load<T, P: AsRef<Path>>(&self, path: P) -> Result<Handle<T>, AssetServerError> {
self.load_untyped(path) self.load_untyped(path)
.map(|handle_id| Handle::from(handle_id)) .map(|handle_id| Handle::from(handle_id))

View File

@ -14,7 +14,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// You can load all assets in a folder like this. they will be loaded in parallel without blocking // You can load all assets in a folder like this. They will be loaded in parallel without blocking
asset_server.load_asset_folder("assets/models/monkey").unwrap(); asset_server.load_asset_folder("assets/models/monkey").unwrap();
// Then any asset in the folder can be accessed like this: // Then any asset in the folder can be accessed like this:
@ -27,19 +27,20 @@ fn setup(
.load("assets/models/cube/cube.gltf") .load("assets/models/cube/cube.gltf")
.unwrap(); .unwrap();
// Assets are loaded in the background by default, which means they might not be available immediately after loading. // Assets are loaded in the background by default, which means they might not be available immediately after calling load().
// If you need immediate access you can load assets synchronously like this: // If you need immediate access you can load assets synchronously like this:
let sphere_handle = asset_server.load_sync(&mut meshes, "assets/models/sphere/sphere.gltf").unwrap(); let sphere_handle = asset_server.load_sync(&mut meshes, "assets/models/sphere/sphere.gltf").unwrap();
// All assets end up in their Assets<T> collection once they are done loading:
let sphere = meshes.get(&sphere_handle).unwrap(); let sphere = meshes.get(&sphere_handle).unwrap();
println!("{:?}", sphere.primitive_topology); println!("{:?}", sphere.primitive_topology);
// You can also add assets directly to their Assets<T> storage // You can also add assets directly to their Assets<T> storage:
let material_handle = materials.add(StandardMaterial { let material_handle = materials.add(StandardMaterial {
albedo: Color::rgb(0.5, 0.4, 0.3), albedo: Color::rgb(0.5, 0.4, 0.3),
..Default::default() ..Default::default()
}); });
// add entities to the world // Add entities to the world:
command_buffer command_buffer
.build() .build()
// monkey // monkey

View File

@ -15,26 +15,27 @@ fn setup(
mut asset_server: ResMut<AssetServer>, mut asset_server: ResMut<AssetServer>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// load an asset folder // Load an asset folder:
asset_server.load_asset_folder("assets").unwrap(); asset_server.load_asset_folder("assets").unwrap();
// tell the asset server to watch for changes // Tell the asset server to watch for asset changes on disk:
asset_server.watch_for_changes().unwrap(); asset_server.watch_for_changes().unwrap();
// load the mesh // Get a handle for our mesh:
let mesh_handle = asset_server let mesh_handle = asset_server
.get_handle("assets/models/monkey/Monkey.gltf") .get_handle("assets/models/monkey/Monkey.gltf")
.unwrap(); .unwrap();
// now any changes to the mesh will be reloaded automatically! // Any changes to the mesh will be reloaded automatically! Try making a change to Monkey.gltf.
// You should see the changes immediately show up in your app.
// create a material for the mesh // Create a material for the mesh:
let material_handle = materials.add(StandardMaterial { let material_handle = materials.add(StandardMaterial {
albedo: Color::rgb(0.5, 0.4, 0.3), albedo: Color::rgb(0.5, 0.4, 0.3),
..Default::default() ..Default::default()
}); });
// add entities to the world // Add entities to the world:
command_buffer command_buffer
.build() .build()
// mesh // mesh