assimp/scene/
scene.rs

1use ffi::*;
2
3// Import all types
4use super::animation::*;
5use super::camera::*;
6use super::light::*;
7use super::material::*;
8use super::mesh::*;
9use super::node::*;
10use super::texture::*;
11
12define_type! {
13    /// The `Scene` type is the root container for all imported scene data.
14    struct Scene(&AiScene)
15}
16
17impl<'a> Scene<'a> {
18    /// Returns true if the imported scene is not complete.
19    pub fn is_incomplete(&self) -> bool {
20        self.flags.contains(AI_SCENE_FLAGS_INCOMPLETE)
21    }
22
23    /// Returns true if the imported scene was successfully validated by the
24    /// `validate_data_structure` post-process step.
25    pub fn is_validated(&self) -> bool {
26        self.flags.contains(AI_SCENE_FLAGS_VALIDATED)
27    }
28
29    /// Returns true if any warnings were generated by the `validate_data_structure`
30    /// post-process step. The details of the warnings are written to the output log.
31    pub fn has_validation_warning(&self) -> bool {
32        self.flags.contains(AI_SCENE_FLAGS_VALIDATION_WARNING)
33    }
34
35    /// Returns true if the `join_identical_vertices` post-process step was run.
36    pub fn is_non_verbose_format(&self) -> bool {
37        self.flags.contains(AI_SCENE_FLAGS_NON_VERBOSE_FORMAT)
38    }
39
40    /// Returns true if the imported mesh contained height-map terrain data.
41    pub fn is_terrain(&self) -> bool {
42        self.flags.contains(AI_SCENE_FLAGS_TERRAIN)
43    }
44
45    /// Returns the root node of the scene hierarchy
46    pub fn root_node(&self) -> Node {
47        Node::from_raw(self.root_node)
48    }
49
50    /// Returns the number of meshes in the scene.
51    pub fn num_meshes(&self) -> u32 {
52        self.num_meshes
53    }
54
55    /// Returns an iterator over all the meshes in the scene.
56    pub fn mesh_iter(&self) -> MeshIter {
57        MeshIter::new(self.meshes as *const *const AiMesh,
58                      self.num_meshes as usize)
59    }
60
61    /// Return an individual mesh from the scene.
62    pub fn mesh(&self, id: usize) -> Option<Mesh> {
63        if id < self.num_meshes as usize {
64            unsafe { Some(Mesh::from_raw(*(self.meshes.offset(id as isize)))) }
65        } else {
66            None
67        }
68    }
69
70    /// Returns the number of materials in the scene.
71    pub fn num_materials(&self) -> u32 {
72        self.num_materials
73    }
74
75    /// Returns an iterator over all the materials in the scene.
76    pub fn material_iter(&self) -> MaterialIter {
77        MaterialIter::new(self.materials as *const *const AiMaterial,
78                          self.num_materials as usize)
79    }
80
81    /// Returns the number of animations in the scene.
82    pub fn num_animations(&self) -> u32 {
83        self.num_animations
84    }
85
86    /// Returns an iterator over all the animations in the scene.
87    pub fn animation_iter(&self) -> AnimationIter {
88        AnimationIter::new(self.animations as *const *const AiAnimation,
89                           self.num_animations as usize)
90    }
91
92    /// Return an individual animation from the scene.
93    pub fn animation(&self, id: usize) -> Option<Animation> {
94        if id < self.num_animations as usize {
95            unsafe { Some(Animation::from_raw(*(self.animations.offset(id as isize)))) }
96        } else {
97            None
98        }
99    }
100
101    /// Returns the number of animations in the scene.
102    pub fn num_textures(&self) -> u32 {
103        self.num_textures
104    }
105
106    /// Returns an iterator over all the textures in the scene.
107    pub fn texture_iter(&self) -> TextureIter {
108        TextureIter::new(self.textures as *const *const AiTexture,
109                         self.num_textures as usize)
110    }
111
112    /// Returns the number of lights in the scene.
113    pub fn num_lights(&self) -> u32 {
114        self.num_lights
115    }
116
117    /// Returns an iterator over all the lights in the scene.
118    pub fn light_iter(&self) -> LightIter {
119        LightIter::new(self.lights as *const *const AiLight,
120                       self.num_lights as usize)
121    }
122
123    /// Returns the number of cameras in the scene.
124    pub fn num_cameras(&self) -> u32 {
125        self.num_cameras
126    }
127
128    /// Returns an iterator over all the cameras in the scene.
129    pub fn camera_iter(&self) -> CameraIter {
130        CameraIter::new(self.cameras as *const *const AiCamera,
131                        self.num_cameras as usize)
132    }
133}
134
135// Drop implementation for a scene owned by Assimp.
136// Scenes returned by aiImportFile* methods must be freed with aiReleaseImport.
137impl<'a> Drop for Scene<'a> {
138    fn drop(&mut self) {
139        unsafe { aiReleaseImport(self.0); }
140    }
141}