Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/benches/bevy_render/compute_normals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand::random;
use std::time::{Duration, Instant};

use bevy_asset::RenderAssetUsages;
use bevy_mesh::{Indices, Mesh, PrimitiveTopology};
use bevy_mesh::{Indices, InfallibleMesh, Mesh, PrimitiveTopology};

const GRID_SIZE: usize = 256;

Expand All @@ -28,7 +28,7 @@ fn compute_normals(c: &mut Criterion) {
.flat_map(|i| std::iter::repeat(i).zip(0..GRID_SIZE))
.map(|(i, j)| [i as f32, j as f32, random::<f32>()])
.collect::<Vec<_>>();
Mesh::new(
InfallibleMesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::MAIN_WORLD,
)
Expand Down
11 changes: 6 additions & 5 deletions crates/bevy_asset/src/render_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use serde::{Deserialize, Serialize};
bitflags::bitflags! {
/// Defines where the asset will be used.
///
/// If an asset is set to the `RENDER_WORLD` but not the `MAIN_WORLD`, the asset will be
/// unloaded from the asset server once it's been extracted and prepared in the render world.
/// If an asset is set to the `RENDER_WORLD` but not the `MAIN_WORLD`, the asset data (pixel data,
/// mesh vertex data, etc) will be removed from the cpu-side asset once it's been extracted and prepared
/// in the render world. The asset will remain in the assets collection, but with only metadata.
///
/// Unloading the asset saves on memory, as for most cases it is no longer necessary to keep
/// it in RAM once it's been uploaded to the GPU's VRAM. However, this means you can no longer
/// access the asset from the CPU (via the `Assets<T>` resource) once unloaded (without re-loading it).
/// Unloading the asset data saves on memory, as for most cases it is no longer necessary to keep
/// it in RAM once it's been uploaded to the GPU's VRAM. However, this means you cannot access the
/// asset data from the CPU (via the `Assets<T>` resource) once unloaded (without re-loading it).
///
/// If you never need access to the asset from the CPU past the first frame it's loaded on,
/// or only need very infrequent access, then set this to `RENDER_WORLD`. Otherwise, set this to
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_camera/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ pub trait MeshAabb {

impl MeshAabb for Mesh {
fn compute_aabb(&self) -> Option<Aabb> {
let Some(VertexAttributeValues::Float32x3(values)) =
self.attribute(Mesh::ATTRIBUTE_POSITION)
if let Some(aabb) = self.final_aabb {
// use precomputed extents
return Some(aabb.into());
}

let Ok(VertexAttributeValues::Float32x3(values)) = self.attribute(Mesh::ATTRIBUTE_POSITION)
else {
return None;
};
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_gltf/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use bevy_math::{Mat4, Vec3};
use bevy_mesh::{
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
Indices, Mesh, Mesh3d, MeshVertexAttribute, PrimitiveTopology,
Indices, InfallibleMesh, Mesh, Mesh3d, MeshVertexAttribute, PrimitiveTopology,
};
#[cfg(feature = "pbr_transmission_textures")]
use bevy_pbr::UvChannel;
Expand Down Expand Up @@ -677,7 +677,7 @@ impl GltfLoader {
};
let primitive_topology = primitive_topology(primitive.mode())?;

let mut mesh = Mesh::new(primitive_topology, settings.load_meshes);
let mut mesh = InfallibleMesh::new(primitive_topology, settings.load_meshes);

// Read vertex attributes
for (semantic, accessor) in primitive.attributes() {
Expand Down Expand Up @@ -787,7 +787,8 @@ impl GltfLoader {
});
}

let mesh_handle = load_context.add_labeled_asset(primitive_label.to_string(), mesh);
let mesh_handle =
load_context.add_labeled_asset(primitive_label.to_string(), mesh.into());
primitives.push(super::GltfPrimitive::new(
&gltf_mesh,
&primitive,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/primitives/dim2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ impl From<ConvexPolygon> for Polygon {
)]
pub struct ConvexPolygon {
/// The vertices of the [`ConvexPolygon`].
vertices: Vec<Vec2>,
pub vertices: Vec<Vec2>,
}

#[cfg(feature = "alloc")]
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_mesh/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use wgpu_types::IndexFormat;

use crate::MeshAccessError;

/// A disjunction of four iterators. This is necessary to have a well-formed type for the output
/// of [`Mesh::triangles`](super::Mesh::triangles), which produces iterators of four different types depending on the
/// branch taken.
Expand Down Expand Up @@ -47,6 +49,8 @@ pub enum MeshWindingInvertError {
/// * [`PrimitiveTopology::LineList`](super::PrimitiveTopology::LineList), but the indices are not in chunks of 2.
#[error("Indices weren't in chunks according to topology")]
AbruptIndicesEnd,
#[error("Mesh access error: {0}")]
MeshAccessError(#[from] MeshAccessError),
}

/// An error that occurred while trying to extract a collection of triangles from a [`Mesh`](super::Mesh).
Expand All @@ -55,17 +59,13 @@ pub enum MeshTrianglesError {
#[error("Source mesh does not have primitive topology TriangleList or TriangleStrip")]
WrongTopology,

#[error("Source mesh lacks position data")]
MissingPositions,

#[error("Source mesh position data is not Float32x3")]
PositionsFormat,

#[error("Source mesh lacks face index data")]
MissingIndices,

#[error("Face index data references vertices that do not exist")]
BadIndices,
#[error("mesh access error: {0}")]
MeshAccessError(#[from] MeshAccessError),
}

/// An array of indices into the [`VertexAttributeValues`](super::VertexAttributeValues) for a mesh.
Expand Down
Loading