Skip to content

Commit 1fc1892

Browse files
committed
Add custom asset path for python
1 parent 43a0de7 commit 1fc1892

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ workspace = true
1111
default = ["wayland"]
1212
wayland = ["processing_render/wayland"]
1313
x11 = ["processing_render/x11"]
14+
python = ["processing_render/python"]
1415

1516
[workspace]
1617
resolver = "3"

crates/processing_pyo3/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ x11 = ["processing/x11"]
1717

1818
[dependencies]
1919
pyo3 = "0.27.0"
20-
processing = { workspace = true }
20+
processing = { workspace = true, features = ["python"] }
2121
bevy = { workspace = true }
2222
glfw = { version = "0.60.0"}
2323

crates/processing_pyo3/src/graphics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl Graphics {
4242
let glfw_ctx =
4343
GlfwContext::new(width, height).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
4444

45+
// TODO: pass in something to set the directory?
4546
init().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
4647

4748
let surface = glfw_ctx

crates/processing_render/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ workspace = true
1010
default = []
1111
wayland = ["bevy/wayland"]
1212
x11 = ["bevy/x11"]
13+
python = []
1314

1415
[dependencies]
1516
bevy = { workspace = true }
@@ -32,4 +33,4 @@ windows = { version = "0.58", features = ["Win32_Foundation", "Win32_System_Libr
3233
wasm-bindgen = "0.2"
3334
wasm-bindgen-futures = "0.4"
3435
js-sys = "0.3"
35-
web-sys = { version = "0.3", features = ["Window", "Document", "HtmlCanvasElement"] }
36+
web-sys = { version = "0.3", features = ["Window", "Document", "HtmlCanvasElement"] }

crates/processing_render/src/image.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! It can be created from raw pixel data, loaded from disk, resized, and read back to CPU memory.
44
use std::path::PathBuf;
55

6+
#[cfg(feature = "python")]
7+
use bevy::asset::{AssetPath, io::AssetSourceId};
68
use bevy::{
79
asset::{
810
LoadState, RenderAssetUsages, handle_internal_asset_events, io::embedded::GetAssetServer,
@@ -138,6 +140,9 @@ pub fn from_handle(
138140
}
139141

140142
pub fn load(In(path): In<PathBuf>, world: &mut World) -> Result<Entity> {
143+
#[cfg(feature = "python")]
144+
let path = AssetPath::from_path_buf(path).with_source(AssetSourceId::from("assets_directory"));
145+
141146
let handle: Handle<bevy::image::Image> = world.get_asset_server().load(path);
142147
while let LoadState::Loading = world.get_asset_server().load_state(&handle) {
143148
world.run_system_once(handle_internal_asset_events).unwrap();

crates/processing_render/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ mod surface;
66

77
use std::{cell::RefCell, num::NonZero, path::PathBuf, sync::OnceLock};
88

9+
#[cfg(feature = "python")]
10+
use bevy::asset::io::AssetSourceBuilder;
911
#[cfg(not(target_arch = "wasm32"))]
1012
use bevy::log::tracing_subscriber;
1113
use bevy::{
@@ -226,6 +228,13 @@ fn create_app() -> App {
226228
..default()
227229
});
228230

231+
#[cfg(feature = "python")]
232+
app.register_asset_source(
233+
"assets_directory",
234+
// TODO: set this path to the directory containing the main sketch file
235+
AssetSourceBuilder::platform_default("TODO/TODO/TODO/libprocessing/assets", None),
236+
);
237+
229238
app.add_plugins(plugins);
230239
app.add_plugins((ImagePlugin, GraphicsPlugin, SurfacePlugin));
231240
app.add_systems(First, (clear_transient_meshes, activate_cameras))

0 commit comments

Comments
 (0)