Skip to content

Commit c74994b

Browse files
simensgreenalouckscart
committed
Added TryFrom for VertexAttributeValues (#1963)
This implementations allows you convert std::vec::Vec<T> to VertexAttributeValues::T and back. # Examples ```rust use std::convert::TryInto; use bevy_render::mesh::VertexAttributeValues; // creating vector of values let before = vec![[0_u32; 4]; 10]; let values = VertexAttributeValues::from(before.clone()); let after: Vec<[u32; 4]> = values.try_into().unwrap(); assert_eq!(before, after); ``` Co-authored-by: aloucks <[email protected]> Co-authored-by: simens_green <[email protected]> Co-authored-by: Carter Anderson <[email protected]>
1 parent 4a477e7 commit c74994b

File tree

2 files changed

+608
-78
lines changed

2 files changed

+608
-78
lines changed

crates/bevy_render/src/mesh/mesh.rs

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod conversions;
2+
13
use crate::{
24
pipeline::{IndexFormat, PrimitiveTopology, RenderPipelines, VertexFormat},
35
renderer::{BufferInfo, BufferUsage, RenderResourceContext, RenderResourceId},
@@ -174,84 +176,6 @@ impl From<&VertexAttributeValues> for VertexFormat {
174176
}
175177
}
176178

177-
impl From<Vec<f32>> for VertexAttributeValues {
178-
fn from(vec: Vec<f32>) -> Self {
179-
VertexAttributeValues::Float(vec)
180-
}
181-
}
182-
183-
impl From<Vec<i32>> for VertexAttributeValues {
184-
fn from(vec: Vec<i32>) -> Self {
185-
VertexAttributeValues::Int(vec)
186-
}
187-
}
188-
189-
impl From<Vec<u32>> for VertexAttributeValues {
190-
fn from(vec: Vec<u32>) -> Self {
191-
VertexAttributeValues::Uint(vec)
192-
}
193-
}
194-
195-
impl From<Vec<[f32; 2]>> for VertexAttributeValues {
196-
fn from(vec: Vec<[f32; 2]>) -> Self {
197-
VertexAttributeValues::Float2(vec)
198-
}
199-
}
200-
201-
impl From<Vec<[i32; 2]>> for VertexAttributeValues {
202-
fn from(vec: Vec<[i32; 2]>) -> Self {
203-
VertexAttributeValues::Int2(vec)
204-
}
205-
}
206-
207-
impl From<Vec<[u32; 2]>> for VertexAttributeValues {
208-
fn from(vec: Vec<[u32; 2]>) -> Self {
209-
VertexAttributeValues::Uint2(vec)
210-
}
211-
}
212-
213-
impl From<Vec<[f32; 3]>> for VertexAttributeValues {
214-
fn from(vec: Vec<[f32; 3]>) -> Self {
215-
VertexAttributeValues::Float3(vec)
216-
}
217-
}
218-
219-
impl From<Vec<[i32; 3]>> for VertexAttributeValues {
220-
fn from(vec: Vec<[i32; 3]>) -> Self {
221-
VertexAttributeValues::Int3(vec)
222-
}
223-
}
224-
225-
impl From<Vec<[u32; 3]>> for VertexAttributeValues {
226-
fn from(vec: Vec<[u32; 3]>) -> Self {
227-
VertexAttributeValues::Uint3(vec)
228-
}
229-
}
230-
231-
impl From<Vec<[f32; 4]>> for VertexAttributeValues {
232-
fn from(vec: Vec<[f32; 4]>) -> Self {
233-
VertexAttributeValues::Float4(vec)
234-
}
235-
}
236-
237-
impl From<Vec<[i32; 4]>> for VertexAttributeValues {
238-
fn from(vec: Vec<[i32; 4]>) -> Self {
239-
VertexAttributeValues::Int4(vec)
240-
}
241-
}
242-
243-
impl From<Vec<[u32; 4]>> for VertexAttributeValues {
244-
fn from(vec: Vec<[u32; 4]>) -> Self {
245-
VertexAttributeValues::Uint4(vec)
246-
}
247-
}
248-
249-
impl From<Vec<[u8; 4]>> for VertexAttributeValues {
250-
fn from(vec: Vec<[u8; 4]>) -> Self {
251-
VertexAttributeValues::Uchar4Norm(vec)
252-
}
253-
}
254-
255179
/// An array of indices into the VertexAttributeValues for a mesh.
256180
///
257181
/// It describes the order in which the vertex attributes should be joined into faces.

0 commit comments

Comments
 (0)