Skip to content

Commit

Permalink
Nannou 3d!
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Sep 29, 2024
1 parent a34a603 commit 18ac4c0
Show file tree
Hide file tree
Showing 20 changed files with 697 additions and 67 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"bevy_nannou",
"bevy_nannou_derive",
"bevy_nannou_draw",
"bevy_nannou_geom",
"bevy_nannou_isf",
"bevy_nannou_video",
"examples",
Expand Down Expand Up @@ -35,4 +36,4 @@ serde = "1"
serde_json = "1"
toml = "0.8"
serde_yaml = "0.9"
wgpu = "22.0"
wgpu = "22.0"
1 change: 1 addition & 0 deletions bevy_nannou/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
bevy = { workspace = true, features = ["jpeg"]}
bevy_nannou_draw = { path = "../bevy_nannou_draw" }
bevy_nannou_geom = { path = "../bevy_nannou_geom" }
bevy_nannou_isf = { path = "../bevy_nannou_isf", optional = true }
bevy_nannou_video = { path = "../bevy_nannou_video", optional = true }

Expand Down
9 changes: 8 additions & 1 deletion bevy_nannou/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub mod prelude {
pub use bevy_nannou_draw::text::*;
pub use bevy_nannou_draw::*;

pub use bevy_nannou_geom::geom::mesh;
pub use bevy_nannou_geom::geom::{Geometry, Geom};
pub use bevy_nannou_geom::geom::properties::*;

#[cfg(feature = "isf")]
pub use bevy_nannou_isf::prelude::*;
#[cfg(feature = "video")]
Expand All @@ -31,7 +35,10 @@ pub struct NannouPlugin;

impl Plugin for NannouPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((bevy_nannou_draw::NannouDrawPlugin,));
app.add_plugins((
bevy_nannou_draw::NannouDrawPlugin,
bevy_nannou_geom::NannouGeomPlugin,
));
#[cfg(feature = "isf")]
{
app.add_plugins(bevy_nannou_isf::NannouIsfPlugin);
Expand Down
10 changes: 10 additions & 0 deletions bevy_nannou_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ pub fn shader_model(attr: TokenStream, item: TokenStream) -> TokenStream {
#fragment_shader_impl
}
}

impl #impl_generics ::nannou::prelude::render::Material for #name #ty_generics #where_clause {
fn vertex_shader(&self) -> ::nannou::prelude::ShaderRef {
<Self as ::nannou::prelude::render::ShaderModel>::vertex_shader()
}

fn fragment_shader(&self) -> ::nannou::prelude::ShaderRef {
<Self as ::nannou::prelude::render::ShaderModel>::fragment_shader()
}
}
};

TokenStream::from(expanded)
Expand Down
10 changes: 10 additions & 0 deletions bevy_nannou_draw/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ pub trait ShaderModel:
}
}

impl ShaderModel for StandardMaterial {
fn vertex_shader() -> ShaderRef {
<Self as ShaderModel>::vertex_shader()
}

fn fragment_shader() -> ShaderRef {
<Self as ShaderModel>::fragment_shader()
}
}

pub struct NannouRenderPlugin;

impl Plugin for NannouRenderPlugin {
Expand Down
8 changes: 8 additions & 0 deletions bevy_nannou_geom/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "bevy_nannou_geom"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = { workspace = true }
bevy_nannou_draw = { path = "../bevy_nannou_draw" }
51 changes: 51 additions & 0 deletions bevy_nannou_geom/src/geom/mesh/cube.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::ops::DerefMut;
use bevy::prelude::*;
use bevy_nannou_draw::render::ShaderModel;
use crate::geom::Geometry;
use crate::geom::properties::mesh::SetMesh;

pub type CubeGeometry<'a, 'w, SM: ShaderModel> = Geometry<'a, 'w, Cube, SM>;

#[derive(Component, Deref, DerefMut, Default, Clone)]
pub struct Cube(pub Cuboid);

impl From<Cube> for Mesh {
fn from(value: Cube) -> Self {
value.0.into()
}
}

impl <'a, 'w, SM> CubeGeometry<'a, 'w, SM>
where SM: ShaderModel + Material + Default
{
pub fn x_length(mut self, length: f32) -> Self {
self.primitive().half_size.x = length / 2.0;
self
}

pub fn y_length(mut self, length: f32) -> Self {
self.primitive().half_size.y = length / 2.0;
self
}

pub fn z_length(mut self, length: f32) -> Self {
self.primitive().half_size.z = length / 2.0;
self
}

pub fn length(mut self, length: f32) -> Self {
self.primitive().half_size = Vec3::splat(length / 2.0);
self
}

pub fn dimensions(mut self, dimensions: Vec3) -> Self {
self.primitive().half_size = dimensions / 2.0;
self
}

pub fn corners(mut self, point1: Vec3, point2: Vec3) -> Self {
self.primitive().half_size = (point2 - point1).abs() / 2.0;
self
}
}

4 changes: 4 additions & 0 deletions bevy_nannou_geom/src/geom/mesh/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use bevy_nannou_draw::render::ShaderModel;
use crate::geom::Geometry;

pub mod cube;
Loading

0 comments on commit 18ac4c0

Please sign in to comment.