oxihuman_export/
collection_export.rs1#![allow(dead_code)]
4
5pub struct CollectionObject {
10 pub name: String,
11 pub object_type: u8,
12}
13
14pub struct CollectionExport {
15 pub name: String,
16 pub objects: Vec<CollectionObject>,
17 pub children: Vec<String>,
18}
19
20pub fn new_collection_export(name: &str) -> CollectionExport {
21 CollectionExport {
22 name: name.to_string(),
23 objects: Vec::new(),
24 children: Vec::new(),
25 }
26}
27
28#[derive(Debug, Clone)]
32pub struct CollectionNode {
33 pub name: String,
34 pub objects: Vec<String>,
35 pub children: Vec<String>,
36}
37
38pub fn new_collection_node(name: &str) -> CollectionNode {
40 CollectionNode {
41 name: name.to_string(),
42 objects: Vec::new(),
43 children: Vec::new(),
44 }
45}
46
47pub fn collection_push_child(node: &mut CollectionNode, child: &str) {
49 node.children.push(child.to_string());
50}
51
52pub fn collection_push_object(node: &mut CollectionNode, obj: &str) {
54 node.objects.push(obj.to_string());
55}
56
57pub fn collection_to_json(node: &CollectionNode) -> String {
59 format!(
60 "{{\"name\":\"{}\",\"objects\":{},\"children\":{}}}",
61 node.name,
62 node.objects.len(),
63 node.children.len()
64 )
65}
66
67pub fn collection_object_count(node: &CollectionNode) -> usize {
69 node.objects.len()
70}
71
72pub fn collection_child_count(node: &CollectionNode) -> usize {
74 node.children.len()
75}
76
77#[cfg(test)]
78mod tests {
79 use super::*;
80
81 #[test]
82 fn test_new_collection_node() {
83 let n = new_collection_node("scene");
84 assert_eq!(n.name, "scene");
85 }
86
87 #[test]
88 fn test_push_object() {
89 let mut n = new_collection_node("s");
90 collection_push_object(&mut n, "Mesh");
91 assert_eq!(collection_object_count(&n), 1);
92 }
93
94 #[test]
95 fn test_push_child() {
96 let mut n = new_collection_node("s");
97 collection_push_child(&mut n, "sub");
98 assert_eq!(collection_child_count(&n), 1);
99 }
100
101 #[test]
102 fn test_collection_to_json() {
103 let n = new_collection_node("s");
104 let j = collection_to_json(&n);
105 assert!(j.contains("\"name\":\"s\""));
106 }
107
108 #[test]
109 fn test_counts_empty() {
110 let n = new_collection_node("s");
111 assert_eq!(collection_object_count(&n), 0);
112 assert_eq!(collection_child_count(&n), 0);
113 }
114}