kittycad_modeling_cmds/format/
obj.rs

1use parse_display::{Display, FromStr};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use crate::{coord, units::UnitLength};
6
7/// Import models in OBJ format.
8pub mod import {
9    use super::*;
10
11    /// Options for importing OBJ.
12    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
13    #[display("coords: {coords}, units: {units}")]
14    #[serde(rename = "ObjImportOptions")]
15    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
16    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
17    #[cfg_attr(
18        feature = "python",
19        pyo3_stub_gen::derive::gen_stub_pyclass,
20        pyo3::pyclass(name = "ObjImportOptions")
21    )]
22    pub struct Options {
23        /// Co-ordinate system of input data.
24        ///
25        /// Defaults to the [KittyCAD co-ordinate system].
26        ///
27        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
28        pub coords: coord::System,
29
30        /// The units of the input data.
31        ///
32        /// This is very important for correct scaling and when calculating physics properties like
33        /// mass, etc.
34        ///
35        /// Defaults to millimeters.
36        pub units: UnitLength,
37    }
38
39    #[cfg(feature = "python")]
40    #[pyo3_stub_gen::derive::gen_stub_pymethods]
41    #[pyo3::pymethods]
42    impl Options {
43        #[new]
44        /// Set the options to their defaults.
45        pub fn new() -> Self {
46            Default::default()
47        }
48    }
49
50    impl Default for Options {
51        fn default() -> Self {
52            Self {
53                coords: *coord::KITTYCAD,
54                units: UnitLength::Millimeters,
55            }
56        }
57    }
58}
59
60/// Export models in OBJ format.
61pub mod export {
62    use super::*;
63
64    /// Options for exporting OBJ.
65    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
66    #[display("coords: {coords}, units: {units}")]
67    #[serde(rename = "ObjExportOptions")]
68    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
69    #[cfg_attr(
70        feature = "python",
71        pyo3_stub_gen::derive::gen_stub_pyclass,
72        pyo3::pyclass(name = "ObjExportOptions")
73    )]
74    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
75    pub struct Options {
76        /// Co-ordinate system of output data.
77        ///
78        /// Defaults to the [KittyCAD co-ordinate system].
79        ///
80        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
81        pub coords: coord::System,
82
83        /// Export length unit.
84        ///
85        /// Defaults to millimeters.
86        pub units: UnitLength,
87    }
88
89    #[cfg(feature = "python")]
90    #[pyo3_stub_gen::derive::gen_stub_pymethods]
91    #[pyo3::pymethods]
92    impl Options {
93        #[new]
94        /// Set the options to their defaults.
95        pub fn new() -> Self {
96            Default::default()
97        }
98    }
99
100    impl Default for Options {
101        fn default() -> Self {
102            Self {
103                coords: *coord::KITTYCAD,
104                units: UnitLength::Millimeters,
105            }
106        }
107    }
108}