1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use ffi::AiAnimation;
use ffi::AiNodeAnim;
use ffi::AiVectorKey;
use ffi::AiQuatKey;

define_type_and_iterator_indirect! {
    /// Animation type (not yet implemented)
    struct Animation(&AiAnimation)
    /// Animation iterator type.
    struct AnimationIter
}

define_type_and_iterator_indirect! {
    /// NodeAnim type (not yet implemented)
    struct NodeAnim(&AiNodeAnim)
    /// NodeAnim iterator type.
    struct NodeAnimIter
}

define_type_and_iterator_indirect! {
    /// VectorKey type (not yet implemented)
    struct VectorKey(&AiVectorKey)
    /// VectorKey iterator type.
    struct VectorKeyIter
}

define_type_and_iterator_indirect! {
    /// QuatKey type (not yet implemented)
    struct QuatKey(&AiQuatKey)
    /// QuatKey iterator type.
    struct QuatKeyIter
}

impl<'a> NodeAnim<'a> {
    pub fn get_position_key(&self, id: usize) -> Option<VectorKey> {
        if id < self.num_position_keys as usize {
            unsafe { Some(VectorKey::from_raw(self.position_keys.offset(id as isize))) }
        } else {
            None
        }
    }
    pub fn get_rotation_key(&self, id: usize) -> Option<QuatKey> {
        if id < self.num_rotation_keys as usize {
            unsafe { Some(QuatKey::from_raw(self.rotation_keys.offset(id as isize))) }
        } else {
            None
        }
    }
    pub fn get_scaling_key(&self, id: usize) -> Option<VectorKey> {
        if id < self.num_scaling_keys as usize {
            unsafe { Some(VectorKey::from_raw(self.scaling_keys.offset(id as isize))) }
        } else {
            None
        }
    }
}

impl<'a> Animation<'a> {
    pub fn get_node_anim(&self, id: usize) -> Option<NodeAnim> {
        if id < self.num_channels as usize {
            unsafe { Some(NodeAnim::from_raw(*(self.channels.offset(id as isize)))) }
        } else {
            None
        }
    }
}