Skip to content

Commit

Permalink
Rustfmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Mar 21, 2024
1 parent c6a8971 commit c42474b
Show file tree
Hide file tree
Showing 19 changed files with 588 additions and 549 deletions.
991 changes: 533 additions & 458 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions bevy_nannou/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ fn startup(mut commands: Commands, assets: Res<AssetServer>, mut meshes: ResMut<
..default()
});

commands.spawn(
(Camera3dBundle {
commands.spawn((
Camera3dBundle {
camera: Camera {
hdr: true,
..Default::default()
Expand All @@ -87,19 +87,18 @@ fn startup(mut commands: Commands, assets: Res<AssetServer>, mut meshes: ResMut<
.into(),
..Default::default()
},
BloomSettings {
intensity: 0.09,
low_frequency_boost: 0.7,
low_frequency_boost_curvature: 0.95,
high_pass_frequency: 1.0,
prefilter_settings: BloomPrefilterSettings {
threshold: 0.1,
threshold_softness: 0.4,
},
composite_mode: BloomCompositeMode::Additive,
}
),
);
BloomSettings {
intensity: 0.09,
low_frequency_boost: 0.7,
low_frequency_boost_curvature: 0.95,
high_pass_frequency: 1.0,
prefilter_settings: BloomPrefilterSettings {
threshold: 0.1,
threshold_softness: 0.4,
},
composite_mode: BloomCompositeMode::Additive,
},
));

let handle = assets.load("images/nannou.png");
commands.insert_resource(MyTexture(handle));
Expand Down Expand Up @@ -134,5 +133,8 @@ fn update_draw(
.x(100.0 + time.elapsed().as_millis() as f32 / 100.0)
.w_h(100.0, 100.0)
.color(Color::SEA_GREEN);
draw.ellipse().x(-100.0).w_h(100.0, 100.0).color(Color::BISQUE);
draw.ellipse()
.x(-100.0)
.w_h(100.0, 100.0)
.color(Color::BISQUE);
}
2 changes: 1 addition & 1 deletion bevy_nannou_draw/src/draw/background.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::Color;
use crate::draw::Draw;
use bevy::prelude::Color;
use nannou_core::color::{self, IntoColor, Srgb, Srgba};

/// A type used to update the background colour.
Expand Down
12 changes: 3 additions & 9 deletions bevy_nannou_draw/src/draw/mesh/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use lyon::tessellation::geometry_builder::{
};
use lyon::tessellation::{FillVertex, GeometryBuilderError, StrokeVertex, VertexId};

use crate::draw::mesh::MeshExt;
use bevy::prelude::*;
use bevy::render::mesh::Indices;
use bevy::render::render_resource::encase::private::RuntimeSizedArray;
use crate::draw::mesh::MeshExt;

pub struct MeshBuilder<'a, A> {
/// The mesh that is to be extended.
Expand Down Expand Up @@ -48,11 +48,7 @@ impl<'a, A> MeshBuilder<'a, A> {

impl<'a> MeshBuilder<'a, SingleColor> {
/// Begin extending a mesh rendered with a single colour.
pub fn single_color(
mesh: &'a mut Mesh,
transform: Mat4,
color: Color,
) -> Self {
pub fn single_color(mesh: &'a mut Mesh, transform: Mat4, color: Color) -> Self {
Self::new(mesh, transform, SingleColor(color))
}
}
Expand Down Expand Up @@ -99,7 +95,6 @@ impl<'a, A> GeometryBuilder for MeshBuilder<'a, A> {
indices.push(c.to_usize() as u32);
}
}

}
}

Expand Down Expand Up @@ -169,7 +164,7 @@ impl<'a> FillGeometryBuilder for MeshBuilder<'a, ColorPerPoint> {
let p = Vec2::new(position.x, position.y).extend(0.0);
let point = self.transform.transform_point3(p);
let col = vertex.interpolated_attributes();
let color= Vec4::new(col[0], col[1], col[2], col[3]);
let color = Vec4::new(col[0], col[1], col[2], col[3]);
let tex_coords = Vec2::ZERO;

self.mesh.points_mut().push(point.to_array());
Expand Down Expand Up @@ -228,7 +223,6 @@ impl<'a> FillGeometryBuilder for MeshBuilder<'a, TexCoordsPerPoint> {
self.mesh.colors_mut().push(color.as_linear_rgba_f32());
self.mesh.tex_coords_mut().push(tex_coords.to_array());


// Return the index.
Ok(id)
}
Expand Down
8 changes: 3 additions & 5 deletions bevy_nannou_draw/src/draw/mesh/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Items related to the custom mesh type used by the `Draw` API.
use bevy::prelude::*;
use std::ops::{Deref, DerefMut};
use bevy::render::mesh::{Indices, PrimitiveTopology, VertexAttributeValues};
use nannou_mesh::{ClearIndices, ClearVertices};
use std::ops::{Deref, DerefMut};

pub mod builder;

Expand Down Expand Up @@ -31,8 +31,7 @@ impl MeshExt for Mesh {

fn init_with_topology(topology: PrimitiveTopology) -> Mesh {
let mesh = Mesh::new(topology);
mesh
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, Vec::<[f32; 3]>::new())
mesh.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, Vec::<[f32; 3]>::new())
.with_inserted_attribute(Mesh::ATTRIBUTE_COLOR, Vec::<[f32; 4]>::new())
.with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, Vec::<[f32; 2]>::new())
.with_indices(Some(Indices::U32(vec![])))
Expand Down Expand Up @@ -115,7 +114,6 @@ impl MeshExt for Mesh {
}
}


fn count_indices(&self) -> usize {
match self.indices() {
Some(Indices::U32(indices)) => indices.len(),
Expand All @@ -129,4 +127,4 @@ impl MeshExt for Mesh {
_ => panic!("Mesh must have U32 indices"),
}
}
}
}
2 changes: 1 addition & 1 deletion bevy_nannou_draw/src/draw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use std::mem;
use std::rc::Rc;
use std::sync::{Arc, RwLock};

use crate::draw::mesh::MeshExt;
use bevy::prelude::*;
use bevy::render::render_resource as wgpu;
use lyon::path::PathEvent;
use nannou_core::geom;
use nannou_mesh::Clear;
use crate::draw::mesh::MeshExt;

pub use self::background::Background;
pub use self::drawing::{Drawing, DrawingContext};
Expand Down
14 changes: 6 additions & 8 deletions bevy_nannou_draw/src/draw/primitive/mesh.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::draw::mesh::MeshExt;
use crate::draw::primitive::{Primitive, Vertex};
use crate::draw::properties::spatial::{orientation, position};
use crate::draw::properties::{SetColor, SetOrientation, SetPosition};
use crate::draw::{self, Drawing};
use bevy::prelude::*;
use bevy::render::mesh::Indices;
use nannou_core::{color, geom};
use std::ops;
use bevy::render::mesh::Indices;
use crate::draw::mesh::MeshExt;
/// The mesh type prior to being initialised with vertices or indices.
#[derive(Clone, Debug, Default)]
pub struct Vertexless;
Expand Down Expand Up @@ -116,12 +116,12 @@ impl Vertexless {
vertex_mode: draw::render::VertexMode,
texture_handle: Option<Handle<Image>>,
) -> PrimitiveMesh
where I: Iterator<Item = Vertex>,
where
I: Iterator<Item = Vertex>,
{
let v_start = inner_mesh.count_vertices();
let i_start = inner_mesh.count_indices();
for (i,(point, color, tex_coords)) in vertices.enumerate() {

for (i, (point, color, tex_coords)) in vertices.enumerate() {
inner_mesh.points_mut().push(point.to_array());
inner_mesh.colors_mut().push(color.as_linear_rgba_f32());
inner_mesh.tex_coords_mut().push(tex_coords.to_array());
Expand Down Expand Up @@ -522,9 +522,7 @@ impl draw::render::RenderPrimitive for PrimitiveMesh {
match fill_color {
Some(fill) => {
let theme_prim = draw::theme::Primitive::Mesh;
let color = fill
.0
.unwrap_or_else(|| ctxt.theme.fill(&theme_prim));
let color = fill.0.unwrap_or_else(|| ctxt.theme.fill(&theme_prim));
let vertices = vertex_range.map(|i| {
let point = transform_point(ctxt.intermediary_mesh.points()[i].into());
let tex_coords: Vec2 = ctxt.intermediary_mesh.tex_coords()[i].into();
Expand Down
6 changes: 2 additions & 4 deletions bevy_nannou_draw/src/draw/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ pub mod text;
pub mod texture;
pub mod tri;

use bevy::prelude::Color;
use nannou_core::geom::{Vec2, Vec3};
pub use self::arrow::Arrow;
pub use self::ellipse::Ellipse;
pub use self::line::Line;
Expand All @@ -23,11 +21,11 @@ pub use self::rect::Rect;
pub use self::text::Text;
pub use self::texture::Texture;
pub use self::tri::Tri;

use bevy::prelude::Color;
use nannou_core::geom::{Vec2, Vec3};

type Vertex = (Vec3, Color, Vec2);


/// A wrapper around all primitive sets of properties so that they may be stored within the
/// **Draw**'s `drawing` field while they are being drawn.
///
Expand Down
9 changes: 2 additions & 7 deletions bevy_nannou_draw/src/draw/primitive/path.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::draw::primitive::Primitive;
use crate::draw::properties::spatial::{orientation, position};
use crate::draw::properties::{
SetColor, SetFill, SetOrientation, SetPosition, SetStroke,
};
use crate::draw::properties::{SetColor, SetFill, SetOrientation, SetPosition, SetStroke};
use crate::draw::{self, Drawing, DrawingContext};
use bevy::prelude::*;
use lyon::path::PathEvent;
Expand Down Expand Up @@ -289,13 +287,10 @@ where
..
} = ctxt;
let start = path_points_colored_buffer.len();
let points = points
.into_iter()
.map(|(p, c)| (p.into(), c.into()));
let points = points.into_iter().map(|(p, c)| (p.into(), c.into()));

path_points_colored_buffer.extend(points);


let end = path_points_colored_buffer.len();
let path_event_src = PathEventSource::ColoredPoints {
range: start..end,
Expand Down
11 changes: 3 additions & 8 deletions bevy_nannou_draw/src/draw/primitive/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::draw::drawing::DrawingContext;
use crate::draw::primitive::path::{self, PathEventSource};
use crate::draw::primitive::Primitive;
use crate::draw::properties::spatial::{orientation, position};
use crate::draw::properties::{
SetColor, SetOrientation, SetPosition, SetStroke,
};
use crate::draw::properties::{SetColor, SetOrientation, SetPosition, SetStroke};
use crate::draw::{self, Drawing};
use bevy::prelude::*;
use lyon::path::PathEvent;
Expand Down Expand Up @@ -125,9 +123,7 @@ impl PolygonInit {
..
} = ctxt;
let start = path_points_colored_buffer.len();
let points = points
.into_iter()
.map(|(p, c)| (p.into(), c.into()));
let points = points.into_iter().map(|(p, c)| (p.into(), c.into()));
path_points_colored_buffer.extend(points);

let end = path_points_colored_buffer.len();
Expand Down Expand Up @@ -385,8 +381,7 @@ impl Polygon {
);
}
PathEventSource::ColoredPoints { range, close } => {
let color =
stroke_color.unwrap_or_else(|| theme.stroke(theme_primitive));
let color = stroke_color.unwrap_or_else(|| theme.stroke(theme_primitive));
let mut points_colored = path_points_colored_buffer[range]
.iter()
.cloned()
Expand Down
4 changes: 1 addition & 3 deletions bevy_nannou_draw/src/draw/primitive/rect.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::draw::primitive::polygon::{self, PolygonInit, PolygonOptions, SetPolygon};
use crate::draw::primitive::Primitive;
use crate::draw::properties::spatial::{dimension, orientation, position};
use crate::draw::properties::{
SetColor, SetDimensions, SetOrientation, SetPosition, SetStroke,
};
use crate::draw::properties::{SetColor, SetDimensions, SetOrientation, SetPosition, SetStroke};
use crate::draw::{self, Drawing};
use bevy::prelude::*;
use lyon::tessellation::StrokeOptions;
Expand Down
11 changes: 3 additions & 8 deletions bevy_nannou_draw/src/draw/primitive/text.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::draw::drawing::DrawingContext;
use crate::draw::mesh::MeshExt;
use crate::draw::primitive::{Primitive, Vertex};
use crate::draw::properties::spatial::{self, dimension, orientation, position};
use crate::draw::properties::{
SetColor, SetDimensions, SetOrientation, SetPosition,
};
use crate::draw::properties::{SetColor, SetDimensions, SetOrientation, SetPosition};
use crate::draw::{self, theme, Drawing};
use crate::text::{self, Align, Font, FontSize, Justify, Layout, Scalar, Wrap};
use bevy::prelude::*;
use nannou_core::geom;
use crate::draw::mesh::MeshExt;

/// Properties related to drawing the **Text** primitive.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -251,10 +249,7 @@ impl<'a> DrawingText<'a> {
I: IntoIterator<Item = C>,
C: Into<Color>,
{
let glyph_colors = glyph_colors
.into_iter()
.map(|c| c.into())
.collect();
let glyph_colors = glyph_colors.into_iter().map(|c| c.into()).collect();

self.map_ty(|ty| ty.glyph_colors(glyph_colors))
}
Expand Down
4 changes: 1 addition & 3 deletions bevy_nannou_draw/src/draw/primitive/tri.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::draw::primitive::polygon::{self, PolygonInit, PolygonOptions, SetPolygon};
use crate::draw::primitive::Primitive;
use crate::draw::properties::spatial::{dimension, orientation, position};
use crate::draw::properties::{
SetColor, SetDimensions, SetOrientation, SetPosition, SetStroke,
};
use crate::draw::properties::{SetColor, SetDimensions, SetOrientation, SetPosition, SetStroke};
use crate::draw::{self, Drawing};
use bevy::prelude::*;
use lyon::tessellation::StrokeOptions;
Expand Down
10 changes: 3 additions & 7 deletions bevy_nannou_draw/src/draw/properties/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,17 @@ pub trait SetColor: Sized {
}

/// Specify the color via red, green and blue channels as bytes
fn rgb8(self, r: u8, g: u8, b: u8) -> Self

{
fn rgb8(self, r: u8, g: u8, b: u8) -> Self {
self.color(Color::rgb_u8(r, g, b))
}

/// Specify the color via red, green, blue and alpha channels.
fn rgba(self, r: f32, g: f32, b: f32, a: f32) -> Self
{
fn rgba(self, r: f32, g: f32, b: f32, a: f32) -> Self {
self.color(Color::rgba(r, g, b, a))
}

/// Specify the color via red, green, blue and alpha channels as bytes
fn rgba8(self, r: u8, g: u8, b: u8, a: u8) -> Self
{
fn rgba8(self, r: u8, g: u8, b: u8, a: u8) -> Self {
self.color(Color::rgba_u8(r, g, b, a))
}

Expand Down
3 changes: 1 addition & 2 deletions bevy_nannou_draw/src/draw/theme.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use bevy::prelude::Color;
use std::collections::HashMap;

/// A set of styling defaults used for coloring texturing geometric primitives that have no entry
/// within the **Draw**'s inner **ColorMap**.
Expand Down Expand Up @@ -47,7 +47,6 @@ impl Theme {
.unwrap_or(self.fill_color.default)
}


/// Retrieve the stroke color representation for the given primitive.
pub fn stroke(&self, prim: &Primitive) -> Color {
self.stroke_color
Expand Down
4 changes: 1 addition & 3 deletions bevy_nannou_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ fn update_draw_mesh(
// Get or spawn the mesh and material.
let (mesh, material) = match mesh_q.iter().nth(i) {
// We already have a mesh and material for this index.
Some((mesh, material)) => {
(mesh.clone(), material.clone())
}
Some((mesh, material)) => (mesh.clone(), material.clone()),
// We need to spawn a new mesh and material for this index.
None => {
let mesh = Mesh::init_with_topology(curr_ctxt.topology);
Expand Down
4 changes: 2 additions & 2 deletions nannou/src/draw/mesh/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ impl<'a> MeshBuilder<'a, TexCoordsPerPoint> {
impl<'a, A> GeometryBuilder for MeshBuilder<'a, A> {
fn begin_geometry(&mut self) {
self.begin_vertex_count = self.mesh.points().len() as u32;
self.begin_index_count = self.mesh.count_indices() as u32;
self.begin_index_count = self.mesh.indices().len() as u32;
}

fn end_geometry(&mut self) -> geometry_builder::Count {
geometry_builder::Count {
vertices: self.mesh.points().len() as u32 - self.begin_vertex_count,
indices: self.mesh.count_indices() as u32 - self.begin_index_count,
indices: self.mesh.indices().len() as u32 - self.begin_index_count,
}
}

Expand Down
Loading

0 comments on commit c42474b

Please sign in to comment.