Skip to content

Commit

Permalink
Merge pull request #94 from SlimeYummy/feat/skeleton-alloc
Browse files Browse the repository at this point in the history
skeleton alloc
  • Loading branch information
SlimeYummy authored Aug 25, 2024
2 parents c36fad4 + b401be9 commit e898bdd
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 109 deletions.
16 changes: 16 additions & 0 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ impl<R: Read> Archive<R> {
return T::read_vec(self, count);
}

/// Reads `[T]` from the archive into slice.
/// * `buffer` - The buffer to read into.
pub fn read_slice<T: ArchiveRead<T>>(&mut self, buffer: &mut [T]) -> Result<(), OzzError> {
return T::read_slice(self, buffer);
}

/// Does the endian need to be swapped.
pub fn endian_swap(&self) -> bool {
return self.endian_swap;
Expand Down Expand Up @@ -128,6 +134,16 @@ pub trait ArchiveRead<T> {
}
return Ok(buffer);
}

/// Reads `[T]` from the archive into slice.
/// * `buffer` - The buffer to read into.
#[inline]
fn read_slice<R: Read>(archive: &mut Archive<R>, buffer: &mut [T]) -> Result<(), OzzError> {
for i in 0..buffer.len() {
buffer[i] = Self::read(archive)?;
}
return Ok(());
}
}

macro_rules! primitive_reader {
Expand Down
22 changes: 11 additions & 11 deletions src/local_to_model_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ mod local_to_model_tests {
use super::*;
use crate::base::DeterministicState;
use crate::math::{SoaQuat, SoaVec3};
use crate::skeleton::JointHashMap;
use crate::skeleton::{JointHashMap, SkeletonRaw};

#[test]
#[wasm_bindgen_test]
Expand Down Expand Up @@ -332,17 +332,16 @@ mod local_to_model_tests {
// j1 j3
// | / \
// j2 j4 j5
return Rc::new(Skeleton::from_raw(
vec![
return Rc::new(Skeleton::from_raw(&SkeletonRaw {
joint_rest_poses: vec![
SoaTransform {
translation: SoaVec3::splat_col([0.0; 3]),
rotation: SoaQuat::splat_col([0.0, 0.0, 0.0, 1.0]),
scale: SoaVec3::splat_col([0.0; 3]),
};
2
],
vec![-1, 0, 1, 0, 3, 3],
(|| {
joint_names: (|| {
let mut map = JointHashMap::with_hashers(DeterministicState::new(), DeterministicState::new());
map.insert("j0".into(), 0);
map.insert("j1".into(), 1);
Expand All @@ -352,7 +351,8 @@ mod local_to_model_tests {
map.insert("j5".into(), 5);
return map;
})(),
));
joint_parents: vec![-1, 0, 1, 0, 3, 3],
}));
}

fn new_input1() -> Rc<RefCell<Vec<SoaTransform>>> {
Expand Down Expand Up @@ -391,17 +391,16 @@ mod local_to_model_tests {
// j2 j4 j6
// |
// j5
return Rc::new(Skeleton::from_raw(
vec![
return Rc::new(Skeleton::from_raw(&SkeletonRaw {
joint_rest_poses: vec![
SoaTransform {
translation: SoaVec3::splat_col([0.0; 3]),
rotation: SoaQuat::splat_col([0.0, 0.0, 0.0, 1.0]),
scale: SoaVec3::splat_col([0.0; 3]),
};
2
],
vec![-1, 0, 1, 0, 3, 4, 3, -1],
(|| {
joint_names: (|| {
let mut map = JointHashMap::with_hashers(DeterministicState::new(), DeterministicState::new());
map.insert("j0".into(), 0);
map.insert("j1".into(), 1);
Expand All @@ -413,7 +412,8 @@ mod local_to_model_tests {
map.insert("j7".into(), 7);
return map;
})(),
));
joint_parents: vec![-1, 0, 1, 0, 3, 4, 3, -1],
}));
}

fn new_input2() -> Rc<RefCell<Vec<SoaTransform>>> {
Expand Down
Loading

0 comments on commit e898bdd

Please sign in to comment.