assimp/scene/
node.rs

1use std::slice::from_raw_parts;
2
3use ffi::AiNode;
4
5use math::Matrix4x4;
6
7define_type_and_iterator_indirect! {
8    /// The `Node` type represents a node in the imported scene hierarchy.
9    struct Node(&AiNode)
10    /// Node iterator type.
11    struct NodeIter
12}
13
14impl<'a> Node<'a> {
15    /// Returns the name of the node.
16    pub fn name(&self) -> &str {
17        self.name.as_ref()
18    }
19
20    /// Returns the node's transformation matrix.
21    pub fn transformation(&self) -> Matrix4x4 {
22        Matrix4x4::from_raw(&self.transformation)
23    }
24
25    /// Return the parent of this node. Returns `None` if this node is the root node.
26    pub fn parent(&self) -> Option<Node> {
27        if !self.parent.is_null() {
28            Some(Node::from_raw(self.parent))
29        } else {
30            None
31        }
32    }
33
34    /// Returns the number of child nodes.
35    pub fn num_children(&self) -> u32 {
36        self.num_children
37    }
38
39    /// Returns a vector containing all of the child nodes under this node.
40    pub fn child_iter(&self) -> NodeIter {
41        NodeIter::new(self.children as *const *const AiNode,
42                      self.num_children as usize)
43    }
44
45    /// Returns the number of meshes under this node.
46    pub fn num_meshes(&self) -> u32 {
47        self.num_meshes
48    }
49
50    /// Returns a vector containing all of the meshes under this node. These are indices into
51    /// the meshes contained in the `Scene` struct.
52    pub fn meshes(&self) -> &[u32] {
53        let len = self.num_meshes as usize;
54        unsafe { from_raw_parts(self.meshes, len) }
55    }
56
57    // TODO metadata
58}