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
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5026,6 +5026,15 @@ doc-scrape-examples = true
[package.metadata.example.test_skinned_mesh_bounds]
hidden = true

[[example]]
name = "test_skinned_mesh_picking"
path = "tests/3d/test_skinned_mesh_picking.rs"
doc-scrape-examples = true
required-features = ["free_camera"]

[package.metadata.example.test_skinned_mesh_picking]
hidden = true

[profile.wasm-release]
inherits = "release"
opt-level = "z"
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_picking/ray_mesh_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ fn bench(c: &mut Criterion) {
&mesh_to_world,
&mesh.positions,
Some(&mesh.normals),
None,
Some(&mesh.indices),
None,
backface_culling,
Expand Down
21 changes: 20 additions & 1 deletion crates/bevy_mesh/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const INDEX_BUFFER_ASSET_INDEX: u64 = 0;
pub const VERTEX_ATTRIBUTE_BUFFER_ID: u64 = 10;

/// Error from accessing mesh vertex attributes or indices
#[derive(Error, Debug, Clone)]
#[derive(Error, Debug, Clone, PartialEq)]
pub enum MeshAccessError {
#[error("The mesh vertex/index data has been extracted to the RenderWorld (via `Mesh::asset_usage`)")]
ExtractedToRenderWorld,
Expand Down Expand Up @@ -354,6 +354,25 @@ impl Mesh {
}
}

/// Returns a copy of the mesh without attributes, indices, morph targets,
/// and the data derived from them (like the AABB). Settings like
/// `primitive_topology` and `asset_usage` are preserved.
pub fn as_empty(&self) -> Mesh {
Comment on lines +357 to +360
Copy link
Copy Markdown
Contributor Author

@greeble-dev greeble-dev Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this so that skin_mesh can replace a mesh's attributes while keeping the settings. It's maybe a bit niche for the main mesh API, but other solutions would break easily if Mesh acquires new members.

Mesh {
primitive_topology: self.primitive_topology,
enable_raytracing: self.enable_raytracing,
asset_usage: self.asset_usage,
attributes: MeshExtractableData::Data(Default::default()),
indices: MeshExtractableData::NoData,
#[cfg(feature = "morph")]
morph_targets: MeshExtractableData::NoData,
#[cfg(feature = "morph")]
morph_target_names: MeshExtractableData::NoData,
final_aabb: None,
skinned_mesh_bounds: None,
}
}

/// Returns the topology of the mesh.
pub fn primitive_topology(&self) -> PrimitiveTopology {
self.primitive_topology
Expand Down
Loading