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.rs55
1 files changed, 43 insertions, 12 deletions
diff --git a/src/classes/vectors.rs b/src/classes/vectors.rs
index c6e3a0d..76760bc 100644
--- a/src/classes/vectors.rs
+++ b/src/classes/vectors.rs
@@ -1,26 +1,57 @@
-use super::FromValue;
-use crate::object::Value;
-use glam::{Quat, Vec3};
+use crate::object::{Value, parser::FromValue};
+use glam::{Mat4, Quat, Vec3};
impl FromValue for Vec3 {
fn from_value(v: Value) -> anyhow::Result<Self> {
- let fields = v.as_class("Vector3f").unwrap();
+ let mut 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(),
+ x: fields.field("x")?,
+ y: fields.field("y")?,
+ z: fields.field("z")?,
})
}
}
impl FromValue for Quat {
fn from_value(v: Value) -> anyhow::Result<Self> {
- let fields = v.as_class("Quaternionf").unwrap();
+ let mut 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(),
+ fields.field("x")?,
+ fields.field("y")?,
+ fields.field("z")?,
+ fields.field("w")?,
+ ]))
+ }
+}
+
+impl FromValue for Mat4 {
+ fn from_value(v: Value) -> anyhow::Result<Self> {
+ let mut fields = v.as_class("Matrix4x4f").unwrap();
+ Ok(Self::from_cols_array_2d(&[
+ [
+ fields.field("e00")?,
+ fields.field("e01")?,
+ fields.field("e02")?,
+ fields.field("e03")?,
+ ],
+ [
+ fields.field("e10")?,
+ fields.field("e11")?,
+ fields.field("e12")?,
+ fields.field("e13")?,
+ ],
+ [
+ fields.field("e20")?,
+ fields.field("e21")?,
+ fields.field("e22")?,
+ fields.field("e23")?,
+ ],
+ [
+ fields.field("e30")?,
+ fields.field("e31")?,
+ fields.field("e32")?,
+ fields.field("e33")?,
+ ],
]))
}
}