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: BrushStrokeThe pixel and brush data of the in-progress stroke.
Implementations§
Source§impl BrushContext
impl BrushContext
Sourcepub fn brush(&self) -> &Brush
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.
Sourcepub fn shape(&mut self) -> &mut BrushShape
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.
Sourcepub fn mode(&mut self) -> &mut BrushMode
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.
Sourcepub fn hardness(&mut self) -> &mut f32
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.
Sourcepub fn alpha(&mut self) -> &mut f32
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.
Sourcepub fn start_stroke(&mut self, terrain: &Terrain, brush: Brush)
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.
Sourcepub fn stamp(&mut self, terrain: &Terrain, position: Vector3<f32>)
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.
Sourcepub fn smear(
&mut self,
terrain: &Terrain,
start: Vector3<f32>,
end: Vector3<f32>,
)
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.
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Update the terrain’s textures to include the latest pixel data without ending the stroke.
Sourcepub fn end_stroke(&mut self)
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
impl Default for BrushContext
Source§fn default() -> BrushContext
fn default() -> BrushContext
Auto Trait Implementations§
impl Freeze for BrushContext
impl !RefUnwindSafe for BrushContext
impl Send for BrushContext
impl !Sync for BrushContext
impl Unpin for BrushContext
impl !UnwindSafe for BrushContext
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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 Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.