Compare commits

...

9 Commits

Author SHA1 Message Date
3c229ff55b Upgraded to Bevy 0.15 2024-12-10 16:06:06 -05:00
3c711f2012
Bumped to 0.1.2 2024-08-04 13:29:54 -04:00
c8860bc561
Merge branch 'master' of github.com:exvacuum/bevy_headless_render 2024-08-04 13:25:51 -04:00
e9e89ef02f
Fixed README setup example 2024-08-04 13:25:13 -04:00
0473421f97
Update README.md docs url 2024-08-04 13:18:23 -04:00
ff3c09c545
Delete .github/workflows/docs.yml 2024-08-04 13:17:05 -04:00
017228ffbd
Bump to 0.1.1 2024-08-04 13:14:50 -04:00
98ff44b334
Merge pull request #1 from kaylendog/master
Disable unnecessary Bevy features
2024-08-04 13:07:32 -04:00
kaylen ✨🍓
57d7b34c86
chore: disable unnecessary features 2024-07-29 17:38:11 +01:00
7 changed files with 3120 additions and 87 deletions

View File

@ -1,50 +0,0 @@
name: Docs
on:
push:
branches: [master]
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: deploy
cancel-in-progress: false
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Dependencies
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Configure cache
uses: Swatinem/rust-cache@v2
- name: Setup pages
id: pages
uses: actions/configure-pages@v4
- name: Clean docs folder
run: cargo clean --doc
- name: Build docs
run: cargo doc --no-deps
- name: Add redirect
run: echo '<meta http-equiv="refresh" content="0;url=framebuffer_extract/index.html">' > target/doc/index.html
- name: Remove lock file
run: rm target/doc/.lock
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: target/doc
deploy:
name: Deploy
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

3075
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,15 @@
[package]
name = "bevy_headless_render"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = "A plugin for the bevy engine which enables headless rendering to an image for use in the main world."
license = "0BSD OR MIT OR Apache-2.0"
[dependencies]
oneshot = "0.1.6"
pollster = "0.3.0"
oneshot = "0.1"
pollster = "0.4"
[dependencies.bevy]
version = "0.14"
version = "0.15"
default-features = false
features = ["bevy_render", "bevy_asset", "png", "bevy_pbr"]

View File

@ -3,8 +3,7 @@
[![Crates](https://img.shields.io/crates/v/bevy_headless_render)](https://crates.io/crates/bevy_headless_render)
![License](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)
![Tag](https://img.shields.io/github/v/tag/exvacuum/bevy_headless_render)
![Build](https://img.shields.io/github/actions/workflow/status/exvacuum/bevy_headless_render/rust.yml)
[![Docs](https://img.shields.io/website?url=https%3A%2F%2Fexvacuum.github.io%2Fbevy_headless_render%2F&label=docs)](https://exvacuum.github.io/bevy_headless_render)
[![Docs](https://img.shields.io/docsrs/bevy_headless_render)](https://exvacuum.github.io/bevy_headless_render)
A plugin for the [Bevy](https://bevyengine.org) engine which allows for headless rendering.
@ -15,19 +14,20 @@ Every frame will be copied from `HeadlessRenderSource` render textures into `Hea
| Crate Version | Bevy Version |
|--- |--- |
| 0.1 | 0.14 |
| 0.2 | 0.15 |
## Installation
### crates.io
```toml
[dependencies]
bevy_headless_render = "0.1"
bevy_headless_render = "0.2"
```
### Using git URL in Cargo.toml
```toml
[dependencies.bevy_headless_render]
git = "https://github.com/exvacuum/bevy_headless_render.git"
git = "https://git.exvacuum.dev/bevy_headless_render"
```
## Usage
@ -40,7 +40,7 @@ use bevy_headless_render;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
DefaultPlugins
bevy_headless_render::HeadlessRenderPlugin,
))
.run();
@ -60,7 +60,7 @@ let mut image = Image {
label: None,
size,
dimension: TextureDimension::D2,
format: TextureFormat::R8Unorm,
format: TextureFormat::Rgba8UnormSrgb,
mip_level_count: 1,
sample_count: 1,
usage: TextureUsages::TEXTURE_BINDING
@ -73,20 +73,15 @@ let mut image = Image {
image.resize(size);
let image_handle = images.add(image); // ResMut<Assets<Image>>
let image_handle = asset_server.add(image);
commands.spawn((
Camera3dBundle {
camera: Camera {
target: image_handle.clone().into();
HeadlessRenderSource::new(&asset_server, image_handle.clone()),
Camera3d::default(),
Camera {
target: image_handle.into(),
..Default::default()
},
..Default::default()
},
bevy_headless_render::HeadlessRenderBundle {
source: headless_render_sources.add(HeadlessRenderSource(image_handle.clone())), // ResMut<Assets<HeadlessRenderSource>>
destination: HeadlessRenderDestination::default(),
},
));
```

View File

@ -1,19 +1,19 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
use bevy::{ecs::query::QueryItem, prelude::*, render::extract_component::ExtractComponent};
use crate::render_assets::HeadlessRenderSource;
use crate::render_assets;
/// Headless render destination. Contains the image which the rendered frame is copied to.
#[derive(Component, Default, Clone)]
pub struct HeadlessRenderDestination(pub Arc<Mutex<Image>>);
impl ExtractComponent for HeadlessRenderDestination {
type QueryData = (&'static Self, &'static Handle<HeadlessRenderSource>);
type QueryData = (&'static Self, &'static HeadlessRenderSource);
type QueryFilter = ();
type Out = (Self, Handle<HeadlessRenderSource>);
type Out = (Self, HeadlessRenderSource);
fn extract_component(
(destination, source_handle): QueryItem<'_, Self::QueryData>,
@ -22,11 +22,21 @@ impl ExtractComponent for HeadlessRenderDestination {
}
}
/// Bundle containing both a source and destination for headless rendering.
#[derive(Bundle)]
pub struct HeadlessRenderBundle {
/// Source
pub source: Handle<HeadlessRenderSource>,
/// Destination
pub dest: HeadlessRenderDestination,
impl HeadlessRenderDestination {
/// Get lock on this destination's image
pub fn image(&self) -> Result<MutexGuard<Image>, PoisonError<MutexGuard<Image>>> {
self.0.lock()
}
}
/// Headless render source
#[derive(Component, Debug, Clone, DerefMut, Deref)]
#[require(HeadlessRenderDestination, Camera3d)]
pub struct HeadlessRenderSource(pub Handle<render_assets::HeadlessRenderSource>);
impl HeadlessRenderSource {
/// Create a new headless render source from the provided image
pub fn new(asset_server: &AssetServer, image: Handle<Image>) -> Self {
Self(asset_server.add(render_assets::HeadlessRenderSource(image)))
}
}

View File

@ -9,18 +9,18 @@ use bevy::{
use pollster::FutureExt;
use crate::{components::HeadlessRenderDestination, render_assets::{HeadlessRenderSource, GpuHeadlessRenderSource}};
use crate::{
components::{HeadlessRenderDestination, HeadlessRenderSource},
render_assets::GpuHeadlessRenderSource,
};
pub fn copy_buffers(
mut headless_render_query: Query<(
&Handle<HeadlessRenderSource>,
&mut HeadlessRenderDestination,
)>,
mut headless_render_query: Query<(&HeadlessRenderSource, &mut HeadlessRenderDestination)>,
sources: Res<RenderAssets<GpuHeadlessRenderSource>>,
device: Res<RenderDevice>,
) {
for (source_handle, destination_handle) in headless_render_query.iter_mut() {
let Some(gpu_source) = sources.get(source_handle) else {
let Some(gpu_source) = sources.get(source_handle.id()) else {
continue;
};