Skip to content

Commit

Permalink
New mesh attribute: color (#1194)
Browse files Browse the repository at this point in the history
New mesh attribute: color
  • Loading branch information
msklywenn authored Jan 3, 2021
1 parent b7e35ef commit ca310b8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/bevy_render/src/mesh/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum VertexAttributeValues {
Float4(Vec<[f32; 4]>),
Int4(Vec<[i32; 4]>),
Uint4(Vec<[u32; 4]>),
Uchar4Norm(Vec<[u8; 4]>),
}

impl VertexAttributeValues {
Expand All @@ -47,6 +48,7 @@ impl VertexAttributeValues {
VertexAttributeValues::Float4(ref values) => values.len(),
VertexAttributeValues::Int4(ref values) => values.len(),
VertexAttributeValues::Uint4(ref values) => values.len(),
VertexAttributeValues::Uchar4Norm(ref values) => values.len(),
}
}

Expand All @@ -69,6 +71,7 @@ impl VertexAttributeValues {
VertexAttributeValues::Float4(values) => values.as_slice().as_bytes(),
VertexAttributeValues::Int4(values) => values.as_slice().as_bytes(),
VertexAttributeValues::Uint4(values) => values.as_slice().as_bytes(),
VertexAttributeValues::Uchar4Norm(values) => values.as_slice().as_bytes(),
}
}
}
Expand All @@ -88,6 +91,7 @@ impl From<&VertexAttributeValues> for VertexFormat {
VertexAttributeValues::Float4(_) => VertexFormat::Float4,
VertexAttributeValues::Int4(_) => VertexFormat::Int4,
VertexAttributeValues::Uint4(_) => VertexFormat::Uint4,
VertexAttributeValues::Uchar4Norm(_) => VertexFormat::Uchar4Norm,
}
}
}
Expand Down Expand Up @@ -164,6 +168,12 @@ impl From<Vec<[u32; 4]>> for VertexAttributeValues {
}
}

impl From<Vec<[u8; 4]>> for VertexAttributeValues {
fn from(vec: Vec<[u8; 4]>) -> Self {
VertexAttributeValues::Uchar4Norm(vec)
}
}

#[derive(Debug)]
pub enum Indices {
U16(Vec<u16>),
Expand All @@ -190,6 +200,7 @@ pub struct Mesh {
}

impl Mesh {
pub const ATTRIBUTE_COLOR: &'static str = "Vertex_Color";
pub const ATTRIBUTE_NORMAL: &'static str = "Vertex_Normal";
pub const ATTRIBUTE_POSITION: &'static str = "Vertex_Position";
pub const ATTRIBUTE_UV_0: &'static str = "Vertex_Uv";
Expand Down

0 comments on commit ca310b8

Please sign in to comment.