Skip to main content

qualia_core_db/render/skeletal/
player.rs

1//! Cold resident allocation and allocation-free visual playback lifecycle (`etalon_render::skeletal::player`).
2
3use super::{Joint, Key, SkinWeight, Track};
4use crate::container_10d::skeletal_section::SkeletalSection;
5use crate::render::body_fit::AnatomyBodyFit;
6
7pub use etalon_render::skeletal::player::{
8    clip_view, BodyFitSource, BodyFitSpec, ClipRecord, PlaybackReceipt, PlayerError,
9    SkeletalCounts, SkeletalPlayer, SkeletalRigDescriptor, SkeletalSectionSource,
10};
11
12impl SkeletalSectionSource for SkeletalSection<'_> {
13    fn section_counts(&self) -> SkeletalCounts {
14        let c = self.counts();
15        SkeletalCounts {
16            joints: c.joints,
17            vertices: c.vertices,
18            clips: c.clips,
19            tracks: c.tracks,
20            keys: c.keys,
21            encoded_bytes: c.encoded_len(),
22        }
23    }
24
25    fn decode_section_into(
26        &self,
27        joints: &mut [Joint],
28        joint_ids: &mut [u64],
29        skin: &mut [SkinWeight],
30        clips: &mut [ClipRecord],
31        tracks: &mut [Track],
32        keys: &mut [Key],
33    ) -> Result<(), PlayerError> {
34        let c = self.counts();
35        if joints.len() < c.joints
36            || joint_ids.len() < c.joints
37            || skin.len() < c.vertices
38            || clips.len() < c.clips
39            || tracks.len() < c.tracks
40            || keys.len() < c.keys
41        {
42            return Err(PlayerError::InvalidInput);
43        }
44        for i in 0..c.joints {
45            joints[i] = self.joint(i).ok_or(PlayerError::InvalidInput)?;
46            joint_ids[i] = self.joint_id(i).ok_or(PlayerError::InvalidInput)?;
47        }
48        for (i, slot) in skin[..c.vertices].iter_mut().enumerate() {
49            *slot = self.skin(i).ok_or(PlayerError::InvalidInput)?;
50        }
51        for (i, slot) in clips[..c.clips].iter_mut().enumerate() {
52            let clip = self.clip(i).ok_or(PlayerError::InvalidInput)?;
53            *slot = ClipRecord {
54                id: clip.id,
55                duration: clip.duration,
56                first_track: clip.first_track,
57                track_count: clip.track_count,
58                looping: clip.looping,
59            };
60        }
61        for (i, slot) in tracks[..c.tracks].iter_mut().enumerate() {
62            *slot = self.track(i).ok_or(PlayerError::InvalidInput)?;
63        }
64        for (i, slot) in keys[..c.keys].iter_mut().enumerate() {
65            *slot = self.key(i).ok_or(PlayerError::InvalidInput)?;
66        }
67        Ok(())
68    }
69}
70
71impl BodyFitSource for AnatomyBodyFit {
72    fn to_body_fit_spec(&self) -> BodyFitSpec {
73        BodyFitSpec {
74            stature_scale: self.stature_scale,
75            torso_scale_y: self.torso_scale_y,
76            leg_scale_y: self.leg_scale_y,
77            arm_span_scale_x: self.arm_span_scale_x,
78            shoulder_scale_x: self.shoulder_scale_x,
79            chest_radial: self.chest_radial,
80            waist_radial: self.waist_radial,
81            hip_radial: self.hip_radial,
82            pregnancy_abdomen: self.pregnancy_abdomen,
83            pelvis_y_norm: self.pelvis_y_norm,
84            waist_y_norm: self.waist_y_norm,
85            chest_y_norm: self.chest_y_norm,
86            shoulder_y_norm: self.shoulder_y_norm,
87            hidden_keys_count: self.hidden_keys.len(),
88            hidden_keys_bytes: self.hidden_keys.iter().map(|s| s.len()).sum(),
89            identity: self.identity,
90        }
91    }
92}