Better struct for scene
This commit is contained in:
parent
2725d04a3d
commit
ef667b5a02
|
@ -4,8 +4,6 @@ extern crate glium;
|
|||
extern crate verbose_log;
|
||||
extern crate model_converter;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
use std::process::exit;
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
|
@ -22,7 +20,7 @@ use glium::glutin::Event;
|
|||
use glium::glutin::WindowEvent;
|
||||
use glium::glutin::VirtualKeyCode;
|
||||
|
||||
|
||||
use model_converter::scene::Scene;
|
||||
use model_converter::math::bounding_box::BoundingBox3;
|
||||
use model_converter::math::vector::Vector3;
|
||||
use model_converter::parser::parse;
|
||||
|
@ -89,7 +87,7 @@ fn main() {
|
|||
let display = Display::new(window, context, &events_loop).unwrap();
|
||||
let mut renderer = Renderer::new(display);
|
||||
|
||||
let mut scene = vec![];
|
||||
let mut scene = Scene::new();
|
||||
let mut before;
|
||||
let mut duration;
|
||||
|
||||
|
@ -110,7 +108,7 @@ fn main() {
|
|||
model.build_vertex_buffers(&renderer);
|
||||
duration = Instant::now().duration_since(before);
|
||||
|
||||
scene.push(Rc::new(RefCell::new(model)));
|
||||
scene.emplace(model);
|
||||
logln!(" done in {}ms.\nFinished", as_millis(duration));
|
||||
}
|
||||
|
||||
|
|
39
src/scene.rs
39
src/scene.rs
|
@ -1,8 +1,45 @@
|
|||
//! This module contains everything related to scenes.
|
||||
|
||||
use std::slice::Iter;
|
||||
use std::vec::IntoIter;
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
use model::Model;
|
||||
|
||||
/// Represents a 3D scene with models.
|
||||
pub type Scene = Vec<Rc<RefCell<Model>>>;
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue