Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
3c229ff55b | |||
3c711f2012 | |||
c8860bc561 | |||
e9e89ef02f | |||
0473421f97 | |||
ff3c09c545 |
50
.github/workflows/docs.yml
vendored
50
.github/workflows/docs.yml
vendored
@ -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
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
target/
|
3075
Cargo.lock
generated
Normal file
3075
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@ -1,15 +1,15 @@
|
||||
[package]
|
||||
name = "bevy_headless_render"
|
||||
version = "0.1.1"
|
||||
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"]
|
||||
features = ["bevy_render", "bevy_asset", "png", "bevy_pbr"]
|
||||
|
27
README.md
27
README.md
@ -3,8 +3,7 @@
|
||||
[](https://crates.io/crates/bevy_headless_render)
|
||||

|
||||

|
||||

|
||||
[](https://exvacuum.github.io/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();
|
||||
..Default::default()
|
||||
},
|
||||
HeadlessRenderSource::new(&asset_server, image_handle.clone()),
|
||||
Camera3d::default(),
|
||||
Camera {
|
||||
target: image_handle.into(),
|
||||
..Default::default()
|
||||
},
|
||||
bevy_headless_render::HeadlessRenderBundle {
|
||||
source: headless_render_sources.add(HeadlessRenderSource(image_handle.clone())), // ResMut<Assets<HeadlessRenderSource>>
|
||||
destination: HeadlessRenderDestination::default(),
|
||||
},
|
||||
));
|
||||
```
|
||||
|
||||
|
@ -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)))
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user