fbxcel_dom/v7400/
document.rs

1//! FBX DOM.
2
3use fbxcel::tree::v7400::Tree;
4
5use crate::v7400::{
6    connection::ConnectionsCache,
7    definition::DefinitionsCache,
8    global_settings::GlobalSettings,
9    object::{scene::SceneHandle, ObjectHandle, ObjectsCache},
10};
11
12pub use self::loader::Loader;
13
14mod loader;
15
16/// FBX DOM.
17#[derive(Debug, Clone)]
18pub struct Document {
19    /// FBX data tree.
20    tree: Tree,
21    /// Objects cache.
22    objects: ObjectsCache,
23    /// Objects connection cache.
24    connections: ConnectionsCache,
25    /// Object template definitions.
26    definitions: DefinitionsCache,
27}
28
29impl Document {
30    /// Returns a reference to the tree.
31    pub fn tree(&self) -> &Tree {
32        &self.tree
33    }
34
35    /// Returns a reference to the objects cache.
36    pub(crate) fn objects_cache(&self) -> &ObjectsCache {
37        &self.objects
38    }
39
40    /// Returns a reference to the connections cache.
41    pub(crate) fn connections_cache(&self) -> &ConnectionsCache {
42        &self.connections
43    }
44
45    /// Returns a reference to the object template definitions.
46    pub(crate) fn definitions_cache(&self) -> &DefinitionsCache {
47        &self.definitions
48    }
49
50    /// Returns an iterator of all object nodes.
51    pub fn objects(&self) -> impl Iterator<Item = ObjectHandle<'_>> {
52        self.objects
53            .object_node_ids()
54            .map(move |id| id.to_object_handle(self))
55    }
56
57    /// Returns `Document` object nodes, which have root object ID of scenes.
58    pub fn scenes(&self) -> impl Iterator<Item = SceneHandle<'_>> {
59        self.objects.document_nodes().iter().map(move |obj_id| {
60            SceneHandle::new(obj_id.to_object_handle(self))
61                .expect("Should never fail: Actually using `Document` objects")
62        })
63    }
64
65    /// Returns the "GlobalSettings" root level property block, if one exists.
66    #[inline]
67    #[must_use]
68    pub fn global_settings(&self) -> Option<GlobalSettings> {
69        GlobalSettings::new(self)
70    }
71}
72
73impl AsRef<Tree> for Document {
74    fn as_ref(&self) -> &Tree {
75        &self.tree
76    }
77}