Skip to content

Commit

Permalink
release 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
foxzool committed Feb 20, 2024
1 parent d6f6c52 commit d0bdfcf
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 91 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [0.5.0] - 2024-02-20

* bump bevy version to `0.13`

## [0.4.0] - 2023-11-06

* bump bevy version to `0.12`
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"
keywords = ["camera", "v4l2", "opencv", "vision"]
categories = ["multimedia", "rendering"]
license = "MIT OR Apache-2.0"
version = "0.4.0"
version = "0.5.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -18,14 +18,14 @@ native = ["nokhwa/input-native"]

[dependencies]
anyhow = "1.0.66"
bevy = { version = "0.12.0", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_winit", "bevy_pbr", "x11", "png", "tonemapping_luts"] }
bevy = { version = "0.13.0", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_winit", "bevy_pbr", "x11", "png", "tonemapping_luts"] }
bytemuck = { version = "1.7.0" }
flume = "0.10.11"
flume = "0.11.0"
image = { version = "0.24", default-features = false, features = [] }
nokhwa = { version = "0.10", features = ["input-native", "output-threaded"] }

[dev-dependencies]
bevy_egui = "0.23.0"
bevy_egui = "0.25.0"



Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ fn setup_camera(

| bevy | bevy_nokhwa |
|------|-------------|
| 0.13 | 0.5.X |
| 0.12 | 0.4.X |
| 0.11 | 0.3.X |
| 0.10 | 0.2.X |
| 0.9 | 0.1.X |

# Licensing
The project is under dual license MIT and Apache 2.0, so joink to your hearts content, just remember the license agreements.
The project is under dual license MIT and Apache 2.0, so join to your hearts content, just remember the license agreements.

# Contributing
Yes this project is still very much WIP, so PRs are very welcome
9 changes: 2 additions & 7 deletions examples/native.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bevy::core_pipeline::clear_color::ClearColorConfig;
use bevy::prelude::*;
use bevy_nokhwa::camera::BackgroundCamera;
use bevy_nokhwa::nokhwa::utils::ApiBackend;
Expand Down Expand Up @@ -31,14 +30,10 @@ fn setup_camera(
) {
commands
.spawn(Camera3dBundle {
camera_3d: Camera3d {
clear_color: ClearColorConfig::None,
..default()
},
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
})
// auto find camera and use highest resolution
// auto find camera and use the highest resolution
// .insert(BackgroundCamera::auto())
.insert(
BackgroundCamera::new(
Expand All @@ -55,7 +50,7 @@ fn setup_camera(

// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(StandardMaterial {
base_color: Color::SEA_GREEN,
unlit: true,
Expand Down
7 changes: 1 addition & 6 deletions examples/setting.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extern crate core;

use bevy::core_pipeline::clear_color::ClearColorConfig;
use bevy::prelude::*;
use bevy_egui::egui;
use bevy_egui::{EguiContexts, EguiPlugin};
Expand Down Expand Up @@ -32,14 +31,10 @@ fn main() {
fn setup_camera(mut commands: Commands) {
commands
.spawn(Camera3dBundle {
camera_3d: Camera3d {
clear_color: ClearColorConfig::None,
..default()
},
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
})
// auto find camera and use highest resolution
// auto find camera and use the highest resolution
// .insert(BackgroundCamera::auto())
.insert(
BackgroundCamera::new(
Expand Down
118 changes: 58 additions & 60 deletions src/background.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use crate::camera::BackgroundCamera;
use bevy::prelude::*;
use bevy::render::extract_resource::ExtractResource;
use bevy::render::render_graph::Node;
use bevy::render::render_graph::{Node, RenderLabel, RenderSubGraph};
use bevy::render::render_graph::{NodeRunError, RenderGraphContext, SlotInfo};
use bevy::render::render_resource::{
AddressMode, BindGroup, BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntry,
BindingType, BlendComponent, BlendState, Buffer, BufferAddress, BufferInitDescriptor,
BufferUsages, ColorTargetState, ColorWrites, Extent3d, Face, FilterMode, FrontFace,
ImageCopyTexture, ImageDataLayout, IndexFormat, LoadOp, MultisampleState, Operations, Origin3d,
PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, RawFragmentState,
RawRenderPipelineDescriptor, RawVertexBufferLayout, RawVertexState, RenderPassDescriptor,
RenderPipeline, SamplerBindingType, SamplerDescriptor, ShaderModuleDescriptor, ShaderSource,
ShaderStages, TextureAspect, TextureDescriptor, TextureDimension, TextureFormat,
TextureSampleType, TextureUsages, TextureViewDescriptor, TextureViewDimension, VertexAttribute,
VertexFormat, VertexStepMode,
AddressMode, BindGroup, BindGroupEntries, BindGroupLayoutEntry, BindingType, BlendComponent,
BlendState, Buffer, BufferAddress, BufferInitDescriptor, BufferUsages, ColorTargetState,
ColorWrites, Extent3d, Face, FilterMode, FrontFace, ImageCopyTexture, ImageDataLayout,
IndexFormat, MultisampleState, Origin3d, PipelineLayoutDescriptor, PolygonMode, PrimitiveState,
PrimitiveTopology, RawFragmentState, RawRenderPipelineDescriptor, RawVertexBufferLayout,
RawVertexState, RenderPassDescriptor, RenderPipeline, SamplerBindingType, SamplerDescriptor,
ShaderModuleDescriptor, ShaderSource, ShaderStages, TextureAspect, TextureDescriptor,
TextureDimension, TextureFormat, TextureSampleType, TextureUsages, TextureViewDescriptor,
TextureViewDimension, VertexAttribute, VertexFormat, VertexStepMode,
};
use bevy::render::renderer::{RenderContext, RenderDevice, RenderQueue};
use bevy::render::texture::BevyDefault;
Expand Down Expand Up @@ -73,8 +72,10 @@ const VERTICES: &[Vertex] = &[

const INDICES: &[u16] = &[0, 1, 2, 2, 1, 3];

const BACKGROUND_GRAPH: &str = "background_graph";
pub(crate) const BACKGROUND_NODE: &str = "background_node";
#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderSubGraph)]
pub struct BackgroundGraph;
#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderLabel)]
pub(crate) struct BackgroundNodeLabel;

#[derive(Resource)]
pub struct BackgroundPipeline {
Expand All @@ -93,28 +94,27 @@ impl FromWorld for BackgroundPipeline {
source: ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});

let texture_bind_group_layout =
device.create_bind_group_layout(&BindGroupLayoutDescriptor {
label: Some("webcam_bind_group_layout"),
entries: &[
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
sample_type: TextureSampleType::Float { filterable: true },
view_dimension: TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
BindGroupLayoutEntry {
binding: 1,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler(SamplerBindingType::Filtering),
count: None,
let texture_bind_group_layout = device.create_bind_group_layout(
"webcam_bind_group_layout",
&[
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
sample_type: TextureSampleType::Float { filterable: true },
view_dimension: TextureViewDimension::D2,
multisampled: false,
},
],
});
count: None,
},
BindGroupLayoutEntry {
binding: 1,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler(SamplerBindingType::Filtering),
count: None,
},
],
);

let render_pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
label: Some("Webcam Render Pipeline Layout"),
Expand Down Expand Up @@ -178,7 +178,7 @@ impl Node for BackgroundPassDriverNode {
_render_context: &mut RenderContext,
_world: &World,
) -> Result<(), NodeRunError> {
graph.run_sub_graph(BACKGROUND_GRAPH, vec![], Some(graph.view_entity()))?;
graph.run_sub_graph(BackgroundGraph, vec![], Some(graph.view_entity()))?;

Ok(())
}
Expand Down Expand Up @@ -276,28 +276,27 @@ impl Node for BackgroundNode {
..Default::default()
});

let texture_bind_group_layout =
device.create_bind_group_layout(&BindGroupLayoutDescriptor {
entries: &[
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
multisampled: false,
view_dimension: TextureViewDimension::D2,
sample_type: TextureSampleType::Float { filterable: true },
},
count: None,
},
BindGroupLayoutEntry {
binding: 1,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler(SamplerBindingType::Filtering),
count: None,
let texture_bind_group_layout = device.create_bind_group_layout(
"texture_bind_group_layout",
&[
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
multisampled: false,
view_dimension: TextureViewDimension::D2,
sample_type: TextureSampleType::Float { filterable: true },
},
],
label: Some("texture_bind_group_layout"),
});
count: None,
},
BindGroupLayoutEntry {
binding: 1,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler(SamplerBindingType::Filtering),
count: None,
},
],
);

let diffuse_bind_group = device.create_bind_group(
Some("diffuse_bind_group"),
Expand All @@ -319,11 +318,10 @@ impl Node for BackgroundNode {
let pipeline = world.get_resource::<BackgroundPipeline>().unwrap();
let pass_descriptor = RenderPassDescriptor {
label: Some("background_pass"),
color_attachments: &[Some(target.get_color_attachment(Operations {
load: LoadOp::Load,
store: true,
}))],
color_attachments: &[Some(target.get_color_attachment())],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
};

if let (Some(vertex_buffer), Some(index_buffer)) =
Expand Down
6 changes: 2 additions & 4 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ impl BackgroundCamera {
}
});

let known_controls: BTreeMap<KnownCameraControl, CameraControl> = known_controls
.into_iter()
.map(|(k, control)| (k, control))
.collect();
let known_controls: BTreeMap<KnownCameraControl, CameraControl> =
known_controls.into_iter().collect();

let controls = known_controls
.iter()
Expand Down
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::background::{
handle_background_image, BackgroundImage, BackgroundNode, BackgroundPipeline, BACKGROUND_NODE,
handle_background_image, BackgroundImage, BackgroundNode, BackgroundNodeLabel,
BackgroundPipeline,
};
use bevy::core_pipeline;
use bevy::prelude::*;
Expand Down Expand Up @@ -28,23 +29,25 @@ impl Plugin for BevyNokhwaPlugin {
let background_node_3d = BackgroundNode::new(&mut render_app.world);
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();

if let Some(graph_2d) = render_graph.get_sub_graph_mut(core_pipeline::core_2d::graph::NAME)
if let Some(graph_2d) =
render_graph.get_sub_graph_mut(core_pipeline::core_2d::graph::Core2d)
{
graph_2d.add_node(BACKGROUND_NODE, background_node_2d);
graph_2d.add_node(BackgroundNodeLabel, background_node_2d);

graph_2d.add_node_edge(
BACKGROUND_NODE,
core_pipeline::core_2d::graph::node::MAIN_PASS,
BackgroundNodeLabel,
core_pipeline::core_2d::graph::Node2d::MainPass,
);
}

if let Some(graph_3d) = render_graph.get_sub_graph_mut(core_pipeline::core_3d::graph::NAME)
if let Some(graph_3d) =
render_graph.get_sub_graph_mut(core_pipeline::core_3d::graph::Core3d)
{
graph_3d.add_node(BACKGROUND_NODE, background_node_3d);
graph_3d.add_node(BackgroundNodeLabel, background_node_3d);

graph_3d.add_node_edge(
BACKGROUND_NODE,
core_pipeline::core_3d::graph::node::MAIN_TRANSPARENT_PASS,
BackgroundNodeLabel,
core_pipeline::core_3d::graph::Node3d::MainTransparentPass,
);
}
}
Expand Down

0 comments on commit d0bdfcf

Please sign in to comment.