mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Async mesh loading works
This commit is contained in:
parent
4e1abea161
commit
35adad6556
2 changed files with 28 additions and 25 deletions
|
@ -346,30 +346,34 @@ fn setup_mesh_resource(
|
|||
render_resources.get_asset_resource(handle, INDEX_BUFFER_ASSET_INDEX),
|
||||
)
|
||||
} else {
|
||||
let mesh_asset = meshes.get(&handle).unwrap();
|
||||
let vertex_bytes = mesh_asset
|
||||
.get_vertex_buffer_bytes(&vertex_buffer_descriptor)
|
||||
.unwrap();
|
||||
// TODO: use a staging buffer here
|
||||
let vertex_buffer = render_resources.create_buffer_with_data(
|
||||
BufferInfo {
|
||||
buffer_usage: BufferUsage::VERTEX,
|
||||
..Default::default()
|
||||
},
|
||||
&vertex_bytes,
|
||||
);
|
||||
let index_bytes = mesh_asset.get_index_buffer_bytes(index_format).unwrap();
|
||||
let index_buffer = render_resources.create_buffer_with_data(
|
||||
BufferInfo {
|
||||
buffer_usage: BufferUsage::INDEX,
|
||||
..Default::default()
|
||||
},
|
||||
&index_bytes,
|
||||
);
|
||||
if let Some(mesh_asset) = meshes.get(&handle) {
|
||||
let vertex_bytes = mesh_asset
|
||||
.get_vertex_buffer_bytes(&vertex_buffer_descriptor)
|
||||
.unwrap();
|
||||
// TODO: use a staging buffer here
|
||||
let vertex_buffer = render_resources.create_buffer_with_data(
|
||||
BufferInfo {
|
||||
buffer_usage: BufferUsage::VERTEX,
|
||||
..Default::default()
|
||||
},
|
||||
&vertex_bytes,
|
||||
);
|
||||
let index_bytes = mesh_asset.get_index_buffer_bytes(index_format).unwrap();
|
||||
let index_buffer = render_resources.create_buffer_with_data(
|
||||
BufferInfo {
|
||||
buffer_usage: BufferUsage::INDEX,
|
||||
..Default::default()
|
||||
},
|
||||
&index_bytes,
|
||||
);
|
||||
|
||||
render_resources.set_asset_resource(handle, vertex_buffer, VERTEX_BUFFER_ASSET_INDEX);
|
||||
render_resources.set_asset_resource(handle, index_buffer, INDEX_BUFFER_ASSET_INDEX);
|
||||
(vertex_buffer, Some(index_buffer))
|
||||
render_resources.set_asset_resource(handle, vertex_buffer, VERTEX_BUFFER_ASSET_INDEX);
|
||||
render_resources.set_asset_resource(handle, index_buffer, INDEX_BUFFER_ASSET_INDEX);
|
||||
(vertex_buffer, Some(index_buffer))
|
||||
} else {
|
||||
// mesh doesn't exist. it probably hasn't loaded yet
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
render_resource_assignments.set_vertex_buffer("Vertex", vertex_buffer, index_buffer);
|
||||
|
|
|
@ -11,12 +11,11 @@ fn main() {
|
|||
fn setup(
|
||||
command_buffer: &mut CommandBuffer,
|
||||
asset_server: ResMut<AssetServer>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// load the mesh
|
||||
let mesh_handle = asset_server
|
||||
.load_sync(&mut meshes, "assets/models/monkey/Monkey.gltf")
|
||||
.load("assets/models/monkey/Monkey.gltf")
|
||||
.unwrap();
|
||||
|
||||
// create a material for the mesh
|
||||
|
|
Loading…
Reference in a new issue