Skip to main content

kittycad_modeling_cmds/format/
obj.rs

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