-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgltf.rs
More file actions
54 lines (45 loc) · 1.74 KB
/
gltf.rs
File metadata and controls
54 lines (45 loc) · 1.74 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use bevy::prelude::Entity;
use processing::prelude::*;
use pyo3::{exceptions::PyRuntimeError, prelude::*};
use crate::graphics::{Geometry, Light, get_graphics};
use crate::material::Material;
#[pyclass(unsendable)]
pub struct Gltf {
entity: Entity,
}
#[pymethods]
impl Gltf {
pub fn geometry(&self, name: &str) -> PyResult<Geometry> {
let entity = gltf_geometry(self.entity, name)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(Geometry { entity })
}
pub fn material(&self, name: &str) -> PyResult<Material> {
let entity = gltf_material(self.entity, name)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(Material { entity })
}
pub fn mesh_names(&self) -> PyResult<Vec<String>> {
gltf_mesh_names(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
pub fn material_names(&self) -> PyResult<Vec<String>> {
gltf_material_names(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
pub fn camera(&self, index: usize) -> PyResult<()> {
gltf_camera(self.entity, index).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
pub fn light(&self, index: usize) -> PyResult<Light> {
let entity =
gltf_light(self.entity, index).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(Light { entity })
}
}
#[pyfunction]
#[pyo3(pass_module)]
pub fn load_gltf(module: &Bound<'_, PyModule>, path: &str) -> PyResult<Gltf> {
let graphics =
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
let entity =
gltf_load(graphics.entity, path).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(Gltf { entity })
}