style: rustfmt run
This commit is contained in:
1 parent
e7659ba387
commit
0661494b0f
17 files changed
+259
-227
No files matched your search
@@ -1,5 +1,5 @@
|
||||
use nalgebra::{Matrix4, Vector3, Vector4};
|
||||
use crate::common::scene::SceneInstance;
|
||||
use nalgebra::{Matrix4, Vector3, Vector4};
|
||||
|
||||
/// Contains all information about an instance of a mesh, specifically its translation, rotation,
|
||||
/// and scale. Note that the rotation is a [`Vector4`], and not a `Quaternion`.
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
pub mod instance;
|
||||
pub mod mesh;
|
||||
pub mod scene;
|
||||
pub mod instance;
|
||||
+10
-9
@@ -1,7 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A scene, which holds all information required to render a world.
|
||||
///
|
||||
@@ -26,16 +26,15 @@ pub struct Scene {
|
||||
impl Scene {
|
||||
/// Converts this `Scene` into its byte representation.
|
||||
pub fn bytes(&self) -> Vec<u8> {
|
||||
postcard::to_allocvec(self)
|
||||
.expect("Couldn't serialize scene")
|
||||
postcard::to_allocvec(self).expect("Couldn't serialize scene")
|
||||
}
|
||||
|
||||
/// Reads a `scene` from the given path. Automatically resolves all paths for the meshes that
|
||||
/// are referenced in the struct.
|
||||
///
|
||||
///
|
||||
/// Reading a scene file allows for all meshes to be loaded at once, which therefore allows
|
||||
/// the program to allocate pipeline buffers just once during the load of this. It would likely
|
||||
/// be reasonable to create a `MeshRegistry` and `InstanceRegistry` at the same time, with
|
||||
/// be reasonable to create a `MeshRegistry` and `InstanceRegistry` at the same time, with
|
||||
/// respect to a single loaded `Scene`.
|
||||
pub fn from_file<P: AsRef<Path>>(path: P) -> Self {
|
||||
let path = path.as_ref();
|
||||
@@ -43,18 +42,20 @@ impl Scene {
|
||||
let mut contents = Vec::new();
|
||||
let _ = file.read_to_end(&mut contents).unwrap();
|
||||
|
||||
let mut scene: Self = postcard::from_bytes(contents.as_slice())
|
||||
.expect("Couldn't deserialize scene");
|
||||
let mut scene: Self =
|
||||
postcard::from_bytes(contents.as_slice()).expect("Couldn't deserialize scene");
|
||||
|
||||
let base = path.parent().unwrap_or(&Path::new("."));
|
||||
scene.mesh_paths = scene.mesh_paths
|
||||
scene.mesh_paths = scene
|
||||
.mesh_paths
|
||||
.into_iter()
|
||||
.map(|(id, mesh_path)| {
|
||||
let res = base.join(mesh_path);
|
||||
let str = res.to_str().unwrap_or_default();
|
||||
|
||||
(id, str.to_string())
|
||||
}).collect::<HashMap<String, String>>();
|
||||
})
|
||||
.collect::<HashMap<String, String>>();
|
||||
|
||||
scene
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user