Skip to main content

oxihuman_export/
collection_export.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5//! Collection export (Blender-style scene collection tree).
6
7/* ── legacy API (kept) ── */
8
9pub 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/* ── spec functions (wave 150B) ── */
29
30/// Spec-style collection node.
31#[derive(Debug, Clone)]
32pub struct CollectionNode {
33    pub name: String,
34    pub objects: Vec<String>,
35    pub children: Vec<String>,
36}
37
38/// Create a new `CollectionNode`.
39pub 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
47/// Add a child collection name.
48pub fn collection_push_child(node: &mut CollectionNode, child: &str) {
49    node.children.push(child.to_string());
50}
51
52/// Add an object name.
53pub fn collection_push_object(node: &mut CollectionNode, obj: &str) {
54    node.objects.push(obj.to_string());
55}
56
57/// Serialize to JSON.
58pub 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
67/// Number of objects in this node.
68pub fn collection_object_count(node: &CollectionNode) -> usize {
69    node.objects.len()
70}
71
72/// Number of child collections.
73pub 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}