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
3 changes: 2 additions & 1 deletion crates/bevy_mesh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ hexasphere = "17.0"
thiserror = { version = "2", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["std"] }
derive_more = { version = "2", default-features = false, features = ["from"] }
half = { version = "2.4.1", features = ["bytemuck"] }

[dev-dependencies]
approx = "0.5"
Expand All @@ -43,7 +44,7 @@ serde_json = "1.0.140"
[features]
default = []
## Adds serialization support through `serde`.
serialize = ["dep:serde", "wgpu-types/serde"]
serialize = ["dep:serde", "wgpu-types/serde", "half/serde"]
morph = ["dep:bevy_image"]

[lints]
Expand Down
17 changes: 17 additions & 0 deletions crates/bevy_mesh/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,23 @@ impl Mesh {
VertexAttributeValues::Snorm8x4(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Uint8x4(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Unorm8x4(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Uint8(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Sint8(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Unorm8(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Snorm8(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Uint16(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Sint16(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Unorm16(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Snorm16(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Float16(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Float16x2(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Float16x4(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Float64(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Float64x2(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Float64x3(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Float64x4(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Unorm10_10_10_2(vec) => *vec = duplicate(vec, indices),
VertexAttributeValues::Unorm8x4Bgra(vec) => *vec = duplicate(vec, indices),
}
}

Expand Down
159 changes: 136 additions & 23 deletions crates/bevy_mesh/src/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,34 +236,96 @@ pub fn triangle_normal(a: [f32; 3], b: [f32; 3], c: [f32; 3]) -> [f32; 3] {
#[derive(Clone, Debug, EnumVariantMeta, PartialEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
pub enum VertexAttributeValues {
/// One unsigned byte (u8). `u32` in shaders.
Uint8(Vec<u8>),
/// Two unsigned bytes (u8). `vec2<u32>` in shaders.
Uint8x2(Vec<[u8; 2]>),
/// Four unsigned bytes (u8). `vec4<u32>` in shaders.
Uint8x4(Vec<[u8; 4]>),
/// One signed byte (i8). `i32` in shaders.
Sint8(Vec<i8>),
/// Two signed bytes (i8). `vec2<i32>` in shaders.
Sint8x2(Vec<[i8; 2]>),
/// Four signed bytes (i8). `vec4<i32>` in shaders.
Sint8x4(Vec<[i8; 4]>),
/// One unsigned byte (u8). [0, 255] converted to float [0, 1] `f32` in shaders.
Unorm8(Vec<u8>),
/// Two unsigned bytes (u8). [0, 255] converted to float [0, 1] `vec2<f32>` in shaders.
Unorm8x2(Vec<[u8; 2]>),
/// Four unsigned bytes (u8). [0, 255] converted to float [0, 1] `vec4<f32>` in shaders.
Unorm8x4(Vec<[u8; 4]>),
/// One signed byte (i8). [&minus;127, 127] converted to float [&minus;1, 1] `f32` in shaders.
Snorm8(Vec<i8>),
/// Two signed bytes (i8). [&minus;127, 127] converted to float [&minus;1, 1] `vec2<f32>` in shaders.
Snorm8x2(Vec<[i8; 2]>),
/// Four signed bytes (i8). [&minus;127, 127] converted to float [&minus;1, 1] `vec4<f32>` in shaders.
Snorm8x4(Vec<[i8; 4]>),
/// One unsigned short (u16). `u32` in shaders.
Uint16(Vec<u16>),
/// Two unsigned shorts (u16). `vec2<u32>` in shaders.
Uint16x2(Vec<[u16; 2]>),
/// Four unsigned shorts (u16). `vec4<u32>` in shaders.
Uint16x4(Vec<[u16; 4]>),
/// One signed short (i16). `i32` in shaders.
Sint16(Vec<i16>),
/// Two signed shorts (i16). `vec2<i32>` in shaders.
Sint16x2(Vec<[i16; 2]>),
/// Four signed shorts (i16). `vec4<i32>` in shaders.
Sint16x4(Vec<[i16; 4]>),
/// One unsigned short (u16). [0, 65535] converted to float [0, 1] `f32` in shaders.
Unorm16(Vec<u16>),
/// Two unsigned shorts (u16). [0, 65535] converted to float [0, 1] `vec2<f32>` in shaders.
Unorm16x2(Vec<[u16; 2]>),
/// Four unsigned shorts (u16). [0, 65535] converted to float [0, 1] `vec4<f32>` in shaders.
Unorm16x4(Vec<[u16; 4]>),
/// One signed short (i16). [&minus;32767, 32767] converted to float [&minus;1, 1] `f32` in shaders.
Snorm16(Vec<i16>),
/// Two signed shorts (i16). [&minus;32767, 32767] converted to float [&minus;1, 1] `vec2<f32>` in shaders.
Snorm16x2(Vec<[i16; 2]>),
/// Four signed shorts (i16). [&minus;32767, 32767] converted to float [&minus;1, 1] `vec4<f32>` in shaders.
Snorm16x4(Vec<[i16; 4]>),
/// One half-precision float (no Rust equiv). `f32` in shaders.
Float16(Vec<half::f16>),
/// Two half-precision floats (no Rust equiv). `vec2<f32>` in shaders.
Float16x2(Vec<[half::f16; 2]>),
/// Four half-precision floats (no Rust equiv). `vec4<f32>` in shaders.
Float16x4(Vec<[half::f16; 4]>),
/// One single-precision float (f32). `f32` in shaders.
Float32(Vec<f32>),
Sint32(Vec<i32>),
Uint32(Vec<u32>),
/// Two single-precision floats (f32). `vec2<f32>` in shaders.
Float32x2(Vec<[f32; 2]>),
Sint32x2(Vec<[i32; 2]>),
Uint32x2(Vec<[u32; 2]>),
/// Three single-precision floats (f32). `vec3<f32>` in shaders.
Float32x3(Vec<[f32; 3]>),
Sint32x3(Vec<[i32; 3]>),
Uint32x3(Vec<[u32; 3]>),
/// Four single-precision floats (f32). `vec4<f32>` in shaders.
Float32x4(Vec<[f32; 4]>),
Sint32x4(Vec<[i32; 4]>),
/// One unsigned int (u32). `u32` in shaders.
Uint32(Vec<u32>),
/// Two unsigned ints (u32). `vec2<u32>` in shaders.
Uint32x2(Vec<[u32; 2]>),
/// Three unsigned ints (u32). `vec3<u32>` in shaders.
Uint32x3(Vec<[u32; 3]>),
/// Four unsigned ints (u32). `vec4<u32>` in shaders.
Uint32x4(Vec<[u32; 4]>),
Sint16x2(Vec<[i16; 2]>),
Snorm16x2(Vec<[i16; 2]>),
Uint16x2(Vec<[u16; 2]>),
Unorm16x2(Vec<[u16; 2]>),
Sint16x4(Vec<[i16; 4]>),
Snorm16x4(Vec<[i16; 4]>),
Uint16x4(Vec<[u16; 4]>),
Unorm16x4(Vec<[u16; 4]>),
Sint8x2(Vec<[i8; 2]>),
Snorm8x2(Vec<[i8; 2]>),
Uint8x2(Vec<[u8; 2]>),
Unorm8x2(Vec<[u8; 2]>),
Sint8x4(Vec<[i8; 4]>),
Snorm8x4(Vec<[i8; 4]>),
Uint8x4(Vec<[u8; 4]>),
Unorm8x4(Vec<[u8; 4]>),
/// One signed int (i32). `i32` in shaders.
Sint32(Vec<i32>),
/// Two signed ints (i32). `vec2<i32>` in shaders.
Sint32x2(Vec<[i32; 2]>),
/// Three signed ints (i32). `vec3<i32>` in shaders.
Sint32x3(Vec<[i32; 3]>),
/// Four signed ints (i32). `vec4<i32>` in shaders.
Sint32x4(Vec<[i32; 4]>),
/// One double-precision float (f64). `f32` in shaders. Requires [`wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT`].
Float64(Vec<f64>),
/// Two double-precision floats (f64). `vec2<f32>` in shaders. Requires [`wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT`].
Float64x2(Vec<[f64; 2]>),
/// Three double-precision floats (f64). `vec3<f32>` in shaders. Requires [`wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT`].
Float64x3(Vec<[f64; 3]>),
/// Four double-precision floats (f64). `vec4<f32>` in shaders. Requires [`wgpu_types::Features::VERTEX_ATTRIBUTE_64BIT`].
Float64x4(Vec<[f64; 4]>),
/// Three unsigned 10-bit integers and one 2-bit integer, packed into a 32-bit integer (u32). [0, 1024] converted to float [0, 1] `vec4<f32>` in shaders.
Unorm10_10_10_2(Vec<u32>),
/// Four unsigned 8-bit integers, packed into a 32-bit integer (u32). [0, 255] converted to float [0, 1] `vec4<f32>` in shaders.
Unorm8x4Bgra(Vec<u32>),
}

impl VertexAttributeValues {
Expand Down Expand Up @@ -303,6 +365,23 @@ impl VertexAttributeValues {
VertexAttributeValues::Snorm8x4(values) => values.len(),
VertexAttributeValues::Uint8x4(values) => values.len(),
VertexAttributeValues::Unorm8x4(values) => values.len(),
VertexAttributeValues::Uint8(values) => values.len(),
VertexAttributeValues::Sint8(values) => values.len(),
VertexAttributeValues::Unorm8(values) => values.len(),
VertexAttributeValues::Snorm8(values) => values.len(),
VertexAttributeValues::Uint16(values) => values.len(),
VertexAttributeValues::Sint16(values) => values.len(),
VertexAttributeValues::Unorm16(values) => values.len(),
VertexAttributeValues::Snorm16(values) => values.len(),
VertexAttributeValues::Float16(values) => values.len(),
VertexAttributeValues::Float16x2(values) => values.len(),
VertexAttributeValues::Float16x4(values) => values.len(),
VertexAttributeValues::Float64(values) => values.len(),
VertexAttributeValues::Float64x2(values) => values.len(),
VertexAttributeValues::Float64x3(values) => values.len(),
VertexAttributeValues::Float64x4(values) => values.len(),
VertexAttributeValues::Unorm10_10_10_2(values) => values.len(),
VertexAttributeValues::Unorm8x4Bgra(values) => values.len(),
}
}

Expand Down Expand Up @@ -356,6 +435,23 @@ impl VertexAttributeValues {
VertexAttributeValues::Snorm8x4(values) => cast_slice(values),
VertexAttributeValues::Uint8x4(values) => cast_slice(values),
VertexAttributeValues::Unorm8x4(values) => cast_slice(values),
VertexAttributeValues::Uint8(values) => cast_slice(values),
VertexAttributeValues::Sint8(values) => cast_slice(values),
VertexAttributeValues::Unorm8(values) => cast_slice(values),
VertexAttributeValues::Snorm8(values) => cast_slice(values),
VertexAttributeValues::Uint16(values) => cast_slice(values),
VertexAttributeValues::Sint16(values) => cast_slice(values),
VertexAttributeValues::Unorm16(values) => cast_slice(values),
VertexAttributeValues::Snorm16(values) => cast_slice(values),
VertexAttributeValues::Float16(values) => cast_slice(values),
VertexAttributeValues::Float16x2(values) => cast_slice(values),
VertexAttributeValues::Float16x4(values) => cast_slice(values),
VertexAttributeValues::Float64(values) => cast_slice(values),
VertexAttributeValues::Float64x2(values) => cast_slice(values),
VertexAttributeValues::Float64x3(values) => cast_slice(values),
VertexAttributeValues::Float64x4(values) => cast_slice(values),
VertexAttributeValues::Unorm10_10_10_2(values) => cast_slice(values),
VertexAttributeValues::Unorm8x4Bgra(values) => cast_slice(values),
}
}
}
Expand Down Expand Up @@ -391,6 +487,23 @@ impl From<&VertexAttributeValues> for VertexFormat {
VertexAttributeValues::Snorm8x4(_) => VertexFormat::Snorm8x4,
VertexAttributeValues::Uint8x4(_) => VertexFormat::Uint8x4,
VertexAttributeValues::Unorm8x4(_) => VertexFormat::Unorm8x4,
VertexAttributeValues::Uint8(_) => VertexFormat::Uint8,
VertexAttributeValues::Sint8(_) => VertexFormat::Sint8,
VertexAttributeValues::Unorm8(_) => VertexFormat::Unorm8,
VertexAttributeValues::Snorm8(_) => VertexFormat::Snorm8,
VertexAttributeValues::Uint16(_) => VertexFormat::Uint16,
VertexAttributeValues::Sint16(_) => VertexFormat::Sint16,
VertexAttributeValues::Unorm16(_) => VertexFormat::Unorm16,
VertexAttributeValues::Snorm16(_) => VertexFormat::Snorm16,
VertexAttributeValues::Float16(_) => VertexFormat::Float16,
VertexAttributeValues::Float16x2(_) => VertexFormat::Float16x2,
VertexAttributeValues::Float16x4(_) => VertexFormat::Float16x4,
VertexAttributeValues::Float64(_) => VertexFormat::Float64,
VertexAttributeValues::Float64x2(_) => VertexFormat::Float64x2,
VertexAttributeValues::Float64x3(_) => VertexFormat::Float64x3,
VertexAttributeValues::Float64x4(_) => VertexFormat::Float64x4,
VertexAttributeValues::Unorm10_10_10_2(_) => VertexFormat::Unorm10_10_10_2,
VertexAttributeValues::Unorm8x4Bgra(_) => VertexFormat::Unorm8x4Bgra,
}
}
}
Expand Down