59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
//! This module contains everything related to scenes.
|
|
|
|
use std::slice::{Iter, IterMut};
|
|
use std::vec::IntoIter;
|
|
use std::rc::Rc;
|
|
use std::cell::RefCell;
|
|
use model::Model;
|
|
|
|
/// Represents a 3D scene with models.
|
|
pub struct Scene {
|
|
models: Vec<Rc<RefCell<Model>>>,
|
|
}
|
|
|
|
impl Scene {
|
|
/// Creates a new empty scene.
|
|
pub fn new() -> Scene {
|
|
Scene {
|
|
models: vec![],
|
|
}
|
|
}
|
|
|
|
/// Adds a model to the scene.
|
|
pub fn push(&mut self, model: Rc<RefCell<Model>>) {
|
|
self.models.push(model);
|
|
}
|
|
|
|
/// Converts the model to a Rc<RefCell<Model>> and adds it to the scene.
|
|
pub fn emplace(&mut self, model: Model) {
|
|
self.models.push(Rc::new(RefCell::new(model)));
|
|
}
|
|
|
|
/// Returns an iterator to the models of the scene.
|
|
pub fn iter(&self) -> Iter<Rc<RefCell<Model>>> {
|
|
self.models.iter()
|
|
}
|
|
|
|
/// Returns a mutable iterator to the model of the scene.
|
|
pub fn iter_mut(&mut self) -> IterMut<Rc<RefCell<Model>>> {
|
|
self.models.iter_mut()
|
|
}
|
|
}
|
|
|
|
impl IntoIterator for Scene {
|
|
type IntoIter = IntoIter<Rc<RefCell<Model>>>;
|
|
type Item = Rc<RefCell<Model>>;
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
self.models.into_iter()
|
|
}
|
|
}
|
|
|
|
impl From<Vec<Model>> for Scene {
|
|
fn from(input: Vec<Model>) -> Scene {
|
|
Scene {
|
|
models: input.into_iter().map(|x| Rc::new(RefCell::new(x))).collect(),
|
|
}
|
|
}
|
|
}
|