forked from processing/libprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial.rs
More file actions
37 lines (32 loc) · 1020 Bytes
/
material.rs
File metadata and controls
37 lines (32 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use bevy::prelude::Entity;
use processing::prelude::*;
use pyo3::{exceptions::PyRuntimeError, prelude::*};
#[pyclass(unsendable)]
pub struct Material {
pub(crate) entity: Entity,
}
#[pymethods]
impl Material {
#[new]
pub fn new() -> PyResult<Self> {
let entity = material_create_pbr().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(Self { entity })
}
pub fn set_float(&self, name: &str, value: f32) -> PyResult<()> {
material_set(self.entity, name, material::MaterialValue::Float(value))
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
pub fn set_float4(&self, name: &str, r: f32, g: f32, b: f32, a: f32) -> PyResult<()> {
material_set(
self.entity,
name,
material::MaterialValue::Float4([r, g, b, a]),
)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
}
impl Drop for Material {
fn drop(&mut self) {
let _ = material_destroy(self.entity);
}
}