pub struct SceneDrawingContext {
pub lines: Vec<Line>,
}
Expand description
Drawing context for simple graphics, it allows you to draw simple figures using a set of lines. Most common use of the context is to draw some debug geometry in your game, draw physics info (contacts, meshes, shapes, etc.), draw temporary geometry in editor and so on.
This drawing context is meant to be used only for debugging purposes, it draws everything as set of lines and no solid faces supported.
It should be noted that the actual drawing is not immediate, provided methods just populate internal array of lines and it will be drawn on special render stage.
§Example
The usage of the drawing context is a bit unusual, at the beginning of the frame you should clear the contents of the context and only then call “drawing” methods. Otherwise, the internal buffer will increase in size to values which will take lots of time draw and the FPS will significantly drop with every frame until it reaches zero.
So typical usage would be:
fn draw_debug_objects(ctx: &mut SceneDrawingContext) {
// Clear at the beginning of the frame.
ctx.clear_lines();
// Draw something.
ctx.draw_cone(20, 1.0, 2.0, Matrix4::identity(), Color::WHITE, true);
}
You could avoid calling clear_lines
in specific cases where your debug geometry is not changing, then
the context could be populated once and rendered multiple times without any issues. Another case when
you could not call clear_lines
each frame, is “tracing” scenario - for example you may need to trace
moving objects. In this case call clear_lines
once in a few seconds, and you’ll see the “track” of
moving objects.
§Rendering performance
The engine renders the entire set of lines in a single draw call, so it very fast - you should be able to draw up to few millions of lines without any significant performance issues.
Fields§
§lines: Vec<Line>
List of lines to draw.
Implementations§
Source§impl SceneDrawingContext
impl SceneDrawingContext
Sourcepub fn draw_frustum(&mut self, frustum: &Frustum, color: Color)
pub fn draw_frustum(&mut self, frustum: &Frustum, color: Color)
Draws frustum with given color.
Sourcepub fn draw_aabb(&mut self, aabb: &AxisAlignedBoundingBox, color: Color)
pub fn draw_aabb(&mut self, aabb: &AxisAlignedBoundingBox, color: Color)
Draws axis-aligned bounding box with given color.
Sourcepub fn draw_oob(
&mut self,
aabb: &AxisAlignedBoundingBox,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_oob( &mut self, aabb: &AxisAlignedBoundingBox, transform: Matrix4<f32>, color: Color, )
Draws object-oriented bounding box with given color.
Sourcepub fn draw_transform(&mut self, matrix: Matrix4<f32>)
pub fn draw_transform(&mut self, matrix: Matrix4<f32>)
Draws transform as basis vectors.
Sourcepub fn draw_triangle(
&mut self,
a: Vector3<f32>,
b: Vector3<f32>,
c: Vector3<f32>,
color: Color,
)
pub fn draw_triangle( &mut self, a: Vector3<f32>, b: Vector3<f32>, c: Vector3<f32>, color: Color, )
Draws a triangle by given points.
Sourcepub fn draw_pyramid(
&mut self,
top: Vector3<f32>,
a: Vector3<f32>,
b: Vector3<f32>,
c: Vector3<f32>,
d: Vector3<f32>,
color: Color,
transform: Matrix4<f32>,
)
pub fn draw_pyramid( &mut self, top: Vector3<f32>, a: Vector3<f32>, b: Vector3<f32>, c: Vector3<f32>, d: Vector3<f32>, color: Color, transform: Matrix4<f32>, )
Draws a pyramid by given points.
Sourcepub fn draw_wire_sphere(
&mut self,
position: Vector3<f32>,
radius: f32,
segments: usize,
color: Color,
)
pub fn draw_wire_sphere( &mut self, position: Vector3<f32>, radius: f32, segments: usize, color: Color, )
Draws a sphere as a set of three circles around each axes.
Sourcepub fn draw_circle(
&mut self,
position: Vector3<f32>,
radius: f32,
segments: usize,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_circle( &mut self, position: Vector3<f32>, radius: f32, segments: usize, transform: Matrix4<f32>, color: Color, )
Draws a circle at given world-space position with given radius. segments
could be used
to control quality of the circle.
Sourcepub fn draw_circle_segment(
&mut self,
position: Vector3<f32>,
radius: f32,
segments: usize,
begin_angle: f32,
end_angle: f32,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_circle_segment( &mut self, position: Vector3<f32>, radius: f32, segments: usize, begin_angle: f32, end_angle: f32, transform: Matrix4<f32>, color: Color, )
Draws a circle segment between two given angles. Center of the segment is defined by position
,
segments
defines quality of the shape.
Sourcepub fn draw_rectangle(
&mut self,
half_width: f32,
half_height: f32,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_rectangle( &mut self, half_width: f32, half_height: f32, transform: Matrix4<f32>, color: Color, )
Draws a rectangle with given width and height.
Sourcepub fn draw_sphere(
&mut self,
position: Vector3<f32>,
slices: usize,
stacks: usize,
radius: f32,
color: Color,
)
pub fn draw_sphere( &mut self, position: Vector3<f32>, slices: usize, stacks: usize, radius: f32, color: Color, )
Draws a wire sphere with given parameters.
Sourcepub fn draw_sphere_section(
&mut self,
radius: f32,
theta_range: Range<f32>,
theta_steps: usize,
phi_range: Range<f32>,
phi_steps: usize,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_sphere_section( &mut self, radius: f32, theta_range: Range<f32>, theta_steps: usize, phi_range: Range<f32>, phi_steps: usize, transform: Matrix4<f32>, color: Color, )
Draws a wire sphere with given parameters.
Sourcepub fn draw_cone(
&mut self,
sides: usize,
r: f32,
h: f32,
transform: Matrix4<f32>,
color: Color,
cap: bool,
)
pub fn draw_cone( &mut self, sides: usize, r: f32, h: f32, transform: Matrix4<f32>, color: Color, cap: bool, )
Draws a wire Y oriented cone where the tip is on +Y with given parameters.
Sourcepub fn draw_cylinder(
&mut self,
sides: usize,
r: f32,
h: f32,
caps: bool,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_cylinder( &mut self, sides: usize, r: f32, h: f32, caps: bool, transform: Matrix4<f32>, color: Color, )
Draws a wire cylinder with given parameters.
Sourcepub fn draw_flat_capsule(
&mut self,
radius: f32,
height: f32,
segments: usize,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_flat_capsule( &mut self, radius: f32, height: f32, segments: usize, transform: Matrix4<f32>, color: Color, )
Draws a flat capsule with given height and radius. segments
defines quality of the shape.
Sourcepub fn draw_capsule(
&mut self,
radius: f32,
height: f32,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_capsule( &mut self, radius: f32, height: f32, transform: Matrix4<f32>, color: Color, )
Draws vertical capsule with given radius and height and then applies given transform.
Sourcepub fn draw_segment_flat_capsule(
&mut self,
begin: Vector2<f32>,
end: Vector2<f32>,
radius: f32,
segments: usize,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_segment_flat_capsule( &mut self, begin: Vector2<f32>, end: Vector2<f32>, radius: f32, segments: usize, transform: Matrix4<f32>, color: Color, )
Draws a flat capsule between two points with given radius. segments
defines quality of
the shape.
Sourcepub fn draw_segment_capsule(
&mut self,
begin: Vector3<f32>,
end: Vector3<f32>,
radius: f32,
v_segments: usize,
h_segments: usize,
transform: Matrix4<f32>,
color: Color,
)
pub fn draw_segment_capsule( &mut self, begin: Vector3<f32>, end: Vector3<f32>, radius: f32, v_segments: usize, h_segments: usize, transform: Matrix4<f32>, color: Color, )
Draws capsule between two points with given tesselation and then applies given transform to all points.
Sourcepub fn draw_arrow(
&mut self,
sides: usize,
color: Color,
length: f32,
radius: f32,
transform: Matrix4<f32>,
)
pub fn draw_arrow( &mut self, sides: usize, color: Color, length: f32, radius: f32, transform: Matrix4<f32>, )
Draws an Y+ oriented arrow with the given parameters.
Sourcepub fn clear_lines(&mut self)
pub fn clear_lines(&mut self)
Removes all lines from internal buffer. For dynamic drawing you should call it every update tick of your application.
Trait Implementations§
Source§impl Clone for SceneDrawingContext
impl Clone for SceneDrawingContext
Source§fn clone(&self) -> SceneDrawingContext
fn clone(&self) -> SceneDrawingContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SceneDrawingContext
impl Debug for SceneDrawingContext
Source§impl DebugRenderBackend for SceneDrawingContext
impl DebugRenderBackend for SceneDrawingContext
Source§fn draw_line(
&mut self,
_object: DebugRenderObject<'_>,
a: Point<f32>,
b: Point<f32>,
color: [f32; 4],
)
fn draw_line( &mut self, _object: DebugRenderObject<'_>, a: Point<f32>, b: Point<f32>, color: [f32; 4], )
Source§fn filter_object(&self, _object: DebugRenderObject<'_>) -> bool
fn filter_object(&self, _object: DebugRenderObject<'_>) -> bool
Source§impl DebugRenderBackend for SceneDrawingContext
impl DebugRenderBackend for SceneDrawingContext
Source§fn draw_line(
&mut self,
_object: DebugRenderObject<'_>,
a: Point<f32>,
b: Point<f32>,
color: [f32; 4],
)
fn draw_line( &mut self, _object: DebugRenderObject<'_>, a: Point<f32>, b: Point<f32>, color: [f32; 4], )
Source§fn filter_object(&self, _object: DebugRenderObject<'_>) -> bool
fn filter_object(&self, _object: DebugRenderObject<'_>) -> bool
Source§impl Default for SceneDrawingContext
impl Default for SceneDrawingContext
Source§fn default() -> SceneDrawingContext
fn default() -> SceneDrawingContext
Auto Trait Implementations§
impl Freeze for SceneDrawingContext
impl RefUnwindSafe for SceneDrawingContext
impl Send for SceneDrawingContext
impl Sync for SceneDrawingContext
impl Unpin for SceneDrawingContext
impl UnwindSafe for SceneDrawingContext
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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<T> ScriptMessagePayload for T
impl<T> ScriptMessagePayload for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self
as &dyn Any
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self
as &dyn Any
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.