#[repr(C)]pub struct Vertex {
pub position: Vec3,
pub normal: Vec3,
pub uv: Vec2,
}Expand description
One corner of a mesh.
Fields§
§position: Vec3Corner position, in mesh space, in meters.
normal: Vec3The corner’s outward direction, used for lighting.
uv: Vec2The texture coordinate, (0, 0) at the texture’s top left.
Implementations§
Source§impl Vertex
impl Vertex
Sourcepub const fn new(position: Vec3, normal: Vec3, uv: Vec2) -> Self
pub const fn new(position: Vec3, normal: Vec3, uv: Vec2) -> Self
A vertex at position, with normal and uv.
Examples found in repository?
examples/stress-preview.rs (line 566)
557fn push_face(vertices: &mut Vec<Vertex>, indices: &mut Vec<u32>, a: Vec3, b: Vec3, c: Vec3) {
558 let normal = (b - a).cross(c - a).normalize();
559 let uvs = [
560 Vec2::new(0.0, 1.0),
561 Vec2::new(0.5, 0.0),
562 Vec2::new(1.0, 1.0),
563 ];
564 let base = vertices.len() as u32;
565 for (point, uv) in [a, b, c].into_iter().zip(uvs) {
566 vertices.push(Vertex::new(point, normal, uv));
567 }
568 indices.extend([base, base + 1, base + 2]);
569}More examples
examples/sound-lab.rs (line 178)
164fn ring_outline() -> MeshData {
165 const SEGMENTS: u32 = 48;
166 const OUTER: f32 = 1.0;
167 const INNER: f32 = 0.94;
168
169 let mut vertices = Vec::with_capacity(SEGMENTS as usize * 4);
170 let mut indices = Vec::with_capacity(SEGMENTS as usize * 6);
171 for segment in 0..SEGMENTS {
172 let a0 = segment as f32 / SEGMENTS as f32 * TAU;
173 let a1 = (segment + 1) as f32 / SEGMENTS as f32 * TAU;
174 let (u0, v0) = (a0.cos(), a0.sin());
175 let (u1, v1) = (a1.cos(), a1.sin());
176 let base = vertices.len() as u32;
177 vertices.extend([
178 Vertex::new(Vec3::new(INNER * u0, 0.0, -INNER * v0), Vec3::Y, Vec2::ZERO),
179 Vertex::new(Vec3::new(OUTER * u0, 0.0, -OUTER * v0), Vec3::Y, Vec2::ZERO),
180 Vertex::new(Vec3::new(OUTER * u1, 0.0, -OUTER * v1), Vec3::Y, Vec2::ZERO),
181 Vertex::new(Vec3::new(INNER * u1, 0.0, -INNER * v1), Vec3::Y, Vec2::ZERO),
182 ]);
183 indices.extend([base, base + 1, base + 2, base, base + 2, base + 3]);
184 }
185 MeshData::new(vertices, indices)
186}
187
188fn facing_marker() -> MeshData {
189 const TIP: Vec3 = Vec3::new(0.0, 0.0, -0.5);
190 const BACK: [Vec3; 4] = [
191 Vec3::new(-0.5, -0.5, 0.5),
192 Vec3::new(0.5, -0.5, 0.5),
193 Vec3::new(0.5, 0.5, 0.5),
194 Vec3::new(-0.5, 0.5, 0.5),
195 ];
196
197 let mut vertices = Vec::with_capacity(BACK.len() * 3);
198 for (corner, next) in BACK.iter().zip(BACK.iter().cycle().skip(1)) {
199 let normal = (next - corner).cross(TIP - corner).normalize();
200 vertices.extend([
201 Vertex::new(*corner, normal, Vec2::new(0.0, 1.0)),
202 Vertex::new(*next, normal, Vec2::new(1.0, 1.0)),
203 Vertex::new(TIP, normal, Vec2::new(0.5, 0.0)),
204 ]);
205 }
206 let indices = (0..vertices.len() as u32).collect();
207 MeshData::new(vertices, indices)
208}examples/material-playground.rs (lines 367-371)
360fn banner_mesh() -> MeshData {
361 let mut vertices = Vec::with_capacity(((BANNER_COLUMNS + 1) * 4) as usize);
362 for normal in [Vec3::Z, Vec3::NEG_Z] {
363 for column in 0..=BANNER_COLUMNS {
364 let u = column as f32 / BANNER_COLUMNS as f32;
365 let x = u * BANNER_WIDTH;
366 for v in [0.0, 1.0] {
367 vertices.push(Vertex::new(
368 Vec3::new(x, -v * BANNER_HEIGHT, 0.0),
369 normal,
370 Vec2::new(u, v),
371 ));
372 }
373 }
374 }
375
376 let side = BANNER_COLUMNS + 1;
377 let mut indices = Vec::with_capacity((BANNER_COLUMNS * 12) as usize);
378 for column in 0..BANNER_COLUMNS {
379 let top_left = column * 2;
380 let bottom_left = top_left + 1;
381 let top_right = top_left + 2;
382 let bottom_right = top_left + 3;
383 indices.extend([
384 bottom_left,
385 bottom_right,
386 top_right,
387 bottom_left,
388 top_right,
389 top_left,
390 ]);
391
392 let back = side * 2;
393 indices.extend([
394 back + top_right,
395 back + bottom_right,
396 back + bottom_left,
397 back + top_left,
398 back + top_right,
399 back + bottom_left,
400 ]);
401 }
402
403 MeshData::new(vertices, indices)
404}examples/isometric-board.rs (line 754)
724fn build_rock(seed: u32) -> MeshData {
725 let corners: [Vec3; 8] = core::array::from_fn(|index| {
726 let sign = Vec3::new(
727 if index & 1 == 0 { -0.5 } else { 0.5 },
728 if index & 2 == 0 { -0.5 } else { 0.5 },
729 if index & 4 == 0 { -0.5 } else { 0.5 },
730 );
731 sign + corner_offset(seed, index as u32)
732 });
733 let corner_at = |sign: Vec3| corners[corner_index(sign)];
734
735 let mut vertices = Vec::with_capacity(ROCK_FACES.len() * 4);
736 let mut indices = Vec::with_capacity(ROCK_FACES.len() * 6);
737 for (face, &(normal, right, up)) in ROCK_FACES.iter().enumerate() {
738 let quad = [
739 corner_at(normal - right - up),
740 corner_at(normal + right - up),
741 corner_at(normal + right + up),
742 corner_at(normal - right + up),
743 ];
744 let normal = (quad[1] - quad[0]).cross(quad[3] - quad[0]).normalize();
745 let uvs = [
746 Vec2::new(0.0, 1.0),
747 Vec2::new(1.0, 1.0),
748 Vec2::new(1.0, 0.0),
749 Vec2::new(0.0, 0.0),
750 ];
751 vertices.extend(
752 quad.into_iter()
753 .zip(uvs)
754 .map(|(corner, uv)| Vertex::new(corner, normal, uv)),
755 );
756 let base = face as u32 * 4;
757 indices.extend(ROCK_TRIANGLES.map(|index| base + index));
758 }
759 MeshData::new(vertices, indices)
760}Trait Implementations§
impl Copy for Vertex
impl Pod for Vertex
impl StructuralPartialEq for Vertex
Auto Trait Implementations§
impl Freeze for Vertex
impl RefUnwindSafe for Vertex
impl Send for Vertex
impl Sync for Vertex
impl Unpin for Vertex
impl UnsafeUnpin for Vertex
impl UnwindSafe for Vertex
Blanket Implementations§
impl<T> AnyBitPattern for Twhere
T: Pod,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more