Skip to content

Commit

Permalink
Bevy 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
DotWith committed Aug 18, 2024
2 parents 47ffefb + 364ecba commit 733d90d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion b3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "b3d"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A parser for the b3d extension"
Expand Down
24 changes: 24 additions & 0 deletions b3d/examples/read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use b3d::{B3D, Error};

fn main() -> Result<(), Error> {
let mut args = std::env::args();
let _ = args.next();
let bytes = std::fs::read(args.next().expect("No b3d file provided")).unwrap();
let b3d = B3D::read(&bytes)?;

let mut min_z = f32::INFINITY;
let mut max_z = -f32::INFINITY;

for vertex in &b3d.node.mesh.vertices.vertices {
let z = vertex.position[2];
min_z = min_z.min(z);
max_z = max_z.max(z);
}

let depth = max_z - min_z;

println!("{:#?}", b3d);
println!("Mesh Depth: {depth}");

Ok(())
}
8 changes: 8 additions & 0 deletions b3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ impl Node {
"NODE" => children.push(Node::read(data, chunk.next)?),
"ANIM" => animation = Animation::read(data, chunk.next)?,
"SEQS" => sequences.push(Sequence::read(data, chunk.next)?),
"PIVO" => {
let mut buf = vec![0; chunk.size as usize];
data.read_exact(&mut buf)?;
}
_ => return Err(Error::InvalidChunk(chunk).into()),
}
}
Expand Down Expand Up @@ -419,6 +423,10 @@ impl B3D {
"TEXS" => textures = Self::read_textures(&mut cursor, chunk.next)?,
"BRUS" => brushes = Self::read_brushes(&mut cursor, chunk.next)?,
"NODE" => node = Node::read(&mut cursor, chunk.next)?,
"PIVO" => {
let mut buf = vec![0; chunk.size as usize];
cursor.read_exact(&mut buf)?;
}
_ => return Err(Error::InvalidChunk(chunk).into()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion bevy_b3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_b3d"
version = "0.3.0"
version = "0.3.2"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A Bevy extension for B3D loading"
Expand Down
6 changes: 6 additions & 0 deletions bevy_b3d/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bevy::{
render::{
mesh::Indices,
render_asset::RenderAssetUsages,
render_asset::RenderAssetUsages,
render_resource::PrimitiveTopology,
renderer::RenderDevice,
texture::{CompressedImageFormats, ImageSampler, ImageType, TextureError},
Expand Down Expand Up @@ -202,6 +203,10 @@ fn load_mesh(b3d_mesh: &b3d::Mesh, index: u32) -> Result<(Mesh, String), B3DErro
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
);
let mut mesh = Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
);

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

if let Err(err) = mesh.generate_tangents() {
Expand Down

0 comments on commit 733d90d

Please sign in to comment.