Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skeleton alloc #94

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading