Skip to content

Commit

Permalink
Update bevy
Browse files Browse the repository at this point in the history
  • Loading branch information
DotWith committed Aug 18, 2024
1 parent 74c151f commit 47ffefb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
6 changes: 3 additions & 3 deletions bevy_b3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "../README.md"
keywords = ["bevy"]

[dependencies]
bevy = { version = "0.12.1", default-features = false, features = ["bevy_asset", "bevy_pbr", "bevy_render", "bevy_scene"] }
bevy = { version = "0.14.1", default-features = false, features = ["bevy_asset", "bevy_pbr", "bevy_render", "bevy_scene"] }
b3d = { path = "../b3d", version = "0.1.7" }
thiserror = "1.0.51"
anyhow = "1.0.76"
thiserror = "1.0.63"
anyhow = "1.0.86"
2 changes: 1 addition & 1 deletion bevy_b3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Plugin for B3DPlugin {
}

fn finish(&self, app: &mut App) {
let supported_compressed_formats = match app.world.get_resource::<RenderDevice>() {
let supported_compressed_formats = match app.world().get_resource::<RenderDevice>() {
Some(render_device) => CompressedImageFormats::from_features(render_device.features()),

None => CompressedImageFormats::NONE,
Expand Down
36 changes: 23 additions & 13 deletions bevy_b3d/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy::{
prelude::*,
render::{
mesh::Indices,
render_asset::RenderAssetUsages,
render_resource::PrimitiveTopology,
renderer::RenderDevice,
texture::{CompressedImageFormats, ImageSampler, ImageType, TextureError},
Expand All @@ -15,6 +16,7 @@ use thiserror::Error;
use crate::B3D;

/// An error that occurs when loading a b3d file.
#[non_exhaustive]
#[derive(Error, Debug)]
pub enum B3DError {
#[error(transparent)]
Expand All @@ -39,17 +41,15 @@ impl AssetLoader for B3DLoader {
type Settings = ();
type Error = B3DError;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
load_context: &'a mut LoadContext,
) -> bevy::utils::BoxedFuture<'a, Result<B3D, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
load_b3d(self, &bytes, load_context).await
})
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
load_b3d(self, &bytes, load_context).await
}

fn extensions(&self) -> &[&str] {
Expand Down Expand Up @@ -79,8 +79,13 @@ async fn load_b3d<'a, 'b>(

let mut materials = vec![];
for (texture_index, texture) in b3d.textures.into_iter().enumerate() {
if let Ok(texture) =
load_texture(&texture, load_context, loader.supported_compressed_formats).await
if let Ok(texture) = load_texture(
&texture,
load_context,
loader.supported_compressed_formats,
RenderAssetUsages::default(),
)
.await
{
let texture_handle =
load_context.add_labeled_asset(format!("Texture{}", texture_index), texture);
Expand Down Expand Up @@ -193,7 +198,10 @@ fn load_node(
}

fn load_mesh(b3d_mesh: &b3d::Mesh, index: u32) -> Result<(Mesh, String), B3DError> {
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
let mut mesh = Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
);

if let Some(vertex_attribute) = b3d_mesh
.vertices
Expand Down Expand Up @@ -236,7 +244,7 @@ fn load_mesh(b3d_mesh: &b3d::Mesh, index: u32) -> Result<(Mesh, String), B3DErro
.collect::<Vec<_>>()
.into()
{
mesh.set_indices(Some(Indices::U32(vertex_attribute)));
mesh.insert_indices(Indices::U32(vertex_attribute));
}

if let Err(err) = mesh.generate_tangents() {
Expand All @@ -254,6 +262,7 @@ async fn load_texture<'a>(
b3d_texture: &b3d::Texture,
load_context: &mut LoadContext<'a>,
supported_compressed_formats: CompressedImageFormats,
render_asset_usages: RenderAssetUsages,
) -> Result<Image, B3DError> {
let parent = load_context.path().parent().unwrap();
let image_path = parent.join(&b3d_texture.file);
Expand All @@ -272,6 +281,7 @@ async fn load_texture<'a>(
supported_compressed_formats,
true,
ImageSampler::Default,
render_asset_usages,
)?)
}

Expand Down

0 comments on commit 47ffefb

Please sign in to comment.