assimp/scene/
scene.rs

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use ffi::*;

// Import all types
use super::animation::*;
use super::camera::*;
use super::light::*;
use super::material::*;
use super::mesh::*;
use super::node::*;
use super::texture::*;

define_type! {
    /// The `Scene` type is the root container for all imported scene data.
    struct Scene(&AiScene)
}

impl<'a> Scene<'a> {
    /// Returns true if the imported scene is not complete.
    pub fn is_incomplete(&self) -> bool {
        self.flags.contains(AI_SCENE_FLAGS_INCOMPLETE)
    }

    /// Returns true if the imported scene was successfully validated by the
    /// `validate_data_structure` post-process step.
    pub fn is_validated(&self) -> bool {
        self.flags.contains(AI_SCENE_FLAGS_VALIDATED)
    }

    /// Returns true if any warnings were generated by the `validate_data_structure`
    /// post-process step. The details of the warnings are written to the output log.
    pub fn has_validation_warning(&self) -> bool {
        self.flags.contains(AI_SCENE_FLAGS_VALIDATION_WARNING)
    }

    /// Returns true if the `join_identical_vertices` post-process step was run.
    pub fn is_non_verbose_format(&self) -> bool {
        self.flags.contains(AI_SCENE_FLAGS_NON_VERBOSE_FORMAT)
    }

    /// Returns true if the imported mesh contained height-map terrain data.
    pub fn is_terrain(&self) -> bool {
        self.flags.contains(AI_SCENE_FLAGS_TERRAIN)
    }

    /// Returns the root node of the scene hierarchy
    pub fn root_node(&self) -> Node {
        Node::from_raw(self.root_node)
    }

    /// Returns the number of meshes in the scene.
    pub fn num_meshes(&self) -> u32 {
        self.num_meshes
    }

    /// Returns an iterator over all the meshes in the scene.
    pub fn mesh_iter(&self) -> MeshIter {
        MeshIter::new(self.meshes as *const *const AiMesh,
                      self.num_meshes as usize)
    }

    /// Return an individual mesh from the scene.
    pub fn mesh(&self, id: usize) -> Option<Mesh> {
        if id < self.num_meshes as usize {
            unsafe { Some(Mesh::from_raw(*(self.meshes.offset(id as isize)))) }
        } else {
            None
        }
    }

    /// Returns the number of materials in the scene.
    pub fn num_materials(&self) -> u32 {
        self.num_materials
    }

    /// Returns an iterator over all the materials in the scene.
    pub fn material_iter(&self) -> MaterialIter {
        MaterialIter::new(self.materials as *const *const AiMaterial,
                          self.num_materials as usize)
    }

    /// Returns the number of animations in the scene.
    pub fn num_animations(&self) -> u32 {
        self.num_animations
    }

    /// Returns an iterator over all the animations in the scene.
    pub fn animation_iter(&self) -> AnimationIter {
        AnimationIter::new(self.animations as *const *const AiAnimation,
                           self.num_animations as usize)
    }

    /// Return an individual animation from the scene.
    pub fn animation(&self, id: usize) -> Option<Animation> {
        if id < self.num_animations as usize {
            unsafe { Some(Animation::from_raw(*(self.animations.offset(id as isize)))) }
        } else {
            None
        }
    }

    /// Returns the number of animations in the scene.
    pub fn num_textures(&self) -> u32 {
        self.num_textures
    }

    /// Returns an iterator over all the textures in the scene.
    pub fn texture_iter(&self) -> TextureIter {
        TextureIter::new(self.textures as *const *const AiTexture,
                         self.num_textures as usize)
    }

    /// Returns the number of lights in the scene.
    pub fn num_lights(&self) -> u32 {
        self.num_lights
    }

    /// Returns an iterator over all the lights in the scene.
    pub fn light_iter(&self) -> LightIter {
        LightIter::new(self.lights as *const *const AiLight,
                       self.num_lights as usize)
    }

    /// Returns the number of cameras in the scene.
    pub fn num_cameras(&self) -> u32 {
        self.num_cameras
    }

    /// Returns an iterator over all the cameras in the scene.
    pub fn camera_iter(&self) -> CameraIter {
        CameraIter::new(self.cameras as *const *const AiCamera,
                        self.num_cameras as usize)
    }
}

// Drop implementation for a scene owned by Assimp.
// Scenes returned by aiImportFile* methods must be freed with aiReleaseImport.
impl<'a> Drop for Scene<'a> {
    fn drop(&mut self) {
        unsafe { aiReleaseImport(self.0); }
    }
}