mechthild/py/src/lib.rs
2025-04-22 08:52:10 -04:00

27 lines
595 B
Rust

use bytemuck::allocation::cast_slice_box;
use mechthild_core::{Scene, color::Rgba};
use pyo3::prelude::*;
#[pyclass(name = "Scene")]
struct PyScene(Scene);
#[pymethods]
impl PyScene {
#[new]
pub fn new() -> Self {
Self(Scene::new())
}
pub fn render(&self, width: usize, height: usize) -> Vec<f32> {
let result = self.0.render(width, height);
cast_slice_box::<Rgba, f32>(result).into_vec()
}
}
/// A Python module implemented in Rust.
#[pymodule]
fn mechthild(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyScene>()?;
Ok(())
}