diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 05a8d1b..ab825cb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,8 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Clippy + run: cargo clippy -p ozz-animation-rs -- --no-deps - name: Build run: cargo build --release - name: Run tests diff --git a/Cargo.toml b/Cargo.toml index 836f1da..659d7a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ozz-animation-rs" -version = "0.10.0" +version = "0.10.1" authors = ["SlimeYummy "] edition = "2021" rust-version = "1.75" diff --git a/demo/src/blend.rs b/demo/src/blend.rs index 04562e4..bc51a5b 100644 --- a/demo/src/blend.rs +++ b/demo/src/blend.rs @@ -109,7 +109,7 @@ impl OzzBlend { impl OzzExample for OzzBlend { fn root(&self) -> Mat4 { - return self.models.buf().unwrap()[0]; + self.models.buf().unwrap()[0] } fn bone_trans(&self) -> &[OzzTransform] { diff --git a/demo/src/playback.rs b/demo/src/playback.rs index eb6c515..8791923 100644 --- a/demo/src/playback.rs +++ b/demo/src/playback.rs @@ -69,7 +69,7 @@ impl OzzPlayback { impl OzzExample for OzzPlayback { fn root(&self) -> Mat4 { - return self.models.buf().unwrap()[0]; + self.models.buf().unwrap()[0] } fn bone_trans(&self) -> &[OzzTransform] { diff --git a/demo/src/two_bone_ik.rs b/demo/src/two_bone_ik.rs index be30fa0..ff4e954 100644 --- a/demo/src/two_bone_ik.rs +++ b/demo/src/two_bone_ik.rs @@ -70,7 +70,7 @@ impl OzzTwoBoneIK { impl OzzExample for OzzTwoBoneIK { fn root(&self) -> Mat4 { - return self.models2.buf().unwrap()[0]; + self.models2.buf().unwrap()[0] } fn bone_trans(&self) -> &[OzzTransform] { diff --git a/src/animation.rs b/src/animation.rs index 98a046e..26b00dd 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -403,7 +403,6 @@ impl Animation { archive.read_slice(animation.s_iframe_desc_mut())?; animation.s_iframe_interval = archive.read()?; archive.read_slice(animation.scales_mut())?; - Ok(animation) } @@ -465,7 +464,7 @@ impl Animation { } pub(crate) fn to_raw(&self) -> AnimationRaw { - return AnimationRaw { + AnimationRaw { duration: self.duration, num_tracks: self.num_tracks, name: self.name.clone(), @@ -491,7 +490,7 @@ impl Animation { s_iframe_interval: self.s_iframe_interval, s_iframe_entries: self.s_iframe_entries().to_vec(), s_iframe_desc: self.s_iframe_desc().to_vec(), - }; + } } fn new(meta: AnimationMeta) -> Animation { @@ -652,171 +651,171 @@ impl Animation { /// Gets the buffer of time points. #[inline] pub fn timepoints(&self) -> &[f32] { - return unsafe { slice::from_raw_parts(self.timepoints, self.timepoints_count as usize) }; + unsafe { slice::from_raw_parts(self.timepoints, self.timepoints_count as usize) } } #[inline] fn timepoints_mut(&mut self) -> &mut [f32] { - return unsafe { slice::from_raw_parts_mut(self.timepoints, self.timepoints_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.timepoints, self.timepoints_count as usize) } } /// Gets the buffer of translation keys. #[inline] pub fn translations(&self) -> &[Float3Key] { - return unsafe { slice::from_raw_parts(self.translations, self.translations_count as usize) }; + unsafe { slice::from_raw_parts(self.translations, self.translations_count as usize) } } #[inline] fn translations_mut(&mut self) -> &mut [Float3Key] { - return unsafe { slice::from_raw_parts_mut(self.translations, self.translations_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.translations, self.translations_count as usize) } } #[inline] fn t_ratios(&self) -> &[u16] { - return unsafe { slice::from_raw_parts(self.t_ratios, self.translations_count as usize) }; + unsafe { slice::from_raw_parts(self.t_ratios, self.translations_count as usize) } } #[inline] fn t_ratios_mut(&mut self) -> &mut [u16] { - return unsafe { slice::from_raw_parts_mut(self.t_ratios, self.translations_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.t_ratios, self.translations_count as usize) } } #[inline] fn t_previouses(&self) -> &[u16] { - return unsafe { slice::from_raw_parts(self.t_previouses, self.translations_count as usize) }; + unsafe { slice::from_raw_parts(self.t_previouses, self.translations_count as usize) } } #[inline] fn t_previouses_mut(&mut self) -> &mut [u16] { - return unsafe { slice::from_raw_parts_mut(self.t_previouses, self.translations_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.t_previouses, self.translations_count as usize) } } #[inline] fn t_iframe_entries(&self) -> &[u8] { - return unsafe { slice::from_raw_parts(self.t_iframe_entries, self.t_iframe_entries_count as usize) }; + unsafe { slice::from_raw_parts(self.t_iframe_entries, self.t_iframe_entries_count as usize) } } #[inline] fn t_iframe_entries_mut(&mut self) -> &mut [u8] { - return unsafe { slice::from_raw_parts_mut(self.t_iframe_entries, self.t_iframe_entries_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.t_iframe_entries, self.t_iframe_entries_count as usize) } } #[inline] fn t_iframe_desc(&self) -> &[u32] { - return unsafe { slice::from_raw_parts(self.t_iframe_desc, self.t_iframe_desc_count as usize) }; + unsafe { slice::from_raw_parts(self.t_iframe_desc, self.t_iframe_desc_count as usize) } } #[inline] fn t_iframe_desc_mut(&mut self) -> &mut [u32] { - return unsafe { slice::from_raw_parts_mut(self.t_iframe_desc, self.t_iframe_desc_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.t_iframe_desc, self.t_iframe_desc_count as usize) } } /// Gets the buffer of rotation keys. #[inline] pub fn rotations(&self) -> &[QuaternionKey] { - return unsafe { slice::from_raw_parts(self.rotations, self.rotations_count as usize) }; + unsafe { slice::from_raw_parts(self.rotations, self.rotations_count as usize) } } #[inline] fn rotations_mut(&mut self) -> &mut [QuaternionKey] { - return unsafe { slice::from_raw_parts_mut(self.rotations, self.rotations_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.rotations, self.rotations_count as usize) } } #[inline] fn r_ratios(&self) -> &[u16] { - return unsafe { slice::from_raw_parts(self.r_ratios, self.rotations_count as usize) }; + unsafe { slice::from_raw_parts(self.r_ratios, self.rotations_count as usize) } } #[inline] fn r_ratios_mut(&mut self) -> &mut [u16] { - return unsafe { slice::from_raw_parts_mut(self.r_ratios, self.rotations_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.r_ratios, self.rotations_count as usize) } } #[inline] fn r_previouses(&self) -> &[u16] { - return unsafe { slice::from_raw_parts(self.r_previouses, self.rotations_count as usize) }; + unsafe { slice::from_raw_parts(self.r_previouses, self.rotations_count as usize) } } #[inline] fn r_previouses_mut(&mut self) -> &mut [u16] { - return unsafe { slice::from_raw_parts_mut(self.r_previouses, self.rotations_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.r_previouses, self.rotations_count as usize) } } #[inline] fn r_iframe_entries(&self) -> &[u8] { - return unsafe { slice::from_raw_parts(self.r_iframe_entries, self.r_iframe_entries_count as usize) }; + unsafe { slice::from_raw_parts(self.r_iframe_entries, self.r_iframe_entries_count as usize) } } #[inline] fn r_iframe_entries_mut(&mut self) -> &mut [u8] { - return unsafe { slice::from_raw_parts_mut(self.r_iframe_entries, self.r_iframe_entries_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.r_iframe_entries, self.r_iframe_entries_count as usize) } } #[inline] fn r_iframe_desc(&self) -> &[u32] { - return unsafe { slice::from_raw_parts(self.r_iframe_desc, self.r_iframe_desc_count as usize) }; + unsafe { slice::from_raw_parts(self.r_iframe_desc, self.r_iframe_desc_count as usize) } } #[inline] fn r_iframe_desc_mut(&mut self) -> &mut [u32] { - return unsafe { slice::from_raw_parts_mut(self.r_iframe_desc, self.r_iframe_desc_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.r_iframe_desc, self.r_iframe_desc_count as usize) } } /// Gets the buffer of scale keys. #[inline] pub fn scales(&self) -> &[Float3Key] { - return unsafe { slice::from_raw_parts(self.scales, self.scales_count as usize) }; + unsafe { slice::from_raw_parts(self.scales, self.scales_count as usize) } } #[inline] fn scales_mut(&mut self) -> &mut [Float3Key] { - return unsafe { slice::from_raw_parts_mut(self.scales, self.scales_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.scales, self.scales_count as usize) } } #[inline] fn s_ratios(&self) -> &[u16] { - return unsafe { slice::from_raw_parts(self.s_ratios, self.scales_count as usize) }; + unsafe { slice::from_raw_parts(self.s_ratios, self.scales_count as usize) } } #[inline] fn s_ratios_mut(&mut self) -> &mut [u16] { - return unsafe { slice::from_raw_parts_mut(self.s_ratios, self.scales_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.s_ratios, self.scales_count as usize) } } #[inline] fn s_previouses(&self) -> &[u16] { - return unsafe { slice::from_raw_parts(self.s_previouses, self.scales_count as usize) }; + unsafe { slice::from_raw_parts(self.s_previouses, self.scales_count as usize) } } #[inline] fn s_previouses_mut(&mut self) -> &mut [u16] { - return unsafe { slice::from_raw_parts_mut(self.s_previouses, self.scales_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.s_previouses, self.scales_count as usize) } } #[inline] fn s_iframe_entries(&self) -> &[u8] { - return unsafe { slice::from_raw_parts(self.s_iframe_entries, self.s_iframe_entries_count as usize) }; + unsafe { slice::from_raw_parts(self.s_iframe_entries, self.s_iframe_entries_count as usize) } } #[inline] fn s_iframe_entries_mut(&mut self) -> &mut [u8] { - return unsafe { slice::from_raw_parts_mut(self.s_iframe_entries, self.s_iframe_entries_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.s_iframe_entries, self.s_iframe_entries_count as usize) } } #[inline] fn s_iframe_desc(&self) -> &[u32] { - return unsafe { slice::from_raw_parts(self.s_iframe_desc, self.s_iframe_desc_count as usize) }; + unsafe { slice::from_raw_parts(self.s_iframe_desc, self.s_iframe_desc_count as usize) } } #[inline] fn s_iframe_desc_mut(&mut self) -> &mut [u32] { - return unsafe { slice::from_raw_parts_mut(self.s_iframe_desc, self.s_iframe_desc_count as usize) }; + unsafe { slice::from_raw_parts_mut(self.s_iframe_desc, self.s_iframe_desc_count as usize) } } /// Gets the buffer of translation keys. #[inline] pub fn translations_ctrl(&self) -> KeyframesCtrl<'_> { - return unsafe { + unsafe { KeyframesCtrl { ratios: slice::from_raw_parts(self.t_ratios, self.translations_count as usize), previouses: slice::from_raw_parts(self.t_previouses, self.translations_count as usize), @@ -824,13 +823,13 @@ impl Animation { iframe_desc: slice::from_raw_parts(self.t_iframe_desc, self.t_iframe_desc_count as usize), iframe_interval: self.t_iframe_interval, } - }; + } } /// Gets the buffer of rotation keys. #[inline] pub fn rotations_ctrl(&self) -> KeyframesCtrl<'_> { - return unsafe { + unsafe { KeyframesCtrl { ratios: slice::from_raw_parts(self.r_ratios, self.rotations_count as usize), previouses: slice::from_raw_parts(self.r_previouses, self.rotations_count as usize), @@ -838,13 +837,13 @@ impl Animation { iframe_desc: slice::from_raw_parts(self.r_iframe_desc, self.r_iframe_desc_count as usize), iframe_interval: self.r_iframe_interval, } - }; + } } /// Gets the buffer of scale keys. #[inline] pub fn scales_ctrl(&self) -> KeyframesCtrl<'_> { - return unsafe { + unsafe { KeyframesCtrl { ratios: slice::from_raw_parts(self.s_ratios, self.scales_count as usize), previouses: slice::from_raw_parts(self.s_previouses, self.scales_count as usize), @@ -852,7 +851,7 @@ impl Animation { iframe_desc: slice::from_raw_parts(self.s_iframe_desc, self.s_iframe_desc_count as usize), iframe_interval: self.s_iframe_interval, } - }; + } } } diff --git a/src/archive.rs b/src/archive.rs index 94f0b35..447e1f1 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -43,7 +43,6 @@ impl Archive { let version = archive.read::()?; archive.version = version; - Ok(archive) } @@ -105,9 +104,9 @@ impl Archive>> { #[cfg(all(feature = "wasm", feature = "nodejs"))] pub fn from_path(path: &str) -> Result>>, OzzError> { match crate::nodejs::read_file(path) { - Ok(buf) => return Archive::from_vec(buf), - Err(err) => return Err(OzzError::Custom(Box::new(err.as_string().unwrap_or("".into())))), - }; + Ok(buf) => Archive::from_vec(buf), + Err(err) => Err(OzzError::Custom(Box::new(err.as_string().unwrap_or("".into())))), + } } } diff --git a/src/base.rs b/src/base.rs index 352b78c..43c5373 100644 --- a/src/base.rs +++ b/src/base.rs @@ -122,12 +122,12 @@ macro_rules! ozz_index { impl OzzIndex for $type { #[inline(always)] fn usize(&self) -> usize { - return *self as usize; + *self as usize } #[inline(always)] fn i32(&self) -> i32 { - return *self as i32; + *self as i32 } } }; @@ -165,7 +165,7 @@ impl OzzObj for T { } } -impl<'t, T: Debug> OzzObj for &'t T { +impl OzzObj for &T { #[inline(always)] fn obj(&self) -> &T { self @@ -175,14 +175,14 @@ impl<'t, T: Debug> OzzObj for &'t T { impl OzzObj for Rc { #[inline(always)] fn obj(&self) -> &T { - return self.as_ref(); + self.as_ref() } } impl OzzObj for Arc { #[inline(always)] fn obj(&self) -> &T { - return self.as_ref(); + self.as_ref() } } @@ -230,13 +230,13 @@ impl<'a, T: 'static + Debug + Clone> OzzBuf for &'a [T] { #[inline(always)] fn buf(&self) -> Result, OzzError> { - return Ok(ObSliceRef(self)); + Ok(ObSliceRef(self)) } } pub struct ObSliceRef<'t, T>(pub &'t [T]); -impl<'t, T> Deref for ObSliceRef<'t, T> { +impl Deref for ObSliceRef<'_, T> { type Target = [T]; #[inline(always)] @@ -256,7 +256,7 @@ impl<'a, T: 'static + Debug + Clone> OzzBuf for &'a mut [T] { #[inline(always)] fn buf(&self) -> Result, OzzError> { - return Ok(ObSliceRef(self)); + Ok(ObSliceRef(self)) } } @@ -267,13 +267,13 @@ impl<'a, T: 'static + Debug + Clone> OzzMutBuf for &'a mut [T] { #[inline(always)] fn mut_buf(&mut self) -> Result, OzzError> { - return Ok(ObSliceRefMut(self)); + Ok(ObSliceRefMut(self)) } } pub struct ObSliceRefMut<'t, T>(pub &'t mut [T]); -impl<'t, T> Deref for ObSliceRefMut<'t, T> { +impl Deref for ObSliceRefMut<'_, T> { type Target = [T]; #[inline(always)] @@ -282,7 +282,7 @@ impl<'t, T> Deref for ObSliceRefMut<'t, T> { } } -impl<'t, T> DerefMut for ObSliceRefMut<'t, T> { +impl DerefMut for ObSliceRefMut<'_, T> { #[inline(always)] fn deref_mut(&mut self) -> &mut Self::Target { self.0 @@ -298,7 +298,7 @@ impl OzzBuf for Vec { #[inline(always)] fn buf(&self) -> Result, OzzError> { - return Ok(ObSliceRef(self.as_slice())); + Ok(ObSliceRef(self.as_slice())) } } @@ -307,7 +307,7 @@ impl OzzMutBuf for Vec { #[inline(always)] fn mut_buf(&mut self) -> Result, OzzError> { - return Ok(ObSliceRefMut(self)); + Ok(ObSliceRefMut(self)) } } @@ -320,18 +320,18 @@ impl OzzBuf for Rc>> { #[inline(always)] fn buf(&self) -> Result, OzzError> { - return Ok(ObCellRef(self.borrow())); + Ok(ObCellRef(self.borrow())) } } pub struct ObCellRef<'t, T>(pub Ref<'t, Vec>); -impl<'t, T> Deref for ObCellRef<'t, T> { +impl Deref for ObCellRef<'_, T> { type Target = [T]; #[inline(always)] fn deref(&self) -> &Self::Target { - return self.0.as_slice(); + self.0.as_slice() } } @@ -340,25 +340,25 @@ impl OzzMutBuf for Rc>> { #[inline(always)] fn mut_buf(&mut self) -> Result, OzzError> { - return Ok(ObCellRefMut(self.borrow_mut())); + Ok(ObCellRefMut(self.borrow_mut())) } } pub struct ObCellRefMut<'t, T>(pub RefMut<'t, Vec>); -impl<'t, T> Deref for ObCellRefMut<'t, T> { +impl Deref for ObCellRefMut<'_, T> { type Target = [T]; #[inline(always)] fn deref(&self) -> &Self::Target { - return self.0.as_slice(); + self.0.as_slice() } } -impl<'t, T> DerefMut for ObCellRefMut<'t, T> { +impl DerefMut for ObCellRefMut<'_, T> { #[inline(always)] fn deref_mut(&mut self) -> &mut Self::Target { - return self.0.as_mut_slice(); + self.0.as_mut_slice() } } @@ -371,21 +371,21 @@ impl OzzBuf for Arc>> { #[inline(always)] fn buf(&self) -> Result, OzzError> { - return match self.read() { + match self.read() { Ok(guard) => Ok(ObRwLockReadGuard(guard)), Err(_) => Err(OzzError::LockPoison), - }; + } } } pub struct ObRwLockReadGuard<'t, T>(pub RwLockReadGuard<'t, Vec>); -impl<'t, T> Deref for ObRwLockReadGuard<'t, T> { +impl Deref for ObRwLockReadGuard<'_, T> { type Target = [T]; #[inline(always)] fn deref(&self) -> &Self::Target { - return self.0.as_slice(); + self.0.as_slice() } } @@ -394,28 +394,28 @@ impl OzzMutBuf for Arc>> { #[inline(always)] fn mut_buf(&mut self) -> Result, OzzError> { - return match self.write() { + match self.write() { Ok(guard) => Ok(ObRwLockWriteGuard(guard)), Err(_) => Err(OzzError::LockPoison), - }; + } } } pub struct ObRwLockWriteGuard<'t, T>(pub RwLockWriteGuard<'t, Vec>); -impl<'t, T> Deref for ObRwLockWriteGuard<'t, T> { +impl Deref for ObRwLockWriteGuard<'_, T> { type Target = [T]; #[inline(always)] fn deref(&self) -> &Self::Target { - return self.0.as_slice(); + self.0.as_slice() } } -impl<'t, T> DerefMut for ObRwLockWriteGuard<'t, T> { +impl DerefMut for ObRwLockWriteGuard<'_, T> { #[inline(always)] fn deref_mut(&mut self) -> &mut Self::Target { - return self.0.as_mut_slice(); + self.0.as_mut_slice() } } diff --git a/src/blending_job.rs b/src/blending_job.rs index 383335d..a4b22cb 100644 --- a/src/blending_job.rs +++ b/src/blending_job.rs @@ -158,7 +158,7 @@ where /// Gets skeleton of `BlendingJob`. #[inline] pub fn skeleton(&self) -> Option<&S> { - return self.skeleton.as_ref(); + self.skeleton.as_ref() } /// Set skeleton of `BlendingJob`. @@ -183,7 +183,7 @@ where /// Gets context of `BlendingJob`. See [BlendingContext]. #[inline] pub fn context(&self) -> Option<&BlendingContext> { - return self.context.as_ref(); + self.context.as_ref() } /// Sets context of `BlendingJob`. See [BlendingContext]. @@ -270,7 +270,7 @@ where /// Validates `BlendingJob` parameters. pub fn validate(&self) -> bool { - return (|| { + (|| { let skeleton = self.skeleton.as_ref()?.obj(); let _ctx = self.context.as_ref()?; let output = self.output.as_ref()?.buf().ok()?; @@ -294,7 +294,7 @@ where Some(ok) })() - .unwrap_or(false); + .unwrap_or(false) } /// Runs job's blending task. @@ -379,7 +379,6 @@ where ctx.num_passes += 1; } } - Ok(()) } @@ -478,7 +477,6 @@ where } } } - Ok(()) } diff --git a/src/ik_two_bone_job.rs b/src/ik_two_bone_job.rs index 22e264c..ebf3065 100644 --- a/src/ik_two_bone_job.rs +++ b/src/ik_two_bone_job.rs @@ -323,7 +323,6 @@ impl IKTwoBoneJob { let mid_rot_ms = self.compute_mid_joint(&setup, start_target_ss_len2); let start_rot_ss = self.compute_start_joint(&setup, mid_rot_ms, start_target_ss, start_target_ss_len2); self.weight_output(start_rot_ss, mid_rot_ms); - Ok(()) } @@ -389,7 +388,6 @@ impl IKTwoBoneJob { let mid_initial_angle = fx4_xor(fx4_splat_y(mid_corrected_angle), bent_side_flip); // [x] let mid_angles_diff = mid_corrected_angle - mid_initial_angle; // [x] - quat_from_axis_angle(self.mid_axis, mid_angles_diff) } @@ -451,7 +449,6 @@ impl IKTwoBoneJob { start_rot_ss = quat_mul(rotate_plane_ss, end_to_target_rot_ss); } } - start_rot_ss } diff --git a/src/local_to_model_job.rs b/src/local_to_model_job.rs index 02ffe79..0f66e9e 100644 --- a/src/local_to_model_job.rs +++ b/src/local_to_model_job.rs @@ -72,7 +72,7 @@ where /// Gets skeleton of `LocalToModelJob`. #[inline] pub fn skeleton(&self) -> Option<&S> { - return self.skeleton.as_ref(); + self.skeleton.as_ref() } /// Sets skeleton of `LocalToModelJob`. @@ -92,7 +92,7 @@ where /// Gets input of `LocalToModelJob`. #[inline] pub fn input(&self) -> Option<&I> { - return self.input.as_ref(); + self.input.as_ref() } /// Sets input of `LocalToModelJob`. @@ -185,7 +185,7 @@ where /// Gets output of `LocalToModelJob`. #[inline] pub fn output(&self) -> Option<&O> { - return self.output.as_ref(); + self.output.as_ref() } /// Sets output of `LocalToModelJob`. @@ -204,7 +204,7 @@ where /// Validates `LocalToModelJob` parameters. pub fn validate(&self) -> bool { - return (|| { + (|| { let skeleton = self.skeleton.as_ref()?.obj(); let input = self.input.as_ref()?.buf().ok()?; let output = self.output.as_ref()?.buf().ok()?; @@ -213,7 +213,7 @@ where ok &= output.len() >= skeleton.num_joints(); Some(ok) })() - .unwrap_or(false); + .unwrap_or(false) } /// Runs local to model job's task. @@ -253,7 +253,6 @@ where process = idx < end && skeleton.joint_parent(idx) as i32 >= self.from; } } - Ok(()) } } diff --git a/src/math.rs b/src/math.rs index 097b3c0..fda6f54 100644 --- a/src/math.rs +++ b/src/math.rs @@ -649,7 +649,6 @@ impl AosMat4 { let a01 = simd_swizzle!(other.cols[3], Y) * self.cols[1] + xxxx; let a23 = simd_swizzle!(other.cols[3], W) * self.cols[3] + zzzz; result.cols[3] = a01 + a23; - result } diff --git a/src/nodejs.rs b/src/nodejs.rs index 0241672..2014c86 100644 --- a/src/nodejs.rs +++ b/src/nodejs.rs @@ -14,5 +14,5 @@ extern "C" { pub fn read_file(path: &str) -> Result, Error> { let buf = read_file_sync(path).unwrap(); let array = Uint8Array::new(&buf); - return Ok(array.to_vec()); + Ok(array.to_vec()) } diff --git a/src/sampling_job.rs b/src/sampling_job.rs index fe04ad0..ac882fa 100644 --- a/src/sampling_job.rs +++ b/src/sampling_job.rs @@ -204,12 +204,12 @@ impl Debug for SamplingContext { if self.0.is_null() { return f.debug_struct("SamplingContext").finish(); } - return f + f .debug_struct("SamplingContext") .field("mem", &self.0) .field("animation_id", &self.animation_id()) .field("ratio", &self.ratio()) - .finish(); + .finish() } } @@ -235,14 +235,13 @@ impl Clone for SamplingContext { ctx.scale_entries_mut().copy_from_slice(self.scale_entries()); ctx.scale_outdated_mut().copy_from_slice(self.scale_outdated()); ctx.set_scale_next(self.scale_next()); - ctx } } impl PartialEq for SamplingContext { fn eq(&self, other: &Self) -> bool { - return self.max_tracks() == other.max_tracks() + self.max_tracks() == other.max_tracks() && self.max_soa_tracks() == other.max_soa_tracks() && self.max_outdated() == other.max_outdated() && self.animation_id() == other.animation_id() @@ -258,7 +257,7 @@ impl PartialEq for SamplingContext { && self.scales() == other.scales() && self.scale_entries() == other.scale_entries() && self.scale_outdated() == other.scale_outdated() - && self.scale_next() == other.scale_next(); + && self.scale_next() == other.scale_next() } } @@ -382,31 +381,31 @@ impl SamplingContext { /// The memory size of the context in bytes. #[inline] pub fn size(&self) -> usize { - return self.inner().size; + self.inner().size } /// The maximum number of SoA tracks that the context can handle. #[inline] pub fn max_soa_tracks(&self) -> usize { - return self.inner().max_soa_tracks; + self.inner().max_soa_tracks } /// The maximum number of tracks that the context can handle. #[inline] pub fn max_tracks(&self) -> usize { - return self.inner().max_tracks; + self.inner().max_tracks } /// The number of tracks that are outdated. #[inline] pub fn max_outdated(&self) -> usize { - return self.inner().max_outdated; + self.inner().max_outdated } /// The unique identifier of the animation that the context is sampling. #[inline] pub fn animation_id(&self) -> u64 { - return self.inner().animation_id; + self.inner().animation_id } fn set_animation_id(&mut self, animation_id: u64) { @@ -416,7 +415,7 @@ impl SamplingContext { /// The current time ratio in the animation. #[inline] pub fn ratio(&self) -> f32 { - return self.inner().ratio; + self.inner().ratio } fn set_ratio(&mut self, ratio: f32) { @@ -427,45 +426,45 @@ impl SamplingContext { #[inline] pub fn translations(&self) -> &[InterpSoaFloat3] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.translations, inner.max_soa_tracks) }; + unsafe { slice::from_raw_parts(inner.translations, inner.max_soa_tracks) } } #[inline] fn translations_mut(&mut self) -> &mut [InterpSoaFloat3] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.translations, inner.max_soa_tracks) }; + unsafe { slice::from_raw_parts_mut(inner.translations, inner.max_soa_tracks) } } /// The keys in the animation that are valid for the current time ratio. #[inline] pub fn translation_entries(&self) -> &[u32] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.translation_entries, inner.max_tracks) }; + unsafe { slice::from_raw_parts(inner.translation_entries, inner.max_tracks) } } #[inline] fn translation_entries_mut(&mut self) -> &mut [u32] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.translation_entries, inner.max_tracks) }; + unsafe { slice::from_raw_parts_mut(inner.translation_entries, inner.max_tracks) } } /// Outdated soa entries. One bit per soa entry (32 joints per byte). #[inline] pub fn translation_outdated(&self) -> &[u8] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.translation_outdated, inner.max_outdated) }; + unsafe { slice::from_raw_parts(inner.translation_outdated, inner.max_outdated) } } #[inline] fn translation_outdated_mut(&mut self) -> &mut [u8] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.translation_outdated, inner.max_outdated) }; + unsafe { slice::from_raw_parts_mut(inner.translation_outdated, inner.max_outdated) } } /// Next key to process in the animation. #[inline] pub fn translation_next(&self) -> usize { - return self.inner().translation_next; + self.inner().translation_next } #[inline] @@ -477,45 +476,45 @@ impl SamplingContext { #[inline] pub fn rotations(&self) -> &[InterpSoaQuaternion] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.rotations, inner.max_soa_tracks) }; + unsafe { slice::from_raw_parts(inner.rotations, inner.max_soa_tracks) } } #[inline] fn rotations_mut(&mut self) -> &mut [InterpSoaQuaternion] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.rotations, inner.max_soa_tracks) }; + unsafe { slice::from_raw_parts_mut(inner.rotations, inner.max_soa_tracks) } } /// The keys in the animation that are valid for the current time ratio. #[inline] pub fn rotation_entries(&self) -> &[u32] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.rotation_entries, inner.max_tracks) }; + unsafe { slice::from_raw_parts(inner.rotation_entries, inner.max_tracks) } } #[inline] fn rotation_entries_mut(&mut self) -> &mut [u32] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.rotation_entries, inner.max_tracks) }; + unsafe { slice::from_raw_parts_mut(inner.rotation_entries, inner.max_tracks) } } /// Outdated soa entries. One bit per soa entry (32 joints per byte). #[inline] pub fn rotation_outdated(&self) -> &[u8] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.rotation_outdated, inner.max_outdated) }; + unsafe { slice::from_raw_parts(inner.rotation_outdated, inner.max_outdated) } } #[inline] fn rotation_outdated_mut(&mut self) -> &mut [u8] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.rotation_outdated, inner.max_outdated) }; + unsafe { slice::from_raw_parts_mut(inner.rotation_outdated, inner.max_outdated) } } /// Next key to process in the animation. #[inline] pub fn rotation_next(&self) -> usize { - return self.inner().rotation_next; + self.inner().rotation_next } #[inline] @@ -527,45 +526,45 @@ impl SamplingContext { #[inline] pub fn scales(&self) -> &[InterpSoaFloat3] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.scales, inner.max_soa_tracks) }; + unsafe { slice::from_raw_parts(inner.scales, inner.max_soa_tracks) } } #[inline] fn scales_mut(&mut self) -> &mut [InterpSoaFloat3] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.scales, inner.max_soa_tracks) }; + unsafe { slice::from_raw_parts_mut(inner.scales, inner.max_soa_tracks) } } /// The keys in the animation that are valid for the current time ratio. #[inline] pub fn scale_entries(&self) -> &[u32] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.scale_entries, inner.max_tracks) }; + unsafe { slice::from_raw_parts(inner.scale_entries, inner.max_tracks) } } #[inline] fn scale_entries_mut(&mut self) -> &mut [u32] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.scale_entries, inner.max_tracks) }; + unsafe { slice::from_raw_parts_mut(inner.scale_entries, inner.max_tracks) } } /// Outdated soa entries. One bit per soa entry (32 joints per byte). #[inline] pub fn scale_outdated(&self) -> &[u8] { let inner = self.inner(); - return unsafe { slice::from_raw_parts(inner.scale_outdated, inner.max_outdated) }; + unsafe { slice::from_raw_parts(inner.scale_outdated, inner.max_outdated) } } #[inline] fn scale_outdated_mut(&mut self) -> &mut [u8] { let inner = self.inner(); - return unsafe { slice::from_raw_parts_mut(inner.scale_outdated, inner.max_outdated) }; + unsafe { slice::from_raw_parts_mut(inner.scale_outdated, inner.max_outdated) } } /// Next key to process in the animation. #[inline] pub fn scale_next(&self) -> usize { - return self.inner().scale_next; + self.inner().scale_next } #[inline] @@ -576,67 +575,67 @@ impl SamplingContext { #[inline] fn translation_update_args<'t>(&'t mut self, animation: &Animation) -> UpdateArgs<'t> { let inner = self.inner_mut(); - return UpdateArgs { + UpdateArgs { num_tracks: animation.num_tracks(), num_soa_tracks: animation.num_soa_tracks(), entries: unsafe { slice::from_raw_parts_mut(inner.translation_entries, inner.max_tracks) }, outdated: unsafe { slice::from_raw_parts_mut(inner.translation_outdated, inner.max_outdated) }, next: &mut inner.translation_next, - }; + } } #[inline] fn translation_decompress_args(&self) -> DecompressArgs<'_, InterpSoaFloat3> { let inner = self.inner(); - return DecompressArgs { + DecompressArgs { entries: unsafe { slice::from_raw_parts(inner.translation_entries, inner.max_tracks) }, outdated: unsafe { slice::from_raw_parts_mut(inner.translation_outdated, inner.max_outdated) }, values: unsafe { slice::from_raw_parts_mut(inner.translations, inner.max_soa_tracks) }, - }; + } } #[inline] fn rotation_update_args(&mut self, animation: &Animation) -> UpdateArgs<'_> { let inner = self.inner_mut(); - return UpdateArgs { + UpdateArgs { num_tracks: animation.num_tracks(), num_soa_tracks: animation.num_soa_tracks(), entries: unsafe { slice::from_raw_parts_mut(inner.rotation_entries, inner.max_tracks) }, outdated: unsafe { slice::from_raw_parts_mut(inner.rotation_outdated, inner.max_outdated) }, next: &mut inner.rotation_next, - }; + } } #[inline] fn rotation_decompress_args(&self) -> DecompressArgs<'_, InterpSoaQuaternion> { let inner = self.inner(); - return DecompressArgs { + DecompressArgs { entries: unsafe { slice::from_raw_parts(inner.rotation_entries, inner.max_tracks) }, outdated: unsafe { slice::from_raw_parts_mut(inner.rotation_outdated, inner.max_outdated) }, values: unsafe { slice::from_raw_parts_mut(inner.rotations, inner.max_soa_tracks) }, - }; + } } #[inline] fn scale_update_args(&mut self, animation: &Animation) -> UpdateArgs<'_> { let inner = self.inner_mut(); - return UpdateArgs { + UpdateArgs { num_tracks: animation.num_tracks(), num_soa_tracks: animation.num_soa_tracks(), entries: unsafe { slice::from_raw_parts_mut(inner.scale_entries, inner.max_tracks) }, outdated: unsafe { slice::from_raw_parts_mut(inner.scale_outdated, inner.max_outdated) }, next: &mut inner.scale_next, - }; + } } #[inline] fn scale_decompress_args(&self) -> DecompressArgs<'_, InterpSoaFloat3> { let inner = self.inner(); - return DecompressArgs { + DecompressArgs { entries: unsafe { slice::from_raw_parts(inner.scale_entries, inner.max_tracks) }, outdated: unsafe { slice::from_raw_parts_mut(inner.scale_outdated, inner.max_outdated) }, values: unsafe { slice::from_raw_parts_mut(inner.scales, inner.max_soa_tracks) }, - }; + } } } @@ -825,7 +824,7 @@ const _: () = { impl<'de> Deserialize<'de> for SamplingContext { fn deserialize>(deserializer: D) -> Result { - return deserializer.deserialize_map(SamplingContextVisitor); + deserializer.deserialize_map(SamplingContextVisitor) } } @@ -1000,7 +999,7 @@ where /// Gets animation to sample of `SamplingJob`. #[inline] pub fn animation(&self) -> Option<&A> { - return self.animation.as_ref(); + self.animation.as_ref() } /// Sets animation to sample of `SamplingJob`. @@ -1018,7 +1017,7 @@ where /// Gets context of `SamplingJob`. See [SamplingContext]. #[inline] pub fn context(&self) -> Option<&C> { - return self.context.as_ref(); + self.context.as_ref() } /// Sets context of `SamplingJob`. See [SamplingContext]. @@ -1061,7 +1060,7 @@ where /// Gets output of `SamplingJob`. #[inline] pub fn output(&self) -> Option<&O> { - return self.output.as_ref(); + self.output.as_ref() } /// Sets output of `SamplingJob`. @@ -1084,7 +1083,7 @@ where /// Validates `SamplingJob` parameters. pub fn validate(&self) -> bool { - return (|| { + (|| { let animation = self.animation.as_ref()?.obj(); let context = self.context.as_ref()?; let output = self.output.as_ref()?.buf().ok()?; @@ -1093,7 +1092,7 @@ where ok &= output.len() >= animation.num_soa_tracks(); Some(ok) })() - .unwrap_or(false); + .unwrap_or(false) } /// Runs job's sampling task. @@ -1197,7 +1196,7 @@ where next - 1 - ctrl.previouses[next - 1] as usize, ) > ratio { - assert!(next - 1 >= args.num_tracks * 2); + assert!(next > args.num_tracks * 2); track = Self::track_backward(args.entries, next - 1, track, args.num_tracks); args.outdated[track / 32] |= 1 << ((track & 0x1F) / 4); assert!((args.entries[track] as usize) == next - 1); @@ -1386,7 +1385,6 @@ where let scale_ratio = (ratio4 - scale.ratio[0]) / (scale.ratio[1] - scale.ratio[0]); out.scale = SoaVec3::lerp(&scale.value[0], &scale.value[1], scale_ratio); } - Ok(()) } } @@ -1417,7 +1415,6 @@ fn decode_gv4<'t>(buffer: &'t [u8], output: &mut [u32]) -> &'t [u8] { let k3 = (prefix >> 6) as usize; output[3] = load(in_buf) & MASK[k3]; in_buf = &in_buf[k3 + 1..]; - in_buf } diff --git a/src/skeleton.rs b/src/skeleton.rs index cd34082..3fc947e 100644 --- a/src/skeleton.rs +++ b/src/skeleton.rs @@ -223,12 +223,12 @@ impl Skeleton { /// Gets joint's rest poses. Rest poses are stored in soa format. #[inline] pub fn joint_rest_poses(&self) -> &[SoaTransform] { - return unsafe { slice::from_raw_parts(self.joint_rest_poses, self.num_soa_joints()) }; + unsafe { slice::from_raw_parts(self.joint_rest_poses, self.num_soa_joints()) } } #[inline] fn joint_rest_poses_mut(&mut self) -> &mut [SoaTransform] { - return unsafe { slice::from_raw_parts_mut(self.joint_rest_poses, self.num_soa_joints()) }; + unsafe { slice::from_raw_parts_mut(self.joint_rest_poses, self.num_soa_joints()) } } /// Gets joint's name map. @@ -246,23 +246,23 @@ impl Skeleton { /// Gets joint's name by index. #[inline] pub fn name_by_joint(&self, index: i16) -> Option<&str> { - return self.joint_names.get_by_right(&index).map(|s| s.as_str()); + self.joint_names.get_by_right(&index).map(|s| s.as_str()) } /// Gets joint's parent indices range. #[inline] pub fn joint_parents(&self) -> &[i16] { - return unsafe { slice::from_raw_parts(self.joint_parents, self.num_joints()) }; + unsafe { slice::from_raw_parts(self.joint_parents, self.num_joints()) } } fn joint_parents_mut(&mut self) -> &mut [i16] { - return unsafe { slice::from_raw_parts_mut(self.joint_parents, self.num_joints()) }; + unsafe { slice::from_raw_parts_mut(self.joint_parents, self.num_joints()) } } /// Gets joint's parent by index. #[inline] pub fn joint_parent(&self, idx: impl OzzIndex) -> i16 { - return self.joint_parents()[idx.usize()]; + self.joint_parents()[idx.usize()] } /// Test if a joint is a leaf. @@ -272,7 +272,7 @@ impl Skeleton { #[inline] pub fn is_leaf(&self, joint: impl OzzIndex) -> bool { let next = joint.usize() + 1; - return next == self.num_joints() || (self.joint_parents()[next] as i32 != joint.i32()); + next == self.num_joints() || (self.joint_parents()[next] as i32 != joint.i32()) } /// Iterates through the joint hierarchy in depth-first order. diff --git a/src/skinning_job.rs b/src/skinning_job.rs index 9ba1351..9b51d3c 100644 --- a/src/skinning_job.rs +++ b/src/skinning_job.rs @@ -134,7 +134,7 @@ where /// Gets joint matrices of `SkinningJob`. #[inline] pub fn joint_matrices(&self) -> Option<&JM> { - return self.joint_matrices.as_ref(); + self.joint_matrices.as_ref() } /// Sets joint matrices of `SkinningJob`. @@ -154,7 +154,7 @@ where /// Gets joint inverse transpose matrices of `SkinningJob`. #[inline] pub fn joint_it_matrices(&self) -> Option<&JM> { - return self.joint_it_matrices.as_ref(); + self.joint_it_matrices.as_ref() } /// Sets joint inverse transpose matrices of `SkinningJob`. @@ -175,7 +175,7 @@ where /// Gets joint indices of `SkinningJob`. #[inline] pub fn joint_indices(&self) -> Option<&JI> { - return self.joint_indices.as_ref(); + self.joint_indices.as_ref() } /// Sets joint indices of `SkinningJob`. @@ -193,7 +193,7 @@ where /// Gets joint weights of `SkinningJob`. #[inline] pub fn joint_weights(&self) -> Option<&JW> { - return self.joint_weights.as_ref(); + self.joint_weights.as_ref() } /// Sets joint weights of `SkinningJob`. @@ -219,7 +219,7 @@ where /// Gets input positions of `SkinningJob`. #[inline] pub fn in_positions(&self) -> Option<&I> { - return self.in_positions.as_ref(); + self.in_positions.as_ref() } /// Sets input positions of `SkinningJob`. @@ -239,7 +239,7 @@ where /// Gets input normals of `SkinningJob`. #[inline] pub fn in_normals(&self) -> Option<&I> { - return self.in_normals.as_ref(); + self.in_normals.as_ref() } /// Sets input normals of `SkinningJob`. @@ -259,7 +259,7 @@ where /// Gets input tangents of `SkinningJob`. #[inline] pub fn in_tangents(&self) -> Option<&I> { - return self.in_tangents.as_ref(); + self.in_tangents.as_ref() } /// Sets input tangents of `SkinningJob`. @@ -279,7 +279,7 @@ where /// Gets output positions of `SkinningJob`. #[inline] pub fn out_positions(&self) -> Option<&O> { - return self.out_positions.as_ref(); + self.out_positions.as_ref() } /// Sets output positions of `SkinningJob`. @@ -299,7 +299,7 @@ where /// Gets output normals of `SkinningJob`. #[inline] pub fn out_normals(&self) -> Option<&O> { - return self.out_normals.as_ref(); + self.out_normals.as_ref() } /// Sets output normals of `SkinningJob`. @@ -319,7 +319,7 @@ where /// Gets output tangents of `SkinningJob`. #[inline] pub fn out_tangents(&self) -> Option<&O> { - return self.out_tangents.as_ref(); + self.out_tangents.as_ref() } /// Sets output tangents of `SkinningJob`. diff --git a/src/track_sampling_job.rs b/src/track_sampling_job.rs index 4f1d885..ad88dc1 100644 --- a/src/track_sampling_job.rs +++ b/src/track_sampling_job.rs @@ -51,7 +51,7 @@ where /// Gets track of `TrackSamplingJob`. #[inline] pub fn track(&self) -> Option<&T> { - return self.track.as_ref(); + self.track.as_ref() } /// Sets track of `TrackSamplingJob`. @@ -136,7 +136,6 @@ where let v1 = track.values()[id1]; self.result = V::lerp(v0, v1, t); } - Ok(()) } } diff --git a/src/track_triggering_job.rs b/src/track_triggering_job.rs index 1c91e43..7d886b8 100644 --- a/src/track_triggering_job.rs +++ b/src/track_triggering_job.rs @@ -78,7 +78,7 @@ where /// Gets track of `TrackTriggeringJob`. #[inline] pub fn track(&self) -> Option<&T> { - return self.track.as_ref(); + self.track.as_ref() } /// Sets track of `TrackTriggeringJob`. @@ -169,7 +169,7 @@ where if self.track.is_none() { return Err(OzzError::InvalidJob); } - return Ok(TrackTriggeringIter::new(self)); + Ok(TrackTriggeringIter::new(self)) } } @@ -240,7 +240,7 @@ where } } -impl<'t, T> Iterator for TrackTriggeringIter<'t, T> +impl Iterator for TrackTriggeringIter<'_, T> where T: OzzObj>, {