draco_core/keyframe_animation_decoder.rs
1//! Decoder for [`KeyframeAnimation`].
2//!
3//! Mirrors C++ Draco's `KeyframeAnimationDecoder`, a thin wrapper around the
4//! sequential point-cloud decoder.
5
6use crate::decoder_buffer::DecoderBuffer;
7use crate::keyframe_animation::KeyframeAnimation;
8use crate::point_cloud::PointCloud;
9use crate::point_cloud_decoder::PointCloudDecoder;
10use crate::status::Status;
11
12/// Decodes a Draco bitstream into [`KeyframeAnimation`] data.
13#[derive(Debug, Default)]
14pub struct KeyframeAnimationDecoder;
15
16impl KeyframeAnimationDecoder {
17 /// Creates a new keyframe animation decoder.
18 pub fn new() -> Self {
19 Self
20 }
21
22 /// Decodes `in_buffer` into `animation`. Mirrors C++
23 /// `KeyframeAnimationDecoder::Decode`.
24 ///
25 /// The point cloud underneath is decoded with [`PointCloudDecoder`]'s
26 /// default, on the calling thread. A caller that wants more threads decodes
27 /// it the same way this does, with a decoder of its own:
28 ///
29 /// ```
30 /// # fn decode(bytes: &[u8]) -> draco_core::Status {
31 /// use draco_core::{DecoderBuffer, KeyframeAnimation, PointCloud, PointCloudDecoder};
32 ///
33 /// let mut point_cloud = PointCloud::new();
34 /// let mut decoder = PointCloudDecoder::new();
35 /// decoder.set_threads(0);
36 /// decoder.decode(&mut DecoderBuffer::new(bytes), &mut point_cloud)?;
37 /// let animation = KeyframeAnimation::from_point_cloud(point_cloud);
38 /// # let _ = animation;
39 /// # Ok(())
40 /// # }
41 /// ```
42 pub fn decode(
43 &mut self,
44 in_buffer: &mut DecoderBuffer,
45 animation: &mut KeyframeAnimation,
46 ) -> Status {
47 let mut point_cloud = PointCloud::new();
48 let mut decoder = PointCloudDecoder::new();
49 decoder.decode(in_buffer, &mut point_cloud)?;
50 *animation = KeyframeAnimation::from_point_cloud(point_cloud);
51 Ok(())
52 }
53}