kittycad_modeling_cmds/format/
gltf.rs

1use parse_display::{Display, FromStr};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5/// Import models in KittyCAD's GLTF format.
6pub mod import {
7    use super::*;
8
9    /// Options for importing glTF 2.0.
10    #[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
11    #[display("")]
12    #[serde(rename = "GltfImportOptions")]
13    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
14    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
15    #[cfg_attr(
16        feature = "python",
17        pyo3_stub_gen::derive::gen_stub_pyclass,
18        pyo3::pyclass(name = "GltfImportOptions")
19    )]
20    pub struct Options {}
21
22    #[cfg(feature = "python")]
23    #[pyo3_stub_gen::derive::gen_stub_pymethods]
24    #[pyo3::pymethods]
25    impl Options {
26        #[new]
27        /// Set the options to their defaults.
28        pub fn new() -> Self {
29            Default::default()
30        }
31    }
32}
33
34/// Export models in KittyCAD's GLTF format.
35pub mod export {
36    use super::*;
37    /// Options for exporting glTF 2.0.
38    #[derive(Default, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
39    #[display("storage: {storage}, presentation: {presentation}")]
40    #[serde(rename = "GltfExportOptions")]
41    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
42    #[cfg_attr(
43        feature = "python",
44        pyo3_stub_gen::derive::gen_stub_pyclass,
45        pyo3::pyclass(name = "GltfExportOptions")
46    )]
47    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
48    pub struct Options {
49        /// Specifies which kind of glTF 2.0 will be exported.
50        pub storage: Storage,
51        /// Specifies how the JSON will be presented.
52        pub presentation: Presentation,
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    /// Describes the storage format of a glTF 2.0 scene.
67    #[derive(
68        Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
69    )]
70    #[display(style = "snake_case")]
71    #[serde(rename = "GltfStorage", rename_all = "snake_case")]
72    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
73    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
74    #[cfg_attr(
75        feature = "python",
76        pyo3_stub_gen::derive::gen_stub_pyclass_enum,
77        pyo3::pyclass(name = "GltfStorage")
78    )]
79    pub enum Storage {
80        /// Binary glTF 2.0.
81        ///
82        /// This is a single binary with .glb extension.
83        Binary,
84
85        /// Standard glTF 2.0.
86        ///
87        /// This is a JSON file with .gltf extension paired with a separate
88        /// binary blob file with .bin extension.
89        Standard,
90
91        /// Embedded glTF 2.0.
92        ///
93        /// Single JSON file with .gltf extension binary data encoded as
94        /// base64 data URIs.
95        ///
96        /// This is the default setting.
97        #[default]
98        Embedded,
99    }
100
101    /// Describes the presentation style of the glTF JSON.
102    #[derive(
103        Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
104    )]
105    #[display(style = "snake_case")]
106    #[serde(rename = "GltfPresentation", rename_all = "snake_case")]
107    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
108    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
109    pub enum Presentation {
110        /// Condense the JSON into the smallest possible size.
111        Compact,
112
113        /// Expand the JSON into a more human readable format.
114        ///
115        /// This is the default setting.
116        #[default]
117        Pretty,
118    }
119}