Skip to main content

SurfaceMeshRenderData

Struct SurfaceMeshRenderData 

Source
pub struct SurfaceMeshRenderData {
    pub vertex_buffer: Buffer,
    pub index_buffer: Buffer,
    pub normal_buffer: Buffer,
    pub barycentric_buffer: Buffer,
    pub color_buffer: Buffer,
    pub edge_is_real_buffer: Buffer,
    pub uniform_buffer: Buffer,
    pub bind_group: BindGroup,
    pub num_triangles: u32,
    pub num_indices: u32,
    pub shadow_bind_group: Option<BindGroup>,
    pub shadow_model_buffer: Option<Buffer>,
}
Expand description

GPU resources for rendering a surface mesh.

Fields§

§vertex_buffer: Buffer

Position buffer (storage buffer, vec4 for alignment).

§index_buffer: Buffer

Index buffer (triangle indices).

§normal_buffer: Buffer

Normal buffer (vertex normals, vec4 for alignment).

§barycentric_buffer: Buffer

Barycentric coordinate buffer for wireframe rendering. Each triangle vertex gets [1,0,0], [0,1,0], [0,0,1].

§color_buffer: Buffer

Color buffer (per-vertex colors for quantities, vec4).

§edge_is_real_buffer: Buffer

Edge is real buffer - marks which edges are real polygon edges vs triangulation internal.

§uniform_buffer: Buffer

Uniform buffer for mesh-specific settings.

§bind_group: BindGroup

Bind group for this surface mesh.

§num_triangles: u32

Number of triangles.

§num_indices: u32

Number of indices (num_triangles * 3).

§shadow_bind_group: Option<BindGroup>

Shadow pass bind group (for rendering to shadow map).

§shadow_model_buffer: Option<Buffer>

Shadow model uniform buffer (contains only model matrix).

Implementations§

Source§

impl SurfaceMeshRenderData

Source

pub fn new( device: &Device, bind_group_layout: &BindGroupLayout, camera_buffer: &Buffer, vertices: &[Vec3], triangles: &[[u32; 3]], vertex_normals: &[Vec3], edge_is_real: &[Vec3], ) -> Self

Creates new render data from mesh geometry.

§Arguments
  • device - The wgpu device
  • bind_group_layout - The bind group layout for surface meshes
  • camera_buffer - The camera uniform buffer
  • vertices - Vertex positions
  • triangles - Triangle indices (each [u32; 3] is one triangle)
  • vertex_normals - Per-vertex normals
  • edge_is_real - Per-triangle-vertex flags marking real polygon edges vs internal triangulation edges
Source

pub fn update_uniforms(&self, queue: &Queue, uniforms: &MeshUniforms)

Updates the mesh uniform buffer.

Source

pub fn update_colors( &self, queue: &Queue, colors: &[Vec4], triangles: &[[u32; 3]], )

Updates the per-vertex color buffer with per-original-vertex colors. This expands the colors to match the per-triangle-vertex buffer layout.

Source

pub fn clear_colors(&self, queue: &Queue)

Clears the color buffer (sets all colors to zero, which means use surface_color).

Source

pub fn init_shadow_resources( &mut self, device: &Device, shadow_bind_group_layout: &BindGroupLayout, light_buffer: &Buffer, )

Initializes shadow rendering resources.

Creates the bind group and model buffer needed for the shadow pass. The shadow pass renders this mesh from the light’s perspective to create shadows on the ground plane.

Source

pub fn has_shadow_resources(&self) -> bool

Returns whether shadow resources have been initialized.

Source

pub fn num_vertices(&self) -> u32

Returns the number of vertices for shadow pass rendering.

The shadow pass uses non-indexed drawing with storage buffers, so this returns the number of expanded triangle vertices.

Source

pub fn update_shadow_model(&self, queue: &Queue, model_matrix: [[f32; 4]; 4])

Updates the shadow model uniform buffer with the current transform.

This should be called whenever the mesh’s transform changes to ensure shadows are rendered at the correct position.

Source

pub fn uniform_buffer(&self) -> &Buffer

Returns the uniform buffer.

Source

pub fn position_buffer(&self) -> &Buffer

Returns the position buffer.

Source

pub fn normal_buffer(&self) -> &Buffer

Returns the normal buffer.

Source

pub fn barycentric_buffer(&self) -> &Buffer

Returns the barycentric buffer.

Source

pub fn color_buffer(&self) -> &Buffer

Returns the color buffer.

Source

pub fn edge_is_real_buffer(&self) -> &Buffer

Returns the edge is real buffer.

Source

pub fn vertex_count(&self) -> u32

Returns the number of vertices (for non-indexed drawing).

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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