Skip to main content

Vertex

Struct Vertex 

Source
#[repr(C)]
pub struct Vertex { pub position: Vec3, pub normal: Vec3, pub uv: Vec2, }
Expand description

One corner of a mesh.

Fields§

§position: Vec3

Corner position, in mesh space, in meters.

§normal: Vec3

The corner’s outward direction, used for lighting.

§uv: Vec2

The texture coordinate, (0, 0) at the texture’s top left.

Implementations§

Source§

impl Vertex

Source

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
Hide additional 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§

Source§

impl Clone for Vertex

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Vertex

Source§

impl Debug for Vertex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Vertex

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Pod for Vertex

Source§

impl StructuralPartialEq for Vertex

Source§

impl Zeroable for Vertex

Source§

fn zeroed() -> Self

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

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

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> NoUninit for T
where T: Pod,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more