kittycad_modeling_cmds/format/
fbx.rs

1use parse_display::{Display, FromStr};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5/// Import models in FBX format.
6pub mod import {
7    use super::*;
8    /// Options for importing FBX.
9    #[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
10    #[display("")]
11    #[serde(rename = "FbxImportOptions")]
12    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
13    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
14    #[cfg_attr(
15        feature = "python",
16        pyo3_stub_gen::derive::gen_stub_pyclass,
17        pyo3::pyclass(name = "FbxImportOptions")
18    )]
19    pub struct Options {}
20
21    #[cfg(feature = "python")]
22    #[pyo3_stub_gen::derive::gen_stub_pymethods]
23    #[pyo3::pymethods]
24    impl Options {
25        #[new]
26        /// Set the options to their defaults.
27        pub fn new() -> Self {
28            Default::default()
29        }
30    }
31}
32
33/// Export models in FBX format.
34pub mod export {
35    use super::*;
36
37    /// Options for exporting FBX.
38    #[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema)]
39    #[serde(rename = "FbxExportOptions")]
40    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
41    #[cfg_attr(
42        feature = "python",
43        pyo3_stub_gen::derive::gen_stub_pyclass,
44        pyo3::pyclass(name = "FbxExportOptions")
45    )]
46    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
47    pub struct Options {
48        /// Specifies which kind of FBX will be exported.
49        pub storage: Storage,
50
51        /// Timestamp override.
52        pub created: Option<chrono::DateTime<chrono::Utc>>,
53    }
54
55    #[cfg(feature = "python")]
56    #[pyo3_stub_gen::derive::gen_stub_pymethods]
57    #[pyo3::pymethods]
58    impl Options {
59        #[new]
60        /// Set the options to their defaults.
61        pub fn new() -> Self {
62            Default::default()
63        }
64    }
65
66    impl std::fmt::Display for Options {
67        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68            write!(f, "storage: {}", self.storage)
69        }
70    }
71
72    impl std::str::FromStr for Options {
73        type Err = <Storage as std::str::FromStr>::Err;
74        fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
75            Ok(Self {
76                storage: <Storage as std::str::FromStr>::from_str(s)?,
77                created: None,
78            })
79        }
80    }
81
82    /// Describes the storage format of an FBX file.
83    #[derive(
84        Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
85    )]
86    #[display(style = "snake_case")]
87    #[serde(rename = "FbxStorage", rename_all = "snake_case")]
88    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
89    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
90    #[cfg_attr(
91        feature = "python",
92        pyo3_stub_gen::derive::gen_stub_pyclass_enum,
93        pyo3::pyclass(name = "FbxStorage")
94    )]
95    pub enum Storage {
96        /// ASCII FBX encoding.
97        Ascii,
98
99        /// Binary FBX encoding.
100        #[default]
101        Binary,
102    }
103}