aboutsummaryrefslogtreecommitdiff
path: root/src/classes
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-14 11:20:02 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-14 11:20:02 +0100
commit6debd2c0a230d623c06869ca4c4f13519f53eb5d (patch)
treea6a2ea4163599833be71fc240ce5fc219eb57afe /src/classes
parentb9affdc70b3fa206c44e1fee352a85dc4f7a27b0 (diff)
downloadunity-tools-6debd2c0a230d623c06869ca4c4f13519f53eb5d.tar
unity-tools-6debd2c0a230d623c06869ca4c4f13519f53eb5d.tar.bz2
unity-tools-6debd2c0a230d623c06869ca4c4f13519f53eb5d.tar.zst
improve PPtr functions
Diffstat (limited to 'src/classes')
-rw-r--r--src/classes/mesh.rs1
-rw-r--r--src/classes/pptr.rs34
-rw-r--r--src/classes/transform.rs2
3 files changed, 30 insertions, 7 deletions
diff --git a/src/classes/mesh.rs b/src/classes/mesh.rs
index b8b9e90..f0b2173 100644
--- a/src/classes/mesh.rs
+++ b/src/classes/mesh.rs
@@ -85,6 +85,7 @@ impl FromValue for Mesh {
})
}
}
+
impl Mesh {
pub fn read_indecies(&self) -> Vec<[u32; 3]> {
if self.index_format == 0 {
diff --git a/src/classes/pptr.rs b/src/classes/pptr.rs
index d6e4bb6..30f37ad 100644
--- a/src/classes/pptr.rs
+++ b/src/classes/pptr.rs
@@ -1,11 +1,17 @@
-use super::HValue;
-use crate::object::{Value, parser::FromValue};
+use crate::{
+ object::{Value, parser::FromValue},
+ serialized_file::SerializedFile,
+};
use anyhow::{Result, anyhow, bail};
+use log::debug;
use serde::Serialize;
-use std::marker::PhantomData;
+use std::{
+ io::{Read, Seek},
+ marker::PhantomData,
+};
#[derive(Debug, Serialize)]
-pub struct PPtr<T = HValue> {
+pub struct PPtr<T = Value> {
#[serde(skip, default)]
_class: PhantomData<T>,
pub class: String,
@@ -36,8 +42,8 @@ impl<T> FromValue for PPtr<T> {
}
}
-impl PPtr {
- pub fn cast<T>(self) -> PPtr<T> {
+impl<T: FromValue> PPtr<T> {
+ pub fn cast<U>(self) -> PPtr<U> {
PPtr {
_class: PhantomData,
class: self.class,
@@ -45,4 +51,20 @@ impl PPtr {
path_id: self.path_id,
}
}
+ pub fn is_null(&self) -> bool {
+ self.path_id == 0 && self.file_id == 0
+ }
+ pub fn load(&self, file: &mut SerializedFile<impl Read + Seek>) -> Result<T> {
+ debug!(
+ "loading PPtr<{}> file_id={} path_id={}",
+ self.class, self.file_id, self.path_id
+ );
+ let ob = file
+ .objects
+ .iter()
+ .find(|o| o.path_id == self.path_id)
+ .ok_or(anyhow!("object with path id {} not found", self.path_id))?
+ .to_owned();
+ file.read_object(ob)?.parse()
+ }
}
diff --git a/src/classes/transform.rs b/src/classes/transform.rs
index 2ec515a..880eb9a 100644
--- a/src/classes/transform.rs
+++ b/src/classes/transform.rs
@@ -29,7 +29,7 @@ impl FromValue for Transform {
.as_vector()
.unwrap()
.into_iter()
- .map(|e| PPtr::from_value(e).unwrap().cast())
+ .map(|e| PPtr::from_value(e).unwrap())
.collect(),
})
}