[−][src]Struct ggez::graphics::MeshBuilder
A builder for creating Mesh
es.
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]
&mut self,
points: &[P],
width: f32,
color: Color
) -> GameResult<&mut Self> where
P: Into<Point2<f32>> + Clone,
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]
&mut self,
mode: DrawMode,
point: P,
radius: f32,
tolerance: f32,
color: Color
) -> &mut Self where
P: Into<Point2<f32>>,
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]
&mut self,
mode: DrawMode,
point: P,
radius1: f32,
radius2: f32,
tolerance: f32,
color: Color
) -> &mut Self where
P: Into<Point2<f32>>,
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]
&mut self,
mode: DrawMode,
points: &[P],
color: Color
) -> GameResult<&mut Self> where
P: Into<Point2<f32>> + Clone,
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]
&mut self,
mode: DrawMode,
points: &[P],
color: Color
) -> GameResult<&mut Self> where
P: Into<Point2<f32>> + Clone,
Create a new mesh for a closed polygon.
pub fn rectangle(
&mut self,
mode: DrawMode,
bounds: Rect,
color: Color
) -> &mut Self
[src]
&mut self,
mode: DrawMode,
bounds: Rect,
color: Color
) -> &mut Self
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]
&mut self,
triangles: &[P],
color: Color
) -> GameResult<&mut Self> where
P: Into<Point2<f32>> + Clone,
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]
&mut self,
verts: &[V],
indices: &[u32],
texture: Option<Image>
) -> &mut Self where
V: Into<Vertex> + Clone,
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 ofverts
- Adding the
indices
orverts
would create a buffer too long to be indexed by au32
.
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 Clone for MeshBuilder
[src]
fn clone(&self) -> MeshBuilder
[src]
default fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for MeshBuilder
[src]
impl Debug for MeshBuilder
[src]
Auto Trait Implementations
impl Send for MeshBuilder
impl Sync for MeshBuilder
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Same for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<T> Erased for T
impl<T> SetParameter for T
default fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
Sets value
as a parameter of self
.