aboutsummaryrefslogtreecommitdiff
path: root/src/classes/vectors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/vectors.rs')
-rw-r--r--src/classes/vectors.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/classes/vectors.rs b/src/classes/vectors.rs
new file mode 100644
index 0000000..c6e3a0d
--- /dev/null
+++ b/src/classes/vectors.rs
@@ -0,0 +1,26 @@
+use super::FromValue;
+use crate::object::Value;
+use glam::{Quat, Vec3};
+
+impl FromValue for Vec3 {
+ fn from_value(v: Value) -> anyhow::Result<Self> {
+ let fields = v.as_class("Vector3f").unwrap();
+ Ok(Self {
+ x: fields["x"].as_f32().unwrap(),
+ y: fields["y"].as_f32().unwrap(),
+ z: fields["z"].as_f32().unwrap(),
+ })
+ }
+}
+
+impl FromValue for Quat {
+ fn from_value(v: Value) -> anyhow::Result<Self> {
+ let fields = v.as_class("Quaternionf").unwrap();
+ Ok(Self::from_array([
+ fields["x"].as_f32().unwrap(),
+ fields["y"].as_f32().unwrap(),
+ fields["z"].as_f32().unwrap(),
+ fields["w"].as_f32().unwrap(),
+ ]))
+ }
+}