diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-26 23:15:22 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-26 23:15:22 +1000 |
commit | 2e2c57a8c04575eec164279a49947cfdba250853 (patch) | |
tree | b5d20aa256de40ebd9bad7c59ab1e8ebb1c47b52 /bindgen/rust/src/lib.rs | |
parent | f5e5a6fdf58f3135f3211135bfbcb6e70630309f (diff) |
scenes and pbr cleanup to handle missing texture of param
Diffstat (limited to 'bindgen/rust/src/lib.rs')
-rw-r--r-- | bindgen/rust/src/lib.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs index f9e77b0..f3382a2 100644 --- a/bindgen/rust/src/lib.rs +++ b/bindgen/rust/src/lib.rs @@ -3,4 +3,43 @@ #![warn(missing_docs)] #![cfg_attr(docsrs, feature(doc_cfg))] +use std::{ + fs::{self, File}, + io::Write, + path::Path, +}; + pub use celeritas_sys as ffi; +use celeritas_sys::{DirectionalLight, PointLight, Vec3}; +use serde::{Deserialize, Serialize}; + +/// Wrapper around a string that is the path to a gltf model **relative** to the configured +/// `ASSETS` folder +#[derive(Debug, Serialize, Deserialize)] +pub struct ModelPath(String); + +/// Scene that can be saved and loaded from disk +#[derive(Debug, Serialize, Deserialize)] +pub struct SerializableScene { + pub sun: DirectionalLight, + pub point_lights: [Option<PointLight>; 4], + pub camera_orientation: (Vec3, Vec3), + pub models: Vec<ModelPath>, +} + +// Runtime Scene <-> Serialized Scene + +impl SerializableScene { + /// TODO: docs + pub fn store_to_file(&self, filepath: &Path) { + let mut file = File::create(filepath).expect("creation failed"); + let json = serde_json::to_string(&self).expect("serialize failed"); + file.write(&json.as_bytes()).expect("writing failed"); + } + /// TODO: docs + pub fn load_from_file(filepath: &Path) -> Self { + let contents = fs::read_to_string(filepath).expect("Filepath should be open and read-able"); + + serde_json::from_str(&contents).expect("Should be deserializable") + } +} |