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    pub struct Options {
18        /// Co-ordinate system of input data.
19        ///
20        /// Defaults to the [KittyCAD co-ordinate system].
21        ///
22        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
23        pub coords: coord::System,
24
25        /// The units of the input data.
26        ///
27        /// This is very important for correct scaling and when calculating physics properties like
28        /// mass, etc.
29        ///
30        /// Defaults to millimeters.
31        pub units: UnitLength,
32    }
33
34    impl Default for Options {
35        fn default() -> Self {
36            Self {
37                coords: *coord::KITTYCAD,
38                units: UnitLength::Millimeters,
39            }
40        }
41    }
42}
43
44/// Export models in OBJ format.
45pub mod export {
46    use super::*;
47
48    /// Options for exporting OBJ.
49    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
50    #[display("coords: {coords}, units: {units}")]
51    #[serde(rename = "ObjExportOptions")]
52    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
53    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
54    pub struct Options {
55        /// Co-ordinate system of output data.
56        ///
57        /// Defaults to the [KittyCAD co-ordinate system].
58        ///
59        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
60        pub coords: coord::System,
61
62        /// Export length unit.
63        ///
64        /// Defaults to millimeters.
65        pub units: UnitLength,
66    }
67
68    impl Default for Options {
69        fn default() -> Self {
70            Self {
71                coords: *coord::KITTYCAD,
72                units: UnitLength::Millimeters,
73            }
74        }
75    }
76}