//! 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>>, } 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>) { self.models.push(model); } /// Converts the model to a Rc> 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>> { self.models.iter() } /// Returns a mutable iterator to the model of the scene. pub fn iter_mut(&mut self) -> IterMut>> { self.models.iter_mut() } } impl IntoIterator for Scene { type IntoIter = IntoIter>>; type Item = Rc>; fn into_iter(self) -> Self::IntoIter { self.models.into_iter() } } impl From> for Scene { fn from(input: Vec) -> Scene { Scene { models: input.into_iter().map(|x| Rc::new(RefCell::new(x))).collect(), } } }