[][src]Struct ggez::graphics::MeshBuilder

pub struct MeshBuilder { /* fields omitted */ }

A builder for creating Meshes.

This allows you to easily make one Mesh containing many different complex pieces of geometry. They don't have to be connected to each other, and will all be drawn at once.

The following example shows how to build a mesh containing a line and a circle:

let mesh: Mesh = MeshBuilder::new()
    .line(&[Point2::new(20.0, 20.0), Point2::new(40.0, 20.0)], 4.0, (255, 0, 0).into())?
    .circle(DrawMode::fill(), Point2::new(60.0, 38.0), 40.0, 1.0, (0, 255, 0).into())
    .build(ctx)?;

A more sophisticated example:

use ggez::{Context, GameResult, nalgebra as na};
use ggez::graphics::{self, DrawMode, MeshBuilder};

fn draw_danger_signs(ctx: &mut Context) -> GameResult {
    // Initialize a builder instance.
    let mesh = MeshBuilder::new()
        // Add vertices for 3 lines (in an approximate equilateral triangle).
        .line(
            &[
                na::Point2::new(0.0, 0.0),
                na::Point2::new(-30.0, 52.0),
                na::Point2::new(30.0, 52.0),
                na::Point2::new(0.0, 0.0),
            ],
            1.0,
            graphics::WHITE,
        )?
        // Add vertices for an exclamation mark!
        .ellipse(DrawMode::fill(), na::Point2::new(0.0, 25.0), 2.0, 15.0, 2.0, graphics::WHITE,)
        .circle(DrawMode::fill(), na::Point2::new(0.0, 45.0), 2.0, 2.0, graphics::WHITE,)
        // Finalize then unwrap. Unwrapping via `?` operator either yields the final `Mesh`,
        // or propagates the error (note return type).
        .build(ctx)?;
    // Draw 3 meshes in a line, 1st and 3rd tilted by 1 radian.
    graphics::draw(ctx, &mesh, (na::Point2::new(50.0, 50.0), -1.0, graphics::WHITE))?;
    graphics::draw(ctx, &mesh, (na::Point2::new(150.0, 50.0), 0.0, graphics::WHITE))?;
    graphics::draw(ctx, &mesh, (na::Point2::new(250.0, 50.0), 1.0, graphics::WHITE))?;
    Ok(())
}

Methods

impl MeshBuilder[src]

pub fn new() -> Self[src]

Create a new MeshBuilder.

pub fn line<P>(
    &mut self,
    points: &[P],
    width: f32,
    color: Color
) -> GameResult<&mut Self> where
    P: Into<Point2<f32>> + Clone
[src]

Create a new mesh for a line of one or more connected segments.

pub fn circle<P>(
    &mut self,
    mode: DrawMode,
    point: P,
    radius: f32,
    tolerance: f32,
    color: Color
) -> &mut Self where
    P: Into<Point2<f32>>, 
[src]

Create a new mesh for a circle.

For the meaning of the tolerance parameter, see here.

pub fn ellipse<P>(
    &mut self,
    mode: DrawMode,
    point: P,
    radius1: f32,
    radius2: f32,
    tolerance: f32,
    color: Color
) -> &mut Self where
    P: Into<Point2<f32>>, 
[src]

Create a new mesh for an ellipse.

For the meaning of the tolerance parameter, see here.

pub fn polyline<P>(
    &mut self,
    mode: DrawMode,
    points: &[P],
    color: Color
) -> GameResult<&mut Self> where
    P: Into<Point2<f32>> + Clone
[src]

Create a new mesh for a series of connected lines.

pub fn polygon<P>(
    &mut self,
    mode: DrawMode,
    points: &[P],
    color: Color
) -> GameResult<&mut Self> where
    P: Into<Point2<f32>> + Clone
[src]

Create a new mesh for a closed polygon.

pub fn rectangle(
    &mut self,
    mode: DrawMode,
    bounds: Rect,
    color: Color
) -> &mut Self
[src]

Create a new mesh for a rectangle.

pub fn triangles<P>(
    &mut self,
    triangles: &[P],
    color: Color
) -> GameResult<&mut Self> where
    P: Into<Point2<f32>> + Clone
[src]

Create a new Mesh from a raw list of triangles.

Currently does not support UV's or indices.

pub fn texture(&mut self, texture: Image) -> &mut Self[src]

Takes an Image to apply to the mesh.

pub fn from_raw<V>(
    &mut self,
    verts: &[V],
    indices: &[u32],
    texture: Option<Image>
) -> &mut Self where
    V: Into<Vertex> + Clone
[src]

Creates a Mesh from a raw list of triangles defined from vertices and indices. You may also supply an Image to use as a texture, if you pass None, it will just use a pure white texture.

This is the most primitive mesh-creation method, but allows you full control over the tesselation and texturing. As such it will panic or produce incorrect/invalid output (that may later cause drawing to panic), if:

  • indices contains a value out of bounds of verts
  • Adding the indices or verts would create a buffer too long to be indexed by a u32.

pub fn build(&self, ctx: &mut Context) -> GameResult<Mesh>[src]

Takes the accumulated geometry and load it into GPU memory, creating a single Mesh.

Trait Implementations

impl Default for MeshBuilder[src]

impl Clone for MeshBuilder[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for MeshBuilder[src]

Auto Trait Implementations

impl Send for MeshBuilder

impl Sync for MeshBuilder

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Same for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf for SP where
    SS: SubsetOf<SP>, 

impl<T> Erased for T

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.