Skip to content

Commit

Permalink
Merge pull request #62 from SlimeYummy/feat/new-trait-tests
Browse files Browse the repository at this point in the history
new trait tests
  • Loading branch information
SlimeYummy authored Apr 8, 2024
2 parents 0edaaa8 + c6ff670 commit 7692a80
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ workflows:
- linux_x86_64:
filters:
branches:
only: [ "-master", "test", "test-full", "test-linux-x64" ]
only: [ "master", "test", "test-full", "test-linux-x64" ]
- linux_aarch64:
filters:
branches:
only: [ "-master", "test", "test-full", "test-linux-arm64" ]
only: [ "master", "test", "test-full", "test-linux-arm64" ]
# - windows_x86_64:
# filters:
# branches:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Main

on:
push:
branches: [ "-master" ]
branches: [ "master" ]
pull_request:
branches: [ "-master" ]
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always
Expand Down
21 changes: 11 additions & 10 deletions tests/additive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use glam::{Mat4, Vec4};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen_test::*;

Expand Down Expand Up @@ -60,12 +61,12 @@ where
let mut sample_job_base: SamplingJob = SamplingJob::default();
sample_job_base.set_animation(animation_base.clone());
sample_job_base.set_context(SamplingContext::new(animation_base.num_tracks()));
let sample_out_base = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out_base = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job_base.set_output(sample_out_base.clone());

let mut blending_job = BlendingJob::default();
blending_job.set_skeleton(skeleton.clone());
let blending_out = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let blending_out = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
blending_job.set_output(blending_out.clone());

let mut layer_base = BlendingLayer::new(sample_out_base.clone());
Expand All @@ -90,13 +91,13 @@ where
let mut l2m_job: LocalToModelJob = LocalToModelJob::default();
l2m_job.set_skeleton(skeleton.clone());
l2m_job.set_input(blending_out.clone());
let l2m_out = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let l2m_out = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));
l2m_job.set_output(l2m_out.clone());

let mut sample_job_splay: SamplingJob = SamplingJob::default();
sample_job_splay.set_animation(animation_splay.clone());
sample_job_splay.set_context(SamplingContext::new(animation_splay.num_tracks()));
let sample_out_splay = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out_splay = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job_splay.set_output(sample_out_splay.clone());

sample_job_splay.set_ratio(0.0); // Only needs the first frame pose
Expand All @@ -108,7 +109,7 @@ where
let mut sample_job_curl: SamplingJob = SamplingJob::default();
sample_job_curl.set_animation(animation_curl.clone());
sample_job_curl.set_context(SamplingContext::new(animation_curl.num_tracks()));
let sample_out_curl = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out_curl = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job_curl.set_output(sample_out_curl.clone());

sample_job_curl.set_ratio(0.0); // Only needs the first frame pose
Expand All @@ -118,9 +119,9 @@ where
.push(BlendingLayer::new(sample_out_curl.clone()));

tester1(&TestDataInit {
sample_out_splay: sample_out_splay.vec().unwrap().clone(),
sample_out_splay: sample_out_splay.buf().unwrap().to_vec(),
sample_ctx_splay: sample_job_splay.context().unwrap().clone_without_animation_id(),
sample_out_curl: sample_out_curl.vec().unwrap().clone(),
sample_out_curl: sample_out_curl.buf().unwrap().to_vec(),
sample_ctx_curl: sample_job_curl.context().unwrap().clone_without_animation_id(),
});

Expand All @@ -142,10 +143,10 @@ where
ratio,
&TestData {
ratio,
sample_out_base: sample_out_base.vec().unwrap().clone(),
sample_out_base: sample_out_base.buf().unwrap().to_vec(),
sample_ctx_base: sample_job_base.context().unwrap().clone_without_animation_id(),
blending_out: blending_out.vec().unwrap().clone(),
l2m_out: l2m_out.vec().unwrap().clone(),
blending_out: blending_out.buf().unwrap().to_vec(),
l2m_out: l2m_out.buf().unwrap().to_vec(),
},
);
}
Expand Down
21 changes: 11 additions & 10 deletions tests/blend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use glam::Mat4;
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen_test::*;

Expand Down Expand Up @@ -50,24 +51,24 @@ where
let mut sample_job1: SamplingJob = SamplingJob::default();
sample_job1.set_animation(animation1.clone());
sample_job1.set_context(SamplingContext::new(animation1.num_tracks()));
let sample_out1 = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out1 = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job1.set_output(sample_out1.clone());

let mut sample_job2: SamplingJob = SamplingJob::default();
sample_job2.set_animation(animation2.clone());
sample_job2.set_context(SamplingContext::new(animation2.num_tracks()));
let sample_out2 = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out2 = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job2.set_output(sample_out2.clone());

let mut sample_job3: SamplingJob = SamplingJob::default();
sample_job3.set_animation(animation3.clone());
sample_job3.set_context(SamplingContext::new(animation3.num_tracks()));
let sample_out3 = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out3 = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job3.set_output(sample_out3.clone());

let mut blending_job = BlendingJob::default();
blending_job.set_skeleton(skeleton.clone());
let blending_out = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let blending_out = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
blending_job.set_output(blending_out.clone());
blending_job.layers_mut().push(BlendingLayer::new(sample_out1.clone()));
blending_job.layers_mut().push(BlendingLayer::new(sample_out2.clone()));
Expand All @@ -76,7 +77,7 @@ where
let mut l2m_job: LocalToModelJob = LocalToModelJob::default();
l2m_job.set_skeleton(skeleton.clone());
l2m_job.set_input(blending_out.clone());
let l2m_out = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let l2m_out = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));
l2m_job.set_output(l2m_out.clone());

for i in range {
Expand Down Expand Up @@ -105,14 +106,14 @@ where
ratio,
&TestData {
ratio,
sample_out1: sample_out1.vec().unwrap().clone(),
sample_out1: sample_out1.buf().unwrap().to_vec(),
sample_ctx1: sample_job1.context().unwrap().clone_without_animation_id(),
sample_out2: sample_out2.vec().unwrap().clone(),
sample_out2: sample_out2.buf().unwrap().to_vec(),
sample_ctx2: sample_job2.context().unwrap().clone_without_animation_id(),
sample_out3: sample_out3.vec().unwrap().clone(),
sample_out3: sample_out3.buf().unwrap().to_vec(),
sample_ctx3: sample_job3.context().unwrap().clone_without_animation_id(),
blending_out: blending_out.vec().unwrap().clone(),
l2m_out: l2m_out.vec().unwrap().clone(),
blending_out: blending_out.buf().unwrap().to_vec(),
l2m_out: l2m_out.buf().unwrap().to_vec(),
},
);
}
Expand Down
25 changes: 13 additions & 12 deletions tests/look_at.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use glam::{Mat4, Quat, Vec3A};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen_test::*;

Expand Down Expand Up @@ -58,10 +59,10 @@ where
panic!("Invalid joints chain");
}

let locals1 = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let locals2 = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let models1 = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let models2 = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let locals1 = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
let locals2 = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
let models1 = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));
let models2 = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));

let mut sample_job: SamplingJob = SamplingJob::default();
sample_job.set_animation(animation.clone());
Expand Down Expand Up @@ -102,7 +103,7 @@ where

let mut previous_joint = SKELETON_NO_PARENT;
for (idx, joint) in joints_chain.iter().enumerate() {
ik_job.set_joint(models1.vec().unwrap()[*joint as usize].into());
ik_job.set_joint(models1.buf().unwrap()[*joint as usize].into());
ik_job.set_up(Vec3A::X);

if idx == joints_chain.len() - 1 {
Expand All @@ -115,13 +116,13 @@ where
ik_job.set_offset(EYES_OFFSET);
ik_job.set_forward(Vec3A::Y);
} else {
let transform: Mat4 = models1.vec().unwrap()[previous_joint as usize].into();
let transform: Mat4 = models1.buf().unwrap()[previous_joint as usize].into();
let corrected_forward_ms =
transform.transform_vector3a(ik_job.joint_correction().mul_vec3a(ik_job.forward()));
let corrected_offset_ms =
transform.transform_point3a(ik_job.joint_correction().mul_vec3a(ik_job.offset()));

let transform: Mat4 = models1.vec().unwrap()[*joint as usize].into();
let transform: Mat4 = models1.buf().unwrap()[*joint as usize].into();
let inv_transform = transform.inverse();
ik_job.set_offset(inv_transform.transform_point3a(corrected_offset_ms));
ik_job.set_forward(inv_transform.transform_vector3a(corrected_forward_ms));
Expand All @@ -132,7 +133,7 @@ where
reacheds[idx] = ik_job.reached();

{
let mut locals_mut = locals2.vec_mut().unwrap();
let mut locals_mut = locals2.borrow_mut();
let idx = *joint as usize;
let quat = locals_mut[idx / 4].rotation.col(idx & 3) * ik_job.joint_correction();
locals_mut[idx / 4].rotation.set_col(idx & 3, quat);
Expand All @@ -147,10 +148,10 @@ where
tester(
idx,
&TestData {
locals1: locals1.vec().unwrap().clone(),
locals2: locals2.vec().unwrap().clone(),
models1: models1.vec().unwrap().clone(),
models2: models2.vec().unwrap().clone(),
locals1: locals1.buf().unwrap().to_vec(),
locals2: locals2.buf().unwrap().to_vec(),
models1: models1.buf().unwrap().to_vec(),
models2: models2.buf().unwrap().to_vec(),
joint_corrections,
reacheds,
},
Expand Down
17 changes: 9 additions & 8 deletions tests/partial_blend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use glam::{Mat4, Vec4};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen_test::*;

Expand Down Expand Up @@ -47,18 +48,18 @@ where
let mut sample_job_lower: SamplingJob = SamplingJob::default();
sample_job_lower.set_animation(animation_lower.clone());
sample_job_lower.set_context(SamplingContext::new(animation_lower.num_tracks()));
let sample_out_lower = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out_lower = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job_lower.set_output(sample_out_lower.clone());

let mut sample_job_upper: SamplingJob = SamplingJob::default();
sample_job_upper.set_animation(animation_upper.clone());
sample_job_upper.set_context(SamplingContext::new(animation_upper.num_tracks()));
let sample_out_upper = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out_upper = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job_upper.set_output(sample_out_upper.clone());

let mut blending_job = BlendingJob::default();
blending_job.set_skeleton(skeleton.clone());
let blending_out = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let blending_out = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
blending_job.set_output(blending_out.clone());

let mut layer_lower = BlendingLayer::new(sample_out_lower.clone());
Expand All @@ -82,7 +83,7 @@ where
let mut l2m_job: LocalToModelJob = LocalToModelJob::default();
l2m_job.set_skeleton(skeleton.clone());
l2m_job.set_input(blending_out.clone());
let l2m_out = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let l2m_out = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));
l2m_job.set_output(l2m_out.clone());

for i in range {
Expand All @@ -102,12 +103,12 @@ where
ratio,
&TestData {
ratio,
sample_out_lower: sample_out_lower.vec().unwrap().clone(),
sample_out_lower: sample_out_lower.buf().unwrap().to_vec(),
sample_ctx_lower: sample_job_lower.context().unwrap().clone_without_animation_id(),
sample_out_upper: sample_out_upper.vec().unwrap().clone(),
sample_out_upper: sample_out_upper.buf().unwrap().to_vec(),
sample_ctx_upper: sample_job_upper.context().unwrap().clone_without_animation_id(),
blending_out: blending_out.vec().unwrap().clone(),
l2m_out: l2m_out.vec().unwrap().clone(),
blending_out: blending_out.buf().unwrap().to_vec(),
l2m_out: l2m_out.buf().unwrap().to_vec(),
},
);
}
Expand Down
9 changes: 5 additions & 4 deletions tests/playback.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use glam::Mat4;
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen_test::*;

Expand Down Expand Up @@ -47,13 +48,13 @@ where
let mut sample_job: SamplingJob = SamplingJob::default();
sample_job.set_animation(animation.clone());
sample_job.set_context(SamplingContext::new(animation.num_tracks()));
let sample_out = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let sample_out = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
sample_job.set_output(sample_out.clone());

let mut l2m_job: LocalToModelJob = LocalToModelJob::default();
l2m_job.set_skeleton(skeleton.clone());
l2m_job.set_input(sample_out.clone());
let l2m_out = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let l2m_out = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));
l2m_job.set_output(l2m_out.clone());

for i in range {
Expand All @@ -66,9 +67,9 @@ where
ratio,
&TestData {
ratio,
sample_out: sample_out.vec().unwrap().clone(),
sample_out: sample_out.buf().unwrap().to_vec(),
sample_ctx: sample_job.context().unwrap().clone_without_animation_id(),
l2m_out: l2m_out.vec().unwrap().clone(),
l2m_out: l2m_out.buf().unwrap().to_vec(),
},
);
}
Expand Down
15 changes: 8 additions & 7 deletions tests/two_bone_ik.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use glam::{Mat4, Quat, Vec3A};
use ozz_animation_rs::math::*;
use ozz_animation_rs::*;
use std::cell::RefCell;
use std::rc::Rc;
use wasm_bindgen_test::*;

Expand Down Expand Up @@ -48,9 +49,9 @@ where
let mid_joint = skeleton.joint_by_name("forearm").unwrap();
let end_joint = skeleton.joint_by_name("wrist").unwrap();

let locals = ozz_buf(vec![SoaTransform::default(); skeleton.num_soa_joints()]);
let models1 = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let models2 = ozz_buf(vec![Mat4::default(); skeleton.num_joints()]);
let locals = Rc::new(RefCell::new(vec![SoaTransform::default(); skeleton.num_soa_joints()]));
let models1 = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));
let models2 = Rc::new(RefCell::new(vec![Mat4::default(); skeleton.num_joints()]));

let mut l2m_job1: LocalToModelJob = LocalToModelJob::default();
l2m_job1.set_skeleton(skeleton.clone());
Expand Down Expand Up @@ -96,7 +97,7 @@ where

models2.borrow_mut().clone_from_slice(models1.borrow().as_slice());
{
let mut locals_mut = locals.vec_mut().unwrap();
let mut locals_mut = locals.borrow_mut();

let idx = start_joint as usize;
let quat = locals_mut[idx / 4].rotation.col(idx & 3) * ik_job.start_joint_correction();
Expand All @@ -116,9 +117,9 @@ where
tester(
idx,
&TestData {
locals: locals.vec().unwrap().clone(),
models1: models1.vec().unwrap().clone(),
models2: models2.vec().unwrap().clone(),
locals: locals.buf().unwrap().to_vec(),
models1: models1.buf().unwrap().to_vec(),
models2: models2.buf().unwrap().to_vec(),
start_correction: ik_job.start_joint_correction(),
mid_correction: ik_job.mid_joint_correction(),
reached: ik_job.reached(),
Expand Down

0 comments on commit 7692a80

Please sign in to comment.