pub use pybevy_macros::{
PyComponent, native_asset, native_component, native_field, native_resource, pybevy_app,
};
use pyo3::{prelude::*, types::IntoPyDict};
pub mod prelude {
pub use pybevy_macros::{
PyComponent, native_asset, native_component, native_field, native_resource, pybevy_app,
};
pub use crate::app::app::PyApp;
}
pub use app::PyStage;
pub use pybevy_core;
pub use pyo3;
#[cfg(feature = "native-plugin")]
pub mod plugin;
#[cfg(feature = "native-plugin")]
pub use plugin::PyBevyPlugin;
pub(crate) mod app;
pub(crate) mod assets;
pub(crate) mod ecs;
pub(crate) mod render;
#[pyfunction]
fn _color_materialize(color: &pybevy_color::PyColor, py: Python<'_>) -> PyResult<Py<PyAny>> {
let material = bevy::pbr::StandardMaterial {
base_color: color.0,
..Default::default()
};
let py_material: Py<pybevy_pbr::PyStandardMaterial> =
Py::new(py, (material.into(), pybevy_core::PyAsset))?;
Ok(py_material.into_any())
}
pub fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<pybevy_core::PyResource>()?;
m.add_class::<pybevy_core::PyComponent>()?;
m.add_class::<pybevy_core::PyPlugin>()?;
pybevy_a11y::add_module(m)?;
pybevy_animation::add_module(m)?;
pybevy_audio::add_module(m)?;
pybevy_camera::add_module(m)?;
pybevy_camera::add_core_pipeline_module(m)?;
pybevy_color::add_module(m)?;
pybevy_gltf::add_module(m)?;
pybevy_image::add_module(m)?;
pybevy_input::add_module(m)?;
pybevy_light::add_module(m)?;
pybevy_math::add_module(m)?;
pybevy_mesh::add_module(m)?;
pybevy_pbr::add_module(m)?;
pybevy_render::add_module(m)?;
pybevy_shader::add_module(m)?;
pybevy_render::add_wgpu_module(m)?;
pybevy_scene::add_module(m)?;
pybevy_sprite::add_module(m)?;
pybevy_text::add_module(m)?;
pybevy_time::add_module(m)?;
pybevy_ui::add_module(m)?;
pybevy_transform::add_module(m)?;
pybevy_window::add_module(m)?;
pybevy_window::add_winit_module(m)?;
#[cfg(feature = "mcp")]
{
pybevy_control::add_module(m)?;
pybevy_control::register_world_wrapper_hook(ecs::world::create_world_wrapper);
}
app::add_module(m)?;
assets::add_module(m)?;
ecs::add_module(m)?;
render::add_module(m)?;
{
let math = m.getattr("math")?.cast_into::<PyModule>()?;
pybevy_mesh::add_math_primitives(&math)?;
}
{
let py = m.py();
let color_mod = m.getattr("color")?.cast_into::<PyModule>()?;
color_mod.add_function(wrap_pyfunction!(_color_materialize, &color_mod)?)?;
let color_class = color_mod.getattr("Color")?;
let func = color_mod.getattr("_color_materialize")?;
py.run(
c"Color.materialize = lambda self: _func(self)",
Some(&[("Color", &color_class), ("_func", &func)].into_py_dict(py)?),
None,
)?;
}
let py = m.py();
let atexit = py.import("atexit")?;
let cleanup_fn = wrap_pyfunction!(app::app::cleanup_apps_on_shutdown, m)?;
atexit.call_method1("register", (cleanup_fn,))?;
Ok(())
}
#[cfg(feature = "native-plugin")]
#[pymodule(gil_used = false)]
pub fn _pybevy(m: &Bound<'_, PyModule>) -> PyResult<()> {
init_module(m)
}