smpl_core/common/
pose_override.rs

1use super::{pose_hands::HandType, pose_parts::PosePart};
2use ndarray as nd;
3use std::collections::HashSet;
4use strum::IntoEnumIterator;
5/// Component for pose override
6#[derive(Clone)]
7pub struct PoseOverride {
8    pub denied_parts: HashSet<PosePart>,
9    pub overwrite_hands: Option<HandType>,
10    pub original_left_hand: Option<nd::Array2<f32>>,
11    pub original_right_hand: Option<nd::Array2<f32>>,
12}
13impl PoseOverride {
14    pub fn allow_all() -> Self {
15        Self {
16            denied_parts: HashSet::new(),
17            overwrite_hands: None,
18            original_left_hand: None,
19            original_right_hand: None,
20        }
21    }
22    pub fn deny_all() -> Self {
23        let mut denied_parts = HashSet::new();
24        for part in PosePart::iter() {
25            denied_parts.insert(part);
26        }
27        Self {
28            denied_parts,
29            overwrite_hands: None,
30            original_left_hand: None,
31            original_right_hand: None,
32        }
33    }
34    #[must_use]
35    pub fn allow(mut self, part: PosePart) -> Self {
36        self.denied_parts.remove(&part);
37        self
38    }
39    /// Will set the rotation of these joints to zero
40    #[must_use]
41    pub fn deny(mut self, part: PosePart) -> Self {
42        self.denied_parts.insert(part);
43        self
44    }
45    /// Will set the poses of the hands to something else
46    #[must_use]
47    pub fn overwrite_hands(mut self, hand_type: HandType) -> Self {
48        self.set_overwrite_hands(hand_type);
49        self
50    }
51    #[must_use]
52    pub fn build(self) -> Self {
53        self
54    }
55    /// Will set the poses of the hands to something else
56    pub fn set_overwrite_hands(&mut self, hand_type: HandType) {
57        self.overwrite_hands = Some(hand_type);
58    }
59    pub fn remove_overwrite_hands(&mut self) {
60        self.overwrite_hands = None;
61    }
62    pub fn get_overwrite_hands_type(&self) -> Option<HandType> {
63        self.overwrite_hands
64    }
65}