BrushContext

Struct BrushContext 

Source
pub struct BrushContext {
    pub value: Option<f32>,
    pub stroke: BrushStroke,
}
Expand description

An object representing the state of a terrain brush being used from code. It has methods for starting, stopping, stamping, and smearing.

Each BrushContext requires some amount of heap allocation, so it may be preferable to reuse a BrushContext for multiple strokes when possible.

A single brush stroke can include multiple operations across multiple frames, but the terrain’s texture resources should not be replaced during a stroke because the BrushContext holds references the the texture resources that the terrain had when the stroke started, and any brush operations will be applied to those textures regardless of replacing the textures in the terrain.

Fields§

§value: Option<f32>

Parameter value for the brush. For flattening, this is the target height. For flattening, it starts as None and then is given a value based on the first stamp or smear.

§stroke: BrushStroke

The pixel and brush data of the in-progress stroke.

Implementations§

Source§

impl BrushContext

Source

pub fn brush(&self) -> &Brush

The current brush. This is immutable access only, because the brush’s target may only be changed through BrushContext::start_stroke.

Mutable access to the brush’s other properties is available through BrushContext::shape, BrushContext::mode, BrushContext::hardness, and BrushContext::alpha.

Source

pub fn shape(&mut self) -> &mut BrushShape

Mutable access to the brush’s shape. This allows the shape of the brush to change without starting a new stroke.

Source

pub fn mode(&mut self) -> &mut BrushMode

Mutable access to the brush’s mode. This allows the mode of the brush to change without starting a new stroke.

Source

pub fn hardness(&mut self) -> &mut f32

Mutable access to the brush’s hardness. This allows the hardness of the brush to change without starting a new stroke.

Source

pub fn alpha(&mut self) -> &mut f32

Mutable access to the brush’s alpha. This allows the alpha of the brush to change without starting a new stroke.

Source

pub fn start_stroke(&mut self, terrain: &Terrain, brush: Brush)

Modify the given BrushStroke so that it is using the given Brush and it is modifying the given terrain. The BrushContext will now hold references to the textures of this terrain for the target of the given brush, and so the stroke should not be used with other terrains until the stroke is finished.

  • terrain: The terrain that this stroke will edit.
  • brush: The Brush containing the brush shape and painting operation to perform.
Source

pub fn stamp(&mut self, terrain: &Terrain, position: Vector3<f32>)

Modify the brushstroke to include a stamp of the brush at the given position. The location of the stamp relative to the textures is determined based on the global position of the terrain and the size of each terrain pixel.

  • terrain: The terrain that will be used to translate the given world-space coordinates into texture-space coordinates. This should be the same terrain as was given to BrushContext::start_stroke.
  • position: The position of the brush in world coordinates.
Source

pub fn smear( &mut self, terrain: &Terrain, start: Vector3<f32>, end: Vector3<f32>, )

Modify the brushstroke to include a smear of the brush from start to end. The location of the smear relative to the textures is determined based on the global position of the terrain and the size of each terrain pixel.

  • terrain: The terrain that will be used to translate the given world-space coordinates into texture-space coordinates. This should be the same terrain as was given to BrushContext::start_stroke.
  • start: The start of the brush in world coordinates.
  • end: The end of the brush in world coordinates.
Source

pub fn flush(&mut self)

Update the terrain’s textures to include the latest pixel data without ending the stroke.

Source

pub fn end_stroke(&mut self)

Update the terrain’s textures to include the latest data and clear this context of all pixel data to prepare for starting another stroke.

Trait Implementations§

Source§

impl Default for BrushContext

Source§

fn default() -> BrushContext

Returns the “default value” for a type. Read more

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> AsyncTaskResult for T
where T: Any + Send + 'static,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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> 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 for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

impl<T> FieldValue for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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